Static methods to convert between different sample formats.

Code is mainly based on information available on the original C source code pa_converters.c from Portable Audio I/O Library.

This class try to be as fast as possible without using unsafe code.

Dither isn't currently supported. Currently supported conversions are 'to' and 'from' conversions between the following most common PCM format:

Integer 8-bit (byte) Integer 16-bit (Int16) Integer 32-bit (Int32) Single precision 32-bit floating point (float)

示例#1
0
        /// <summary>
        ///   Copies this signal to a given array.
        /// </summary>
        ///
        public void CopyTo(double[] array)
        {
            if (format == Audio.SampleFormat.Format64BitIeeeFloat)
            {
                Buffer.BlockCopy(rawData, 0, array, 0, rawData.Length);
            }
            else if (format == Audio.SampleFormat.Format32BitIeeeFloat)
            {
                float[] source = new float[Samples];
                Buffer.BlockCopy(rawData, 0, source, 0, rawData.Length);
                for (int i = 0; i < source.Length; i++)
                {
                    array[i] = source[i];
                }
            }
            else if (format == Audio.SampleFormat.Format16Bit)
            {
                short[] source = new short[Samples];
                Buffer.BlockCopy(rawData, 0, source, 0, rawData.Length);
                SampleConverter.Convert(source, array);
            }

            else
            {
                throw new InvalidOperationException();
            }
        }
示例#2
0
 /// <summary>
 ///   Copies this signal to a given array.
 /// </summary>
 ///
 public void CopyTo(double[] array)
 {
     if (format == Audio.SampleFormat.Format64BitIeeeFloat)
     {
         if (array.Length < NumberOfSamples)
         {
             throw new Exception("The provided array is not large enough to contain the signal.");
         }
         Buffer.BlockCopy(rawData, 0, array, 0, Math.Min(NumberOfBytes, array.GetNumberOfBytes()));
     }
     else if (format == Audio.SampleFormat.Format32BitIeeeFloat)
     {
         float[] source = new float[NumberOfSamples];
         Buffer.BlockCopy(rawData, 0, source, 0, Math.Min(NumberOfBytes, source.GetNumberOfBytes()));
         SampleConverter.Convert(source, array);
     }
     else if (format == Audio.SampleFormat.Format16Bit)
     {
         short[] source = new short[NumberOfSamples];
         Buffer.BlockCopy(rawData, 0, source, 0, Math.Min(NumberOfBytes, source.GetNumberOfBytes()));
         SampleConverter.Convert(source, array);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
示例#3
0
        /// <summary>
        ///   Copies this signal to a given array.
        /// </summary>
        ///
        public void CopyTo(float[] array)
        {
            if (format == Audio.SampleFormat.Format32BitIeeeFloat)
            {
                Buffer.BlockCopy(rawData, 0, array, 0, rawData.Length);
            }

            else if (format == Audio.SampleFormat.Format16Bit)
            {
                short[] source = new short[Samples];
                Buffer.BlockCopy(rawData, 0, source, 0, rawData.Length);
                SampleConverter.Convert(source, array);
            }

            else
            {
                throw new InvalidOperationException();
            }
        }