using System; namespace NAudio.Wave.SampleProviders { /// /// Helper class for when you need to convert back to an IWaveProvider from /// an ISampleProvider. Keeps it as IEEE float /// public class SampleToWaveProvider : IWaveProvider { private readonly ISampleProvider source; /// /// Initializes a new instance of the WaveProviderFloatToWaveProvider class /// /// Source wave provider public SampleToWaveProvider(ISampleProvider source) { if (source.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) { throw new ArgumentException("Must be already floating point"); } this.source = source; } /// /// Reads from this provider /// public int Read(byte[] buffer, int offset, int count) { int samplesNeeded = count / 4; var wb = new WaveBuffer(buffer); int samplesRead = source.Read(wb.FloatBuffer, offset / 4, samplesNeeded); return samplesRead * 4; } /// /// The waveformat of this WaveProvider (same as the source) /// public WaveFormat WaveFormat => source.WaveFormat; } }