C++ 错误代码
我正在使用C++ 错误代码,c++,c,portaudio,C++,C,Portaudio,我正在使用portaudio播放声音。我希望能够通过UI选择输出。我是这样处理的: PaError err = Pa_Initialize(); if( err != paNoError ) return false; qDebug() <<"Port audio succeed initialization !"; int numDevices; numDevices = Pa_GetDeviceCount(); if( numDevices <= 0 ) {
portaudio
播放声音。我希望能够通过UI选择输出。我是这样处理的:
PaError err = Pa_Initialize();
if( err != paNoError )
return false;
qDebug() <<"Port audio succeed initialization !";
int numDevices;
numDevices = Pa_GetDeviceCount();
if( numDevices <= 0 )
{
qDebug() << "ERROR: Pa_CountDevices returned " << numDevices;
return false;
}
const PaDeviceInfo *deviceInfo;
bool isThereOutput = false;
int i = 0;
while(i < numDevices and !isThereOutput)
{
deviceInfo = Pa_GetDeviceInfo( i );
isThereOutput = (deviceInfo->maxOutputChannels > 0);
i++;
}
if(!isThereOutput)
{
qDebug() << "No output device";
return false;
}
PaError errorOpening;
if(outputDevice != "")
{
PaStreamParameters outputDeviceInfo;
int numDevices = Pa_GetDeviceCount();
const PaDeviceInfo *deviceInfo;
for(int i = 0; i<numDevices; i++ )
{
deviceInfo = Pa_GetDeviceInfo( i );
if(deviceInfo->maxOutputChannels > 0 && deviceInfo->name == outputDevice)
{
outputDeviceInfo.device = i;
outputDeviceInfo.channelCount = 1;
outputDeviceInfo.sampleFormat = paInt8;
outputDeviceInfo.suggestedLatency = deviceInfo->defaultLowOutputLatency;
}
}
if(outputDeviceInfo.channelCount > 1)
{
errorOpening = Pa_OpenStream(&stream, NULL, &outputDeviceInfo, SAMPLE_RATE, FRAME_PER_BUFFER, paNoFlag, audioCallback, this);
}
}
if(outputDevice == "" or errorOpening != paNoError)
{
if(errorOpening != paNoError)
qDebug() << "Can't open selected device ("<< outputDevice <<"), switching to the default one. Error : " << Pa_GetErrorText(errorOpening);
errorOpening = Pa_OpenDefaultStream( &stream,
0, /* no input channels */
1, /* mono output */
paInt8, /* 8 bits output */
SAMPLE_RATE,
FRAME_PER_BUFFER, /* frames per buffer, i.e. the number
of sample frames that PortAudio will
request from the callback. Many apps
may want to use
paFramesPerBufferUnspecified, which
tells PortAudio to pick the best,
possibly changing, buffer size.*/
audioCallback, /* this is your callback function */
this ); /*This is a pointer that will be passed to
your callback*/
}
if(errorOpening != paNoError)
return false;
if(Pa_StartStream( stream ) != paNoError)
return false;
PaError err=Pa_Initialize();
如果(错误!=错误)
返回false;
qDebug()1)
{
errorOpening=Pa_OpenStream(&stream,NULL,&outputDeviceInfo,采样率,每缓冲区帧数,panofag,audioCallback,this);
}
}
如果(outputDevice==“”或ErrorOpen!=错误)
{
如果(错误打开!=错误)
qdGug():p>我假设你使用C++(尽管在代码中有几个奇怪的代码>和<代码> >代码>或。
如果您的for
循环未找到任何满足eviceInfo->maxOutputChannel>0&&deviceInfo->name==outputDevice
,则您的outputDeviceInfo
将保持未初始化状态。这意味着其channelConnect
可以具有任何值,包括大负值s、 然后,Pa\u OpenStream
不会被调用,您的errorOpening
也会被un初始化。我打赌这就是无效错误代码(值大于零)
的原因,当您将其输入Pa\u GetErrorText()
时,您是否检查了音频输出“出击次数”了已被另一个应用程序使用?在这种情况下,我认为PortAudio无法访问它。@StephaneRolland它是免费的,并且它是通过OpenDefaultStream
选择的,这对于未初始化的变量来说是正确的,但它不能解决问题,因为for
循环找到一个设备并提供一个设备来操作Nstream事实上,你是对的。问题来自于结构的部分初始化。