getDuckLevel
Added in 6.5.0
Get the level of a target's duck at this moment, from 0 to 1. It reads the duck's gain, so during the attack and the release it returns the level on the way. Once the ramp is done that is the amount you gave duck while a trigger plays, and 1 otherwise.
getDuckLevel(target: string): number;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
target | string | required | A target name you passed to duck. |
Returns
number: the current level of the duck, or 1 when the target has no duck.
Example
soundHub.duck('music', { when: 'voice', amount: 0.25 });
soundHub.getDuckLevel('music'); // 1
soundHub.play('voice');
// 50 ms later, after the default attack:
soundHub.getDuckLevel('music'); // 0.25
A meter next to the music
// The level moves during a ramp, so read it every frame
const draw = () => {
duckMeter.value = soundHub.getDuckLevel('music');
requestAnimationFrame(draw);
};
draw();
Good to know
- For where the duck is heading rather than where it is, use
isDuckedor theduck_startedandduck_endedevents, which carry the target level involume. - While nothing plays through the target, a browser does not run the duck's gain node, so its gain stays where it was. In 6.5.0
getDuckLevelreturns that frozen value. From 6.5.1 it returns the level the duck is heading for, which is the level the target starts at. - The level multiplies the target's own volume. A sound at volume 0.8 ducked to 0.25 plays at 0.2, and
getSoundVolumestill returns 0.8.