c++ - Debian 上的音频采样

标签 c++ audio debian alsa

我们正在运行带有 ALSA 的 Debian,我们需要从我们的音频输入线中提取音频样本。我们希望能够用这些样本填充缓冲区,以便在它们到来时对它们执行操作。

我们已经尝试直接查看 ALSA 调用,但我们遇到了折旧函数的问题,因为那里的很多资源都非常陈旧。

关于这个问题的方向有什么好的引用或建议吗?

最佳答案

使用一些最新的例子,像这样:

#include <alsa/asoundlib.h>

static char *device = "default"; /* capture device */

unsigned short buffer[2 * 24000];

int main(void)
{
    int err;
    snd_pcm_t *handle;
    snd_pcm_sframes_t frames;

    if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
        printf("open error: %s\n", snd_strerror(err));
        exit(EXIT_FAILURE);
    }
    if ((err = snd_pcm_set_params(handle,
                                  SND_PCM_FORMAT_S16,
                                  SND_PCM_ACCESS_RW_INTERLEAVED,
                                  2,
                                  48000,
                                  1,
                                  500000)) < 0) { /* 0.5 sec */
        printf(" open error: %s\n", snd_strerror(err));
        exit(EXIT_FAILURE);
    }

    for (;;) {
        frames = snd_pcm_readi(handle, buffer, 24000);
        if (frames < 0)
            frames = snd_pcm_recover(handle, frames, 0);
        if (frames < 0) {
            printf("snd_pcm_readi failed: %s\n", snd_strerror(err));
            break;
        }

        // ...
    }

    snd_pcm_close(handle);
    return 0;
}

关于c++ - Debian 上的音频采样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15961343/

相关文章:

python - Librosa - 如何为立体声音频创建梅尔频谱图?

c++ - 您如何在mciSendString中使用变量代替体积? C++

linux - Bash 找不到现有文件

linux - 速度测试消耗多少带宽?

c++ - 克利翁 : Debug into cpp class

c++ - 为什么必须在何处以及为什么要放置"template"和"typename"关键字?

c++ - 作为函数模板参数的基本类型

audio - 是否有使用频率对数除法的 FFT?

pip - 为什么 'pip3 install netifaces' 在 Debian 10 Buster 上失败?

c++ - 如何传递指针 vector 以便在函数中更改它们?