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

PropTypeDefaultDescription
type'gain'Filter identifier
valuenumberLinear 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 volume prop on Sound. A volume of 0.5 and a gain of 2 cancel out to unity.
  • Values above 1 can cause clipping if the signal is already near full scale. Keep headroom when boosting.
  • value is fully animatable: its lerp handler interpolates linearly between keyframes.