Class: AudioStream::Fx::Distortion

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_stream/fx/distortion.rb

Instance Method Summary collapse

Constructor Details

#initialize(gain: 40.0, level: -20.0)) ⇒ Distortion

Returns a new instance of Distortion.

Parameters:



6
7
8
9
# File 'lib/audio_stream/fx/distortion.rb', line 6

def initialize(gain: 40.0, level: -20.0)
  @gain = Decibel.db(gain).mag
  @level = Decibel.db(level).mag
end

Instance Method Details

#process(input) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/audio_stream/fx/distortion.rb', line 11

def process(input)
  streams = input.streams.map {|stream|
    dst = Vdsp::DoubleArray.new(input.window_size)
    Vdsp::UnsafeDouble.vclip(stream * @gain, 0, 1, -1.0, 1.0, dst, 0, 1, input.window_size)
    dst * @level
  }
  Buffer.new(*streams)
end