pub struct SCDistortion { /* private fields */ }Implementations§
Source§impl SCDistortion
impl SCDistortion
pub fn new( id: u32, name: String, is_active: bool, threshold: f32, level: f32, smoothing: f32, color: String, ) -> Self
Sourcepub fn threshold(&self) -> f32
pub fn threshold(&self) -> f32
Returns the current clipping threshold in range [0.0, 1.0].
§Returns
The threshold value; lower values produce heavier clipping.
Sourcepub fn set_threshold(&self, threshold: f32)
pub fn set_threshold(&self, threshold: f32)
Sets the clipping threshold. Value is clamped to [0.001, 1.0].
The change takes effect on the very next audio sample — no synchronisation needed.
§Parameters
threshold— New clipping level in(0.0, 1.0]
Sourcepub fn level(&self) -> f32
pub fn level(&self) -> f32
Returns the normalised output level in range [0.0, 1.0].
Internally the gain is stored as [1.0, 2.0]; this method reverses that mapping
to give the external normalised value.
§Returns
Normalised level: 0.0 = no boost (unity gain), 1.0 = ×2.0 boost
Sourcepub fn set_level(&self, level: f32)
pub fn set_level(&self, level: f32)
Sets the output level from a normalised value [0.0, 1.0].
Internally maps to gain [1.0, 2.0] and stores it in the atomic.
The change takes effect on the very next audio sample — no synchronisation needed.
§Parameters
level— Normalised level in[0.0, 1.0]. Will be clamped.
pub fn smoothing(&self) -> f32
pub fn set_smoothing(&self, smoothing: f32)
Trait Implementations§
Source§impl AudioProcessor for SCDistortion
impl AudioProcessor for SCDistortion
Source§fn process(&mut self, sample: f32) -> f32
fn process(&mut self, sample: f32) -> f32
Processes a single audio sample through soft clipping and level boost.
§Algorithm
- Load clipping threshold & the smoothing factor atomically (lock-free)
- Normalize the sample to the clipping threshold. Needs to be done because smoothing algorithm smooths towards 1.0 and -1.0
- Smooth the curve towards the limit
- Denormalize the sample to get back to the desired amplitude
- Apply gain boost via the
GainProcessorwith smoothed transitions
§Parameters
sample— audio sample, typically-1.0to1.0
§Returns
Processed sample: clipped, smoothed and boosted by the level knob
Source§impl Effect for SCDistortion
impl Effect for SCDistortion
Source§fn to_dto(&self) -> EffectDto
fn to_dto(&self) -> EffectDto
Converts this effect into its serialisable DTO representation.
Called when sending effect state to the frontend or external clients.
§Returns
EffectDto::SCDistortion with all current parameters
Source§fn f32_params(&self) -> HashMap<&'static str, Arc<AtomicF32>>
fn f32_params(&self) -> HashMap<&'static str, Arc<AtomicF32>>
Returns a map of named f32 parameters for command infrastructure.
This enables the generic command dispatcher to update effect parameters without needing to know about specific effect types.
§Returns
HashMap with keys:
"threshold"— points tolimitatomic; external code can write new thresholds"level"— points to internal gain atomic[1.0, 2.0]
§Note
The "level" key stores the raw gain value. Command handlers should convert
the external normalised [0, 1] range to internal gain [1, 2] before writing.
Source§fn name(&self) -> &str
fn name(&self) -> &str
Source§fn get_color(&self) -> String
fn get_color(&self) -> String
Source§fn active_flag(&self) -> Arc<AtomicBool>
fn active_flag(&self) -> Arc<AtomicBool>
Arc<AtomicBool> that drives process_if_active.
Command handlers write to it; the audio thread reads it lock-free.Source§fn is_active(&self) -> bool
fn is_active(&self) -> bool
true if the effect is currently enabled and processing audio. Read more