aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-09-29 21:15:31 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-09-29 21:15:31 +0200
commit56e3b02de7f67da4b94bbcb504b05c407502b76c (patch)
tree5da7c015e3b4035dd14c80a471d53dfb6c131cfd /src
parentb1d172ca6ae5f92b5b468fe37b736a00d56c90ae (diff)
downloadfl2k_ampliphase-56e3b02de7f67da4b94bbcb504b05c407502b76c.tar.gz
fl2k_ampliphase-56e3b02de7f67da4b94bbcb504b05c407502b76c.tar.bz2
fl2k_ampliphase-56e3b02de7f67da4b94bbcb504b05c407502b76c.zip
Apply asin to input samplesHEADmain
Diffstat (limited to 'src')
-rw-r--r--src/main.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index e35062e..8519158 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -270,10 +270,20 @@ fn main() {
}
}
- // Downmix stereo to mono, apply (v/2 + i16::MAX/2), and normalise to [-1.0; 1.0]
+ // Downmix stereo to mono, apply (v/2 + i16::MAX/2),
+ // normalise to [0.0; 1.0],
+ // take the arcsine to compensate for the phasing,
+ // and divide by PI/2 to normalise to [0.0; 1.0]
+ use std::f32::consts::FRAC_2_PI;
let buf: Vec<f32> = buf
.chunks_exact(2)
- .map(|v| ((v[0]/2 + v[1]/2)/2 + i16::MAX/2) as f32 / 32768.0)
+ .map(|v| {
+ let samp = ((v[0]/2 + v[1]/2)/2 + i16::MAX/2) as f32 / 32768.0;
+ if samp < -1.0 || samp > 1.0 {
+ panic!("sample normalistion broken")
+ }
+ f32::asin(samp) * FRAC_2_PI
+ })
.collect();
if let Some(w) = &mut in_debug {