aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2023-01-15 11:36:22 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2023-01-15 11:36:22 +0100
commitd16bebaa173789c7371b300b185ebe325596edaf (patch)
tree975b20cce9581116f9c0b0142af0b8db7727bd35
parentc3a258460e54103e74fcff1843511683fcd7aa39 (diff)
downloadfl2k_ampliphase-d16bebaa173789c7371b300b185ebe325596edaf.tar.gz
fl2k_ampliphase-d16bebaa173789c7371b300b185ebe325596edaf.tar.bz2
fl2k_ampliphase-d16bebaa173789c7371b300b185ebe325596edaf.zip
Downmix the source from stereo to mono
-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) {