Courage.Audio#
Courage.Audio plays audio files from disk. Sounds run on a background audio thread and do not block the game loop.
Supported formats: MP3, WAV, FLAC, OGG/Vorbis.
Loading#
API#
Audio.play(path, loop?, volume?) -> handle | nil, err?#
Loads and plays an audio file. Returns a handle on success. On failure, returns nil and an error string.
| Parameter | Type | Description |
|---|---|---|
path | string | Absolute path to the audio file |
loop | boolean? | Loop until stopped. Defaults to false |
volume | number? | Linear playback volume. 1.0 is full volume, 0.0 is silent. Defaults to 1.0 |
Use Storage.asset_path to get the correct absolute path for a bundled asset file:
Audio.stop(handle)#
Stops and unloads a playing sound.
| Parameter | Type | Description |
|---|---|---|
handle | number | Handle returned by Audio.play |
Audio.set_volume(handle, volume)#
Sets the volume of a playing sound.
| Parameter | Type | Description |
|---|---|---|
handle | number | Handle returned by Audio.play |
volume | number | Linear volume. 1.0 is full volume, 0.0 is silent |
Audio.is_playing(handle) -> boolean#
Returns true if the sound is still playing.
| Parameter | Type | Description |
|---|---|---|
handle | number | Handle returned by Audio.play |
Audio.stop_all()#
Stops and unloads every sound currently playing.
Example: play a sound on a game event#
local Hook = require("Augment.Hook")
local Storage = require("Petrichor.Storage")
local Audio = require("Courage.Audio")
local soundPath = Storage.asset_path("void.mp3")
Hook.dStage_restartRoom:before(function()
Audio.play(soundPath)
end)
local Mod = {}
Mod.__index = Mod
function Mod.new() return setmetatable({}, Mod) end
function Mod:tick() end
function Mod:shutdown() Audio.stop_all() end
return Mod
Notes#
- Each call to
playallocates a new sound instance. Callstoporstop_allto free them. - Always call
Audio.stop_all()in your mod'sshutdownto avoid leaving sounds running after the mod is unloaded.
See also#
- Petrichor.Storage for
Storage.asset_path, which resolves bundled asset paths