Class: AudioStream::Fx::CombFilter

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

Instance Method Summary collapse

Constructor Details

#initialize(soundinfo, freq:, q:) ⇒ CombFilter

Returns a new instance of CombFilter.

Parameters:



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/audio_stream/fx/comb_filter.rb', line 8

def initialize(soundinfo, freq:, q:)
  freq = Rate.freq(freq)

  @window_size = soundinfo.window_size
  @delaysample = freq.sample(soundinfo).round
  @q = q.to_f

  @delaybufs = [
    Vdsp::DoubleArray.new(soundinfo.window_size + @delaysample),
    Vdsp::DoubleArray.new(soundinfo.window_size + @delaysample),
  ]
end

Instance Method Details

#process(input) ⇒ Object



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

def process(input)
  window_size = input.window_size
  if @window_size!=window_size
    raise "window size is not match: impulse.size=#{@window_size} input.size=#{window_size}"
  end

  streams = input.streams.map.with_index {|src, i|
    buf = @delaybufs[i]

    Vdsp::UnsafeDouble.copy(buf, window_size, 1, buf, 0, 1, @delaysample)
    if @delaysample<window_size
      Vdsp::UnsafeDouble.vclr(buf, window_size, 1, @delaysample)
    end
    Vdsp::UnsafeDouble.vsmsma(src, 0, 1, 1.0, buf, 0, 1, @q, buf, @delaysample, 1, window_size)
    dst = buf[@delaysample, window_size]

    dst
  }

  Buffer.new(*streams)
end