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

Can NAudio WaveOut Filter channel data for stereo wave?

Apr 9, 2013 at 4:46 AM
Hi,
I will use NAudio in my project and I got a problem now.

I want WaveOut to play only one channel data (eg. right channel) when WaveStream is a stereo wave stream (mp3 encoding). How I can let WaveOut to filter it?
Regards!
Apr 9, 2013 at 10:56 AM
Not WaveOut will filter this. You have to convert the stream first into mono and then play it.
You can use the SteroToMonoProvider but this will mix both channels together. I don't know whether something like this already exists. If not you will have to write your own provider.
Apr 10, 2013 at 2:57 AM
Edited Apr 10, 2013 at 3:02 AM
Thanks for your reply!

I try to update WaveOut and its WaveOutBuffer source code like this:

WaveOutBuffer.cs

/// this is called by the WAVE callback and should be used to refill the buffer
    internal bool OnDone()
    {
        int bytes;
        lock (waveStream)
        {
            bytes = waveStream.Read(buffer, 0, buffer.Length);
        }
        if (bytes == 0)
        {
            return false;
        }
        else
        {
            //Edit by charley at 2013/4/9
            //左右声道是交替出现的,所以在间隔处用0填充
            if (VolumnMode != 1)
            {
                for (int i = 0; i < bytes - 1; i += mVolumnSize)
                {
                    if (VolumnMode == 2)
                    {
                        for (int j = 0; j < mVolumnSize; j++)
                        {
                            buffer[i + j] = mLeftVolumn ? buffer[i + j] : (byte)0;
                        }
                        mLeftVolumn = !mLeftVolumn;
                    }
                    if (VolumnMode == 3)
                    {
                        for (int j = 0; j < mVolumnSize; j++)
                        {
                            buffer[i + j] = !mLeftVolumn ? buffer[i + j] : (byte)0;
                        }
                        mLeftVolumn = !mLeftVolumn;
                    }
                }
            }

            for (int n = bytes; n < buffer.Length; n++)
            {
                buffer[n] = 0;
            }
        }
        WriteToWaveOut();
        return true;
    }
Not well but can meet my requirement.

Any other method and how to write new provider?

Note:

I want to control each channel when wave playing.