User Guide

DSP Code Component
Advanced Features
Arrays
You can declare arrays in the code component. These act as buffers that you can use for storing past values for example or for using as a
lookup table.
An array is declared as follows:
float buffer[100];
This defines an array called buffer which is 100 floats (4x100=400 bytes) in size.
Initialising
By default all the entries in the array are set to zero. You have two other options for initialising an array:
1. Set all entries to a particular value
float buffer[100] = 0.62;
2. Randomise the contents of the array
float buffer[100] = rand(-0.5,0.5);
Accessing
To access a particular entry in an array use the array specifiers (square brackets) ‘[‘ and ‘]’.
out = buffer[25] ;
buffer[6] = 3.14159;
Note that the array index is zero based so in the example above buffer[0] would be the first entry and buffer[99] would be the last entry in the
array.
You must make sure that you use indexes that are within range for the array, failure to do so will produce unpredictable results and could
even crash the software.
Mem Input
You can access data from external Mem components direclty in the code component. Once declared they behave exactly like arrays.
A mem input is declared as follows:
memin sound[1000];
This will create a Mem type connector on the component so that you can pass in data from outside. You need to specify a maximum size for
the mem data this is so that enough space is reserved for mem data in the compiled code. Whilst Mems do know their size we don't want to
be recompiling every time a mem changes so by declaring a maximum from the outset the Mem size can change dynamically without
affecting anything.
The above declaration would allow for Mems that are 4 x 1000 bytes in size. If you pass in a Mem that is larger it will get truncated.
178 of 212