How markharrison/audiomark works
Project type and purpose
• This is a front-end JavaScript audio library (“AudioMark”) for web games and interactive apps.
• It’s delivered as a single-file module (audio.js), demo page (index.html), tests (test.js), and docs (audiomark.md).
File structure
• Top-level files:
– audio.js: the core library implementation
– index.html & test.js: demo/test harness
– audiomark.md: API documentation
– README.md: overview & usage
• No backend or database layers—this lives entirely in the browser.
• Key external interactions: fetch (for audio file URLs), Web Audio API.
README for architectural clues
• Core features imply modular sub-systems inside audio.js:
– Loading (URL, File, ArrayBuffer)
– Preloading & processing queue
– Playback (SFX vs Music with separate channels)
– Volume control (master, music, sfx)
– Crossfade/transition manager
– Resource cleanup and context suspension handling
Main components & relationships
a. Components:
1. Demo/UI Layer (index.html + test.js)
2. AudioMark Library (audio.js) with internal modules:
– Loader Module
– Preloader/Queue Module
– Decoder Module (AudioContext.decodeAudioData)
– Playback Manager (SourceNode factory)
– Volume Controller (Master/Music/SFX GainNodes)
– Transition Manager (crossfade logic)
– Resource Manager (cleanup/suspension)
3. Web Audio API (AudioContext, AudioBufferSourceNode, GainNode, Destination)
4. External Resources (audio files served via HTTP)
b. Interactions:
– UI calls AudioMark.initialize(), loadAudio(), playMusic(), playSFX(), setVolume()
– Loader fetches URLs → ArrayBuffer
– Decoder hands off ArrayBuffer → AudioBuffer
– Playback Manager spawns AudioBufferSourceNode → GainNode → Destination
– Transition Manager orchestrates overlapping GainNodes for crossfade
– Volume Controller routes all channels through master GainNode
– Resource Manager monitors nodes for stop/unload
c. Architectural patterns & principles:
– Modular separation: Loader vs Decoder vs Playback vs Volume
– Single Responsibility: each module has a clear job
– Publish/Subscribe: state events (loaded, decoded, ended) for UI logging
– Lazy initialization & preloading workflow
d. Key technologies & libraries:
– Native Web Audio API (no external audio framework)
– ES6 module pattern in audio.js
– Fetch API for network loading