using System; using NAudio.Utils; namespace NAudio.Wave.SampleProviders { /// /// Helper base class for classes converting to ISampleProvider /// public abstract class SampleProviderConverterBase : ISampleProvider { /// /// Source Wave Provider /// protected IWaveProvider source; private readonly WaveFormat waveFormat; /// /// Source buffer (to avoid constantly creating small buffers during playback) /// protected byte[] sourceBuffer; /// /// Initialises a new instance of SampleProviderConverterBase /// /// Source Wave provider public SampleProviderConverterBase(IWaveProvider source) { this.source = source; waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(source.WaveFormat.SampleRate, source.WaveFormat.Channels); } /// /// Wave format of this wave provider /// public WaveFormat WaveFormat => waveFormat; /// /// Reads samples from the source wave provider /// /// Sample buffer /// Offset into sample buffer /// Number of samples required /// Number of samples read public abstract int Read(float[] buffer, int offset, int count); /// /// Ensure the source buffer exists and is big enough /// /// Bytes required protected void EnsureSourceBuffer(int sourceBytesRequired) { sourceBuffer = BufferHelpers.Ensure(sourceBuffer, sourceBytesRequired); } } }