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:
parent
cd70cb5c78
commit
00bcaf7685
15
Cargo.lock
generated
15
Cargo.lock
generated
@ -101,6 +101,7 @@ dependencies = [
|
|||||||
name = "audio-reactive-source"
|
name = "audio-reactive-source"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bytemuck",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"cpal",
|
"cpal",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
@ -171,6 +172,20 @@ name = "bytemuck"
|
|||||||
version = "1.21.0"
|
version = "1.21.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3"
|
checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3"
|
||||||
|
dependencies = [
|
||||||
|
"bytemuck_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytemuck_derive"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bcfcc3cd946cb52f0bbfdbbcfa2f4e24f75ebb6c0e1002f7c25904fada18b9ec"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
|
@ -15,4 +15,6 @@ color-eyre = "0.6"
|
|||||||
cpal = { version = "0.15", features = ["jack"] }
|
cpal = { version = "0.15", features = ["jack"] }
|
||||||
realfft = "3.4"
|
realfft = "3.4"
|
||||||
|
|
||||||
|
bytemuck = { version = "1.21", features = ["derive"] }
|
||||||
|
|
||||||
textplots = "0.8"
|
textplots = "0.8"
|
||||||
|
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 color_eyre::eyre::{bail, Result};
|
||||||
use cpal::{
|
use cpal::{
|
||||||
traits::{DeviceTrait, HostTrait, StreamTrait},
|
traits::{DeviceTrait, HostTrait, StreamTrait},
|
||||||
@ -72,6 +73,8 @@ fn main() -> color_eyre::Result<()> {
|
|||||||
None,
|
None,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let socket = UdpSocket::bind("239.0.0.1:11988")?;
|
||||||
|
|
||||||
stream.play()?;
|
stream.play()?;
|
||||||
|
|
||||||
let mut previous_sample_smth = 0.0;
|
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);
|
data.sample_smth = 0.8f32.mul_add(previous_sample_smth, 0.2 * data.sample_raw);
|
||||||
previous_sample_smth = data.sample_smth;
|
previous_sample_smth = data.sample_smth;
|
||||||
|
|
||||||
let plot_data: Vec<_> = data
|
if let Err(e) = socket.send_to(bytemuck::bytes_of(&data), "239.0.0.1:11988") {
|
||||||
.fft_result
|
error!("Unable to send packet over multicast: {e}");
|
||||||
.iter()
|
}
|
||||||
.enumerate()
|
|
||||||
.map(|(i, datum)| (i as f32, f32::from(*datum)))
|
// let plot_data: Vec<_> = data
|
||||||
.collect();
|
// .fft_result
|
||||||
Chart::new_with_y_range(250, 50, 0.0, 16.0, 0.0, 255.0)
|
// .iter()
|
||||||
.lineplot(&Shape::Bars(&plot_data[..]))
|
// .enumerate()
|
||||||
.display();
|
// .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
|
/// new "V2" audiosync struct - 44 Bytes
|
||||||
|
#[derive(Debug, PartialEq, Clone, Copy, Pod, Zeroable)]
|
||||||
#[repr(C, packed(1))]
|
#[repr(C, packed(1))]
|
||||||
struct AudioSyncPacket {
|
struct AudioSyncPacket {
|
||||||
/// "00002" for protocol version 2 (includes '\0' for c-style string termination)
|
/// "00002" for protocol version 2 (includes '\0' for c-style string termination)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user