randcubic glissandi: random line with cubic interpolation

Audio example of randcubic used for glissandi

Custom Csound user-defined opcode randcubic to generate cubic interpolated lines. Example above uses randcubic for achieving time-varying glissandi with multiple voices.

Based on code from http://paulbourke.net/miscellaneous/interpolation/.

Code for UDO is as follows:

opcode randcubic, a,kk
  kamp, kfreq xin
  
  ky0 init random:i(-1, 1)
  ky1 init random:i(-1, 1)
  ky2 init random:i(-1, 1)
  ky3 init random:i(-1, 1)  
  
  kcount init 0
  asig init 0
  
  kperiod = sr / kfreq
  kndx = 0
  
  while (kndx < ksmps) do
    ka0 = ky3 - ky2 - ky0 + ky1
   	ka1 = ky0 - ky1 - ka0
    ka2 = ky2 - ky0
    ka3 = ky1
    
    kmu = kcount / kperiod
    kmu2 = kmu * kmu
    
    asig[kndx] = ka0 * kmu * kmu2 + ka1 * kmu2 + ka2 * kmu + ka3
    
    kcount += 1
    
    if(kcount > kperiod) then
      ky0 = ky1
  	  ky1 = ky2 
  	  ky2 = ky3       
      ky3 = random:k(-1, 1)  
      kcount -= kperiod
    endif
    
    kndx += 1
  od
    
  asig *= kamp
    
  xout asig
  
endop

Leave a comment

Your email address will not be published. Required fields are marked *