Class: AudioStream::Fx::GraphicEqualizer

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

Instance Method Summary collapse

Constructor Details

#initialize(soundinfo) ⇒ GraphicEqualizer

Returns a new instance of GraphicEqualizer.

Parameters:



5
6
7
8
# File 'lib/audio_stream/fx/graphic_equalizer.rb', line 5

def initialize(soundinfo)
  @soundinfo = soundinfo
  @filters = []
end

Instance Method Details

#add(freq:, bandwidth: 1.0, gain:) ⇒ Object

Parameters:

  • freq (AudioStream::Rate | Float)

    Cutoff frequency

  • bandwidth (Float) (defaults to: 1.0)

    bandwidth (octave)

  • gain (AudioStream::Decibel | Float)

    Amplification level at cutoff frequency



13
14
15
16
# File 'lib/audio_stream/fx/graphic_equalizer.rb', line 13

def add(freq:, bandwidth: 1.0, gain:)
  @filters << PeakingFilter.create(@soundinfo, freq: freq, bandwidth: bandwidth, gain: gain)
  self
end

#plot(width = 500) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/audio_stream/fx/graphic_equalizer.rb', line 25

def plot(width=500)
  data_arr = @filters.map{|filter| filter.plot_data(width)}

  data = {
    x: data_arr[0][:x],
    magnitude: data_arr.map{|d| d[:magnitude]}.transpose.map {|a| a.sum},
    phase: data_arr.map{|d| d[:phase]}.transpose.map {|a| a.sum},
  }

  Plotly::Plot.new(
    data: [{x: data[:x], y: data[:magnitude], name: 'Magnitude', yaxis: 'y1'}, {x: data[:x], y: data[:phase], name: 'Phase', yaxis: 'y2'}],
    layout: {
      xaxis: {title: 'Frequency (Hz)', type: 'log'},
      yaxis: {side: 'left', title: 'Magnitude (dB)', showgrid: false},
      yaxis2: {side: 'right', title: 'Phase (deg)', showgrid: false, overlaying: 'y'}
    }
  )
end

#process(input) ⇒ Object



18
19
20
21
22
23
# File 'lib/audio_stream/fx/graphic_equalizer.rb', line 18

def process(input)
  @filters.each {|filter|
    input = filter.process(input)
  }
  input
end