/// <summary> /// Helper function to go from IWaveProvider to a SampleProvider /// Must already be PCM or IEEE float /// </summary> /// <param name="waveProvider">The WaveProvider to convert</param> /// <returns>A sample provider</returns> public static ISampleProvider ConvertWaveProviderIntoSampleProvider(IWaveProvider waveProvider) { ISampleProvider sampleProvider; if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.Pcm) { // go to float if (waveProvider.WaveFormat.BitsPerSample == 8) { sampleProvider = new Pcm8BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 16) { sampleProvider = new Pcm16BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 24) { sampleProvider = new Pcm24BitToSampleProvider(waveProvider); } else { throw new InvalidOperationException("Unsupported operation"); } } else if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat) { sampleProvider = new WaveToSampleProvider(waveProvider); } else { throw new ArgumentException("Unsupported source encoding"); } return sampleProvider; }
/// <summary> /// Helper function to go from IWaveProvider to a SampleProvider /// Must already be PCM or IEEE float /// </summary> /// <param name="waveProvider">The WaveProvider to convert</param> /// <returns>A sample provider</returns> public static ISampleProvider ConvertWaveProviderIntoSampleProvider(IWaveProvider waveProvider) { ISampleProvider sampleProvider; if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.Pcm) { // go to float if (waveProvider.WaveFormat.BitsPerSample == 8) { sampleProvider = new Pcm8BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 16) { sampleProvider = new Pcm16BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 24) { sampleProvider = new Pcm24BitToSampleProvider(waveProvider); } else { throw new InvalidOperationException("Unsupported operation"); } } else if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat) { sampleProvider = new WaveToSampleProvider(waveProvider); } else { throw new ArgumentException("Unsupported source encoding"); } return(sampleProvider); }
public static ISampleProvider ConvertWaveProviderIntoSampleProvider(IWaveProvider waveProvider) { ISampleProvider result; if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.Pcm) { if (waveProvider.WaveFormat.BitsPerSample == 8) { result = new Pcm8BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 16) { result = new Pcm16BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 24) { result = new Pcm24BitToSampleProvider(waveProvider); } else { if (waveProvider.WaveFormat.BitsPerSample != 32) { throw new InvalidOperationException("Unsupported bit depth"); } result = new Pcm32BitToSampleProvider(waveProvider); } } else { if (waveProvider.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) { throw new ArgumentException("Unsupported source encoding"); } if (waveProvider.WaveFormat.BitsPerSample == 64) { result = new WaveToSampleProvider64(waveProvider); } else { result = new WaveToSampleProvider(waveProvider); } } return(result); }
/// <summary> /// Initialises a new instance of SampleChannel /// </summary> /// <param name="waveProvider">Source wave provider, must be PCM or IEEE</param> public SampleChannel(IWaveProvider waveProvider) { ISampleProvider sampleProvider; if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.Pcm) { // go to float if (waveProvider.WaveFormat.BitsPerSample == 8) { sampleProvider = new Pcm8BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 16) { sampleProvider = new Pcm16BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 24) { sampleProvider = new Pcm24BitToSampleProvider(waveProvider); } else { throw new InvalidOperationException("Unsupported operation"); } } else if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat) { sampleProvider = new WaveToSampleProvider(waveProvider); } else { throw new ArgumentException("Unsupported source encoding"); } if (sampleProvider.WaveFormat.Channels == 1) { sampleProvider = new MonoToStereoSampleProvider(sampleProvider); } this.waveFormat = sampleProvider.WaveFormat; // let's put the meter before the volume (useful for drawing waveforms) this.preVolumeMeter = new MeteringSampleProvider(sampleProvider); this.volumeProvider = new VolumeSampleProvider(preVolumeMeter); }