Module: Music::Performance::Interpolation

Defined in:
lib/music-performance/util/interpolation.rb

Class Method Summary collapse

Class Method Details

.linear(y0, y1, x) ⇒ Object

Linear interpolation Given 2 sample points, interpolates a value anywhere between the two points.

Parameters:

  • y0 (Numeric)

    First (left) y-value

  • y1 (Numeric)

    Second (right) y-value

  • x (Numeric)

    Percent distance (along the x-axis) between the two y-values

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/music-performance/util/interpolation.rb', line 11

def self.linear y0, y1, x
  raise ArgumentError, "x is not between 0.0 and 1.0" unless x.between?(0.0,1.0)
  return y0 + x * (y1 - y0)
end