From f922e668b7e8a01e1294fd802b757f776bc454b8 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 5 Apr 2023 19:52:09 +0200 Subject: [PATCH] Add an upsampling-only option to the oversamplers This will be used to upsample the slew control signal. --- plugins/aw_soft_vacuum/src/oversampling.rs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugins/aw_soft_vacuum/src/oversampling.rs b/plugins/aw_soft_vacuum/src/oversampling.rs index c00435a5..a63c9da6 100644 --- a/plugins/aw_soft_vacuum/src/oversampling.rs +++ b/plugins/aw_soft_vacuum/src/oversampling.rs @@ -184,6 +184,29 @@ impl Lanczos3Oversampler { self.downsample_to(block, factor) } + /// An upsample-only version of `process` that returns the upsampled version of the signal that + /// would normally be passed to `process`'s callback. Useful for upsampling control signals. + /// + /// # Panics + /// + /// Panics if `factor > max_factor`, or if `block`'s length is longer than the maximum block + /// size. + pub fn upsample_only<'a>(&'a mut self, block: &'a mut [f32], factor: usize) -> &'a mut [f32] { + assert!(factor <= self.stages.len()); + + // This is the 1x oversampling case, this should also modify the block to be consistent + if factor == 0 { + return block; + } + + assert!( + block.len() <= self.stages[0].scratch_buffer.len() / 2, + "The block's size exceeds the maximum block size" + ); + + self.upsample_from(block, factor) + } + /// Upsample `block` through `factor` oversampling stages. Returns a reference to the /// oversampled output stored in the last `LancZos3Stage`'s scratch buffer **with the correct /// length**. This is a multiple of `block`'s length, which may be shorter than the entire