ALSA Api:如何同时播放两个波形文件? [英] ALSA Api: How to play two wave files simultaneously?

查看:46
本文介绍了ALSA Api:如何同时播放两个波形文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

播放重叠的两个独立波形文件所需的 API 配置/调用是什么?我试图这样做,我收到资源繁忙错误.一些解决问题的建议会很有帮助.

What is the required API configuration/call for playing two independent wavefiles overlapped ? I tried to do so , I am getting resource busy error. Some pointers to solve the problem will be very helpful.

以下是来自第二个wavefile的snd_pcm_prepare()的错误信息

Following is the error message from snd_pcm_prepare() of the second wavefile

"Device or resource busy"

推荐答案

ALSA 不提供混合器.如果您需要同时播放多个音频流,您需要自己将它们混合在一起.

ALSA does not provide a mixer. If you need to play multiple audio streams at the same time, you need to mix them together on your own.

最简单的方法是将 WAV 文件解码为 float 样本,添加它们,并在将它们转换回整数样本时剪辑它们.

The easiest way this can be accomplished is by decoding the WAV files to float samples, add them, and clip them when converting them back to integer samples.

或者,您可以尝试多次打开默认音频设备(而不是不是硬件设备,例如hw:0"),每次打开您希望的流播放,并希望 dmix ALSA 插件已加载并提供混音功能.

Alternatively, you can try to open the default audio device (and not a hardware device like "hw:0") multiple times, once for each stream you wish to play, and hope that the dmix ALSA plugin is loaded and will provide the mixing functionality.

这篇关于ALSA Api:如何同时播放两个波形文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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