From 6a9aa076b839d7af08069a3cea359b24c3197d96 Mon Sep 17 00:00:00 2001 From: Jared Szechy Date: Mon, 7 Jul 2014 20:21:39 -0400 Subject: [PATCH] Add option to display available portaudio devices. --- dsd_main.c | 7 +++- pa_devs.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ pa_devs.h | 6 ++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 pa_devs.c create mode 100644 pa_devs.h diff --git a/dsd_main.c b/dsd_main.c index fe45a78..4c69990 100644 --- a/dsd_main.c +++ b/dsd_main.c @@ -26,6 +26,7 @@ #include "provoice_const.h" #include "git_ver.h" #include "p25p1_heuristics.h" +#include "pa_devs.h" int @@ -273,6 +274,7 @@ usage () printf (" -g Audio output gain (default = 0 = auto, disable = -1)\n"); printf (" -n Do not send synthesized speech to audio output device\n"); printf (" -w Output synthesized speech to a .wav file\n"); + printf (" -a Display port audio devices\n"); printf ("\n"); printf ("Scanner control options:\n"); printf (" -B Serial port baud rate (default=115200)\n"); @@ -466,7 +468,7 @@ main (int argc, char **argv) exitflag = 0; signal (SIGINT, sigfun); - while ((c = getopt (argc, argv, "hep:qstv:z:i:o:d:g:nw:B:C:R:f:m:u:x:A:S:M:rl")) != -1) + while ((c = getopt (argc, argv, "haep:qstv:z:i:o:d:g:nw:B:C:R:f:m:u:x:A:S:M:rl")) != -1) { opterr = 0; switch (c) @@ -474,6 +476,9 @@ main (int argc, char **argv) case 'h': usage (); exit (0); + case 'a': + printPortAudioDevices(); + exit(0); case 'e': opts.errorbars = 1; opts.datascope = 0; diff --git a/pa_devs.c b/pa_devs.c new file mode 100644 index 0000000..f627c41 --- /dev/null +++ b/pa_devs.c @@ -0,0 +1,104 @@ +#include + +#ifdef USE_PORTAUDIO +#include + +#ifdef WIN32 +#include +#endif + +void printPortAudioDevices() +{ + int i, numDevices, defaultDisplayed; + const PaDeviceInfo *deviceInfo; + PaStreamParameters inputParameters, outputParameters; + PaError err; + + + Pa_Initialize(); + + printf( "\nPortAudio version number = %d\nPortAudio version text = '%s'\n", + Pa_GetVersion(), Pa_GetVersionText() ); + + + numDevices = Pa_GetDeviceCount(); + if( numDevices < 0 ) + { + printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices ); + err = numDevices; + goto error; + } + + printf( "Number of devices = %d\n", numDevices ); + for( i=0; ihostApi )->defaultInputDevice ) + { + const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); + printf( "[ Default %s Input", hostInfo->name ); + defaultDisplayed = 1; + } + + if( i == Pa_GetDefaultOutputDevice() ) + { + printf( (defaultDisplayed ? "," : "[") ); + printf( " Default Output" ); + defaultDisplayed = 1; + } + else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice ) + { + const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); + printf( (defaultDisplayed ? "," : "[") ); + printf( " Default %s Output", hostInfo->name ); + defaultDisplayed = 1; + } + + if( defaultDisplayed ) + printf( " ]\n" ); + + /* print device info fields */ +#ifdef WIN32 + { /* Use wide char on windows, so we can show UTF-8 encoded device names */ + wchar_t wideName[MAX_PATH]; + MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1); + wprintf( L"Name = %s\n", wideName ); + } +#else + printf( "Name = %s\n", deviceInfo->name ); +#endif + printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name ); + printf( "Max inputs = %d", deviceInfo->maxInputChannels ); + printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels ); + printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate ); + } + + Pa_Terminate(); + + printf("----------------------------------------------\n"); + return; + +error: + Pa_Terminate(); + fprintf( stderr, "An error occured while using the portaudio stream\n" ); + fprintf( stderr, "Error number: %d\n", err ); + fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); +} + +#else + +void printPortAudioDevices() +{ + printf("PortAudio not supported in this build of dsd\n"); +} + +#endif diff --git a/pa_devs.h b/pa_devs.h new file mode 100644 index 0000000..9e6f65a --- /dev/null +++ b/pa_devs.h @@ -0,0 +1,6 @@ +#ifndef PA_DEVS_H +#define PA_DEVS_H + +void printPortAudioDevices(); + +#endif