diff options
-rw-r--r-- | klangfarbrs/src/adsr.rs | 32 | ||||
-rw-r--r-- | klangfarbrs/src/lib.rs | 2 |
2 files changed, 34 insertions, 0 deletions
diff --git a/klangfarbrs/src/adsr.rs b/klangfarbrs/src/adsr.rs new file mode 100644 index 0000000..ca03735 --- /dev/null +++ b/klangfarbrs/src/adsr.rs @@ -0,0 +1,32 @@ +use crate::{Millisecond, Amplitude}; + +pub struct Envelope { + attack: Vec<Amplitude>, + decay: Vec<Amplitude>, + release: Vec<Amplitude>, +} + +impl Envelope { + fn new(attack: Millisecond, decay: Millisecond, sustain: Amplitude, release: Millisecond) -> Self { + let attack = vec![sustain; attack as usize]; + let decay = vec![sustain; decay as usize]; + let release = vec![sustain; release as usize]; + + Self{attack, decay, release} + } + + pub fn len(&self) -> usize { + self.attack.len() + self.decay.len() + self.release.len() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_has_expected_total_length() { + let total = Envelope::new(10, 10, 1.0, 10).len(); + assert_eq! (30, total) + } +} diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs index a96393f..087cbd7 100644 --- a/klangfarbrs/src/lib.rs +++ b/klangfarbrs/src/lib.rs @@ -15,6 +15,8 @@ use gdnative::core_types::TypedArray; mod osc; use osc::{Osc}; +mod adsr; + /// Aliasing some types to distinguish various audio properties. type Sample = f32; type SamplesPerSecond = f32; |