Module: Synthesizer::Utils

Defined in:
lib/synthesizer/utils.rb

Class Method Summary collapse

Class Method Details

.cross_panning(pan) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/synthesizer/utils.rb', line 13

def self.cross_panning(pan)
  if pan<-1.0
    pan = -1.0
  elsif 1.0<pan
    pan = 1.0
  end

  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

  {
    l_gain: l_gain,
    lr_gain: lr_gain,
    r_gain: r_gain,
    rl_gain: rl_gain,
    normalize: normalize
  }
end

.panning(pan) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/synthesizer/utils.rb', line 4

def self.panning(pan)
  cp = cross_panning(pan)

  l_gain = (cp[:l_gain] + cp[:lr_gain]) / cp[:normalize]
  r_gain = (cp[:r_gain] + cp[:rl_gain]) / cp[:normalize]

  [l_gain, r_gain]
end