2021-06-04 18:24:55 +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-04 18:24:55 +00:00
|
|
|
// See README.md and COPYING for details.
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
use crate::dsp::{DspNode, LedPhaseVals, NodeContext, NodeId, ProcBuf, SAtom};
|
2021-06-04 18:24:55 +00:00
|
|
|
use crate::nodes::{NodeAudioContext, NodeExecContext};
|
|
|
|
|
|
|
|
/// A simple amplifier
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct FbWr {
|
2022-07-17 09:58:28 +00:00
|
|
|
fb_index: u8,
|
2021-06-04 18:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FbWr {
|
|
|
|
pub fn new(nid: &NodeId) -> Self {
|
2022-07-17 09:58:28 +00:00
|
|
|
Self { fb_index: nid.instance() as u8 }
|
2021-06-04 18:24:55 +00:00
|
|
|
}
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const inp: &'static str = "FbWr inp\nSignal input\nRange: (-1..1)\n";
|
2021-06-07 03:00:10 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const DESC: &'static str = "Feedback Delay Writer\n\n\
|
2021-06-08 03:02:16 +00:00
|
|
|
HexoSynth does not allow direct feedback cycles in it's graph.\n\
|
|
|
|
To make feedback possible anyways the 'FbWr' and 'FbRd' nodes are provided.\n\
|
|
|
|
This node allows you to write a signal into the corresponsing signal delay buffer.\n\
|
|
|
|
Use 'FbRd' for using the signal.\n\
|
|
|
|
The delay is 3.14ms.";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const HELP: &'static str = r#"Feedback Delay Writer
|
2021-06-08 03:02:16 +00:00
|
|
|
|
|
|
|
HexoSynth does not allow direct feedback cycles in it's graph.
|
|
|
|
To make feedback possible anyways the 'FbWr' and 'FbRd' nodes are provided.
|
|
|
|
This node allows you to send a signal into the corresponsing 'FbWr' signal
|
|
|
|
delay.
|
|
|
|
|
|
|
|
The instance id of the node defines which FbWr and FbRd are connected.
|
|
|
|
That means 'FbRd 0' is connected to the corresponding 'FbWr 0'. You can use
|
|
|
|
the signal multiple times by connecting the 'FbRd 0' 'sig' port to multiple
|
|
|
|
inputs.
|
|
|
|
|
|
|
|
The delay is always 3.14ms, regardless of the sampling rate the synthesizer
|
|
|
|
is running at.
|
|
|
|
"#;
|
2021-06-04 18:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DspNode for FbWr {
|
2022-07-17 09:58:28 +00:00
|
|
|
fn outputs() -> usize {
|
|
|
|
0
|
|
|
|
}
|
2021-06-04 18:24:55 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
fn set_sample_rate(&mut self, _srate: f32) {}
|
|
|
|
fn reset(&mut self) {}
|
2021-06-04 18:24:55 +00:00
|
|
|
|
|
|
|
#[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::inp;
|
2021-06-04 18:24:55 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
let inp = inp::FbWr::inp(inputs);
|
2021-06-04 18:24:55 +00:00
|
|
|
|
|
|
|
for frame in 0..ctx.nframes() {
|
2022-07-17 09:58:28 +00:00
|
|
|
ectx.feedback_delay_buffers[self.fb_index as usize].write(inp.read(frame));
|
2021-06-04 18:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx_vals[0].set(inp.read(ctx.nframes() - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A simple amplifier
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct FbRd {
|
2022-07-17 09:58:28 +00:00
|
|
|
fb_index: u8,
|
2021-06-04 18:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FbRd {
|
|
|
|
pub fn new(nid: &NodeId) -> Self {
|
2022-07-17 09:58:28 +00:00
|
|
|
Self { fb_index: nid.instance() as u8 }
|
2021-06-04 18:24:55 +00:00
|
|
|
}
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const atv: &'static str = "FbRd atv\nAttenuate or invert input.\n\
|
2021-06-08 03:02:16 +00:00
|
|
|
Use this to adjust the feedback amount.\nRange: (-1..1)\n";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const sig: &'static str = "FbRd sig\nFeedback signal output.\nRange: (-1..1)\n";
|
2021-06-07 03:00:10 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const DESC: &'static str = "Feedback Delay Reader\n\n\
|
2022-06-25 08:23:14 +00:00
|
|
|
HexoSynth does not allow direct feedback cycles in it's graph.\n\
|
|
|
|
To make feedback possible anyways the 'FbWr' and 'FbRd' nodes are provided.\n\
|
|
|
|
This node allows you to tap into the corresponsing 'FbWr' signal delay \
|
|
|
|
for feedback.\n\
|
|
|
|
The delay is 3.14ms.";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const HELP: &'static str = r#"Feedback Delay Reader
|
2021-06-08 03:02:16 +00:00
|
|
|
|
|
|
|
HexoSynth does not allow direct feedback cycles in it's graph.
|
|
|
|
To make feedback possible anyways the 'FbWr' and 'FbRd' nodes are provided.
|
|
|
|
This node allows you to tap into the corresponsing 'FbWr' signal delay for
|
|
|
|
feedback.
|
|
|
|
|
|
|
|
The instance id of the node defines which FbWr and FbRd are connected.
|
|
|
|
That means 'FbRd 0' is connected to the corresponding 'FbWr 0'. You can use
|
|
|
|
the signal multiple times by connecting the 'FbRd 0' 'sig' port to multiple
|
|
|
|
inputs.
|
|
|
|
|
|
|
|
The delay is always 3.14ms, regardless of the sampling rate the synthesizer
|
|
|
|
is running at.
|
|
|
|
|
|
|
|
The 'atv' parameter is a convenience parameter to allow attenuating or
|
|
|
|
even inverting the signal.
|
|
|
|
"#;
|
2021-06-04 18:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DspNode for FbRd {
|
2022-07-17 09:58:28 +00:00
|
|
|
fn outputs() -> usize {
|
|
|
|
1
|
|
|
|
}
|
2021-06-04 18:24:55 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
fn set_sample_rate(&mut self, _srate: f32) {}
|
|
|
|
fn reset(&mut self) {}
|
2021-06-04 18:24:55 +00:00
|
|
|
|
|
|
|
#[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};
|
2021-06-04 18:24:55 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
let atv = inp::FbRd::atv(inputs);
|
|
|
|
let sig = out::FbRd::sig(outputs);
|
2021-06-04 18:24:55 +00:00
|
|
|
|
|
|
|
let mut last_val = 0.0;
|
|
|
|
for frame in 0..ctx.nframes() {
|
2022-07-17 09:58:28 +00:00
|
|
|
last_val = ectx.feedback_delay_buffers[self.fb_index as usize].read();
|
2021-06-04 18:24:55 +00:00
|
|
|
last_val *= denorm::FbRd::atv(atv, frame);
|
|
|
|
sig.write(frame, last_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx_vals[0].set(last_val);
|
|
|
|
}
|
|
|
|
}
|