]> code.octet-stream.net Git - m17rt/blobdiff - m17codec2/src/lib.rs
Generate preamble and EOT
[m17rt] / m17codec2 / src / lib.rs
index eb45f770caa8c31b5ea3cadd75b734e01817c1e6..bfd30950bd1b762633ce993b97cfabc31232dc75 100755 (executable)
@@ -1,9 +1,12 @@
 use codec2::{Codec2, Codec2Mode};
-
+use cpal::traits::DeviceTrait;
+use cpal::traits::HostTrait;
+use cpal::traits::StreamTrait;
+use cpal::{Sample, SampleFormat, SampleRate};
+use log::debug;
 use m17app::adapter::StreamAdapter;
 use m17app::app::TxHandle;
 use m17core::protocol::LsfFrame;
-
 use std::collections::VecDeque;
 use std::fs::File;
 use std::io::Write;
@@ -13,13 +16,6 @@ use std::sync::{
     Arc, Mutex,
 };
 
-use cpal::traits::DeviceTrait;
-use cpal::traits::HostTrait;
-use cpal::traits::StreamTrait;
-use cpal::{Sample, SampleFormat, SampleRate};
-
-use log::debug;
-
 pub fn decode_codec2<P: AsRef<Path>>(data: &[u8], out_path: P) -> Vec<i16> {
     let codec2 = Codec2::new(Codec2Mode::MODE_3200);
     let var_name = codec2;
@@ -54,6 +50,7 @@ impl Codec2Adapter {
                 codec2: Codec2::new(Codec2Mode::MODE_3200),
                 end_tx: None,
             })),
+            // TODO: this doesn't work on rpi. Use default_output_device() by default
             output_card: "default".to_owned(),
         }
     }
@@ -135,6 +132,8 @@ fn stream_thread(end: Receiver<()>, state: Arc<Mutex<AdapterState>>, output_card
         .find(|d| d.name().unwrap() == output_card)
         .unwrap();
     let mut configs = device.supported_output_configs().unwrap();
+    // TODO: channels == 1 doesn't work on a Raspberry Pi
+    // make this configurable and support interleaving LRLR stereo samples if using 2 channels
     let config = configs
         .find(|c| c.channels() == 1 && c.sample_format() == SampleFormat::I16)
         .unwrap()
@@ -142,7 +141,12 @@ fn stream_thread(end: Receiver<()>, state: Arc<Mutex<AdapterState>>, output_card
     let stream = device
         .build_output_stream(
             &config.into(),
-            move |data: &mut [i16], _: &cpal::OutputCallbackInfo| {
+            move |data: &mut [i16], info: &cpal::OutputCallbackInfo| {
+                debug!(
+                    "callback {:?} playback {:?}",
+                    info.timestamp().callback,
+                    info.timestamp().playback
+                );
                 output_cb(data, &state);
             },
             |e| {