pub use pikopiko_runtime::synth::sn76489::{Sn76489Config, Sn76489Synth, 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-sn76489.rs"));
}
const PARAMS: &[ParamInfo] = &[
ParamInfo {
name: "noise_mode",
min: 0,
max: 1,
default: 1,
scope: Scope::Synth,
},
ParamInfo {
name: "noise_rate",
min: 0,
max: 3,
default: 1,
scope: Scope::Synth,
},
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: "3579545",
}];
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 * 1023.0)).ceil().clamp(0.0, 127.0) as u8;
let hi = hz_to_key(clock / 32.0).floor().clamp(0.0, 127.0) as u8;
(lo, hi)
}
pub const SN76489: SynthSpec = SynthSpec {
texts: text_table::CATALOGS,
name: "sn76489",
aliases: &["sn76496", "psg"],
max_tracks: 4,
polyphony: 1,
tones: &[ToneInfo { id: 0 }],
default_tone: 0,
unpitched_tones: &[],
duty_tones: false,
wave_memory: false,
params: PARAMS,
options: OPTIONS,
presets: &[],
knobs: &[],
tone_files: &[],
check_sample: None,
key_range,
create: |cfg, sr, n| Box::new(Sn76489Synth::new(sn76489_config(cfg), sr, n)),
};
pub fn sn76489_config(cfg: &SynthConfig) -> Sn76489Config {
Sn76489Config {
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!(SN76489.options[0].default, DEFAULT_CLOCK_HZ.to_string());
}
}