【问题标题】:PortAudio: Device unavailablePortAudio:设备不可用
【发布时间】:2017-07-24 11:59:54
【问题描述】:

我做错了什么?
我一直在尝试运行此代码,但每次运行时,它都会显示:
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;
}

我不运行任何以任何方式使用音频的程序。

【问题讨论】:

    标签: c++ portaudio


    【解决方案1】:

    你应该在打开一个流之前正确初始化,然后从那里开始调试..

    这是您可以使用的example。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-08
      • 2013-12-08
      • 1970-01-01
      • 2018-10-19
      • 2018-12-01
      • 2019-11-10
      • 1970-01-01
      • 2016-03-05
      相关资源
      最近更新 更多