Class: Wavify::DSP::Effects::AutoPan

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

Overview

Stereo sine-LFO auto-panner.

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: 0.5, depth: 1.0) ⇒ AutoPan

Returns a new instance of AutoPan.

Parameters:

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


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

def initialize(rate: 0.5, depth: 1.0)
  super()
  @rate = validate_positive!(rate, :rate)
  @depth = validate_unit!(depth, :depth)
  reset
end

Instance Method Details

#process_sample(sample, channel:, sample_rate:) ⇒ Float

Processes a single sample for one stereo channel.

Parameters:

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

Returns:

  • (Float)

Raises:



21
22
23
24
25
26
27
28
29
# File 'lib/wavify/dsp/effects/auto_pan.rb', line 21

def process_sample(sample, channel:, sample_rate:)
  raise InvalidParameterError, "AutoPan requires stereo input" unless @runtime_channels == 2

  position = Math.sin(@phase) * @depth
  left_gain, right_gain = constant_power_pan_gains(position)
  output = sample.to_f * (channel.zero? ? left_gain : right_gain)
  advance_phase! if channel == 1
  output
end