summaryrefslogtreecommitdiff
path: root/klangfarbrs/src
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2021-11-09 20:51:57 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2021-11-09 20:51:57 -0600
commite2aec3161f791614fc19fc50a4dadf239d7422ad (patch)
tree17f5eb8c0b820ca64fec545d8ae2f01b079b6e63 /klangfarbrs/src
parent2676bee57d6907a3a55ec6f0f8f6316692ef4a35 (diff)
Add: stub of asdr module / Envelope struct
Diffstat (limited to 'klangfarbrs/src')
-rw-r--r--klangfarbrs/src/adsr.rs32
-rw-r--r--klangfarbrs/src/lib.rs2
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;