Class: Wavify::DSP::Effects::Tremolo

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

Overview

Amplitude modulation effect using a sine LFO.

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, #tail_duration

Constructor Details

#initialize(rate: 5.0, depth: 0.5, mix: 1.0) ⇒ Tremolo

Returns a new instance of Tremolo.

Parameters:

  • rate: (Numeric) (defaults to: 5.0)
  • depth: (Numeric) (defaults to: 0.5)
  • mix: (Numeric) (defaults to: 1.0)


8
9
10
11
12
13
14
# File 'lib/wavify/dsp/effects/tremolo.rb', line 8

def initialize(rate: 5.0, depth: 0.5, mix: 1.0)
  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
# File 'lib/wavify/dsp/effects/tremolo.rb', line 22

def process_sample(sample, channel:, sample_rate:)
  dry = sample.to_f
  mod = 1.0 - (@depth * ((Math.sin(@phase) + 1.0) / 2.0))
  wet = dry * mod
  advance_phase! if channel == (@runtime_channels - 1)

  (dry * (1.0 - @mix)) + (wet * @mix)
end