Module: JSound::Convert

Defined in:
lib/jsound/convert.rb

Overview

Helper methods for converting MIDI data values

Constant Summary collapse

MAX_14BIT_VALUE =

The maximum value for unsigned 14-bit integer

16383

Instance Method Summary collapse

Instance Method Details

#from_7bit(lsb, msb) ⇒ Object

Convert a [least_significant, most_significant] pair of 7-bit ints to a single integer



15
16
17
# File 'lib/jsound/convert.rb', line 15

def from_7bit(lsb, msb)
  lsb + (msb << 7)
end

#normalized_float_to_14bit(float) ⇒ Object

Scales a float from the range [-1.0, 1.0] to the integer range [0, 16383]



20
21
22
# File 'lib/jsound/convert.rb', line 20

def normalized_float_to_14bit(float)
  (MAX_14BIT_VALUE*(float+1)/2).round
end

#to_7bit(value) ⇒ Object

Convert a single integer to a [least_significant, most_significant] pair of 7-bit ints



10
11
12
# File 'lib/jsound/convert.rb', line 10

def to_7bit(value)
  [value & 127, (value >> 7) & 127]
end