[Csnd] ga-woes

Hi everyone :slight_smile:

I have a situation in which my global a-variables don’t behave as I expected them to.
I’m sure I might misunderstand some aspect of their general behaviour, maybe someone can help?

In the following example, instr 10 is creating a ramp to either 1 or 0.
I need the variable ga_tester to stay on its value until the next time instr 10 is being called.
Alas, it doesn’t. In fact, it changes all the time.

What am I missing here?

sr = 44100
0dbfs = 1
nchnls = 1

ga_tester init 0
giramp = .01

instr 10
p3=giramp
ga_tester linseg 1-p4, p3, p4
endin

instr 81
asine poscil 1, 200
aout = asine * ga_tester
out aout
endin

i10 1 1 1
i10 3 1 0

i81 0 5

Adding a printk, I see ga_tester climbing to 1 after 1 sec, staying at that value, then climbing down to zero,
as expected. I hear it too.

Hi!
That’s exactly what I expected, but for some reaaon in my case ga_tester is oscillating rather weirdly all the time.
I went back to 6.18 to see if there’s any difference but there isn’t.

M

The value of ga_tester is steady here, tested on 6.18. Can you give printout showing the issue? You can add printk 0, ga_tester to instr 81.

Prof. Victor Lazzarini
Maynooth University
Ireland

Hi!

I am afraid that doesn’t illustrate the issue for me because
the “weird oscillation” happens over exactly one k-cycle so that at every prrink-readout the values are ok.
ksmps = 1 solves the issue (but is not possible in my situation).

This is what the signal looks like after supposedly going back to zero:

[

linetest.png
dropbox.com

favicon.ico

](https://www.dropbox.com/scl/fi/w5t9y3860pgadyz8wcxfa/linetest.png?rlkey=bpd179vt9eedhhxwlprx5uaxf&dl=0)

I can see the “oscillations” also. Without looking at the source I assume that the offending part is changing p3 and its effects on linseg. This modification gets rid of the oscillations:

instr 10
ga_tester linseg 1-p4, giramp, p4
if eventtime() > giramp then
turnoff
endif
endin

favicon.png

ah, ok but ga_tester does not change, it is the same block of ksmps that was last generated. The block may not have a single value sample, but a ramp, and that’s what you see oscillating. The way to guarantee a single value at the end is to make sure the envelope stops ramping up before the instrument stops generating it.

Prof. Victor Lazzarini
Maynooth University
Ireland

Wow, ok, thanks a lot for that explanation!

Like this it works now:

sr = 44100
0dbfs = 1
nchnls = 1
ksmps = 32

ga_tester init 0
giramp = .01

instr 10
p3=giramp
ga_tester linseg 1-p4, p3-1/kr, p4, 1/kr, p4
endin

instr 81
asine poscil 1, 200
aout = asine * ga_tester
printk 0, k(ga_tester )
out aout
endin

i10 1 1 1
i10 3 1 0

i81 0 5