static const PaDeviceInfo *select_device(const char *device) { #if (USE_PORTAUDIO == 19) int numDevices = Pa_GetDeviceCount(); #else int numDevices = Pa_CountDevices(); #endif if (numDevices < 0) return NULL; #if (USE_PORTAUDIO == 19) PaDeviceIndex i = 0, selectedIndex = 0; #else PaDeviceID i = 0, selectedIndex = 0; #endif const PaDeviceInfo *deviceInfo = NULL; const PaDeviceInfo *selectedDeviceInfo = NULL; if (option_device_number >= 0) { selectedIndex = option_device_number; selectedDeviceInfo = Pa_GetDeviceInfo(selectedIndex); } if (device == NULL) { #if (USE_PORTAUDIO == 19) selectedIndex = Pa_GetDefaultOutputDevice(); #else selectedIndex = Pa_GetDefaultOutputDeviceID(); #endif selectedDeviceInfo = Pa_GetDeviceInfo(selectedIndex); } if (selectedDeviceInfo == NULL) { for (i = 0; i < numDevices; i++) { deviceInfo = Pa_GetDeviceInfo(i); if (deviceInfo != NULL && !strcmp(device, deviceInfo->name)) { selectedIndex = i; selectedDeviceInfo = deviceInfo; } } } if (selectedDeviceInfo) update_output_parameters(selectedIndex, selectedDeviceInfo); return selectedDeviceInfo; }
static void select_device(const char* the_api) { ENTER("select_device"); #if (USE_PORTAUDIO == 19) int numDevices = Pa_GetDeviceCount(); if( numDevices < 0 ) { SHOW( "ERROR: Pa_CountDevices returned 0x%x\n", numDevices ); assert(0); } PaDeviceIndex i=0, selectedIndex=0, defaultAlsaIndex=numDevices; const PaDeviceInfo *deviceInfo=NULL; const PaDeviceInfo *selectedDeviceInfo=NULL; if(option_device_number >= 0) { selectedIndex = option_device_number; selectedDeviceInfo = Pa_GetDeviceInfo(selectedIndex); } if(selectedDeviceInfo == NULL) { for( i=0; i<numDevices; i++ ) { deviceInfo = Pa_GetDeviceInfo( i ); if (deviceInfo == NULL) { break; } const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); if (hostInfo && hostInfo->type == paALSA) { // Check (once) the default output device if (defaultAlsaIndex == numDevices) { defaultAlsaIndex = hostInfo->defaultOutputDevice; const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo( defaultAlsaIndex ); update_output_parameters(defaultAlsaIndex, deviceInfo); if (Pa_IsFormatSupported(NULL, &myOutputParameters, wave_samplerate) == 0) { SHOW( "select_device > ALSA (default), name=%s (#%d)\n", deviceInfo->name, defaultAlsaIndex); selectedIndex = defaultAlsaIndex; selectedDeviceInfo = deviceInfo; break; } } // if the default output device does not match, // look for the device with the highest number of output channels SHOW( "select_device > ALSA, i=%d (numDevices=%d)\n", i, numDevices); update_output_parameters(i, deviceInfo); if (Pa_IsFormatSupported(NULL, &myOutputParameters, wave_samplerate) == 0) { SHOW( "select_device > ALSA, name=%s (#%d)\n", deviceInfo->name, i); if (!selectedDeviceInfo || (selectedDeviceInfo->maxOutputChannels < deviceInfo->maxOutputChannels)) { selectedIndex = i; selectedDeviceInfo = deviceInfo; } } } } } if (selectedDeviceInfo) { update_output_parameters(selectedIndex, selectedDeviceInfo); } else { i = Pa_GetDefaultOutputDevice(); deviceInfo = Pa_GetDeviceInfo( i ); update_output_parameters(i, deviceInfo); } #endif }