DSP local variables persist?

DSP related issues, mathematics, processing and techniques
Post Reply
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

DSP local variables persist?

Post 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?
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: DSP local variables persist?

Post by Exo »

Do you have an example? Not sure I understand what you mean.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: DSP local variables persist?

Post 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."
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: DSP local variables persist?

Post 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.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: DSP local variables persist?

Post by Perfect Human Interface »

I see. I believe whenever the schematic recompiles as well.

This should definitely be in the manual.
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: DSP local variables persist?

Post 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).
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: DSP local variables persist?

Post by Perfect Human Interface »

Thanks. I just wish I had known this a long time ago. :?
Post Reply