C++ I';我想在PortAudio中打开一条流
我正在使用这个api:Pa_OpenStream() 我得到了err=-9993,即pabadiodevicombination 我配置了输入和输出设备,我想从输入录制并传输到输出播放设备 我不知道为什么我会犯这个错误 谢谢你的帮助,C++ I';我想在PortAudio中打开一条流,c++,portaudio,C++,Portaudio,我正在使用这个api:Pa_OpenStream() 我得到了err=-9993,即pabadiodevicombination 我配置了输入和输出设备,我想从输入录制并传输到输出播放设备 我不知道为什么我会犯这个错误 谢谢你的帮助, Aviel确保将正确的参数传递给该方法。为此,您可以执行以下操作 通过Pa\u Initialize()初始化PortAudio 通过PortAudio检查哪些音频设备可供您使用。对每个可用设备使用Pa_GetDeviceCount(),然后使用Pa_GetDev
Aviel确保将正确的参数传递给该方法。为此,您可以执行以下操作
Pa\u Initialize()初始化PortAudio
Pa_GetDeviceCount()
,然后使用Pa_GetDeviceInfo()
。查看每个设备实际可用的输入和输出数量,不要传递超过其支持的数量PaStreamParameters
结构的相应字段int MyClass::initSoundInterfaces()
{
int result = -1; // target ASIO/CoreAudio device index
PaError err = Pa_Initialize();
const PaDeviceInfo* deviceInfo;
int numDevices = Pa_GetDeviceCount();
for( int DevIndex=0; DevIndex<numDevices; DevIndex++ )
{
deviceInfo = Pa_GetDeviceInfo( DevIndex );
QString str = Pa_GetHostApiInfo(deviceInfo->hostApi)->name;
qDebug() << "DEV: ApiInfo: " << str;
qDebug() << "defaultSampleRate = " << deviceInfo->defaultSampleRate;
qDebug() << "maxInputChannels = " << deviceInfo->maxInputChannels;
qDebug() << "maxOutputChannels = " << deviceInfo->maxOutputChannels;
QRegExp reg_exp(".*(ASIO|Core.*Audio).*", Qt::CaseInsensitive);
if( str.contains(reg_exp) )
{
if(deviceInfo->maxInputChannels > 0
&& deviceInfo->maxOutputChannels > 1)
{
result = DevIndex;
break;
}
}
}
return result;
}
好的,当调用Pa_GetDeviceCount()时,我会得到许多可用的设备。 目前我有onborad声卡和usb声卡。(每个都有输入和输出设备) 当我配置车载声卡的输入和输出时,它工作正常。 但当我配置usb卡的输入和板载卡的输出时,它返回err=paInvalidDevice 我还看到,每个卡都有几个在hostApi中不同的设备(paInDevelopment=0,paDirectSound=1,paMME=2) 他们之间有什么不同?我应该选择哪种设备?可以在它们之间进行混合,即选择具有“PadDirectSound”的输入设备和具有“paInDevelopment”的输出设备 我注意的另一件事是采样率和通道数,输入采样率44100,输出48000可以吗 最后一件事:您确认了变量:根据什么采样nBufferSize 谢谢, 阿维尔
int MyClass::initSoundInterfaces()
{
int result = -1; // target ASIO/CoreAudio device index
PaError err = Pa_Initialize();
const PaDeviceInfo* deviceInfo;
int numDevices = Pa_GetDeviceCount();
for( int DevIndex=0; DevIndex<numDevices; DevIndex++ )
{
deviceInfo = Pa_GetDeviceInfo( DevIndex );
QString str = Pa_GetHostApiInfo(deviceInfo->hostApi)->name;
qDebug() << "DEV: ApiInfo: " << str;
qDebug() << "defaultSampleRate = " << deviceInfo->defaultSampleRate;
qDebug() << "maxInputChannels = " << deviceInfo->maxInputChannels;
qDebug() << "maxOutputChannels = " << deviceInfo->maxOutputChannels;
QRegExp reg_exp(".*(ASIO|Core.*Audio).*", Qt::CaseInsensitive);
if( str.contains(reg_exp) )
{
if(deviceInfo->maxInputChannels > 0
&& deviceInfo->maxOutputChannels > 1)
{
result = DevIndex;
break;
}
}
}
return result;
}
bool MyClass::startAudio(int DevIndex)
{
PaError err = paNoError;
PaStreamParameters in_param;
in_param.device = DevIndex;
g_ChannelCount = min(Pa_GetDeviceInfo(DevIndex)->maxInputChannels,
MAX_INPUT_COUNT);
in_param.channelCount = g_ChannelCount;
in_param.hostApiSpecificStreamInfo = NULL;
in_param.sampleFormat = paFloat32 | paNonInterleaved;
in_param.suggestedLatency = 0;
// Pa_GetDeviceInfo(DevIndex)->defaultLowInputLatency;
PaStreamParameters out_param;
out_param.device = DevIndex;
out_param.channelCount = 2; // I do not need more than 2 output channels
out_param.hostApiSpecificStreamInfo = NULL;
out_param.sampleFormat = paFloat32 | paNonInterleaved; // Not all devices support 32 bits
out_param.suggestedLatency = 0;
// Pa_GetDeviceInfo(DevIndex)->defaultLowOutputLatency;
if(err == paNoError)
{
err = Pa_OpenStream(&stream,
&in_param,
&out_param,
nSampleRate,
cBufferSize/*paFramesPerBufferUnspecified*/,
paNoFlag,
process,
0);
}
err = Pa_StartStream(stream);
...
}