use crate::synth::cymbal::{CymbalBand, CymbalSpec};
use crate::synth::perc::{
Particles, PercMode, PercNoise, PercSpec, PercTone, Resonator,
};
#[derive(Clone, Copy, Debug)]
pub enum DrumSound {
Perc(&'static PercSpec),
Cymbal(&'static CymbalSpec),
}
#[derive(Clone, Copy, Debug)]
pub struct DrumPatch {
pub sound: DrumSound,
pub gain: f32,
pub group: u8,
pub pan: f32,
}
const fn perc(spec: &'static PercSpec, gain: f32) -> DrumPatch {
DrumPatch {
sound: DrumSound::Perc(spec),
gain,
group: 0,
pan: 0.0,
}
}
const fn cymbal(spec: &'static CymbalSpec, gain: f32) -> DrumPatch {
DrumPatch {
sound: DrumSound::Cymbal(spec),
gain,
group: 0,
pan: 0.0,
}
}
const fn group(mut p: DrumPatch, g: u8) -> DrumPatch {
p.group = g;
p
}
const fn pan(mut p: DrumPatch, x: f32) -> DrumPatch {
p.pan = x;
p
}
pub const DRUM_KEYS: std::ops::RangeInclusive<u8> = 27..=87;
pub fn gm_drum_name(key: u8) -> Option<&'static str> {
const NAMES: [&str; 61] = [
"High Q",
"Slap",
"Scratch Push",
"Scratch Pull",
"Sticks",
"Square Click",
"Metronome Click",
"Metronome Bell",
"Acoustic Bass Drum",
"Bass Drum 1",
"Side Stick",
"Acoustic Snare",
"Hand Clap",
"Electric Snare",
"Low Floor Tom",
"Closed Hi-Hat",
"High Floor Tom",
"Pedal Hi-Hat",
"Low Tom",
"Open Hi-Hat",
"Low-Mid Tom",
"Hi-Mid Tom",
"Crash Cymbal 1",
"High Tom",
"Ride Cymbal 1",
"Chinese Cymbal",
"Ride Bell",
"Tambourine",
"Splash Cymbal",
"Cowbell",
"Crash Cymbal 2",
"Vibraslap",
"Ride Cymbal 2",
"Hi Bongo",
"Low Bongo",
"Mute Hi Conga",
"Open Hi Conga",
"Low Conga",
"High Timbale",
"Low Timbale",
"High Agogo",
"Low Agogo",
"Cabasa",
"Maracas",
"Short Whistle",
"Long Whistle",
"Short Guiro",
"Long Guiro",
"Claves",
"Hi Wood Block",
"Low Wood Block",
"Mute Cuica",
"Open Cuica",
"Mute Triangle",
"Open Triangle",
"Shaker",
"Jingle Bell",
"Belltree",
"Castanets",
"Mute Surdo",
"Open Surdo",
];
DRUM_KEYS
.contains(&key)
.then(|| NAMES[(key - DRUM_KEYS.start()) as usize])
}
const fn band(hz: f32, db: f32, bloom: f32, tau: f32) -> CymbalBand {
CymbalBand { hz, db, bloom, tau }
}
const CRASH_BANDS: [CymbalBand; 10] = [
band(150.0, -30.0, 0.0, 0.05),
band(250.0, -16.0, -1.5, 0.06),
band(400.0, -4.0, -4.0, 0.05),
band(600.0, -3.0, -1.0, 0.05),
band(1_100.0, -11.0, -0.5, 0.1),
band(2_000.0, -2.0, 0.85, 0.05),
band(3_150.0, 8.5, 0.9, 0.05),
band(5_000.0, 3.0, 0.85, 0.07),
band(9_000.0, -6.0, 0.7, 0.1),
band(13_000.0, -18.0, 0.0, 0.1),
];
const CRASH_1: CymbalSpec = CymbalSpec {
seed: 49,
lo: 140.0,
hi: 13_000.0,
density: 3.0,
scatter_db: 4.0,
floor_db: -4.0,
bands: &CRASH_BANDS,
ring: 7.5,
ring_corner: 4_500.0,
brightness: 7_000.0,
noise_hz: 11_000.0,
stick: 0.2,
stick_tau: 0.03,
sizzle: 0.08,
sizzle_t60: 1.2,
drive: 0.0,
wobble: 1.2,
};
const CRASH_2: CymbalSpec = CymbalSpec {
seed: 57,
lo: 110.0,
ring: 6.5,
ring_corner: 4_600.0,
brightness: 6_000.0,
..CRASH_1
};
const SPLASH_BANDS: [CymbalBand; 7] = [
band(300.0, -15.0, 0.0, 0.05),
band(500.0, 0.0, -1.5, 0.05),
band(1_000.0, 2.0, -1.0, 0.05),
band(2_000.0, 3.0, -0.5, 0.08),
band(4_000.0, 8.0, 0.5, 0.025),
band(8_000.0, 8.0, 0.5, 0.04),
band(13_000.0, -2.0, 0.3, 0.05),
];
const SPLASH: CymbalSpec = CymbalSpec {
seed: 55,
lo: 300.0,
hi: 13_000.0,
density: 3.0,
scatter_db: 4.0,
floor_db: -2.0,
bands: &SPLASH_BANDS,
ring: 2.2,
ring_corner: 7_000.0,
brightness: 8_000.0,
noise_hz: 11_000.0,
stick: 0.25,
stick_tau: 0.02,
sizzle: 0.12,
sizzle_t60: 0.7,
drive: 0.0,
wobble: 1.2,
};
const CHINA_BANDS: [CymbalBand; 8] = [
band(150.0, -20.0, 0.0, 0.05),
band(300.0, 2.0, -1.5, 0.06),
band(600.0, 6.0, -1.0, 0.08),
band(1_200.0, 8.0, 0.6, 0.04),
band(2_400.0, 9.0, 0.7, 0.05),
band(4_800.0, 5.0, 0.6, 0.06),
band(9_000.0, -6.0, 0.4, 0.1),
band(13_000.0, -15.0, 0.0, 0.1),
];
const CHINA: CymbalSpec = CymbalSpec {
seed: 52,
lo: 140.0,
hi: 13_000.0,
density: 3.5,
scatter_db: 5.0,
floor_db: 0.0,
bands: &CHINA_BANDS,
ring: 3.0,
ring_corner: 4_000.0,
brightness: 6_000.0,
noise_hz: 11_000.0,
stick: 0.25,
stick_tau: 0.03,
sizzle: 0.06,
sizzle_t60: 0.8,
drive: 0.6,
wobble: 1.2,
};
const RIDE_BANDS: [CymbalBand; 10] = [
band(150.0, -30.0, 0.0, 0.05),
band(200.0, -24.0, -2.0, 0.05),
band(315.0, -4.0, -1.8, 0.08),
band(500.0, -13.0, -0.3, 0.1),
band(800.0, -1.0, 0.0, 0.1),
band(1_250.0, -8.0, 0.0, 0.1),
band(2_000.0, -7.0, 0.3, 0.08),
band(3_150.0, 1.0, -0.4, 0.12),
band(5_000.0, -3.0, -1.0, 0.12),
band(8_000.0, -4.0, -1.8, 0.12),
];
const RIDE_1: CymbalSpec = CymbalSpec {
seed: 51,
lo: 150.0,
hi: 13_000.0,
density: 4.5,
scatter_db: 12.0,
floor_db: -22.0,
bands: &RIDE_BANDS,
ring: 12.0,
ring_corner: 4_000.0,
brightness: 8_000.0,
noise_hz: 8_000.0,
stick: 16.0,
stick_tau: 0.02,
sizzle: 0.015,
sizzle_t60: 1.5,
drive: 0.0,
wobble: 1.2,
};
const RIDE_2_BANDS: [CymbalBand; 10] = [
band(150.0, -30.0, 0.0, 0.05),
band(200.0, -24.0, -2.0, 0.05),
band(315.0, -8.0, -1.8, 0.08),
band(500.0, -14.0, -0.3, 0.1),
band(800.0, -5.0, 0.0, 0.1),
band(1_250.0, -9.0, 0.0, 0.1),
band(2_000.0, -7.0, 0.3, 0.08),
band(3_150.0, 0.0, -0.4, 0.12),
band(5_000.0, -1.0, -1.0, 0.12),
band(8_000.0, -1.0, -1.8, 0.12),
];
const RIDE_2: CymbalSpec = CymbalSpec {
seed: 59,
bands: &RIDE_2_BANDS,
ring: 11.0,
..RIDE_1
};
const RIDE_BELL_BANDS: [CymbalBand; 6] = [
band(400.0, -6.0, 0.0, 0.05),
band(800.0, 4.0, 0.0, 0.05),
band(1_600.0, 6.0, 0.0, 0.05),
band(3_200.0, 3.0, -0.5, 0.08),
band(6_000.0, -6.0, -1.5, 0.08),
band(9_000.0, -14.0, -1.5, 0.08),
];
const RIDE_BELL: CymbalSpec = CymbalSpec {
seed: 53,
lo: 400.0,
hi: 9_000.0,
density: 1.0,
scatter_db: 9.0,
floor_db: -15.0,
bands: &RIDE_BELL_BANDS,
ring: 7.0,
ring_corner: 4_000.0,
brightness: 6_000.0,
noise_hz: 10_000.0,
stick: 0.3,
stick_tau: 0.015,
sizzle: 0.02,
sizzle_t60: 1.0,
drive: 0.0,
wobble: 0.4,
};
const fn m(hz: f32, db: f32, t60: f32) -> PercMode {
PercMode {
hz,
db,
t60,
delay: 0.0,
}
}
const fn nz(lo: f32, hi: f32, db: f32, t60: f32) -> PercNoise {
PercNoise {
lo,
hi,
db,
delay: 0.0,
attack: 0.0005,
hold: 0.0,
t60,
bursts: 1,
spacing: 0.0,
vel: 0.0,
}
}
const fn rz(hz: f32, q: f32, db: f32) -> Resonator {
Resonator { hz, q, db }
}
const fn tuned<const N: usize>(
f0: f32,
rows: [(f32, f32, f32); N],
) -> [PercMode; N] {
let mut out = [m(0.0, 0.0, 0.0); N];
let mut k = 0;
while k < N {
out[k] = m(f0 * rows[k].0, rows[k].1, rows[k].2);
k += 1;
}
out
}
const fn membrane(f0: f32, second: f32, t60: f32, slope: f32) -> [PercMode; 8] {
const RATIO: [f32; 8] =
[1.0, 1.594, 2.136, 2.296, 2.653, 2.918, 3.156, 3.501];
const LEVEL: [f32; 8] = [0.0, -4.0, -8.0, -11.0, -13.0, -15.0, -17.0, -19.0];
let mut out = [m(0.0, 0.0, 0.0); 8];
let mut k = 0;
while k < 8 {
let r = if k == 1 { second } else { RATIO[k] };
let mut d = 1.0;
let mut j = 0;
while j < 4 {
d *= 1.0 + (r - 1.0) * slope * 0.25;
j += 1;
}
out[k] = m(f0 * r, LEVEL[k], t60 / d);
k += 1;
}
out
}
const KICK_MODES: [PercMode; 8] = membrane(52.0, 1.62, 0.3, 2.2);
const KICK_NOISE: [PercNoise; 3] = [
PercNoise {
vel: 0.6,
..nz(500.0, 4_000.0, 3.0, 0.035)
},
nz(200.0, 800.0, 0.0, 0.03),
PercNoise {
attack: 0.01,
..nz(150.0, 1_500.0, -14.0, 0.2)
},
];
const KICK: PercSpec = PercSpec {
modes: &KICK_MODES,
glide: 0.9,
glide_tau: 0.015,
hardness: 2_500.0,
noise: &KICK_NOISE,
..PercSpec::EMPTY
};
const KICK_BIG_MODES: [PercMode; 8] = membrane(50.0, 1.58, 0.42, 1.8);
const KICK_BIG_NOISE: [PercNoise; 3] = [
PercNoise {
vel: 0.6,
..nz(600.0, 5_000.0, 2.0, 0.03)
},
nz(200.0, 900.0, -2.0, 0.035),
PercNoise {
attack: 0.01,
..nz(150.0, 1_500.0, -12.0, 0.25)
},
];
const KICK_BIG: PercSpec = PercSpec {
modes: &KICK_BIG_MODES,
glide: 0.6,
glide_tau: 0.02,
hardness: 2_500.0,
noise: &KICK_BIG_NOISE,
..PercSpec::EMPTY
};
const SNARE_MODES: [PercMode; 10] = [
m(185.0, -5.0, 0.2),
m(300.0, -3.0, 0.35),
m(420.0, -14.0, 0.35),
m(498.0, -14.0, 0.4),
m(590.0, -14.0, 0.45),
m(705.0, -14.0, 0.35),
m(905.0, -18.0, 0.3),
m(1_150.0, -20.0, 0.25),
m(1_420.0, -23.0, 0.2),
m(1_760.0, -25.0, 0.18),
];
const SNARE_NOISE: [PercNoise; 3] = [
PercNoise {
delay: 0.002,
attack: 0.002,
..nz(2_200.0, 11_000.0, 1.0, 0.55)
},
PercNoise {
delay: 0.001,
attack: 0.002,
..nz(500.0, 2_200.0, -16.0, 0.25)
},
PercNoise {
vel: 0.6,
..nz(1_500.0, 14_000.0, -10.0, 0.01)
},
];
const SNARE: PercSpec = PercSpec {
modes: &SNARE_MODES,
glide: 0.06,
glide_tau: 0.02,
hardness: 2_500.0,
noise: &SNARE_NOISE,
..PercSpec::EMPTY
};
const SNARE_TIGHT_MODES: [PercMode; 8] = [
m(240.0, 0.0, 0.35),
m(392.0, -4.0, 0.3),
m(545.0, -9.0, 0.28),
m(650.0, -9.0, 0.3),
m(770.0, -11.0, 0.3),
m(920.0, -16.0, 0.22),
m(1_180.0, -19.0, 0.2),
m(1_500.0, -22.0, 0.15),
];
const SNARE_TIGHT_NOISE: [PercNoise; 3] = [
PercNoise {
delay: 0.0015,
attack: 0.0015,
..nz(3_000.0, 12_000.0, 0.0, 0.3)
},
PercNoise {
delay: 0.001,
attack: 0.002,
..nz(700.0, 3_000.0, -12.0, 0.18)
},
PercNoise {
vel: 0.6,
..nz(2_000.0, 15_000.0, -5.0, 0.008)
},
];
const SNARE_TIGHT: PercSpec = PercSpec {
modes: &SNARE_TIGHT_MODES,
glide: 0.05,
glide_tau: 0.015,
hardness: 3_500.0,
noise: &SNARE_TIGHT_NOISE,
..PercSpec::EMPTY
};
const SIDE_STICK_MODES: [PercMode; 11] = [
m(188.0, -12.0, 0.15),
m(339.0, -13.0, 0.1),
m(468.0, -17.0, 0.08),
m(711.0, -18.0, 0.08),
m(1_007.0, -2.0, 0.06),
m(1_125.0, 0.0, 0.08),
m(1_346.0, -8.0, 0.07),
m(1_453.0, -8.0, 0.06),
m(1_820.0, -5.0, 0.05),
m(2_864.0, -8.0, 0.04),
m(3_900.0, -12.0, 0.03),
];
const SIDE_STICK_NOISE: [PercNoise; 1] = [PercNoise {
vel: 0.4,
..nz(1_500.0, 14_000.0, 12.0, 0.015)
}];
const SIDE_STICK: PercSpec = PercSpec {
modes: &SIDE_STICK_MODES,
hardness: 6_000.0,
noise: &SIDE_STICK_NOISE,
..PercSpec::EMPTY
};
const CLAP_NOISE: [PercNoise; 2] = [
PercNoise {
bursts: 3,
spacing: 0.011,
..nz(900.0, 2_200.0, 2.0, 0.02)
},
PercNoise {
delay: 0.008,
attack: 0.006,
..nz(400.0, 2_400.0, -14.0, 0.45)
},
];
const CLAP: PercSpec = PercSpec {
noise: &CLAP_NOISE,
..PercSpec::EMPTY
};
const TOM_STICK: PercNoise = PercNoise {
vel: 0.6,
..nz(900.0, 5_000.0, -5.0, 0.012)
};
const TOM_NOISE_FLOOR: [PercNoise; 2] = [
TOM_STICK,
PercNoise {
attack: 0.002,
..nz(250.0, 1_500.0, -2.0, 0.4)
},
];
const TOM_NOISE_RACK: [PercNoise; 2] = [
TOM_STICK,
PercNoise {
attack: 0.002,
..nz(300.0, 3_000.0, -2.0, 0.6)
},
];
const TOM_FLOOR_LO_MODES: [PercMode; 8] = membrane(82.0, 1.84, 2.6, 1.0);
const TOM_FLOOR_HI_MODES: [PercMode; 8] = membrane(98.0, 1.8, 2.2, 1.0);
const TOM_LO_MODES: [PercMode; 8] = membrane(117.0, 1.75, 1.8, 1.0);
const TOM_LO_MID_MODES: [PercMode; 8] = membrane(148.0, 1.7, 1.5, 1.0);
const TOM_HI_MID_MODES: [PercMode; 8] = membrane(178.0, 1.68, 1.3, 1.0);
const TOM_HI_MODES: [PercMode; 8] = membrane(215.0, 1.65, 1.1, 1.0);
const TOM: PercSpec = PercSpec {
glide: 0.12,
glide_tau: 0.04,
hardness: 1_800.0,
noise: &TOM_NOISE_RACK,
..PercSpec::EMPTY
};
const TOM_FLOOR_LO: PercSpec = PercSpec {
modes: &TOM_FLOOR_LO_MODES,
noise: &TOM_NOISE_FLOOR,
..TOM
};
const TOM_FLOOR_HI: PercSpec = PercSpec {
modes: &TOM_FLOOR_HI_MODES,
noise: &TOM_NOISE_FLOOR,
..TOM
};
const TOM_LO: PercSpec = PercSpec {
modes: &TOM_LO_MODES,
..TOM
};
const TOM_LO_MID: PercSpec = PercSpec {
modes: &TOM_LO_MID_MODES,
..TOM
};
const TOM_HI_MID: PercSpec = PercSpec {
modes: &TOM_HI_MID_MODES,
..TOM
};
const TOM_HI: PercSpec = PercSpec {
modes: &TOM_HI_MODES,
..TOM
};
const HAND_SLAP: [PercNoise; 1] = [PercNoise {
vel: 0.6,
..nz(800.0, 8_000.0, -10.0, 0.03)
}];
const BONGO_HI_MODES: [PercMode; 8] = tuned(
420.0,
[
(1.0, 0.0, 0.12),
(1.246, -11.0, 0.09),
(1.47, -19.0, 0.1),
(2.62, -18.0, 0.05),
(4.35, -30.0, 0.06),
(5.57, -30.0, 0.05),
(6.69, -35.0, 0.1),
(8.79, -28.0, 0.04),
],
);
const BONGO_LO_MODES: [PercMode; 7] = tuned(
300.0,
[
(1.0, -2.0, 0.18),
(1.617, 0.0, 0.08),
(2.40, -9.0, 0.35),
(3.26, -16.0, 0.22),
(3.52, -7.0, 0.07),
(4.62, -27.0, 0.05),
(5.76, -27.0, 0.13),
],
);
const CONGA_HI_MODES: [PercMode; 10] = tuned(
336.0,
[
(0.79, -7.0, 0.28),
(1.0, 0.0, 0.39),
(1.568, -11.0, 0.4),
(2.17, -20.0, 0.16),
(2.37, -25.0, 0.16),
(2.76, -24.0, 0.25),
(3.0, -23.0, 0.18),
(3.12, -25.0, 0.04),
(4.39, -29.0, 0.13),
(5.6, -30.0, 0.06),
],
);
const CONGA_MUTE_MODES: [PercMode; 8] = tuned(
300.0,
[
(1.0, 0.0, 0.06),
(1.33, -11.0, 0.19),
(2.47, -25.0, 0.13),
(3.29, -34.0, 0.25),
(4.07, -34.0, 0.1),
(4.36, -38.0, 0.25),
(6.8, -33.0, 0.04),
(8.03, -32.0, 0.04),
],
);
const CONGA_LO_MODES: [PercMode; 10] = tuned(
207.0,
[
(1.0, 0.0, 0.45),
(1.377, -6.0, 0.39),
(1.686, -4.0, 0.25),
(2.338, -10.0, 0.07),
(2.58, -8.0, 0.13),
(3.256, -17.0, 0.19),
(4.02, -26.0, 0.1),
(4.22, -24.0, 0.12),
(7.22, -18.0, 0.04),
(8.25, -20.0, 0.06),
],
);
const SURDO_MODES: [PercMode; 8] = membrane(64.0, 1.6, 1.0, 1.4);
const SURDO_MUTE_MODES: [PercMode; 8] = membrane(66.0, 1.6, 0.18, 1.0);
const HAND: PercSpec = PercSpec {
glide: 0.04,
glide_tau: 0.03,
hardness: 1_600.0,
noise: &HAND_SLAP,
..PercSpec::EMPTY
};
const BONGO_HI: PercSpec = PercSpec {
modes: &BONGO_HI_MODES,
hardness: 2_400.0,
..HAND
};
const BONGO_LO: PercSpec = PercSpec {
modes: &BONGO_LO_MODES,
hardness: 2_000.0,
..HAND
};
const CONGA_MUTE: PercSpec = PercSpec {
modes: &CONGA_MUTE_MODES,
hardness: 2_200.0,
..HAND
};
const CONGA_HI: PercSpec = PercSpec {
modes: &CONGA_HI_MODES,
..HAND
};
const CONGA_LO: PercSpec = PercSpec {
modes: &CONGA_LO_MODES,
..HAND
};
const SURDO_NOISE: [PercNoise; 1] = [nz(300.0, 2_500.0, -24.0, 0.03)];
const SURDO: PercSpec = PercSpec {
modes: &SURDO_MODES,
glide: 0.1,
glide_tau: 0.05,
hardness: 900.0,
noise: &SURDO_NOISE,
..PercSpec::EMPTY
};
const SURDO_MUTE: PercSpec = PercSpec {
modes: &SURDO_MUTE_MODES,
..SURDO
};
const TIMBALE_HI_MODES: [PercMode; 15] = tuned(
434.0,
[
(0.514, -2.0, 0.42),
(1.0, 0.0, 0.42),
(1.11, -7.0, 0.43),
(1.40, -9.0, 0.37),
(1.54, -2.0, 0.04),
(1.90, -11.0, 0.07),
(2.23, -13.0, 0.04),
(3.15, -8.0, 0.19),
(3.54, -13.0, 0.15),
(6.93, -16.0, 0.16),
(5.67, -26.0, 0.35),
(6.70, -24.0, 0.4),
(7.23, -24.0, 0.4),
(9.56, -27.0, 0.35),
(13.9, -30.0, 0.3),
],
);
const TIMBALE_LO_MODES: [PercMode; 15] = tuned(
282.0,
[
(0.507, 0.0, 0.61),
(1.0, -3.0, 1.5),
(1.43, -4.0, 0.04),
(1.97, -13.0, 0.72),
(2.60, -20.0, 0.51),
(2.92, -17.0, 0.55),
(3.32, -21.0, 0.09),
(3.72, -19.0, 0.31),
(4.73, -17.0, 0.42),
(5.79, -19.0, 0.12),
(6.99, -28.0, 0.45),
(10.75, -26.0, 0.5),
(12.38, -26.0, 0.5),
(14.7, -29.0, 0.4),
(21.5, -31.0, 0.35),
],
);
const STICK_CLICK: [PercNoise; 1] = [PercNoise {
vel: 0.5,
..nz(1_500.0, 12_000.0, -12.0, 0.01)
}];
const TIMBALE_HI: PercSpec = PercSpec {
modes: &TIMBALE_HI_MODES,
glide: 0.03,
glide_tau: 0.02,
hardness: 5_000.0,
noise: &STICK_CLICK,
..PercSpec::EMPTY
};
const TIMBALE_LO: PercSpec = PercSpec {
modes: &TIMBALE_LO_MODES,
..TIMBALE_HI
};
const COWBELL_MODES: [PercMode; 12] = tuned(
540.0,
[
(0.91, -12.0, 0.25),
(1.0, 0.0, 0.31),
(2.063, -14.0, 0.6),
(2.668, -24.0, 0.5),
(3.386, -29.0, 0.37),
(3.994, -13.0, 0.25),
(4.990, -14.0, 0.48),
(5.042, -15.0, 0.39),
(5.320, -28.0, 0.4),
(5.451, -28.0, 0.21),
(6.66, -25.0, 0.3),
(8.226, -31.0, 0.25),
],
);
const COWBELL: PercSpec = PercSpec {
modes: &COWBELL_MODES,
hardness: 5_000.0,
noise: &STICK_CLICK,
..PercSpec::EMPTY
};
const AGOGO_HI_MODES: [PercMode; 10] = tuned(
1_189.0,
[
(0.842, -8.0, 0.07),
(0.919, -17.0, 0.07),
(1.0, 0.0, 0.6),
(1.022, -8.0, 0.6),
(1.100, -26.0, 0.19),
(1.833, -25.0, 0.06),
(2.0, -27.0, 0.34),
(2.514, -27.0, 0.55),
(2.999, -32.0, 0.43),
(4.151, -31.0, 0.15),
],
);
const AGOGO_LO_MODES: [PercMode; 10] = tuned(
882.0,
[
(0.910, -3.0, 0.09),
(1.0, 0.0, 0.5),
(1.139, -22.0, 1.5),
(2.294, -18.0, 0.4),
(4.051, -23.0, 0.4),
(4.819, -21.0, 0.34),
(6.314, -19.0, 0.24),
(8.575, -20.0, 0.19),
(8.855, -10.0, 0.06),
(9.348, -17.0, 0.15),
],
);
const AGOGO_HI: PercSpec = PercSpec {
modes: &AGOGO_HI_MODES,
hardness: 6_000.0,
noise: &STICK_CLICK,
..PercSpec::EMPTY
};
const AGOGO_LO: PercSpec = PercSpec {
modes: &AGOGO_LO_MODES,
..AGOGO_HI
};
const TRIANGLE_MODES: [PercMode; 12] = tuned(
1.0,
[
(2_748.0, -14.0, 4.0),
(3_297.0, -5.0, 2.9),
(4_354.0, -15.0, 3.3),
(5_633.0, -2.0, 2.1),
(6_429.0, -3.0, 2.5),
(6_920.0, -7.0, 1.1),
(8_975.0, -6.0, 1.0),
(10_066.0, -5.0, 0.9),
(11_207.0, 0.0, 0.73),
(12_215.0, -13.0, 0.64),
(13_381.0, -4.0, 0.64),
(13_921.0, -1.0, 0.55),
],
);
const TRIANGLE: PercSpec = PercSpec {
modes: &TRIANGLE_MODES,
hardness: 9_000.0,
..PercSpec::EMPTY
};
const TRIANGLE_MUTE_MODES: [PercMode; 10] = tuned(
1.0,
[
(2_750.0, -16.0, 0.25),
(5_632.0, -14.0, 0.6),
(6_430.0, -7.0, 0.34),
(6_730.0, -10.0, 0.28),
(6_917.0, -10.0, 0.34),
(8_934.0, -3.0, 0.19),
(8_972.0, -2.0, 0.25),
(11_203.0, -11.0, 0.45),
(13_373.0, -19.0, 0.27),
(13_914.0, 0.0, 0.3),
],
);
const TRIANGLE_MUTE: PercSpec = PercSpec {
modes: &TRIANGLE_MUTE_MODES,
..TRIANGLE
};
const BELLTREE_MODES: [PercMode; 16] = {
let mut out = [m(0.0, 0.0, 0.0); 16];
let mut k = 0;
while k < 16 {
let mut f = 5_300.0;
let mut j = 0;
while j < k / 2 {
f *= 0.885;
j += 1;
}
let hz = if k % 2 == 0 { f } else { f * 2.76 };
out[k] = PercMode {
hz,
db: if k % 2 == 0 { 0.0 } else { -10.0 },
t60: if k % 2 == 0 { 1.6 } else { 0.8 },
delay: 0.032 * (k / 2) as f32,
};
k += 1;
}
out
};
const BELLTREE: PercSpec = PercSpec {
modes: &BELLTREE_MODES,
hardness: 9_000.0,
..PercSpec::EMPTY
};
const METRO_BELL_MODES: [PercMode; 4] = [
m(2_640.0, 0.0, 0.7),
m(6_270.0, -9.0, 0.35),
m(6_420.0, -11.0, 0.35),
m(10_900.0, -18.0, 0.2),
];
const METRO_BELL: PercSpec = PercSpec {
modes: &METRO_BELL_MODES,
hardness: 8_000.0,
noise: &STICK_CLICK,
..PercSpec::EMPTY
};
const VIBRASLAP_RES: [Resonator; 6] = [
rz(900.0, 4.0, -12.0),
rz(1_600.0, 5.0, -9.0),
rz(2_500.0, 6.0, 0.0),
rz(3_500.0, 6.0, -4.0),
rz(5_200.0, 5.0, -6.0),
rz(7_800.0, 4.0, -7.0),
];
const VIBRASLAP_MODES: [PercMode; 3] = [
m(620.0, 0.0, 0.05),
m(1_340.0, -6.0, 0.04),
m(2_150.0, -10.0, 0.03),
];
const VIBRASLAP_KNOCK: [PercNoise; 1] = [nz(500.0, 5_000.0, 6.0, 0.02)];
const VIBRASLAP: PercSpec = PercSpec {
modes: &VIBRASLAP_MODES,
modes_db: -10.0,
noise: &VIBRASLAP_KNOCK,
particles: Some(Particles {
rate: 62.0,
regular: 0.97,
delay: 0.008,
attack: 0.002,
hold: 0.05,
t60: 2.2,
scatter: 0.35,
grain: 0.05,
groups: 0,
click: 0.0,
resonators: &VIBRASLAP_RES,
db: 10.8,
}),
..PercSpec::EMPTY
};
const TAMBOURINE_RES: [Resonator; 6] = [
rz(3_100.0, 22.0, -16.0),
rz(4_350.0, 22.0, 0.0),
rz(5_600.0, 20.0, 0.0),
rz(7_200.0, 18.0, 0.0),
rz(8_900.0, 16.0, 0.0),
rz(11_200.0, 14.0, -1.0),
];
const TAMBOURINE_MODES: [PercMode; 3] = [
m(260.0, 0.0, 0.08),
m(415.0, -6.0, 0.06),
m(560.0, -10.0, 0.05),
];
const TAMBOURINE_NOISE: [PercNoise; 1] = [nz(5_000.0, 14_000.0, -18.0, 0.12)];
const TAMBOURINE: PercSpec = PercSpec {
modes: &TAMBOURINE_MODES,
modes_db: -30.0,
noise: &TAMBOURINE_NOISE,
particles: Some(Particles {
rate: 1_400.0,
regular: 0.0,
delay: 0.0,
attack: 0.02,
hold: 0.01,
t60: 0.3,
scatter: 0.8,
grain: 0.0,
groups: 0,
click: 0.0,
resonators: &TAMBOURINE_RES,
db: 6.0,
}),
..PercSpec::EMPTY
};
const fn bell(f0: f32, second: f32) -> [Resonator; 4] {
[
rz(f0, 200.0, -10.0),
rz(f0 * second, 300.0, 0.0),
rz(f0 * 4.08, 300.0, -10.0),
rz(f0 * 5.95, 200.0, -16.0),
]
}
const JINGLE_RES: [Resonator; 24] = {
let bells = [
bell(2_450.0, 2.62),
bell(2_560.0, 2.45),
bell(2_630.0, 2.63),
bell(2_710.0, 2.38),
bell(2_820.0, 2.55),
bell(2_930.0, 2.42),
];
let mut out = [rz(1_000.0, 1.0, 0.0); 24];
let mut k = 0;
while k < 24 {
out[k] = bells[k / 4][k % 4];
k += 1;
}
out
};
const JINGLE_BELL: PercSpec = PercSpec {
particles: Some(Particles {
rate: 350.0,
regular: 0.0,
delay: 0.0,
attack: 0.005,
hold: 0.04,
t60: 0.5,
scatter: 0.7,
grain: 0.0,
groups: 6,
click: 0.012,
resonators: &JINGLE_RES,
db: 43.8,
}),
..PercSpec::EMPTY
};
const CABASA_RES: [Resonator; 3] = [
rz(5_200.0, 1.5, 0.0),
rz(8_000.0, 2.0, -2.0),
rz(11_500.0, 2.0, -6.0),
];
const CABASA: PercSpec = PercSpec {
particles: Some(Particles {
rate: 4_000.0,
regular: 0.0,
delay: 0.0,
attack: 0.05,
hold: 0.08,
t60: 0.2,
scatter: 0.9,
grain: 0.0,
groups: 0,
click: 0.0,
resonators: &CABASA_RES,
db: 0.0,
}),
..PercSpec::EMPTY
};
const MARACAS_RES: [Resonator; 2] =
[rz(4_000.0, 3.0, 0.0), rz(6_500.0, 3.0, -8.0)];
const MARACAS: PercSpec = PercSpec {
particles: Some(Particles {
rate: 2_500.0,
regular: 0.0,
delay: 0.0,
attack: 0.04,
hold: 0.01,
t60: 0.25,
scatter: 0.9,
grain: 0.0,
groups: 0,
click: 0.0,
resonators: &MARACAS_RES,
db: 0.0,
}),
..PercSpec::EMPTY
};
const SHAKER_RES: [Resonator; 4] = [
rz(1_800.0, 1.5, -20.0),
rz(4_800.0, 2.5, -4.0),
rz(7_400.0, 2.2, -2.0),
rz(10_000.0, 2.0, 0.0),
];
const SHAKER: PercSpec = PercSpec {
particles: Some(Particles {
rate: 3_000.0,
regular: 0.0,
delay: 0.0,
attack: 0.035,
hold: 0.01,
t60: 0.25,
scatter: 0.9,
grain: 0.0,
groups: 0,
click: 0.0,
resonators: &SHAKER_RES,
db: 0.0,
}),
..PercSpec::EMPTY
};
const GUIRO_RES: [Resonator; 5] = [
rz(1_300.0, 6.0, 0.0),
rz(1_700.0, 6.0, -3.0),
rz(3_300.0, 5.0, 0.0),
rz(4_200.0, 5.0, -2.0),
rz(6_000.0, 4.0, -16.0),
];
const GUIRO_SHORT: PercSpec = PercSpec {
particles: Some(Particles {
rate: 180.0,
regular: 0.9,
delay: 0.0,
attack: 0.006,
hold: 0.035,
t60: 0.06,
scatter: 0.3,
grain: 0.012,
groups: 0,
click: 0.0,
resonators: &GUIRO_RES,
db: 14.3,
}),
..PercSpec::EMPTY
};
const GUIRO_LONG: PercSpec = PercSpec {
particles: Some(Particles {
rate: 55.0,
regular: 0.92,
delay: 0.0,
attack: 0.02,
hold: 0.36,
t60: 0.06,
scatter: 0.3,
grain: 0.04,
groups: 0,
click: 0.0,
resonators: &GUIRO_RES,
db: 4.6,
}),
..PercSpec::EMPTY
};
const CLAVES_MODES: [PercMode; 10] = tuned(
2_230.0,
[
(1.0, 0.0, 0.15),
(1.043, -3.0, 0.1),
(1.06, -7.0, 0.1),
(0.949, -24.0, 0.12),
(0.917, -26.0, 0.16),
(0.893, -27.0, 0.09),
(0.718, -28.0, 0.15),
(2.234, -26.0, 0.07),
(2.383, -27.0, 0.07),
(2.5, -23.0, 0.15),
],
);
const WOOD_CLICK: [PercNoise; 1] = [PercNoise {
vel: 0.4,
..nz(1_200.0, 10_000.0, -16.0, 0.006)
}];
const CLAVES: PercSpec = PercSpec {
modes: &CLAVES_MODES,
hardness: 9_000.0,
noise: &WOOD_CLICK,
..PercSpec::EMPTY
};
const fn woodblock(f0: f32, t60: f32) -> [PercMode; 9] {
tuned(
f0,
[
(1.0, 0.0, t60),
(0.972, -20.0, t60 * 0.8),
(0.886, -25.0, t60 * 0.8),
(0.669, -31.0, t60),
(0.61, -38.0, t60 * 0.7),
(1.277, -42.0, 0.12),
(1.396, -44.0, 0.1),
(2.264, -48.0, 0.12),
(3.228, -51.0, 0.16),
],
)
}
const WOODBLOCK_HI_MODES: [PercMode; 9] = woodblock(1_640.0, 0.07);
const WOODBLOCK_LO_MODES: [PercMode; 9] = woodblock(1_150.0, 0.09);
const WOODBLOCK_HI: PercSpec = PercSpec {
modes: &WOODBLOCK_HI_MODES,
hardness: 6_000.0,
noise: &WOOD_CLICK,
..PercSpec::EMPTY
};
const WOODBLOCK_LO: PercSpec = PercSpec {
modes: &WOODBLOCK_LO_MODES,
..WOODBLOCK_HI
};
const CASTANETS_MODES: [PercMode; 9] = tuned(
1_620.0,
[
(1.0, 0.0, 0.13),
(1.13, -19.0, 0.15),
(1.211, -15.0, 0.16),
(1.441, -14.0, 0.19),
(2.326, -34.0, 0.24),
(3.196, -21.0, 0.18),
(3.613, -25.0, 0.15),
(3.897, -35.0, 0.13),
(5.31, -26.0, 0.03),
],
);
const CASTANETS_NOISE: [PercNoise; 1] = [nz(1_500.0, 12_000.0, 8.0, 0.008)];
const CASTANETS: PercSpec = PercSpec {
modes: &CASTANETS_MODES,
modes_db: -14.0,
hardness: 9_000.0,
noise: &CASTANETS_NOISE,
..PercSpec::EMPTY
};
const STICKS_MODES: [PercMode; 5] = tuned(
1.0,
[
(1_050.0, -4.0, 0.02),
(2_019.0, -6.0, 0.04),
(2_960.0, 0.0, 0.035),
(4_290.0, -2.0, 0.03),
(6_100.0, -10.0, 0.02),
],
);
const STICKS_NOISE: [PercNoise; 2] = [
PercNoise {
vel: 0.5,
..nz(700.0, 9_000.0, 8.0, 0.012)
},
nz(600.0, 1_800.0, 6.0, 0.02),
];
const STICKS: PercSpec = PercSpec {
modes: &STICKS_MODES,
hardness: 9_000.0,
noise: &STICKS_NOISE,
..PercSpec::EMPTY
};
const SLAP_MODES: [PercMode; 3] = [
m(1_250.0, 0.0, 0.05),
m(2_100.0, -4.0, 0.04),
m(3_300.0, -8.0, 0.03),
];
const SLAP_NOISE: [PercNoise; 1] = [nz(800.0, 8_000.0, 0.0, 0.025)];
const SLAP: PercSpec = PercSpec {
modes: &SLAP_MODES,
modes_db: -4.0,
noise: &SLAP_NOISE,
..PercSpec::EMPTY
};
const METRO_CLICK_MODES: [PercMode; 3] = [
m(1_620.0, 0.0, 0.025),
m(3_150.0, -4.0, 0.02),
m(4_900.0, -10.0, 0.015),
];
const METRO_CLICK: PercSpec = PercSpec {
modes: &METRO_CLICK_MODES,
hardness: 9_000.0,
noise: &WOOD_CLICK,
..PercSpec::EMPTY
};
const WHISTLE_BREATH_SHORT: [PercNoise; 1] = [PercNoise {
attack: 0.015,
hold: 0.1,
..nz(1_800.0, 7_000.0, -20.0, 0.05)
}];
const WHISTLE_BREATH_LONG: [PercNoise; 1] = [PercNoise {
attack: 0.02,
hold: 0.42,
..nz(1_800.0, 7_000.0, -20.0, 0.06)
}];
const WHISTLE_TONE: PercTone = PercTone {
from: 2_700.0,
to: 2_850.0,
glide: 0.02,
warble_hz: 36.0,
warble: 0.035,
rough: 0.6,
drive: 0.4,
formant: 0.0,
formant_q: 1.0,
attack: 0.015,
hold: 0.1,
t60: 0.05,
db: 0.0,
};
const WHISTLE_SHORT: PercSpec = PercSpec {
noise: &WHISTLE_BREATH_SHORT,
tone: Some(WHISTLE_TONE),
..PercSpec::EMPTY
};
const WHISTLE_LONG: PercSpec = PercSpec {
noise: &WHISTLE_BREATH_LONG,
tone: Some(PercTone {
attack: 0.02,
hold: 0.42,
t60: 0.06,
..WHISTLE_TONE
}),
..PercSpec::EMPTY
};
const CUICA_OPEN: PercSpec = PercSpec {
tone: Some(PercTone {
from: 290.0,
to: 470.0,
glide: 0.06,
warble_hz: 9.0,
warble: 0.01,
rough: 0.5,
drive: 2.5,
formant: 1_000.0,
formant_q: 1.5,
attack: 0.012,
hold: 0.1,
t60: 0.18,
db: 6.0,
}),
..PercSpec::EMPTY
};
const CUICA_MUTE: PercSpec = PercSpec {
tone: Some(PercTone {
from: 620.0,
to: 760.0,
glide: 0.02,
warble_hz: 9.0,
warble: 0.01,
rough: 0.5,
drive: 2.5,
formant: 1_300.0,
formant_q: 1.5,
attack: 0.006,
hold: 0.03,
t60: 0.07,
db: 6.0,
}),
..PercSpec::EMPTY
};
const SCRATCH_NOISE: [PercNoise; 1] = [PercNoise {
attack: 0.01,
hold: 0.05,
..nz(500.0, 4_000.0, -14.0, 0.04)
}];
const SCRATCH_PUSH: PercSpec = PercSpec {
noise: &SCRATCH_NOISE,
tone: Some(PercTone {
from: 260.0,
to: 1_100.0,
glide: 0.05,
warble_hz: 0.0,
warble: 0.0,
rough: 0.0,
drive: 4.0,
formant: 1_400.0,
formant_q: 0.8,
attack: 0.01,
hold: 0.06,
t60: 0.05,
db: 0.0,
}),
..PercSpec::EMPTY
};
const SCRATCH_PULL: PercSpec = PercSpec {
noise: &SCRATCH_NOISE,
tone: Some(PercTone {
from: 1_000.0,
to: 220.0,
glide: 0.05,
warble_hz: 0.0,
warble: 0.0,
rough: 0.0,
drive: 4.0,
formant: 1_200.0,
formant_q: 0.8,
attack: 0.01,
hold: 0.07,
t60: 0.05,
db: 0.0,
}),
..PercSpec::EMPTY
};
const HIGH_Q: PercSpec = PercSpec {
tone: Some(PercTone {
from: 3_200.0,
to: 700.0,
glide: 0.008,
warble_hz: 0.0,
warble: 0.0,
rough: 0.0,
drive: 0.5,
formant: 0.0,
formant_q: 1.0,
attack: 0.0005,
hold: 0.0,
t60: 0.06,
db: 0.0,
}),
..PercSpec::EMPTY
};
const SQUARE_CLICK: PercSpec = PercSpec {
tone: Some(PercTone {
from: 1_800.0,
to: 1_800.0,
glide: 0.01,
warble_hz: 0.0,
warble: 0.0,
rough: 0.0,
drive: 6.0,
formant: 0.0,
formant_q: 1.0,
attack: 0.0003,
hold: 0.002,
t60: 0.012,
db: -4.0,
}),
..PercSpec::EMPTY
};
const HAT_CLOSED_BANDS: [CymbalBand; 8] = [
band(300.0, -14.0, 0.0, 0.02),
band(450.0, -6.0, -1.0, 0.02),
band(800.0, -12.0, 0.0, 0.02),
band(1_600.0, -12.0, 0.0, 0.02),
band(3_200.0, -4.0, 0.0, 0.02),
band(6_300.0, 0.0, 0.0, 0.02),
band(10_000.0, 0.0, 0.0, 0.02),
band(13_000.0, -3.0, 0.0, 0.02),
];
const HAT_CLOSED: CymbalSpec = CymbalSpec {
seed: 42,
lo: 300.0,
hi: 13_000.0,
density: 3.0,
scatter_db: 5.0,
floor_db: 0.0,
bands: &HAT_CLOSED_BANDS,
ring: 0.2,
ring_corner: 30_000.0,
brightness: 8_000.0,
noise_hz: 7_000.0,
stick: 0.6,
stick_tau: 0.006,
sizzle: 0.25,
sizzle_t60: 0.15,
drive: 0.0,
wobble: 1.2,
};
const HAT_PEDAL_BANDS: [CymbalBand; 8] = [
band(300.0, -18.0, 0.9, 0.015),
band(450.0, -10.0, 0.9, 0.015),
band(800.0, -16.0, 0.9, 0.015),
band(1_600.0, -14.0, 0.9, 0.015),
band(3_200.0, -5.0, 0.9, 0.015),
band(6_300.0, 0.0, 0.9, 0.015),
band(10_000.0, 0.0, 0.9, 0.015),
band(13_000.0, -3.0, 0.9, 0.015),
];
const HAT_PEDAL: CymbalSpec = CymbalSpec {
seed: 44,
bands: &HAT_PEDAL_BANDS,
ring: 0.35,
stick: 0.0,
sizzle: 0.05,
sizzle_t60: 0.2,
..HAT_CLOSED
};
const HAT_OPEN_BANDS: [CymbalBand; 10] = [
band(300.0, -24.0, 0.0, 0.05),
band(420.0, -3.0, -1.0, 0.05),
band(550.0, -3.0, 0.0, 0.05),
band(800.0, -22.0, 0.0, 0.05),
band(1_000.0, -20.0, 0.0, 0.05),
band(1_600.0, -6.0, 0.0, 0.05),
band(3_200.0, -3.0, 0.0, 0.05),
band(5_000.0, 0.0, 0.0, 0.05),
band(8_000.0, -2.0, 0.0, 0.05),
band(12_500.0, -8.0, 0.0, 0.05),
];
const HAT_OPEN: CymbalSpec = CymbalSpec {
seed: 46,
bands: &HAT_OPEN_BANDS,
floor_db: -6.0,
ring: 3.0,
ring_corner: 16_000.0,
stick: 0.5,
sizzle: 0.1,
sizzle_t60: 1.5,
..HAT_CLOSED
};
pub fn drum_patch(note: u8) -> DrumPatch {
match note {
27 => perc(&HIGH_Q, 1.17),
28 => perc(&SLAP, 4.11),
29 => perc(&SCRATCH_PUSH, 0.293),
30 => perc(&SCRATCH_PULL, 0.321),
31 => perc(&STICKS, 0.7),
32 => perc(&SQUARE_CLICK, 0.836),
33 => perc(&METRO_CLICK, 0.674),
34 => perc(&METRO_BELL, 0.745),
35 => perc(&KICK_BIG, 1.0),
36 => perc(&KICK, 1.0),
37 => perc(&SIDE_STICK, 0.6),
38 => perc(&SNARE, 0.996),
39 => perc(&CLAP, 6.73),
40 => perc(&SNARE_TIGHT, 0.673),
41 => pan(perc(&TOM_FLOOR_LO, 0.621), 0.4),
42 => pan(group(cymbal(&HAT_CLOSED, 0.157), 1), -0.35),
43 => pan(perc(&TOM_FLOOR_HI, 0.8), 0.3),
44 => pan(group(cymbal(&HAT_PEDAL, 0.189), 1), -0.35),
45 => pan(perc(&TOM_LO, 0.374), 0.15),
46 => pan(group(cymbal(&HAT_OPEN, 0.0705), 1), -0.35),
47 => pan(perc(&TOM_LO_MID, 0.44), 0.0),
48 => pan(perc(&TOM_HI_MID, 0.455), -0.1),
49 => pan(cymbal(&CRASH_1, 0.19), -0.4),
50 => pan(perc(&TOM_HI, 0.425), -0.2),
51 => pan(cymbal(&RIDE_1, 0.052), 0.45),
52 => pan(cymbal(&CHINA, 0.36), 0.5),
53 => pan(cymbal(&RIDE_BELL, 0.1), 0.45),
54 => perc(&TAMBOURINE, 7.14),
55 => pan(cymbal(&SPLASH, 0.24), -0.2),
56 => perc(&COWBELL, 0.594),
57 => pan(cymbal(&CRASH_2, 0.2), 0.35),
58 => perc(&VIBRASLAP, 1.0),
59 => pan(cymbal(&RIDE_2, 0.048), 0.45),
60 => pan(perc(&BONGO_HI, 1.18), 0.2),
61 => pan(perc(&BONGO_LO, 1.05), 0.1),
62 => pan(perc(&CONGA_MUTE, 1.17), -0.1),
63 => pan(perc(&CONGA_HI, 0.877), -0.1),
64 => pan(perc(&CONGA_LO, 0.984), -0.25),
65 => pan(perc(&TIMBALE_HI, 0.659), 0.25),
66 => pan(perc(&TIMBALE_LO, 0.601), 0.15),
67 => perc(&AGOGO_HI, 0.4),
68 => perc(&AGOGO_LO, 0.4),
69 => perc(&CABASA, 2.01),
70 => perc(&MARACAS, 6.22),
71 => group(perc(&WHISTLE_SHORT, 0.434), 2),
72 => group(perc(&WHISTLE_LONG, 0.395), 2),
73 => group(perc(&GUIRO_SHORT, 1.0), 3),
74 => group(perc(&GUIRO_LONG, 1.0), 3),
75 => perc(&CLAVES, 1.06),
76 => perc(&WOODBLOCK_HI, 1.66),
77 => perc(&WOODBLOCK_LO, 1.58),
78 => group(perc(&CUICA_MUTE, 1.32), 4),
79 => group(perc(&CUICA_OPEN, 1.47), 4),
80 => group(perc(&TRIANGLE_MUTE, 0.3), 5),
81 => group(perc(&TRIANGLE, 0.201), 5),
82 => perc(&SHAKER, 2.62),
83 => perc(&JINGLE_BELL, 1.0),
84 => perc(&BELLTREE, 0.386),
85 => perc(&CASTANETS, 1.2),
86 => group(perc(&SURDO_MUTE, 1.97), 6),
87 => group(perc(&SURDO, 1.56), 6),
_ => perc(&METRO_CLICK, 0.3),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hi_hats_choke_each_other() {
for key in [42, 44, 46] {
assert_eq!(drum_patch(key).group, 1, "key {key}");
}
}
mod perc {
use super::*;
use crate::synth::perc::Perc;
const SR: f32 = 44_100.0;
fn render(key: u8, secs: f32, choke_at: Option<f32>) -> (Vec<f32>, bool) {
let DrumSound::Perc(spec) = drum_patch(key).sound else {
panic!("key {key} is not a percussion model");
};
let mut p = Perc::new(spec, 0.6, 12_345, SR);
let mut out = Vec::new();
while out.len() < (secs * SR) as usize {
if choke_at.is_some_and(|t| out.len() as f32 >= t * SR) {
p.damp();
}
p.update_level();
if p.is_silent() {
return (out, true);
}
out.extend((0..512).map(|_| p.tick()));
}
(out, false)
}
fn rms_db(x: &[f32], a: f32, b: f32) -> f32 {
let (a, b) = ((a * SR) as usize, ((b * SR) as usize).min(x.len()));
if a >= b {
return -200.0;
}
let p = x[a..b].iter().map(|v| v * v).sum::<f32>() / (b - a) as f32;
10.0 * p.max(1e-20).log10()
}
fn perc_keys() -> impl Iterator<Item = u8> {
(27..=87).filter(|&k| matches!(drum_patch(k).sound, DrumSound::Perc(_)))
}
#[test]
fn every_drum_sounds_and_dies_away() {
for key in perc_keys() {
let (x, idle) = render(key, 8.0, None);
assert!(x.iter().all(|v| v.is_finite()), "key {key}: not finite");
let peak = x.iter().fold(0.0f32, |m, v| m.max(v.abs()));
assert!(peak > 1e-3, "key {key}: silent (peak {peak})");
assert!(idle, "key {key}: still sounding after 8 s");
}
}
#[test]
fn slow_onsets_are_not_retired_at_note_on() {
for key in [54, 69, 70, 82, 83] {
let (x, _) = render(key, 0.3, None);
let late = rms_db(&x, 0.03, 0.1);
assert!(late > -60.0, "key {key}: {late:.0} dB at 30–100 ms");
}
}
#[test]
fn choking_stops_the_sound() {
for key in [71, 72, 74, 79, 81, 87] {
let (x, idle) = render(key, 2.0, Some(0.05));
let before = rms_db(&x, 0.0, 0.05);
let after = rms_db(&x, 0.3, 0.4);
assert!(idle, "key {key}: never went idle after the choke");
assert!(
after < before - 40.0,
"key {key}: {before:.0} dB → {after:.0} dB"
);
}
}
#[test]
fn open_strokes_ring_longer_than_muted() {
for (open, muted) in [(63, 62), (81, 80), (87, 86)] {
let (o, _) = render(open, 1.0, None);
let (m, _) = render(muted, 1.0, None);
let fall = |x: &[f32]| rms_db(x, 0.0, 0.03) - rms_db(x, 0.15, 0.25);
assert!(
fall(&o) + 10.0 < fall(&m),
"open {open} falls {:.0} dB, muted {muted} {:.0} dB",
fall(&o),
fall(&m)
);
}
}
}
mod cymbals {
use super::*;
use crate::synth::cymbal::Cymbal;
use crate::synth::waveguide::Biquad;
const SR: f32 = 44_100.0;
const CYMBAL_KEYS: [u8; 7] = [49, 51, 52, 53, 55, 57, 59];
fn render(key: u8, velocity: f32, secs: f32) -> Vec<f32> {
let DrumSound::Cymbal(spec) = drum_patch(key).sound else {
panic!("key {key} is not a cymbal");
};
let mut c = Cymbal::new(spec, SR);
c.strike(velocity, 0);
let mut out = Vec::new();
while out.len() < (secs * SR) as usize {
c.cull();
out.extend((0..512).map(|_| c.tick()));
}
out
}
fn db(x: f32) -> f32 {
10.0 * x.max(1e-20).log10()
}
fn band_power(x: &[f32], hz: f32, a: f32, b: f32) -> f32 {
let (mut b1, mut b2) =
(Biquad::bandpass(hz, 3.0, SR), Biquad::bandpass(hz, 3.0, SR));
let y: Vec<f32> = x.iter().map(|&v| b2.tick(b1.tick(v))).collect();
let seg = &y[(a * SR) as usize..(b * SR) as usize];
seg.iter().map(|v| v * v).sum::<f32>() / seg.len() as f32
}
#[test]
fn cymbals_are_partials_neither_noise_nor_glass() {
for key in CYMBAL_KEYS {
let x = render(key, 0.5, 0.6);
let seg = &x[(0.3 * SR) as usize..(0.55 * SR) as usize];
let n = seg.len();
let mut bins: Vec<f32> = (0..250)
.map(|k| {
let w = std::f32::consts::TAU * (2_000.0 + 4.0 * k as f32) / SR;
let (mut re, mut im) = (0.0f32, 0.0f32);
for (i, v) in seg.iter().enumerate() {
let hann =
0.5 - 0.5 * (std::f32::consts::TAU * i as f32 / n as f32).cos();
re += v * hann * (w * i as f32).cos();
im += v * hann * (w * i as f32).sin();
}
re * re + im * im
})
.collect();
bins.sort_by(f32::total_cmp);
let spread = db(bins[225]) - db(bins[125]);
let max = if key == 53 { 30.0 } else { 22.0 };
assert!(
(8.0..max).contains(&spread),
"key {key}: p90/median {spread:.1} dB"
);
}
}
#[test]
fn hitting_a_ringing_cymbal_restrikes_it() {
let mut s = crate::synth::Synth::new(SR);
let mut buf = vec![0.0f32; 1024];
for _ in 0..4 {
s.note_on(9, 51, 100);
s.render(&mut buf);
}
assert_eq!(s.voices.len(), 1);
assert!(buf.iter().any(|v| v.abs() > 1e-3));
}
#[test]
fn crash_swells_and_ride_pings() {
for key in [49, 57] {
let x = render(key, 0.6, 0.15);
let (early, later) = (
band_power(&x, 4_500.0, 0.0, 0.015),
band_power(&x, 4_500.0, 0.06, 0.1),
);
assert!(
db(later) - db(early) > 3.0,
"key {key}: 4.5 kHz grows only {:.1} dB",
db(later) - db(early)
);
}
let x = render(51, 0.6, 0.15);
let (early, later) = (
band_power(&x, 4_500.0, 0.0, 0.015),
band_power(&x, 4_500.0, 0.06, 0.1),
);
assert!(early > later, "ride swells instead of pinging");
}
#[test]
fn cymbal_highs_die_first() {
for (key, min) in [(49, 10.0), (57, 10.0), (51, 18.0), (59, 18.0)] {
let x = render(key, 0.5, 1.6);
let tilt = |a: f32, b: f32| {
db(band_power(&x, 9_000.0, a, b)) - db(band_power(&x, 2_000.0, a, b))
};
let drop = tilt(0.2, 0.3) - tilt(1.4, 1.5);
assert!(drop > min, "key {key}: highs fall only {drop:.1} dB faster");
}
}
#[test]
fn harder_hits_are_brighter() {
let tilt = |v: f32| {
let x = render(49, v, 0.5);
db(band_power(&x, 9_000.0, 0.05, 0.4))
- db(band_power(&x, 1_500.0, 0.05, 0.4))
};
let (soft, hard) = (tilt(0.1), tilt(1.0));
assert!(
hard - soft > 4.0,
"ff only {:.1} dB brighter than pp",
hard - soft
);
}
}
}