Mix audio array into a single audio signal

Hi all, I’m trying to develop an oscillator bank UDO with a parametrizable oscillator count. I’m using multiple vco2 in a loop and put their audio output in an audio array:

opcode oscillators, a, iii
  setksmps 1
  iFreq, iDetune, iOscilCount xin
  iIndexOffset = (iOscilCount - 1) / 2
  aOuts[] init iOscilCount
  kIndex = 0
  while kIndex < iOscilCount do
    aOuts[kIndex] vco2 1, iFreq + iDetune * (kIndex - iIndexOffset)
    kIndex += 1
  od
  xout [aOuts as a single audio value]
endop

How to do it?

You can’t do it like this as vco2 had internal state. To do this, modify your UDO so it’s recursive. Then each instance of vco2 will be unique.

1 Like

Thanks for the tip.

Here’s my working oscillator bank implemented with a recursive UDO. Thanks again Rory.

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

Thanks for sharing the solution. Btw, in Csound 7 it will be possible to do this kind of thing without a recursive UDO. :+1:

And how will it be done? What change are you referring to?

You can read about it here - ( I’m still not 100% on how it will work )

1 Like