User Guide
DSP Code Component
Hop
There are some calculations that don’t need to be calculated for every sample, it’s sufficient to recalculate for every 4
th
sample say. For this
purpose we have the hop command.
The syntax for the hop command is as follows:
hop(8)
{
< code in here is executed only for every 8
th
sample >
}
Hops must be powers of 2 and the maximum hop length is 4096 so values of 2,4,8,16,32,64,128,256,512,1024,2048 and 4096 are the only
acceptable values.
Loop
Sometimes you need to execute the same code several times, changing one or two parameters on each pass. You can do this in the code
component using the loop command.
Here’s the syntax:
loop(10)
{
< code in here is executed 10 times in succession >
}
You could use a loop to initialise an array for example:
float index;
float buffer[10];
loop(10)
{
buffer[10] = sin1(index);
index = index+0.1;
}
You should take care not to use too many loops or loops with many iterations as they can cause significant increases in cpu. Also for some
loops (like the array initialisation example) you only want them to be executed once, this is where the stages come in.
Stages
The code is split into four parts called stages. These are numbered 0,1,2 and 3.
Stage(0)
Stage(0) runs only for the first sample and is intended for processing that you only want to happen at the very start, usually to set up other
parameters that you will then use on every sample.
For the example we’ve just been looking at we could put the array initialisation into Stage(0) and it will run only once.
Defining the stage is very easy:
stage(0)
{
179 of 212