Skip to content

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

ParameterTypeDescription
int16ArrayInt16ArrayThe 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:

  • -32768 to -1.0
  • 0 to 0.0
  • 32767 to 1.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.

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency