1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! # Audio
//!
//! The GameTank uses a dedicated 6502 coprocessor for audio synthesis.
//! This module provides the audio firmware and a high-level interface.
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use rom::sdk::audio::{FIRMWARE, voices, MidiNote, WAVETABLE};
//!
//! // Initialize audio (do once at startup)
//! console.sc.set_audio(0); // Disable while loading
//! console.audio.copy_from_slice(FIRMWARE); // Load firmware
//! console.sc.set_audio(0xFF); // Enable at ~14kHz
//!
//! // Play a note
//! let v = voices();
//! v[0].set_note(MidiNote::C4);
//! v[0].set_volume(63);
//! v[0].set_wavetable(WAVETABLE[0]);
//! ```
//!
//! ## Playing Music
//!
//! The wavetable synth gives you 8 voices. Each voice has:
//! - **Note/Frequency** - Set with [`Voice::set_note`](wavetable_8v::Voice::set_note) or raw frequency
//! - **Volume** - 0 (silent) to 63 (max)
//! - **Wavetable** - Which of 8 waveforms to use
//!
//! ```rust,ignore
//! let v = voices();
//!
//! // Play a C major chord
//! v[0].set_note(MidiNote::C4); v[0].set_volume(50);
//! v[1].set_note(MidiNote::E4); v[1].set_volume(50);
//! v[2].set_note(MidiNote::G4); v[2].set_volume(50);
//!
//! // Stop a voice
//! v[0].mute();
//! ```
//!
//! ## Custom Wavetables
//!
//! You can load custom 256-byte waveforms into the wavetable slots:
//!
//! ```rust,ignore
//! // Wavetables live at $3400-$3BFF in audio RAM (8 × 256 bytes)
//! let waveform: [u8; 256] = make_sine_wave();
//! console.audio[0x400..0x500].copy_from_slice(&waveform);
//! ```
//!
//! ## Audio Firmware
//!
//! Enable a firmware via Cargo features:
//! - `audio-wavetable-8ch` - 8-channel wavetable synth (default, recommended)
//! - `audio-wavetable-7ch-linear` - 7-channel wavetable synth with linear volume (16 levels)
//!
//! The firmware runs on the Audio Coprocessor at ~14kHz sample rate,
//! with about 660 CPU cycles available per sample for synthesis.
// Audio firmware binary - selected via Cargo.toml features
pub static FIRMWARE: & = include_bytes!;
pub static FIRMWARE: & = include_bytes!;
pub static FIRMWARE: & = include_bytes!;
// Audio interface modules - selected via Cargo.toml features
pub use *;
pub use *;
// Shared
pub use MidiNote;