2021-06-28 03:10:46 +00:00
|
|
|
// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
|
2021-08-04 01:58:43 +00:00
|
|
|
// This file is a part of HexoDSP. Released under GPL-3.0-or-later.
|
2021-06-28 03:10:46 +00:00
|
|
|
// See README.md and COPYING for details.
|
|
|
|
|
|
|
|
use crate::dsp::helpers::AllPass;
|
2022-07-17 09:58:28 +00:00
|
|
|
use crate::dsp::{DspNode, LedPhaseVals, NodeContext, NodeId, ProcBuf, SAtom};
|
|
|
|
use crate::nodes::{NodeAudioContext, NodeExecContext};
|
2021-06-28 03:10:46 +00:00
|
|
|
|
|
|
|
/// A simple amplifier
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct AllP {
|
2021-08-07 22:56:10 +00:00
|
|
|
allpass: Box<AllPass<f64>>,
|
2021-06-28 03:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AllP {
|
|
|
|
pub fn new(_nid: &NodeId) -> Self {
|
2022-07-17 09:58:28 +00:00
|
|
|
Self { allpass: Box::new(AllPass::new()) }
|
2021-06-28 03:10:46 +00:00
|
|
|
}
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const inp: &'static str =
|
2021-06-28 03:10:46 +00:00
|
|
|
"AllP inp\nThe signal input for the allpass filter.\nRange: (-1..1)";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const g: &'static str =
|
2021-06-28 03:10:46 +00:00
|
|
|
"AllP g\nThe internal factor for the allpass filter.\nRange: (-1..1)";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const time: &'static str = "AllP time\nThe allpass delay time.\nRange: (0..1)";
|
|
|
|
pub const sig: &'static str = "AllP sig\nThe output of allpass filter.\nRange: (-1..1)";
|
2021-06-28 03:10:46 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const DESC: &'static str = r#"Single Allpass Filter
|
2021-06-28 03:10:46 +00:00
|
|
|
|
|
|
|
This is an allpass filter that can be used to build reverbs
|
|
|
|
or anything you might find it useful for.
|
|
|
|
"#;
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const HELP: &'static str = r#"AllP - A Simple Single Allpass Filter
|
2021-06-28 03:10:46 +00:00
|
|
|
|
|
|
|
This is an allpass filter that can be used to build reverbs
|
|
|
|
or anything you might find it useful for.
|
|
|
|
|
|
|
|
Typical arrangements are (Schroeder Reverb):
|
|
|
|
|
|
|
|
t=4.5ms
|
|
|
|
g=0.7 -> Comb
|
|
|
|
AllP -> AllP -> AllP -> -> Comb
|
|
|
|
t=42ms t=13.5ms -> Comb
|
|
|
|
g=0.7 g=0.7 -> Comb
|
|
|
|
|
|
|
|
Or:
|
|
|
|
|
|
|
|
Comb -> t=0.48ms
|
|
|
|
Comb -> g=0.7
|
|
|
|
Comb -> AllP -> AllP -> AllP
|
|
|
|
Comb -> t=5ms t=1.68ms
|
|
|
|
g=0.7 g=0.7
|
|
|
|
|
|
|
|
Typical values for the comb filters are in the range g=0.6 to 0.9
|
|
|
|
and time in the range of 30ms to 250ms.
|
|
|
|
|
|
|
|
Feel free to deviate from this and experiment around.
|
|
|
|
|
|
|
|
Building your own reverbs is fun!
|
|
|
|
|
|
|
|
(And don't forget that you can create feedback
|
|
|
|
using the FbWr and FbRd nodes!)
|
|
|
|
"#;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DspNode for AllP {
|
2022-07-17 09:58:28 +00:00
|
|
|
fn outputs() -> usize {
|
|
|
|
1
|
|
|
|
}
|
2021-06-28 03:10:46 +00:00
|
|
|
|
|
|
|
fn set_sample_rate(&mut self, srate: f32) {
|
2021-08-07 22:56:10 +00:00
|
|
|
self.allpass.set_sample_rate(srate as f64);
|
2021-06-28 03:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn reset(&mut self) {
|
|
|
|
self.allpass.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn process<T: NodeAudioContext>(
|
2022-07-17 09:58:28 +00:00
|
|
|
&mut self,
|
|
|
|
ctx: &mut T,
|
|
|
|
_ectx: &mut NodeExecContext,
|
2021-07-10 19:27:18 +00:00
|
|
|
_nctx: &NodeContext,
|
2022-07-17 09:58:28 +00:00
|
|
|
_atoms: &[SAtom],
|
|
|
|
inputs: &[ProcBuf],
|
|
|
|
outputs: &mut [ProcBuf],
|
|
|
|
ctx_vals: LedPhaseVals,
|
|
|
|
) {
|
|
|
|
use crate::dsp::{denorm, inp, out};
|
|
|
|
|
|
|
|
let inp = inp::AllP::inp(inputs);
|
2021-06-28 03:10:46 +00:00
|
|
|
let time = inp::AllP::time(inputs);
|
2022-07-17 09:58:28 +00:00
|
|
|
let g = inp::AllP::g(inputs);
|
|
|
|
let out = out::AllP::sig(outputs);
|
2021-06-28 03:10:46 +00:00
|
|
|
|
|
|
|
let ap = &mut *self.allpass;
|
|
|
|
|
|
|
|
for frame in 0..ctx.nframes() {
|
|
|
|
let v = inp.read(frame);
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
out.write(
|
|
|
|
frame,
|
2021-06-28 03:10:46 +00:00
|
|
|
ap.next(
|
2021-08-07 22:56:10 +00:00
|
|
|
denorm::AllP::time(time, frame) as f64,
|
|
|
|
denorm::AllP::g(g, frame) as f64,
|
2022-07-17 09:58:28 +00:00
|
|
|
v as f64,
|
|
|
|
) as f32,
|
|
|
|
);
|
2021-06-28 03:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let last_frame = ctx.nframes() - 1;
|
|
|
|
ctx_vals[0].set(out.read(last_frame));
|
|
|
|
}
|
|
|
|
}
|