ALSA:不支持非交错访问吗? [英] ALSA: non-interleaved access not supported?

查看:86
本文介绍了ALSA:不支持非交错访问吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ALSA的时,a>函数失败SND_PCM_ACCESS_RW_NONINTERLEAVED访问类型,报告存在无效的参数.相同的代码与 SND_PCM_AESS访问.

ALSA's snd_pcm_hw_params_set_access function fails when called with SND_PCM_ACCESS_RW_NONINTERLEAVED access type, reporting that there was an invalid argument. The same code works fine with SND_PCM_ACCESS_RW_INTERLEAVED access.

我试图更改对snd_pcm_hw_params_ *函数的调用顺序,但没有任何效果.

I tried to change the order of calls to snd_pcm_hw_params_* functions with no effect.

接下来,我认为我的硬件可能不支持非交错播放,但是根据

Next I thought that my hardware might not support non-interleaved playback, but according to this post ALSA subsystem will interleave non-interleaved data before sending it to the hardware if it does not support non-interleaved playback itself. Thus, non-interleaved access should always be available.

那为什么为什么不支持不交错的访问呢?

Why is it then, that non-interleaved access seems not be unsupported?

以下是适用于交错播放的代码,但对于非交错播放会产生此问题:

Following is the code that works fine for interleaved playback, but produces this problem for non-interleaved playback:

int err;
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) {
    fprintf(stderr, "ALSA: allocate hw_params error: %s\n", snd_strerror(err));
    throw 5;
}
if ((err = snd_pcm_hw_params_any(pb_dev, hw_params)) < 0) {
    fprintf(stderr, "ALSA: hw_params_any error: %s\n", snd_strerror(err));
    throw 5;
}
if ((err = snd_pcm_hw_params_set_access(pb_dev, hw_params, (pAudioCtx->sample_fmt < AV_SAMPLE_FMT_U8P) ? SND_PCM_ACCESS_RW_INTERLEAVED : SND_PCM_ACCESS_RW_NONINTERLEAVED)) < 0) {
    fprintf(stderr, "ALSA: set access type error: %s\n", snd_strerror(err));
    throw 5;
}
if ((err = snd_pcm_hw_params_set_channels(pb_dev, hw_params, pAudioCtx->channels)) < 0) {
    fprintf(stderr, "ALSA: set channel count error: %s\n", snd_strerror(err));
    throw 5;
}

snd_pcm_format_t sample_format;
switch (pAudioCtx->sample_fmt) {
    case AV_SAMPLE_FMT_U8: case AV_SAMPLE_FMT_U8P: sample_format = SND_PCM_FORMAT_U8; break;
    case AV_SAMPLE_FMT_S16: case AV_SAMPLE_FMT_S16P: sample_format = SND_PCM_FORMAT_S16; break;
    case AV_SAMPLE_FMT_S32: case AV_SAMPLE_FMT_S32P: sample_format = SND_PCM_FORMAT_S32; break;
    case AV_SAMPLE_FMT_FLT: case AV_SAMPLE_FMT_FLTP: sample_format = SND_PCM_FORMAT_FLOAT; break;
    case AV_SAMPLE_FMT_DBL: case AV_SAMPLE_FMT_DBLP: sample_format = SND_PCM_FORMAT_FLOAT64; break;
    default: fprintf(stderr, "sampleformat %d is not supported\n", pAudioCtx->sample_fmt);
        throw 5;
}

if ((err = snd_pcm_hw_params_set_format(pb_dev, hw_params, sample_format)) < 0) {
    fprintf(stderr, "ALSA: set sample format error: %s\n", snd_strerror(err));
    throw 5;
}
if ((err = snd_pcm_hw_params_set_rate_near(pb_dev, hw_params, (unsigned int*)&pAudioCtx->sample_rate, 0)) < 0) {
    fprintf(stderr, "ALSA: set sample rate error: %s\n", snd_strerror(err));
    throw 5;
}

if ((err = snd_pcm_hw_params(pb_dev, hw_params)) < 0) {
    fprintf(stderr, "ALSA: set parameters error: %s\n", snd_strerror(err));
    throw 5;
}

执行此操作将产生以下输出:

Executing this yields following output:

ALSA: set access type error: Invalid argument

推荐答案

hw_params_set _ * 函数仅接受设备支持的那些值.

The hw_params_set_* functions accept only those values that are supported by the device.

大多数默认设备( plughw default 等)支持自动转换,因此可以接受所有格式.硬件设备没有.

Most of the default devices (plughw, default, etc.) support automatic conversions, and thus accept all formats. hw devices do not.

这篇关于ALSA:不支持非交错访问吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆