Class: Wavify::DSP::Effects::SoftLimiter
- Inherits:
-
EffectBase
- Object
- EffectBase
- Wavify::DSP::Effects::SoftLimiter
- Defined in:
- lib/wavify/dsp/effects/soft_limiter.rb,
sig/effects.rbs
Overview
Soft-knee peak limiter for taming overs without a hard flat top.
Constant Summary
Constants inherited from EffectBase
Instance Method Summary collapse
-
#initialize(threshold: 0.8, ceiling: 1.0, drive: 1.0) ⇒ SoftLimiter
constructor
A new instance of SoftLimiter.
-
#process_sample(sample, channel:, sample_rate:) ⇒ Float
Processes a single sample for one channel.
Methods inherited from EffectBase
#apply, #build_runtime, #flush, #latency, #lookahead, #process, #reset, #tail_duration
Constructor Details
#initialize(threshold: 0.8, ceiling: 1.0, drive: 1.0) ⇒ SoftLimiter
Returns a new instance of SoftLimiter.
8 9 10 11 12 13 14 15 16 |
# File 'lib/wavify/dsp/effects/soft_limiter.rb', line 8 def initialize(threshold: 0.8, ceiling: 1.0, drive: 1.0) super() @threshold = validate_unit!(threshold, :threshold) @ceiling = validate_unit!(ceiling, :ceiling) raise InvalidParameterError, "ceiling must be greater than threshold" unless @ceiling > @threshold @drive = validate_positive!(drive, :drive) reset end |
Instance Method Details
#process_sample(sample, channel:, sample_rate:) ⇒ Float
Processes a single sample for one channel.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wavify/dsp/effects/soft_limiter.rb', line 24 def process_sample(sample, channel:, sample_rate:) value = sample.to_f magnitude = value.abs return value if magnitude <= @threshold range = @ceiling - @threshold sign = value.negative? ? -1.0 : 1.0 limited = @threshold + (range * (1.0 - Math.exp(-((magnitude - @threshold) * @drive) / range))) sign * limited.clamp(@threshold, @ceiling) end |