xyscale — 2D linear interpolation


Plugin opcode in emugens.

2D linear interpolation between 4 points at (0,0), (1,0), (0,1), (1,1)


kout xyscale kx, ky, k00, k10, k01, k11


kx, ky -- Coordinates to evaluate the interpolation. Value between 0-1, where:

k00 -- Value of point at coord (x=0, y=0)

k10 -- Value of point at coord (x=1, y=0)

k01 -- Value of point at coord (x=0, y=1)

k11 -- Value of point at coord (x=1, y=1)

          (0,1)      (1,1)

          (0,0)      (1,0)

Given 4 values placed at the corners of a square, find the interpolated value at point (x, y), where x and y are defined between 0-1.


Here is an example of the xyscale opcode. It uses the file xyscale.csd.

Example 1155. Example of the xyscale opcode.

; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac           -iadc     -d     ;;;RT audio I/O


giwidth = 400
giheight = 300
FLpanel "FLmouse", giwidth, giheight, 10, 10


0dbfs = 1

instr 1
  ; We define four chords for bottom-left, bottom-right, top-left and top-right
  ; Use the mouse to interpolate between them
  ibl[] array ntom:i("4C"), ntom:i("4Eb"), ntom:i("4G")
  itl[] array ntom:i("4E"), ntom:i("4G#"), ntom:i("4B")
  ibr[] array ntom:i("4G"), ntom:i("4A"), ntom:i("4B")
  itr[] array ntom:i("4Eb"), ntom:i("4Eb+"), ntom:i("4F")
  kmousex, kmousey, kb1, kb2, kb3    FLmouse 2
  kx = limit(kmousex/giwidth, 0, 1)
  ky = 1 - limit(kmousey/giheight, 0, 1)

  printf "x: %f   y: %f \n", changed(kx, ky), kx, ky

  iamp = 0.1
  a0 oscili iamp, mtof(xyscale(kx, ky, ibl[0], itl[0], ibr[0], itr[0]))
  a1 oscili iamp, mtof(xyscale(kx, ky, ibl[1], itl[1], ibr[1], itr[1]))
  a2 oscili iamp, mtof(xyscale(kx, ky, ibl[2], itl[2], ibr[2], itr[2]))
  aout = sum(a0, a1, a2)
  outs aout, aout  

i 1 0 120


See Also

scale, ntrpol, linlin


By: Eduardo Moguillansky 2017