[sosten] add dissipation, remove mix

main
annieversary 2021-08-05 12:00:29 +02:00
parent 512541026b
commit 62bc461f60
1 changed files with 15 additions and 11 deletions

View File

@ -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;