From 62bc461f60063e9f244aaf3154168e2b0841316e Mon Sep 17 00:00:00 2001 From: annieversary Date: Thu, 5 Aug 2021 12:00:29 +0200 Subject: [PATCH] [sosten] add dissipation, remove mix --- crates/sosten/src/lib.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/crates/sosten/src/lib.rs b/crates/sosten/src/lib.rs index 620c2b6..dffb8fe 100644 --- a/crates/sosten/src/lib.rs +++ b/crates/sosten/src/lib.rs @@ -16,11 +16,11 @@ baseplug::model! { #[parameter(name = "length")] length: f32, #[model(min = 0.0, max = 1.0)] - #[parameter(name = "mix")] - mix: f32, - #[model(min = 0.0, max = 1.0)] #[parameter(name = "enable")] enable: f32, + #[model(min = 0.0, max = 1.0)] + #[parameter(name = "dissipation")] + dissipation: f32, } } @@ -28,8 +28,8 @@ impl Default for SostenModel { fn default() -> Self { Self { length: 1000.0, - mix: 1.0, enable: 0.0, + dissipation: 1.0, } } } @@ -96,17 +96,21 @@ impl Plugin for Sosten { // Length of section to play let len = model.length[i].trunc() as usize; - // Pass through input - let mix_inv = 1. - model.mix[i]; - output[0][i] = mix_inv * input[0][i]; - output[1][i] = mix_inv * input[1][i]; - // If len has changed, idx may have not, so we do the min so we don't go out of bounds let idx = self.idx.min(len - 1); // Play from Buffer - output[0][i] += model.mix[i] * self.buffer_l[(LEN - len) + idx]; - output[1][i] += model.mix[i] * self.buffer_r[(LEN - len) + idx]; + output[0][i] = self.buffer_l[(LEN - len) + idx]; + output[1][i] = self.buffer_r[(LEN - len) + idx]; + + // dissipates the audio in the buffer, idk + // it adds a bit of the next sample to this one, which smooths it out + let diss = model.dissipation[i]; + let a = (LEN - len) + idx; + self.buffer_l[a] *= diss; + self.buffer_r[a] *= diss; + self.buffer_l[a] += (1.0 - diss) * self.buffer_l[(a + 1) % LEN]; + self.buffer_r[a] += (1.0 - diss) * self.buffer_r[(a + 1) % LEN]; // Loop index after we finish playing a section self.idx += 1;