void displayOption() { Pa_Initialize(); fprintf(stderr, "--------------------------------------------------\n"); fprintf(stderr, "Input Devices\n"); fprintf(stderr, "--------------------------------------------------\n"); for (int i = 0; i < Pa_GetDeviceCount(); i++) { const PaDeviceInfo *deviceInfo; deviceInfo = Pa_GetDeviceInfo(i); if (deviceInfo->maxInputChannels > 0) { const PaHostApiInfo *apiInfo; apiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi); fprintf(stderr, "%2d %s(%s)\n", i, deviceInfo->name, apiInfo->name); } } fprintf(stderr, "\n--------------------------------------------------\n"); fprintf(stderr, "Output Devices\n"); fprintf(stderr, "--------------------------------------------------\n"); for (int i = 0; i < Pa_GetDeviceCount(); i++) { const PaDeviceInfo *deviceInfo; deviceInfo = Pa_GetDeviceInfo(i); if (deviceInfo->maxOutputChannels > 0) { const PaHostApiInfo *apiInfo; apiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi); fprintf(stderr, "%2d %s(%s)\n", i, deviceInfo->name, apiInfo->name); } } Pa_Terminate(); }
void PortAudioOutput::initAudio( long sampleRate, int channels ) { if ( m_audio ) { Pa_CloseStream( m_audio ); m_audio = 0; } if ( m_deviceNum >= Pa_GetDeviceCount() || m_deviceNum < 0 ) m_deviceNum = 0; int bufferSize = 512; int deviceID = internalSoundCardID( m_deviceNum ); qDebug() << "Internal ID:" << deviceID << "-" << "Config:" << m_deviceNum; if ( deviceID < 0 ) { emit error( Radio_NoSoundcard, tr( "Your soundcard is either busy or not present. " "Try restarting the application." ) ); return; } PaStreamParameters p; memset( &p, 0, sizeof( PaStreamParameters ) ); p.sampleFormat = paInt16; p.channelCount = 0; while ( p.channelCount < channels && deviceID < Pa_GetDeviceCount() ) { #ifdef Q_WS_WIN p.device = Pa_HostApiDeviceIndexToDeviceIndex( Pa_HostApiTypeIdToHostApiIndex( paDirectSound ), deviceID++ ); #endif #ifdef Q_WS_MAC p.device = Pa_HostApiDeviceIndexToDeviceIndex( Pa_HostApiTypeIdToHostApiIndex( paCoreAudio ), deviceID++ ); #endif #ifdef Q_WS_X11 p.device = Pa_HostApiDeviceIndexToDeviceIndex( Pa_HostApiTypeIdToHostApiIndex( paALSA ), deviceID++ ); #endif p.suggestedLatency = Pa_GetDeviceInfo( p.device )->defaultHighOutputLatency; p.channelCount = Pa_GetDeviceInfo( p.device )->maxOutputChannels; } qDebug() << "Using device with id:" << --deviceID; p.channelCount = channels; // Pa_IsFormatSupported( 0, &p, bufferSize ); m_deviceInfo = *Pa_GetDeviceInfo( p.device ); m_sourceChannels = channels; PaError error = Pa_OpenStream( &m_audio, 0, &p, sampleRate, bufferSize, 0, audioCallback, this ); if ( error != paNoError ) { qDebug() << "PortAudio Error:" << Pa_GetErrorText( error ); m_audio = 0; } }
// Get device list // If first argument is NULL, return the maximum number of devices int get_device_list(int *devidlist, char **namelist, int maxstrlen, int maxnum) { PaDeviceIndex numDevice = Pa_GetDeviceCount(), i; const PaDeviceInfo *deviceInfo; const PaHostApiInfo *apiInfo; static char buf[256]; int n; n = 0; for(i=0;i<numDevice;i++) { deviceInfo = Pa_GetDeviceInfo(i); if (!deviceInfo) continue; if (deviceInfo->maxInputChannels <= 0) continue; apiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi); if (!apiInfo) continue; if (devidlist != NULL) { if ( n >= maxnum ) break; snprintf(buf, 255, "%s: %s", apiInfo->name, deviceInfo->name); buf[255] = '\0'; devidlist[n] = i; strncpy(namelist[n], buf, maxstrlen); } n++; } return n; }
static int paqaVerifyDeviceInfoLatency( void ) { PaDeviceIndex id; const PaDeviceInfo *pdi; int numDevices = Pa_GetDeviceCount(); printf("\n ------------------------ paqaVerifyDeviceInfoLatency\n"); for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */ { pdi = Pa_GetDeviceInfo( id ); printf("Using device #%d: '%s' (%s)\n", id, pdi->name, Pa_GetHostApiInfo(pdi->hostApi)->name); if( pdi->maxOutputChannels > 0 ) { printf(" Output defaultLowOutputLatency = %f seconds\n", pdi->defaultLowOutputLatency); printf(" Output defaultHighOutputLatency = %f seconds\n", pdi->defaultHighOutputLatency); QA_ASSERT_TRUE( "defaultLowOutputLatency should be > 0", (pdi->defaultLowOutputLatency > 0.0) ); QA_ASSERT_TRUE( "defaultHighOutputLatency should be > 0", (pdi->defaultHighOutputLatency > 0.0) ); QA_ASSERT_TRUE( "defaultHighOutputLatency should be >= Low", (pdi->defaultHighOutputLatency >= pdi->defaultLowOutputLatency) ); } if( pdi->maxInputChannels > 0 ) { printf(" Input defaultLowInputLatency = %f seconds\n", pdi->defaultLowInputLatency); printf(" Input defaultHighInputLatency = %f seconds\n", pdi->defaultHighInputLatency); QA_ASSERT_TRUE( "defaultLowInputLatency should be > 0", (pdi->defaultLowInputLatency > 0.0) ); QA_ASSERT_TRUE( "defaultHighInputLatency should be > 0", (pdi->defaultHighInputLatency > 0.0) ); QA_ASSERT_TRUE( "defaultHighInputLatency should be >= Low", (pdi->defaultHighInputLatency >= pdi->defaultLowInputLatency) ); } } return 0; error: return -1; }
static int paqaVerifySuggestedLatency( void ) { PaDeviceIndex id; int result = 0; const PaDeviceInfo *pdi; int numDevices = Pa_GetDeviceCount(); printf("\n ------------------------ paqaVerifySuggestedLatency\n"); for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */ { pdi = Pa_GetDeviceInfo( id ); printf("\nUsing device #%d: '%s' (%s)\n", id, pdi->name, Pa_GetHostApiInfo(pdi->hostApi)->name); if( pdi->maxOutputChannels > 0 ) { if( paqaCheckMultipleSuggested( id, 0 ) < 0 ) { printf("OUTPUT CHECK FAILED !!! #%d: '%s'\n", id, pdi->name); result -= 1; } } if( pdi->maxInputChannels > 0 ) { if( paqaCheckMultipleSuggested( id, 1 ) < 0 ) { printf("INPUT CHECK FAILED !!! #%d: '%s'\n", id, pdi->name); result -= 1; } } } return result; }
void GetAudioInfo() { PaHostApiIndex ApiCount = Pa_GetHostApiCount(); Log::Logf("AUDIO: The default API is %d\n", Pa_GetDefaultHostApi()); for (PaHostApiIndex i = 0; i < ApiCount; i++) { const PaHostApiInfo* Index = Pa_GetHostApiInfo(i); Log::Logf("(%d) %s: %d (%d)\n", i, Index->name, Index->defaultOutputDevice, Index->type); #ifdef WIN32 if (Index->type == paWASAPI) DefaultWasapiDevice = Index->defaultOutputDevice; else if (Index->type == paDirectSound) DefaultDSDevice = Index->defaultOutputDevice; #endif } Log::Logf("\nAUDIO: The audio devices are\n"); PaDeviceIndex DevCount = Pa_GetDeviceCount(); for (PaDeviceIndex i = 0; i < DevCount; i++) { const PaDeviceInfo *Info = Pa_GetDeviceInfo(i); Log::Logf("(%d): %s\n", i, Info->name); Log::Logf("\thighLat: %f, lowLat: %f\n", Info->defaultHighOutputLatency, Info->defaultLowOutputLatency); Log::Logf("\tsampleRate: %f, hostApi: %d\n", Info->defaultSampleRate, Info->hostApi); Log::Logf("\tmaxchannels: %d\n", Info->maxOutputChannels); } }
/// Gets a NEW list of devices by terminating and restarting portaudio /// Assumes that DeviceManager is only used on the main thread. void DeviceManager::Rescan() { // get rid of the previous scan info this->mInputDeviceSourceMaps.clear(); this->mOutputDeviceSourceMaps.clear(); // if we are doing a second scan then restart portaudio to get NEW devices if (m_inited) { // check to see if there is a stream open - can happen if monitoring, // but otherwise Rescan() should not be available to the user. if (gAudioIO) { if (gAudioIO->IsMonitoring()) { gAudioIO->StopStream(); while (gAudioIO->IsBusy()) wxMilliSleep(100); } } // restart portaudio - this updates the device list // FIXME: TRAP_ERR restarting PortAudio Pa_Terminate(); Pa_Initialize(); } // FIXME: TRAP_ERR PaErrorCode not handled in ReScan() int nDevices = Pa_GetDeviceCount(); //The heirarchy for devices is Host/device/source. //Some newer systems aggregate this. //So we need to call port mixer for every device to get the sources for (int i = 0; i < nDevices; i++) { const PaDeviceInfo *info = Pa_GetDeviceInfo(i); if (info->maxOutputChannels > 0) { AddSources(i, info->defaultSampleRate, &mOutputDeviceSourceMaps, 0); } if (info->maxInputChannels > 0) { #ifdef __WXMSW__ #if !defined(EXPERIMENTAL_FULL_WASAPI) if (Pa_GetHostApiInfo(info->hostApi)->type != paWASAPI || PaWasapi_IsLoopback(i) > 0) #endif #endif AddSources(i, info->defaultSampleRate, &mInputDeviceSourceMaps, 1); } } // If this was not an initial scan update each device toolbar. // Hosts may have disappeared or appeared so a complete repopulate is needed. if (m_inited) { DeviceToolBar *dt; for (size_t i = 0; i < gAudacityProjects.size(); i++) { dt = gAudacityProjects[i]->GetDeviceToolBar(); dt->RefillCombos(); } } m_inited = true; mRescanTime = std::chrono::steady_clock::now(); }
/** * Sets up the input device with name given by the string * passed in as a parameter * @param in_pars Poiner to a PaStreamParameters struct that will be * modified and setup properly * @param device String with the desired device name * @param format the sample format for the input device to use */ void setupInputParametersWithDeviceName( PaStreamParameters *in_pars, const char *device, PaSampleFormat format) { int i; int device_found = false; for (i = 0; i < Pa_GetDeviceCount(); i++) { if(strcmp(Pa_GetDeviceInfo(i)->name, device) == 0) { in_pars->device = i; printf("Using %s\n", device); device_found = true; break; } } /* If device isn't found, use the default device */ if (!device_found) { printf("Requested device not found. Using default\n"); in_pars->device = Pa_GetDefaultInputDevice(); } if (in_pars->device == paNoDevice) fatal_terminate("No default input device"); in_pars->channelCount = in_pars->sampleFormat = format; in_pars->suggestedLatency = Pa_GetDeviceInfo(in_pars->device)->maxInputChannels; Pa_GetDeviceInfo(in_pars->device)->defaultLowInputLatency; in_pars->hostApiSpecificStreamInfo = NULL; }
JNIEXPORT jobject JNICALL Java_org_jpab_PortAudio_getDevicesAsBuffer(JNIEnv *env, jclass paClass) { Device * device; const PaDeviceInfo * device_info; const UINT8 count = Pa_GetDeviceCount(); UINT16 index, size = DEVICE_SIZE * count, offset = 0, temp; char * buffer = (char *)malloc(size); for (index = 0; index < count; index ++) { device_info = Pa_GetDeviceInfo(index); device = (Device *) (buffer + offset); device->default_high_input_latency = device_info->defaultHighInputLatency; device->default_high_output_latency = device_info->defaultHighOutputLatency; device->default_low_input_latency = device_info->defaultLowInputLatency; device->default_low_output_latency = device_info->defaultLowOutputLatency; device->default_sample_rate = device_info->defaultSampleRate; device->index = index; device->host_api = device_info->hostApi; device->max_input_channels = device_info->maxInputChannels; device->max_output_channels = device_info->maxOutputChannels; temp = strlen(device_info->name); device->name_length = temp; size += temp; buffer = (char *) realloc(buffer, size); offset += DEVICE_SIZE; memcpy(buffer + offset, device_info->name, temp); offset += temp; } return env->NewDirectByteBuffer(buffer, (jint) size); }
void CPaCommon::Enumerate(vector < string > &choices, vector < string > &descriptions) { vector < string > tmp; names.clear(); descriptions.clear(); names.push_back(""); /* default device */ descriptions.push_back(""); int numDevices = Pa_GetDeviceCount(); if (numDevices < 0) throw string("PortAudio error: ") + Pa_GetErrorText(numDevices); PaHostApiIndex nApis = Pa_GetHostApiCount(); for (int i = 0; i < numDevices; i++) { const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(i); if (( is_capture && deviceInfo->maxInputChannels > 1) || ( (!is_capture) && deviceInfo->maxOutputChannels > 1)) { string api=""; if (nApis>1) { const PaHostApiInfo* info = Pa_GetHostApiInfo(deviceInfo->hostApi); if (info) api = string(info->name)+":"; } names.push_back(api+deviceInfo->name); devices.push_back(i); } } choices = names; }
/******************************************************************* * Try each output device, through its full range of capabilities. */ static void TestDevices( int mode ) { int id, jc, i; int maxChannels; const PaDeviceInfo *pdi; static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, 44100.0, 48000.0, 88200.0, 96000.0, -1.0 }; /* Negative terminated list. */ int numDevices = Pa_GetDeviceCount(); for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */ { pdi = Pa_GetDeviceInfo( id ); /* Try 1 to maxChannels on each device. */ maxChannels = (( mode == MODE_INPUT ) ? pdi->maxInputChannels : pdi->maxOutputChannels); for( jc=1; jc<=maxChannels; jc++ ) { printf("Name = %s\n", pdi->name ); /* Try each standard sample rate. */ for( i=0; standardSampleRates[i] > 0; i++ ) { TestFormats( mode, (PaDeviceIndex)id, standardSampleRates[i], jc ); } } } }
/* * Try to intelligently fetch a default audio input device */ static PaDeviceIndex GetDefaultInputDevice() { int i, n; PaDeviceIndex def; const PaDeviceInfo *deviceInfo; n = Pa_GetDeviceCount(); if (n < 0) { return paNoDevice; } /* Try default input */ if ((def = Pa_GetDefaultInputDevice()) != paNoDevice) { return def; } /* No luck, iterate and check for API specific input device */ for (i = 0; i < n; i++) { deviceInfo = Pa_GetDeviceInfo(i); if (i == Pa_GetHostApiInfo(deviceInfo->hostApi)->defaultInputDevice) { return i; } } /* No device :( */ return paNoDevice; }
void AudioPortAudioSetupUtil::updateDevices() { PaError err = Pa_Initialize(); if( err != paNoError ) { printf( "Couldn't initialize PortAudio: %s\n", Pa_GetErrorText( err ) ); return; } // get active backend const QString& backend = m_backendModel.currentText(); int hostApi = 0; const PaHostApiInfo * hi; for( int i = 0; i < Pa_GetHostApiCount(); ++i ) { hi = Pa_GetHostApiInfo( i ); if( backend == hi->name ) { hostApi = i; break; } } // get devices for selected backend m_deviceModel.clear(); const PaDeviceInfo * di; for( int i = 0; i < Pa_GetDeviceCount(); ++i ) { di = Pa_GetDeviceInfo( i ); if( di->hostApi == hostApi ) { m_deviceModel.addItem( di->name ); } } Pa_Terminate(); }
/* scanning for devices */ void pa_getdevs(char *indevlist, int *nindevs, char *outdevlist, int *noutdevs, int *canmulti, int maxndev, int devdescsize) { int i, nin = 0, nout = 0, ndev; *canmulti = 1; /* one dev each for input and output */ pa_init(); ndev = Pa_GetDeviceCount(); for (i = 0; i < ndev; i++) { const PaDeviceInfo *pdi = Pa_GetDeviceInfo(i); if (pdi->maxInputChannels > 0 && nin < maxndev) { sprintf(indevlist + nin * devdescsize, "(%d)%s", pdi->hostApi,pdi->name); /* strcpy(indevlist + nin * devdescsize, pdi->name); */ nin++; } if (pdi->maxOutputChannels > 0 && nout < maxndev) { sprintf(outdevlist + nout * devdescsize, "(%d)%s", pdi->hostApi,pdi->name); /* strcpy(outdevlist + nout * devdescsize, pdi->name); */ nout++; } } *nindevs = nin; *noutdevs = nout; }
static int do_portaudio(int argc, char *argv[]) { PaError err; PaDeviceIndex idx; err = Pa_Initialize(); do_pa_error(err,"init"); if(!f_log) usage(2,stderr); if (argc > 1) usage(2,stderr); idx = Pa_GetDeviceCount(); if(!idx) { fprintf(stderr,"No devices available!\n"); exit(1); } else if (idx < 0) do_pa_error(idx,"Device enum"); while(idx-- > 0) { const struct PaDeviceInfo *dev = Pa_GetDeviceInfo(idx); if(argc) { if (!strcmp(dev->name,argv[0])) do_pa_run(idx, dev->defaultLowInputLatency); } else printf("%s (%f)\n",dev->name, dev->defaultSampleRate); } if (argc) { fprintf(stderr,"Device '%s' not found.\n",argv[0]); exit(1); } exit(0); /* NOTREACHED */ }
/* * The class is the sink for the data generated. * It will send the data to the soundcard */ paWriter::paWriter (int32_t cardRate, uint8_t Latency) { int32_t i; CardRate = cardRate; this -> Latency = Latency; this -> Latency = LOWLATENCY; _O_Buffer = new RingBuffer<float>(4 * 16384); portAudio = false; writerRunning = false; if (Pa_Initialize () != paNoError) { fprintf (stderr, "Initializing Pa for output failed\n"); return; } portAudio = true; qDebug ("Hostapis: %d\n", Pa_GetHostApiCount ()); for (i = 0; i < Pa_GetHostApiCount (); i ++) qDebug ("Api %d is %s\n", i, Pa_GetHostApiInfo (i) -> name); numofDevices = Pa_GetDeviceCount (); ostream = NULL; }
/** * Setups the input parameters to use the input device * specified by the given device number * @param in_pars input parameters object to modify and setup * @param device_num the device number of the device to use * @param format the sample format for the input device to use */ void setupInputParametersWithDeviceNumber( PaStreamParameters *in_pars, int device_num, PaSampleFormat format) { /* Ensure device number is valid */ bool device_found = false; if (0 <= device_num && device_num < Pa_GetDeviceCount()) { device_found = true; in_pars->device = device_num; } /* If device isn't found, use the default device */ if (!device_found) { printf("Requested device (%d) not found. Using default\n", device_num ); in_pars->device = Pa_GetDefaultInputDevice(); } if (in_pars->device == paNoDevice) fatal_terminate("No default input device"); in_pars->channelCount = Pa_GetDeviceInfo(in_pars->device)->maxInputChannels; in_pars->sampleFormat = format; in_pars->suggestedLatency = Pa_GetDeviceInfo(in_pars->device)->defaultLowInputLatency; in_pars->hostApiSpecificStreamInfo = NULL; }
void PortAudioSound::ListDevices(){ const PaDeviceInfo *deviceInfo; int numDevices = Pa_GetDeviceCount(); for (int i = 0; i < numDevices; i++){ CString desc = L""; deviceInfo = Pa_GetDeviceInfo(i); PaStreamParameters inputParameters; inputParameters.device = i; inputParameters.channelCount = 1; inputParameters.sampleFormat = paInt16; inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultHighInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; int err = Pa_IsFormatSupported(&inputParameters, NULL, sampleRate); CString str; if (err == 0) str = ""; else str = L"not "; desc.Format(L"%d - %s by %s - desired format is %ssupported\n", i, CString(deviceInfo->name), CString((Pa_GetHostApiInfo(deviceInfo->hostApi)->name)),str); logFile.WriteString(desc); } }
static int get_dev_by_name(char *name, int in) { int i; int numDevices; const PaDeviceInfo *pdi; numDevices = Pa_GetDeviceCount(); if (numDevices < 0) { switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices); return -2; } for (i = 0; i < numDevices; i++) { int match = 0; pdi = Pa_GetDeviceInfo(i); if (zstr(name)) { match = 1; } else if (pdi && pdi->name && strstr(pdi->name, name)) { match = 1; } if (match) { if (in && pdi->maxInputChannels) { return i; } else if (!in && pdi->maxOutputChannels) { return i; } } } return -1; }
int PortAudioOutput::internalSoundCardID( int settingsID ) { if ( settingsID < 0 ) settingsID = 0; int firstCardFound = -1; int card = 0; int const N = Pa_GetDeviceCount(); for (int i = 0; i < N; i++) { const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo( i ); if ( deviceInfo->maxOutputChannels > 0 ) { if ( firstCardFound < 0 ) firstCardFound = card; if ( card++ == settingsID ) return i; } } return Pa_GetDefaultOutputDevice(); // return firstCardFound; }
void list_devices(void) { PaError err; int i; if ((err = Pa_Initialize()) != paNoError) { LOG_WARN("error initialising port audio: %s", Pa_GetErrorText(err)); return; } printf("Output devices:\n"); #ifndef PA18API for (i = 0; i < Pa_GetDeviceCount(); ++i) { if (Pa_GetDeviceInfo(i)->maxOutputChannels) { printf(" %i - %s [%s]\n", i, Pa_GetDeviceInfo(i)->name, Pa_GetHostApiInfo(Pa_GetDeviceInfo(i)->hostApi)->name); } #else for (i = 0; i < Pa_CountDevices(); ++i) { printf(" %i - %s\n", i, Pa_GetDeviceInfo(i)->name); #endif } printf("\n"); if ((err = Pa_Terminate()) != paNoError) { LOG_WARN("error closing port audio: %s", Pa_GetErrorText(err)); } } void set_volume(unsigned left, unsigned right) { LOG_DEBUG("setting internal gain left: %u right: %u", left, right); LOCK; output.gainL = left; output.gainR = right; UNLOCK; }
audioSink::audioSink (int16_t latency, QComboBox *s, RingBuffer<int16_t> *b): audioBase (b) { int32_t i; this -> latency = latency; this -> streamSelector = s; this -> CardRate = 48000; this -> latency = latency; _O_Buffer = new RingBuffer<float>(2 * 32768); portAudio = false; writerRunning = false; if (Pa_Initialize () != paNoError) { fprintf (stderr, "Initializing Pa for output failed\n"); return; } portAudio = true; qDebug ("Hostapis: %d\n", Pa_GetHostApiCount ()); for (i = 0; i < Pa_GetHostApiCount (); i ++) qDebug ("Api %d is %s\n", i, Pa_GetHostApiInfo (i) -> name); numofDevices = Pa_GetDeviceCount (); outTable = new int16_t [numofDevices + 1]; for (i = 0; i < numofDevices; i ++) outTable [i] = -1; ostream = NULL; setupChannels (streamSelector); connect (streamSelector, SIGNAL (activated (int)), this, SLOT (set_streamSelector (int))); streamSelector -> show (); selectDefaultDevice (); }
int show_devices(void) { PaDeviceIndex numDevices,p; const PaDeviceInfo *pdi; PaError err; int nOutputDevices = 0; Pa_Initialize(); numDevices = Pa_GetDeviceCount(); if( numDevices < 0 ) { printf("ERROR: Pa_CountDevices returned 0x%x\n", numDevices ); err = numDevices; return err; } //printf("Number of devices = %d\n", numDevices ); printf("Device\tInput\tOutput\tName\n"); for( p=0; p<numDevices; p++ ) { pdi = Pa_GetDeviceInfo( p ); nOutputDevices++; if( p == Pa_GetDefaultOutputDevice() ) printf("*"); else printf(" "); printf("%d\t%d\t%d\t%s\n",p, pdi->maxInputChannels, pdi->maxOutputChannels, pdi->name); } Pa_Terminate(); return 0; }
static int find_device(struct mp_log *log, const char *name) { int found = paNoDevice; if (!name) return found; int help = strcmp(name, "help") == 0; int count = Pa_GetDeviceCount(); check_pa_ret(log, count); int index = to_int(name, -1); if (help) mp_info(log, "PortAudio devices:\n"); for (int n = 0; n < count; n++) { const PaDeviceInfo* info = Pa_GetDeviceInfo(n); if (help) { if (info->maxOutputChannels < 1) continue; mp_info(log, " %d '%s', %d channels, latency: %.2f " "ms, sample rate: %.0f\n", n, info->name, info->maxOutputChannels, info->defaultHighOutputLatency * 1000, info->defaultSampleRate); } if (strcmp(name, info->name) == 0 || n == index) { found = n; break; } } if (found == paNoDevice && !help) mp_warn(log, "Device '%s' not found!\n", name); return found; }
void AudioIO::openAudioStream() { int numInputChannels = 2; int numOutputChannels = echoAudio ? 2 : 0; int audioDeviceId = 0; PaStreamParameters outputParameters; PaStreamParameters inputParameters; PaError err; void *callbackUserData = (void *) this; const PaDeviceInfo *deviceInfo; int numDevices = Pa_GetDeviceCount(); if(audioDeviceName != NULL) { for(int i=0; i<numDevices; i++) { deviceInfo = Pa_GetDeviceInfo(i); if(strncmp(audioDeviceName, deviceInfo->name, strlen(audioDeviceName)) == 0) audioDeviceId = i; } } for(int i=0; i<numDevices; i++) { deviceInfo = Pa_GetDeviceInfo(i); printf("device %d%s: '%s', %d in, %d out\n", i, (i == audioDeviceId) ? " SELECTED" : "", deviceInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels); } bzero(&inputParameters, sizeof(inputParameters)); inputParameters.channelCount = numInputChannels; inputParameters.device = audioDeviceId; inputParameters.sampleFormat = paFloat32; if(echoAudio) { bzero(&outputParameters, sizeof(outputParameters)); outputParameters.channelCount = numOutputChannels; outputParameters.device = audioDeviceId; outputParameters.sampleFormat = paFloat32; } err = Pa_OpenStream( &paStream, &inputParameters, echoAudio ? &outputParameters : NULL, audioParameters.sampleRate, audioParameters.bufferSize, paNoFlag, AudioIO_portaudioCallback, callbackUserData ); if( err != paNoError ) { printf("failed to open audio stream (%s)\n", Pa_GetErrorText(err)); exit(0); } if(Pa_StartStream( paStream ) != paNoError ) { printf("failed to start stream\n"); exit(0); } }
int padevsub_(int *numdev, int *ndefin, int *ndefout, int nchin[], int nchout[]) { int i, devIdx; int numDevices; const PaDeviceInfo *pdi; PaError err; // PaHostApiInfo *hostapi; Pa_Initialize(); /* n = Pa_GetHostApiCount(); printf("HostAPI Type #Devices\n"); for(i = 0; i < n; i++) { hostapi = Pa_GetHostApiInfo(i); printf(" %3d %2d %3d %s\n",i,hostapi->type, hostapi->deviceCount,hostapi->name); } */ numDevices = Pa_GetDeviceCount(); *numdev = numDevices; if( numDevices < 0 ) { err = numDevices; Pa_Terminate(); return err; } if ((devIdx = Pa_GetDefaultInputDevice()) > 0) { *ndefin = devIdx; } else { *ndefin = 0; } if ((devIdx = Pa_GetDefaultOutputDevice()) > 0) { *ndefout = devIdx; } else { *ndefout = 0; } printf("\nAudio Input Output Device Name\n"); printf("Device Channels Channels\n"); printf("------------------------------------------------------------------\n"); for( i=0; i < numDevices; i++ ) { pdi = Pa_GetDeviceInfo(i); // if(i == Pa_GetDefaultInputDevice()) *ndefin = i; // if(i == Pa_GetDefaultOutputDevice()) *ndefout = i; nchin[i]=pdi->maxInputChannels; nchout[i]=pdi->maxOutputChannels; printf(" %2d %2d %2d %s\n",i,nchin[i],nchout[i],pdi->name); } Pa_Terminate(); return 0; }
static int pa_devicecount(lua_State *L) { int narg = lua_gettop(L); if(narg != 0) luaL_error(L, "invalid arguments: no argument expected"); lua_pushnumber(L, Pa_GetDeviceCount()); return 1; }
void MFSound_InitModulePlatformSpecific(int *pSoundDataSize, int *pVoiceDataSize) { MFCALLSTACK; // we need to return the size of the internal structures so the platform independant // code can make the correct allocations.. *pSoundDataSize = sizeof(MFSoundDataInternal); MFDebug_Log(2, "Initialising PortAudio driver."); // init portaudio Pa_Initialize(); // choose the output device PaDeviceIndex device = Pa_GetDefaultOutputDevice(); // HACK: try and find an ALSA device (default OSS sucks) PaHostApiIndex alsaAPI = Pa_HostApiTypeIdToHostApiIndex(paALSA); if(alsaAPI >= 0) { int numDevices = Pa_GetDeviceCount(); for(int a=0; a<numDevices; ++a) { pDeviceInfo = Pa_GetDeviceInfo(a); if(pDeviceInfo->hostApi == alsaAPI) { device = a; break; } } } pDeviceInfo = Pa_GetDeviceInfo(device); pHostAPIInfo = Pa_GetHostApiInfo(pDeviceInfo->hostApi); MFDebug_Log(2, MFStr("PortAudio output: %s", pDeviceInfo->name)); MFDebug_Log(2, MFStr("PortAudio host: %s", pHostAPIInfo->name)); MFDebug_Log(2, MFStr("Sample rate: %g", (float)pDeviceInfo->defaultSampleRate)); MFDebug_Log(2, MFStr("In/Out channels: %d/%d", pDeviceInfo->maxInputChannels, pDeviceInfo->maxOutputChannels)); MFDebug_Log(2, MFStr("Input latency: %g-%g", (float)pDeviceInfo->defaultLowInputLatency, (float)pDeviceInfo->defaultHighInputLatency)); MFDebug_Log(2, MFStr("Output latency: %g-%g", (float)pDeviceInfo->defaultLowOutputLatency, (float)pDeviceInfo->defaultHighOutputLatency)); // create a very low latency audio output stream PaStreamParameters params; params.device = Pa_GetDefaultOutputDevice(); params.channelCount = 2; params.sampleFormat = paInt16; params.suggestedLatency = 0.0167; params.hostApiSpecificStreamInfo = NULL; PaError error = Pa_OpenStream(&pPAStream, NULL, ¶ms, pDeviceInfo->defaultSampleRate, paFramesPerBufferUnspecified, paPrimeOutputBuffersUsingStreamCallback, MFSound_MixCallback, NULL); if(error != paNoError) MFDebug_Log(2, MFStr("Error: %s", Pa_GetErrorText(error))); else Pa_StartStream(pPAStream); }
void print_deviceinfo() { int i; printf("\tdevice_id list (Pa_GetDeviceInfo() result)\n"); for (i = 0; i < Pa_GetDeviceCount(); i++) { const PaDeviceInfo *devinfo = Pa_GetDeviceInfo(i); printf("\t\t%d: %s\n", i, devinfo->name); } }
JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDeviceCount( JNIEnv *env, jclass clazz) { PaDeviceIndex deviceCount = Pa_GetDeviceCount(); if (deviceCount < 0) PortAudio_throwException(env, deviceCount); return deviceCount; }