Skip to main content

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

PropertyTypeDefaultDescription
debugModebooleanfalseEnables debug logging to the console
globalVolumenumber1Master volume for all sounds (0 to 1)
globalMutedbooleanfalseWhether all sounds are muted globally
globalPannumber0Master stereo pan (-1 left to 1 right)
masterSpatialPositionobjectnullMaster 3D spatial position { x, y, z }
masterSpatialConfigSoundPannerConfigundefinedMaster panner configuration
progressUpdateIntervalnumber250Interval in ms for progress tracking updates
spatialAudioEnabledbooleanautoWhether 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);
});