Skip to main content

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​

ParameterTypeDefaultDescription
soundIdstringrequiredID of a sound with a 3D panner.
newConfigPartial<SoundPannerConfig>requiredOnly 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 setSpatialPosition first.
  • The values are written straight onto the PannerNode. A value the browser rejects, such as a negative refDistance, is caught, logged and dispatched as an error event.
  • 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​