From bbcb3a6b2dd829db5b963996d746d003f24c6051 Mon Sep 17 00:00:00 2001 From: TerraMaster85 Date: Mon, 16 Dec 2024 22:58:30 -0500 Subject: [PATCH] tx working in theory, but must be optimized --- src/audio_transmitter/mod.rs | 4 ++-- src/dsp_common/carrier.rs | 26 ++++++++++++-------------- src/dsp_outb/mod.rs | 10 ++++++---- src/main.rs | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/audio_transmitter/mod.rs b/src/audio_transmitter/mod.rs index 9587705..230f4c4 100644 --- a/src/audio_transmitter/mod.rs +++ b/src/audio_transmitter/mod.rs @@ -148,8 +148,8 @@ where *outgoing = match channel.try_recv() { Ok(sample) => sample.to_sample::(), Err(_) => { - //warn!("rx_for_wire has no samples for us! carrier dead!"); - //warn!("are we able to produce samples quickly enough? CPU OK?"); + warn!("rx_for_wire has no samples for us! carrier dead!"); + warn!("are we able to produce samples quickly enough? CPU OK?"); T::EQUILIBRIUM } }; diff --git a/src/dsp_common/carrier.rs b/src/dsp_common/carrier.rs index 1339f6a..e835823 100644 --- a/src/dsp_common/carrier.rs +++ b/src/dsp_common/carrier.rs @@ -19,39 +19,37 @@ pub trait Carrier { impl Carrier for TwoStateCarrier { fn byte_into_fsk_samples(&mut self, byte: &u8) -> Vec { - let mut bits: Vec = vec![]; + let mut bits: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; let mut out: Vec = vec![]; // MSb first - bits.push((byte ) & 1); - bits.push((byte >> 1) & 1); - bits.push((byte >> 2) & 1); - bits.push((byte >> 3) & 1); - bits.push((byte >> 4) & 1); - bits.push((byte >> 5) & 1); - bits.push((byte >> 6) & 1); - bits.push((byte >> 7) & 1); + bits[0] = (byte ) & 1; + bits[1] = (byte >> 1) & 1; + bits[2] = (byte >> 2) & 1; + bits[3] = (byte >> 3) & 1; + bits[4] = (byte >> 4) & 1; + bits[5] = (byte >> 5) & 1; + bits[6] = (byte >> 6) & 1; + bits[7] = (byte >> 7) & 1; for (i, bit) in bits.into_iter().enumerate() { if bit == 0 { trace!("low bit {} in fsk code", i); while (self.phase_low) < self.sample_rate / self.freq_low { - trace!("low bit gen sin"); out.push((self.phase_low * TAU * self.freq_low / self.sample_rate).sin().to_sample::()); self.phase_low += 1.0; } - self.phase_low = self.phase_low % self.sample_rate; + self.phase_low = self.phase_low % (self.sample_rate / self.freq_high); } else if bit == 1 { trace!("high bit {} in fsk code", i); while (self.phase_high) < self.sample_rate / self.freq_high { - trace!("high bit gen sin"); out.push((self.phase_high * TAU * self.freq_low / self.sample_rate).sin().to_sample::()); self.phase_high += 1.0; } - self.phase_high = self.phase_high % self.sample_rate; + self.phase_high = self.phase_high % (self.sample_rate / self.freq_low); } } - trace!("FSK calculations turned up {:?}", &out); + //trace!("FSK calculations turned up {:?}", &out); out } } diff --git a/src/dsp_outb/mod.rs b/src/dsp_outb/mod.rs index 2803112..0c46e0f 100644 --- a/src/dsp_outb/mod.rs +++ b/src/dsp_outb/mod.rs @@ -17,8 +17,8 @@ pub async fn dsp_outb_main( trace!("pcm_outb task started"); let carrier_phase = 0_f64; - let carrier_low = 2400; - let carrier_high = 2500; + let carrier_low = 240; + let carrier_high = 250; // TODO: fetch real sample rate let mut carrier = TwoStateCarrier::new(carrier_low, carrier_high, 384000); @@ -27,8 +27,10 @@ pub async fn dsp_outb_main( let eth_frame = match rx_for_mod.try_recv() { Ok(x) => x, Err(TryRecvError::Empty) => { - tx_for_wire.send(i64::EQUILIBRIUM).await?; - continue; + trace!("no eth frames to modulate!"); + //tx_for_wire.send(i64::EQUILIBRIUM).await?; + //continue; + vec![0, 0, 0, 0, 0, 0, 0, 0,] } Err(TryRecvError::Disconnected) => { Err(anyhow::Error::msg( diff --git a/src/main.rs b/src/main.rs index 2d7889a..fc2228c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ async fn main() -> Result<()> { let (tx_for_eth_inb, rx_for_eth_inb) = unbounded_channel::(); let (tx_for_mod, rx_for_mod) = channel::(1024); - let (tx_for_wire, rx_for_wire) = channel::(1); + let (tx_for_wire, rx_for_wire) = channel::(1024); trace!("starting listener for audio on wire"); let audio_in_stream = audio_receiver_main(tx_for_demod, &cpal_input)