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 (将#修改为@)