audio module lets you play audio files such as music or sound effects.
It contains the following classes:
At the moment, DOME only supports OGG and WAV files, with a sample frequency of 44.1kHz (CD quality audio)
An audio file is loaded from disk into memory using the
load function, and remains in memory until you call
unloadAll(), or when DOME closes.
When an audio file is about to be played, DOME allocates it an “audio channel”, which handles the settings for volume, looping and panning. Once the audio is stopped or finishes playing, that channel is no longer usable, and a new one will need to be acquired.
AudioEngine.load("fire", "res/Laser_Shoot.wav") var channel = AudioEngine.play("fire") channel.stop() ... AudioEngine.unload("fire")
static register(name: String, path: String)
DOME keeps a mapping from a developer-friendly name to the file path. Calling this method sets up this mapping, but doesn’t load that file into memory.
static load(name: String)
name has been mapped to a file path, DOME will load that file into memory, ready to play.
static load(name: String, path: String)
This combines the
load(_) calls, for convenience.
static play(name: String): AudioChannel
Plays the named audio sample once, at maximum volume, with equal pan.
static play(name: String, volume: Number): AudioChannel
Plays the named audio sample once, at volume, with equal pan.
static play(name: String, volume: Number, loop: Boolean): AudioChannel
Plays the named audio sample, at volume, with equal pan. If loop is set, the sample will repeat once playback completes.
static play(name: String, volume: Number, loop: Boolean, pan: Number): AudioChannel
Play the named audio sample and returns the channel object representing that playback. The other parameters are explained in the AudioChannel api.
Stop all playing audio channels.
Releases the resources of the all currently loaded audio samples. This will halt any audio using that sample immediately.
static unload(name: String)
Releases the resources of the chosen audio sample. This will halt any audio using that sample immediately.
These are created when you
play a buffer of AudioData using the AudioEngine. You cannot construct these directly.
A playing audio channel has three main properties:
Returns true if the audio channel has finished playing. It cannot be restarted after this point.
The total number of samples in this channel’s audio buffer.
You should divide this by
44100 to get the length in seconds.
You can set this to control whether the sample will loop once it completes, or stop.
The channel will become invalid if it reaches the end of the sample and
loop is false.
You can read and modify the pan position, as a bounded value between -1.0 and 1.0.
This marks the position of the next sample to be loaded into the AudioEngine mix buffer (which happens on a seperate thread). You can set a new position for the channel, but it isn’t going to be exact, due to delays in audio processing.
You should divide this by
44100 to get the position in seconds.
This is the sample name used for this sound.
This is an enum which represents the current state of the audio.
This returns a number with a minimum of 0.0 representing the volume of the channel. 1.0 is the default for the audio data.
You can set this to change the volume.
Requests that the channel stops as soon as possible.
AudioChannel objects can be in one of the following states: