music( name ) music( name, loop ) music( name, loop, volume ) music( name, loop, volume, pan )
Calling this function immediately plays the music track specified by
loop parameter controls whether the music track plays continuously, or stops when finished.
Only one music track can be played at a time. You can modify the currently playing music track by accessing elements of the
music table, such as
Do not call this function repeatedly in your draw loop. The
music function is intended to be called once each time you wish to start playing music, or when you wish to change music tracks.
string, the name of the music track to play
boolean, specifies whether this track should continue playing in a loop
number, the initial volume of playback from 0.0 to 1.0
number, the stereo panning of playback, from -1.0 to 1.0
-- Getting vol = music.volume -- Setting music.volume = 0.5
This variable controls the currently playing music track's volume. It ranges from 0.0 to 1.0.
Volume of the currently playing music track
-- Getting pan = music.pan -- Setting music.pan = -1.0
This variable controls the currently playing music track's stereo panning. It ranges from -1.0 to 1.0.
Panning amount of the currently playing music track
-- Getting time = music.currentTime -- Setting music.currentTime = music.duration * 0.5
This variable controls the seek position of the currently playing music track. It ranges from 0.0 (start of the track) to
music.duration (end of the track).
Current time into the playing music track
-- Getting isPaused = music.paused -- Setting music.paused = true
This variable sets the paused state of the current music track.
Paused state of the currently music track.
-- Getting muted = music.muted -- Setting music.muted = true
This variable controls whether the music track is currently muted.
Whether the current track is muted
duration = music.duration
Read only. This variable returns the length of the current music track in seconds.
Length of the current music track in seconds.
channels = music.channels
Read only. This variable returns the number of channels supported by the current track (usually 1 or 2).
Number of channels supported by the current track.
print( music.name )
Read only. This value returns the asset string of the currently playing music.
Asset string of current music track
-- For sound assets sound( name, volume ) sound( name, volume, pitch ) sound( name, volume, pitch, pan ) sound( name, volume, pitch, pan, loop ) -- For generated sounds sound( name ) sound( name, seed ) sound( parameterTable ) sound( buffer )
Calling this function immediately plays a sound effect, or a randomly generated sound with a type specified by
name or encoded with the given parameters.
If using a sound asset (a sound from an asset pack) the
sound function accepts the following optional parameters:
loop. Please see the parameter table for an explanation of these.
sound() can use sfxr to randomly generate sounds of a given type. The
name parameter is a string specifying the type of sound (see related items), and the
seed parameter allows you to choose a particular random sound. Sounds with the same name and seed always sound the same. If no
seed is specified the resulting sound will be a random sound of the specified type. If a
parameterTable is passed in, those values are used to generate the sound.
Do not call this function repeatedly in your draw loop. The
sound function is intended to be called when you wish to play a sound effect (on a game event such as the player getting hit).
string, the sound effect asset or type of sound to play
This can be an asset name, such as "A Hero's Quest:Arrow Shoot 1" or it can be used to specify a randomly generated sound effect from the following:
Can also be
number, specifies the volume of the sound effect from 0.0 to 1.0 (only for sounds from an asset pack)
number, specifies the pitch of the sound effect, where 1.0 is the normal pitch (only for sounds from an asset pack)
number, specifies the stereo panning of the sound effect from -1.0 to 1.0 (only for sounds from an asset pack)
boolean, specifies whether this sound effect plays on a loop (only for sounds from an asset pack)
int, specifies the random seed to use when generating a sound of this type
soundbuffer, specifies the raw sound data to play
table, specifies the parameters to use when generating a sound. This is an advanced option, the parameters will change the noise in subtle ways. Play with the Sounds Plus example app to see what these parameters do. Any missing keys will cause the sound to use a default value for that parameter
The table can contain the following (case sensitive) keys:
soundbuffer( data, format, freq )
This object represents a sound buffer containing arbitrary audio data. You may create
soundbuffer objects using
soundbuffer( data, format, freq ) where the data is uncompressed PCM audio and the format is one of
string, uncompressed audio data
integer, the frequency of the data
A new soundbuffer object
soundBufferSize( size ) soundBufferSize()
Calling this function will set the maximum buffer size for sounds. Sounds are stored in a buffer so that they do not need to be recreated if reused. Sounds are removed from this buffer on a least recently used basis when the buffer is full and a new sound is added. For example, if the buffer is 2 megabytes (the default), and we add a sound that puts it over the limit, the sound we used the longest time ago is removed from the buffer and will have to be re-created if played again. Generating the sound data can take a considerable amount of time for longer sounds.Playing a sound at 0 volume counts as playing and can be used to keep a sound in the cache (and to pre-generate a sound in the setup function.) Calling this method with 0 for the size sets the buffer to no limit. This can cause Codea to crash if too many sounds are generated as it may run out of memory.Calling this with no parameters returns the max size and current size of the buffer.
number, the maximum size of the buffer in megabytes. This can be a fraction. If this is 0, the buffer size is unlimited. An unlimited buffer size can cause Codea to crash if it runs out of memory, so take care if it is used.
If no parameters are given, a pair of values: maxBufferSize, currentBufferSize
This constant specifies a jump sound. Similar to a character jumping in a platform game.
The string "jump"
This constant specifies a hit sound. For example, when the enemy collides with the player.
The string "hit"
This constant specifies a pickup sound. For example, collecting coins in a game.
The string "pickup"
This constant specifies a powerup sound. For example, collecting bonuses in a game.
The string "powerup"
This constant specifies a shooting sound. For example, firing a bullet in a game.
The string "shoot"
This constant specifies an explosion sound. For example, a space ship blowing up.
The string "explode"
This constant specifies a generic "blit" sound.
The string "blit"
This constant specifies a randomly generated sound. You can use this in conjunction with the seed value of the
sound() function to find a sound that you like.
The string "random"
This specifices to use a white noise function as the waveform for this sound
The integer 3
This specifices to use a sawtooth function as the waveform for this sound
The integer 1
This specifices to use a sine wave function as the waveform for this sound
The integer 2