User Guide

DSP Code Component
< code in here is executed only for the first sample >
}
Stage(2)
We'll jump to Stage(2) now because this is the default stage. Any code written outside of a Stage definition is assumed to be Stage(2).
Stage(2) code is executed for every sample (including the first) and happens after Stage(0).
Stage(1) and Stage(3)
These two stages are only used for implementing delays. They are needed to make sure that data flows correctly when one or more delays
are chained together in a feedback loop.
The software executes the code in stage order so after Stage(0) Stage(1) goes next.
Stage(1) should be used to move data from internal variables (most likely a buffer) and the outputs. This ensures that all delays have a
consistent output value before doing any calculations.
Next the standard Stage(2) is executed. Any code that needs the outputs of any delays will have the values they need now.
Finally Stage(3) is executed. This should be used to move data from the inputs to internal variables (again most likely a buffer) and perform
any calculations.
Note that each stage is executed for the whole of the schematic before proceeding to the next stage.
An example of how to use Stage(1 ) and Stage(3) for a delay is shown below.
streamin in;
streamout out;
streamin delay;
float mem[44100];
float index;
stage(1)
{
out = mem[index];
}
stage(3)
{
mem[index] = in;
index = index + 1;
index = (index<delay)&index;
}
Note that because the transfer to outputs in Stage(1) occurs before the buffer update in Stage(3) this will always produce a minimum of 1
sample delay. If you need a delay that will work correctly when the input delay length is zero samples then you can implement this by
modifying the above code as follows:
stage(1)
{
out = mem[index]&(delay>0) + in&(delay==0);
}
.
180 of 212