Overview

Content

Recursive UDO Design

You can create UDO’s which are calling themselfs. This is called recursion. In this way you can solve problems that are not solved easily in other ways.

Here are some examples.

  • create a oscillator bank
opcode vco2Bank, a, kkioOo
  kFreq, kDetune, iCount, iMode, kPulseWidth, iIndex xin
  iFactor = 1 / (iCount - 1) * iIndex
  iDetuneFactor = iFactor * 2 - 1
  kOscFreq = kFreq + kDetune * iDetuneFactor
  aSig vco2 0dbfs / iCount, kOscFreq, iMode, kPulseWidth
  if iIndex < iCount - 1 then
    aSig2 vco2Bank kFreq, kDetune, iCount, iMode, kPulseWidth, iIndex + 1
    aSig += aSig2
  endif
  xout aSig
endop
opcode AddSynth,a,i[]i[]iooo
 /* iFqs[], iAmps[]: arrays with frequency ratios and amplitude multipliers
 iBasFreq: base frequency (hz)
 iPtlIndex: partial index (first partial = index 0)
 iFreqDev, iAmpDev: maximum frequency (cent) and amplitude (db) deviation */
 iFqs[], iAmps[], iBasFreq, iPtlIndx, iFreqDev, iAmpDev xin
 iFreq = iBasFreq * iFqs[iPtlIndx] * cent(rnd31:i(iFreqDev,0))  ; cent(0) -> 1; entspricht einem Faktor
 iAmp = iAmps[iPtlIndx] * ampdb(rnd31:i(iAmpDev,0))             ; ampdb(0) -> 1
 aPartial poscil iAmp, iFreq
 if iPtlIndx < lenarray(iFqs)-1 then
  aPartial += AddSynth(iFqs,iAmps,iBasFreq,iPtlIndx+1,iFreqDev,iAmpDev)
 endif
 xout aPartial
;;; by Joachim Heintz
endop
  • UDO for creating a Sine wave with undertones
opcode undersine, a, kkkio
  kFreq, kAmpWeight, kFreqRatio, iNumOfUndertones, iIndex xin
 
  aSig = poscil(0dbfs / iNumOfUndertones, kFreq)
 
  if (iIndex < iNumOfUndertones) then
	aSigNew = undersine(kFreq / kFreqRatio, kFreqRatio, kAmpWeight, iNumOfUndertones, iIndex + 1)
	aSigNew = (kAmpWeight / sqrt(iIndex+1)) * aSigNew
	aSig += aSigNew
  endif
 
  xout aSig
endop