diff options
Diffstat (limited to 'klangfarbrs/src/instrument.rs')
-rw-r--r-- | klangfarbrs/src/instrument.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/klangfarbrs/src/instrument.rs b/klangfarbrs/src/instrument.rs index bf08fe4..3170464 100644 --- a/klangfarbrs/src/instrument.rs +++ b/klangfarbrs/src/instrument.rs @@ -1,4 +1,4 @@ -use super::{ Partial, Sample, Hz, SamplesPerSecond }; +use super::{ Partial, Millisecond, Sample, Hz, SamplesPerSecond }; pub struct Instrument { pub partials: Vec<Partial>, @@ -13,6 +13,28 @@ impl Instrument { } } + pub fn bell(base_freq: Hz, duration: Millisecond, sample_rate: SamplesPerSecond) -> Self { + let bell_partials = vec![ + (1.0, 1.0, 0.56, 0.0), + (0.67, 0.9, 0.56, 1.0), + (1.0, 0.65, 0.82, 0.0), + (1.8, 0.55, 0.92, 1.7), + (2.67, 0.325, 1.19, 0.0), + (1.67, 0.35, 1.7, 0.0), + (1.46, 0.25, 2.0, 0.0), + (1.33, 0.2, 2.74, 0.0), + (1.33, 0.15, 3.0, 0.0), + (1.0, 0.1, 3.76, 0.0), + (1.33, 0.075, 4.07, 0.0), + ]; + + Self { + partials: bell_partials.iter() + .map(|&p| Partial::new(p.0, p.1, p.2, p.3, sample_rate, duration, base_freq)) + .collect() + } + } + pub fn sample(&mut self) -> Sample { match self.next() { Some(s) => { s }, @@ -52,3 +74,5 @@ mod tests { assert_eq!(inst.last(), Some(0.0)); } } + +// Partial::new(1.0, 1.0, p, 0.0, sample_rate, 2000, base_freq) |