applyFade
Applies linear fade-in and fade-out effects to audio samples.
function applyFade(
samples,
fadeInSamples,
fadeOutSamples): Float32Array;
Defined in: src/utils/audio.ts:457
Applies linear fade-in and fade-out effects to audio samples.
Parameters
| Parameter | Type | Description |
|---|---|---|
samples | Float32Array | The input audio samples as a Float32Array. |
fadeInSamples | number | The number of samples for the fade-in ramp. |
fadeOutSamples | number | The number of samples for the fade-out ramp. |
Returns
Float32Array
A new Float32Array with the fade effects applied.
Remarks
Creates a copy of the input samples with linear gain ramps at the beginning (fade-in) and end (fade-out) of the buffer. This is useful for preventing audible clicks or pops when audio chunks are stitched together or when playback starts/stops abruptly.
The fade durations are specified in number of samples, not milliseconds. To convert milliseconds to samples: samples = (ms / 1000) * sampleRate.
Example
// Apply 10ms fade at 16 kHz (160 samples)
const fadeSamples = 160;
const smoothed = applyFade(audioBuffer, fadeSamples, fadeSamples);