From 466a034c4cd18df4e4933a6b48dc1be38b2e7557 Mon Sep 17 00:00:00 2001 From: Hailey Somerville Date: Sat, 4 Apr 2020 00:51:10 +1100 Subject: [PATCH] add mono line type --- frontend/src/workspace.rs | 3 ++- protocol/src/lib.rs | 1 + src/module/amplifier.rs | 10 +++++++--- src/module/trigger.rs | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/frontend/src/workspace.rs b/frontend/src/workspace.rs index efec7f1..5c38589 100644 --- a/frontend/src/workspace.rs +++ b/frontend/src/workspace.rs @@ -750,9 +750,10 @@ impl Component for Terminal { > { match self.props.terminal.line_type { + LineType::Mono => html! {}, LineType::Stereo => html! { - } + }, } } diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index b895715..d4f26d9 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -93,6 +93,7 @@ impl OutputId { #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] pub enum LineType { + Mono, Stereo, } diff --git a/src/module/amplifier.rs b/src/module/amplifier.rs index 345556f..acf732f 100644 --- a/src/module/amplifier.rs +++ b/src/module/amplifier.rs @@ -27,21 +27,25 @@ impl Module for Amplifier { fn run_tick(&mut self, _t: u64, inputs: &[Option<&[Sample]>], outputs: &mut [&mut [Sample]]) -> Option { let AmplifierParams {mod_depth, amplitude} = self.params; - let len = outputs[0].len(); let input = &inputs[0].unwrap_or(&ZERO_BUFFER); let mod_input = &inputs[1].unwrap_or(&ONE_BUFFER); let output = &mut outputs[0]; + let len = input.len(); + for i in 0..len { - output[i] = input[i] * depth(mod_input[i], mod_depth) * amplitude; + // mod input is a mono channel and so half the length: + let mod_value = mod_input[i / 2]; + + output[i] = input[i] * depth(mod_value, mod_depth) * amplitude; } None } fn inputs(&self) -> &[LineType] { - &[LineType::Stereo, LineType::Stereo] + &[LineType::Stereo, LineType::Mono] } fn outputs(&self) -> &[LineType] { diff --git a/src/module/trigger.rs b/src/module/trigger.rs index 66aa558..d0a0d18 100644 --- a/src/module/trigger.rs +++ b/src/module/trigger.rs @@ -45,6 +45,6 @@ impl Module for Trigger { } fn outputs(&self) -> &[LineType] { - &[LineType::Stereo] + &[LineType::Mono] } }