summaryrefslogtreecommitdiff
path: root/klangfarbrs/src/utils.rs
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2021-12-02 21:45:12 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2021-12-02 21:45:12 -0600
commit7574c5c7acaebe120de3efbaba56b8e9f474d330 (patch)
treec22046e612414fbd9d0f3ec55a789984215e74e6 /klangfarbrs/src/utils.rs
parentaf484658565920005a502553422530493a5d91de (diff)
Clean: factor out a utils module and fix some tests
Diffstat (limited to 'klangfarbrs/src/utils.rs')
-rw-r--r--klangfarbrs/src/utils.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/klangfarbrs/src/utils.rs b/klangfarbrs/src/utils.rs
new file mode 100644
index 0000000..9f99e23
--- /dev/null
+++ b/klangfarbrs/src/utils.rs
@@ -0,0 +1,10 @@
+use super::{ Amplitude, Millisecond, SamplesPerSecond };
+
+pub fn slope(start: Amplitude, end: Amplitude, duration: Millisecond) -> f32 {
+ return (end - start) / duration as f32 ;
+}
+
+pub fn ms_to_samples(ms: Millisecond, sample_rate: SamplesPerSecond) -> u32 {
+ let multiplier = sample_rate as u32 / 1000;
+ multiplier * ms
+}