Audio Module
Audio commands for MVU programs: play sound effects with per-play knobs, drive the single music channel (play, pause, seek, fades), and set volumes. Resolve nothing yourself — the helpers find the host-registered IAudio service through the GameContext.
The sounds and tracks are registered in the program's bank
(RaylibProgram.withBank / MonoGameProgram.withBank) before
init runs. Playing an unregistered key is a silent no-op, as is
every helper when no audio service is registered (headless runs).
fadeMusicIn fades toward the last volume passed to
setMusicVolume (1.0 if never set), so the music slider and fades
compose: setMusicVolume ctx 0.8f once, then
fadeMusicIn ctx 2.0f after every track start.
Example
| Jump -> { model with Vy = jumpSpeed }, Audio.play ctx "jump"
| LevelStart ->
model,
Cmd.batch
[ Audio.playMusic ctx "overworld"
Audio.fadeMusicIn ctx 2.0f ]
Functions and values
| Function or value |
Description
|
Full Usage:
Audio.fadeMusicIn ctx seconds
Parameters:
GameContext
-
The game context.
seconds : float32
-
Fade duration in seconds.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Fades the music in over seconds, toward the current music slider value — the last volume passed to Audio.setMusicVolume (1.0 if never set), read from the service.
|
Full Usage:
Audio.fadeMusicOut ctx seconds
Parameters:
GameContext
-
The game context.
seconds : float32
-
Fade duration in seconds.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Fades the music out over seconds; the music stops when the fade completes.
|
Full Usage:
Audio.pauseMusic ctx
Parameters:
GameContext
-
The game context.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
|
Full Usage:
Audio.play ctx key
Parameters:
GameContext
-
The game context (the helpers resolve the audio service from it).
key : string
-
The key the sound was registered under in the bank.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Plays the sound registered under key with the default voice.
|
Full Usage:
Audio.playMusic ctx key
Parameters:
GameContext
-
The game context.
key : string
-
The key the track was registered under in the bank.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Starts the music registered under key as the background track, looping. Replaces the track that is playing.
|
Full Usage:
Audio.playMusicOnce ctx key
Parameters:
GameContext
-
The game context.
key : string
-
The key the track was registered under in the bank.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Starts the music registered under key once through, then stops. Replaces the track that is playing.
|
Full Usage:
Audio.playWith ctx key voice
Parameters:
GameContext
-
The game context.
key : string
-
The key the sound was registered under in the bank.
voice : Voice
-
Volume, pan, and pitch for this playback (start from Voice.center and update fields).
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Plays the sound registered under key with per-play knobs.
|
Full Usage:
Audio.resumeMusic ctx
Parameters:
GameContext
-
The game context.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
|
Full Usage:
Audio.seekMusic ctx seconds
Parameters:
GameContext
-
The game context.
seconds : float32
-
The position to jump to, counted from the track start.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Seeks the music to an absolute time in seconds.
|
Full Usage:
Audio.setMasterVolume ctx volume
Parameters:
GameContext
-
The game context.
volume : float32
-
Master volume (1.0 = full).
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Sets the master volume that scales the whole mix — every sound effect and the music channel, live (see IAudio.SetMasterVolume).
|
Full Usage:
Audio.setMusicVolume ctx volume
Parameters:
GameContext
-
The game context.
volume : float32
-
Music volume (1.0 = full, 0.0 = silent).
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Sets the music volume live — the music slider. This is also the volume a later Audio.fadeMusicIn fades to.
|
Full Usage:
Audio.stopAll ctx
Parameters:
GameContext
-
The game context.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Stops every playing sound effect. Music keeps playing.
|
Full Usage:
Audio.stopMusic ctx
Parameters:
GameContext
-
The game context.
Returns: Cmd<'Msg>
Type parameters: 'Msg |
Mibo