pub use pikopiko_runtime::synth::apu2a03::{Apu2a03Config, Apu2a03Synth, DEFAULT_CLOCK_HZ};
use super::{
hz_to_key, OptionInfo, OptionKind, ParamInfo, Scope, SynthConfig, SynthSpec, ToneInfo,
};
#[allow(dead_code)]
pub(crate) mod text_table {
use crate::text::{Catalog, Seg};
include!(concat!(env!("OUT_DIR"), "/text-2a03.rs"));
}
const PARAMS: &[ParamInfo] = &[
ParamInfo {
name: "noise_mode",
min: 0,
max: 1,
default: 0,
scope: Scope::Synth,
},
ParamInfo {
name: "noise_period",
min: 0,
max: 15,
default: 6,
scope: Scope::Synth,
},
ParamInfo {
name: "sweep_shift",
min: 0,
max: 7,
default: 0,
scope: Scope::Track,
},
ParamInfo {
name: "sweep_period",
min: 0,
max: 7,
default: 0,
scope: Scope::Track,
},
ParamInfo {
name: "sweep_neg",
min: 0,
max: 1,
default: 0,
scope: Scope::Track,
},
ParamInfo {
name: "pan",
min: 0,
max: 16,
default: 8,
scope: Scope::Track,
},
];
const OPTIONS: &[OptionInfo] = &[OptionInfo {
name: "clock",
kind: OptionKind::Range {
min: 100_000,
max: 10_000_000,
},
default: "1789773",
}];
fn key_range(cfg: &SynthConfig) -> (u8, u8) {
let clock = cfg.get_u32("clock").unwrap_or(DEFAULT_CLOCK_HZ) as f64;
let lo = hz_to_key(clock / (32.0 * 2048.0)).ceil().clamp(0.0, 127.0) as u8;
let hi = hz_to_key(clock / (16.0 * 9.0)).floor().clamp(0.0, 127.0) as u8;
(lo, hi)
}
pub const APU_2A03: SynthSpec = SynthSpec {
texts: text_table::CATALOGS,
name: "2a03",
aliases: &["apu", "nes", "famicom"],
max_tracks: 4,
polyphony: 1,
tones: &[
ToneInfo { id: 0 },
ToneInfo { id: 1 },
ToneInfo { id: 2 },
ToneInfo { id: 3 },
],
default_tone: 2,
unpitched_tones: &[],
duty_tones: true,
wave_memory: false,
params: PARAMS,
options: OPTIONS,
presets: &[],
knobs: &[],
tone_files: &[],
check_sample: None,
key_range,
create: |cfg, sr, n| Box::new(Apu2a03Synth::new(apu2a03_config(cfg), sr, n)),
};
pub fn apu2a03_config(cfg: &SynthConfig) -> Apu2a03Config {
Apu2a03Config {
clock_hz: cfg.get_u32("clock").unwrap_or(DEFAULT_CLOCK_HZ),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_option_matches_runtime() {
assert_eq!(APU_2A03.options[0].default, DEFAULT_CLOCK_HZ.to_string());
}
}