melody-bay
melody-bay is a Kira-compatible audio graph and sequencing crate with a
Rust-shaped WebAudio API. It is designed for games, tools, tests, and offline
audio workflows that want WebAudio-style nodes without a browser runtime.
The name is a nod to Melody Bay, the music puzzle location in Super Mario RPG.
The core graph models WebAudio concepts such as AudioContext, source nodes,
AudioParam automation, filters, panners, analysers, worklets, offline
rendering, and channel routing. The sequencer layer adds tempo-mapped and
timestamped note events that can render offline or play through Kira
SoundData.
Quick Start
use ;
let mut context = new;
let osc = context.create_oscillator;
osc.set_type;
osc.frequency.set_value?;
osc.try_start?;
osc.try_stop?;
let gain = context.create_gain;
gain.gain.set_value?;
context.connect?;
context.connect?;
# Ok::
For live playback, pass context.sound_data() to a Kira AudioManager. For
headless verification or asset generation, use OfflineAudioContext and
start_rendering().
Sequencing
Use IndexedSequence for tempo-mapped musical material and TimedSequence for
events that already have exact timestamps. Indexed sequences resolve to timed
sequences before rendering or playback.
use ;
let mut graph = new;
let source = graph.create_constant_source;
let gain = graph.create_gain;
graph.connect?;
graph.connect?;
let mut sequence = new;
sequence.tempo_at;
sequence.add_track;
let timed = sequence.resolve;
let _sound_data = timed.try_sound_data?.sample_rate;
# Ok::
Infallible sequencer helpers follow Kira's ergonomic SoundData style and skip
invalid automation. Use validate, try_sound_data, try_render_offline, and
try_track_sound_data when invalid tracks or automation should be reported.
Importers
The crate includes MIDI, MOD, and XM import helpers:
let bytes = read?;
let imported = import_midi?;
let sequence = imported.sequence.resolve;
# Ok::
Importers preserve supported musical structure and report approximations or
unsupported effects as ImportWarning values. They are intentionally practical
instead of bit-exact emulators; use the warning list when building conversion
tools.
WebAudio Compatibility
melody-bay follows WebAudio graph shape where it maps cleanly to Rust and
Kira. Browser-only integration points are intentionally unsupported: DOM media
elements, MediaStream, sink/device selection, decodeAudioData,
ScriptProcessorNode, AudioRenderCapacity, JavaScript module loading,
MessagePort, promises, and EventTarget.
Use create_sound_data_source for Kira media/source integration and
create_audio_worklet_node with an AudioWorkletProcessor implementation for
custom render-quantum processing. Panner nodes use equal-power spatialization;
HRTF panning is not currently implemented.
Examples
Run examples from the crate root:
Live examples use CPAL and require an audio output device. Offline examples and
tests run headlessly. See examples/README.md for the curated live demo map.
License
Licensed under the MIT license.