Package-level declarations

Overview

Audio playback system providing sound effects and music management for the application. Supports loading, modifying, and playing audio files with various controls.

Key Components

  • AudioWrapper — Wrapper around Java Sound API for playing audio files

    • Loads audio from URLs

    • Supports volume, pitch, and playback speed control

    • Provides play, pause, stop, and loop functionality

  • AudioModifier — Fluent API for configuring audio properties

    • Set loop count (including infinite looping)

    • Configure volume levels

    • Adjust playback speed and pitch

  • AudioPool — Collection manager for multiple audio tracks

    • Stores and retrieves audio by name

    • Provides builder pattern for pool construction

    • Supports batch loading of audio resources

  • BooleanControlWrapper — Wrapper for on/off audio controls (mute, etc.)

  • FloatControlWrapper — Wrapper for continuous audio controls (volume, pan, etc.)

Responsibilities

  • Loading audio files from resources or URLs

  • Playing sound effects and background music

  • Managing audio playback state (play, pause, stop)

  • Controlling audio properties (volume, pitch, speed, looping)

  • Providing a simple API for game audio management

  • Handling audio control types (boolean and float controls)

Usage Examples

// Load a single audio file
val audio = loadAudio("click", url)

// Load audio with infinite looping
val music = loadAudio("theme", url, AudioModifier().setToLoopInfinitely())

// Build an audio pool
val audioPool = buildAudioPool {
add(loadAudio("click", clickUrl))
add(loadAudio("move", moveUrl))
add(loadAudio("capture", captureUrl))
}

// Play audio from pool
audioPool["click"]?.play()

Notes

  • Uses Java Sound API (javax.sound.sampled) for audio playback

  • Supports common audio formats (WAV, AIFF, AU)

  • Audio controls depend on the underlying audio format and system capabilities

  • Gracefully handles missing controls with fallback behavior

Types

Link copied to clipboard
data class AudioModifier(val closeOnFinish: Boolean = false, val gotoStartOnStop: Boolean = true, val startPosition: Int? = null, val loop: Boolean = false, val loopStartPosition: Int? = null, val loopEndPosition: Int? = null)

Modifier for audio playback behavior.

Link copied to clipboard
class AudioPool(startPool: List<AudioWrapper>)

Represents a pool of audio tracks that can be managed together.

Link copied to clipboard
data class AudioWrapper(val id: String, val clip: Clip, val modifier: AudioModifier = AudioModifier())

A wrapper for an audio Clip, providing methods to control playback and audio properties.