NeverMine17
NeverMine17

Reputation: 81

PortAudio: Device unavailable

What do I do wrong?
I have been trying to run this code but every time I run it, it says:
Error: Device unavailable
My Linux: Ubuntu 17.04. Any help?

#include <portaudio.h>
#include <iostream>

#define SAMPLE_RATE (48000)
static float *data;
PaStream *stream;

int callback(const void *pVoid, void *pVoid1, unsigned long i, const PaStreamCallbackTimeInfo *pInfo,
         PaStreamCallbackFlags i1, void *pVoid2);

int main() {
    PaError err;
    /* Open an audio I/O stream. */
    err = Pa_OpenDefaultStream(&stream,
                           0,          /* no input channels */
                           2,          /* stereo output */
                           paFloat32,  /* 32 bit floating point output */
                           SAMPLE_RATE,
                           paFramesPerBufferUnspecified, /* frames per buffer */
                           callback,   /* this is your callback function */
                           &data);     /*This is a pointer that will be passed to
                                               your callback*/
    if (err != paNoError) {
        std::cout << "Error: " << Pa_GetErrorText(err) << std::endl;
        auto a = Pa_GetLastHostErrorInfo();
        if (a->errorCode != 0) {
            std::cout << "Host error: " << a->errorText << std::endl;
        }
        return 1;
    }
return 0;
}

int callback(const void *pVoid, void *pVoid1, unsigned long i, const PaStreamCallbackTimeInfo *pInfo,
             PaStreamCallbackFlags i1, void *pVoid2) {
    // Do something with the stream...
    return 0;
}

I do not run any programs that use audio in any way.

Upvotes: 1

Views: 1524

Answers (1)

Lamda
Lamda

Reputation: 944

You should properly init before openening a stream, and start by debugging from there..

Here is an example you can work with.

Upvotes: 1

Related Questions