int16ToFloat
Converts an Int16Array of 16-bit PCM samples to a Float32Array of normalized floats.
function int16ToFloat(int16Array): Float32Array;
Defined in: src/utils/audio.ts:97
Converts an Int16Array of 16-bit PCM samples to a Float32Array of normalized floats.
Parameters
| Parameter | Type | Description |
|---|---|---|
int16Array | Int16Array | The input 16-bit PCM audio samples. |
Returns
Float32Array
A new Float32Array containing normalized float samples in the range [-1.0, 1.0].
Remarks
Performs the inverse of floatTo16BitPCM. The conversion maps:
-32768to-1.00to0.032767to1.0
Useful when receiving PCM audio from providers and needing to process it with the Web Audio API, which operates on float samples.
Example
const pcmSamples = new Int16Array([0, 16383, -16384, 32767, -32768]);
const floatSamples = int16ToFloat(pcmSamples);
// floatSamples: Float32Array [0.0, ~0.5, ~-0.5, 1.0, -1.0]
See
floatTo16BitPCM for the inverse conversion.