fadeGlobalIn
Raise the master volume over a number of seconds. Every sound goes through the master, so the whole mix fades in. Use it at the start of a scene, or to come back from a global mute.
fadeGlobalIn(duration?: number, startVolume?: number, endVolume?: number): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
duration | number | fadeInDuration from the config (0.5) | Length of the fade in seconds. |
startVolume | number | 0 | Master volume to start from. |
endVolume | number | see below | Master volume to end at. Without it the fade ends at the current master volume, or at the remembered one when the master is at 0. |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music', { loop: true });
// Fade the whole mix in from silence over 3 seconds
soundHub.fadeGlobalIn(3, 0, 1);
// Later, after soundHub.muteAllSounds():
// fade back to the volume from before the mute
soundHub.fadeGlobalIn(2);
Try it
Fade the master volume
IdleDirection
Master gain1.00
The fade runs on the master gain, so every sound on the page follows it.
Code
Your clicks show up here as soundhub calls
Good to know
startVolumedefaults to0, not to the current volume. With the master at1,fadeGlobalIn(2)drops to silence first and then fades back up.- The remembered master volume is the one from before
muteAllSoundsorfadeGlobalOut, or the last value given tosetGlobalVolume. - When the fade ends, the global mute is lifted. Until then
getGlobalVolumestill returns0if you started from a mute. - A running
fadeGlobalOutorfadeGlobalInis replaced. - Every step dispatches
master_volume_changed, and the end dispatchesSoundEventsEnum.FADE_MASTER_IN_COMPLETED('fade_master_in_completed').
See also
fadeGlobalOut: fade the whole mix out.fadeIn: fade one sound in.setGlobalVolume: set the master volume at once.