SoundManagerConfig
The SoundManagerConfig interface defines the configuration options for the Sound Manager. You can set these options when initializing the Sound Manager to customize its behavior.
export interface SoundManagerConfig {
debugMode?: boolean; // Enable or disable debug logging
globalVolume?: number; // 0 to 1 (default: 1)
globalMuted?: boolean; // (default: false)
globalPan?: number; // -1 (left) to 1 (right) (default: 0)
masterSpatialPosition?: { x: number; y: number; z: number };
masterSpatialConfig?: SoundPannerConfig;
progressUpdateInterval?: number; // in milliseconds (default: 250)
spatialAudioEnabled?: boolean; // (default: false if not supported, true if supported)
}
Getting the Current Configuration
Use getConfig() to retrieve the current configuration:
const mySoundManager = new SoundManager();
const config = mySoundManager.getConfig();
console.log('Debug mode:', config.debugMode);
console.log('Global volume:', config.globalVolume);
console.log('Spatial audio enabled:', config.spatialAudioEnabled);
Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
debugMode | boolean | false | Enables debug logging to the console |
globalVolume | number | 1 | Master volume for all sounds (0 to 1) |
globalMuted | boolean | false | Whether all sounds are muted globally |
globalPan | number | 0 | Master stereo pan (-1 left to 1 right) |
masterSpatialPosition | object | null | Master 3D spatial position { x, y, z } |
masterSpatialConfig | SoundPannerConfig | undefined | Master panner configuration |
progressUpdateInterval | number | 250 | Interval in ms for progress tracking updates |
spatialAudioEnabled | boolean | auto | Whether spatial audio is enabled |
Practical Example
const mySoundManager = new SoundManager();
// Configure the sound manager
mySoundManager.setGlobalVolume(0.8);
mySoundManager.setDebugMode(true);
mySoundManager.setProgressUpdateInterval(100); // Update progress every 100ms
// Later, check the configuration
const config = mySoundManager.getConfig();
console.log('Current config:', config);
// Output example:
// {
// debugMode: true,
// globalVolume: 0.8,
// globalMuted: false,
// globalPan: 0,
// masterSpatialPosition: null,
// progressUpdateInterval: 100,
// spatialAudioEnabled: true
// }
Listening for Configuration Changes
You can listen for configuration-related events using the event system:
const mySoundManager = new SoundManager();
// Listen for volume changes
mySoundManager.addEventListener(SoundEventsEnum.MASTER_VOLUME_CHANGED, (event) => {
console.log('Master volume changed to:', event.volume);
});
// Listen for pan changes
mySoundManager.addEventListener(SoundEventsEnum.MASTER_PAN_CHANGED, (event) => {
console.log('Master pan changed to:', event.pan);
});
// Listen for mute changes
mySoundManager.addEventListener(SoundEventsEnum.MUTE_GLOBAL, (event) => {
console.log('Global mute:', event.isMuted);
});
Related Methods
getConfig- Get the current configurationsetGlobalVolume- Set the global volumesetGlobalPan- Set the global pansetDebugMode- Enable or disable debug modesetProgressUpdateInterval- Set the progress update intervaltoggleGlobalMute- Toggle global mute