# Generating weighted sum of tables with GEN18

**URL:** <https://forum.cabbageaudio.com/t/generating-weighted-sum-of-tables-with-gen18/3754>\
**Category:** Cabbage Stew\
**Created:** [5 June 2023 23:49 UTC](https://forum.cabbageaudio.com/t/generating-weighted-sum-of-tables-with-gen18/3754 "2023-06-05T23:49:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ULAlgorithm](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/ulalgorithm/32/4832_2.png) [@ULAlgorithm](https://forum.cabbageaudio.com/u/ULAlgorithm)\
**Post date:** [5 June 2023 23:49 UTC](https://forum.cabbageaudio.com/t/generating-weighted-sum-of-tables-with-gen18/3754/1 "2023-06-05T23:49:09Z")

</div>

Hi everyone,

I’m trying to generate a weighted sum of pre-existing tables from the orchestra.  
For that I’m using ftgen with GEN18, which does nothing but crushes Cabbage. Am I looking in the right direction with it?

The idea is to have an array of weights for 20 tables and mix them like that.  
Here’s the code:

```
instr calculateWeightedTable
    
    ftset 50, 0
    ftset 48, 0
    
    iCounter = 1
    
    while iCounter< lenarray(gSFiles) do
    tablecopy 50, iCounter

    iCurWeight init giWeights[iCounter-1]

    iTabNrA ftgen 48, 0, 2621434, 18, 50, 1, 0, 262143, iCounter, iCurWeight,0,262143
    tablecopy 50, 48
    iCounter += 1
    od
    turnoff
endin  

```

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [6 June 2023 07:58 UTC](https://forum.cabbageaudio.com/t/generating-weighted-sum-of-tables-with-gen18/3754/2 "2023-06-06T07:58:40Z")

</div>

Can you provide me with a complete example? I’ve not used GEN18 before but I can take a look. Btw. have you tried it outside of Cabbage with vanilla Csound? It might be Csound that is causing the problem rather than Cabbage.

---

<div class="post-metadata">

**Author:** ![ULAlgorithm](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/ulalgorithm/32/4832_2.png) [@ULAlgorithm](https://forum.cabbageaudio.com/u/ULAlgorithm)\
**Post date:** [6 June 2023 08:29 UTC](https://forum.cabbageaudio.com/t/generating-weighted-sum-of-tables-with-gen18/3754/3 "2023-06-06T08:29:33Z")

</div>

SOLVED!  
So, for everyone facing the same issue in the future: tablemix opcode does the same job and actually works. The only difference to GEN18 is that it takes only two tables at once. Which in my case is okay, because I sum the tables in loop one after another.

---

<div class="post-metadata">

**Author:** ![ULAlgorithm](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/ulalgorithm/32/4832_2.png) [@ULAlgorithm](https://forum.cabbageaudio.com/u/ULAlgorithm)\
**Post date:** [6 June 2023 08:33 UTC](https://forum.cabbageaudio.com/t/generating-weighted-sum-of-tables-with-gen18/3754/4 "2023-06-06T08:33:20Z")

</div>

Hey Rory,  
There’s not much more happening regarding this snippet. Just a global array of weights plus an instrument call with ‘event’ from another instrument. Haven’t tried it with vanilla, but it seems to me that GEN18 just crushes it.

Thank you for the quick response anyway!  
It’s great to have you supporting newbies!

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [6 June 2023 08:38 UTC](https://forum.cabbageaudio.com/t/generating-weighted-sum-of-tables-with-gen18/3754/5 "2023-06-06T08:38:34Z")

</div>

There wasn’t much support dished out here, you figure it out on your own 🙂 Btw, there is also the [ftmorph](https://csound.com/docs/manual/ftmorf.html) opcode. He’s an example of it using [p5js and Csound](https://rorywalsh.github.io/p5.Csound/#/examples/table_synth).
