aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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 {