Gain
Scales the clip's amplitude by a linear factor. Use it to raise or lower the volume of a Sound without touching the source file.
Usage
import { Sound, AudioFilters } from '@motion-script/core';
// Via AudioFilters builder
const clip = new Sound({ src: './voice.mp3', filters: AudioFilters.gain(1.5) });
// Via raw object
const clip = new Sound({ src: './voice.mp3', filters: [{ type: 'gain', value: 1.5 }] });
Props
| Prop | Type | Default | Description |
|---|---|---|---|
type | 'gain' | – | Filter identifier |
value | number | – | Linear amplitude multiplier. 1 = unchanged, 0 = silent, >1 = louder |
Animating
Interpolate value inside a tween to fade volume in or out:
import { Sound, AudioFilters, tween, lerpNumber, easeOut } from '@motion-script/core';
const clip = new Sound({ src: './music.mp3', filters: AudioFilters.gain(0) });
clip.start();
// Fade in over 2 seconds
yield* tween(2, (t) => {
clip.set({ filters: AudioFilters.gain(lerpNumber(0, 1, easeOut(t))) });
});
Notes
- Gain stacks multiplicatively with the
volumeprop onSound. Avolumeof0.5and a gain of2cancel out to unity. - Values above
1can cause clipping if the signal is already near full scale. Keep headroom when boosting. valueis fully animatable: its lerp handler interpolates linearly between keyframes.