gpt4 book ai didi

c++ - 错误的错误代码

转载 作者:太空宇宙 更新时间:2023-11-04 03:50:00 25 4
gpt4 key购买 nike

我正在使用 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;

它失败了:

Can't open selected device ( "Sortie intégr" ), switching to the default one. Error : Invalid error code (value greater than zero)

但我不明白为什么 OpenStream 会失败并显示一个奇怪的错误代码,而 Pa_OpenDefaultStream 却能正常工作。

所以:

  • 为什么会失败?
  • 为什么会抛出错误的错误代码?

最佳答案

我假设您使用 C++(尽管您的代码中有几个奇怪的 andor。)

如果您的 for 循环没有找到任何满足 eviceInfo->maxOutputChannels > 0 && deviceInfo->name == outputDevicePaDeviceInfo ,那么您的 outputDeviceInfo 将被初始化。这意味着它的 channelConnect 可以有任何值,包括大的负值。然后 Pa_OpenStream 不会被调用,您的 errorOpening 也会被初始化。我敢打赌,当您将其输入 Pa_GetErrorText() 时,这就是 Invalid error code (value greater than zero) 的原因。

关于c++ - 错误的错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21479400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com