Page 1 of 1
DSP local variables persist?
Posted: Mon Aug 18, 2014 4:53 am
by Perfect Human Interface
I thought local variables in DSP code were initialized at every tick (to 0 if not explicitly). What I'm looking at right now suggests otherwise. Do variable states in DSP code blocks persist indefinitely?
Re: DSP local variables persist?
Posted: Mon Aug 18, 2014 6:29 am
by Exo
Do you have an example? Not sure I understand what you mean.
Re: DSP local variables persist?
Posted: Mon Aug 18, 2014 6:42 am
by Perfect Human Interface
Code: Select all
streamout x;
float y = 0;
y = y + 1;
x = y;
Here y increases indefinitely. I thought local variables were initialized every step, at audio rate. So my expected output to this code before now would have been a constant "1."
Re: DSP local variables persist?
Posted: Mon Aug 18, 2014 6:48 am
by Exo
Ah see what you mean.
No all variables are initialized on the start of the process.
So for poly the variable is initialized for every new voice, for mono it will be initialized when you turn direct sound/asio on.
Re: DSP local variables persist?
Posted: Mon Aug 18, 2014 9:03 am
by Perfect Human Interface
I see. I believe whenever the schematic recompiles as well.
This should definitely be in the manual.
Re: DSP local variables persist?
Posted: Mon Aug 18, 2014 12:10 pm
by KG_is_back
Variables are initialized when the stream is created and that is immediately followed by stage(0). For poly, that means when the note starts to play. For mono when you turn on your soundcard, or cause recompile (by selector or clear audio prim), for signal analyzer, when it receives a trigger. It wouldn't make much sense if the variables didn't persist between samples - how would you do delays? and code blocks that use buffers?
However I noticed, that sometimes when you turn mono stream off with a selector, it simply pauses and continues where it was when you turn it back on (doesn't recompiles/resets).
Re: DSP local variables persist?
Posted: Mon Aug 18, 2014 12:23 pm
by Perfect Human Interface
Thanks. I just wish I had known this a long time ago.
