Search code examples
c#naudio

Create silence WAVE stream with NAudio


Being new to NAudio and audio applications, I don't know exactly how to implement the following:

I want to make an empty (silence) wave stream and convert it to WaveChannel32, in order to feed it to a MultiplexingWaveProvider and mute one output channel. I tried it with a silence wav file and mutes successfully the output channel, but in the end I don't want to use a file in the application, but do it "on the fly". Any ideas?


Solution

  • You can make a silence producing IWaveProvider very easily. Create a class that implements IWaveProvider and in the Read method, always return the number of bytes asked for. Fill the buffer with zeros as well.

    Something like this will do for the Read method:

    public int Read(byte[] buffer, int offset, int count)
    {
       for(int n = 0; n < count; n++) buffer[offset++] = 0;
       return count;
    }