diff --git a/Cargo.lock b/Cargo.lock index a22f1162bf558f991bd714898b07f589e0a4db83..81e66c9bda3e8215d0d94627ae8f3f749ab603bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,6 +89,56 @@ dependencies = [ "syn", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "hashbrown" version = "0.11.2" @@ -121,6 +171,7 @@ dependencies = [ "clap", "jack", "libc", + "rayon", "rosc", ] @@ -179,6 +230,25 @@ dependencies = [ "winapi", ] +[[package]] +name = "memoffset" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "os_str_bytes" version = "3.1.0" @@ -233,6 +303,31 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + [[package]] name = "rosc" version = "0.5.2" @@ -242,6 +337,12 @@ dependencies = [ "byteorder", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index ca5d7456d736d8de16fc6c83cb666d7f55afd49a..c1091765cd06b087e987759eabb974cd5e0e8246 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,6 @@ description = "A 16×16 channel matrix mixer for Jack, controllable via OSC" jack = "0.7" libc = "0.2" rosc = "~0.5" +rayon ="1.5" arr_macro = "0.1.3" clap = { version = "3.0.0-beta.2", features = ["color", "suggestions"] } diff --git a/src/main.rs b/src/main.rs index da9e38b131077b7abcef5d4c421bb8bd218fc149..50b8ae7b3aaecbe26ee8e54c8740e24d082e5980 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use std::str::FromStr; use std::sync::atomic::{AtomicUsize, Ordering}; use arr_macro::arr; use clap::{Arg, App}; +use rayon::prelude::*; /* TODO: @@ -148,8 +149,7 @@ fn main() { let input_samples = inport.as_slice(ps); // Sum each input to output buffer - output_buffers.iter_mut() - .take(buffersize) + output_buffers.par_iter_mut() .enumerate() .filter(|(output_index, _buffer)| { match outputs[*output_index].connected_count() { @@ -158,7 +158,7 @@ fn main() { } }) .for_each(|(output_index, b)| { - b.iter_mut() + b.par_iter_mut() .take(buffersize) .enumerate() .for_each(|(sample_index, sample)| { @@ -199,7 +199,7 @@ fn main() { outputs.iter_mut() .enumerate() .for_each(|(output_index, outport)| { - outport.as_mut_slice(ps).clone_from_slice(&output_buffers[output_index]); + outport.as_mut_slice(ps).clone_from_slice(&output_buffers[output_index][..buffersize]); }); jack::Control::Continue }; @@ -337,8 +337,8 @@ impl jack::NotificationHandler for Notifications { // ); } - fn sample_rate(&mut self, _: &jack::Client, srate: jack::Frames) -> jack::Control { - println!("JACK: sample rate changed to {}", srate); + fn sample_rate(&mut self, _: &jack::Client, _srate: jack::Frames) -> jack::Control { + // println!("JACK: sample rate changed to {}", srate); jack::Control::Continue } @@ -401,13 +401,13 @@ impl jack::NotificationHandler for Notifications { jack::Control::Continue } - fn latency(&mut self, _: &jack::Client, mode: jack::LatencyType) { - println!( - "JACK: {} latency has changed", - match mode { - jack::LatencyType::Capture => "capture", - jack::LatencyType::Playback => "playback", - } - ); + fn latency(&mut self, _: &jack::Client, _mode: jack::LatencyType) { + // println!( + // "JACK: {} latency has changed", + // match mode { + // jack::LatencyType::Capture => "capture", + // jack::LatencyType::Playback => "playback", + // } + // ); } } \ No newline at end of file