DCP
DCP

Reputation: 131

Port Audio:How to solve the error of finding default devices in PortAudio(Windows)?

I want to run a PortAudio test program of generating and playing a Sine Wave. For that I have included all required header files. Infact the program compiles well but when I run it shows that "No Default Device found" in console. So, anybody can give me its solution.

OS:Windows 8.1

Coding Language:C

Below is the program:-

typedef struct
{
    float sine[TABLE_SIZE];
    int left_phase;
    int right_phase;
    char message[20];
}
paTestData;

static int patestCallback(...)//Callback Function
{....
}

static void StreamFinished( void* userData )
{
    paTestData *data = (paTestData *) userData;
    printf( "Stream Completed: %s\n", data->message );
}


int main(void)//main function
{
    PaStreamParameters outputParameters;
    PaStream *stream;
    PaError err;
    paTestData data;

    int i;

    printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n",       SAMPLE_RATE, FRAMES_PER_BUFFER);

    /* initialise sinusoidal wavetable */

    for( i=0; i<TABLE_SIZE; i++ )
    {
        data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
    }

    data.left_phase = data.right_phase = 0;

    err = Pa_Initialize();

    if( err != paNoError )
    {
        printf("Error in Initialize:-",err);
        goto error;
    }

    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output     device */

    if (outputParameters.device == paNoDevice)
    {
        fprintf(stderr,"Error: No default output device.\n");
        goto error;
    }

    outputParameters.channelCount = 2;       /* stereo output */
    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
    outputParameters.suggestedLatency = Pa_GetDeviceInfo(      outputParameters.device )->defaultLowOutputLatency;
    outputParameters.hostApiSpecificStreamInfo = NULL;

    err = Pa_OpenStream
    (
       &stream,
       NULL, /* no input */
       &outputParameters,
       SAMPLE_RATE,
       FRAMES_PER_BUFFER,
       paClipOff,      /* we won't output out of range samples so don't bother clipping them */
       patestCallback,
       &data
    );

    if( err != paNoError )
        goto error;

    sprintf( data.message, "No Message" );
    err = Pa_SetStreamFinishedCallback( stream, &StreamFinished );

    if( err != paNoError )
        goto error;

    err = Pa_StartStream( stream );

    if( err != paNoError )
        goto error;

    printf("Play for %d seconds.\n", NUM_SECONDS );
    Pa_Sleep( NUM_SECONDS * 1000 );

    err = Pa_StopStream( stream );

    if( err != paNoError )
        goto error;

    err = Pa_CloseStream( stream );

    if( err != paNoError )
        goto error;

    Pa_Terminate();
    printf("Test finished.\n");

    return err;

    error:
        Pa_Terminate();

    fprintf( stderr, "An error occured while using the portaudio stream\n" );
    fprintf( stderr, "Error number: %d\n", err );
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );

    return err;
}

And after compiling and Running I get the following output in the console:-

PortAudio Test: output sine wave. SR = 44100, BufSize = 64
Error: No default output device.
An error occured while using the portaudio stream
Error number: 0
Error message: Success

Process returned 0 (0x0)   execution time : 0.016 s
Press any key to continue.

Can anybody figure out the problem.

Upvotes: 0

Views: 4375

Answers (1)

Ross Bencina
Ross Bencina

Reputation: 4173

As a first step, check whether PortAudio has detected any devices. You can do this by printing the result of a call to Pa_GetDeviceCount(), or you can compile and run examples/pa_devs.c. pa_devs will give you the list of devices that PortAudio has detected. If the list is non-empty you can try to manually substitute the device index into outputParameters.device.

However, if there is no default device available then I suspect that you will find that there are no devices registered at all. In that case, the most likely cause is that the host APIs were not compiled in. You didn't say how you compiled PortAudio, but usually when you compile it from source you need to specify which host APIs to build by defining preprocessor symbols such as PA_USE_WMME or PA_USE_WASAPI (e.g. using -D flag to the compiler). There is a full list of the supported Windows preprocessor defines here.

There are detailed build instructions for various toolchains in the documentation.

Upvotes: 3

Related Questions