Class: AudioStream::Fx::Equalizer3band

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

Instance Method Summary collapse

Constructor Details

#initialize(soundinfo, lowfreq: 400.0, lowgain:, midfreq: 1000.0, midgain:, highfreq: 4000.0, highgain:) ⇒ Equalizer3band

Returns a new instance of Equalizer3band.

Parameters:



11
12
13
14
15
# File 'lib/audio_stream/fx/equalizer_3band.rb', line 11

def initialize(soundinfo, lowfreq: 400.0, lowgain:, midfreq: 1000.0, midgain:, highfreq: 4000.0, highgain:)
  @low_filter = LowShelfFilter.create(soundinfo, freq: lowfreq, q: BiquadFilter::DEFAULT_Q, gain: lowgain)
  @mid_filter = PeakingFilter.create(soundinfo, freq: midfreq, bandwidth: 1.0, gain: midgain)
  @high_filter = HighShelfFilter.create(soundinfo, freq: highfreq, q: BiquadFilter::DEFAULT_Q, gain: highgain)
end

Instance Method Details

#plot(width = 500) ⇒ Object



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

def plot(width=500)
  data1 = @low_filter.plot_data(width)
  data2 = @mid_filter.plot_data(width)
  data3 = @high_filter.plot_data(width)

  data = {
    x: data1[:x],
    magnitude: [data1[:magnitude], data2[:magnitude], data3[:magnitude]].transpose.map {|a| a[0] + a[1] + a[2]},
    phase: [data1[:phase], data2[:phase], data3[:phase]].transpose.map {|a| a[0] + a[1] + a[2]},
  }

  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



17
18
19
20
21
# File 'lib/audio_stream/fx/equalizer_3band.rb', line 17

def process(input)
  input = @low_filter.process(input)
  input = @mid_filter.process(input)
  input = @high_filter.process(input)
end