cleaning the house

This commit is contained in:
TerraMaster85 2024-12-26 13:31:51 -05:00
parent a9e4916c68
commit f050cec085
9 changed files with 167 additions and 221 deletions

197
Cargo.lock generated
View file

@ -225,103 +225,12 @@ dependencies = [
"windows",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
[[package]]
name = "dasp_envelope"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ec617ce7016f101a87fe85ed44180839744265fae73bb4aa43e7ece1b7668b6"
dependencies = [
"dasp_frame",
"dasp_peak",
"dasp_ring_buffer",
"dasp_rms",
"dasp_sample",
]
[[package]]
name = "dasp_frame"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2a3937f5fe2135702897535c8d4a5553f8b116f76c1529088797f2eee7c5cd6"
dependencies = [
"dasp_sample",
]
[[package]]
name = "dasp_interpolate"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc975a6563bb7ca7ec0a6c784ead49983a21c24835b0bc96eea11ee407c7486"
dependencies = [
"dasp_frame",
"dasp_ring_buffer",
"dasp_sample",
]
[[package]]
name = "dasp_peak"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cf88559d79c21f3d8523d91250c397f9a15b5fc72fbb3f87fdb0a37b79915bf"
dependencies = [
"dasp_frame",
"dasp_sample",
]
[[package]]
name = "dasp_ring_buffer"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07d79e19b89618a543c4adec9c5a347fe378a19041699b3278e616e387511ea1"
[[package]]
name = "dasp_rms"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6c5dcb30b7e5014486e2822537ea2beae50b19722ffe2ed7549ab03774575aa"
dependencies = [
"dasp_frame",
"dasp_ring_buffer",
"dasp_sample",
]
[[package]]
name = "dasp_sample"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"
[[package]]
name = "dasp_signal"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa1ab7d01689c6ed4eae3d38fe1cea08cba761573fbd2d592528d55b421077e7"
dependencies = [
"dasp_envelope",
"dasp_frame",
"dasp_interpolate",
"dasp_peak",
"dasp_ring_buffer",
"dasp_rms",
"dasp_sample",
"dasp_window",
]
[[package]]
name = "dasp_window"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99ded7b88821d2ce4e8b842c9f1c86ac911891ab89443cc1de750cae764c5076"
dependencies = [
"dasp_sample",
]
[[package]]
name = "either"
version = "1.13.0"
@ -382,7 +291,7 @@ dependencies = [
"combine",
"jni-sys",
"log",
"thiserror 1.0.69",
"thiserror",
"walkdir",
"windows-sys 0.45.0",
]
@ -502,7 +411,7 @@ dependencies = [
"log",
"ndk-sys",
"num_enum",
"thiserror 1.0.69",
"thiserror",
]
[[package]]
@ -552,6 +461,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-complex"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]
[[package]]
name = "num-derive"
version = "0.4.2"
@ -563,6 +481,15 @@ dependencies = [
"syn",
]
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.19"
@ -673,10 +600,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "portable-atomic"
version = "1.10.0"
name = "primal-check"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
checksum = "dc0d895b311e3af9902528fbb8f928688abbd95872819320517cc24ca6b2bd08"
dependencies = [
"num-integer",
]
[[package]]
name = "proc-macro-crate"
@ -743,16 +673,6 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "ringbuf"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "726bb493fe9cac765e8f96a144c3a8396bdf766dedad22e504b70b908dcbceb4"
dependencies = [
"crossbeam-utils",
"portable-atomic",
]
[[package]]
name = "rustc-demangle"
version = "0.1.24"
@ -765,6 +685,21 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustfft"
version = "6.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43806561bc506d0c5d160643ad742e3161049ac01027b5e6d7524091fd401d86"
dependencies = [
"num-complex",
"num-integer",
"num-traits",
"primal-check",
"strength_reduce",
"transpose",
"version_check",
]
[[package]]
name = "same-file"
version = "1.0.6"
@ -780,9 +715,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"cpal",
"dasp_signal",
"ringbuf",
"thiserror 2.0.6",
"rustfft",
"tokio",
"tokio-tun",
"tracing",
@ -835,6 +768,12 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "strength_reduce"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82"
[[package]]
name = "syn"
version = "2.0.90"
@ -852,16 +791,7 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fec2a1820ebd077e2b90c4df007bebf344cd394098a13c563957d0afc83ea47"
dependencies = [
"thiserror-impl 2.0.6",
"thiserror-impl",
]
[[package]]
@ -875,17 +805,6 @@ dependencies = [
"syn",
]
[[package]]
name = "thiserror-impl"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d65750cab40f4ff1929fb1ba509e9914eb756131cef4210da8d5d700d26f6312"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "thread_local"
version = "1.1.8"
@ -933,7 +852,7 @@ checksum = "9bf48df2abbfd12d0b8495dcf960b125109493d85f2c787b44a2729a8022bc4b"
dependencies = [
"libc",
"nix",
"thiserror 1.0.69",
"thiserror",
"tokio",
]
@ -1011,6 +930,16 @@ dependencies = [
"tracing-log",
]
[[package]]
name = "transpose"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad61aed86bc3faea4300c7aee358b4c6d0c8d6ccc36524c96e4c92ccf26e77e"
dependencies = [
"num-integer",
"strength_reduce",
]
[[package]]
name = "unicode-ident"
version = "1.0.14"
@ -1023,6 +952,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "walkdir"
version = "2.5.0"

View file

@ -6,9 +6,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.94"
cpal = "0.15.3"
dasp_signal = "0.11.0"
ringbuf = "0.4.7"
thiserror = "2.0.6"
rustfft = "6.2.0"
tokio = { version = '^1', features = ["full"] }
tokio-tun = "0.12.1"
tracing = "0.1.41"

View file

@ -0,0 +1,13 @@
use cpal::{FromSample, Sample};
use rustfft::{FftPlanner, num_complex::Complex};
pub fn take_input_pcm<T>(pcm: &[T], channel: &tokio::sync::mpsc::Sender<Vec<f64>>) where T: Sample + FromSample<f64> + std::fmt::Debug, f64: FromSample<T> {
let mut pcm_complex = pcm.iter().map(|s| Complex { re: s.to_sample::<f64>(), im: 0.0f64 }).collect::<Vec<Complex<_>>>();
let mut fft_planner = FftPlanner::<f64>::new();
let fft_machine = fft_planner.plan_fft_forward(pcm.len());
fft_machine.process(&mut pcm_complex);
let fft_out = pcm_complex.iter().map(|n| n.norm()).collect::<Vec<_>>();
println!("{:?}",fft_out);
}

View file

@ -1,14 +1,15 @@
use anyhow::{Context, Result};
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::traits::{DeviceTrait, StreamTrait};
use cpal::{FromSample, Sample, SampleFormat};
use tracing::{error, info, trace, warn};
use tracing::{info, trace, warn};
use tokio::sync::mpsc::Sender;
mod input_dsp;
use self::input_dsp::take_input_pcm;
pub fn audio_receiver_main(
tx_for_demod: Sender<Vec<f64>>,
tx_for_demod: tokio::sync::mpsc::Sender<Vec<f64>>,
cpal_input: &cpal::Device,
) -> Result<cpal::Stream> {
trace!("audio_receiver started");
@ -102,10 +103,3 @@ pub fn audio_receiver_main(
Ok(input_stream)
}
fn take_input_pcm<T>(pcm: &[T], channel: &Sender<Vec<f64>>) where T: Sample + std::fmt::Debug, f64: FromSample<T> {
let _ = pcm;
//if channel.try_send(pcm.iter().map(|&n| n.to_sample::<f64>()).collect()).is_err() {
// error!("demodulator PCM data queue is full???");
//}
}

View file

@ -2,18 +2,18 @@ use std::collections::VecDeque;
use anyhow::{Context, Result};
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::{FromSample, Sample, SampleFormat};
use cpal::traits::{DeviceTrait, StreamTrait};
use cpal::SampleFormat;
use tracing::{error, info, trace, warn};
use tracing::{info, trace, warn};
use tokio::sync::mpsc::Receiver;
use crate::dsp_common::carrier::{Carrier, TwoStateCarrier};
mod output_dsp;
use output_dsp::give_output_pcm;
pub fn audio_transmitter_main(
mut rx_for_mod: Receiver<u8>,
tx_sample_rate_notify: tokio::sync::oneshot::Sender<u32>,
cpal_output: &cpal::Device,
) -> Result<cpal::Stream> {
trace!("audio_transmitter started");
@ -50,7 +50,7 @@ pub fn audio_transmitter_main(
};
// TODO: from cli
let mut carrier = TwoStateCarrier::new(
let mut carrier = crate::dsp_common::carrier::TwoStateCarrier::new(
2400, // freq_low
2800, // freq_high
cpal_output_config.sample_rate().0, // sample_rate
@ -173,56 +173,3 @@ pub fn audio_transmitter_main(
Ok(output_stream)
}
fn give_output_pcm<T>(
pcm: &mut [T],
rx_for_mod: &mut Receiver<u8>,
carrier: &mut TwoStateCarrier,
leftovers: &mut VecDeque<f64>,
) where
T: Sample + std::fmt::Debug + FromSample<f64>,
{
trace!("ALSA demands {} samples...", pcm.len());
let mut output = pcm.iter_mut().peekable();
while let Some(samp) = leftovers.pop_front() {
if let Some(sample_to_write) = output.next() {
*sample_to_write = samp.to_sample::<T>();
} else {
trace!("ALSA demand fulfilled (last samp with leftovers), {} leftovers remain", leftovers.len());
return;
}
}
while let Ok(byte) = rx_for_mod.try_recv() {
let samps = carrier.byte_into_fsk_samples(&byte);
//trace!("new ether samps {:?}", samps);
let mut samps_iter = samps.iter().cloned();
while let Some(samp) = samps_iter.next() {
if let Some(sample_to_write) = output.next() {
*sample_to_write = samp.to_sample::<T>();
} else {
let mut collected = samps_iter.collect::<VecDeque<f64>>();
leftovers.append(&mut collected);
trace!("ALSA demand fulfilled (last samp with modulated eth data)! collected {} leftovers", leftovers.len());
return;
}
}
}
while let Some(_) = output.peek() {
let idle_samps = carrier.idle();
let mut idle_samps_iter = idle_samps.iter().cloned();
while let Some(samp) = idle_samps_iter.next() {
if let Some(sample_to_write) = output.next() {
*sample_to_write = samp.to_sample::<T>();
} else {
let mut collected = idle_samps_iter.collect::<VecDeque<f64>>();
leftovers.append(&mut collected);
trace!("ALSA demand fulfilled (last samp with empty carrier)! collected {} leftovers", leftovers.len());
return;
}
}
}
trace!("Alsa demand fulfilled with no leftovers, apparently. (leftovers={})", leftovers.len());
}

View file

@ -0,0 +1,61 @@
use std::collections::VecDeque;
use cpal::{FromSample, Sample};
use tracing::trace;
use crate::dsp_common::carrier::{Carrier, TwoStateCarrier};
pub fn give_output_pcm<T>(
pcm: &mut [T],
rx_for_mod: &mut tokio::sync::mpsc::Receiver<u8>,
carrier: &mut TwoStateCarrier,
leftovers: &mut VecDeque<f64>,
) where
T: Sample + std::fmt::Debug + FromSample<f64>,
{
trace!("ALSA demands {} samples...", pcm.len());
let mut output = pcm.iter_mut().peekable();
while let Some(samp) = leftovers.pop_front() {
if let Some(sample_to_write) = output.next() {
*sample_to_write = samp.to_sample::<T>();
} else {
trace!("ALSA demand fulfilled (last samp with leftovers), {} leftovers remain", leftovers.len());
return;
}
}
while let Ok(byte) = rx_for_mod.try_recv() {
let samps = carrier.byte_into_fsk_samples(&byte);
//trace!("new ether samps {:?}", samps);
let mut samps_iter = samps.iter().cloned();
while let Some(samp) = samps_iter.next() {
if let Some(sample_to_write) = output.next() {
*sample_to_write = samp.to_sample::<T>();
} else {
let mut collected = samps_iter.collect::<VecDeque<f64>>();
leftovers.append(&mut collected);
trace!("ALSA demand fulfilled (last samp with modulated eth data)! collected {} leftovers", leftovers.len());
return;
}
}
}
while let Some(_) = output.peek() {
let idle_samps = carrier.idle();
let mut idle_samps_iter = idle_samps.iter().cloned();
while let Some(samp) = idle_samps_iter.next() {
if let Some(sample_to_write) = output.next() {
*sample_to_write = samp.to_sample::<T>();
} else {
let mut collected = idle_samps_iter.collect::<VecDeque<f64>>();
leftovers.append(&mut collected);
trace!("ALSA demand fulfilled (last samp with empty carrier)! collected {} leftovers", leftovers.len());
return;
}
}
}
trace!("Alsa demand fulfilled with no leftovers, apparently. (leftovers={})", leftovers.len());
}

View file

@ -1,6 +1,3 @@
use cpal::Sample;
use tracing::trace;
use super::sample::PcmSample;
const TAU: f64 = 2.0 * std::f64::consts::PI;
@ -92,7 +89,7 @@ impl TwoStateCarrier {
}
}
// setters
fn freq_low(mut self, freq_low: u32) {
/*fn freq_low(mut self, freq_low: u32) {
self.freq_low = freq_low.into();
}
fn freq_high(mut self, freq_high: u32) {
@ -103,5 +100,5 @@ impl TwoStateCarrier {
}
fn symbol_rate(mut self, symbol_rate: u32) {
self.symbol_rate = symbol_rate.into();
}
}*/
}

View file

@ -10,7 +10,7 @@ use cpal::traits::HostTrait;
use tracing::{trace};
use tokio::sync::mpsc::{channel, unbounded_channel};
use tokio::sync::mpsc::channel;
mod audio_receiver;
use crate::audio_receiver::audio_receiver_main;
@ -23,8 +23,6 @@ mod dsp_common;
mod tap_junction;
use crate::tap_junction::tap_junction_main;
mod wire_fmt;
//#[derive(argh::FromArgs)]
//struct Cli {}
@ -40,24 +38,23 @@ async fn main() -> Result<()> {
"no audio output could be found; is a sound card installed?"
)?;
let (tx_for_demod, rx_for_demod) = channel::<Vec<f64>>(8192);
let (tx_for_eth_inb, rx_for_eth_inb) = channel::<Vec<u8>>(8192);
let (tx_for_mod, rx_for_mod) = channel::<u8>(8192);
let (tx_sample_rate_notify, rx_sample_rate_notify) =
tokio::sync::oneshot::channel::<u32>();
trace!("starting listener for audio on wire");
let audio_in_stream = audio_receiver_main(tx_for_demod, &cpal_input)
.context("listener for audio on wire has failed to start")?;
let mut tasks = tokio::task::JoinSet::new();
let task_tap_junction = tasks.spawn(async move {
trace!("starting listener for audio on wire");
let _audio_in_stream = audio_receiver_main(tx_for_demod, &cpal_input)
.context("listener for audio on wire has failed to start")?;
let _task_tap_junction = tasks.spawn(async move {
trace!("Starting tap manager");
tap_junction_main(tx_for_mod, rx_for_eth_inb).await
});
trace!("Starting audio sender");
let audio_out_stream = audio_transmitter_main(rx_for_mod, tx_sample_rate_notify, &cpal_output)
let _audio_out_stream = audio_transmitter_main(rx_for_mod, &cpal_output)
.context("transmitter for audio on wire has failed to start")?;
while let Some(task_result) = tasks.join_next().await {

4
src/process Normal file

File diff suppressed because one or more lines are too long