pub struct BypassHandler { /* private fields */ }Expand description
Utility for handling bypass with smooth crossfading.
Maintains bypass state and provides automatic crossfade between wet (processed) and dry (passthrough) signals when bypass is toggled.
§Usage Pattern
match self.bypass_handler.begin(is_bypassed) {
BypassAction::Passthrough => buffer.copy_to_output(),
BypassAction::Process => self.process_dsp(buffer),
BypassAction::ProcessAndCrossfade => {
self.process_dsp(buffer);
self.bypass_handler.finish(buffer);
}
}§Sample Type Flexibility
BypassHandler is not generic over sample type. The finish() method
is generic, so a single BypassHandler instance can process both
Buffer<f32> and Buffer<f64> buffers.
§Real-Time Safety
This struct performs no heap allocations and is safe to use in audio processing callbacks.
Implementations§
Source§impl BypassHandler
impl BypassHandler
Sourcepub fn new(ramp_samples: u32, curve: CrossfadeCurve) -> Self
pub fn new(ramp_samples: u32, curve: CrossfadeCurve) -> Self
Create a new bypass handler.
§Arguments
ramp_samples- Number of samples for crossfade (0 = instant bypass)curve- Crossfade curve shape
Sourcepub fn state(&self) -> BypassState
pub fn state(&self) -> BypassState
Get the current bypass state.
Sourcepub fn is_ramping(&self) -> bool
pub fn is_ramping(&self) -> bool
Returns true if currently in a ramping (crossfading) state.
Sourcepub fn is_bypassed(&self) -> bool
pub fn is_bypassed(&self) -> bool
Returns true if fully bypassed (not ramping).
Sourcepub fn ramp_samples(&self) -> u32
pub fn ramp_samples(&self) -> u32
Get the configured ramp length in samples.
Sourcepub fn set_ramp_samples(&mut self, samples: u32)
pub fn set_ramp_samples(&mut self, samples: u32)
Set the ramp length. Takes effect on next state transition.
Sourcepub fn set_curve(&mut self, curve: CrossfadeCurve)
pub fn set_curve(&mut self, curve: CrossfadeCurve)
Set the crossfade curve. Takes effect on next state transition.
Sourcepub fn begin(&mut self, bypassed: bool) -> BypassAction
pub fn begin(&mut self, bypassed: bool) -> BypassAction
Begin bypass processing for this buffer.
Call this at the start of your process() method. It updates the internal
state and returns what action you should take.
§Arguments
bypassed- Current bypass parameter state (true = bypassed)
§Returns
A BypassAction telling you what to do:
Passthrough: Just copy input to output, no DSP neededProcess: Run your DSP normallyProcessAndCrossfade: Run your DSP, then callfinish()
§Example
match self.bypass_handler.begin(is_bypassed) {
BypassAction::Passthrough => buffer.copy_to_output(),
BypassAction::Process => self.process_dsp(buffer),
BypassAction::ProcessAndCrossfade => {
self.process_dsp(buffer);
self.bypass_handler.finish(buffer);
}
}Sourcepub fn finish<S: Sample>(&mut self, buffer: &mut Buffer<'_, S>)
pub fn finish<S: Sample>(&mut self, buffer: &mut Buffer<'_, S>)
Finish bypass processing by applying the crossfade.
Call this AFTER your DSP processing when begin() returned
BypassAction::ProcessAndCrossfade.
This blends the wet signal (in output buffer) with the dry signal (in input buffer) according to the current ramp position.
§Arguments
buffer- The buffer containing processed (wet) output and original (dry) input