Class: Wavify::DSP::Effects::Distortion
- Inherits:
-
EffectBase
- Object
- EffectBase
- Wavify::DSP::Effects::Distortion
- Defined in:
- lib/wavify/dsp/effects/distortion.rb,
sig/effects.rbs
Overview
Soft-clipping distortion with tone shaping and dry/wet mix.
Constant Summary
Constants inherited from EffectBase
Instance Method Summary collapse
-
#initialize(drive: 0.5, tone: 0.5, mix: 1.0) ⇒ Distortion
constructor
A new instance of Distortion.
-
#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(drive: 0.5, tone: 0.5, mix: 1.0) ⇒ Distortion
Returns a new instance of Distortion.
8 9 10 11 12 13 14 |
# File 'lib/wavify/dsp/effects/distortion.rb', line 8 def initialize(drive: 0.5, tone: 0.5, mix: 1.0) super() @drive = validate_unit!(drive, :drive) @tone = validate_unit!(tone, :tone) @mix = validate_unit!(mix, :mix) reset end |
Instance Method Details
#process_sample(sample, channel:, sample_rate:) ⇒ Float
Processes a single sample for one channel.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wavify/dsp/effects/distortion.rb', line 22 def process_sample(sample, channel:, sample_rate:) dry = sample.to_f wet = Math.tanh(dry * pre_gain) # One-pole low-pass on the distorted signal for tone shaping. previous = @tone_state.fetch(channel) filtered = previous + (@tone_coefficient * (wet - previous)) @tone_state[channel] = filtered (dry * (1.0 - @mix)) + (filtered * @mix) end |