BypassHandler

Struct BypassHandler 

Source
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

Source

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
Source

pub fn state(&self) -> BypassState

Get the current bypass state.

Source

pub fn is_ramping(&self) -> bool

Returns true if currently in a ramping (crossfading) state.

Source

pub fn is_bypassed(&self) -> bool

Returns true if fully bypassed (not ramping).

Source

pub fn is_active(&self) -> bool

Returns true if fully active (not ramping, not bypassed).

Source

pub fn ramp_samples(&self) -> u32

Get the configured ramp length in samples.

Source

pub fn set_ramp_samples(&mut self, samples: u32)

Set the ramp length. Takes effect on next state transition.

Source

pub fn set_curve(&mut self, curve: CrossfadeCurve)

Set the crossfade curve. Takes effect on next state transition.

Source

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 needed
  • Process: Run your DSP normally
  • ProcessAndCrossfade: Run your DSP, then call finish()
§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);
    }
}
Source

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

Trait Implementations§

Source§

impl Default for BypassHandler

Source§

fn default() -> Self

Create a bypass handler with default settings (64 samples, linear curve).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.