wip jack input
This commit is contained in:
parent
06ea05e112
commit
8be1d4b0df
3 changed files with 121 additions and 1 deletions
|
@ -9,6 +9,7 @@ softbuffer = "0.4.2"
|
||||||
cgmath = "*"
|
cgmath = "*"
|
||||||
prisma = "0.1.1"
|
prisma = "0.1.1"
|
||||||
angular-units = "*"
|
angular-units = "*"
|
||||||
|
jack = "0.11"
|
||||||
|
|
||||||
[dependencies.async-std]
|
[dependencies.async-std]
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
|
|
118
src/jack.rs
Normal file
118
src/jack.rs
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
use crate::Inputs;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
Arc<
|
||||||
|
dyn Fn(&jack::Client, &jack::ProcessScope) -> jack::Control
|
||||||
|
+ Send + Sync
|
||||||
|
>
|
||||||
|
let mut audio_val = Arc::new(RwLock::<f32>::new(0.0));
|
||||||
|
|
||||||
|
// Jack
|
||||||
|
// Create client
|
||||||
|
let (jack_client, _status) =
|
||||||
|
jack::Client::new("ledmatrix_visualizer", jack::ClientOptions::NO_START_SERVER).unwrap();
|
||||||
|
|
||||||
|
// Register ports. They will be used in a callback that will be
|
||||||
|
// called when new data is available.
|
||||||
|
let in_a = jack_client
|
||||||
|
.register_port("in", jack::AudioIn::default())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let av = audio_val.clone();
|
||||||
|
let process_callback = move |_: &jack::Client, ps: &jack::ProcessScope| -> jack::Control {
|
||||||
|
let in_a_p = in_a.as_slice(ps);
|
||||||
|
|
||||||
|
/* FFT
|
||||||
|
let mut input: Vec<Complex<f32>> = in_a_p.iter().map(|y| Complex::from(y)).collect::<Vec<Complex<f32>>>();
|
||||||
|
let fft = Radix4::new(input.len(), false);
|
||||||
|
fft.process(&mut input, &mut cur_spectrum.write().unwrap());
|
||||||
|
|
||||||
|
*v.get_mut() = in_a_p.iter().sum::<f32>() / 2048.0;
|
||||||
|
*/
|
||||||
|
|
||||||
|
let mut sum = 0.0 as f32;
|
||||||
|
let b = 0.025 as f32;
|
||||||
|
for i in 1 .. in_a_p.len() {
|
||||||
|
sum += (b * in_a_p[i] + (1.0 - b) * in_a_p[i-1]).abs()
|
||||||
|
}
|
||||||
|
|
||||||
|
*av.write().unwrap() = sum / in_a_p.len() as f32;
|
||||||
|
|
||||||
|
jack::Control::Continue
|
||||||
|
};
|
||||||
|
|
||||||
|
let process = jack::ClosureProcessHandler::new(process_callback);
|
||||||
|
|
||||||
|
// Activate the client, which starts the processing.
|
||||||
|
let active_client = jack_client.activate_async((), process).unwrap();
|
||||||
|
|
||||||
|
let mut stream : Option<TcpStream> = TcpStream::connect("192.168.4.1:6789").ok();
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub fn init_jack( inputs: Arc<RwLock< Inputs >> )
|
||||||
|
-> jack::AsyncClient<
|
||||||
|
(),
|
||||||
|
jack::ClosureProcessHandler<
|
||||||
|
Arc<
|
||||||
|
dyn FnMut(&jack::Client, &jack::ProcessScope) -> jack::Control
|
||||||
|
+ Send + Sync
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
{
|
||||||
|
// Jack
|
||||||
|
// Create client
|
||||||
|
let (jack_client, _status) =
|
||||||
|
jack::Client::new("FragmentalLightControl", jack::ClientOptions::NO_START_SERVER).unwrap();
|
||||||
|
|
||||||
|
// Register ports. They will be used in a callback that will be
|
||||||
|
// called when new data is available.
|
||||||
|
let in_a = jack_client
|
||||||
|
.register_port("in", jack::AudioIn::default())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let av = audio_val.clone();
|
||||||
|
|
||||||
|
let process_callback = move |_: &jack::Client, ps: &jack::ProcessScope| -> jack::Control {
|
||||||
|
let in_a_p = in_a.as_slice(ps);
|
||||||
|
|
||||||
|
/* FFT
|
||||||
|
let mut input: Vec<Complex<f32>> = in_a_p.iter().map(|y| Complex::from(y)).collect::<Vec<Complex<f32>>>();
|
||||||
|
let fft = Radix4::new(input.len(), false);
|
||||||
|
fft.process(&mut input, &mut cur_spectrum.write().unwrap());
|
||||||
|
|
||||||
|
*v.get_mut() = in_a_p.iter().sum::<f32>() / 2048.0;
|
||||||
|
*/
|
||||||
|
|
||||||
|
let mut sum = 0.0 as f32;
|
||||||
|
let b = 0.025 as f32;
|
||||||
|
for i in 1 .. in_a_p.len() {
|
||||||
|
sum += (b * in_a_p[i] + (1.0 - b) * in_a_p[i-1]).abs()
|
||||||
|
}
|
||||||
|
|
||||||
|
*av.write().unwrap() = sum / in_a_p.len() as f32;
|
||||||
|
|
||||||
|
jack::Control::Continue
|
||||||
|
};
|
||||||
|
|
||||||
|
let process = jack::ClosureProcessHandler::new(
|
||||||
|
|
||||||
|
Arc::new(process_callback) as
|
||||||
|
Arc<
|
||||||
|
dyn FnMut(&jack::Client, &jack::ProcessScope) -> jack::Control
|
||||||
|
+ Send + Sync
|
||||||
|
>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Activate the client, which starts the processing.
|
||||||
|
jack_client.activate_async((), process).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
|
@ -18,6 +18,7 @@ mod fixture;
|
||||||
mod setup;
|
mod setup;
|
||||||
mod view;
|
mod view;
|
||||||
mod stripe_driver;
|
mod stripe_driver;
|
||||||
|
mod jack;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
view::ColorGrid,
|
view::ColorGrid,
|
||||||
|
|
Loading…
Reference in a new issue