Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误代码_C++_C_Portaudio - Fatal编程技术网

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事实上,你是对的。问题来自于结构的部分初始化。