using System; namespace NAudio.Wave.SampleProviders { /// /// Helper class turning an already 32 bit floating point IWaveProvider /// into an ISampleProvider - hopefully not needed for most applications /// public class WaveToSampleProvider : SampleProviderConverterBase { /// /// Initializes a new instance of the WaveToSampleProvider class /// /// Source wave provider, must be IEEE float public WaveToSampleProvider(IWaveProvider source) : base(source) { if (source.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) { throw new ArgumentException("Must be already floating point"); } } /// /// Reads from this provider /// public override int Read(float[] buffer, int offset, int count) { int bytesNeeded = count * 4; EnsureSourceBuffer(bytesNeeded); int bytesRead = source.Read(sourceBuffer, 0, bytesNeeded); int samplesRead = bytesRead / 4; int outputIndex = offset; for (int n = 0; n < bytesRead; n+=4) { buffer[outputIndex++] = BitConverter.ToSingle(sourceBuffer, n); } return samplesRead; } } }