Skip to main content
Version: 🚧 Alpha 🚧

Sound Extension

Extension: gama.extension.sound

The Sound extension allows agents to play audio files. The supported formats are aif, au, mp3 and wav, the decoders being shipped with the extension. No audio hardware is required to run a model: a file which cannot be read simply raises an error at run time.

Statements​

StatementDescription
start_soundStarts a file on the player of the agent which executes the statement
stop_soundStops that player
pause_soundPauses it
resume_soundResumes a paused player

An agent owns at most one player, and the three control statements take no facet: they always act on the player of the current agent, never on the sound another agent is playing. All four are sequence statements: they accept a block of statements which is executed after the sound command has been sent.

start_sound​

FacetTypeDescription
sourcestringAudio file. The path is relative to the folder of the model (no facet name required)
modeidentifieroverwrite (the default) interrupts the sound already playing on the player and starts the new one; ignore leaves the current sound untouched
repeatboolPlays the file in a loop until stop_sound (default: false)

Example:

species speaker {
reflex greet when: my_age = 1#min {
start_sound "hello.wav";
}
reflex theme {
// mode: ignore prevents the theme from restarting at every cycle
start_sound "theme.mp3" mode: ignore repeat: true;
}
reflex leave when: my_age > 10#min {
stop_sound;
}
}

The pool holds only two players for the whole platform. While both are taken, start_sound does nothing: the statement is silently ignored. A player is released when its agent dies, or when it has stopped and was not repeating, which makes stop_sound the way to give a player back to the other agents.

The music skill​

The extension also registers a skill named music, backed by the MIDI synthesizer of the virtual machine. It is declared in GamlAdditions without any member: in 2026-11 it exposes no action to GAML, and skills: [music] on a species has no visible effect.

Runnable model​

The extension ships Tests > Sound Tests > SoundAdvancedTest.gaml, which checks that a missing file and a file which is not audio are both reported as errors instead of being ignored.

See Also​