int main(void) { PaStreamParameters inputParameters, outputParameters; PaStream *stream; PaError err; err = Pa_Initialize(); if( err != paNoError ) goto error; inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ if (inputParameters.device == paNoDevice) { fprintf(stderr,"Error: No default input device.\n"); goto error; } inputParameters.channelCount = 2; /* stereo input */ inputParameters.sampleFormat = PA_SAMPLE_TYPE; inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ if (outputParameters.device == paNoDevice) { fprintf(stderr,"Error: No default output device.\n"); goto error; } outputParameters.channelCount = 2; /* stereo output */ outputParameters.sampleFormat = PA_SAMPLE_TYPE; outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; outputParameters.hostApiSpecificStreamInfo = NULL; err = Pa_OpenStream( &stream, &inputParameters, &outputParameters, SAMPLE_RATE, FRAMES_PER_BUFFER, 0, /* paClipOff, */ /* we won't output out of range samples so don't bother clipping them */ fuzzCallback, NULL ); if( err != paNoError ) goto error; err = Pa_StartStream( stream ); if( err != paNoError ) goto error; printf("Hit ENTER to stop program.\n"); getchar(); err = Pa_CloseStream( stream ); if( err != paNoError ) goto error; printf("Finished. gNumNoInputs = %d\n", gNumNoInputs ); Pa_Terminate(); return 0; 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 ) ); return -1; }
bool initializeAudio() { PaError err=Pa_Initialize(); #ifdef MAKETEST printf("Devs: %d\ndefInp: %d\n", Pa_GetDeviceCount(), Pa_GetDefaultInputDevice()); const PaDeviceInfo*di=Pa_GetDeviceInfo(Pa_GetDefaultInputDevice()); printf("defNfo: %s\ndefHostApi: %d\n", di->name, di->hostApi); #endif pthread_spin_init(&recBufferLock, 0); recBuffer=0; audioStream=0; return (err==paNoError); }
bool AudioStream::setInputDevice(int device, AudioSample::eChannel channel, eLatency latency) { if (device < 0) device = Pa_GetDefaultInputDevice(); _inputDevice = device; return _setDevice(device, channel, latency, _inputParameter, INPUT_STREAM, _inputDeviceInfo); }
std::pair<std::string, std::string> default_device_names() { const PaDeviceIndex default_input = Pa_GetDefaultInputDevice(); const PaDeviceIndex default_output = Pa_GetDefaultOutputDevice(); std::cout << default_input << " " << default_output; return std::make_pair(device_name(default_input), device_name(default_output)); }
bool AudioCapturePortAudio::initialize() { PaError err; PaStreamParameters inputParameters; err = Pa_Initialize(); if( err != paNoError ) return false; QSettings settings; QVariant var = settings.value(SETTINGS_AUDIO_INPUT_DEVICE); if (var.isValid() == true) inputParameters.device = QString(var.toString()).toInt(); else inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ if (inputParameters.device == paNoDevice) { qWarning("Error: No default input device found.\n"); Pa_Terminate(); return false; } inputParameters.channelCount = m_channels; inputParameters.sampleFormat = paInt16; inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; // ensure initialize() has not been called multiple times Q_ASSERT(stream == NULL); /* -- setup stream -- */ err = Pa_OpenStream( &stream, &inputParameters, NULL, m_sampleRate, paFramesPerBufferUnspecified, paClipOff, /* we won't output out of range samples so don't bother clipping them */ NULL, /* no callback, use blocking API */ NULL ); /* no callback, so no callback userData */ if( err != paNoError ) { qWarning("Cannot open audio input stream (%s)\n", Pa_GetErrorText(err)); Pa_Terminate(); return false; } /* -- start capture -- */ err = Pa_StartStream( stream ); if( err != paNoError ) { qWarning("Cannot start stream capture (%s)\n", Pa_GetErrorText(err)); Pa_CloseStream( stream ); stream = NULL; Pa_Terminate(); return false; } return true; }
int snd_open_stream() { faacEncConfigurationPtr pConfiguration; hEncoder = faacEncOpen(samplerate, channel, &nInputSamples, &nMaxOutputBytes); if(hEncoder == NULL) { printf("[ERROR] Failed to call faacEncOpen()\n"); return -1; } // (2.1) Get current encoding configuration pConfiguration = faacEncGetCurrentConfiguration(hEncoder); pConfiguration->inputFormat = FAAC_INPUT_16BIT; // (2.2) Set encoding configuration int nRet = faacEncSetConfiguration(hEncoder, pConfiguration); pbAACBuffer = new unsigned char [nMaxOutputBytes]; //////////////////////// char info_buf[256]; PaStreamParameters pa_params; PaError pa_err; pa_params.device = Pa_GetDefaultInputDevice(); /* default input device */ if (pa_params.device == paNoDevice) { fprintf(stderr,"Error: No default input device.\n"); return 1; } pa_params.channelCount = channel; pa_params.sampleFormat = paInt16; pa_params.suggestedLatency = Pa_GetDeviceInfo(pa_params.device)->defaultHighInputLatency; pa_params.hostApiSpecificStreamInfo = NULL; pa_err = Pa_IsFormatSupported(&pa_params, NULL, samplerate); if(pa_err != paFormatIsSupported) { printf("Samplerate not supported: %dHz\n", samplerate); return 1; } pa_err = Pa_OpenStream(&stream, &pa_params, NULL, samplerate, PA_FRAMES, paNoFlag, snd_callback, NULL); if(pa_err != paNoError) { printf("error opening sound device: \n%s\n", Pa_GetErrorText(pa_err)); return 1; } Pa_StartStream(stream); return 0; }
int AudioStreamManager::StreamAudio(ISoundDelegate* delegate) { PaStreamParameters inputParameters, outputParameters; PaError err; soundDelegate = delegate; err = Pa_Initialize(); if (err != paNoError) goto error; inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ if (inputParameters.device == paNoDevice) { fprintf(stderr, "Error: No default input device.\n"); goto error; } inputParameters.channelCount = 2; /* stereo input */ inputParameters.sampleFormat = PA_SAMPLE_TYPE; inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ if (outputParameters.device == paNoDevice) { fprintf(stderr, "Error: No default output device.\n"); goto error; } outputParameters.channelCount = 2; /* stereo output */ outputParameters.sampleFormat = PA_SAMPLE_TYPE; outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency; outputParameters.hostApiSpecificStreamInfo = NULL; err = Pa_OpenStream( &audioStream, &inputParameters, &outputParameters, SAMPLE_RATE, FRAMES_PER_BUFFER, 0, /* paClipOff, */ /* we won't output out of range samples so don't bother clipping them */ readStreamCallback, NULL); if (err != paNoError) goto error; delegate->willBeginPlay(); err = Pa_StartStream(audioStream); if (err != paNoError) goto error; return 0; 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)); delegate->didEndPlay(); return -1; }
void GuitarSori::init( const int mFramesPerBuffer, const int mNumChannels, const int mSampleSize, PaSampleFormat mSampleFormat, const double mSampleRate) { int numBytes, numBytesConverted; framesPerBuffer = mFramesPerBuffer; numChannels = mNumChannels; sampleSize = mSampleSize; sampleFormat = mSampleFormat; sampleRate = mSampleRate; numBytes = mFramesPerBuffer * mNumChannels * mSampleSize; numBytesConverted = mFramesPerBuffer * mNumChannels * 8; freeBuffers(); sampleBlock = (char *)malloc(numBytes); sampleBlockConverted = (double *)malloc(numBytesConverted); sampleBlockFFT = (double *)malloc(numBytesConverted / 2); if ( !isBuffersReady() ) { printf("Cannot allocate sample block\n"); return; } memset(sampleBlock, 0x00, numBytes); memset(sampleBlockConverted, 0x00, numBytesConverted); memset(sampleBlockFFT, 0x00, numBytesConverted / 2); err = Pa_Initialize(); printf("──────────────────────────────\n"); inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ inputParameters.device = 1; printf("Input device # %d. : %s\n", inputParameters.device, Pa_GetDeviceInfo(inputParameters.device)->name); printf("Input LL: %g s\n", Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency); printf("Input HL: %g s\n", Pa_GetDeviceInfo(inputParameters.device)->defaultHighInputLatency); printf("Input HL: %g s\n", Pa_GetDeviceInfo(inputParameters.device)->defaultHighInputLatency); printf("Input Channel(MAX.) : %d ", Pa_GetDeviceInfo(inputParameters.device)->maxInputChannels); inputParameters.channelCount = numChannels; inputParameters.sampleFormat = sampleFormat; inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultHighInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ printf("Output device # %d.\n", outputParameters.device); printf("Output LL: %g s\n", Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency); printf("Output HL: %g s\n", Pa_GetDeviceInfo(outputParameters.device)->defaultHighOutputLatency); outputParameters.channelCount = numChannels; outputParameters.sampleFormat = sampleFormat; outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultHighOutputLatency; outputParameters.hostApiSpecificStreamInfo = NULL; err = Pa_OpenStream(&stream, &inputParameters, &outputParameters, sampleRate, framesPerBuffer, paClipOff, NULL, NULL); err = Pa_StartStream(stream); }
static int quisk_pa_name2index (struct sound_dev * dev, int is_capture) { // Based on the device name, set the portaudio index, or -1. // Return non-zero for error. Not a portaudio device is not an error. const PaDeviceInfo * pInfo; int i, count; if (strncmp (dev->name, "portaudio", 9)) { dev->portaudio_index = -1; // Name does not start with "portaudio" return 0; // Not a portaudio device, not an error } if ( ! strcmp (dev->name, "portaudiodefault")) { if (is_capture) // Fill in the default device index dev->portaudio_index = Pa_GetDefaultInputDevice(); else dev->portaudio_index = Pa_GetDefaultOutputDevice(); strncpy (dev->msg1, "Using default portaudio device", QUISK_SC_SIZE); return 0; } if ( ! strncmp (dev->name, "portaudio#", 10)) { // Integer index follows "#" dev->portaudio_index = i = atoi(dev->name + 10); pInfo = Pa_GetDeviceInfo(i); if (pInfo) { snprintf (dev->msg1, QUISK_SC_SIZE, "PortAudio device %s", pInfo->name); return 0; } else { snprintf (quisk_sound_state.err_msg, QUISK_SC_SIZE, "Can not find portaudio device number %s", dev->name + 10); } return 1; } if ( ! strncmp (dev->name, "portaudio:", 10)) { dev->portaudio_index = -1; count = Pa_GetDeviceCount(); // Search for string in device name for (i = 0; i < count; i++) { pInfo = Pa_GetDeviceInfo(i); if (pInfo && strstr(pInfo->name, dev->name + 10)) { dev->portaudio_index = i; snprintf (dev->msg1, QUISK_SC_SIZE, "PortAudio device %s", pInfo->name); break; } } if (dev->portaudio_index == -1) { // Error snprintf (quisk_sound_state.err_msg, QUISK_SC_SIZE, "Can not find portaudio device named %s", dev->name + 10); return 1; } return 0; } snprintf (quisk_sound_state.err_msg, QUISK_SC_SIZE, "Did not recognize portaudio device %s", dev->name); return 1; }
PaDeviceIndex SoundcardDialog::getInputSource() { int index = ui->inputComboBox->currentIndex(); if (index == -1) { // no item was selected, so we return the // default input device return Pa_GetDefaultInputDevice(); } else { bool ok; PaDeviceIndex idx = ui->inputComboBox->itemData(index).toInt(&ok); if (!ok) { // conversion to int not succesfull // return the default input device .. :( return Pa_GetDefaultInputDevice(); } return idx; } }
static PaDeviceIndex FindInputOnlyDevice(void) { PaDeviceIndex result = Pa_GetDefaultInputDevice(); if( result != paNoDevice && Pa_GetDeviceInfo(result)->maxOutputChannels == 0 ) return result; for( result = 0; result < Pa_GetDeviceCount(); ++result ) { if( Pa_GetDeviceInfo(result)->maxOutputChannels == 0 ) return result; } return paNoDevice; }
void PortAudioHelper::loadDevices() { DEVICE_COUNT = Pa_GetDeviceCount(); DEFAULT_INPUT_DEVICE = Pa_GetDefaultInputDevice(); DEFAULT_OUTPUT_DEVICE = Pa_GetDefaultOutputDevice(); for (PaDeviceIndex i=0; i<DEVICE_COUNT; i++) { AudioDeviceInfo deviceInfo; deviceInfo.deviceInfo = *Pa_GetDeviceInfo(i); deviceInfo.supportedSampleRates = getSupportedSampleRate(i); DEVICES.append(deviceInfo); } CURRENT_INPUT_DEVICE = loadFromSettings(keyDefaultInputDevice, DEFAULT_INPUT_DEVICE).toInt(); CURRENT_OUTPUT_DEVICE = loadFromSettings(keyDefaultOutputDevice, DEFAULT_OUTPUT_DEVICE).toInt(); }
int AudioRecorder::open(const char* file) { size_t s = strlen(file); char* filename = new char[s]; strncpy(filename, file, s); PaError err; file_ = new AudioFile(filename); if ((err = file_->open(AudioFile::Write))) { HANDLE_PA_ERROR(err); return err; } ring_buffer_ = new RingBuffer<SamplesType, 4>(chunk_size_); err = Pa_Initialize(); if(err != paNoError) { HANDLE_PA_ERROR(err); } input_params_.device = Pa_GetDefaultInputDevice(); if (input_params_.device == paNoDevice) { HANDLE_PA_ERROR(err); } input_params_.channelCount = 1; input_params_.sampleFormat = paFloat32; input_params_.suggestedLatency = Pa_GetDeviceInfo( input_params_.device )->defaultLowInputLatency; input_params_.hostApiSpecificStreamInfo = NULL; err = Pa_OpenStream( &stream_, &input_params_, NULL, file_->samplerate(), chunk_size_, paClipOff, audio_callback, this); if(err != paNoError) { HANDLE_PA_ERROR(err); } err = Pa_SetStreamFinishedCallback(stream_, &finished_callback); if(err != paNoError) { HANDLE_PA_ERROR(err); } return 0; }
QString DevicePortAudio::deviceInputDefaultName() { PaDeviceIndex DevIdx = Pa_GetDefaultInputDevice(); if( DevIdx == paNoDevice ) { return( QString() ); } const PaDeviceInfo *DevInf = Pa_GetDeviceInfo( DevIdx ); const PaHostApiInfo *HstInf = Pa_GetHostApiInfo( DevInf->hostApi ); return( QString( "%1: %2" ).arg( HstInf->name ).arg( DevInf->name ) ); }
bool PAudioStream::initInput() { if (_buffer->input == NULL) return (false); if ((_inputParam.device = Pa_GetDefaultInputDevice()) == paNoDevice) { qDebug() << "No default input device."; return (false); } _inputParam.channelCount = NUM_CHANNELS; _inputParam.sampleFormat = PA_SAMPLE_TYPE; _inputParam.suggestedLatency = (Pa_GetDeviceInfo(_inputParam.device))->defaultLowInputLatency; _inputParam.hostApiSpecificStreamInfo = NULL; return (true); }
AudioInput::AudioInput() : stream(0) { PaStreamParameters inputParameters; PaError err = paNoError; std::cout << "Initializing PortAudio\n"; err = Pa_Initialize(); if( err != paNoError ) return; std::cout << "Getting default audio input device\n"; inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ if (inputParameters.device == paNoDevice) { std::cerr << "Error: No default input device.\n"; return; } inputParameters.channelCount = 1; /* mono input */ inputParameters.sampleFormat = paInt16; inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; std::cout << "Opening stream\n"; /* Open audio stream. -------------------------------------------- */ err = Pa_OpenStream( &stream, &inputParameters, NULL, /* &outputParameters, */ SAMPLE_RATE, CHUNK_SIZE, paNoFlag, NULL, NULL); if (err != paNoError) { std::cerr << "Error opening stream: " << Pa_GetErrorText(err) << '\n'; return; } std::cout << "Audio device open\n"; if ((err = Pa_StartStream(stream)) != paNoError) { std::cerr << "Error starting stream: " << Pa_GetErrorText(err) << '\n'; } }
portaudio_manager_t(int p_sample_rate, int p_size) : sample_rate(p_sample_rate), size(p_size), input_stream_parameters(), input_stream(NULL) { // initialize portaudio to stream from the default audio device PaError pa_error; pa_error = Pa_Initialize(); if (pa_error != 0) { std::ostringstream ss; ss << "failure initializing portaudio " << pa_error; throw std::runtime_error(ss.str()); } input_stream_parameters.device = Pa_GetDefaultInputDevice(); if (input_stream_parameters.device == paNoDevice) { throw std::runtime_error("No device. Cannot continue."); } input_stream_parameters.channelCount = 1; input_stream_parameters.sampleFormat = paFloat32; input_stream_parameters.suggestedLatency = Pa_GetDeviceInfo(input_stream_parameters.device)->defaultHighInputLatency; input_stream_parameters.hostApiSpecificStreamInfo = NULL; std::cout << "Opening input " << Pa_GetDeviceInfo(input_stream_parameters.device)->name << "\n"; pa_error = Pa_OpenStream(&input_stream, &input_stream_parameters, NULL, sample_rate, size, paClipOff, // ? NULL, NULL); if (pa_error != 0) { std::ostringstream ss2; ss2 << "failure opening input stream " << pa_error; throw std::runtime_error(ss2.str()); } // start the input stream pa_error = Pa_StartStream(input_stream); if (pa_error != 0) { std::ostringstream ss3; ss3 << "failure starting input stream " << pa_error; throw std::runtime_error(ss3.str()); } }
void AudioManager::initInput() { if ((this->_inputParam.device = Pa_GetDefaultInputDevice()) == paNoDevice) { // std::cout << "ZIZI" << std::endl; this->errorAudio(); return ; } this->_inputParam.channelCount = 1; this->_inputParam.sampleFormat = PA_SAMPLE_TYPE; this->_inputParam.suggestedLatency = Pa_GetDeviceInfo(this->_inputParam.device)->defaultHighInputLatency; this->_inputParam.hostApiSpecificStreamInfo = NULL; // std::cout << "Input device # " << this->_inputParam.device << std::endl; // std::cout << "Input LowLatency : " << Pa_GetDeviceInfo(this->_inputParam.device)->defaultLowInputLatency << std::endl; // std::cout << "Input HighLatency : " << Pa_GetDeviceInfo(this->_inputParam.device)->defaultHighInputLatency << std::endl; }
static int pa_defaultinputdevice(lua_State *L) { int narg = lua_gettop(L); PaDeviceIndex dev; if(narg != 0) luaL_error(L, "invalid arguments: no argument expected"); dev = Pa_GetDefaultInputDevice(); if(dev == paNoDevice) return 0; else lua_pushnumber(L, dev+1); return 1; }
int audio_pa_run(audio_callback_fn_pt callback, double sample_rate, unsigned long chunk_size) { chunk = calloc(chunk_size, sizeof *chunk); if(chunk == NULL) MEMFAIL(); PaError err = Pa_Initialize(); if(err != paNoError) FAIL("Could not initialize PortAudio\n"); PaStreamParameters inputParameters; inputParameters.device = Pa_GetDefaultInputDevice(); inputParameters.channelCount = NUM_CHANNELS; inputParameters.sampleFormat = PA_SAMPLE_TYPE; inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency ; inputParameters.hostApiSpecificStreamInfo = NULL; PaStream *stream = NULL; err = Pa_OpenStream(&stream, &inputParameters, 0, sample_rate, chunk_size, paClipOff, 0, 0); if(err != paNoError) FAIL("Could not open PortAudio input stream\n"); err = Pa_StartStream(stream); if(err != paNoError) FAIL("Could not open audio input stream\n"); /* printf("Gracefully terminated PortAudio\n"); */ int cb_err = 0; while(cb_err == 0){ err = Pa_ReadStream(stream, chunk, chunk_size ); if(err != paNoError) FAIL("Could not read audio chunk\n"); cb_err = callback(chunk); } err = Pa_Terminate(); if(err != paNoError) FAIL("Could not terminate PortAudio\n"); free(chunk); return 0; }
int SoundManager::initAudio(){ PaStreamParameters inputParameters; PaError err = paNoError; err = Pa_Initialize(); if( err != paNoError) { printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) ); return 1; } inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ if (inputParameters.device == paNoDevice) { fprintf(stderr,"Error: No default input device.\n"); return 1; } inputParameters.channelCount = 2; /* stereo input */ inputParameters.sampleFormat = PA_SAMPLE_TYPE; inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; err = Pa_OpenStream( &stream, &inputParameters, NULL, /* &outputParameters, */ SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff, /* we won't output out of range samples so don't bother clipping them */ &SoundManager::processCallback, data ); if( err != paNoError) { printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) ); return 1; } err = Pa_StartStream( stream ); if( err != paNoError) { printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) ); return 1; } printf("\n=== Working. Press Ctrl+C to quit ===\n"); fflush(stdout); return 0; }
bool PortAudioDriver::initPortAudio(int sampleRate, int bufferSize) { qCInfo(jtAudio) << "initializing portaudio..."; PaError error = Pa_Initialize(); if (error != paNoError){ qCCritical(jtAudio) << "ERROR initializing portaudio:" << Pa_GetErrorText(error); return false; } paStream = nullptr;// inputBuffer = outputBuffer = NULL; //check for invalid audio device index if(audioDeviceIndex < 0 || audioDeviceIndex >= Pa_GetDeviceCount()){ audioDeviceIndex = Pa_GetDefaultInputDevice(); if(audioDeviceIndex == paNoDevice){ audioDeviceIndex = Pa_GetDefaultOutputDevice(); } } ensureInputRangeIsValid(); ensureOutputRangeIsValid(); //set sample rate this->sampleRate = (sampleRate >= 44100 && sampleRate <= 192000) ? sampleRate : 44100; if(audioDeviceIndex != paNoDevice){//avoid query sample rates in a invalid device QList<int> validSampleRates = getValidSampleRates(audioDeviceIndex); if(this->sampleRate > validSampleRates.last()){ this->sampleRate = validSampleRates.last();//use the max supported sample rate } } this->bufferSize = bufferSize; if(audioDeviceIndex != paNoDevice){ QList<int> validBufferSizes = getValidBufferSizes(audioDeviceIndex); if(this->bufferSize < validBufferSizes.first()){ this->bufferSize = validBufferSizes.first();//use the minimum supported buffer size } if(this->bufferSize > validBufferSizes.last()){ this->bufferSize = validBufferSizes.last();//use the max supported buffer size } } return true; }
int padevsub_(int *numdev, int *ndefin, int *ndefout, int nchin[], int nchout[]) { int i; int numDevices; const PaDeviceInfo *pdi; PaError err; // PaHostApiInfo *hostapi; Pa_Initialize(); // numDevices = Pa_CountDevices(); numDevices = Pa_GetDeviceCount(); *numdev=numDevices; if( numDevices < 0 ) { err = numDevices; goto error; } printf("\nAudio Output Device Name\n"); printf("Device 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; if(nchout[i]>0) printf(" %2d %2d %s\n",i,nchout[i],pdi->name); } Pa_Terminate(); return 0; error: Pa_Terminate(); return err; }
//FULL int IOControl::startFull() { int err; this->_inputParam.device = Pa_GetDefaultInputDevice(); if (this->_inputParam.device == paNoDevice) { std::cout << "C'est ici" << std::endl; throw std::exception(); } this->_inputParam.channelCount = NUM_CHANNELS; this->_inputParam.sampleFormat = PA_TYPE; this->_inputParam.suggestedLatency = Pa_GetDeviceInfo(this->_inputParam.device)->defaultLowInputLatency; this->_inputParam.hostApiSpecificStreamInfo = NULL; this->_outputParam.device = Pa_GetDefaultOutputDevice(); if (this->_outputParam.device == paNoDevice) throw std::exception(); this->_outputParam.channelCount = NUM_CHANNELS; this->_outputParam.sampleFormat = PA_TYPE; this->_outputParam.suggestedLatency = Pa_GetDeviceInfo(this->_outputParam.device)->defaultLowOutputLatency; this->_outputParam.hostApiSpecificStreamInfo = NULL; err = Pa_OpenStream(&this->_stream, &this->_inputParam, &this->_outputParam, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff, IOCallback, this); if (err != paNoError) throw std::exception(); err = Pa_StartStream(this->_stream); if (err != paNoError) throw std::exception(); std::cout << "Running ..." << std::endl; return (1); }
inline static void session_init_devices(session_t session) { native_index_t count; list_t devices; count = Pa_GetDeviceCount(); devices = fa_list_empty(); for (size_t i = 0; i < count; ++i) { device_t device = new_device(session, i); if (device) { devices = fa_list_dcons(device, devices); } } session->devices = fa_list_dreverse(devices); session->def_input = new_device(session, Pa_GetDefaultInputDevice()); session->def_output = new_device(session, Pa_GetDefaultOutputDevice()); }
void DevicePortAudio::deviceInitialise() { // PaHostApiIndex HostApiCount = Pa_GetHostApiCount(); // PaHostApiIndex DefaultHostApi = Pa_GetDefaultHostApi(); #if defined( PORTAUDIO_SUPPORTED ) qDebug() << "DefInp:" << Pa_GetDefaultInputDevice() << "DefOut:" << Pa_GetDefaultOutputDevice(); PaDeviceIndex DevCnt = Pa_GetDeviceCount(); for( PaDeviceIndex DevIdx = 0 ; DevIdx < DevCnt ; DevIdx++ ) { const PaDeviceInfo *DevInf = Pa_GetDeviceInfo( DevIdx ); const PaHostApiInfo *HstInf = Pa_GetHostApiInfo( DevInf->hostApi ); qDebug() << HstInf->name << DevInf->name << DevInf->maxInputChannels << DevInf->maxOutputChannels; } #endif }
bool PaInstance::getInputDevice (PaStreamParameters& streamParams, const int numChannels) { PaDeviceIndex inputDevice = Pa_GetDefaultInputDevice(); if (inputDevice == paNoDevice) { std::cerr << "Error: no default input device.\n"; return false; } const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(inputDevice); const PaHostApiInfo *hostApiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi); std::cout << "Opening audio input device: " << hostApiInfo->name << " " << deviceInfo->name << "\n"; streamParams.device = inputDevice; streamParams.channelCount = numChannels; streamParams.sampleFormat = paFloat32; streamParams.suggestedLatency = deviceInfo->defaultLowOutputLatency; streamParams.hostApiSpecificStreamInfo = NULL; return true; }
AudioDevice::AudioDevice(bool useDefaultDevice ,std::string inputDeviceId, std::string outputDeviceId) { err = Pa_Initialize(); if( err != paNoError) std::cout<<"Couldn't initialize portaudio"<<std::endl; if(useDefaultDevice) { outputParameters.device = Pa_GetDefaultOutputDevice(); sampleRate = Pa_GetDeviceInfo(outputParameters.device)->defaultSampleRate; bufferSize = 32; inputParameters.device = Pa_GetDefaultInputDevice(); } else { for(auto device = 0; device < Pa_GetDeviceCount(); device++) { auto info = Pa_GetDeviceInfo(device); if(info->name == inputDeviceId) { outputParameters.device = device; } } } numInputs = Pa_GetDeviceInfo(inputParameters.device)->maxInputChannels; numOutputs = Pa_GetDeviceInfo(outputParameters.device)->maxOutputChannels; outputParameters.channelCount = numOutputs; outputParameters.sampleFormat = paNonInterleaved | paFloat32; /* 32 bit floating point output */ outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; outputParameters.hostApiSpecificStreamInfo = NULL; inputParameters.channelCount = numInputs; inputParameters.sampleFormat = paNonInterleaved | paFloat32; /* 32 bit floating point output */ inputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; }
void pa_listdevs(void) /* lifted from pa_devs.c in portaudio */ { int i,j; int numDevices; const PaDeviceInfo *pdi; PaError err; pa_init(); numDevices = Pa_GetDeviceCount(); if( numDevices < 0 ) { fprintf(stderr, "ERROR: Pa_GetDeviceCount returned %d\n", numDevices ); err = numDevices; goto error; } fprintf(stderr, "Audio Devices:\n"); for( i=0; i<numDevices; i++ ) { pdi = Pa_GetDeviceInfo( i ); fprintf(stderr, "device %d:", i+1 ); fprintf(stderr, " %s;", pdi->name ); fprintf(stderr, "%d inputs, ", pdi->maxInputChannels ); fprintf(stderr, "%d outputs", pdi->maxOutputChannels ); if ( i == Pa_GetDefaultInputDevice() ) fprintf(stderr, " (Default Input)"); if ( i == Pa_GetDefaultOutputDevice() ) fprintf(stderr, " (Default Output)"); fprintf(stderr, "\n"); } fprintf(stderr, "\n"); return; error: 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 ) ); }
void AudioIn::initAudioIn(const PaStreamParameters ¶ms, int seconds) { this->InputParams = params; this->data.maxFrameIndex = seconds*SAMPLE_RATE; this->data.frameIndex = 0; this->numSamples = seconds * SAMPLE_RATE * NUM_CHANNELS; this->numBytes = numSamples * sizeof(SAMPLE); this->data.recordedSamples = new SAMPLE[this->numBytes]; if(this->data.recordedSamples == nullptr) return; memset(this->data.recordedSamples, 0, this->numBytes); this->err = Pa_Initialize(); if(err != paNoError) return; this->InputParams.device = Pa_GetDefaultInputDevice(); /* default input device */ if (this->InputParams.device == paNoDevice) { return; } this->InputParams.channelCount = 1; /* mono input */ this->InputParams.sampleFormat = PA_SAMPLE_TYPE; this->InputParams.suggestedLatency = Pa_GetDeviceInfo(this->InputParams.device)->defaultLowInputLatency; this->InputParams.hostApiSpecificStreamInfo = NULL; }