Cabbage Logo
Back to Cabbage Site

Summing oscillators not as expected

Hi,

I have a little problem with an instrument. I summed several detuned oscillators in a loop. I expected to hear a rich chorus sound, but all i get is one single oscillator. This is the simplified code:

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>

sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

seed 0

instr 1
    ;count of oscilators
    icofosc=10
    asum=0
    loop:
        iChorusDetune linrand 2
        asig oscil 1000,440+iChorusDetune,4
        asum+=asig
        icofosc-=1
    if icofosc>0 igoto loop
    out asum
endin

</CsInstruments>
<CsScore>

;GEN07 straight lines
f 4 0 1024 7 1 1024 -1

i1 0 5
e
</CsScore>
</CsoundSynthesizer>

I assume it has something to do with the loop or with the a-rate topic. When I rewrite it in this long manner, it works:

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>

sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

instr 1
    asum=0
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    iChorusDetune linrand 2
    asig oscil 1000,440+iChorusDetune,4
    asum+=asig
    out asum
endin

</CsInstruments>
<CsScore>

;GEN07 straight lines
f 4 0 1024 7 1 1024 -1

i1 0 5
e
</CsScore>
</CsoundSynthesizer>

I could be fine with the second approach, but what if I wanted to use a hundred oscillators? Why does the first example not work? Any help is appreciated.

You might expect that each time the loop is called, a new instance of oscil is created, but this is not the case. What happens is the same oscil instance is simply updated each time. The best way to achieve this is to use a recursive UDO, which will by-pass this limitation by creating unique instances for each oscillator. I’ve attached a simple .csd that should do the trick, although I don’t have access to any speakers right now, so I can’t verify i actually works :joy: You’ll have to let me know :wink:

oscilBank.csd (869 Bytes)

1 Like

Thank you very much, that is very interesting and also a little overwhelming. However, I get a segmentation fault with your example. It must be the if then construct in the UDO. I had that before, that’s why I know. It must have to do with my version of Csound, I read about it in a post. But I guess that is another topic. I will change it to if … igoto, that usually works.

But first I will figure out your example. I will let you know then. It can take some time, if you have no experience with an UDO.

Tell me about it. It’s one of those odd things that somehow became part of the language, but is as confusing as hell! What version of Csound are you using? I think mine is 6.12, the one that ships with Cabbage. Apropos, what version of Cabbage are you using?

Ok, I finally understood your example. I also checked the manual about the UDO. But now it is getting a little strange. I changed if then to if igoto and got a little further in compilation, but not far enough. A new error and segmentation fault occurred: ‘OscBank: not initialised’. This is the input file and the error output, in case you are interested:

oscilBank_v2.csd (652 Bytes)

errmsg.txt (2.2 KB)

My Csound version is 6.10 on Ubuntu 18.04. I don’t use Cabbage, just plain vi. I did a test on Ubuntu Studio 19.04 live with preinstalled Csound 6.12 beta. There your example with if then works fine, my version leads to the same error, but at least without the segmentation fault. Is there any problem with if igoto? I should mention that when I remove the oscili statement it works:

oscilBank_simpletest.csd (430 Bytes)

I detected an issue with the Csound version in Ubuntu Studio which prevents me from switching to it. I’m unable to use the repeat statement ‘r’ in the score section. That leads also to a segmentation fault.

Since this is really demanding I got to take a little break and recover. Maybe you have any idea?

You should probably update your version of Csound. Even if it means building it yourself from source. There is little point spending time trying to find solutions to problems that don’t exist in newer versions?

I found a solution! It has to be goto instead of igoto, I got the answer through this post: http://csound.1045644.n5.nabble.com/Csnd-puzzling-PERF-ERROR-td5750331.html
It jumps now on every pass not only the init pass. It’s a tough topic. Now your example works on my system.

Ubuntu doesn’t allow updating to a higher version. I once tried to compile mplayer, I don’t have good memories about that. Then I’d rather switch the system completely.

Thank you for your tip with the UDO. It really helped.

I’m glad you found a solution, but I’m also happy to try to help you update your version of Csound if you like. If you want to try, follow the instructions here:


And let me know how it goes. 6.10 is already quite old…

Thank you, I’ll keep that in mind. It’s a challenging task for a week or a month or so.

It should only take a few hours max!

I also found an opcode to achieve this : the phasorbnk opcode let you generate multiple moving phases, that you can then use to generate sounds using wavetables for example… That’s the approach I took in my Synthesizer ToneZ

You can see the .csd here

Hope it helps :slight_smile:

1 Like

Thank you. At first sight that seems to me a little more advanced approach, but I’ll need to take a closer look.

1 Like