如何解决Opus / libopus 从 N 通道缩混到 1
我主要处理 N=2 和 N=3 的案例。我正在尝试将 2 通道或 3 通道 PCM 音频缩混为单声道。如果输入/输出都是单声道,我的代码工作正常。但我在缩混方面失败了。
目前我的 N=2 代码是:
int error = 0;
unsigned char mapping[255];
memset(mapping,255);
OpusMSEncoder* opusME = opus_multistream_encoder_create(
48000,2,1,mapping,OPUS_APPLICATION_AUDIO,&error);
// verified that error == OPUS_OK
// when I'm encoding,my input is
float interleaved[4096]
unsigned char out[4096];
int returnValue = opus_multistream_encode_float(
opusME,interleaved,960,out,4096);
// the returnValue is usually around 50,meaning I encoded 960 PCM samples into 50 bytes.
// if I now decode the 50 bytes as a mono PCM and play it,I hear gibberish.
// if I create an opusME for mono input and mono output,and have interleaved contain
// just one channel of data,then the encode and decode and playing of audio works fine
interleaved 的布局是 [从通道 1 浮动][从通道 2 浮动][从通道 1 浮动][从通道 2 浮动] ...
对于 N=3 的情况,浮点数来自通道 123123123...
但是当我对此进行编码,然后对其进行解码(解码为单声道流)时。我只是胡言乱语。
以前,我在 ffmpeg 中使用了“amix”过滤器,效果很好。但是,我正在尝试减少开销,所以现在我直接使用 libopus 1.3.1,而不涉及 ffmpeg,更不用说我不需要来自 amix 的任何花哨的功能,例如权重。
我尝试了各种映射值,但老实说,对于 2 个输入通道,可能性并不多。
opus_multistream_encode_float 是否没有达到我所期望的效果,即从 N 个流缩混为单声道音频?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。