Module: Deftones::Effects::Oversampling

Included in:
BitCrusher, Chebyshev, Distortion
Defined in:
lib/deftones/effect/oversampling.rb

Constant Summary collapse

OVERSAMPLE_FACTORS =
[1, 2, 4].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#oversampleObject

Returns the value of attribute oversample.



8
9
10
# File 'lib/deftones/effect/oversampling.rb', line 8

def oversample
  @oversample
end

Instance Method Details

#ensure_oversample_state(channel_index) ⇒ Object (private)



37
38
39
40
# File 'lib/deftones/effect/oversampling.rb', line 37

def ensure_oversample_state(channel_index)
  required = [channel_index.to_i, 0].max
  @oversample_previous.fill(0.0, @oversample_previous.length..required)
end

#process_oversampled(input_buffer, channel_index) ⇒ Object (private)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/deftones/effect/oversampling.rb', line 20

def process_oversampled(input_buffer, channel_index)
  ensure_oversample_state(channel_index)
  return input_buffer.map { |sample| yield sample } if @oversample == 1

  input_buffer.map do |sample|
    previous = @oversample_previous[channel_index]
    current = sample.to_f
    sum = 0.0
    1.upto(@oversample) do |step|
      position = step.to_f / @oversample
      sum += yield Deftones::DSP::Helpers.lerp(previous, current, position)
    end
    @oversample_previous[channel_index] = current
    sum / @oversample
  end
end