HexoDSP/src/dsp/node_map.rs

111 lines
3.3 KiB
Rust
Raw Normal View History

2021-07-02 03:11:11 +00:00
// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
// This is a part of HexoDSP. Released under (A)GPLv3 or any later.
// See README.md and COPYING for details.
use crate::nodes::{NodeAudioContext, NodeExecContext};
use crate::dsp::{NodeId, SAtom, ProcBuf, DspNode, LedPhaseVals};
#[macro_export]
2021-07-02 03:12:17 +00:00
macro_rules! fa_map_mode { ($formatter: expr, $v: expr, $denorm_v: expr) => { {
let s =
match ($v.round() as usize) {
0 => "Bipolar",
1 => "Unipolar",
_ => "?",
};
write!($formatter, "{}", s)
2021-07-02 03:11:11 +00:00
} } }
/// A simple amplifier
#[derive(Debug, Clone)]
pub struct Map {
}
impl Map {
pub fn new(_nid: &NodeId) -> Self {
Self {
}
}
pub const inp : &'static str =
"Map inp\nSignal input\nRange: (-1..1)\n";
pub const atv : &'static str =
"Map atv\n\nRange: (0..1)\n";
2021-07-02 03:12:17 +00:00
pub const offs : &'static str =
"Map offs\nSignal input offset\nRange: (-1..1)\n";
pub const min : &'static str =
"Map min\n\nRange: (0..1)\n";
pub const max : &'static str =
"Map max\n\nRange: (0..1)\n";
pub const mode : &'static str =
"Map mode\n";
2021-07-02 03:11:11 +00:00
pub const sig : &'static str =
"Map sig\nMapped signal output\nRange: (-1..1)\n";
pub const DESC : &'static str =
r#"Signal Range Mapper
"#;
pub const HELP : &'static str =
r#"Map - Signal Range Mapper
"#;
}
impl DspNode for Map {
fn outputs() -> usize { 1 }
fn set_sample_rate(&mut self, _srate: f32) { }
fn reset(&mut self) { }
#[inline]
fn process<T: NodeAudioContext>(
&mut self, ctx: &mut T, _ectx: &mut NodeExecContext,
atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf],
outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals)
{
use crate::dsp::{out, inp, denorm, denorm_v, inp_dir, at};
// let gain = inp::Amp::gain(inputs);
// let att = inp::Amp::att(inputs);
// let inp = inp::Amp::inp(inputs);
// let out = out::Amp::sig(outputs);
// let neg = at::Amp::neg_att(atoms);
//
// let last_frame = ctx.nframes() - 1;
//
// let last_val =
// if neg.i() > 0 {
// for frame in 0..ctx.nframes() {
// out.write(frame,
// inp.read(frame)
// * denorm_v::Amp::att(
// inp_dir::Amp::att(att, frame)
// .max(0.0))
// * denorm::Amp::gain(gain, frame));
// }
//
// inp.read(last_frame)
// * denorm_v::Amp::att(
// inp_dir::Amp::att(att, last_frame)
// .max(0.0))
// * denorm::Amp::gain(gain, last_frame)
//
// } else {
// for frame in 0..ctx.nframes() {
// out.write(frame,
// inp.read(frame)
// * denorm_v::Amp::att(
// inp_dir::Amp::att(att, frame).abs())
// * denorm::Amp::gain(gain, frame));
// }
//
// inp.read(last_frame)
// * denorm_v::Amp::att(
// inp_dir::Amp::att(att, last_frame).abs())
// * denorm::Amp::gain(gain, last_frame)
// };
//
// ctx_vals[0].set(last_val);
}
}