Skip to content
1 min read · 120 words

Function: resampleTo()

ts
function resampleTo(
  pcm: Float32Array,
  fromRate: number,
  toRate: number,
): Float32Array;

Defined in: src/lib/utils/audio.ts:29

Linearly resamples a mono PCM buffer from one sample rate to another.

Parameters

ParameterTypeDescription
pcmFloat32ArrayThe source mono PCM samples.
fromRatenumberThe source sample rate, in Hz.
toRatenumberThe target sample rate, in Hz.

Returns

Float32Array

The resampled mono PCM samples, Math.floor(pcm.length * toRate / fromRate) long.

Remarks

Pure resample only — no channel/downmix logic lives here (see downmixToMono for that). Uses linear interpolation between the two nearest source samples for each output sample; a no-op (returns pcm as-is) when fromRate === toRate.