Logo Mibo

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

Audio.fadeMusicIn ctx seconds

Full Usage: Audio.fadeMusicIn ctx seconds

Parameters:
    ctx : 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.

ctx : GameContext

The game context.

seconds : float32

Fade duration in seconds.

Returns: Cmd<'Msg>

Audio.fadeMusicOut ctx seconds

Full Usage: Audio.fadeMusicOut ctx seconds

Parameters:
    ctx : 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.

ctx : GameContext

The game context.

seconds : float32

Fade duration in seconds.

Returns: Cmd<'Msg>

Audio.pauseMusic ctx

Full Usage: Audio.pauseMusic ctx

Parameters:
Returns: Cmd<'Msg>
Type parameters: 'Msg

Pauses the music at the current position.

ctx : GameContext

The game context.

Returns: Cmd<'Msg>

Audio.play ctx key

Full Usage: Audio.play ctx key

Parameters:
    ctx : 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.

ctx : 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>

Audio.playMusic ctx key

Full Usage: Audio.playMusic ctx key

Parameters:
    ctx : 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.

ctx : GameContext

The game context.

key : string

The key the track was registered under in the bank.

Returns: Cmd<'Msg>

Audio.playMusicOnce ctx key

Full Usage: Audio.playMusicOnce ctx key

Parameters:
    ctx : 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.

ctx : GameContext

The game context.

key : string

The key the track was registered under in the bank.

Returns: Cmd<'Msg>

Audio.playWith ctx key voice

Full Usage: Audio.playWith ctx key voice

Parameters:
    ctx : 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.

ctx : 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>

Audio.resumeMusic ctx

Full Usage: Audio.resumeMusic ctx

Parameters:
Returns: Cmd<'Msg>
Type parameters: 'Msg

Resumes the music from where it was paused.

ctx : GameContext

The game context.

Returns: Cmd<'Msg>

Audio.seekMusic ctx seconds

Full Usage: Audio.seekMusic ctx seconds

Parameters:
    ctx : 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.

ctx : GameContext

The game context.

seconds : float32

The position to jump to, counted from the track start.

Returns: Cmd<'Msg>

Audio.setMasterVolume ctx volume

Full Usage: Audio.setMasterVolume ctx volume

Parameters:
    ctx : 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).

ctx : GameContext

The game context.

volume : float32

Master volume (1.0 = full).

Returns: Cmd<'Msg>

Audio.setMusicVolume ctx volume

Full Usage: Audio.setMusicVolume ctx volume

Parameters:
    ctx : 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.

ctx : GameContext

The game context.

volume : float32

Music volume (1.0 = full, 0.0 = silent).

Returns: Cmd<'Msg>

Audio.stopAll ctx

Full Usage: Audio.stopAll ctx

Parameters:
Returns: Cmd<'Msg>
Type parameters: 'Msg

Stops every playing sound effect. Music keeps playing.

ctx : GameContext

The game context.

Returns: Cmd<'Msg>

Audio.stopMusic ctx

Full Usage: Audio.stopMusic ctx

Parameters:
Returns: Cmd<'Msg>
Type parameters: 'Msg

Stops the music and resets it to its start.

ctx : GameContext

The game context.

Returns: Cmd<'Msg>

Type something to start searching.