Class: Zappa::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/zappa/processor.rb

Instance Method Summary collapse

Instance Method Details

#amplify(samples, db) ⇒ Object

fix order



11
12
13
# File 'lib/zappa/processor.rb', line 11

def amplify(samples, db) # fix order
  mul_samples(samples, db_to_float(db))
end

#compress(samples, ratio, threshold) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zappa/processor.rb', line 19

def compress(samples, ratio, threshold)
  threshold_value = 32_768 * db_to_float(threshold) # calc this somehow
  samples.each do |f|
    f.map! do |s|
      if s.abs > threshold_value
        s += (threshold_value - s) / ratio if s > 0
        s -= (s + threshold_value) / ratio if s < 0
      end
      s.round
    end
  end
  samples
end

#invert(samples) ⇒ Object



15
16
17
# File 'lib/zappa/processor.rb', line 15

def invert(samples)
  mul_samples(samples, -1)
end

#normalize(samples, headroom) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/zappa/processor.rb', line 3

def normalize(samples, headroom)
  fail 'headroom cannot be positive' if headroom > 0.0
  curr_peak = max_sample(samples)
  targ_peak = 32_768 * db_to_float(headroom)  # calculate this constants
  ratio = (targ_peak / curr_peak)
  mul_samples(samples, ratio)
end