gpt4 book ai didi

audio - CSCore - 将立体声转换为环绕声

转载 作者:行者123 更新时间:2023-12-02 23:11:17 24 4
gpt4 key购买 nike

我必须解码立体声 mp4 文件并将 L 和 R 声道映射到 5.1 or 7.1 surround .另外我必须提供一个特定的输出格式:16bit pcm 44.1kHz .
将音频源转换为44100Hz 16bit 没有问题.唯一的问题是 channel 混合。
我有以下编码:

const string filename = @"stereo.mp3";
IWaveSource waveSource = CodecFactory.Instance.GetCodec(filename)
.AppendSource(x => new CSCore.Streams.CachedSoundSource(x))
.ChangeSampleRate(44100) //44.1kHz
.ToSampleSource()
.ToWaveSource(16); //16bit

官方项目页面在这里: http://cscore.codeplex.com/告诉我 channel 混合是可能的。我找到了 CSCore.DSP.ChannelMatrix类,但很难弄清楚如何使用它。
也许有人可以帮助我?

最佳答案

你是绝对正确的,你必须使用 CSCore.DSP.ChannelMatrix类(class)。
我为您创建了一个小示例并添加了一些评论。它应该是自我解释的:

static void Main(string[] args)
{
const string filename = @"stereo.mp3";

/*
* First of all you need a channel matrix that fits your needs.
* There are many ways to get one...:
*/

//Simply use one of the predefined...
ChannelMatrix channelMatrix = ChannelMatrix.StereoToSevenDotOneSurround;

//or

//use some kind of factory to get one
channelMatrix = ChannelMatrix.GetMatrix(
ChannelMasks.StereoMask,
ChannelMasks.SevenDotOneMask);

//or

//or create your own one (the matrix below equals the two above but of course you can use custom values)
//the rows represent your input channels (the stereo signal) and the columns your output channels.
//specify with a value from 0-1 how much percentage of the L (row index 0) or the R (row index 1) channel
//you want to apply to the specific column (the columns are getting mapped to the output channel mask
// -> the SevenDotOneMask ordered by the values of the certain flags inside of the channel mask).
channelMatrix = new ChannelMatrix(
ChannelMasks.StereoMask,
ChannelMasks.SevenDotOneMask);
channelMatrix.SetMatrix(
new[,]
{
{0.222f, 0f, 0.157f, 0.022f, 0.189f, 0.116f, 0.203f, 0.090f},
{0f, 0.222f, 0.157f, 0.022f, 0.116f, 0.189f, 0.090f, 0.203f}
});

IWaveSource waveSource = CodecFactory.Instance.GetCodec(filename)
.AppendSource(x => new CSCore.Streams.CachedSoundSource(x))
.ChangeSampleRate(44100) //44.1kHz
.AppendSource(x => new DmoChannelResampler(x, channelMatrix)) //append a channelresampler with the channelmatrix
.ToSampleSource()
.ToWaveSource(16); //16bit

...
}

我强烈建议您使用预定义的 channel 矩阵。
当然,如果您需要一些自定义值,请在上面的示例中定义您自己的值。

顺便提一句。您还可以实时更改 channel 矩阵:
只需对 channelMatrix 进行更改即可之后调用 CommitChannelMatrixChanges (当然,您必须存储 DmoChannelResampler 实例 -> 使用 out parameter 方法的 AppendSource 来做到这一点)。

关于audio - CSCore - 将立体声转换为环绕声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30742321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com