loopseg — Generate control signal consisting of linear segments delimited by two or more specified points.
Generate control signal consisting of linear segments delimited by two or more specified points. The entire envelope is looped at kfreq rate. Each parameter can be varied at k-rate.
ksig loopseg kfreq, ktrig, iphase, kvalue0, ktime0 [, kvalue1] [, ktime1] \
[, kvalue2] [, ktime2][...]
iphase -- A value between 0 and 1 to say where to start the loop. Zero, the commonest value, indicates the beginning.
ksig -- Output signal.
kfreq -- Repeat rate in Hz or fraction of Hz.
ktrig -- If non-zero, retriggers the envelope from start (see trigger opcode), before the envelope cycle is completed.
kvalue0...kvalueN -- Values of points
ktime0...ktimeN -- Times between points; expressed in fractions of a cycle (see below). The final time designates a ramp between the final value and the first value.
loopseg opcode is similar to linseg, but the entire envelope is looped at kfreq rate. Notice that times are not expressed in seconds but in fraction of a cycle. Actually each duration represent is proportional to the other, and the entire cycle duration is proportional to the sum of all duration values.
The sum of all duration is then rescaled according to kfreq argument. For example, considering an envelope made up of 3 segments, each segment having 100 as duration value, their sum will be 300. This value represents the total duration of the envelope, and is actually divided into 3 equal parts, a part for each segment.
Actually, the real envelope duration in seconds is determined by kfreq. Again, if the envelope is made up of 3 segments, but this time the first and last segments have a duration of 50, whereas the central segment has a duration of 100 again, their sum will be 200. This time 200 represent the total duration of the 3 segments, so the central segment will be twice as long as the other segments.
All parameters can be varied at k-rate. Negative frequency values are allowed, reading the envelope backward. ktime0 should always be set to 0, except if the user wants some special effect.
Here is an example of the loopseg opcode. Play loopseg.csd
Example 532. Example of the loopseg opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac ;;;realtime audio out ;-iadc ;;;uncomment -iadc if realtime audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o loopseg.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 instr 1 kfreq init p4 ; frequency of loop repetition ifrac = p5 ; frequency ratio of restart triggers ktrig metro kfreq * ifrac ; triggers to restart loop iphase = 0 ; initial phase ; loop of note values (some glissandi) ; val dur val dur etc... knote loopseg kfreq, ktrig, iphase, 40, 1, 40, 0, 43,1,43,0, 49,2,48,0, \ 47,1,47,0, 46,1,46,0, 46,1,47,0, 49,1,49,0, 43,1,43,0, 46,1,46,0, 40,1,39,0 ; loop of filter cutoff values (oct format). This loop, half speed of note loop. kcfoct loopseg kfreq*0.5, ktrig, iphase, 11,2,4,0, 12,1,4,0, 13,1,4,0, \ 11.5,3,4,0, 12.5,1,4,0, 13,2,4,0, 12.5,1,4,0 kenv linseg 0,0.01,1,p3-5.01,1,5,0 ioct = int((rnd(0.999)*4)-2) ; random value either -1, 0 or 1 asig vco2 0.2*kenv,cpsmidinn(knote)*octave(ioct),0 ; sawtooth asig moogladder asig,cpsoct(kcfoct),rnd(0.6) ; filter sawtooth aL,aR pan2 asig,rnd(1) ; random static pan location outs aL, aR endin </CsInstruments> <CsScore> ; 4 layers, each with a different frequency of loop repetition (p4), ; frequency ratio of restart triggers (p5) and pan position (p6). i 1 0 30 0.5 [11/19] i 1 6 30 0.25 [11/13] i 1 12 30 0.125 [11/16] i 1 18 30 1 [11/12] e </CsScore> </CsoundSynthesizer>