Csound Csound-dev Csound-tekno Search About

[Csnd] UDO for morphing between arrays

Date2024-01-15 18:41
FromPhilipp Neumann
Subject[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
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-01-15 19:34
From"Jeanette C."
SubjectRe: [Csnd] UDO for morphing between arrays
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

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

Can't you see I'm a fool in so many ways <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-01-15 23:36
FromEduardo Moguillansky
SubjectRe: [Csnd] UDO for morphing between arrays

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 ]

On 15.01.24 19:41, Philipp Neumann wrote:

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
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-01-16 06:40
FromPhilipp Neumann
SubjectRe: [Csnd] UDO for morphing between arrays
Thank you both!

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

> Am 16.01.2024 um 00:36 schrieb Eduardo Moguillansky :
> 
> 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 ]
> 
> On 15.01.24 19:41, Philipp Neumann wrote:
>> 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
>> https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>> 
> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here