Cabbage Logo
Back to Cabbage Site

Uninitialized oscili error when using goto

I am trying to understand why I am getting this error

PERF ERROR in instr 1 line 51: oscili: not initialised

I don’t get the error if I have the toneType channel set to one.

instr 1

ktone = chnget("toneType")

if (ktone == 1) then
    goto oscOne
    
elseif (ktone == 2) then
    goto oscTwo
    
elseif (ktone == 3) then
    goto oscThree
    
endif


oscOne:

kEnv1 expsegr 0.0001, .00001, 1, 0.08, 0.7, 3, 0.5, 3, 0.000001
ap1 oscili kEnv1*0.5, 440
goto play

oscTwo:

kEnv1 expsegr 0.0001, .00001, 1, 0.5, 0.8, 3.7, 0.000001
ap1 oscili kEnv1*0.5, 880
goto play

oscThree:

kEnv1 expsegr 0.0001, .00001, 1, 0.97, 0.562, 2.4, 0.000001
ap1 oscili kEnv1*0.5, 1200
goto play

play:
outs ap1, ap1


endin

Why use goto, why not just put the code into the if branches?

Two reasons,

  1. I am still learning different aspects of Csound, so I am trying to use things that I haven’t used before.
  2. I feel it improves readability, at least form me anyway.(The code above is a much shorter version of what i have)

:slightly_smiling_face::slightly_smiling_face::slightly_smiling_face:

it works if you change ktone to itone. you don’t need to evaluate at k-rate

I don’t understand exactly why it work, though :slight_smile:

1 Like

Tha’s a pretty good reason! But I’d still recommend using modern style syntax of if-then. I’ve yet to see goto code that matches the readability of some well placed if/thens. They are definitely a dying breed. Most other languages have wiped them out. They could well be gone from Csound too only for it has a strict backward comptability policy.

Fair enough. You and I both know how pedantic programmers can be about their source code! But I think the following version wins hands down in terms of succintness and readability:

instr 1

ktone = chnget("toneType")

if (ktone == 1) then
    kEnv1 expsegr 0.0001, .00001, 1, 0.08, 0.7, 3, 0.5, 3, 0.000001
    ap1 oscili kEnv1*0.5, 440    
elseif (ktone == 2) then
    kEnv1 expsegr 0.0001, .00001, 1, 0.5, 0.8, 3.7, 0.000001
    ap1 oscili kEnv1*0.5, 880    
elseif (ktone == 3) then
    kEnv1 expsegr 0.0001, .00001, 1, 0.97, 0.562, 2.4, 0.000001
    ap1 oscili kEnv1*0.5, 1200
endif

outs ap1, ap1

endin

It’s because goto is an i-rate opcode. If you’re checking k-rate variables you need to use kgoto.

1 Like

Oh wow, I thought goto was Csound specific, I have never encountered them before.
I guess from the readability side, I am coming from an object-orientated background and am used to functions with code that’s no longer than a couple of lines, so the goto is my version of calling a function :laughing:

Your right tho, when looking at that code the standard if-then does seem much easier to read.
Thanks again Rory :slightly_smiling_face:

The first rule of goto club: you don’t talk about goto! :rofl: