Convert data from one pcm-format to another.
Usage
const convert = //convert data from float32 to uint8 arraylet uint8arr = //convert interleaved uint8 to planar float32 arraylet float32arr = //deinterleave keeping the same data typelet int8arr = //change endianness keeping the same data typelet float32be = //use objects as formatslet float64 = //skip source format string, convert directly to data formatlet uint16 = //put data into target container skipping format strings //full arguments caselet uint16arr =
API
convert(src, srcFormat?, dstFormat?, dst?)
Takes data in src
container and converts from srcFormat
to dstFormat
. Format can be whether a string with tags or an object with properties, see audio-format module. If srcFormat
is skipped, it is detected from src
. Optionally a destination container can be provided as dst
, and in case if dstFormat
is skipped, it will be detected from dst
.
Source
Source format is inferred from src
data type and extended with srcFormat
properties. By default source is considered planar mono le
. Source data types:
Type | Dtype |
---|---|
Array |
float32 |
Float32Array |
float32 |
Float64Array |
float64 |
ArrayBuffer |
uint8 |
Buffer |
uint8 |
Uint8Array |
uint8 |
Uint8ClampedArray |
uint8 |
Uint16Array |
uint16 |
Uint32Array |
uint32 |
Int8Array |
int8 |
Int16Array |
int16 |
Int32Array |
int32 |
Format
Can be defined as dtype
string with tags, eg. 'uint8 interleaved mono le'
, 'float64 planar quad'
(some tags can be skipped), or an object with the following properties:
Property | Meaning |
---|---|
dtype |
Data type string: uint8 , uint16 , uint32 , int8 , int16 , int32 , float32 , float64 , array (only dstFormat ), arraybuffer (only dstFormat ). |
interleaved |
Boolean indicating if data has interleaved or planar layout. |
channels |
Number of channels in source: mono , stereo , quad , 5.1 . |
endianness |
be or le , defaults to OS endianness. |
Related
- audio-format - audio format notation parser/stringifier.
- audio-speaker - output data to speaker in node.
- dtype - list of standard data types.
License
© 2017 Dima Yv. MIT License