错误的错误代码

托马斯·阿尤布

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;

它失败了:

无法打开所选设备(“ Sortieintégr”),切换到默认设备。错误:无效的错误代码(值大于零)

但是我不知道为什么会OpenStream失败,并显示一个奇怪的错误代码,并且Pa_OpenDefaultStream像魅力一样工作。

因此:

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

我假设你使用C ++(虽然有一些好奇and,并or在你的代码。)

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章