Problem playing multiple wav files with 8000khz

Dec 24, 2009 at 2:27 PM
Edited Dec 25, 2009 at 9:20 AM


my intention is to play multiple wav files at the same time (I havent seen an example which does this)

So far I got it working, but only when using files with a samplerate of  44100, when using files with  8000 it plays back much to fast. So I'm missing a conversion, but where ? (all files are 16bit, 1 channel)

I want to use DirectSound.  

I use WaveMixerStream32  which  takes multiple WaveChannel32 objects.   The WaveChannel32 objects  I'm  creating via    "new WaveFileReader(fileName)".




Dec 31, 2009 at 12:21 PM

hi Henrik,

you can mix multiple streams at any sample rate, but they must all be of the same sample rate for things to work. You will have to post a bit more of your code to set up the WaveMixerStream32 for me to offer any more assistance



Dec 31, 2009 at 2:45 PM

Hi Mark, here's some code (only one file gets loaded):


   mixer = new WaveMixerStream32();
   waveOutDevice = new DirectSoundOut();

   sample = new AudioSample(fileName);****


**** AudioSample inherits from WaveStream and in its ctor:

     WaveStream readerStream = new WaveFileReader(fileName);

     WaveChannel32  inputStream = new WaveChannel32(readerStream);

This will make a file with 8khz 16Bit Mono play back much too fast. 

Or just look at the OpenSebJ  NAudio tutorial 3 project which also fails to play back a 8khz file correctly. 




Dec 31, 2009 at 2:57 PM

you are calling Init on the WaveOutDevice too early. At that point the mixer doesn't yet know what sample rate it will be operating at (will only know when you add the first input stream). You need to add the first mixer input before initializing the wave out device.


Dec 31, 2009 at 3:33 PM

As you suggested:





but with the same result : plays too fast !

Maybe because of this (?):

/// <summary>
        /// Creates a new 32 bit WaveMixerStream
        /// </summary>
        public WaveMixerStream32()
            this.autoStop = true;
            this.waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(44100, 2); // <--------
            this.bytesPerSample = 4;
            this.inputStreams = new List<WaveStream>();





Dec 31, 2009 at 4:39 PM

yes, but that should get overridden when you call AddInputStream.


public void AddInputStream(WaveStream waveStream)
            if (waveStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
                throw new ArgumentException("Must be IEEE floating point", "waveStream.WaveFormat");
            if (waveStream.WaveFormat.BitsPerSample != 32)
                throw new ArgumentException("Only 32 bit audio currently supported", "waveStream.WaveFormat");

            if (inputStreams.Count == 0)
                // first one - set the format
                int sampleRate = waveStream.WaveFormat.SampleRate;
                int channels = waveStream.WaveFormat.Channels;
                this.waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channels);


What does your AudioSample class return as its WaveFormat?



Jan 1, 2010 at 2:15 PM

Hi Mark,

now i got it (it was a stupid mistake) Thanks for your support!

So the conclusion is:  you'll have to dispose waveOutDevice and call Init() every time when loading  streams that have a different samplerate  than streams which were added before(and then removed via RemoveInputStream)



Jan 4, 2010 at 2:11 PM

ah, I see how you got the playback speed problem now. glad you have it working now