Class: Wavify::DSP::Effects::Chorus

Inherits:
EffectBase show all
Defined in:
lib/wavify/dsp/effects/chorus.rb,
sig/effects.rbs

Overview

Modulated delay chorus effect.

Constant Summary

Constants inherited from EffectBase

EffectBase::TAIL_CHUNK_FRAMES

Instance Method Summary collapse

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.

Parameters:

  • rate: (Numeric) (defaults to: 1.0)
  • depth: (Numeric) (defaults to: 0.5)
  • mix: (Numeric) (defaults to: 0.5)
  • delay: (Numeric)
  • voices: (Integer)


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.

Parameters:

  • sample (Numeric)
  • channel (Integer)
  • sample_rate (Integer)

Returns:

  • (Float)


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_durationFloat

Returns maximum modulation delay emitted after input ends.

Returns:

  • (Float)

    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