Reputation: 81
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