stabilizing phase bugs

This commit is contained in:
TerraMaster85 2024-12-22 00:25:11 -05:00
parent e632ac3c44
commit cc048b81df

View file

@ -51,13 +51,13 @@ pub fn audio_transmitter_main(
// TODO: from cli
let mut carrier = TwoStateCarrier::new(
3200, // freq_low
3840, // freq_high
320, // freq_low
340, // freq_high
cpal_output_config.sample_rate().0, // sample_rate
48, // symbol_rate
20, // symbol_rate
);
let mut leftovers: Vec<f64> = vec![];
let mut leftovers: VecDeque<f64> = vec![].into();
// TODO: config .clone()s should be obsolete
let output_stream = match cpal_output_config.sample_format() {
@ -178,60 +178,51 @@ fn give_output_pcm<T>(
pcm: &mut [T],
rx_for_mod: &mut Receiver<u8>,
carrier: &mut TwoStateCarrier,
leftovers: &mut Vec<f64>,
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();
let mut leftovers_owned = leftovers.clone();
let mut leftovers_iter = leftovers_owned.into_iter();
while let Some(samp) = leftovers_iter.next() {
while let Some(samp) = leftovers.pop_front() {
if let Some(sample_to_write) = output.next() {
*sample_to_write = samp.to_sample::<T>();
} else {
*leftovers = leftovers_iter.collect();
//leftovers.extend(leftovers_iter);
trace!("ALSA demand fulfilled (last samp with leftovers)! collected {} leftovers", leftovers.len());
trace!("ALSA demand fulfilled (last samp with leftovers), {} leftovers remain", leftovers.len());
return;
}
}
while let Ok(byte) = rx_for_mod.try_recv() {
//trace!("recv byte {}", byte);
let samps = carrier.byte_into_fsk_samples(&byte);
let mut samps_iter = samps.iter();
//trace!("Samples for this byte: {:?}", samps_iter);
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 {
*leftovers = leftovers_iter.collect();
//leftovers.extend(samps_iter);
trace!("{:?}", leftovers);
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;
}
}
}
//trace!("No more eth frame bytes, idling carrier");
while let Some(_) = output.peek() {
let idle_samps = carrier.idle();
let mut idle_samps_iter = idle_samps.iter();
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 {
*leftovers = leftovers_iter.collect();
//leftovers.extend(idle_samps_iter);
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;
}
}
}
//*leftovers = leftovers_iter.collect();
leftovers.extend(leftovers_iter);
trace!("ALSA demand fulfilled! collected {} leftovers", leftovers.len());
trace!("Alsa demand fulfilled with no leftovers, apparently. (leftovers={})", leftovers.len());
}