pub use pikopiko_runtime::synth::scc::{SccConfig, SccSynth, 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-scc.rs"));
}
const PARAMS: &[ParamInfo] = &[
ParamInfo {
name: "share",
min: 0,
max: 1,
default: 0,
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 * 4096.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 SCC: SynthSpec = SynthSpec {
texts: text_table::CATALOGS,
name: "scc",
aliases: &["k051649", "konami-scc"],
max_tracks: 5,
polyphony: 1,
tones: &[
ToneInfo { id: 0 },
ToneInfo { id: 1 },
ToneInfo { id: 2 },
ToneInfo { id: 3 },
ToneInfo { id: 4 },
ToneInfo { id: 5 },
ToneInfo { id: 6 },
ToneInfo { id: 7 },
],
default_tone: 3,
unpitched_tones: &[],
duty_tones: true,
wave_memory: true,
params: PARAMS,
options: OPTIONS,
presets: &[],
knobs: &[],
tone_files: &[],
check_sample: None,
key_range,
create: |cfg, sr, n| Box::new(SccSynth::new(scc_config(cfg), sr, n)),
};
pub fn scc_config(cfg: &SynthConfig) -> SccConfig {
SccConfig {
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!(SCC.options[0].default, DEFAULT_CLOCK_HZ.to_string());
}
}