Class: AudioStream::Fx::Panning
- Inherits:
-
Object
- Object
- AudioStream::Fx::Panning
- Defined in:
- lib/audio_stream/fx/panning.rb
Instance Method Summary collapse
-
#initialize(pan: 0.0) ⇒ Panning
constructor
A new instance of Panning.
- #process(input) ⇒ Object
Constructor Details
#initialize(pan: 0.0) ⇒ Panning
Returns a new instance of Panning.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/audio_stream/fx/panning.rb', line 5 def initialize(pan: 0.0) @pan = pan.to_f l_gain = 1.0 - pan lr_gain = 0.0 if 1.0<l_gain lr_gain = l_gain - 1.0 l_gain = 1.0 end r_gain = 1.0 + pan rl_gain = 0.0 if 1.0<r_gain rl_gain = r_gain - 1.0 r_gain = 1.0 end normalize = [1.0 - pan, 1.0 + pan].max @r_gain = r_gain / normalize @rl_gain = rl_gain / normalize @l_gain = l_gain / normalize @lr_gain = lr_gain / normalize end |
Instance Method Details
#process(input) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/audio_stream/fx/panning.rb', line 30 def process(input) return input if @pan==0.0 src = input.stereo.streams src0 = src[0] src1 = src[1] dst0 = Vdsp::DoubleArray.new(src0.length) Vdsp::UnsafeDouble.vsmsma(src0, 0, 1, @l_gain, src1, 0, 1, @lr_gain, dst0, 0, 1, src0.length) dst1 = Vdsp::DoubleArray.new(src1.length) Vdsp::UnsafeDouble.vsmsma(src0, 0, 1, @rl_gain, src1, 0, 1, @r_gain, dst1, 0, 1, src1.length) Buffer.new(dst0, dst1) end |