updatePannerConfigById
Change the panner settings of a sound that already has a 3D panner, without moving it. Use it to set cone angles or change how quickly a sound fades with distance.
updatePannerConfigById(soundId: string, newConfig: Partial<SoundPannerConfig>): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
soundId | string | required | ID of a sound with a 3D panner. |
newConfig | Partial<SoundPannerConfig> | required | Only the settings to change. Keys you leave out, or set to undefined, stay as they are. See Spatial audio for every field. |
Returns
Nothing.
Example
import { SoundHub, PanningModel } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('rain', '/audio/rain.mp3');
soundHub.play('rain', { loop: true });
soundHub.setSpatialPosition(0, 0, -5, 'rain');
soundHub.updatePannerConfigById('rain', {
panningModel: PanningModel.HRTF,
rolloffFactor: 3,
});
Good to know
- Does nothing when the sound has no 3D panner yet. Call
setSpatialPositionfirst. - The values are written straight onto the
PannerNode. A value the browser rejects, such as a negativerefDistance, is caught, logged and dispatched as anerrorevent. - The settings are not stored. If the panner is removed and created again, it starts from the defaults and the hub's
pannerNodeConfig. - No event is dispatched.
See also
setSpatialPosition: position a sound, optionally with a full panner config.setSpatialOrientation: point the cone.soundHubConfig: setpannerNodeConfigfor every new panner.