Iterate in blocks in Crisp
I want to add a wet-only version, and this can help reduce per-sample branching a bit.
This commit is contained in:
parent
5041f959b7
commit
9fc5b048ad
|
@ -29,6 +29,8 @@ mod pcg;
|
||||||
|
|
||||||
/// The number of channels we support. Hardcoded to allow for easier SIMD-ifying in the future.
|
/// The number of channels we support. Hardcoded to allow for easier SIMD-ifying in the future.
|
||||||
const NUM_CHANNELS: u32 = 2;
|
const NUM_CHANNELS: u32 = 2;
|
||||||
|
/// The number of channels to iterate over at a time.
|
||||||
|
const BLOCK_SIZE: usize = 64;
|
||||||
|
|
||||||
/// These seeds being fixed makes bouncing deterministic.
|
/// These seeds being fixed makes bouncing deterministic.
|
||||||
const INITIAL_PRNG_SEED: Pcg32iState = Pcg32iState::new(69, 420);
|
const INITIAL_PRNG_SEED: Pcg32iState = Pcg32iState::new(69, 420);
|
||||||
|
@ -339,9 +341,13 @@ impl Plugin for Crisp {
|
||||||
buffer: &mut Buffer,
|
buffer: &mut Buffer,
|
||||||
_context: &mut impl ProcessContext,
|
_context: &mut impl ProcessContext,
|
||||||
) -> ProcessStatus {
|
) -> ProcessStatus {
|
||||||
for channel_samples in buffer.iter_mut() {
|
for (_, mut block) in buffer.iter_blocks(BLOCK_SIZE) {
|
||||||
|
let mut rm_outputs = [[0.0; NUM_CHANNELS as usize]; BLOCK_SIZE];
|
||||||
|
|
||||||
|
// Reduce per-sample branching a bit by iterating over smaller blocks and only then
|
||||||
|
// deciding what to dowith the output
|
||||||
|
for (channel_samples, rm_outputs) in block.iter_samples().zip(&mut rm_outputs) {
|
||||||
let amount = self.params.amount.smoothed.next() * AMOUNT_GAIN_MULTIPLIER;
|
let amount = self.params.amount.smoothed.next() * AMOUNT_GAIN_MULTIPLIER;
|
||||||
let output_gain = self.params.output_gain.smoothed.next();
|
|
||||||
|
|
||||||
// Controls the pre-RM LPF and the HPF applied to the noise signal
|
// Controls the pre-RM LPF and the HPF applied to the noise signal
|
||||||
self.maybe_update_filters();
|
self.maybe_update_filters();
|
||||||
|
@ -352,21 +358,32 @@ impl Plugin for Crisp {
|
||||||
match self.params.stereo_mode.value() {
|
match self.params.stereo_mode.value() {
|
||||||
StereoMode::Mono => {
|
StereoMode::Mono => {
|
||||||
let noise = self.gen_noise(0);
|
let noise = self.gen_noise(0);
|
||||||
for (channel_idx, sample) in channel_samples.into_iter().enumerate() {
|
for (channel_idx, (sample, rm_output)) in
|
||||||
*sample += self.do_ring_mod(*sample, channel_idx, noise) * amount;
|
channel_samples.into_iter().zip(rm_outputs).enumerate()
|
||||||
*sample *= output_gain;
|
{
|
||||||
|
*rm_output = self.do_ring_mod(*sample, channel_idx, noise) * amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StereoMode::Stereo => {
|
StereoMode::Stereo => {
|
||||||
for (channel_idx, sample) in channel_samples.into_iter().enumerate() {
|
for (channel_idx, (sample, rm_output)) in
|
||||||
|
channel_samples.into_iter().zip(rm_outputs).enumerate()
|
||||||
|
{
|
||||||
let noise = self.gen_noise(channel_idx);
|
let noise = self.gen_noise(channel_idx);
|
||||||
*sample += self.do_ring_mod(*sample, channel_idx, noise) * amount;
|
*rm_output = self.do_ring_mod(*sample, channel_idx, noise) * amount;
|
||||||
*sample *= output_gain;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (channel_samples, rm_outputs) in block.iter_samples().zip(&mut rm_outputs) {
|
||||||
|
let output_gain = self.params.output_gain.smoothed.next();
|
||||||
|
|
||||||
|
for (sample, rm_output) in channel_samples.into_iter().zip(rm_outputs) {
|
||||||
|
*sample = (*sample + *rm_output) * output_gain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProcessStatus::Normal
|
ProcessStatus::Normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue