Click or drag to resize
Accord.NET (logo)

SampleConverter Class

Static methods to convert between different sample formats.
Inheritance Hierarchy
SystemObject
  Accord.AudioSampleConverter

Namespace:  Accord.Audio
Assembly:  Accord.Audio (in Accord.Audio.dll) Version: 3.8.0
Syntax
public static class SampleConverter
Request Example View Source
Methods
  NameDescription
Public methodStatic memberConvert(Byte, Int16)
Converts a unsigned 8-bit byte sample into a 16-bit short integer sample.
Public methodStatic memberConvert(Byte, Int32)
Converts a unsigned 8-bit byte sample into a 32-bit integer sample.
Public methodStatic memberConvert(Byte, Single)
Converts a unsigned 8-bit byte sample into a 32-bit floating point sample.
Public methodStatic memberConvert(Byte, Int16)
Converts an array of unsigned 8-bit byte samples into an array of 16-bit short integer samples.
Public methodStatic memberConvert(Byte, Int32)
Converts an array of unsigned 8-bit byte samples into an array of 32-bit integer samples.
Public methodStatic memberConvert(Byte, Single)
Converts an array of unsigned 8-bit byte samples into an array of 32-bit floating point samples.
Public methodStatic memberConvert(Byte, Int16)
Converts a matrix of unsigned 8-bit byte samples into a array of 16-bit short integer samples.
Public methodStatic memberConvert(Byte, Int32)
Converts a matrix of unsigned 8-bit byte samples into a matrix of 32-bit integer samples.
Public methodStatic memberConvert(Byte, Single)
Converts a matrix of unsigned 8-bit byte samples into a matrix of 32-bit floating-point samples.
Public methodStatic memberConvert(Int16, Byte)
Converts a signed 16-bit integer sample into a 8-bit unsigned byte sample.
Public methodStatic memberConvert(Int16, Double)
Converts a signed 16-bit integer sample into a 64-bit floating point sample.
Public methodStatic memberConvert(Int16, Int32)
Converts a signed 16-bit integer sample into a 32-bit signed integer sample.
Public methodStatic memberConvert(Int16, Single)
Converts a signed 16-bit integer sample into a 32-bit floating point sample.
Public methodStatic memberConvert(Int16, Byte)
Converts a array of signed 16-bit integer samples into a array of 8-bit unsigned byte samples.
Public methodStatic memberConvert(Int16, Double)
Converts a array of signed 16-bit integer samples into a array of 64-bit floating point samples.
Public methodStatic memberConvert(Int16, Int32)
Converts a array of signed 16-bit integer samples into a array of 32-bit signed integer samples.
Public methodStatic memberConvert(Int16, Single)
Converts a array of signed 16-bit integer samples into a array of 32-bit floating point samples.
Public methodStatic memberConvert(Int16, Byte)
Converts a matrix of signed 16-bit integer samples into a matrix of 8-bit unsigned byte samples.
Public methodStatic memberConvert(Int16, Double)
Converts a matrix of signed 16-bit integer samples into a matrix of 64-bit floating point samples.
Public methodStatic memberConvert(Int16, Int32)
Converts a matrix of signed 16-bit integer samples into a matrix of 32-bit signed integer samples.
Public methodStatic memberConvert(Int16, Single)
Converts a matrix of signed 16-bit integer samples into a matrix of 32-bit floating point samples.
Public methodStatic memberConvert(Int32, Byte)
Converts a signed 32-bit integer sample into a 8-bit unsigned byte sample.
Public methodStatic memberConvert(Int32, Int16)
Converts a signed 32-bit integer sample into a 16-bit signed integer sample.
Public methodStatic memberConvert(Int32, Int32)
Converts a signed 32-bit integer sample into a 32-bit floating point sample.
Public methodStatic memberConvert(Int32, Single)
Converts a signed 32-bit integer sample into a 32-bit float-point sample.
Public methodStatic memberConvert(Int32, Byte)
Converts a array of signed 32-bit integer samples into a array of 8-bit unsigned byte samples.
Public methodStatic memberConvert(Int32, Int16)
Converts a array of signed 32-bit integer samples into a array of 16-bit signed integer samples.
Public methodStatic memberConvert(Int32, Int32)
Converts a array of signed 32-bit integer samples into a array of 32-bit floating point samples.
Public methodStatic memberConvert(Int32, Single)
Converts a array of signed 32-bit integer samples into a array of 32-bit float-point samples.
Public methodStatic memberConvert(Int32, Byte)
Converts a matrix of signed 32-bit integer samples into a matrix of 8-bit unsigned byte samples.
Public methodStatic memberConvert(Int32, Int16)
Converts a matrix of signed 32-bit integer samples into a matrix of 16-bit signed integer samples.
Public methodStatic memberConvert(Int32, Single)
Converts a matrix of signed 32-bit integer samples into a matrix of 32-bit float-point samples.
Public methodStatic memberConvert(Single, Byte)
Converts a signed 32-bit float sample into a 8-bit unsigned byte sample.
Public methodStatic memberConvert(Single, Int16)
Converts a 32-bit float sample into a 16-bit integer sample.
Public methodStatic memberConvert(Single, Byte)
Converts a array of signed 32-bit float samples into a array of 8-bit unsigned byte samples.
Public methodStatic memberConvert(Single, Int16)
Converts a array of 32-bit float samples into a array of 16-bit integer samples.
Public methodStatic memberConvert(Single, Byte)
Converts a matrix of signed 32-bit float samples into a matrix of 8-bit unsigned byte samples.
Public methodStatic memberConvert(Single, Int16)
Converts a matrix of 32-bit float samples into a matrix of 16-bit integer samples.
Public methodStatic memberConvert(Single, Int32)
Converts a matrix of signed 32-bit integer samples into a matrix of 32-bit floating point samples.
Top
Remarks

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)

Examples
To use it, just call Convert. The compiler will automatically detect which method to call based on your data types.
// Suppose we have a collection of samples in PCM-16 format
// and wish to convert it into IEEE-32 floating point format:

int[]   pcm16Samples = new int  [3] { 1, 2, 3 }; // source
float[] floatSamples = new float[3];             // target

// Call convert passing the source samples. Converted
// IEEE samples in will be stored in the target array.
SampleConverter.Convert(pcm16samples, floatSamples);
See Also