我必须解码一个立体声mp4文件,并将L和R声道映射到5.1 or 7.1 surround。此外,我还必须提供一个特定的输出格式:16bit pcm 44.1kHz。将音频源转换为44100Hz 16bit没有问题。唯一的问题是通道混合。我得到了以下代码:
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/告诉我频道混合是可能的。我已经找到了CSCore.DSP.ChannelMatrix类,但很难弄清楚如何使用它。也许有人能帮我一下?
发布于 2015-06-10 04:53:07
您完全正确,您必须使用CSCore.DSP.ChannelMatrix类。我已经为您创建了一个小示例,并添加了一些注释。这应该不言自明:
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
...
}我强烈建议您使用预定义的通道矩阵。当然,如果你需要一些自定义的值,你可以像上面的例子一样定义你自己的值。
顺便说一句。您还可以实时更改通道矩阵:只需对channelMatrix进行更改,然后调用CommitChannelMatrixChanges (当然,您必须存储DmoChannelResampler实例->,通过使用AppendSource方法的out parameter来完成此操作)。
https://stackoverflow.com/questions/30742321
复制相似问题