Sha256: a20935c4cec2d041a9afbd41f2132854132fd1c371bbc4c7e99c618feae6c209

Contents?: true

Size: 653 Bytes

Versions: 1

Compression:

Stored size: 653 Bytes

Contents

module Xi::CoreExt
  module Numeric
    def midi_to_cps
      440 * (2 ** ((self - 69) / 12.0))
    end

    def db_to_amp
      10 ** (self / 20.0)
    end

    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
  end
end

class Fixnum
  include Xi::CoreExt::Numeric
end

class Float
  include Xi::CoreExt::Numeric
end

class Rational
  include Xi::CoreExt::Numeric
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xi-lang-0.1.5 lib/xi/core_ext/numeric.rb