send multicast packets
All checks were successful
Build legacy Nix package on Ubuntu / build (push) Successful in 4m31s
All checks were successful
Build legacy Nix package on Ubuntu / build (push) Successful in 4m31s
This commit is contained in:
28
src/main.rs
28
src/main.rs
@ -1,5 +1,6 @@
|
||||
use std::{cmp::Ordering, sync::mpsc, thread::sleep, time::Duration};
|
||||
use std::{cmp::Ordering, net::UdpSocket, sync::mpsc, thread::sleep, time::Duration};
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use color_eyre::eyre::{bail, Result};
|
||||
use cpal::{
|
||||
traits::{DeviceTrait, HostTrait, StreamTrait},
|
||||
@ -72,6 +73,8 @@ fn main() -> color_eyre::Result<()> {
|
||||
None,
|
||||
)?;
|
||||
|
||||
let socket = UdpSocket::bind("239.0.0.1:11988")?;
|
||||
|
||||
stream.play()?;
|
||||
|
||||
let mut previous_sample_smth = 0.0;
|
||||
@ -80,19 +83,24 @@ fn main() -> color_eyre::Result<()> {
|
||||
data.sample_smth = 0.8f32.mul_add(previous_sample_smth, 0.2 * data.sample_raw);
|
||||
previous_sample_smth = data.sample_smth;
|
||||
|
||||
let plot_data: Vec<_> = data
|
||||
.fft_result
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, datum)| (i as f32, f32::from(*datum)))
|
||||
.collect();
|
||||
Chart::new_with_y_range(250, 50, 0.0, 16.0, 0.0, 255.0)
|
||||
.lineplot(&Shape::Bars(&plot_data[..]))
|
||||
.display();
|
||||
if let Err(e) = socket.send_to(bytemuck::bytes_of(&data), "239.0.0.1:11988") {
|
||||
error!("Unable to send packet over multicast: {e}");
|
||||
}
|
||||
|
||||
// let plot_data: Vec<_> = data
|
||||
// .fft_result
|
||||
// .iter()
|
||||
// .enumerate()
|
||||
// .map(|(i, datum)| (i as f32, f32::from(*datum)))
|
||||
// .collect();
|
||||
// Chart::new_with_y_range(250, 50, 0.0, 16.0, 0.0, 255.0)
|
||||
// .lineplot(&Shape::Bars(&plot_data[..]))
|
||||
// .display();
|
||||
}
|
||||
}
|
||||
|
||||
/// new "V2" audiosync struct - 44 Bytes
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Pod, Zeroable)]
|
||||
#[repr(C, packed(1))]
|
||||
struct AudioSyncPacket {
|
||||
/// "00002" for protocol version 2 (includes '\0' for c-style string termination)
|
||||
|
Reference in New Issue
Block a user