I have to decode a stereo mp4 file and map the L and R channel to 5.1 or 7.1 surround
. In addition I have to provide a specific output format: 16bit pcm 44.1kHz
.
Its no problem to convert the audio source to 44100Hz 16bit
. The only problem is the channel mixing.
I've got the following coding:
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
The official project page here: http://cscore.codeplex.com/ tells me that channel mixing is possible. I've found the CSCore.DSP.ChannelMatrix
class but its pretty hard to figure out how to use it.
Maybe someone could help me out?
You are absolutely right, you have to use the CSCore.DSP.ChannelMatrix class. I've created a little example for you and added some comments. It should be pretty much self explaining:
I would strongly recommend you to use a predefined channel matrix. Of course, if you need some custom values define your own like in the example above.
Btw. you can also change the channel matrix in realtime: Simply make your changes to the
channelMatrix
and after that call CommitChannelMatrixChanges (of course you would have to store theDmoChannelResampler
instance -> do that by using theout parameter
of theAppendSource
method).