首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PortAudio:设备不可用

PortAudio:设备不可用
EN

Stack Overflow用户
提问于 2017-07-24 19:59:55
回答 1查看 938关注 0票数 0

我做错了什么?

我一直在尝试运行这段代码,但每次我运行它时,它都会说:

Error: Device unavailable

我的Linux: Ubuntu 17.04。有什么帮助吗?

代码语言:javascript
复制
#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;
}

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

EN

回答 1

Stack Overflow用户

发布于 2017-11-02 21:04:01

您应该在打开一个流之前正确地初始化它,并从那里开始调试。

这是一个您可以使用的example

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45280083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档