Provides 3D sound support using OpenAL.
A SoundDevice object can be constructed with TurbulenzEngine.createSoundDevice.
Summary
Creates a sound source.
Syntax
var source = soundDevice.createSource({
position : mathDevice.v3Build(0, 0, 0),
direction : mathDevice.v3Build(1, 0, 0),
velocity : mathDevice.v3Build(0, 0, 0),
gain: 1.0,
minDistance: 1.0,
maxDistance: 100.0,
rollOff: 1.0,
relative: false,
looping: false,
pitch: 1.0
});
Returns a Source object.
Summary
Creates or loads a Sound. Returns immediately.
The parameter name must be specified e.g. “Duck01”, unless a src is specified in which case the name will be the src e.g. “sounds/duck.ogg” if name is not explicitly specified.
Syntax
var soundLoaded = function soundLoadedFn(loadedSound, status)
{
if (loadedSound)
{
log("Sound loaded:");
log("Name: " + loadedSound.name);
log("Channels: " + loadedSound.channels);
log("Frequency: " + loadedSound.frequency);
log("Bitrate: " + loadedSound.bitrate);
log("Length: " + loadedSound.length);
log("Compressed: " + loadedSound.compressed);
source.play(loadedSound);
}
};
soundDevice.createSound({
src : "sounds/bomb.ogg",
uncompress: false,
onload : soundLoaded
});
// For a procedural sound (without a src parameter)
soundDevice.createSound({
name : "Beep1",
data : SoundManager.prototype.beep(4000, 400, 1),
channels : 1,
frequency : 4000,
onload : function (proceduralSound)
{
defaultSound = proceduralSound;
}
});
Returns a Sound object or null if parameters are missing or incorrect. For more information on the parameters see the Sound object.
Note
You should manage the response status codes correctly. See the RequestHandler for handling connection and service busy issues. Alternatively, use the SoundManager to load sounds.
Summary
Loads Sounds from an archive if the sound files are supported by the Turbulenz Engine. Returns immediately.
The sound will take the name given to it as part of the archive directory structure, e.g. “bomb.ogg” or “sound/duck.wav”.
Syntax
var sounds = [];
var soundArchiveParams =
{
src : "sounds.tar",
uncompress : true,
onsoundload : function (sound)
{
if (sound)
{
sounds[sounds.length] = sound;
}
},
onload : function (success, status)
{
if (!success)
{
alert("sounds.tar was not successfully loaded");
}
}
};
soundDevice.loadSoundsArchive(soundArchiveParams);
Returns true if the parameters are valid and reading of the archive has started.
Note
You should manage the response status codes correctly. See the RequestHandler for handling connection and service busy issues. Alternatively, use the SoundManager to load sounds.
Summary
Creates a SoundEffect object from the parameters specified. If an effect property is not passed as a parameter, the effect will take the default property value.
Syntax
var effect = soundDevice.createEffect({
name : "HallwayReverb01",
type : "Reverb",
delay : 0.15
});
Common Parameters
When an effect has been created, it takes on the properties of the type specified as an argument. A list of the properties for the available effects can be found in the SoundEffect object documentation.
Returns a SoundEffect object if the parameters are correct. Returns null if the type is not supported or if any of the parameters are incorrect.
Summary
Creates a SoundEffectSlot from the parameters specified. A SoundEffectSlot allows a single effect to be applied to the output of multiple sound sources. Once a SoundEffectSlot is created, it can be attached to the output of a source using the setAuxiliarySendFilter function on the Source object.
Syntax
var effectSlot = soundDevice.createEffectSlot({
effect : effect,
gain : 0.8
});
Parameters
Returns a SoundEffectSlot object if the parameters are correct. Returns null if the effect is not a SoundEffect object or if any of the parameters are incorrect.
Summary
Creates a sound filter from the parameters specified. If a filter property is not passed as a parameter, the filter will take the default property value. Once a SoundFilter object is created, it can be attached to the output of a source using the setAuxiliarySendFilter or setDirectFilter function on the Source object.
Syntax
var filter = soundDevice.createFilter({
name : "LowPassFilter01",
type : "LowPass",
gain : 0.7
});
Parameters
When a filter has been created, it takes on the properties of the type specified as an argument. A list of the properties for the available filters can be found in the SoundFilter object documentation.
Returns a SoundFilter object if the parameters are correct. Returns null if the filter is not a SoundFilter object or if any of the parameters are incorrect.
Summary
Polls the state of playing sounds and updates data accordingly.
Note
This method should be called frequently to avoid sound issues, for example once per rendering frame.
Syntax
function renderFrame()
{
soundDevice.update();
}
TurbulenzEngine.setInterval(renderFrame, (1000 / 60));
Summary
Used to check if a feature is supported.
Syntax
var feature = "FILEFORMAT_OGG";
if (soundDevice.isSupported(feature))
{
// ...
}
Returns a boolean.
Summary
The name of the company responsible for the OpenAL sound renderer used by the sound device.
Syntax
var vendorString = soundDevice.vendor;
Note
Read Only
Summary
The name of the OpenAL sound renderer used by the sound device.
Syntax
var rendererString = soundDevice.renderer;
Note
Read Only
Summary
The version string of the OpenAL sound renderer used by the sound device.
Syntax
var versionString = soundDevice.version;
Note
Read Only
Summary
The specifier string for the low level sound device used by the engine sound device.
Syntax
var deviceSpecifierString = soundDevice.deviceSpecifier;
Note
Read Only
Summary
List of the OpenAL extensions supported by the sound renderer used by the sound device.
Syntax
var extensionsString = soundDevice.extensions;
if (-1 !== extensionsString.indexOf('AL_EXT_MCFORMATS'))
{
multiChannelSupported();
}
Note
Read Only
Summary
The Matrix43 object representing the position and orientation of the listener in world space. Default to the identity matrix.
Syntax
soundDevice.listenerTransform = mathDevice.m43BuildTranslation(100, 10, 100);
Summary
The Vector3 object representing the velocity of the listener in world space. Defaults to a zero vector.
Syntax
soundDevice.listenerTransform = mathDevice.v3Build(100, 0, 0);
Summary
Indicates the gain (volume amplification) applied to the listener. The accepted range is 0.0 or above. A value of 1.0 means unattenuated/unchanged. Each division by 2 equals an attenuation of -6dB. Each multiplication by 2 equals an amplification of +6dB. A value of 0.0 is meaningless with respect to a logarithmic scale; it is interpreted as zero volume, the channel is effectively disabled. Defaults to 1.
Syntax
soundDevice.listenerGain = 0.5;
Summary
Frequency for mixing output buffer, in units of Hz. Defaults to 44100.
Syntax
var frequency = soundDevice.frequency;
Note
Read Only
Summary
The OpenAL Doppler factor value. Defaults to 1.
Syntax
var dopplerFactor = soundDevice.dopplerFactor;
Summary
The OpenAL Doppler velocity value. Defaults to 1.
Syntax
var dopplerVelocity = soundDevice.dopplerVelocity;
Summary
The OpenAL Speed of Sound value in meters per second. Defaults to 343.3.
Syntax
var speedOfSound = soundDevice.speedOfSound;
Summary
The string version of OpenAL in use by the SoundDevice.
Syntax
var alcVersion = soundDevice.alcVersion;
Summary
A string list of extensions supported by the OpenAL implementation.
Syntax
var alcExtensions = soundDevice.alcExtensions;
Summary
The string version of the EFX extension that is supported by the OpenAL implementation.
Syntax
var alcEfxVersion = soundDevice.alcEfxVersion;
Summary
The maximum number of auxiliary sends available per source, that this implementation of OpenAL supports.
Syntax
var alcMaxAuxiliarySends = soundDevice.alcMaxAuxiliarySends;