Reputation: 21
I have a requirement to play the sound (.wav file) only on the left channel of teh headphone and another file to play only on the right channel of the headphone. I am new to c #, please help me out to solve this problem.
Upvotes: 2
Views: 2896
Reputation: 631
var input2 = new Mp3FileReader(@"C:\Users\Public\Music\Sample Music\Kalimba.mp3");
var input1 = new Mp3FileReader(@"C:\Users\Public\Music\Sample Music\Maid with the Flaxen Hair.mp3");
MultiplexingWaveProvider waveProvider = new MultiplexingWaveProvider(new IWaveProvider[] { input1, input2 }, 2);
waveProvider.ConnectInputToOutput(1, 1);
WaveOut wave = new WaveOut();
wave.Init(waveProvider);
wave.Play();
I just added the following lines to the above code and it works with 2 channels
waveProvider.ConnectInputToOutput(1, 0);
waveProvider.ConnectInputToOutput(3, 1);
and removed
waveProvider.ConnectInputToOutput(1, 1);
Upvotes: 1
Reputation: 1510
This article on the code project shows a way to visualize audio. If you can actively visualize audio you will understand that your common stereo wave file contains two channels (A left and a right channel). With that information on how to visualize it you can easily adapt the stream to destroy the left channel (E.G. put zero's in the left stream/right stream). And thus when you would play it the regular way after that it would only play music in the left or the right ear.
The above is the easy part when you have a stereo file which has two equal channels. There is also the case where your stereo file has different channels (E.G. a guitar on the left ear a drum on the right ear.) In that case you will have to merge two channels to one channel, find duplicate information and finally destroy the other channel you don't want to use.)
The third possibility is your audio file is mono and thus only has one channel. Normally your computer will automatically duplicate the channel from a mono file to a stereo file. So it plays on both ears/speakers. Thus we will never here that the file is mono. However in programming if you would want to make it play on just one ear/channel. You would have to manually convert it to a stereo file (by adding a blank channel). And then again you would have sound on just one ear/speaker.
Hope this helps.
Upvotes: 0
Reputation: 2639
I don't think that WPF alone can do that, but you might want to check out NAudio.
Upvotes: 2