Game audio

A real time mixer, loops, variations and audio sprites.

On this page

A real time mixer, loops, variations and audio sprites.

audioMixer

Open a real time mixer that plays many sounds at once with volume, pan, pitch, loops and buses, the way a game needs

audioMixer( sampleRate=44100, channels=2, output="speakers", buses )
ArgumentTypeDefault
sampleRateinteger44100Output sample rate. Defaults to 44100.
channelsinteger21 or 2. Defaults to 2.
outputstring"speakers"speakers plays to the sound card. null keeps time with no sound, for servers. memory runs nothing: call render(seconds) on the mixer to get the audio. Defaults to speakers.
busesstructoptionalStarting volumes of named buses, for example { music: 0.7, sfx: 1 }. A sound goes on a bus with the bus option of play().

Returns A mixer. Its methods: play(sound, options) returns a playback; options are bus, volume, pan, pitch, loop, loopStart, loopEnd, start and fadeIn. A playback has stop(fadeSeconds), pause(), resume(), setVolume(v), setPan(p), setPitch(p), fadeTo(level, seconds), isPlaying() and getPosition(). The mixer has crossfade(playback, sound, seconds, options), setVolume(v), setVolume(bus, v), stopAll(), stopAll(bus, fade), getActiveCount(), waitUntilSilent(seconds), render(seconds) for memory mixers, and close().

audioPlay

Play audio through the speakers

audioPlay( audio, wait=true, volume=1, output="speakers" )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
waitbooleantrueTrue to return when the sound has finished. False to return at once and let it play on a background mixer. Defaults to true.
volumedouble1Volume, 1 is the sound as it is. Defaults to 1.
outputstring"speakers"speakers, null (keep time, no sound) or memory is not allowed here. Defaults to speakers.

Returns The playback, which can be stopped with stop().

audioLoopify

Make a sound loop seamlessly by blending its end into its start

audioLoopify( audio, crossfade=0.25 )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
crossfadedouble0.25Seconds of overlap, at most half the sound. Defaults to 0.25.

Returns A new buffer, shorter by the crossfade, whose end runs straight into its start.

audioVariations

Make several slightly different copies of a sound, so repeated effects do not sound the same

audioVariations( audio, count=5, pitchRange=1, gainRange=2, seed=1 )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
countinteger5How many variations. Defaults to 5.
pitchRangedouble1Random change of pitch, plus or minus this many semitones; the speed changes with it, like a tape. Defaults to 1.
gainRangedouble2Random change of level, plus or minus this many dB. Defaults to 2.
seedlong1Seed of the random numbers, so the same call gives the same variations. Defaults to 1.

Returns An array of audio buffers.

audioSprite

Join named sounds into one audio sprite with a map of where each starts, the way Howler.js and game engines load effects

audioSprite( sounds, gap=0.1, path="" )
ArgumentTypeDefault
soundsstructrequiredA struct of name to audio buffer. They are joined in the order of the struct, so use an ordered struct, written with square brackets [ jump: a, coin: b ], when the order matters.
gapdouble0.1Seconds of silence between sounds. Defaults to 0.1.
pathstring""A file to write the sprite audio to; a .json map is written next to it in the Howler.js format. Empty to only return it.

Returns A struct with audio (the joined buffer) and sprites, a struct of name to { start, end, duration } in seconds. When a path is given, also path and mapPath.

Edit this page Download Markdown Last updated Oct 16, 2026, 11:59:46 AM Report an issue