[Csnd] UDO for morphing between arrays

Hello everybody!

I don’t know if this already exists as an opcode (i couldn’t find it), so i tried to do it as an recursive UDO for an actual project.

I want to morph/interpolate between two arrays.
This should happen between the values of the same index.
For example:
Array-1[0] = 0
Array-2[0] = 10

ResultArray[0] gives the interpolate numbers between 0 and 10 via indexing.

I thought i found the solution,
but the value accumulation is not working as expected and i get strange results.

Here is my code:

opcode morf_arrays,k[],ki[]i[]o
  kIndex,iArray1[],iArray2[],iArrIndx xin
  kArray[] init lenarray(iArray1)
  
  iTable ftgen 0,0,0,-2,iArray1[iArrIndx],iArray2[iArrIndx]
  kRes tablei kIndex,iTable
  kArray[iArrIndx] = kRes
  if iArrIndx < lenarray(iArray1)-1 then
    kArray[] += morf_arrays(kIndex,iArray1,iArray2,iArrIndx+1)
  endif
  
  xout kArray
endop

instr 1
  iSpectrArr1[] fillarray 1,1.0, 3,0.33, 5,0.2, 7,0.8, 24,0.9, 12,0.1
  iSpectrArr2[] fillarray 2,1.0, 1,0.33, 50,0.2, 10,0.8, 24,0.9, 12,0.9

  kMorphIndex line 0,p3,1
  kSpectrArr[] morf_arrays kMorphIndex,iSpectrArr1,iSpectrArr2

  printk 0.1,kSpectrArr[2]
endin
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

Hi Philipp,
do you just want morphed values for every index or do you want to accumulate a value? If it's the former, you could do it in a loop:
kIndex = 0
while (kIndex < iArrayLen) do
   kResultArray[kIndex] = iArray1[kIndex] * kWeight + iArray2[kIndex}
     * (1 - kWeight)
   kIndex += 1
od
This would create a kResultArray every k-cycle, that morphs between iArray1 and iArray2 based on the kWeight parameter, i.e. how much of iArray1 and iArray2 will influence the output.

If ftables were a solution, you could try hvs1 (Hyper Vectorial Synthesis) or other table morphing opcodes, depending on your exact needs.

Best wishes,

Jeanette

linlin can do exactly that, see the following form, where kA and kB are two arrays of the same shape and kx is the interpolation index

kC[] **linlin** kx, kA[], kB[] [, kx0, kx1 ]

Thank you both!

linlin is perfect! I didn’t find it in the manual while searching for a fitting opcode, thanks!