AudioService (Sound and Music) - UQcsse3200/2026-studio-3 GitHub Wiki
AudioService
This page details the use of the AudioService class which handles the loading and playing of audio resources (sound effects and music).
Important Fields / Constants
-
SFX_COOLDOWN -> Amount of time in milliseconds before the same sound can be repeated. Exists to avoid audio getting spammed on menu items and so on.
-
UPPER/LOWER_PITCH_BOUND -> Pitch is varied randomly by a factor of .10 to create variation on repeat sound effects.
-
OVERLAP_DAMPING -> The factor by which volume is decreased on the second sound effect when two overlap.
-
FULL_MUSIC_VOLUME -> The maximum factor by which the music volume can be output. Essentially an abstraction for the UI slider and the reality of audio volume.
-
playing -> The actual record of the currently playing music object.
-
nowPlaying -> The current playlist associated with a given screen that might contain multiple songs.
-
soundPaths and musicPaths -> The required string arrays of asset paths for the ResourceService loading functions.
load()
This function wraps the ResourceService calls to load audio in the service where the encapsulated string arrays are kept. The current system time is also initialized for the sake of tracking sfx cooldowns.
MusicId and SoundId enums
Because of the way audio paths are loaded in and audio is played by libgdx it becomes necessary to remember long asset directories or sound effects by their index in an array. To wrap this logic behind something a bit clearer the MusicId and SoundId enums exist as verbose ID's that map to the array indices in AudioService.
playSound(SoundId soundID, float volume)
This static function will play the SoundId mapped effect where it is placed in the code logic. It wraps behaviors for locating the sound resource in memory, modulating the pitch and volume, and handles the cooldown logic.