This project has moved and is read-only. For the latest updates, please go here.

Mixing and IWaveProviders

Jul 9, 2011 at 6:30 AM

I have been wading through some of the discussions here about streaming and mixing, and I think I'm stuck at the lack of a Mixer that handles IWaveProviders.

I am writing a library that records voice data via a WaveIn and sends it out over UDP. On the receiving end, I get these UDP packets and pass the payloads into my implementation of a BuferedWaveProvider, which would get sent to a WaveOut. Since I need to have multiple people talking at once, I have looked through the examples and used a WaveMixerStream32:

// Playback Mixer pipeline
internal static readonly WaveFormat MIX_FMT = new WaveFormat(22050, 1);
private readonly WaveMixerStream32 _mixer = new WaveMixerStream32();
private readonly WaveOut _out = new WaveOut() { NumberOfBuffers = 3 };
// Initialize the output mixer
//_out.DeviceNumber = _playDev.Index;
_out.DeviceNumber = -1;
_out.Volume = (PlayVolume / 100f);
_mixer.AutoStop = false;

Where things get hairy is when I start getting some data and need to add a stream to the WaveMixerStream32. Since it can't accept an IWaveProvider, I've written a WaveStream implementation that wraps my CircularBuffer, and converts it to a common format as described above, like so:

CircularBuffer buf = new CircularBuffer(_fmt.AverageBytesPerSecond * 5);
WaveStream ws = new WaveStreamBufferWrapper(_fmt, _buf);
WaveStream cws = new WaveFormatConversionStream(VoiceClient.MIX_FMT, ws);
WaveChannel ch32 = new WaveChannel32(cws);

I see that my BufferedWaveProvider is getting written to, but its Read() method is never called. There appears to be data if I call ws.TotalTime, but interestingly ch32.TotalTime is 0:00 (is that why the MixerStream never calls Read?) 

Is there a proper way to convert an IWaveProvider into a WaveStream? I seem to be doing it wrong.



Jul 9, 2011 at 9:02 PM

hi Luke,

I saw you also asked this on StackOverflow, so I answered there