Class: AudioStream::Fx::Equalizer2band
- Inherits:
-
Object
- Object
- AudioStream::Fx::Equalizer2band
- Defined in:
- lib/audio_stream/fx/equalizer_2band.rb
Instance Method Summary collapse
-
#initialize(soundinfo, lowfreq: 400.0, lowgain:, highfreq: 4000.0, highgain:) ⇒ Equalizer2band
constructor
A new instance of Equalizer2band.
- #plot(width = 500) ⇒ Object
- #process(input) ⇒ Object
Constructor Details
#initialize(soundinfo, lowfreq: 400.0, lowgain:, highfreq: 4000.0, highgain:) ⇒ Equalizer2band
Returns a new instance of Equalizer2band.
9 10 11 12 |
# File 'lib/audio_stream/fx/equalizer_2band.rb', line 9 def initialize(soundinfo, lowfreq: 400.0, lowgain:, highfreq: 4000.0, highgain:) @low_filter = LowShelfFilter.create(soundinfo, freq: lowfreq, q: BiquadFilter::DEFAULT_Q, gain: lowgain) @high_filter = HighShelfFilter.create(soundinfo, freq: highfreq, q: BiquadFilter::DEFAULT_Q, gain: highgain) end |
Instance Method Details
#plot(width = 500) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/audio_stream/fx/equalizer_2band.rb', line 19 def plot(width=500) data1 = @low_filter.plot_data(width) data2 = @high_filter.plot_data(width) data = { x: data1[:x], magnitude: [data1[:magnitude], data2[:magnitude]].transpose.map {|a| a[0] + a[1]}, phase: [data1[:phase], data2[:phase]].transpose.map {|a| a[0] + a[1]}, } 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
14 15 16 17 |
# File 'lib/audio_stream/fx/equalizer_2band.rb', line 14 def process(input) input = @low_filter.process(input) input = @high_filter.process(input) end |