Idk, i'll proly rebase
This commit is contained in:
@ -192,7 +192,7 @@ impl RadioReceiver
|
||||
|
||||
let mut error: f32 = 0.;
|
||||
let is_symbol_center = x.1.as_ref().is_some_and(|t| {
|
||||
if let Some(err) = t.retrieve(symbol_tag2.clone())
|
||||
if let Some(err) = t.retrieve(&symbol_tag2.clone())
|
||||
{
|
||||
error = *err;
|
||||
true
|
||||
@ -220,7 +220,7 @@ impl RadioReceiver
|
||||
if sample
|
||||
.1
|
||||
.as_ref()
|
||||
.is_some_and(|t| t.retrieve(symbol_tag.clone()).is_some())
|
||||
.is_some_and(|t| t.retrieve(&symbol_tag.clone()).is_some())
|
||||
&& let Some(packet) = builder.next_bit(sample.0 < 0.)
|
||||
{
|
||||
let _ = packet_tx.send(packet);
|
||||
|
||||
@ -29,6 +29,7 @@ use std::sync::mpsc::Receiver;
|
||||
use std::sync::mpsc::SyncSender;
|
||||
use std::sync::mpsc::sync_channel;
|
||||
use std::thread::JoinHandle;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::CARRIER;
|
||||
use crate::DEVIATION;
|
||||
@ -37,109 +38,6 @@ use crate::SAMPLE_RATE;
|
||||
use crate::gaussian;
|
||||
use crate::to_bits;
|
||||
|
||||
#[derive(BlockIO)]
|
||||
pub struct FlatMap<I, O, F>
|
||||
where
|
||||
I: 'static,
|
||||
O: IntoIterator + 'static,
|
||||
O::IntoIter: FusedIterator,
|
||||
F: Fn(I) -> O,
|
||||
{
|
||||
#[input]
|
||||
input: In<I>,
|
||||
|
||||
#[output]
|
||||
output: Out<O::Item>,
|
||||
|
||||
current_iter: Option<O::IntoIter>,
|
||||
map: F,
|
||||
}
|
||||
|
||||
impl<I, O, F> FlatMap<I, O, F>
|
||||
where
|
||||
I: 'static,
|
||||
O: IntoIterator + 'static,
|
||||
O::IntoIter: FusedIterator,
|
||||
F: Fn(I) -> O,
|
||||
{
|
||||
pub fn new(input: In<I>, map: F) -> (Self, In<O::Item>)
|
||||
{
|
||||
let (output, port) = oxydsp_flowgraph::io::stream();
|
||||
(
|
||||
Self {
|
||||
input,
|
||||
output,
|
||||
current_iter: None,
|
||||
map,
|
||||
},
|
||||
port,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, O, F> Block for FlatMap<I, O, F>
|
||||
where
|
||||
I: 'static,
|
||||
O: IntoIterator + 'static,
|
||||
O::IntoIter: FusedIterator,
|
||||
F: Fn(I) -> O,
|
||||
{
|
||||
fn work(&mut self) -> BlockResult
|
||||
{
|
||||
let writer = self.output.write();
|
||||
let reader = self.input.read();
|
||||
|
||||
let max_write = writer.len();
|
||||
let mut written = 0;
|
||||
|
||||
while written < max_write
|
||||
{
|
||||
if let Some(current_iter) = self.current_iter.as_mut()
|
||||
{
|
||||
if let Some(next_elt) = current_iter.next()
|
||||
{
|
||||
let _ = writer.push((next_elt, None).into());
|
||||
written += 1;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Iterator empty
|
||||
self.current_iter = None;
|
||||
}
|
||||
}
|
||||
|
||||
if self.current_iter.is_none()
|
||||
{
|
||||
// Get input
|
||||
if let Some(input) = reader.pop()
|
||||
{
|
||||
let mut new_iter = (self.map)(input.0).into_iter();
|
||||
if let Some(first_elt) = new_iter.next()
|
||||
{
|
||||
self.current_iter = Some(new_iter);
|
||||
let _ = writer.push((first_elt, input.1).into());
|
||||
written += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Iterator empty
|
||||
self.current_iter = None;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cannot continue
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BlockResult::Ok
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Transmitter
|
||||
{
|
||||
flowgraph_handle: JoinHandle<()>,
|
||||
@ -176,13 +74,17 @@ impl Transmitter
|
||||
.map(|x| if x { 1. } else { -1. })
|
||||
});
|
||||
|
||||
let (repeat, bits) = Repeat::new(bits, SAMPLE_PER_SYMBOL);
|
||||
let (repeat, bits) = FlatMap::new(bits, |symbol| {
|
||||
let mut v = vec![0.; SAMPLE_PER_SYMBOL - 1];
|
||||
v.push(symbol);
|
||||
v
|
||||
});
|
||||
|
||||
// gaussian fir
|
||||
let fir = Fir((0..SAMPLE_PER_SYMBOL)
|
||||
.map(|x| gaussian(0.8, x as f32 / SAMPLE_PER_SYMBOL as f32))
|
||||
.collect())
|
||||
.normalized();
|
||||
.map(|x| gaussian(0.3, x as f32 / SAMPLE_PER_SYMBOL as f32))
|
||||
.collect());
|
||||
//.normalized();
|
||||
|
||||
let (bit_filter, bits) = FirFilter::new(bits, fir);
|
||||
let (to_freq, freq) = Map::new(bits, move |x| {
|
||||
@ -194,18 +96,19 @@ impl Transmitter
|
||||
let (audio_tx, audio_rx) = mpsc::channel::<Complex<f32>>();
|
||||
|
||||
let reverb_length = 20;
|
||||
// let (reverb, passband) = FirFilter::new(
|
||||
// passband,
|
||||
// Fir((0..reverb_length)
|
||||
// .map(|x| (-15. * (x as f32) / (reverb_length as f32)).exp())
|
||||
// .collect())
|
||||
// .normalized(),
|
||||
// );
|
||||
let (reverb, passband) = FirFilter::new(
|
||||
passband,
|
||||
Fir((0..reverb_length)
|
||||
.map(|x| (-15. * (x as f32) / (reverb_length as f32)).exp())
|
||||
.collect())
|
||||
.normalized(),
|
||||
);
|
||||
|
||||
let (udp_map, passband) = Scan::new(
|
||||
passband,
|
||||
UdpSocket::bind("127.0.0.1:25566").unwrap(),
|
||||
|sckt, sample| {
|
||||
std::thread::sleep(Duration::from_micros(20));
|
||||
sckt.send_to(
|
||||
&(sample.re + ((random::<f32>() * 2.) - 1.) * 0.0).to_le_bytes(),
|
||||
"127.0.0.1:25565",
|
||||
@ -219,7 +122,7 @@ impl Transmitter
|
||||
let graph = flowgraph![
|
||||
packet_rec,
|
||||
linearizer,
|
||||
//reverb,
|
||||
reverb,
|
||||
bit_filter,
|
||||
udp_map,
|
||||
to_freq,
|
||||
@ -250,7 +153,7 @@ impl Transmitter
|
||||
{
|
||||
if let Ok(y) = audio_rx.try_recv()
|
||||
{
|
||||
*x = y.re;
|
||||
*x = y.re * 0.01;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user