Skip to content

Commit

Permalink
fix clippy issues + clean for releasing first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Dec 5, 2024
1 parent a144d9b commit 4754c00
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/node/convolver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::any::Any;
// use std::sync::Arc;

// use realfft::{num_complex::Complex, ComplexToReal, RealFftPlanner, RealToComplex};
use fft_convolver::FFTConvolver;

use crate::buffer::AudioBuffer;
Expand Down Expand Up @@ -283,16 +281,19 @@ impl ConvolverNode {
};

let mut convolvers = Vec::<FFTConvolver<f32>>::new();
// Size of the partition changes a lot the perf...
// - RENDER_QUANTUM_SIZE -> 20x (compared to real-time)
// - RENDER_QUANTUM_SIZE * 8 -> 134x
// @note - value defined by "rule of thumb", to be explored further
let partition_size = RENDER_QUANTUM_SIZE * 8;
// @todo - implement multichannel
// cf. https://webaudio.github.io/web-audio-api/#Convolution-channel-configurations
let num_convolvers = 1;

for index in 0..num_convolvers {
let channel = std::cmp::min(buffer.number_of_channels(), index);

[0..buffer.number_of_channels()].iter().for_each(|_| {
let mut scaled_channel = vec![0.; buffer.length()];
scaled_channel
.iter_mut()
.zip(buffer.get_channel_data(0))
.zip(buffer.get_channel_data(channel))
.for_each(|(o, i)| *o = *i * scale);

let mut convolver = FFTConvolver::<f32>::default();
Expand All @@ -301,7 +302,7 @@ impl ConvolverNode {
.expect("Unable to initialize convolution engine");

convolvers.push(convolver);
});
}

let msg = ConvolverInfosMessage {
convolvers: Some(convolvers),
Expand Down Expand Up @@ -345,7 +346,7 @@ impl AudioProcessor for ConvolverRenderer {
// single input/output node
let input = &inputs[0];
let output = &mut outputs[0];
output.force_mono();
output.make_silent();

let convolvers = match &mut self.convolvers {
None => {
Expand All @@ -360,19 +361,14 @@ impl AudioProcessor for ConvolverRenderer {
let mut mono = input.clone();
mono.mix(1, ChannelInterpretation::Speakers);

// let input = &mono.channel_data(0)[..];
// let output = &mut output.channel_data_mut(0)[..];
let _ = convolvers[0].process(&mono.channel_data(0), &mut output.channel_data_mut(0));
let i = &mono.channel_data(0)[..];
let o = &mut output.channel_data_mut(0)[..];
let _ = convolvers[0].process(i, o);

// handle tail time
if input.is_silent() {
self.tail_count += RENDER_QUANTUM_SIZE;

if self.tail_count >= self.impulse_length {
return false;
} else {
return true
}
return self.tail_count < self.impulse_length;
}

self.tail_count = 0;
Expand Down

0 comments on commit 4754c00

Please sign in to comment.