mod bass_boost;
mod comb;
mod comp;
mod crackle;
mod crusher;
mod deess;
pub(crate) mod drive;
mod eq;
mod exciter;
mod flanger;
mod fold;
mod fshift;
mod gate;
pub(crate) mod granular;
mod harmonizer;
mod imager;
mod limiter;
mod mbc;
mod phaser;
mod rotary;
mod saturate;
pub(crate) mod send;
mod stutter;
mod tape;
mod transient;
mod tstop;
pub(crate) use bass_boost::BassBoostFx;
pub(crate) use comb::CombFx;
pub(crate) use comp::CompFx;
pub(crate) use crackle::CrackleFx;
pub(crate) use crusher::CrusherFx;
pub(crate) use deess::DeessFx;
pub(crate) use drive::DriveFx;
pub(crate) use eq::EqFx;
pub(crate) use exciter::ExciterFx;
pub(crate) use flanger::FlangerFx;
pub(crate) use fold::FoldFx;
pub(crate) use fshift::FshiftFx;
pub(crate) use gate::GateFx;
pub(crate) use granular::GranularFx;
pub(crate) use harmonizer::HarmonizerFx;
pub(crate) use imager::ImagerFx;
pub(crate) use limiter::{lookahead_frames, LimiterFx};
pub(crate) use mbc::MbcFx;
pub(crate) use phaser::PhaserFx;
pub(crate) use rotary::RotaryFx;
pub(crate) use saturate::SaturateFx;
pub(crate) use stutter::StutterFx;
pub(crate) use tape::TapeFx;
pub(crate) use transient::TransientFx;
pub(crate) use tstop::TstopFx;
pub(crate) const MAX_FX: usize = 22;
pub(crate) struct Params<'a> {
values: &'a [u32],
pub(crate) eq_freq_mod: f32,
pub(crate) drive_mod: f32,
pub(crate) bpm: f32,
pub(crate) note_hz: f32,
pub(crate) grain_src: Option<&'a crate::synth::va::sample::DrumSample>,
pub(crate) chord_hz: [f32; 8],
pub(crate) chord_n: usize,
gen: Option<u32>,
}
#[derive(Clone, Copy, PartialEq)]
struct ParamsKey {
gen: u32,
sample_rate: u32,
mods: [u32; 4],
chord_hz: [u32; 8],
chord_n: usize,
}
impl<'a> Params<'a> {
pub(crate) const fn new(values: &'a [u32]) -> Self {
Params {
values,
eq_freq_mod: 0.0,
drive_mod: 0.0,
bpm: 120.0,
note_hz: 0.0,
grain_src: None,
chord_hz: [0.0; 8],
chord_n: 0,
gen: None,
}
}
pub(crate) const fn with_grain_src(
mut self,
src: Option<&'a crate::synth::va::sample::DrumSample>,
) -> Self {
self.grain_src = src;
self
}
pub(crate) const fn with_chord_hz(mut self, hz: [f32; 8], n: usize) -> Self {
self.chord_hz = hz;
self.chord_n = n;
self
}
pub(crate) const fn with_grain_ctx(mut self, bpm: f32, note_hz: f32) -> Self {
self.bpm = bpm;
self.note_hz = note_hz;
self
}
pub(crate) const fn with_eq_freq_mod(mut self, v: f32) -> Self {
self.eq_freq_mod = v;
self
}
pub(crate) const fn with_drive_mod(mut self, v: f32) -> Self {
self.drive_mod = v;
self
}
pub(crate) const fn with_gen(mut self, gen: u32) -> Self {
self.gen = Some(gen);
self
}
fn key(&self, sample_rate: f32) -> Option<ParamsKey> {
let gen = self.gen?;
let mut chord_hz = [0u32; 8];
for (o, v) in chord_hz.iter_mut().zip(self.chord_hz) {
*o = v.to_bits();
}
Some(ParamsKey {
gen,
sample_rate: sample_rate.to_bits(),
mods: [
self.eq_freq_mod.to_bits(),
self.drive_mod.to_bits(),
self.bpm.to_bits(),
self.note_hz.to_bits(),
],
chord_hz,
chord_n: self.chord_n,
})
}
pub(crate) fn raw(&self, id: impl Into<usize>) -> u32 {
self.values[id.into()]
}
pub(crate) fn get(&self, id: u8) -> f32 {
self.values[id as usize] as f32
}
pub(crate) fn get_hi(&self, id: u16) -> f32 {
self.values[usize::from(id)] as f32
}
}
pub(crate) trait Effect {
fn update(&mut self, p: &Params<'_>, sample_rate: f32) -> bool;
fn process(&mut self, x: [f32; 2], sample_rate: f32) -> [f32; 2];
fn clear(&mut self);
}
#[derive(Default)]
pub(crate) struct SilenceGate {
quiet: u32,
}
pub(crate) enum Quiet {
Run,
Flush,
Skip,
}
impl SilenceGate {
const SILENT: f32 = 1e-20;
pub(crate) fn tick(&mut self, x: [f32; 2], sample_rate: f32) -> Quiet {
if x[0].abs() >= Self::SILENT || x[1].abs() >= Self::SILENT {
self.quiet = 0;
return Quiet::Run;
}
let limit = sample_rate.max(1.0) as u32;
if self.quiet < limit {
self.quiet += 1;
if self.quiet == limit {
return Quiet::Flush;
}
return Quiet::Run;
}
Quiet::Skip
}
pub(crate) fn reset(&mut self) {
self.quiet = 0;
}
}
#[allow(clippy::large_enum_variant)]
pub(crate) enum FxSlot {
Crusher(CrusherFx),
Drive(DriveFx),
Eq(EqFx),
Comp(CompFx),
Phaser(PhaserFx),
Flanger(FlangerFx),
Granular(GranularFx),
Harmonizer(HarmonizerFx),
BassBoost(BassBoostFx),
Saturate(SaturateFx),
Limiter(LimiterFx),
Mbc(MbcFx),
Tape(TapeFx),
Tstop(TstopFx),
Crackle(CrackleFx),
Rotary(RotaryFx),
Transient(TransientFx),
Fold(FoldFx),
Comb(CombFx),
Gate(GateFx),
Deess(DeessFx),
Exciter(ExciterFx),
Imager(ImagerFx),
Fshift(FshiftFx),
Stutter(StutterFx),
}
impl Effect for FxSlot {
fn update(&mut self, p: &Params<'_>, sample_rate: f32) -> bool {
match self {
FxSlot::Crusher(f) => f.update(p, sample_rate),
FxSlot::Drive(f) => f.update(p, sample_rate),
FxSlot::Eq(f) => f.update(p, sample_rate),
FxSlot::Comp(f) => f.update(p, sample_rate),
FxSlot::Phaser(f) => f.update(p, sample_rate),
FxSlot::Flanger(f) => f.update(p, sample_rate),
FxSlot::Granular(f) => f.update(p, sample_rate),
FxSlot::Harmonizer(f) => f.update(p, sample_rate),
FxSlot::BassBoost(f) => f.update(p, sample_rate),
FxSlot::Saturate(f) => f.update(p, sample_rate),
FxSlot::Limiter(f) => f.update(p, sample_rate),
FxSlot::Mbc(f) => f.update(p, sample_rate),
FxSlot::Tape(f) => f.update(p, sample_rate),
FxSlot::Tstop(f) => f.update(p, sample_rate),
FxSlot::Crackle(f) => f.update(p, sample_rate),
FxSlot::Rotary(f) => f.update(p, sample_rate),
FxSlot::Transient(f) => f.update(p, sample_rate),
FxSlot::Fold(f) => f.update(p, sample_rate),
FxSlot::Comb(f) => f.update(p, sample_rate),
FxSlot::Gate(f) => f.update(p, sample_rate),
FxSlot::Deess(f) => f.update(p, sample_rate),
FxSlot::Exciter(f) => f.update(p, sample_rate),
FxSlot::Imager(f) => f.update(p, sample_rate),
FxSlot::Fshift(f) => f.update(p, sample_rate),
FxSlot::Stutter(f) => f.update(p, sample_rate),
}
}
fn process(&mut self, x: [f32; 2], sample_rate: f32) -> [f32; 2] {
match self {
FxSlot::Crusher(f) => f.process(x, sample_rate),
FxSlot::Drive(f) => f.process(x, sample_rate),
FxSlot::Eq(f) => f.process(x, sample_rate),
FxSlot::Comp(f) => f.process(x, sample_rate),
FxSlot::Phaser(f) => f.process(x, sample_rate),
FxSlot::Flanger(f) => f.process(x, sample_rate),
FxSlot::Granular(f) => f.process(x, sample_rate),
FxSlot::Harmonizer(f) => f.process(x, sample_rate),
FxSlot::BassBoost(f) => f.process(x, sample_rate),
FxSlot::Saturate(f) => f.process(x, sample_rate),
FxSlot::Limiter(f) => f.process(x, sample_rate),
FxSlot::Mbc(f) => f.process(x, sample_rate),
FxSlot::Tape(f) => f.process(x, sample_rate),
FxSlot::Tstop(f) => f.process(x, sample_rate),
FxSlot::Crackle(f) => f.process(x, sample_rate),
FxSlot::Rotary(f) => f.process(x, sample_rate),
FxSlot::Transient(f) => f.process(x, sample_rate),
FxSlot::Fold(f) => f.process(x, sample_rate),
FxSlot::Comb(f) => f.process(x, sample_rate),
FxSlot::Gate(f) => f.process(x, sample_rate),
FxSlot::Deess(f) => f.process(x, sample_rate),
FxSlot::Exciter(f) => f.process(x, sample_rate),
FxSlot::Imager(f) => f.process(x, sample_rate),
FxSlot::Fshift(f) => f.process(x, sample_rate),
FxSlot::Stutter(f) => f.process(x, sample_rate),
}
}
fn clear(&mut self) {
match self {
FxSlot::Crusher(f) => f.clear(),
FxSlot::Drive(f) => f.clear(),
FxSlot::Eq(f) => f.clear(),
FxSlot::Comp(f) => f.clear(),
FxSlot::Phaser(f) => f.clear(),
FxSlot::Flanger(f) => f.clear(),
FxSlot::Granular(f) => f.clear(),
FxSlot::Harmonizer(f) => f.clear(),
FxSlot::BassBoost(f) => f.clear(),
FxSlot::Saturate(f) => f.clear(),
FxSlot::Limiter(f) => f.clear(),
FxSlot::Mbc(f) => f.clear(),
FxSlot::Tape(f) => f.clear(),
FxSlot::Tstop(f) => f.clear(),
FxSlot::Crackle(f) => f.clear(),
FxSlot::Rotary(f) => f.clear(),
FxSlot::Transient(f) => f.clear(),
FxSlot::Fold(f) => f.clear(),
FxSlot::Comb(f) => f.clear(),
FxSlot::Gate(f) => f.clear(),
FxSlot::Deess(f) => f.clear(),
FxSlot::Exciter(f) => f.clear(),
FxSlot::Imager(f) => f.clear(),
FxSlot::Fshift(f) => f.clear(),
FxSlot::Stutter(f) => f.clear(),
}
}
}
pub(crate) struct FxChain {
slots: Box<[Option<FxSlot>]>,
order: [Option<u16>; MAX_FX],
ordered: bool,
keys: [u32; MAX_FX],
perm: [u8; MAX_FX],
len: usize,
last_key: Option<ParamsKey>,
run: [u8; MAX_FX],
run_n: usize,
}
impl FxChain {
pub(crate) fn new() -> Self {
FxChain {
slots: (0..MAX_FX).map(|_| None).collect(),
order: [None; MAX_FX],
ordered: false,
keys: [u32::MAX; MAX_FX],
perm: core::array::from_fn(|i| i as u8),
len: 0,
last_key: None,
run: [0; MAX_FX],
run_n: 0,
}
}
pub(crate) fn standard(sample_rate: u32) -> Self {
use crate::synth::va::engine::param;
Self::new()
.eq_pre()
.order_by(param::ORD_TDRIVE)
.fold()
.order_by(param::ORD_FOLD)
.drive()
.order_by(param::ORD_TDRIVE)
.crusher()
.order_by(param::ORD_CRUSH)
.eq()
.order_by(param::ORD_EQ)
.transient()
.order_by(param::ORD_TS)
.comp()
.order_by(param::ORD_COMP)
.mbc()
.order_by(param::ORD_MBC)
.phaser()
.order_by(param::ORD_PHASER)
.flanger(sample_rate)
.order_by(param::ORD_FLANGER)
.comb(sample_rate)
.order_by(param::ORD_COMB)
.granular(sample_rate)
.order_by(param::ORD_GRAIN)
.harmonizer(sample_rate)
.order_by(param::ORD_HARM)
.rotary(sample_rate)
.order_by(param::ORD_ROT)
.tstop(sample_rate)
.order_by(param::ORD_TSTOP)
.tape(sample_rate)
.order_by(param::ORD_TAPE)
.gate()
.order_by(param::ORD_GATE)
.deess()
.order_by(param::ORD_DEESS)
.exciter()
.order_by(param::ORD_EXC)
.fshift()
.order_by(param::ORD_FSHIFT)
.imager()
.order_by(param::ORD_IMG)
.stutter(sample_rate)
.order_by(param::ORD_STUT)
}
pub(crate) fn master(sample_rate: u32) -> Self {
Self::new()
.bass_boost(sample_rate)
.crackle()
.saturate()
.mbc_master()
.limiter(sample_rate)
}
pub(crate) fn drive(self) -> Self {
self.push(FxSlot::Drive(DriveFx::new()))
}
pub(crate) fn fold(self) -> Self {
self.push(FxSlot::Fold(FoldFx::new()))
}
pub(crate) fn gate(self) -> Self {
self.push(FxSlot::Gate(GateFx::new()))
}
pub(crate) fn deess(self) -> Self {
self.push(FxSlot::Deess(DeessFx::new()))
}
pub(crate) fn exciter(self) -> Self {
self.push(FxSlot::Exciter(ExciterFx::new()))
}
pub(crate) fn imager(self) -> Self {
self.push(FxSlot::Imager(ImagerFx::new()))
}
pub(crate) fn stutter(self, sample_rate: u32) -> Self {
self.push(FxSlot::Stutter(StutterFx::new(sample_rate)))
}
pub(crate) fn fshift(self) -> Self {
self.push(FxSlot::Fshift(FshiftFx::new()))
}
pub(crate) fn transient(self) -> Self {
self.push(FxSlot::Transient(TransientFx::new()))
}
pub(crate) fn comb(self, sample_rate: u32) -> Self {
self.push(FxSlot::Comb(CombFx::new(sample_rate)))
}
pub(crate) fn rotary(self, sample_rate: u32) -> Self {
self.push(FxSlot::Rotary(RotaryFx::new(sample_rate)))
}
pub(crate) fn crusher(self) -> Self {
self.push(FxSlot::Crusher(CrusherFx::new()))
}
pub(crate) fn eq(self) -> Self {
self.push(FxSlot::Eq(EqFx::post()))
}
pub(crate) fn eq_pre(self) -> Self {
self.push(FxSlot::Eq(EqFx::pre()))
}
pub(crate) fn comp(self) -> Self {
self.push(FxSlot::Comp(CompFx::new()))
}
pub(crate) fn mbc(self) -> Self {
self.push(FxSlot::Mbc(MbcFx::track()))
}
pub(crate) fn mbc_master(self) -> Self {
self.push(FxSlot::Mbc(MbcFx::master()))
}
pub(crate) fn phaser(self) -> Self {
self.push(FxSlot::Phaser(PhaserFx::new()))
}
pub(crate) fn flanger(self, sample_rate: u32) -> Self {
self.push(FxSlot::Flanger(FlangerFx::new(sample_rate)))
}
pub(crate) fn granular(self, sample_rate: u32) -> Self {
self.push(FxSlot::Granular(GranularFx::new(sample_rate)))
}
pub(crate) fn harmonizer(self, sample_rate: u32) -> Self {
self.push(FxSlot::Harmonizer(HarmonizerFx::new(sample_rate)))
}
pub(crate) fn tape(self, sample_rate: u32) -> Self {
self.push(FxSlot::Tape(TapeFx::new(sample_rate)))
}
pub(crate) fn tstop(self, sample_rate: u32) -> Self {
self.push(FxSlot::Tstop(TstopFx::new(sample_rate)))
}
pub(crate) fn crackle(self) -> Self {
self.push(FxSlot::Crackle(CrackleFx::new()))
}
pub(crate) fn bass_boost(self, sample_rate: u32) -> Self {
self.push(FxSlot::BassBoost(BassBoostFx::new(sample_rate)))
}
pub(crate) fn saturate(self) -> Self {
self.push(FxSlot::Saturate(SaturateFx::new()))
}
pub(crate) fn limiter(self, sample_rate: u32) -> Self {
self.push(FxSlot::Limiter(LimiterFx::new(sample_rate)))
}
pub(crate) fn order_by(mut self, id: impl Into<u16>) -> Self {
assert!(
self.len > 0,
"FxChain::order_by はエフェクトを足した後に呼ぶ"
);
self.order[self.len - 1] = Some(id.into());
self.ordered = true;
self
}
fn push(mut self, slot: FxSlot) -> Self {
assert!(
self.len < MAX_FX,
"FxChain に MAX_FX より多くのエフェクトを並べた"
);
self.slots[self.len] = Some(slot);
self.len += 1;
self
}
fn sort_key(&self, p: &Params<'_>, i: usize) -> u32 {
let pos = self.order[i].map_or(0, |id| p.raw(id));
pos * MAX_FX as u32 + i as u32
}
fn reorder(&mut self, p: &Params<'_>) {
let mut keys = [u32::MAX; MAX_FX];
for (i, k) in keys.iter_mut().enumerate().take(self.len) {
*k = self.sort_key(p, i);
}
if keys == self.keys {
return;
}
self.keys = keys;
for (i, slot) in self.perm.iter_mut().enumerate() {
*slot = i as u8;
}
for i in 1..self.len {
let mut j = i;
while j > 0 && keys[self.perm[j - 1] as usize] > keys[self.perm[j] as usize] {
self.perm.swap(j - 1, j);
j -= 1;
}
}
}
pub(crate) fn process(&mut self, p: &Params<'_>, x: [f32; 2], sample_rate: f32) -> [f32; 2] {
let key = p.key(sample_rate);
if key.is_some() && key == self.last_key {
let mut y = x;
for k in 0..self.run_n {
if let Some(fx) = self.slots[self.run[k] as usize].as_mut() {
y = fx.process(y, sample_rate);
}
}
return y;
}
self.last_key = None;
self.run_n = 0;
let mut y = x;
if !self.ordered {
for (i, slot) in self.slots.iter_mut().enumerate() {
let Some(fx) = slot.as_mut() else { continue };
if fx.update(p, sample_rate) {
self.run[self.run_n] = i as u8;
self.run_n += 1;
y = fx.process(y, sample_rate);
}
}
} else {
self.reorder(p);
for k in 0..self.len {
let i = self.perm[k] as usize;
if let Some(fx) = self.slots[i].as_mut() {
if fx.update(p, sample_rate) {
self.run[self.run_n] = i as u8;
self.run_n += 1;
y = fx.process(y, sample_rate);
}
}
}
}
self.last_key = key;
y
}
pub(crate) fn clear(&mut self) {
for fx in self.slots.iter_mut().flatten() {
fx.clear();
}
self.last_key = None;
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::synth::va::engine::param;
use crate::synth::va::VA;
fn defaults() -> Vec<u32> {
VA.params.iter().map(|p| p.default).collect()
}
fn run(chain: &mut FxChain, params: &[u32], n: usize) -> Vec<[f32; 2]> {
let p = Params::new(params);
(0..n)
.map(|i| {
let x = ((i % 37) as f32 / 18.0 - 1.0) * 0.8;
chain.process(&p, [x, -x], 48_000.0)
})
.collect()
}
#[test]
fn empty_chain_passes_through() {
let mut chain = FxChain::new();
let out = run(&mut chain, &defaults(), 64);
for (i, y) in out.iter().enumerate() {
let x = ((i % 37) as f32 / 18.0 - 1.0) * 0.8;
assert_eq!(*y, [x, -x]);
}
}
#[test]
fn standard_chain_with_defaults_changes_nothing() {
let mut empty = FxChain::new();
let mut standard = FxChain::standard(48_000);
let d = defaults();
assert_eq!(run(&mut empty, &d, 256), run(&mut standard, &d, 256));
}
#[test]
fn update_skip_is_bit_exact() {
let mut slow = FxChain::standard(48_000);
let mut fast = FxChain::standard(48_000);
let mut vals = defaults();
for (id, v) in [
(param::TAPE, 60),
(param::COMP, 50),
(param::ROT, 70),
(param::HARM, 50),
(param::COMB, 40),
(param::GRAIN, 60),
] {
vals[usize::from(id)] = v;
}
let mut gen = 0u32;
for i in 0..6_000usize {
if i % 1_500 == 0 {
vals[usize::from(param::TAPE)] = (i / 1_500 * 25) as u32;
vals[usize::from(param::ORD_GRAIN)] = (i / 1_500 % 3) as u32;
gen += 1;
}
if i == 3_000 {
slow.clear();
fast.clear();
}
let hz = 220.0 + (i / 700) as f32 * 11.0;
let m = (i / 300) as f32 * 0.5;
let x = ((i % 37) as f32 / 18.0 - 1.0) * 0.8;
let pa = Params::new(&vals)
.with_grain_ctx(120.0, hz)
.with_eq_freq_mod(m);
let a = slow.process(&pa, [x, -x], 48_000.0);
let pb = pa.with_gen(gen);
let b = fast.process(&pb, [x, -x], 48_000.0);
assert_eq!(a, b, "sample {i}");
}
}
#[test]
fn order_matters() {
let mut d = defaults();
d[param::CRUSH_BITS as usize] = 3;
d[param::EQ_GAIN as usize] = 40;
let mut a = FxChain::new().crusher().eq();
let mut b = FxChain::new().eq().crusher();
assert_ne!(run(&mut a, &d, 256), run(&mut b, &d, 256));
}
#[test]
fn clear_returns_to_unused_state() {
let mut d = defaults();
d[param::EQ_GAIN as usize] = 40;
let mut chain = FxChain::standard(48_000);
let first = run(&mut chain, &d, 128);
chain.clear();
assert_eq!(run(&mut chain, &d, 128), first);
}
#[test]
fn master_chain_keeps_quiet_sound_with_defaults() {
let mut master = FxChain::master(48_000);
let mut empty = FxChain::new();
let d = defaults();
let n = lookahead_frames(48_000);
let dry = run(&mut empty, &d, 256);
let wet = run(&mut master, &d, 256);
assert!(wet[..n].iter().all(|y| *y == [0.0, 0.0]));
assert_eq!(&wet[n..], &dry[..256 - n]);
}
#[test]
fn mbc_slots_are_off_by_default_and_work_when_asked() {
let d = defaults();
let mut off = FxChain::new().mbc();
assert_eq!(run(&mut FxChain::new(), &d, 256), run(&mut off, &d, 256));
let mut on_params = defaults();
on_params[param::MBC as usize] = 100;
let mut on = FxChain::new().mbc();
assert_ne!(
run(&mut FxChain::new(), &on_params, 2048),
run(&mut on, &on_params, 2048)
);
let mut master = FxChain::new().mbc_master();
assert_eq!(
run(&mut FxChain::new(), &on_params, 256),
run(&mut master, &on_params, 256)
);
let mut master_on_params = defaults();
master_on_params[param::MST_MBC as usize] = 100;
let mut master = FxChain::new().mbc_master();
assert_ne!(
run(&mut FxChain::new(), &master_on_params, 2048),
run(&mut master, &master_on_params, 2048)
);
}
#[test]
fn master_chain_ends_with_limiter() {
let mut d = defaults();
d[param::BASS_BOOST as usize] = 24;
d[param::SAT as usize] = 100;
let mut master = FxChain::master(48_000);
let p = Params::new(&d);
for i in 0..4_800 {
let x = if i % 40 < 20 { 0.9 } else { -0.9 };
let y = master.process(&p, [x, x], 48_000.0);
assert!(y[0].abs() <= 0.951 && y[1].abs() <= 0.951, "{y:?}");
}
}
#[test]
fn standard_order_params_follow_the_default_order() {
let mut d = defaults();
d[param::CRUSH_BITS as usize] = 4;
d[param::EQ_GAIN as usize] = 40;
d[param::COMP as usize] = 60;
d[param::TDRIVE as usize] = 50;
let mut plain = FxChain::new()
.eq_pre()
.drive()
.crusher()
.eq()
.comp()
.phaser()
.flanger(48_000);
let mut standard = FxChain::standard(48_000);
assert_eq!(run(&mut plain, &d, 512), run(&mut standard, &d, 512));
}
#[test]
fn order_params_move_effects() {
let mut d = defaults();
d[param::EQ_GAIN as usize] = 44;
d[param::TDRIVE as usize] = 80;
let mut expect = FxChain::new().eq().drive();
let want = run(&mut expect, &d, 512);
let mut standard = FxChain::standard(48_000);
assert_ne!(run(&mut standard, &d, 512), want, "既定では歪みが先");
d[param::ORD_EQ as usize] = 0;
let mut moved = FxChain::standard(48_000);
assert_eq!(run(&mut moved, &d, 512), want);
}
#[test]
fn eq_pre_band_stays_just_before_drive() {
let mut d = defaults();
d[param::EQ_TYPE as usize] = 5;
d[param::EQ_FREQ as usize] = 40;
d[param::EQ_PRE as usize] = 1;
d[param::TDRIVE as usize] = 80;
d[param::CRUSH_BITS as usize] = 4;
d[param::ORD_TDRIVE as usize] = 9;
let mut expect = FxChain::new().crusher().eq_pre().drive();
let mut moved = FxChain::standard(48_000);
assert_eq!(run(&mut moved, &d, 512), run(&mut expect, &d, 512));
}
#[test]
#[should_panic(expected = "MAX_FX")]
fn too_many_effects_panics_when_building() {
let mut chain = FxChain::new();
for _ in 0..=MAX_FX {
chain = chain.crusher();
}
}
}