Example #1
0
        /// <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 if (waveProvider.WaveFormat.BitsPerSample == 32)
                {
                    sampleProvider = new Pcm32BitToSampleProvider(waveProvider);
                }
                else
                {
                    throw new InvalidOperationException("Unsupported operation");
                }
            }
            else if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
            {
                if (waveProvider.WaveFormat.BitsPerSample == 64)
                {
                    sampleProvider = new WaveToSampleProvider64(waveProvider);
                }
                else
                {
                    sampleProvider = new WaveToSampleProvider(waveProvider);
                }
            }
            else
            {
                throw new ArgumentException("Unsupported source encoding");
            }
            return(sampleProvider);
        }
Example #2
0
        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>
 /// 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 if (waveProvider.WaveFormat.BitsPerSample == 32)
         {
             sampleProvider = new Pcm32BitToSampleProvider(waveProvider);
         }
         else
         {
             throw new InvalidOperationException("Unsupported bit depth");
         }
     }
     else if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
     {
         if (waveProvider.WaveFormat.BitsPerSample == 64)
             sampleProvider = new WaveToSampleProvider64(waveProvider);
         else
             sampleProvider = new WaveToSampleProvider(waveProvider);
     }
     else
     {
         throw new ArgumentException("Unsupported source encoding");
     }
     return sampleProvider;
 }