This project has moved. For the latest updates, please go here.

MultiplexingWaveProvider problem

Oct 8, 2013 at 10:00 AM
Hi,

I'm having an issue with the MultiplexingWaveProvider class. I have the following scenario:
I have multiple incoming IWaveProvider streams (all mono with 1 channel and 16bit rate) and must mix them so that the user can hear them in the right or left or both sides of his/her headphone. So I created two MixingWaveProvider32 object, one for each side and created a MultiplexingWaveProvider with the two MixingWaveProviders32s. However when the same IWaveProvider is added to both MixingWaveProvider32s on one side it can be heard clearly, but on the other side it is just noise. I think it is because of the MultiplexingWaveProviders Read method, but I'm not sure. Can you help me out?

Regards,
Istvan
Coordinator
Oct 8, 2013 at 11:54 AM
you can't pass the same IWaveProvider in twice. When the Read method is called, it doesn't know who is calling it, so it just returns the next block of data. You'd need to come up with some way to buffer the data allowing it to be read twice. Two BufferedWaveProviders wouldn't be a bad way to approach this.
Oct 9, 2013 at 6:46 AM
Thanks, that helped me out.

Have another question though, to be able to mix the channels, I need to convert them to IEEE floating point. Isn't there a Mixer that can handle PCM mono streams?
Coordinator
Oct 9, 2013 at 7:36 AM
no, you really want to be mixing at IEEE floating point. NAudio has loads of converters that can get you from PCM WaveProviders to SampleProviders, then you can use MixingSampleProvider and MultiplexingSampleProvider.
Oct 9, 2013 at 7:49 AM
Ok, but can't I use the MixingWaveProvider32 and MultiplexingWaveProvider classes? Should I use the SampleProvider counterparts? And what is the difference between the WaveProvider and SampleProvider classes (for example MultiplexingWaveProvider and MultiplexingSampleProvider).
Coordinator
Oct 9, 2013 at 10:01 AM
ISampleProvider deals with float[] while IWaveProvider deals with byte[]. ISampleProvider is always IEEE float samples, whilst IWaveProvider could be anything (PCM 16 or 24 bit, G.711, IEEE float etc). You'll find ISampleProvider is much more straightforward to work with and create your own classes.

I'm currently working on a Pluralsight course in which I go into a lot of detail about this, so keep an eye out on this site or my blog and I'll announce it.
Oct 9, 2013 at 10:53 AM
With IWaveProvider you can use WaveOut or WaveOutEvent. What can you use instead of this class with ISampleProviders?
Coordinator
Oct 9, 2013 at 10:56 AM
at the end of your signal chain, use a SampleToWaveProvider16 to go back to 16 bit PCM (or just a SampleToWaveProvider to stay at IEEE float). The next NAudio will have some extension methods that make this a lot easier.