stabilizing phase bugs
This commit is contained in:
parent
e632ac3c44
commit
cc048b81df
1 changed files with 15 additions and 24 deletions
|
@ -51,13 +51,13 @@ pub fn audio_transmitter_main(
|
||||||
|
|
||||||
// TODO: from cli
|
// TODO: from cli
|
||||||
let mut carrier = TwoStateCarrier::new(
|
let mut carrier = TwoStateCarrier::new(
|
||||||
3200, // freq_low
|
320, // freq_low
|
||||||
3840, // freq_high
|
340, // freq_high
|
||||||
cpal_output_config.sample_rate().0, // sample_rate
|
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
|
// TODO: config .clone()s should be obsolete
|
||||||
let output_stream = match cpal_output_config.sample_format() {
|
let output_stream = match cpal_output_config.sample_format() {
|
||||||
|
@ -178,60 +178,51 @@ fn give_output_pcm<T>(
|
||||||
pcm: &mut [T],
|
pcm: &mut [T],
|
||||||
rx_for_mod: &mut Receiver<u8>,
|
rx_for_mod: &mut Receiver<u8>,
|
||||||
carrier: &mut TwoStateCarrier,
|
carrier: &mut TwoStateCarrier,
|
||||||
leftovers: &mut Vec<f64>,
|
leftovers: &mut VecDeque<f64>,
|
||||||
) where
|
) where
|
||||||
T: Sample + std::fmt::Debug + FromSample<f64>,
|
T: Sample + std::fmt::Debug + FromSample<f64>,
|
||||||
{
|
{
|
||||||
trace!("ALSA demands {} samples...", pcm.len());
|
trace!("ALSA demands {} samples...", pcm.len());
|
||||||
let mut output = pcm.iter_mut().peekable();
|
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() {
|
if let Some(sample_to_write) = output.next() {
|
||||||
*sample_to_write = samp.to_sample::<T>();
|
*sample_to_write = samp.to_sample::<T>();
|
||||||
} else {
|
} else {
|
||||||
*leftovers = leftovers_iter.collect();
|
trace!("ALSA demand fulfilled (last samp with leftovers), {} leftovers remain", leftovers.len());
|
||||||
//leftovers.extend(leftovers_iter);
|
|
||||||
trace!("ALSA demand fulfilled (last samp with leftovers)! collected {} leftovers", leftovers.len());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Ok(byte) = rx_for_mod.try_recv() {
|
while let Ok(byte) = rx_for_mod.try_recv() {
|
||||||
//trace!("recv byte {}", byte);
|
|
||||||
let samps = carrier.byte_into_fsk_samples(&byte);
|
let samps = carrier.byte_into_fsk_samples(&byte);
|
||||||
let mut samps_iter = samps.iter();
|
trace!("new ether samps {:?}", samps);
|
||||||
//trace!("Samples for this byte: {:?}", samps_iter);
|
let mut samps_iter = samps.iter().cloned();
|
||||||
while let Some(samp) = samps_iter.next() {
|
while let Some(samp) = samps_iter.next() {
|
||||||
if let Some(sample_to_write) = output.next() {
|
if let Some(sample_to_write) = output.next() {
|
||||||
*sample_to_write = samp.to_sample::<T>();
|
*sample_to_write = samp.to_sample::<T>();
|
||||||
} else {
|
} else {
|
||||||
*leftovers = leftovers_iter.collect();
|
let mut collected = samps_iter.collect::<VecDeque<f64>>();
|
||||||
//leftovers.extend(samps_iter);
|
leftovers.append(&mut collected);
|
||||||
trace!("{:?}", leftovers);
|
|
||||||
trace!("ALSA demand fulfilled (last samp with modulated eth data)! collected {} leftovers", leftovers.len());
|
trace!("ALSA demand fulfilled (last samp with modulated eth data)! collected {} leftovers", leftovers.len());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//trace!("No more eth frame bytes, idling carrier");
|
|
||||||
while let Some(_) = output.peek() {
|
while let Some(_) = output.peek() {
|
||||||
let idle_samps = carrier.idle();
|
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() {
|
while let Some(samp) = idle_samps_iter.next() {
|
||||||
if let Some(sample_to_write) = output.next() {
|
if let Some(sample_to_write) = output.next() {
|
||||||
*sample_to_write = samp.to_sample::<T>();
|
*sample_to_write = samp.to_sample::<T>();
|
||||||
} else {
|
} else {
|
||||||
*leftovers = leftovers_iter.collect();
|
let mut collected = idle_samps_iter.collect::<VecDeque<f64>>();
|
||||||
//leftovers.extend(idle_samps_iter);
|
leftovers.append(&mut collected);
|
||||||
trace!("ALSA demand fulfilled (last samp with empty carrier)! collected {} leftovers", leftovers.len());
|
trace!("ALSA demand fulfilled (last samp with empty carrier)! collected {} leftovers", leftovers.len());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//*leftovers = leftovers_iter.collect();
|
trace!("Alsa demand fulfilled with no leftovers, apparently. (leftovers={})", leftovers.len());
|
||||||
leftovers.extend(leftovers_iter);
|
|
||||||
trace!("ALSA demand fulfilled! collected {} leftovers", leftovers.len());
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue