JNIEXPORT jobject JNICALL Java_org_jpab_PortAudio_getHostAPIsAsBuffer(JNIEnv *env, jclass paClass) { HostAPI * host_api; const PaHostApiInfo * host_api_info; const UINT8 count = Pa_GetHostApiCount(); UINT16 index, size = HOST_API_SIZE * count, offset = 0, temp; char * buffer = (char *)malloc(size); for (index = 0; index < count; index ++) { host_api_info = Pa_GetHostApiInfo(index); host_api = (HostAPI *) (buffer + offset); host_api->default_input_device = host_api_info->defaultInputDevice == -1 ? -1 : Pa_HostApiDeviceIndexToDeviceIndex(index, host_api_info->defaultInputDevice); host_api->default_output_device = host_api_info->defaultOutputDevice == -1 ? -1 : Pa_HostApiDeviceIndexToDeviceIndex(index, host_api_info->defaultOutputDevice); if (host_api->default_input_device < -1) host_api->default_input_device = -1; if (host_api->default_output_device < -1) host_api->default_output_device = -1; host_api->device_count = host_api_info->deviceCount; host_api->type = host_api_info->type; host_api->index = index; temp = strlen(host_api_info->name); host_api->name_length = temp; size += temp; buffer = (char *) realloc(buffer, size); offset += HOST_API_SIZE; memcpy(buffer + offset, host_api_info->name, temp); offset += temp; } return env->NewDirectByteBuffer(buffer, (jint) size); }
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; } }
QStringList AudioPA::DeviceList(bool typeInput) { //This static method may get called before constructor //So we have to make sure Pa_Initialize is called, make sure we have matching Pa_Terminate() Pa_Initialize(); QStringList devList; QString di; int apiCnt = Pa_GetHostApiCount(); const PaHostApiInfo *apiInfo; const PaDeviceInfo *devInfo; for (int i = 0; i < apiCnt; i++) { apiInfo = Pa_GetHostApiInfo(i); for (int j=0; j < apiInfo->deviceCount; j++) { devInfo = Pa_GetDeviceInfo(j); //Note: PortAudio must be compiled as ASIO files to enable ASIO4ALL driver support //Ignore device types we don't support if (apiInfo->type==paMME || apiInfo->type==paASIO || apiInfo->type==paDirectSound //Mac types || apiInfo->type==paCoreAudio) { //Ignore input and output devices that only have 1 channel //We need stereo in for I/Q if(typeInput && devInfo->maxInputChannels > 1) { di = di.sprintf("%2d:%s:%s",Pa_HostApiDeviceIndexToDeviceIndex(i,j), apiInfo->name,devInfo->name); devList << di; } else if(!typeInput && devInfo->maxOutputChannels > 1) { //This is the fully qualified name that will be saved and used to find the same device //See FindDeviceByName() di = di.sprintf("%2d:%s:%s",Pa_HostApiDeviceIndexToDeviceIndex(i,j), apiInfo->name,devInfo->name); devList << di; } } } } Pa_Terminate(); return devList; }
std::vector<ApiInfo> getHostApis(){ // Returns information about available host apis. Currently uses portaudio. if( Pa_Initialize() != paNoError ) throw std::runtime_error("Portaudio could not be initialized during 'getHostApis'."); PaHostApiIndex apiCount = Pa_GetHostApiCount(); PaDeviceIndex devCount = 0; PaDeviceIndex devNum = 0; std::vector<DevInfo> devInf; const PaHostApiInfo* p_ApiInf; const PaDeviceInfo* p_DevInf; std::vector<ApiInfo> vApiInf(apiCount); for(int api=0; api<apiCount; ++api){ p_ApiInf = Pa_GetHostApiInfo(api); vApiInf[api].apiName = p_ApiInf->name; devCount = p_ApiInf->deviceCount; devInf.resize(devCount); for(int dev=0; dev<devCount; ++dev){ devNum = Pa_HostApiDeviceIndexToDeviceIndex(api, dev); p_DevInf = Pa_GetDeviceInfo(devNum); devInf[dev].devName = p_DevInf->name; devInf[dev].numInputs = p_DevInf->maxInputChannels; devInf[dev].numOutputs= p_DevInf->maxOutputChannels; vApiInf[api].devices = devInf; } } if( Pa_Terminate() != paNoError ) throw std::runtime_error("Error terminating portaudio during 'getHostApis'."); return vApiInf; }
void PortAudioSettingsPage::populateDeviceList() { int index = hostAPIList->currentIndex(); inputDeviceList->clear(); outputDeviceList->clear(); if (index < 0) { return; } PaHostApiIndex apiIndex = hostAPIList->itemData(index).toInt(NULL); const PaHostApiInfo *hostAPIInfo = Pa_GetHostApiInfo(apiIndex); if (!hostAPIInfo) { return; } int i; for (i = 0; i < hostAPIInfo->deviceCount; i++) { PaDeviceIndex devIndex = Pa_HostApiDeviceIndexToDeviceIndex(apiIndex, i); const PaDeviceInfo *devInfo = Pa_GetDeviceInfo(devIndex); QString name = QString::fromUtf8(devInfo->name); if (devInfo->maxInputChannels > 0) { inputDeviceList->addItem(name, devIndex); } if (devInfo->maxOutputChannels > 0) { outputDeviceList->addItem(name, devIndex); } } }
static const PaDeviceInfo *findDeviceInfo(PaHostApiIndex hostAPI, const char *name, PaDeviceIndex *index) { const PaHostApiInfo *hostAPIInfo = Pa_GetHostApiInfo(hostAPI); if (!hostAPIInfo) { return NULL; } const PaDeviceInfo *deviceInfo; PaDeviceIndex deviceIndex; int i; for (i = 0; i < hostAPIInfo->deviceCount; i++) { deviceIndex = Pa_HostApiDeviceIndexToDeviceIndex(hostAPI, i); if (deviceIndex < 0) { continue; } deviceInfo = Pa_GetDeviceInfo(deviceIndex); if (deviceInfo && strcmp(name, deviceInfo->name) == 0) { break; } } if (i >= hostAPIInfo->deviceCount) { deviceIndex = hostAPIInfo->defaultInputDevice; deviceInfo = Pa_GetDeviceInfo(deviceIndex); } if (index) { *index = deviceIndex; } return deviceInfo; }
JNIEXPORT jobject JNICALL Java_org_jpab_PortAudio_getHostAPIAsBuffer(JNIEnv *env, jclass paClass, jint index) { const PaHostApiInfo * host_api_info = Pa_GetHostApiInfo((PaHostApiIndex) index); const UINT8 size = HOST_API_SIZE + strlen(host_api_info->name); char * buffer = (char *)malloc(size), * original = buffer; HostAPI * host_api = (HostAPI *) buffer; host_api->device_count = host_api_info->deviceCount; host_api->default_input_device = host_api_info->defaultInputDevice == -1 ? -1 : Pa_HostApiDeviceIndexToDeviceIndex(index, host_api_info->defaultInputDevice); host_api->default_output_device = host_api_info->defaultOutputDevice == -1 ? -1 : Pa_HostApiDeviceIndexToDeviceIndex(index, host_api_info->defaultOutputDevice); if (host_api->default_input_device < -1) host_api->default_input_device = -1; if (host_api->default_output_device < -1) host_api->default_output_device = -1; host_api->type = host_api_info->type; host_api->index = index; host_api->name_length = strlen(host_api_info->name); buffer += HOST_API_SIZE; memcpy(buffer, host_api_info->name, host_api->name_length); return env->NewDirectByteBuffer(original, (jint) size); }
QHash<PaDeviceIndex, QString> deviceNames(PaHostApiIndex hostApi) { QHash<int, QString> names; for (int i = 0; i < Pa_GetHostApiInfo(hostApi)->deviceCount; ++i) { PaDeviceIndex index = Pa_HostApiDeviceIndexToDeviceIndex(hostApi, i); names[index] = Pa_GetDeviceInfo(index)->name; } return names; }
PaDeviceIndex PA_AudioIO_ALSA::setDevice(int deviceIndex = 0){ PaHostApiIndex alsaInd = Pa_HostApiTypeIdToHostApiIndex(paALSA); const PaHostApiInfo* apiInf = Pa_GetHostApiInfo(alsaInd); if(!apiInf) throw Pa_NoApiException(); if(-1 == deviceIndex) return apiInf->defaultOutputDevice; if(deviceIndex > apiInf->deviceCount || deviceIndex < 0){ throw Pa_DeviceIndexNotFoundException(); } return Pa_HostApiDeviceIndexToDeviceIndex(alsaInd, deviceIndex); }
PaDeviceIndex PA_AudioIO_DS::setDevice(int deviceIndex){ PaHostApiIndex dsInd = Pa_HostApiTypeIdToHostApiIndex(paDirectSound); const PaHostApiInfo* apiInf = nullptr; apiInf = Pa_GetHostApiInfo(dsInd); if(!apiInf) throw Pa_NoApiException(); if(-1 == deviceIndex) return apiInf->defaultOutputDevice; if(deviceIndex > apiInf->deviceCount || deviceIndex < 0){ throw Pa_DeviceIndexNotFoundException(); } return Pa_HostApiDeviceIndexToDeviceIndex(dsInd, deviceIndex); }
PaDeviceIndex PA_AudioIO_WMME::setDevice(int deviceIndex){ PaHostApiIndex mmeInd = Pa_HostApiTypeIdToHostApiIndex(paMME); const PaHostApiInfo* apiInf = nullptr; apiInf = Pa_GetHostApiInfo(mmeInd); if(!apiInf) throw Pa_NoApiException(); if(-1 == deviceIndex) return apiInf->defaultOutputDevice; if(deviceIndex > apiInf->deviceCount || deviceIndex < 0){ throw Pa_DeviceIndexNotFoundException(); } std::cout << "Device index is: " << deviceIndex << std::endl; return Pa_HostApiDeviceIndexToDeviceIndex(mmeInd, deviceIndex); }
PaDeviceIndex PA_AudioIO_ASIO::setDevice(int deviceIndex){ PaHostApiIndex asioInd = Pa_HostApiTypeIdToHostApiIndex(paASIO); const PaHostApiInfo* apiInf = nullptr; apiInf = Pa_GetHostApiInfo(asioInd); if(!apiInf) throw Pa_NoApiException(); if(-1 == deviceIndex) return apiInf->defaultOutputDevice; if(deviceIndex > apiInf->deviceCount || deviceIndex < 0){ throw Pa_DeviceIndexNotFoundException(); } std::cout << "Warning: ASIO blocking is currently unimplemented in portaudio." << std::endl; return Pa_HostApiDeviceIndexToDeviceIndex(asioInd, deviceIndex); }
static const PaDeviceInfo *findDeviceInfo(PaHostApiIndex hostAPI, const char *name, PaDeviceIndex *index, bool isInput) { const PaHostApiInfo *hostAPIInfo = Pa_GetHostApiInfo(hostAPI); if (!hostAPIInfo) { return NULL; } const PaDeviceInfo *deviceInfo; PaDeviceIndex deviceIndex; int i; for (i = 0; i < hostAPIInfo->deviceCount; i++) { deviceIndex = Pa_HostApiDeviceIndexToDeviceIndex(hostAPI, i); if (deviceIndex < 0) { continue; } deviceInfo = Pa_GetDeviceInfo(deviceIndex); if (!deviceInfo) { continue; } if (isInput && deviceInfo->maxInputChannels == 0) { continue; } if (!isInput && deviceInfo->maxOutputChannels == 0) { continue; } if (strcmp(deviceInfo->name, name) == 0) { break; } } if (i >= hostAPIInfo->deviceCount) { deviceIndex = isInput ? hostAPIInfo->defaultInputDevice : hostAPIInfo->defaultOutputDevice; deviceInfo = Pa_GetDeviceInfo(deviceIndex); if (deviceInfo) { qDebug("Unable to find %s device \"%s\", falling back to \"%s\" (%d)", isInput ? "input" : "output", name, deviceInfo->name, deviceIndex); } else { qDebug("Unable to find %s device \"%s\" and no fallback available", isInput ? "input" : "output", name); } } if (index) { *index = deviceIndex; } return deviceInfo; }
QStringList Portaudio::deviceList(int apiIdx) { QStringList dl; const PaHostApiInfo* info = Pa_GetHostApiInfo(apiIdx); if (info) { for (int i = 0; i < info->deviceCount; ++i) { PaDeviceIndex idx = Pa_HostApiDeviceIndexToDeviceIndex(apiIdx, i); const PaDeviceInfo* di = Pa_GetDeviceInfo(idx); if (di) dl.append(di->name); } } return dl; }
int Portaudio::currentDevice() const { PaDeviceIndex idx = preferences.portaudioDevice; if (idx < 0) idx = Pa_GetDefaultOutputDevice(); for (int api = 0; api < Pa_GetHostApiCount(); ++api) { const PaHostApiInfo* info = Pa_GetHostApiInfo(api); if (info) { for (int k = 0; k < info->deviceCount; ++k) { PaDeviceIndex i = Pa_HostApiDeviceIndexToDeviceIndex(api, k); if (i == idx) return k; } } } qDebug("Portaudio: no current ApiDevice found for device %d", idx); return -1; }
const QList<audioDevice> PortAudioSystem::enumerateDevices(bool input, PaDeviceIndex match) { PaHostApiIndex iApiCnt; PaHostApiIndex iApiIndex; int iApiDevIndex; PaDeviceIndex iDevIndex; const PaDeviceInfo *pDevInfo; QList<audioDevice> adl; adl << audioDevice(tr("Default Device"), -1); iApiCnt = Pa_GetHostApiCount(); for (iApiIndex = 0; iApiIndex < iApiCnt; iApiIndex++) { const PaHostApiInfo *apiInfo = Pa_GetHostApiInfo(iApiIndex); if (!apiInfo) continue; QString qsApiName = QLatin1String(apiInfo->name); for (iApiDevIndex = 0; iApiDevIndex < apiInfo->deviceCount; iApiDevIndex++) { iDevIndex = Pa_HostApiDeviceIndexToDeviceIndex(iApiIndex, iApiDevIndex); pDevInfo = Pa_GetDeviceInfo(iDevIndex); if (!pDevInfo) continue; QString qsDevName = QLatin1String(pDevInfo->name); if ((input && (pDevInfo->maxInputChannels > 0)) || (!input && (pDevInfo->maxOutputChannels > 0))) adl << audioDevice(qsApiName + QLatin1String(": ") + qsDevName, iDevIndex); } } for (int i=0;i<adl.count();++i) { if (adl.at(i).second == match) { audioDevice ad = adl.takeAt(i); adl.prepend(ad); break; } } return adl; }
pure_expr *audio_driver_info(int api) { const PaHostApiInfo *info = Pa_GetHostApiInfo(api); if (info) { size_t i, n = info->deviceCount; pure_expr *devs, **xv; if (n == 0) devs = pure_listl(0); else { if (!(xv = malloc(n*sizeof(pure_expr*)))) return 0; for (i = 0; i < n; i++) xv[i] = pure_int(Pa_HostApiDeviceIndexToDeviceIndex(api, i)); devs = pure_listv(n, xv); free(xv); } return pure_tuplel(5, pure_cstring_dup(info->name), pure_int(info->type), devs, pure_int(info->defaultInputDevice), pure_int(info->defaultOutputDevice)); } else return 0; }
// prints the device to stdout. Don't call this function, call pa_printdevinfo // as Pa_Init needs to be done first. void printdevice(int api_idx, int device) { const PaDeviceInfo *pdi; pdi = Pa_GetDeviceInfo(Pa_HostApiDeviceIndexToDeviceIndex(api_idx, device)); if (pdi != NULL) { char *format = NULL; /* switch (pdi->nativeSampleFormats) { case (0): format = strdup("float32"); break; case (1): format = strdup("int16"); break; case (2): format = strdup("int32"); break; case (3): format = strdup("int24"); break; case (4): format = strdup("packedint24"); break; case (5): format = strdup("int8"); break; case (6): format = strdup("uint8"); break; case (16): format = strdup("custom"); break; } mexPrintf("\nDevice %i\nDevice name: %s\nMax Input channels: %i Max Output channels: %i\nNative Sample Format: %s\n" , device, pdi->name, pdi->maxInputChannels, pdi->maxOutputChannels, format); */ mexPrintf("\nDevice %i\nDevice name: %s\nMax Input channels: %i Max Output channels: %i\n" , device, pdi->name, pdi->maxInputChannels, pdi->maxOutputChannels); if (format != NULL) delete format; } }
static void logPortAudioInfo() { qDebug(Pa_GetVersionText()); PaHostApiIndex api = 0; const PaHostApiInfo *apiInfo; while ((apiInfo = Pa_GetHostApiInfo(api))) { qDebug("Host API: %s (%d devices)", apiInfo->name, apiInfo->deviceCount); int device; for (device = 0; device < apiInfo->deviceCount; device++) { PaDeviceIndex devIdx = Pa_HostApiDeviceIndexToDeviceIndex(api, device); if (devIdx < 0) { qDebug("[%02d] Error: %s", device, Pa_GetErrorText(devIdx)); continue; } const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(devIdx); if (!deviceInfo) { qDebug("[%02d] Invalid device index", device); continue; } qDebug("[%02d] \"%s\" (%d)", device, deviceInfo->name, devIdx); qDebug(" Channels: %d in, %d out", deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels); qDebug(" Default sample rate: %g Hz", deviceInfo->defaultSampleRate); qDebug(" Input latency: %g low, %g high", deviceInfo->defaultLowInputLatency, deviceInfo->defaultHighInputLatency); qDebug(" Output latency: %g low, %g high", deviceInfo->defaultLowOutputLatency, deviceInfo->defaultHighOutputLatency); } api++; } }
int AudioPA::FindDeviceByName(QString name, bool inputDevice) { QString di; int apiCnt = Pa_GetHostApiCount(); const PaHostApiInfo *apiInfo; const PaDeviceInfo *devInfo; for (int i = 0; i < apiCnt; i++) { apiInfo = Pa_GetHostApiInfo(i); for (int j=0; j < apiInfo->deviceCount; j++){ devInfo = Pa_GetDeviceInfo(j); if ((inputDevice && devInfo->maxInputChannels > 1) || (!inputDevice && devInfo->maxOutputChannels > 0)){ //Must be EXACT format as returned by DeviceList, minus device index number di = di.sprintf("%s:%s",apiInfo->name,devInfo->name); if (di == name) return Pa_HostApiDeviceIndexToDeviceIndex(i,j); //Index } } } return -1; //Not found }
/*fa MTR_AudioInit yes */ MTR_DCLSPC bool MTR_CALL MTR_AudioInit(uint32_t sndDmSize, uint32_t sndReservedCount, uint32_t musDmSize, uint32_t musReservedCount, int freq, int channels, int chunkSize) { PaError error; int hostApiCount; const PaHostApiInfo* hostApiInfo; int deviceIndex; int devicesCount; const PaDeviceInfo* deviceInfo; int i; int j; MTR_LogWrite("Initializing audio manager", 0, MTR_LMT_INFO); MTR_LogWrite_s("Reporting PortAudio version:", 1, MTR_LMT_INFO, Pa_GetVersionInfo()->versionText); error = Pa_Initialize(); if (error != paNoError) { MTR_LogWrite("Unable to initialize PortAudio", 0, MTR_LMT_ERROR); MTR_LogWrite(Pa_GetErrorText(error), 0, MTR_LMT_ERROR); return false; } MTR_LogWrite("Reporting available devices:", 1, MTR_LMT_INFO); devicesCount = Pa_GetDeviceCount(); for (i = 0; i < devicesCount; i++) { deviceInfo = Pa_GetDeviceInfo(i); MTR_LogWrite(deviceInfo->name, 2, MTR_LMT_INFO); hostApiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi); MTR_LogWrite_s("Host API:", 3, MTR_LMT_INFO, hostApiInfo->name); MTR_LogWrite_i("Max input channels:", 3, MTR_LMT_INFO, deviceInfo->maxInputChannels); MTR_LogWrite_i("Max output channels:", 3, MTR_LMT_INFO, deviceInfo->maxOutputChannels); MTR_LogWrite_d("Default low input latency (sec.):", 3, MTR_LMT_INFO, deviceInfo->defaultLowInputLatency); MTR_LogWrite_i("Default low output latency (sec.):", 3, MTR_LMT_INFO, deviceInfo->defaultLowOutputLatency); MTR_LogWrite_d("Default high input latency (sec.):", 3, MTR_LMT_INFO, deviceInfo->defaultHighInputLatency); MTR_LogWrite_i("Default high output latency (sec.):", 3, MTR_LMT_INFO, deviceInfo->defaultHighOutputLatency); MTR_LogWrite_i("Default sample rate:", 3, MTR_LMT_INFO, deviceInfo->defaultSampleRate); } MTR_LogWrite("Reporting available hosts APIs:", 1, MTR_LMT_INFO); hostApiCount = Pa_GetHostApiCount(); for (i = 0; i < hostApiCount; i++) { hostApiInfo = Pa_GetHostApiInfo(i); MTR_LogWrite(hostApiInfo->name, 2, MTR_LMT_INFO); MTR_LogWrite("Devices of this host API:", 3, MTR_LMT_INFO); devicesCount = hostApiInfo->deviceCount; for (j = 0; j < devicesCount; j++) { deviceIndex = Pa_HostApiDeviceIndexToDeviceIndex(i, j); deviceInfo = Pa_GetDeviceInfo(deviceIndex); MTR_LogWrite(deviceInfo->name, 4, MTR_LMT_INFO); } deviceInfo = Pa_GetDeviceInfo(hostApiInfo->defaultInputDevice); MTR_LogWrite_s("Default input device:", 3, MTR_LMT_INFO, deviceInfo->name); deviceInfo = Pa_GetDeviceInfo(hostApiInfo->defaultOutputDevice); MTR_LogWrite_s("Default output device:", 3, MTR_LMT_INFO, deviceInfo->name); } hostApiInfo = Pa_GetHostApiInfo(Pa_GetDefaultHostApi()); MTR_LogWrite_s("Default host API:", 1, MTR_LMT_INFO, hostApiInfo->name); // if (SDL_InitSubSystem(SDL_INIT_AUDIO) == 0) // MTR_LogWrite("SDL audio subsystem initialized", 1, MTR_LMT_INFO); // else // MTR_LogWrite("Unable to initialize SDL audio subsystem", 1, // MTR_LMT_INFO); // // initFlags = MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MODPLUG | MIX_INIT_MP3 | // MIX_INIT_OGG | MIX_INIT_FLUIDSYNTH; // initResult = Mix_Init(initFlags); // if(initResult != initFlags) // { // if (initResult == 0) // { // MTR_Notify("Unable to load libraries needed by SDL_mixer", 1, // MTR_LMT_ERROR); // return false; // } // // MTR_LogWrite("Unable to initialize support of this formats:", 1, // MTR_LMT_WARNING); // if ((initResult & MIX_INIT_FLAC) == 0) // MTR_LogWrite("FLAC", 2, MTR_LMT_WARNING); // if ((initResult & MIX_INIT_MOD) == 0) // MTR_LogWrite("MOD", 2, MTR_LMT_WARNING); // if ((initResult & MIX_INIT_MODPLUG) == 0) // MTR_LogWrite("MODPlug", 2, MTR_LMT_WARNING); // if ((initResult & MIX_INIT_MP3) == 0) // MTR_LogWrite("MP3", 2, MTR_LMT_WARNING); // if ((initResult & MIX_INIT_OGG) == 0) // MTR_LogWrite("OGG", 2, MTR_LMT_WARNING); // if ((initResult & MIX_INIT_FLUIDSYNTH) == 0) // MTR_LogWrite("FluidSynth", 2, MTR_LMT_WARNING); // } // else // MTR_LogWrite("Support of the every SDL_mixer audio format initialized", // 1, MTR_LMT_INFO); // // MTR_LogWrite("Preparing parameters for initialize SDL_mixer", 1, // MTR_LMT_INFO); // // /* Choosing sampling frequency */ // if (freq == MTR_AU_FREQ_DEFAULT) // { // frequency = MIX_DEFAULT_FREQUENCY; // MTR_LogWrite_i("Choosed default sampling frequency (Hz): ", 2, // MTR_LMT_INFO, MIX_DEFAULT_FREQUENCY); // } // else if (freq < 11025) // { // frequency = 11025; // MTR_LogWrite_i("Choosed sampling frequency not supported. Using " // "minimal supported sampling frequency (Hz): ", 2, MTR_LMT_WARNING, // 11025); // } // else // { // frequency = freq; // MTR_LogWrite_i("Choosed sampling frequency (Hz): ", 2, MTR_LMT_INFO, // freq); // } // // /* Choosing channels count */ // if (channels == MTR_AU_CHANNELS_DEFAULT) // { // channelsCount = MIX_DEFAULT_CHANNELS; // MTR_LogWrite_s("Choosed default channels count: ", 2, MTR_LMT_INFO, // channelsConf[MIX_DEFAULT_CHANNELS - 1]); // } // else if (channels > 2) // { // channelsCount = 2; // MTR_LogWrite_s("Choosed channels count are not supported. Using max " // "supported channels count: ", 2, MTR_LMT_WARNING, channelsConf[2 - 1]); // } // else // { // channelsCount = channels; // MTR_LogWrite_s("Choosed channels count: ", 2, MTR_LMT_INFO, // channelsConf[channels - 1]); // } // // /* Choosing chunk size */ // if (chunkSize == MTR_AU_CHUNK_SIZE_DEFAULT) // { // finalChunkSize = 4096; // MTR_LogWrite_i("Choosed default chunk size (bytes): ", 2, MTR_LMT_INFO, // 4096); // } // else if (chunkSize > 8192) // { // finalChunkSize = 8192; // MTR_LogWrite_i("Choosed chunk size not supported. Using max supported " // "chunk size (bytes): ", 2, MTR_LMT_WARNING, 8192); // } // else if (chunkSize < 512) // { // finalChunkSize = 512; // MTR_LogWrite_i("Choosed chunk size not supported. Using minimal " // "supported chunk size (bytes): ", 2, MTR_LMT_WARNING, 512); // } // else // { // finalChunkSize = chunkSize; // MTR_LogWrite_i("Choosed chunk size (bytes): ", 2, MTR_LMT_INFO, // chunkSize); // } // // if (Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, channelsCount, // finalChunkSize) == 0) // { // MTR_LogWrite("SDL_mixer initialized", 1, MTR_LMT_INFO); // // MTR_LogWrite("Reporting built-in SDL_mixer chunk decoders", 1, // MTR_LMT_INFO); // for (i = 0; i < Mix_GetNumChunkDecoders(); i++) // MTR_LogWrite_s("Chunk decoder found: ", 2, MTR_LMT_INFO, // Mix_GetChunkDecoder(i)); // MTR_LogWrite("Reporting built-in SDL_mixer music decoders", 1, // MTR_LMT_INFO); // for (i = 0; i < Mix_GetNumMusicDecoders(); i++) // MTR_LogWrite_s("Music decoder found: ", 2, MTR_LMT_INFO, // Mix_GetMusicDecoder(i)); // } // else // { // MTR_Notify("Unable to initialize SDL2_mixer", 1, MTR_LMT_ERROR); // MTR_LogWrite_s("SDL2_mixer error: ", 1, MTR_LMT_ERROR, Mix_GetError()); // Mix_Quit(); // return false; // } // Mix_AllocateChannels(64); // // mtrSoundKeeper = (mtrIndexkeeper_t *)MTR_IndexkeeperCreate(sndDmSize, // sndReservedCount, sizeof(mtrSound_t)); // if (mtrSoundKeeper == NULL) // { // MTR_Notify("Unable to initialize indexkeeper structure for sounds", 1, // MTR_LMT_ERROR); // Mix_CloseAudio(); // Mix_Quit(); // return false; // } // else // MTR_LogWrite("Indexkeeper structure for sounds initialized", 1, // MTR_LMT_INFO); // // mtrMusicKeeper = (mtrIndexkeeper_t *)MTR_IndexkeeperCreate(musDmSize, // musReservedCount, sizeof(mtrMusic_t)); // if (mtrMusicKeeper == NULL) // { // MTR_Notify("Unable to initialize indexkeeper structure for music", 1, // MTR_LMT_ERROR); // Mix_CloseAudio(); // Mix_Quit(); // return false; // } // else // MTR_LogWrite("Indexkeeper structure for music initialized", 1, // MTR_LMT_INFO); // // MTR_LogWrite("Audio manager initialized", 0, MTR_LMT_INFO); mtrCurrentMusic = 0U; mtrAudioInited = true; return true; }
int pa_wavplayrec(SAMPLE *buffer, int buflen, int bufchannels, SAMPLE *recbuffer, int recbuffirstchannel, int recbufflastchannel, int recbuflen, int deviceID, int recdevID, int samplerate) { //mexPrintf("buflen=%i bufchannels=%i samplerate=%i\n", buflen, bufchannels, samplerate); // Make our wavData object, to pass to OpenStream. This gets given to us again in the // callback. I guess you could just have a global variable instead... paWavData wav; wav.buffer = buffer; wav.recbuffer = recbuffer; wav.buflen = buflen; wav.recbuflen = recbuflen; wav.bufchannels = bufchannels; wav.recbuffirstchan = recbuffirstchannel; wav.recbufflastchan = recbufflastchannel; wav.bufpos = 0; wav.recbufpos = 0; if (recbuffer == NULL) if (buffer == NULL) mexErrMsgTxt("recbuffer && buffer NULL in pa_wavplay"); else { mexPrintf("Playing on device %i\n", deviceID); wav.recmode = play; } else if (buffer == NULL) { mexPrintf("Recording on device %i\n", recdevID); wav.recmode = record; } else { mexPrintf("Recording on device %i\n", recdevID); mexPrintf("Playing on device %i\n", deviceID); wav.recmode = playrecord; } PaStream *stream; PaError err; err = Pa_Initialize(); if( err != paNoError ) goto error; int dev_type_indx = -1; const PaHostApiInfo* Api_Info; int num_APIs = (int )Pa_GetHostApiCount(); for (int i=0; i<num_APIs; i++) { Api_Info = Pa_GetHostApiInfo(i); if (strcmp(Api_Info->name,API_NAME)==0) dev_type_indx = i; } if (dev_type_indx == -1) { goto error; } Api_Info = Pa_GetHostApiInfo(dev_type_indx); if (recdevID != -1) recdevID = Pa_HostApiDeviceIndexToDeviceIndex(dev_type_indx, recdevID); if (deviceID != -1) deviceID = Pa_HostApiDeviceIndexToDeviceIndex(dev_type_indx, deviceID); // Open an audio I/O stream. PaWasapiStreamInfo api_info; api_info.size = sizeof(PaWasapiStreamInfo); api_info.version = 1; api_info.hostApiType = paWASAPI; api_info.flags = paWinWasapiExclusive; void *p_api_info; if ((strcmp(API_NAME, "Windows WASAPI")== 0)) { p_api_info = &api_info; } else { p_api_info = NULL; } PaStreamParameters inputParameters; // Parameters governing portaudio input stream PaStreamParameters outputParameters; // Parameters governing portaudio output stream inputParameters.channelCount = recbufflastchannel; inputParameters.device = recdevID; inputParameters.hostApiSpecificStreamInfo = p_api_info; inputParameters.sampleFormat = paFloat32; // Input data returned as floating point if (recdevID != -1) inputParameters.suggestedLatency = Pa_GetDeviceInfo(recdevID)->defaultLowInputLatency ; outputParameters.channelCount = bufchannels; outputParameters.device = deviceID; outputParameters.hostApiSpecificStreamInfo = p_api_info; outputParameters.sampleFormat = paFloat32; // Output data returned as floating point if (deviceID != -1) outputParameters.suggestedLatency = Pa_GetDeviceInfo(deviceID)->defaultLowInputLatency ; err = Pa_IsFormatSupported(NULL, &outputParameters, (double )samplerate); if (recbuffer == NULL) err = Pa_OpenStream( &stream, NULL, &outputParameters, samplerate, // stream sample rate BLOCK, // frames per buffer paNoFlag, // stream flag (PaStreamCallback (__cdecl *))paWavCallback, // callback function &wav); // user data else if (buffer == NULL) err = Pa_OpenStream( &stream, &inputParameters, NULL, samplerate, // stream sample rate BLOCK, // frames per buffer paNoFlag, // stream flag (PaStreamCallback (__cdecl *))paWavCallback, // callback function &wav); // user data else err = Pa_OpenStream( &stream, &inputParameters, &outputParameters, samplerate, // stream sample rate BLOCK, // frames per buffer paNoFlag, // stream flag (PaStreamCallback (__cdecl *))paWavCallback, // callback function &wav); // user data if( err != paNoError ) goto error; err = Pa_StartStream( stream ); if( err != paNoError ) goto error; // sleep while stream's active while( Pa_IsStreamActive(stream) ) Pa_Sleep( 50 ); if (err = Pa_IsStreamStopped( stream ) == 0) { err = Pa_StopStream( stream ); if( err != paNoError ) goto error; } else if (err != paNoError ) goto error; err = Pa_CloseStream( stream ); if( err != paNoError ) goto error; Pa_Terminate(); return err; // wtf? A goto? Yeah, that's leftover from the portaudio example code error: Pa_Terminate(); mexPrintf( "An error occured while using the portaudio stream\n" ); mexPrintf( "Error number: %d\n", err ); mexPrintf( "Error message: %s\n", Pa_GetErrorText( err ) ); return err; }
int Portaudio::deviceIndex(int apiIdx, int apiDevIdx) { return Pa_HostApiDeviceIndexToDeviceIndex(apiIdx, apiDevIdx); }
int maxInputChannels(PaHostApiIndex hostApi, PaDeviceIndex device) { return Pa_GetDeviceInfo(Pa_HostApiDeviceIndexToDeviceIndex(hostApi, device))->maxInputChannels; }
JNIEXPORT jint JNICALL Java_com_github_rjeschke_jpa_JPA_hostApiDeviceIndexToDeviceIndex(JNIEnv *env, jclass clazz, jint hostApi, jint hostApiDeviceIndex) { return (jint)Pa_HostApiDeviceIndexToDeviceIndex((PaHostApiIndex)hostApi, (int)hostApiDeviceIndex); }
PaTime defaultLowInputLatency(PaHostApiIndex hostApi, PaDeviceIndex device) { return Pa_GetDeviceInfo(Pa_HostApiDeviceIndexToDeviceIndex(hostApi, device))->defaultLowInputLatency; }