Module: Xi::CoreExt::Numeric

Included in:
Float, Integer, Rational
Defined in:
lib/xi/core_ext/numeric.rb

Instance Method Summary collapse

Instance Method Details

#db_to_ampObject



7
8
9
# File 'lib/xi/core_ext/numeric.rb', line 7

def db_to_amp
  10 ** (self / 20.0)
end

#degree_to_key(scale, steps_per_octave) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/xi/core_ext/numeric.rb', line 11

def degree_to_key(scale, steps_per_octave)
  accidental = (self - self.to_i) * 10.0
  inner_key = scale[self % scale.size]
  base_key = (self / scale.size).to_i * steps_per_octave + inner_key
  if accidental != 0
    base_key + accidental * (steps_per_octave / 12.0)
  else
    base_key
  end
end

#midi_to_cpsObject



3
4
5
# File 'lib/xi/core_ext/numeric.rb', line 3

def midi_to_cps
  440 * (2 ** ((self - 69) / 12.0))
end