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

Problem with large wave file playback

Sep 5, 2012 at 2:37 PM
Edited Sep 5, 2012 at 2:41 PM

I have been working on an audio player based on tutorials from OpenSebj and NAudio and right now I'm trying to put together a mixer that will mix large wave streams.

The wave files are in MuLaw format and I converted them to PCM via WaveFileConversionStream.CreatePcmStream

See the code below:

 public AudioSample(string fileName)
      file_name = fileName;
      WaveStream file_stream = new WaveFileReader(file_name);
      if (file_stream.WaveFormat.Encoding != WaveFormatEncoding.Pcm && file_stream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
          file_stream = WaveFormatConversionStream.CreatePcmStream(file_stream);
          file_stream = new BlockAlignReductionStream(file_stream);
       offset_stream = new WaveOffsetStream(file_stream);
       channel_stream = new WaveChannel32(offset_stream);
       muted = false;
       volume = 1.0f;          

The problem I'm having is here:       mixer = new WaveMixerStream32();

The wave file is 10 mins long and the playback is extremely fast. While debugging I noticed
After the PCM conversion, the WaveMixerStream32() converts to IeeeFloat.
So I go from MuLaw --> PCM --> IeeeFloat. I believe this is where I'm getting the alvin & the chipmunks
super fast playback from. If this is the case I believe I can fix it by modifying the WaveChannel32 class
so that it doesn't convert to IeeeFloat, but I wanted to make sure I was on the right track.

Any helpful insight would be very much appreciated.

Sep 5, 2012 at 4:07 PM

the whole point of WaveChannel32 is to convert to IeeeFloat. If you just want to play the audio directly, there is no need for the WaveOffsetStream, WaveChannel32, or WaveMixerStream32. Also, those tutorials are very old. It would be better to look at the NAudioDemo source code for examples of how to do playback.


Sep 5, 2012 at 5:18 PM

Thanks for the quick reply!

I have looked through the source code, and I'm not actually trying to do a direct playback. I am eventually going to add features that allow me to speed up and slow down playback and I don't think this can be done without buffers.

My goal at this point is the ability to mix say 10 audio files and play them back simultaneously. I've looked through the MixDiff project and doesn't seem to do this currently.

Any other advice or tips on how I could accomplish this?

Sep 6, 2012 at 3:32 PM

Just wanted to update this thread. I resolved the issue and it seems I wasn't disposing the DirectSound device which resulted in the fast playback. Again, thanks for the help.

Sep 7, 2012 at 2:10 PM

glad you got it working in the end