Provides loading and managing of sounds.
This object keeps a map of requested sounds by path in order to avoid duplicates, it also provides a default sound for those cases where the required one is missing or still not yet loaded.
Loading of sounds is an asynchronous operation, so the application should periodically check for the manager to finish all the pending requests before updating all its sound references.
Remapping functionality is also supported by the manager.
Required scripts
The SoundManager object requires:
/*{{ javascript("jslib/soundmanager.js") }}*/
/*{{ javascript("jslib/observer.js") }}*/
Summary
Syntax
var soundManager = SoundManager.create(soundDevice, requestHandler, defaultSound, errorCallback);
Summary
Requests loading of a sound by path.
Syntax
var onload = function onloadFn(sound) {};
var sound = soundManager.load(path, uncompress, onload);
Returns the requested Sound if already loaded, the default sound otherwise. The callback function is called with the loaded Sound as an argument.
Summary
Returns the loaded sound stored with the given path.
Syntax
var sound = soundManager.get(path);
Returns the requested Sound object or the default sound if the requested one is missing or not yet loaded.
Summary
Alias one sound to another name.
Syntax
soundManager.map(alias, name);
Summary
Deletes the sound stored with the given path.
Syntax
soundManager.remove(path);
Summary
Reloads the sound stored with the given path. Useful when the sound has been updated on the server and the application wants to retrieve the new one. The reloading of the sound will be done asynchronously.
Syntax
soundManager.reload(path);
Summary
Reloads all the stored sounds. Useful when many sounds have been updated on the server and the application wants to retrieve the new ones.
This operation may take a long time to complete, the reloading of the sound will be done asynchronously.
Syntax
soundManager.reloadAll();
Summary
Returns the number of sounds requested but still to be loaded.
Syntax
var numPendingSounds = soundManager.getNumPendingSounds();
if (numPendingSounds)
{
keepWaiting();
}
Summary
Returns true if a sound is not pending.
Syntax
if (soundManager.isSoundLoaded(path))
{
noMoreWaiting();
}
Summary
Returns true if a sound is missing.
Syntax
if (soundManager.isSoundMissing(path))
{
errorWhilstLoading();
}
Summary
Enables remapping of loading paths.
The remapping only affects the loading URLs, the sound will be stored under the original path it was requested with.
Syntax
soundManager.setPathRemapping(mappingDictionary, prefix);
// example usage:
var mappingTableReceived = function mappingTableReceivedFn(mappingTable)
{
soundManager.setPathRemapping(mappingTable.urlMapping, mappingTable.assetPrefix);
};
mappingTable = TurbulenzServices.createMappingTable(gameSession,
mappingTableReceived);
If a remapping is required to find the shaders then this must be called before the renderer is created. If the remapping is done afterwards then some shaders may not load correctly.
Both arguments for setPathRemapping are properties on the MappingTable object.
Summary
Generates a beep sound.
Syntax
var beepSound = soundManager.beep(frequency, wavefrequency, length);
The beep used as default sound is generated with beep(4000, 400, 1).
Summary
Releases the SoundManager object and all the resources it allocated; the object and the sounds it referenced will be invalid after the method is called.
Syntax
soundManager.destroy();