diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2e7b3cb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.cargo.features": ["tracing"] +} diff --git a/Cargo.lock b/Cargo.lock index 14b5c65..5c19a7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1421,6 +1421,27 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", + "unicode-xid", +] + [[package]] name = "digest" version = "0.10.7" @@ -1772,6 +1793,19 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "generator" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6bd114ceda131d3b1d665eba35788690ad37f5916457286b32ab6fd3c438dd" +dependencies = [ + "cfg-if", + "libc", + "log", + "rustversion", + "windows 0.58.0", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -2283,6 +2317,19 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "loom" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" +dependencies = [ + "cfg-if", + "generator", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + [[package]] name = "lru" version = "0.10.1" @@ -2307,6 +2354,15 @@ dependencies = [ "libc", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matches" version = "0.1.10" @@ -2483,7 +2539,6 @@ dependencies = [ [[package]] name = "nih_plug" version = "0.0.0" -source = "git+https://github.com/robbert-vdh/nih-plug.git#40269e13940689c6b5432cc16782964ae33f3d12" dependencies = [ "anyhow", "anymap", @@ -2525,7 +2580,6 @@ source = "git+https://github.com/robbert-vdh/nih_plug_assets.git#a04e327923e120b [[package]] name = "nih_plug_derive" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/nih-plug.git#40269e13940689c6b5432cc16782964ae33f3d12" dependencies = [ "proc-macro2", "quote", @@ -2535,7 +2589,6 @@ dependencies = [ [[package]] name = "nih_plug_vizia" version = "0.0.0" -source = "git+https://github.com/robbert-vdh/nih-plug.git#40269e13940689c6b5432cc16782964ae33f3d12" dependencies = [ "baseview 0.1.0 (git+https://github.com/RustAudio/baseview.git?rev=2c1b1a7b0fef1a29a5150a6a8f6fef6a0cbab8c4)", "crossbeam", @@ -2548,7 +2601,6 @@ dependencies = [ [[package]] name = "nih_plug_xtask" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/nih-plug.git#40269e13940689c6b5432cc16782964ae33f3d12" dependencies = [ "anyhow", "cargo_metadata", @@ -2605,6 +2657,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-complex" version = "0.4.6" @@ -2839,6 +2901,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking" version = "2.2.1" @@ -3302,6 +3370,15 @@ dependencies = [ "regex-syntax 0.8.5", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + [[package]] name = "regex-automata" version = "0.3.9" @@ -3324,6 +3401,12 @@ dependencies = [ "regex-syntax 0.8.5", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.7.5" @@ -3417,6 +3500,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + [[package]] name = "rusty-fork" version = "0.3.0" @@ -3461,6 +3550,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.2.0" @@ -3494,7 +3589,7 @@ source = "git+https://github.com/robbert-vdh/vizia.git?tag=patched-2024-05-06#e3 dependencies = [ "bitflags 1.3.2", "cssparser", - "derive_more", + "derive_more 0.99.18", "fxhash", "log", "phf 0.8.0", @@ -3590,6 +3685,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -3812,6 +3916,16 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "time" version = "0.3.37" @@ -3932,6 +4046,68 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "tracing-tracy" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc775fdaf33c3dfd19dc354729e65e87914bc67dcdc390ca1210807b8bee5902" +dependencies = [ + "tracing-core", + "tracing-subscriber", + "tracy-client", +] + +[[package]] +name = "tracy-client" +version = "0.17.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73202d787346a5418f8222eddb5a00f29ea47caf3c7d38a8f2f69f8455fa7c7e" +dependencies = [ + "loom", + "once_cell", + "tracy-client-sys", +] + +[[package]] +name = "tracy-client-sys" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69fff37da548239c3bf9e64a12193d261e8b22b660991c6fd2df057c168f435f" +dependencies = [ + "cc", + "windows-targets 0.52.6", ] [[package]] @@ -4094,6 +4270,12 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "utf8parse" version = "0.2.2" @@ -4109,6 +4291,12 @@ dependencies = [ "getrandom 0.2.15", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "variantly" version = "0.4.0" @@ -4275,6 +4463,8 @@ dependencies = [ "proptest", "proptest-derive", "rustfft", + "tracing", + "tracy-client", ] [[package]] @@ -4283,11 +4473,16 @@ version = "0.1.0" dependencies = [ "atomic_float 1.1.0", "dasp", + "derive_more 1.0.0", "drawille", "itertools", "lang", "nih_plug", "nih_plug_vizia", + "tracing", + "tracing-subscriber", + "tracing-tracy", + "tracy-client", "triple_buffer", "vm", ] @@ -4530,8 +4725,8 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-implement", - "windows-interface", + "windows-implement 0.48.0", + "windows-interface 0.48.0", "windows-targets 0.48.5", ] @@ -4545,6 +4740,16 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -4560,7 +4765,20 @@ version = "0.54.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" dependencies = [ - "windows-result", + "windows-result 0.1.2", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement 0.58.0", + "windows-interface 0.58.0", + "windows-result 0.2.0", + "windows-strings", "windows-targets 0.52.6", ] @@ -4575,6 +4793,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "windows-interface" version = "0.48.0" @@ -4586,6 +4815,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "windows-result" version = "0.1.2" @@ -4595,6 +4835,25 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result 0.2.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.45.0" diff --git a/Cargo.toml b/Cargo.toml index ed2e70e..f6b1c5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ drawille = "0.3.0" lang = { version = "0.1.0", path = "lang" } # Remove the `assert_process_allocs` feature to allow allocations on the audio # thread in debug builds. -nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", features = ["assert_process_allocs", "standalone"] } -nih_plug_vizia = { git = "https://github.com/robbert-vdh/nih-plug.git" } +nih_plug = { path = "../nih-plug", features = ["assert_process_allocs", "standalone", "vst3"], default-features = false } +nih_plug_vizia = { path = "../nih-plug/nih_plug_vizia" } triple_buffer = "8.0.0" # Uncomment the below line to disable the on-by-default VST3 feature to remove # the GPL compatibility requirement @@ -28,9 +28,22 @@ triple_buffer = "8.0.0" vm = {path = "./vm"} dasp = { workspace = true } itertools = "0.13.0" +tracing = { workspace = true } +tracing-subscriber = { workspace = true, optional = true } +tracing-tracy = { workspace = true, optional = true } +tracy-client = { workspace = true, optional = true } +derive_more = { version = "1.0.0", features = ["debug"] } + +[features] +tracing = ["dep:tracing-subscriber", "dep:tracing-tracy", "dep:tracy-client", "vm/tracing" ] + [workspace.dependencies] dasp = { version = "0.11.0", features = [ "all" ] } +tracing = { version = "0.1.41" } +tracing-subscriber = { version = "0.3.19"} +tracing-tracy = { version = "0.11.3"} +tracy-client = {version = "0.17.6" } [profile.release] lto = "thin" diff --git a/Justfile b/Justfile index ac62c86..cbf6c4e 100644 --- a/Justfile +++ b/Justfile @@ -1,7 +1,12 @@ -bundle: - cargo xtask bundle-universal vm_glitch --release - just install +bundle *CARGO_ARGS: && install + @echo "Pass '-F tracing' to bundle with tracing enabled" + cargo xtask bundle-universal vm_glitch --release {{CARGO_ARGS}} install: rm -rf ~/Library/Audio/Plug-Ins/VST3/VM\ Glitch.vst3 - cp -r target/bundled/VM\ Glitch.vst3 ~/Library/Audio/Plug-Ins/VST3/ \ No newline at end of file + cp -r target/bundled/VM\ Glitch.vst3 ~/Library/Audio/Plug-Ins/VST3/ + +trace: + @echo "Starting the profiler frontend." + @echo "Make sure you bundle with 'just bundle -F tracing', then connect the frontend to localhost." + tracy || (brew install tracy && tracy) \ No newline at end of file diff --git a/src/delay_buffer.rs b/src/delay_buffer.rs index e7d73fb..b2a56bd 100644 --- a/src/delay_buffer.rs +++ b/src/delay_buffer.rs @@ -2,6 +2,7 @@ use dasp::ring_buffer::Fixed; use dasp::*; use nih_plug::buffer::Buffer; +#[derive(Debug)] pub struct DelayBuffer { pub buffer: Fixed>, } @@ -15,6 +16,8 @@ impl DelayBuffer { /// Push incoming samples to the back of the buffer pub fn ingest_audio(&mut self, audio: &mut Buffer) { + #[cfg(feature = "tracing")] + let _span = tracy_client::span!("delay buffer: Ingest new audio samples"); let audio = audio.as_slice(); for (left, right) in audio[0].iter().zip(audio[1].iter()) { self.buffer.push([*left, *right]); @@ -23,6 +26,8 @@ impl DelayBuffer { /// Copy front to the audio buffer pub fn write_to_audio(&self, audio: &mut Buffer) { + #[cfg(feature = "tracing")] + let _span = tracy_client::span!("delay buffer: Fill audio buffer with output"); for (frame, mut chan_iter) in self.buffer.iter().zip(audio.iter_samples()) { *chan_iter.get_mut(0).unwrap() = frame[0]; *chan_iter.get_mut(1).unwrap() = frame[1]; diff --git a/src/editor.rs b/src/editor.rs index 22ba310..3552ea1 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -9,6 +9,7 @@ use crate::analyzer::AnalyzerView; use crate::logo::Logo; use crate::VmGlitchParams; use lang::*; +use tracing::{instrument, trace}; use triple_buffer::{Input, Output}; #[derive(Lens)] @@ -21,6 +22,7 @@ struct Data { } impl Model for Data { + #[instrument(skip(self, cx, event))] fn event(&mut self, cx: &mut EventContext, event: &mut Event) { event.map(|app_event, meta| match app_event { AppEvent::Edit(s) => { @@ -52,9 +54,10 @@ impl Model for Data { }; { let mut guard = self.to_vm_buffer.lock().unwrap(); - guard.input_buffer().copy_from_slice(&bytecode); - guard.publish(); + trace!("->audio: publish bytecode"); + guard.write(bytecode); } + trace!("->audio: set dirty for bytecode"); self.dirty.store(true, Ordering::Release); } Err(errs) => { diff --git a/src/lib.rs b/src/lib.rs index fb53609..4e0da89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,8 @@ mod analyzer; mod delay_buffer; mod editor; mod logo; +#[cfg(feature = "tracing")] +mod trace; use delay_buffer::DelayBuffer; use nih_plug::prelude::*; use nih_plug_vizia::ViziaState; @@ -12,6 +14,7 @@ use std::{ }, vec, }; +use tracing::{instrument, trace}; use triple_buffer::{triple_buffer, Input, Output}; use vm::Vm; @@ -19,7 +22,9 @@ use vm::Vm; // https://github.com/robbert-vdh/nih-plug/blob/master/plugins/examples/gain/src/lib.rs to get // started +#[derive(derive_more::Debug)] pub struct VmGlitch { + #[debug(ignore)] params: Arc, vm: Vm, to_ui_buffer: (Input>, Option>>), @@ -46,9 +51,12 @@ pub struct VmGlitchParams { impl Default for VmGlitch { fn default() -> Self { - let vm = Vm::default(); let to_ui = triple_buffer(&vec![0; 512]); let from_ui = triple_buffer(&vec![0; 512]); + + #[cfg(feature = "tracing")] + trace::setup(); + Self { params: Arc::new(VmGlitchParams::default()), vm: Vm::default(), @@ -152,19 +160,21 @@ impl Plugin for VmGlitch { // allocate. You can remove this function if you do not need it. } + #[instrument(skip(self, buffer, _aux, _context))] fn process( &mut self, buffer: &mut Buffer, _aux: &mut AuxiliaryBuffers, _context: &mut impl ProcessContext, ) -> ProcessStatus { - let samples = buffer.samples(); // TODO decide whether to just get updates from the UI thread periodically, e.g. every X calls. // Would be less complex, though it would mean the bytecode gets reset regardless of whether the user edited it. + if let Ok(true) = self.dirty .compare_exchange(true, false, Ordering::AcqRel, Ordering::Acquire) { + trace!("UI->audio bytecode update"); let updated_bytecode = self.from_ui_buffer.1.read(); // copy the user's new bytecode without publishing back to the UI thread yet. self.to_ui_buffer @@ -182,8 +192,12 @@ impl Plugin for VmGlitch { self.delay_buffer.write_to_audio(buffer); + trace!("audio->UI bytecode update"); self.to_ui_buffer.0.publish(); + #[cfg(feature = "tracing")] + tracy_client::Client::running().unwrap().frame_mark(); + ProcessStatus::Normal } diff --git a/src/trace.rs b/src/trace.rs new file mode 100644 index 0000000..234e18e --- /dev/null +++ b/src/trace.rs @@ -0,0 +1,12 @@ +use tracing::{level_filters::LevelFilter, subscriber::DefaultGuard, Level}; +use tracing_subscriber::Layer; +use {tracing_subscriber::layer::SubscriberExt, tracing_subscriber::util::SubscriberInitExt}; + +pub fn setup() { + let tracy_layer = tracing_tracy::TracyLayer::default(); + let fmt = tracing_subscriber::fmt::layer().with_filter(LevelFilter::DEBUG); + tracing_subscriber::registry() + .with(fmt) + .with(tracy_layer) + .init(); +} diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 3de0ecb..3aed946 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -8,6 +8,11 @@ dasp = { workspace = true } itertools = "0.13.0" numquant = "0.2.0" rustfft = "6.2.0" +tracing = { workspace = true } +tracy-client = { workspace = true, optional = true } + +[features] +tracing = ["dep:tracy-client"] [dev-dependencies] proptest = "1.6.0" diff --git a/vm/src/lib.rs b/vm/src/lib.rs index ee3f987..c1e4553 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -3,6 +3,7 @@ use dasp::*; use numquant::linear; use op::{Op, Opcode}; use ring_buffer::Fixed; +use tracing::{debug, instrument, trace}; pub type RawBuffer<'a> = &'a mut Fixed>; @@ -42,7 +43,15 @@ impl Vm { } } + #[instrument(skip(self, bytecode, buf))] fn step(&mut self, bytecode: &mut [u8], buf: RawBuffer) { + #[cfg(feature = "tracing")] + { + tracy_client::plot!("PC", self.pc as f64); + tracy_client::plot!("buf_idx", self.buf_index as f64); + tracy_client::plot!("total_for_run", self.total_for_run as f64); + } + let op = self.parse_op(bytecode, REGISTER_COUNT); if let Some(op) = op { self.run_op(op, bytecode, buf); @@ -58,6 +67,7 @@ impl Vm { } /// Parses the current [Op] and its args + #[instrument(skip(self, bytecode))] fn parse_op(&mut self, bytecode: &mut [u8], registers: usize) -> Option { let byte = *bytecode.get(self.pc)?; if byte == Opcode::Copy as u8 || byte == Opcode::Swap as u8 { @@ -65,8 +75,10 @@ impl Vm { self.pc += 1; let j = *bytecode.get(self.pc + 1)? as usize; self.pc += 1; - - if i >= registers || j >= registers { return None; } + + if i >= registers || j >= registers { + return None; + } if byte == Opcode::Swap as u8 { return Some(Op::Swap(i, j)); @@ -89,6 +101,7 @@ impl Vm { None } + #[instrument(skip(self, bytecode, buf))] fn run_op(&mut self, op: Op, bytecode: &mut [u8], buf: RawBuffer) { let chunk_size_audio = buf.len() / REGISTER_COUNT; let chunk_size_bytecode = bytecode.len() / REGISTER_COUNT; @@ -101,6 +114,9 @@ impl Vm { let to_frame = buf.get_mut((to_idx * chunk_size_audio) + i); to_frame[0] = from_frame[0]; to_frame[1] = from_frame[1]; + + #[cfg(feature = "tracing")] + tracy_client::plot!("Op::Copy", 1.0); } let chunk_start = from_idx * chunk_size_bytecode; @@ -109,13 +125,17 @@ impl Vm { } Op::Jump(i) => { self.pc = i; + #[cfg(feature = "tracing")] + tracy_client::plot!("Op::Jump", 1.0); } Op::Sample(i) => { let frame = buf.get(i); let mut sample = frame[0] + frame[1]; sample /= buf.len() as f32; bytecode[self.pc] = linear::quantize(sample as f64, -1.0..1.0, 255); - }, + #[cfg(feature = "tracing")] + tracy_client::plot!("Op::Sample", 1.0); + } Op::Swap(i, j) => { for offset in 0..chunk_size_audio { let j_frame = *buf.get((j * chunk_size_audio) + offset); @@ -127,10 +147,15 @@ impl Vm { j_frame[0] = i_backup[0]; j_frame[1] = i_backup[1]; } - + for offset in 0..chunk_size_bytecode { - bytecode.swap((i * chunk_size_bytecode) + offset, (j * chunk_size_bytecode) + offset); + bytecode.swap( + (i * chunk_size_bytecode) + offset, + (j * chunk_size_bytecode) + offset, + ); } + #[cfg(feature = "tracing")] + tracy_client::plot!("Op::Swap", 1.0); } _ => {} } diff --git a/vm/src/op.rs b/vm/src/op.rs index 7c22027..8e9db24 100644 --- a/vm/src/op.rs +++ b/vm/src/op.rs @@ -10,14 +10,15 @@ pub enum Opcode { Jump, /// Copy sample `i` from the audio buffer into the bytecode. If there are multiple channels this will be the product. Sample, - /// Swap chunk `i` and `j` in the audio buffer and byte `i` for `j` in the bytecode. + /// Swap chunk `i` and `j` in the audio buffer and byte `i` for `j` in the bytecode. Swap, } +#[derive(Debug)] pub enum Op { Copy(usize, usize), Flip(usize), Jump(usize), Sample(usize), - Swap(usize, usize) + Swap(usize, usize), } diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 6ea187b..595ff9c 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] -nih_plug_xtask = { git = "https://github.com/robbert-vdh/nih-plug.git" } +nih_plug_xtask = { path = "../../nih-plug/nih_plug_xtask" }