xyscale

xyscale — 2D linear interpolation

Description

Plugin opcode in emugens.

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

Syntax

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

Performance

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.

Examples

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

Example 1226. Example of the xyscale opcode.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o xyscale.wav -W ;;; for file output any platform

; By Stefano Cucchi 2020

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
; In the instr 1  using f1 and f2 you reach the 4 corners (values)
k00 = p4
k10 = p5
k01 = p6
k11 = p7

kx oscil 1, p8, p9
ky oscil 1, p10, p11

kout1 xyscale kx, ky, k00, k10, k01, k11 
kout2 xyscale kx, ky, k00*3/2, k10*4/3, k01*5/4, k11*6/5

a1 buzz 0.2, kout1, 8, 3
a2 buzz 0.2, kout2, 4, 3

outs a1, a2

endin

instr 2
; In the instr 2 setting the first value to 0 or 1 (p8 & p9) you can start from the corner  (value) you want

k00 = p4
k10 = p5
k01 = p6
k11 = p7

kx randomh 0, 1, 2, 2, p8 ; p8 is the X starting value
ky randomh 0, 1, 2, 2, p9 ; p9 is the Y starting value

kout1 xyscale kx, ky, k00, k10, k01, k11 
kout2 xyscale kx, ky, k00*3/2, k10*4/3, k01*5/4, k11*6/5

a1 buzz 0.2, kout1, 8, 3
a2 buzz 0.2, kout2, 4, 3

outs a1, a2

endin


</CsInstruments>
<CsScore>


f1 0 1024 -7 0 400 0 100 1 400 1 124 0
f2 0 1024 -7 0 200 0 100 1 400 1 100 0 224 1
f3 0 1024 10 1 

i1 0 10 300 400 500 600 0.3 1 0.2 2
i2 10 10 300 410 520 630 0 0

e


</CsScore>
</CsoundSynthesizer>


Here is another example of the xyscale opcode. It uses the file xyscale-FLTK.csd.

Example 1227. Advanced example of the xyscale opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

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

ksmps=128
nchnls=2

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

FLrun

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[] fillarray ntom:i("4C"), ntom:i("4Eb"), ntom:i("4G")
  itl[] fillarray ntom:i("4E"), ntom:i("4G#"), ntom:i("4B")
  ibr[] fillarray ntom:i("4G"), ntom:i("4A"), ntom:i("4B")
  itr[] fillarray 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  
endin

</CsInstruments>
<CsScore>
i 1 0 120

</CsScore>
</CsoundSynthesizer>


See Also

scale, ntrpol, linlin

Credits

By: Eduardo Moguillansky 2017