The init
block is an optional block that takes care of initializing and storing all variables that might be needed in your algorithm. This is also where the creation of any struct
(more on them later) should happen.
-
Here
myVariable
is created in theinit
block and passed over thesample
block (more on it later).myVariable
can then be accessed and modified in thesample
block, creating an increasing ramp over one second that goes from 0 tosamplerate
(samplerate
is a keyword to retrieve the current system samplerate).init: myVariable = 0 sample: out1 = myVariable myVariable = (myVariable + 1) % samplerate
-
This is a slightly more complex example that shows the use of memory allocation via the creation of a
Delay
(more on it later). Here is also used thebuild
block, which only passes specific variables tosample
, asinit
passes by default all declared variables in its scope.ins: input params: delayTime {0.5, 0, 1} init: myDelay = Delay(samplerate) #the build block only passes specific variables to perform/sample build: myDelay sample: #write input to the delay line myDelay.write(input) #input + read of the delay line, using the delayTime param as a delay time control outVal = (input * 0.5) + (myDelay.read(delayTime * samplerate) * 0.5) out1 = outVal