我做错了什么?
我一直试图运行这个代码,但每次运行它时都会说:
Error: Device unavailable
我的Linux:Ubuntu 17.04。
有什么帮助吗?
#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;
}
我没有运行任何以任何方式使用音频的程序。