Class: Wavify::DSP::Effects::Chorus
- Inherits:
-
EffectBase
- Object
- EffectBase
- Wavify::DSP::Effects::Chorus
- Defined in:
- lib/wavify/dsp/effects/chorus.rb,
sig/effects.rbs
Overview
Modulated delay chorus effect.
Constant Summary
Constants inherited from EffectBase
Instance Method Summary collapse
-
#initialize(rate: 1.0, depth: 0.5, mix: 0.5) ⇒ Chorus
constructor
A new instance of Chorus.
-
#process_sample(sample, channel:, sample_rate:) ⇒ Float
Processes a single sample for one channel.
-
#tail_duration ⇒ Float
Maximum modulation delay emitted after input ends.
Methods inherited from EffectBase
#apply, #build_runtime, #flush, #latency, #lookahead, #process, #reset
Constructor Details
#initialize(rate: 1.0, depth: 0.5, mix: 0.5) ⇒ Chorus
Returns a new instance of Chorus.
8 9 10 11 12 13 14 |
# File 'lib/wavify/dsp/effects/chorus.rb', line 8 def initialize(rate: 1.0, depth: 0.5, mix: 0.5) super() @rate = validate_positive!(rate, :rate) @depth = validate_unit!(depth, :depth) @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 33 34 35 36 37 |
# File 'lib/wavify/dsp/effects/chorus.rb', line 22 def process_sample(sample, channel:, sample_rate:) dry = sample.to_f line = @delay_lines.fetch(channel) write_index = @write_indices.fetch(channel) mod_phase = @lfo_phase + channel_phase_offset(channel) mod = Math.sin(mod_phase) delay_samples = @base_delay_samples + (@depth_delay_samples * ((mod + 1.0) / 2.0)) wet = read_fractional_delay(line, write_index, delay_samples) line[write_index] = dry @write_indices[channel] = (write_index + 1) % line.length advance_lfo! if channel == (@runtime_channels - 1) (dry * (1.0 - @mix)) + (wet * @mix) end |
#tail_duration ⇒ Float
Returns maximum modulation delay emitted after input ends.
40 41 42 43 44 |
# File 'lib/wavify/dsp/effects/chorus.rb', line 40 def tail_duration return 0.0 if @mix.zero? 0.03 end |