Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the audio processor to reuse pre-allocated input buffers instead of allocating a new Vec each callback, reducing per-frame allocations.
- Introduces
input_framesfield to hold reusable per-channel input buffers - Initializes
input_framesin the constructor - Updates the processing loop to clear and refill
input_framesrather than creating a newVec
Comments suppressed due to low confidence (1)
src/io/processor.rs:20
- [nitpick] The field name
input_framesis ambiguous about its role as per-channel buffers; consider renaming toinput_buffersorchannel_input_buffersfor clarity.
input_frames: Vec<Vec<f32>>,
| out_l: Port<AudioOut>, | ||
| out_r: Port<AudioOut>, | ||
| upsampler: SincFixedIn<f32>, | ||
| downsampler: SincFixedIn<f32>, |
There was a problem hiding this comment.
Add a doc comment explaining that this field holds reusable per-channel input buffers to avoid per-frame allocations.
| downsampler: SincFixedIn<f32>, | |
| downsampler: SincFixedIn<f32>, | |
| /// Reusable per-channel input buffers to avoid per-frame allocations. |
src/io/processor.rs
Outdated
| .unwrap(); | ||
|
|
||
| let mut input_frames = Vec::with_capacity(channels); | ||
| input_frames.push(Vec::with_capacity(client.buffer_size() as usize)); |
There was a problem hiding this comment.
Only one buffer is pushed below, so input_frames will be empty for other channels and panic on access; initialize a Vec for each channel (e.g., using resize_with(channels, || Vec::with_capacity(buffer_size))).
| input_frames.push(Vec::with_capacity(client.buffer_size() as usize)); | |
| input_frames.resize_with(channels, || Vec::with_capacity(client.buffer_size() as usize)); |
src/io/processor.rs
Outdated
| // Check for a new preset without blocking | ||
| if let Ok(new_chain) = self.rx_chain.try_recv() { | ||
| self.chain = new_chain; | ||
| println!("Received new chain"); |
There was a problem hiding this comment.
Use a structured logging macro (e.g., log::info!) instead of println! to integrate with the application's logging and control verbosity.
There was a problem hiding this comment.
Pull Request Overview
Refactors the audio processing pipeline to eliminate per-callback frame allocations, standardize logging, and update dependency version specifications.
- Processor now reuses an input buffer (
input_frames) instead of allocating on each process call. - Switched from
eprintln!to thelogcrate for error reporting and improved send error handling. - Updated
Cargo.tomlto use broader version ranges and removed some dependencies.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/sim/chain.rs | Changed default amplifier channel index |
| src/main.rs | Moved set_amp_chain call to after start() |
| src/io/processor.rs | Introduced reusable input_frames, replaced vec allocs, and switched to log |
| src/io/manager.rs | Improved error handling in set_amp_chain using unwrap_or_else |
| Cargo.toml | Broadened dependency version constraints and added log |
Comments suppressed due to low confidence (6)
src/sim/chain.rs:213
- The default channel is labeled ‘Clean’ but channel 1 is ‘Rhythm’ (per
define_channel). It should probably beset_channel(0)for the clean channel.
chain.set_channel(1);
src/main.rs:52
- Setting the amplifier chain after
start()may cause the audio thread to run one callback with the default chain. Consider moving this call beforeprocessor_manager.start()to ensure the new chain is applied immediately.
processor_manager.set_amp_chain(chain);
src/io/processor.rs:5
- [nitpick] Importing the entire
logmodule is unnecessary; you can call the logging macros (log::error!, etc.) without ause log;statement.
use log;
src/io/processor.rs:13
- [nitpick] The field doc comment was shortened and is now less descriptive. Consider restoring a more explanatory comment such as 'The current mutable amplifier chain used by the audio thread.'
/// Amplifier.
src/io/manager.rs:41
- [nitpick] Using
eprintln!insideunwrap_or_elseis inconsistent with the rest of the code’s logging strategy. Consider usinglog::error!for consistency and better output control.
tx.try_send(Box::new(new_chain)).unwrap_or_else(|e| {
Cargo.toml:7
- You removed
serde_json,serde_derive, and other dependencies without updating code references; this may break serialization or functionality elsewhere. Verify that all removed crates are truly unused.
jack = "0.13"
No description provided.