using System; using System.Collections.Generic; using System.Text; namespace NAudio.Wave { /// /// Base class for creating a 16 bit wave provider /// public abstract class WaveProvider16 : IWaveProvider { private WaveFormat waveFormat; /// /// Initializes a new instance of the WaveProvider16 class /// defaulting to 44.1kHz mono /// public WaveProvider16() : this(44100, 1) { } /// /// Initializes a new instance of the WaveProvider16 class with the specified /// sample rate and number of channels /// public WaveProvider16(int sampleRate, int channels) { SetWaveFormat(sampleRate, channels); } /// /// Allows you to specify the sample rate and channels for this WaveProvider /// (should be initialised before you pass it to a wave player) /// public void SetWaveFormat(int sampleRate, int channels) { this.waveFormat = new WaveFormat(sampleRate, 16, channels); } /// /// Implements the Read method of IWaveProvider by delegating to the abstract /// Read method taking a short array /// public int Read(byte[] buffer, int offset, int count) { WaveBuffer waveBuffer = new WaveBuffer(buffer); int samplesRequired = count / 2; int samplesRead = Read(waveBuffer.ShortBuffer, offset / 2, samplesRequired); return samplesRead * 2; } /// /// Method to override in derived classes /// Supply the requested number of samples into the buffer /// public abstract int Read(short[] buffer, int offset, int sampleCount); /// /// The Wave Format /// public WaveFormat WaveFormat { get { return waveFormat; } } } }