aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 0814506..825d4e1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -261,9 +261,10 @@ fn main() {
}
}
+ // Downmix stereo to mono, apply (v/2 + i16::MAX/2), and normalise to [-1.0; 1.0]
let buf: Vec<f32> = buf
- .iter()
- .map(|v| (v/2 + i16::MAX/2) as f32 / 32768.0)
+ .chunks_exact(2)
+ .map(|v| ((v[0]/2 + v[1]/2)/2 + i16::MAX/2) as f32 / 32768.0)
.collect();
if let Some(w) = &mut in_debug {
@@ -283,7 +284,7 @@ fn main() {
// Read samples, calculate PD and PDSLOPE
thread::spawn(move || {
- let mut lastamp = 0f32;
+ let mut last_sample = 0f32;
let mut debug_writer = match output {
Output::Debug => Some(BufWriter::new(File::create("debug-pd.csv").expect("create file"))),
@@ -303,9 +304,9 @@ fn main() {
efficient and pretty good interpolation filter. */
for sample in buf {
- let slope = (sample - lastamp) / rf_to_baseband_sample_ratio as f32;
+ let slope = (sample - last_sample) / rf_to_baseband_sample_ratio as f32;
- let pd = lastamp * modulation_index * INT32_MAX_AS_FLOAT;
+ let pd = last_sample * modulation_index * INT32_MAX_AS_FLOAT;
const MIN_VAL: f32 = std::i32::MIN as f32;
const MAX_VAL: f32 = std::i32::MAX as f32;
@@ -326,7 +327,7 @@ fn main() {
pd_buf.push((pd as i32, pdslope as i32));
- lastamp = sample;
+ last_sample = sample;
}
if let Err(_) = pd_tx.send(pd_buf) {