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

Clicking noise at end of wave file

Feb 3, 2010 at 5:48 PM

I am using the WaveOut class to play a series of wav files back-to-back.  Everything works great except for there is a rather loud click/screetch sound as each wav file reaches the end.  Has anyone found a way around this?

Here is my derived class that I'm using to host each wav file and play it  back:

 

    public class CIAudioBuffer : NAudio.Wave.WaveOut   

    {
        public EventHandler MediaOpened;
        public EventHandler MediaEnded;
        private NAudio.Wave.WaveFileReader sourceStream;
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }

        public CIAudioBuffer()
        {
            Volume = 0.75f; //default to 75% volume
            this.PlaybackStopped += (o, e) =>
                {
                    if (MediaEnded != null)
                        MediaEnded(this, new EventArgs());
                };
        }

        public void Open(string filename)
        {
            sourceStream = new NAudio.Wave.WaveFileReader(filename);
            this.Init(sourceStream);
            HasAudio = true;
            if (MediaOpened != null)
                MediaOpened(this, new EventArgs());
        }

        public bool HasAudio { get; private set; }

        public TimeSpan Position
        {
            get
            {
                double pos = (double)sourceStream.Position / sourceStream.Length;
                return TimeSpan.FromSeconds(CIAudioPlayer.DEFAULT_BUFFER_SECONDS * pos);
            }
            set
            {
                if (sourceStream != null)
                {
                    double total = EndTime.Subtract(StartTime).TotalSeconds;
                    double seconds = value.TotalSeconds / total;
                    sourceStream.Position = (long)(seconds * sourceStream.Length);
                    if (MediaOpened != null)
                        MediaOpened(this, new EventArgs());
                }
            }
        }
    }

Mar 25, 2010 at 5:49 PM

I can't see anything obviously wrong. Do your WAV files play correctly in the NAudio demo application?

Mark