sang/src/dsp_outb/mod.rs

50 lines
1.4 KiB
Rust
Raw Normal View History

2024-12-16 21:06:39 -05:00
use anyhow::{Context, Result};
use cpal::Sample;
use tracing::{error, info, trace, warn};
use tokio::sync::mpsc::{Receiver, Sender};
use tokio::sync::mpsc::error::TryRecvError;
use crate::task_msg::{RawEthFrameMessage, PcmSampleMessage};
use crate::dsp_common::carrier::{Carrier, TwoStateCarrier};
pub async fn dsp_outb_main(
tx_for_wire: Sender<PcmSampleMessage>,
mut rx_for_mod: Receiver<RawEthFrameMessage>,
) -> Result<()> {
trace!("pcm_outb task started");
let carrier_phase = 0_f64;
let carrier_low = 2400;
let carrier_high = 2500;
let mut carrier = TwoStateCarrier::new(carrier_low, carrier_high, 384000);
loop {
let eth_frame = match rx_for_mod.try_recv() {
Ok(x) => x,
Err(TryRecvError::Empty) => {
tx_for_wire.send(i64::EQUILIBRIUM).await?;
continue;
}
Err(TryRecvError::Disconnected) => {
Err(anyhow::Error::msg(
format!("rx_for_mod closed?! the tap task likely crashed"),
))?
}
};
for byte in eth_frame {
for samp in carrier.byte_into_fsk_samples(&byte).iter() {
tx_for_wire.send(*samp).await?;
}
}
println!("done with that");
// TODO: fetch real sample rate
//(*carrier_phase * TAU * freq / sample_rate).sin()
}
}