Wrong error code

Thomas Ayoub

I'm using portaudio to play a sound. I want to be able to select the output via the UI. I managed it like that :

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;

And it fails :

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

But I can't figure why OpenStream fails with a strange error code and Pa_OpenDefaultStream works like a charm.

So :

  • Why does it fails ?
  • Why does it throw a wrong error code ?
nodakai

I assume you use C++ (though there are several curious and and or in your code.)

If your for loop didn't find any PaDeviceInfo which satisfies eviceInfo->maxOutputChannels > 0 && deviceInfo->name == outputDevice, then your outputDeviceInfo is left un-initialized. That means its channelConnect can have any values including large negative values. Then Pa_OpenStream isn't invoked and your errorOpening is also left un-initialized. I bet that's the reason of Invalid error code (value greater than zero) when you feed it into Pa_GetErrorText().

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

what is wrong with this code it gives error

From Dev

plsql what is wrong with this code error 'INTO list is of wrong type'

From Dev

what is the wrong between this error and my code?

From Dev

Error in code; Getting wrong summation output

From Dev

PHP Code Returns Error Code 500. What's Wrong?

From Dev

PHP Code Returns Error Code 500. What's Wrong?

From Dev

Oracle SQL : Wrong error count per error code

From Dev

Oracle SQL : Wrong error count per error code

From Java

Webpack Code Splitting 'Loading chunk failed' error wrong file path

From Dev

What's wrong with my SQL code? Getting an error on last line

From Dev

Error in php code.Maybe my for loop is wrong?

From Dev

Stack level too deep error - what's wrong with this code?

From Dev

What's wrong with my java code? (parsing error)

From Dev

"Extra argument in call" i am having this error .... what is wrong with this code

From Dev

What's wrong with my SQL code? Getting an error on last line

From Dev

java while loop error? additional outputs what is the wrong with the code?

From Dev

What is wrong in my code? The program just terminates without error statement

From Dev

What is wrong with my SQLite code? The error i get: SQLite error near"name":syntax error

From Dev

Android code having error at the back-end. Yet I can't figure where the code goes wrong

From Dev

Error: $injector:modulerr Module Error seems there is an injection error in my directive but I don't understand whats wrong in my code

From Dev

javascript Whats wrong with this code

From Dev

Code executes condition wrong?

From Dev

Is the JIT generating the wrong code

From Dev

Is it a Wrong Code in MSDN?

From Dev

Something wrong with code

From Dev

What is the wrong with this verilog code?

From Dev

What is wrong with my code?

From Dev

What is wrong with this piece of code?

From Dev

Something is wrong with my code

Related Related

  1. 1

    what is wrong with this code it gives error

  2. 2

    plsql what is wrong with this code error 'INTO list is of wrong type'

  3. 3

    what is the wrong between this error and my code?

  4. 4

    Error in code; Getting wrong summation output

  5. 5

    PHP Code Returns Error Code 500. What's Wrong?

  6. 6

    PHP Code Returns Error Code 500. What's Wrong?

  7. 7

    Oracle SQL : Wrong error count per error code

  8. 8

    Oracle SQL : Wrong error count per error code

  9. 9

    Webpack Code Splitting 'Loading chunk failed' error wrong file path

  10. 10

    What's wrong with my SQL code? Getting an error on last line

  11. 11

    Error in php code.Maybe my for loop is wrong?

  12. 12

    Stack level too deep error - what's wrong with this code?

  13. 13

    What's wrong with my java code? (parsing error)

  14. 14

    "Extra argument in call" i am having this error .... what is wrong with this code

  15. 15

    What's wrong with my SQL code? Getting an error on last line

  16. 16

    java while loop error? additional outputs what is the wrong with the code?

  17. 17

    What is wrong in my code? The program just terminates without error statement

  18. 18

    What is wrong with my SQLite code? The error i get: SQLite error near"name":syntax error

  19. 19

    Android code having error at the back-end. Yet I can't figure where the code goes wrong

  20. 20

    Error: $injector:modulerr Module Error seems there is an injection error in my directive but I don't understand whats wrong in my code

  21. 21

    javascript Whats wrong with this code

  22. 22

    Code executes condition wrong?

  23. 23

    Is the JIT generating the wrong code

  24. 24

    Is it a Wrong Code in MSDN?

  25. 25

    Something wrong with code

  26. 26

    What is the wrong with this verilog code?

  27. 27

    What is wrong with my code?

  28. 28

    What is wrong with this piece of code?

  29. 29

    Something is wrong with my code

HotTag

Archive