Csound: Looping and Triggering Lines 2
- kjcoleman7
- Apr 15, 2018
- 2 min read
Before I get to the stutter toy using Csound, there is one further and more standard method in Csound, of retriggering a line during performance. This is discussed in the chapter 17 of 'The Csound Book' (p.339). This method involves making use of the timout and reinit opcodes. reinit will re-initialise all of the variables and opcodes in an instrument that appear after the label provided as an argument (and before an optional rireturn opcode).
Including a reinit alone does not help us to loop a line, because the line will simply be reinitialised on every control-rate pass and will never output further than the first argument in the opcode. This is demonstrated below.


(Image shows the instrument outputting a value of 3 at control rate)
It is with the inclusion of the timout opcode that we get the opportunity to run a line to its conclusion before resetting it with reinit. The timout opcode will skip to a label from a set time in an instrument's life, and will continue to skip for a set amount of time. In the example below, the timout opcode begins at time 0 in the life of the instrument, and branches the execution to the label 'toline' for one second. After one second the reinit is called and everything under the 'start' label is reset.


(Now the output of the instrument increases over 1 second, as intended)
This is an elegant solution to retriggering a line, and allows the whole process to be contained within a single instrument. Also, because reinit reinitialises the i-rate parameters, the line length can be manipulated during performance. The audio code for the line triggering toy that I made in the first part of this blog can now be simplified into a single instrument:

It is worth noting that the 'sample and hold' effect that occurred in the previous method of triggering (see previous blog), does not occur here. Instead, when the line reaches its end, the line is retriggered from the start and the sample loops. It is also worth noting some behaviour that the mincer opcode displays when the pitch line is allowed to continue beyond its bounds. As mentioned in the previous blog, a line opcode in Csound will not stop counting once it reaches its destination value. As long as it is active it will keep counting at the same rate. In this case the line has counted from 1 to 0.05. If the pitch line is set to take longer than the playback time (speed line) then the pitch line will reach 0 and begin counting down through negative values. A negative value given to the 'pitch' control in the mincer opcode causes the mincer to read the sample backwards with the specified pitch. The sample will therefore be heard to pitch down, and then up again in a reversed state until the time value (provided by the 'speed' control) has passed.
The full code with an interface looks like this:


Here is the resulting tool:
Using reinit, timout, and rireturn allows a line to be looped fairly elegantly, but does behave differently to triggering a line from a separately called instrument, as described in my previous blog.
Next time I will get to using the mincer to create a stutter effect.
Comments