The Clayground.Sound module provides cross-platform audio for games:
.song.json pattern file against instruments.sfx.json effect recipe, with variation, live or rendered offlineThe engine mixes in stereo. Every instrument has a pan, from -1 (left) to +1 (right). The centre, 0 and the default, plays the same samples in both channels that the engine played in mono before; panning only turns the far channel down, to silence at either edge.
Every instrument also names the bus its voices mix into: "sfx" (the default), "music" or "voice". SoundMixer holds one volume per bus, which scales everything on that bus on top of each instrument's own volume, so a game's settings screen sets three numbers instead of touching every instrument. SongPlayer.volume scales every note a song plays, whatever instrument plays it.
| Platform | Backend |
|---|---|
| WASM (Browser) | Web Audio API via Emscripten |
| Desktop (Windows/macOS/Linux) | Qt Multimedia (QSoundEffect, QMediaPlayer) |
| Mobile (iOS/Android) | Qt Multimedia |
Import the module:
import Clayground.Sound
Use Sound for short audio like jumps, clicks, or explosions:
Sound {
id: jumpSound
source: "sounds/jump.wav"
volume: 0.8
}
// Play sound (can overlap multiple times)
onPlayerJumped: jumpSound.play()
Use Music for longer tracks with playback controls:
Music {
id: bgMusic
source: "music/theme.mp3"
volume: 0.5
loop: true
}
onGameStarted: bgMusic.play()
onGamePaused: bgMusic.pause()
onGameOver: bgMusic.stop()
By default, audio is preloaded when source is set. For memory optimization, enable lazy loading to defer loading until first play:
Sound { source: "sounds/rare_event.wav" lazyLoading: true // Only loads when play() is called }
loop; use the finished signal or a Sound re-triggered by a Timer for a looping background track.mp3 for Music - a staged .wav is labelled audio/vnd.wave, a type browsers decline, and stays silentSNES-style echo of one bus: a delay, feedback and an 8-tap FIR filter | |
SNES-style atmospheric music generator with customizable environments and scales | |
Play background music with play/pause/stop/loop controls | |
Small reverb of one bus | |
PCM sample playback with loop points, root note, and ADSR | |
Plays an effect recipe (.sfx.json) with variation, and renders it offline the same way | |
Plays a parsed .song.json file against a set of instruments | |
Play sound effects with support for overlapping playback | |
Volume, echo and reverb of each mixer bus: sound effects, music and voices | |
Real-time oscillator voice with ADSR, pitch envelope, LFO and a resonant filter |