Skip to content

Commit 4754c00

Browse files
committed
fix clippy issues + clean for releasing first pass
1 parent a144d9b commit 4754c00

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/node/convolver.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::any::Any;
2-
// use std::sync::Arc;
32

4-
// use realfft::{num_complex::Complex, ComplexToReal, RealFftPlanner, RealToComplex};
53
use fft_convolver::FFTConvolver;
64

75
use crate::buffer::AudioBuffer;
@@ -283,16 +281,19 @@ impl ConvolverNode {
283281
};
284282

285283
let mut convolvers = Vec::<FFTConvolver<f32>>::new();
286-
// Size of the partition changes a lot the perf...
287-
// - RENDER_QUANTUM_SIZE -> 20x (compared to real-time)
288-
// - RENDER_QUANTUM_SIZE * 8 -> 134x
284+
// @note - value defined by "rule of thumb", to be explored further
289285
let partition_size = RENDER_QUANTUM_SIZE * 8;
286+
// @todo - implement multichannel
287+
// cf. https://webaudio.github.io/web-audio-api/#Convolution-channel-configurations
288+
let num_convolvers = 1;
289+
290+
for index in 0..num_convolvers {
291+
let channel = std::cmp::min(buffer.number_of_channels(), index);
290292

291-
[0..buffer.number_of_channels()].iter().for_each(|_| {
292293
let mut scaled_channel = vec![0.; buffer.length()];
293294
scaled_channel
294295
.iter_mut()
295-
.zip(buffer.get_channel_data(0))
296+
.zip(buffer.get_channel_data(channel))
296297
.for_each(|(o, i)| *o = *i * scale);
297298

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

303304
convolvers.push(convolver);
304-
});
305+
}
305306

306307
let msg = ConvolverInfosMessage {
307308
convolvers: Some(convolvers),
@@ -345,7 +346,7 @@ impl AudioProcessor for ConvolverRenderer {
345346
// single input/output node
346347
let input = &inputs[0];
347348
let output = &mut outputs[0];
348-
output.force_mono();
349+
output.make_silent();
349350

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

363-
// let input = &mono.channel_data(0)[..];
364-
// let output = &mut output.channel_data_mut(0)[..];
365-
let _ = convolvers[0].process(&mono.channel_data(0), &mut output.channel_data_mut(0));
364+
let i = &mono.channel_data(0)[..];
365+
let o = &mut output.channel_data_mut(0)[..];
366+
let _ = convolvers[0].process(i, o);
366367

367368
// handle tail time
368369
if input.is_silent() {
369370
self.tail_count += RENDER_QUANTUM_SIZE;
370-
371-
if self.tail_count >= self.impulse_length {
372-
return false;
373-
} else {
374-
return true
375-
}
371+
return self.tail_count < self.impulse_length;
376372
}
377373

378374
self.tail_count = 0;

0 commit comments

Comments
 (0)