12.07.2015 Views

Csound Reference Manual in PDF Format

Csound Reference Manual in PDF Format

Csound Reference Manual in PDF Format

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ContributorsIn addition to the core code developed by Barry Vercoe at MIT, a large part of the <strong>Csound</strong> codewas modified, developed and extended by an <strong>in</strong>dependent group of programmers, composers andscientists. Copyright to this code is held by the respective authors:Mike BerryEli BrederMichael CaseyMichael ClarkPerry CookSean CostelloRichard DobsonMark DolsonRasmus EkmanDan EllisTom ErbeJohn ffitchBill GardnerMatt IngallsRichard KarpenVictor Lazzar<strong>in</strong>iAllan LeeDavid Mac<strong>in</strong>tyreGabriel MaldonadoMax MathewsHans MikelsonPeter NeubäckerVille PulkkiMarc ResiboisRob ShawParis SmaragdisGreg SullivanBill VerplankRob<strong>in</strong> WhittleThis manual was compiled from the canonical <strong>Csound</strong> <strong>Manual</strong> sources ma<strong>in</strong>ta<strong>in</strong>ed by Johnffitch, Richard Boulanger, Jean Piché and David Boothe.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page iii


Table of ContentsCopyright Notice.............................................................................................................................................................iiContributors................................................................................................................................................................... iiiTable of Contents ............................................................................................................................................................vF<strong>in</strong>der .. ....................................................................................................................................................................xv1 Preface ............................................................................................................................1-11.1 Where to Get Public <strong>Csound</strong> and the <strong>Csound</strong> <strong>Manual</strong> ............................................................................... 1-31.2 How to Install <strong>Csound</strong> ................................................................................................................................ 1-41.3 How to use the <strong>Csound</strong> <strong>Manual</strong>.................................................................................................................. 1-81.4 The <strong>Csound</strong> Mail<strong>in</strong>g List............................................................................................................................ 1-92 Syntax of the Orchestra ..................................................................................................2-12.1 Directories and Files ................................................................................................................................... 2-22.2 Nomenclature.............................................................................................................................................. 2-32.3 Orchestra Statement Types ......................................................................................................................... 2-62.4 Constants and Variables ............................................................................................................................. 2-72.5 Expressions ................................................................................................................................................. 2-93 Orchestra Syntax: Orchestra Header Statements............................................................3-13.1 sr, kr, ksmps, nchnls ................................................................................................................................... 3-13.2 strset, pset.................................................................................................................................................... 3-23.3 seed ............................................................................................................................................................. 3-33.4 ftgen ............................................................................................................................................................ 3-43.5 massign, ctrl<strong>in</strong>it........................................................................................................................................... 3-54 Orchestra Syntax: Instrument Block Statements............................................................4-14.1 <strong>in</strong>str, end<strong>in</strong> .................................................................................................................................................. 4-15 Orchestra Syntax: Variable Initialization .......................................................................5-15.1 =, <strong>in</strong>it, tival, divz......................................................................................................................................... 5-16 Instrument Control: Instrument Invocation ....................................................................6-16.1 schedule, schedwhen................................................................................................................................... 6-16.2 schedkwhen................................................................................................................................................. 6-36.3 turnon .......................................................................................................................................................... 6-47 Instrument Control: Duration Control Statements..........................................................7-17.1 ihold, turnoff ............................................................................................................................................... 7-18 Instrument Control: Real-time Performance Control .....................................................8-18.1 active........................................................................................................................................................... 8-18.2 cpuprc, maxalloc, prealloc.......................................................................................................................... 8-2The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page v


9 Instrument Control: Time Read<strong>in</strong>g.................................................................................9-19.1 timek, times, time<strong>in</strong>stk, time<strong>in</strong>sts ............................................................................................................... 9-110 Instrument Control: Clock Control...............................................................................10-110.1 clockon, clockoff, readclock..................................................................................................................... 10-111 Instrument Control: Sens<strong>in</strong>g and Control.....................................................................11-111.1 pitch .......................................................................................................................................................... 11-111.2 pitchamdf .................................................................................................................................................. 11-311.3 tempest ...................................................................................................................................................... 11-511.4 follow ........................................................................................................................................................ 11-711.5 trigger........................................................................................................................................................ 11-811.6 peak........................................................................................................................................................... 11-911.7 xy<strong>in</strong>, tempo ............................................................................................................................................. 11-1011.8 follow2 .................................................................................................................................................... 11-1112 Instrument Control: Conditional Values ......................................................................12-112.1 >, =,


21 Mathematical Functions: Opcode Equivalents of Functions........................................21-121.1 sum............................................................................................................................................................ 21-121.2 product ...................................................................................................................................................... 21-221.3 pow............................................................................................................................................................ 21-321.4 tan<strong>in</strong>v2 ...................................................................................................................................................... 21-521.5 mac, maca ................................................................................................................................................. 21-622 Pitch Converters: Functions .........................................................................................22-122.1 octpch, pchoct, cpspch, octcps, cpsoct ..................................................................................................... 22-123 Pitch Converters: Tun<strong>in</strong>g Opcodes...............................................................................23-123.1 cps2pch, cpsxpch ...................................................................................................................................... 23-124 MIDI Support: Converters............................................................................................24-124.1 notnum, veloc, cpsmidi, cpsmidib, octmidi, octmidib, pchmidi, pchmidib, ampmidi, aftouch, pchbend,midictrl...................................................................................................................................................... 24-124.2 cpstmid...................................................................................................................................................... 24-325 MIDI Support: Controller Input ...................................................................................25-125.1 <strong>in</strong>itc7, <strong>in</strong>itc14, <strong>in</strong>itc21 ............................................................................................................................... 25-125.2 midic7, midic14, midic21, ctrl7, ctrl14, ctrl21......................................................................................... 25-225.3 chanctrl...................................................................................................................................................... 25-426 MIDI Support: Slider Banks.........................................................................................26-126.1 slider8, slider16, slider32, slider64, slider8f, slider16f, slider32f, slider64f, s16b14, s32b14 ................ 26-127 MIDI Support: Generic I/O ..........................................................................................27-127.1 midi<strong>in</strong> ........................................................................................................................................................ 27-127.2 midiout...................................................................................................................................................... 27-228 MIDI Support: Note-on/Note-off .................................................................................28-128.1 noteon, noteoff, noteondur, noteondur2 ................................................................................................... 28-128.2 moscil, midion .......................................................................................................................................... 28-328.3 midion2 ..................................................................................................................................................... 28-429 MIDI Support: MIDI Message Output .........................................................................29-129.1 outic, outkc, outic14, outkc14, outipb, outkpb, outiat, outkat, outipc, outkpc, outipat, outkpat.............. 29-129.2 nrpn ........................................................................................................................................................... 29-329.3 mdelay....................................................................................................................................................... 29-430 MIDI Support: Real-time Messages.............................................................................30-130.1 mclock, mrtmsg ........................................................................................................................................ 30-131 MIDI Support: Event Extenders...................................................................................31-131.1 xtratim, release.......................................................................................................................................... 31-1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page vii


32 Signal Generators: L<strong>in</strong>ear and Exponential Generators ...............................................32-132.1 l<strong>in</strong>e, expon, l<strong>in</strong>seg, l<strong>in</strong>segr, expseg, expsegr, expsega.............................................................................. 32-132.2 adsr, madsr, xadsr, mxadsr ....................................................................................................................... 32-333 Signal Generators: Table Access..................................................................................33-133.1 table, tablei, table3, oscil1, oscil1i, osciln ................................................................................................ 33-134 Signal Generators: Phasors...........................................................................................34-134.1 phasor........................................................................................................................................................ 34-134.2 phasorbnk.................................................................................................................................................. 34-235 Signal Generators: Basic Oscillators ............................................................................35-135.1 oscil, oscili, oscil3..................................................................................................................................... 35-135.2 poscil, poscil3 ........................................................................................................................................... 35-335.3 lfo .............................................................................................................................................................. 35-436 Signal Generators: Dynamic Spectrum Oscillators......................................................36-136.1 buzz, gbuzz ............................................................................................................................................... 36-136.2 vco............................................................................................................................................................. 36-337 Signal Generators: Additive Synthesis/Resynthesis.....................................................37-137.1 adsyn ......................................................................................................................................................... 37-137.2 adsynt ........................................................................................................................................................ 37-337.3 hsboscil ..................................................................................................................................................... 37-538 Signal Generators: FM Synthesis .................................................................................38-138.1 foscil, foscili.............................................................................................................................................. 38-138.2 fmvoice ..................................................................................................................................................... 38-238.3 fmbell, fmrhode, fmwurlie, fmmetal, fmb3, fmpercfl............................................................................. 38-339 Signal Generators: Sample Playback............................................................................39-139.1 loscil, loscil3 ............................................................................................................................................. 39-139.2 lposcil, lposcil3 ......................................................................................................................................... 39-339.3 sfload, sfplist, sfilist, sfpassign, sfpreset, sfplay, sfplaym, sf<strong>in</strong>str, sf<strong>in</strong>strm ............................................ 39-440 Signal Generators: Granular Synthesis.........................................................................40-140.1 fof, fof2 ..................................................................................................................................................... 40-140.2 fog ............................................................................................................................................................. 40-340.3 gra<strong>in</strong> .......................................................................................................................................................... 40-540.4 granule ...................................................................................................................................................... 40-740.5 sndwarp, sndwarpst................................................................................................................................. 40-1041 Signal Generators: Scanned Synthesis .........................................................................41-141.1 scanu ......................................................................................................................................................... 41-341.2 scans.......................................................................................................................................................... 41-5The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page viii


42 Signal Generators: Waveguide Physical Model<strong>in</strong>g......................................................42-142.1 pluck.......................................................................................................................................................... 42-142.2 wgpluck..................................................................................................................................................... 42-342.3 repluck, wgpluck2..................................................................................................................................... 42-442.4 wgbow....................................................................................................................................................... 42-542.5 wgflute ...................................................................................................................................................... 42-642.6 wgbrass ..................................................................................................................................................... 42-842.7 wgclar........................................................................................................................................................ 42-942.8 wgbowedbar............................................................................................................................................ 42-1143 Signal Generators: Models and Emulations .................................................................43-143.1 moog ......................................................................................................................................................... 43-143.2 shaker ........................................................................................................................................................ 43-243.3 marimba, vibes.......................................................................................................................................... 43-343.4 mandol ...................................................................................................................................................... 43-543.5 gogobel...................................................................................................................................................... 43-643.6 voice.......................................................................................................................................................... 43-743.7 lorenz ........................................................................................................................................................ 43-843.8 planet....................................................................................................................................................... 43-1043.9 cabasa, crunch, sekere, sandpaper, stix................................................................................................... 43-1243.10 guiro, tambour<strong>in</strong>e, bamboo, dripwater, sleighbells ................................................................................ 43-1444 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) ......................................................44-144.1 pvoc, vpvoc............................................................................................................................................... 44-144.2 pvread, pvbufread, pv<strong>in</strong>terp, pvcross, tableseg, tablexseg ....................................................................... 44-344.3 pvadd......................................................................................................................................................... 44-645 Signal Generators: LPC Resynthesis............................................................................45-145.1 lpread, lpreson, lpfreson ........................................................................................................................... 45-145.2 lpslot, lp<strong>in</strong>terp ........................................................................................................................................... 45-346 Signal Generators: Random (Noise) Generators ..........................................................46-146.1 rand, randh, randi...................................................................................................................................... 46-146.2 x-class noise generators ............................................................................................................................ 46-246.3 p<strong>in</strong>kish....................................................................................................................................................... 46-447 Function Table Control: Table Queries........................................................................47-147.1 ftlen, ftlptim, ftsr, nsamp .......................................................................................................................... 47-147.2 tableng....................................................................................................................................................... 47-348 Function Table Control: Table Selection......................................................................48-148.1 tablekt, tableikt.......................................................................................................................................... 48-149 Function Table Control: Read/Write Operations..........................................................49-149.1 tableiw, tablew, tablewkt .......................................................................................................................... 49-149.2 tablegpw, tablemix, tablecopy, tableigpw, tableimix, tableicopy ............................................................ 49-449.3 tablera, tablewa ......................................................................................................................................... 49-6The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page ix


50 Signal Modifiers: Standard Filters................................................................................50-150.1 port, portk, tone, tonek, atone, atonek, reson, resonk, areson, aresonk.................................................... 50-150.2 tonex, atonex, resonx ................................................................................................................................ 50-350.3 resonr, resonz............................................................................................................................................ 50-450.4 resony........................................................................................................................................................ 50-750.5 lowres, lowresx ......................................................................................................................................... 50-950.6 vlowres.................................................................................................................................................... 50-1050.7 lowpass2.................................................................................................................................................. 50-1150.8 biquad, rezzy, moogvcf........................................................................................................................... 50-1350.9 svfilter ..................................................................................................................................................... 50-1550.10 hilbert ...................................................................................................................................................... 50-1750.11 butterhp, butterlp, butterbp, butterbr....................................................................................................... 50-2150.12 filter2, zfilter2 ......................................................................................................................................... 50-2251 Signal Modifiers: Specialized Filters ...........................................................................51-151.1 nlfilt........................................................................................................................................................... 51-151.2 pareq.......................................................................................................................................................... 51-351.3 dcblock...................................................................................................................................................... 51-552 Signal Modifiers: Envelope Modifiers .........................................................................52-152.1 l<strong>in</strong>en, l<strong>in</strong>enr, envlpx, envlpxr.................................................................................................................... 52-153 Signal Modifiers: Amplitude Modifiers .......................................................................53-153.1 rms, ga<strong>in</strong>, balance ..................................................................................................................................... 53-153.2 dam............................................................................................................................................................ 53-253.3 clip ............................................................................................................................................................ 53-354 Signal Modifiers: Signal Limiters ................................................................................54-154.1 limit, mirror, wrap..................................................................................................................................... 54-155 Signal Modifiers: Delay ...............................................................................................55-155.1 delayr, delayw, delay, delay1 ................................................................................................................... 55-155.2 deltap, deltapi, deltapn, deltap3 ................................................................................................................ 55-355.3 multitap ..................................................................................................................................................... 55-555.4 vdelay, vdelay3 ......................................................................................................................................... 55-656 Signal Modifiers: Reverberation ..................................................................................56-156.1 comb, alpass, reverb.................................................................................................................................. 56-156.2 reverb2, nreverb........................................................................................................................................ 56-356.3 nestedap .................................................................................................................................................... 56-457 Signal Modifiers: Waveguides .....................................................................................57-157.1 wguide1, wguide2..................................................................................................................................... 57-157.2 streson ....................................................................................................................................................... 57-3The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page x


58 Signal Modifiers: Special Effects.................................................................................58-158.1 harmon ...................................................................................................................................................... 58-158.2 flanger ....................................................................................................................................................... 58-358.3 distort1 ...................................................................................................................................................... 58-458.4 phaser1, phaser2........................................................................................................................................ 58-659 Signal Modifiers: Convolution and Morph<strong>in</strong>g .............................................................59-159.1 convolve.................................................................................................................................................... 59-159.2 cross2 ........................................................................................................................................................ 59-460 Signal Modifiers: Pann<strong>in</strong>g and Spatialization ..............................................................60-160.1 pan............................................................................................................................................................. 60-160.2 locsig, locsend........................................................................................................................................... 60-360.3 space, spsend, spdist ................................................................................................................................. 60-560.4 hrtfer.......................................................................................................................................................... 60-960.5 vbapls<strong>in</strong>it, vbap4, vbap8, vbap16, vbap4move, vbap8move, vbap16move, vbapz, vbapzmove........... 60-1161 Signal Modifiers: Sample Level Operators ..................................................................61-161.1 samphold, downsamp, upsamp, <strong>in</strong>terp, <strong>in</strong>teg, diff.................................................................................... 61-161.2 ntrpol......................................................................................................................................................... 61-361.3 fold ............................................................................................................................................................ 61-462 Zak Patch System .........................................................................................................62-162.1 zak<strong>in</strong>it........................................................................................................................................................ 62-262.2 ziw, zkw, zaw, ziwm, zkwm, zawm ......................................................................................................... 62-362.3 zir, zkr, zar, zarg ....................................................................................................................................... 62-562.4 zkmod, zamod, zkcl, zacl......................................................................................................................... 62-663 Operations Us<strong>in</strong>g Spectral Data Types.........................................................................63-163.1 specaddm, specdiff, specscal, spechist, specfilt ....................................................................................... 63-263.2 specptrk..................................................................................................................................................... 63-363.3 specsum, specdisp..................................................................................................................................... 63-563.4 spectrum.................................................................................................................................................... 63-664 Signal Input and Output: Input .....................................................................................64-164.1 <strong>in</strong>, <strong>in</strong>s, <strong>in</strong>q, <strong>in</strong>h, <strong>in</strong>o, sound<strong>in</strong>, disk<strong>in</strong>......................................................................................................... 64-164.2 <strong>in</strong>x, <strong>in</strong>32, <strong>in</strong>ch, <strong>in</strong>z .................................................................................................................................... 64-365 Signal Input and Output: Output ..................................................................................65-165.1 soundout, soundouts, out, outs1, outs2, outs, outq1, outq2, outq3, outq4, outq, outh, outo .................... 65-165.2 outx, out32, outc, outch, outz ................................................................................................................... 65-366 Signal Input and Output: File I/O.................................................................................66-166.1 dumpk, dumpk2, dumpk3, dumpk4, readk, readk2, readk3, readk4 ........................................................ 66-166.2 fout, foutk, fouti, foutir, fiopen................................................................................................................. 66-366.3 f<strong>in</strong>, f<strong>in</strong>k, f<strong>in</strong>i.............................................................................................................................................. 66-566.4 v<strong>in</strong>cr, clear ................................................................................................................................................ 66-6The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page xi


67 Signal Input and Output: Sound File Queries...............................................................67-167.1 filelen, filesr, filenchnls, filepeak ............................................................................................................. 67-168 Signal Input and Output: Pr<strong>in</strong>t<strong>in</strong>g and Display ............................................................68-168.1 pr<strong>in</strong>t, display, dispfft................................................................................................................................. 68-168.2 pr<strong>in</strong>tk, pr<strong>in</strong>tks............................................................................................................................................ 68-268.3 pr<strong>in</strong>tk2....................................................................................................................................................... 68-469 The Standard Numeric Score........................................................................................69-169.1 Preprocess<strong>in</strong>g of Standard Scores............................................................................................................. 69-169.2 Next-P and Previous-P Symbols............................................................................................................... 69-369.3 Ramp<strong>in</strong>g.................................................................................................................................................... 69-469.4 Score Macros ............................................................................................................................................ 69-569.5 Multiple File Score ................................................................................................................................... 69-769.6 Evaluation of Expressions ........................................................................................................................ 69-869.7 f Statement (or Function Table Statement)............................................................................................... 69-969.8 i Statement (Instrument or Note Statement) ........................................................................................... 69-1169.9 a Statement (or Advance Statement) ...................................................................................................... 69-1569.10 t Statement (Tempo Statement) .............................................................................................................. 69-1669.11 b Statement ............................................................................................................................................. 69-1769.12 v Statement ............................................................................................................................................. 69-1869.13 s Statement.............................................................................................................................................. 69-1969.14 e Statement.............................................................................................................................................. 69-2069.15 r Statement (Repeat Statement) .............................................................................................................. 69-2169.16 m Statement (Mark Statement)............................................................................................................... 69-2269.17 n Statement ............................................................................................................................................. 69-2370 GEN Rout<strong>in</strong>es...............................................................................................................70-170.1 GEN01 ...................................................................................................................................................... 70-270.2 GEN02 ...................................................................................................................................................... 70-470.3 GEN03 ...................................................................................................................................................... 70-570.4 GEN04 ...................................................................................................................................................... 70-670.5 GEN05, GEN07........................................................................................................................................ 70-770.6 GEN06 ...................................................................................................................................................... 70-870.7 GEN08 ...................................................................................................................................................... 70-970.8 GEN09, GEN10, GEN19........................................................................................................................ 70-1070.9 GEN11 .................................................................................................................................................... 70-1170.10 GEN12 .................................................................................................................................................... 70-1270.11 GEN13, GEN14...................................................................................................................................... 70-1370.12 GEN15 .................................................................................................................................................... 70-1570.13 GEN17 .................................................................................................................................................... 70-1670.14 GEN20 .................................................................................................................................................... 70-1770.15 GEN21 .................................................................................................................................................... 70-1970.16 GEN23 .................................................................................................................................................... 70-2070.17 GEN25, GEN27...................................................................................................................................... 70-21The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page xii


70.18 GEN28 .................................................................................................................................................... 70-2271 The <strong>Csound</strong> Command .................................................................................................71-171.1 Order of Precedence.................................................................................................................................. 71-171.2 Generic Flags ............................................................................................................................................ 71-171.3 PC W<strong>in</strong>dows Specific flags ...................................................................................................................... 71-271.4 Mac<strong>in</strong>tosh Specific Flags.......................................................................................................................... 71-371.5 Description................................................................................................................................................ 71-372 Unified File <strong>Format</strong> for Orchestras and Scores............................................................72-172.1 Description................................................................................................................................................ 72-172.2 Structured Data File <strong>Format</strong> ..................................................................................................................... 72-172.3 Command L<strong>in</strong>e Parameter File................................................................................................................. 72-273 Score File Preprocess<strong>in</strong>g ..............................................................................................73.173.1 The Extract Feature....................................................................................................................................73.173.2 Independent Pre-Process<strong>in</strong>g with Scsort ...................................................................................................73.274 Utility Programs ...........................................................................................................74-174.1 snd<strong>in</strong>fo ...................................................................................................................................................... 74-374.2 hetro .......................................................................................................................................................... 74-474.3 lpanal......................................................................................................................................................... 74-674.4 pvanal........................................................................................................................................................ 74-874.5 cvanal ...................................................................................................................................................... 74-1074.6 pvlook ..................................................................................................................................................... 74-1175 Cscore ...........................................................................................................................75.175.1 Events, Lists, and Operations ....................................................................................................................75.275.2 Writ<strong>in</strong>g a Ma<strong>in</strong> Program............................................................................................................................75.475.3 More Advanced Examples.......................................................................................................................75.1075.4 Compil<strong>in</strong>g a Cscore Program...................................................................................................................75.1376 Add<strong>in</strong>g your own Cmodules to <strong>Csound</strong> .......................................................................76-177 Appendix A: Miscellaneous Information .....................................................................77-177.1 Pitch Conversion....................................................................................................................................... 77-177.2 Sound Intensity Values (for a 1000 Hz tone) ........................................................................................... 77-277.3 Formant Values......................................................................................................................................... 77-377.4 W<strong>in</strong>dow Functions.................................................................................................................................... 77-677.5 SoundFont2 File <strong>Format</strong> ......................................................................................................................... 77-1077.6 Pr<strong>in</strong>t Edition Update Procedure.............................................................................................................. 77-1177.7 <strong>Manual</strong> Update History........................................................................................................................... 77-12The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page xiii


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page xiv


F<strong>in</strong>derSymbols- .................................. 16-1!=................................. 12-1#def<strong>in</strong>e(orc)................. 13-1#def<strong>in</strong>e(sco) ................ 69-5#<strong>in</strong>clude(orc)............... 13-4#<strong>in</strong>clude(sco)............... 69-7#undef(orc) ................. 13-1#undef(sco) ................. 69-5$NAME(orc)............... 13-1$NAME(sco)............... 69-5%................................. 16-1&&.............................. 16-1( .................................. 69-4) .................................. 69-4* .................................. 16-1/ .................................. 16-1? .................................. 12-1@................................. 69-8@@............................. 69-8^ .................................. 16-1{ .................................. 69-4|| .................................. 16-1} .................................. 69-4~ .................................. 69-4+(orc) .......................... 16-1


ihold.............................. 7-1<strong>in</strong> ................................. 64-1<strong>in</strong>32 ............................. 64-3<strong>in</strong>ch ............................. 64-3<strong>in</strong>h ............................... 64-1<strong>in</strong>it................................. 5-1<strong>in</strong>itc14 ......................... 25-1<strong>in</strong>itc21 ......................... 25-1<strong>in</strong>itc7 ........................... 25-1<strong>in</strong>o ............................... 64-1<strong>in</strong>q ............................... 64-1<strong>in</strong>s................................ 64-1<strong>in</strong>str ............................... 4-1<strong>in</strong>t................................ 17-1<strong>in</strong>teg ............................ 61-1<strong>in</strong>terp........................... 61-1<strong>in</strong>x ............................... 64-3<strong>in</strong>z ............................... 64-3Kkgoto ........................... 14-1kr................................... 3-1ksmps............................ 3-1Llfo................................ 35-4limit............................. 54-1l<strong>in</strong>e .............................. 32-1l<strong>in</strong>en ............................ 52-1l<strong>in</strong>enr........................... 52-1l<strong>in</strong>rand......................... 46-2l<strong>in</strong>seg........................... 32-1l<strong>in</strong>segr ......................... 32-1locsend........................ 60-3locsig........................... 60-3log ............................... 17-1log10 ........................... 17-1logbtwo ....................... 17-2lorenz .......................... 43-8loscil............................ 39-1loscil3.......................... 39-1lowpass2 ................... 50-11lowres.......................... 50-9lowresx........................ 50-9lpanal .......................... 74-6lpfreson ....................... 45-1lp<strong>in</strong>terp........................ 45-3lposcil.......................... 39-3lposcil3........................ 39-3lpread .......................... 45-1lpreson ........................ 45-1lpslot ........................... 45-3Mm Statement .............. 69-22mac.............................. 21-6maca............................ 21-6macros, orchestra ........ 13-1madsr .......................... 32-3mandol ........................ 43-5marimba ...................... 43-3massign ......................... 3-5maxalloc........................ 8-2mclock ........................ 30-1mdelay ........................ 29-4MIDI sliders................ 26-1midic14 .......................25-2midic21 .......................25-2midic7 .........................25-2midictrl........................24-1midi<strong>in</strong> ..........................27-1midion .........................28-3midion2 .......................28-4midiout ........................27-2mirror ..........................54-1moog ...........................43-1moogvcf ....................50-13moscil..........................28-3mrtmsg ........................30-1multiple files, orchestra.........................................13-4multiple files, score.....69-7multitap .......................55-5mxadsr.........................32-3Nn Statement................69-23nchnls ............................3-1nestedap.......................56-4nlfilt.............................51-1noteoff.........................28-1noteon..........................28-1noteondur ....................28-1noteondur2 ..................28-1notnum ........................24-1np.................................69-4nreverb ........................56-3nrpn .............................29-3nsamp ..........................47-1ntrpol...........................61-3Ooctcps ..........................22-1octmidi ........................24-1octmidib ......................24-1octpch..........................22-1oscil.............................35-1oscil1...........................33-1oscil1i..........................33-1oscil3...........................35-1oscili............................35-1osciln...........................33-1out ...............................65-1out32 ...........................65-3outc..............................65-3outch............................65-3outh .............................65-1outiat ...........................29-1outic.............................29-1outic14.........................29-1outipat .........................29-1outipb ..........................29-1outipc...........................29-1outkat...........................29-1outkc............................29-1outkc14........................29-1outkpat.........................29-1outkpb .........................29-1outkpc..........................29-1outo .............................65-1outq .............................65-1outq1 ...........................65-1outq2 ...........................65-1outq3 ...........................65-1outq4 ...........................65-1outs ............................. 65-1outs1 ........................... 65-1outs2 ........................... 65-1outx............................. 65-3outz............................. 65-3Ppan .............................. 60-1pareq........................... 51-3pcauchy....................... 46-2pchbend ...................... 24-1pchmidi....................... 24-1pchmidib..................... 24-1pchoct ......................... 22-1peak ............................ 11-9phaser1 ....................... 58-6phaser2 ....................... 58-6phasor ......................... 34-1p<strong>in</strong>kish ........................ 46-4pitch............................ 11-1pitchamdf.................... 11-3planet ........................ 43-10pluck........................... 42-1poisson........................ 46-2port ............................. 50-1portk ........................... 50-1poscil .......................... 35-3poscil3 ........................ 35-3pow............................. 21-3powoftwo.................... 17-2pp................................ 69-4prealloc......................... 8-2pr<strong>in</strong>t ............................ 68-1pr<strong>in</strong>tk .......................... 68-2pr<strong>in</strong>tk2 ........................ 68-4pr<strong>in</strong>tks......................... 68-2product........................ 21-2pset ............................... 3-2pvadd .......................... 44-6pvanal ......................... 74-8pvbufread.................... 44-3pvcross........................ 44-3pv<strong>in</strong>terp....................... 44-3pvlook....................... 74-11pvoc ............................ 44-1pvread......................... 44-3Rr Statement................ 69-21rand............................. 46-1randh........................... 46-1randi............................ 46-1readclock .................... 10-1readk........................... 66-1readk2......................... 66-1readk3......................... 66-1readk4......................... 66-1re<strong>in</strong>it ........................... 15-1release......................... 31-1repluck........................ 42-4reson ........................... 50-1resonk ......................... 50-1resonr.......................... 50-4resonx ......................... 50-3resony ......................... 50-7resonz ......................... 50-4reverb.......................... 56-1reverb2........................ 56-3rezzy ......................... 50-13rigoto........................... 15-1rireturn ........................ 15-1rms .............................. 53-1rnd............................... 20-1Ss Statement................ 69-19s16b14......................... 26-1s32b14......................... 26-1samphold..................... 61-1sandpaper.................. 43-12scans ........................... 41-5scanu ........................... 41-3schedkwhen .................. 6-3schedule ........................ 6-1schedwhen .................... 6-1seed ............................... 3-3sekere........................ 43-12sfilist ........................... 39-4sf<strong>in</strong>str .......................... 39-4sf<strong>in</strong>strm ....................... 39-4sfload .......................... 39-4sfpassign ..................... 39-4sfplay .......................... 39-4sfplaym ....................... 39-4sfplist .......................... 39-4sfpreset........................ 39-4shaker.......................... 43-2s<strong>in</strong> ............................... 18-1s<strong>in</strong>h ............................. 18-1s<strong>in</strong><strong>in</strong>v .......................... 18-1sleighbells ................. 43-14slider16 ....................... 26-1slider16f...................... 26-1slider32 ....................... 26-1slider32f...................... 26-1slider64 ....................... 26-1slider64f...................... 26-1slider8 ......................... 26-1slider8f........................ 26-1snd<strong>in</strong>fo ........................ 74-3sndwarp..................... 40-10sndwarpst.................. 40-10sound<strong>in</strong>........................ 64-1soundout...................... 65-1soundouts.................... 65-1space ........................... 60-5spdist........................... 60-5specaddm .................... 63-2specdiff ....................... 63-2specdisp ...................... 63-5specfilt ........................ 63-2spechist ....................... 63-2specptrk....................... 63-3specscal....................... 63-2specsum ...................... 63-5spectrum...................... 63-6spsend ......................... 60-5sqrt .............................. 17-1sr ................................... 3-1stix ............................ 43-12streson......................... 57-3strset.............................. 3-2sum ............................. 21-1svfilter....................... 50-15The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page xvi


Tt Statement ................ 69-16table ............................ 33-1table3 .......................... 33-1tablecopy..................... 49-4tablegpw...................... 49-4tablei ........................... 33-1tableicopy.................... 49-4tableigpw .................... 49-4tableikt ........................ 48-1tableimix ..................... 49-4tableiw ........................ 49-1tablekt ......................... 48-1tablemix ...................... 49-4tableng ........................ 47-3tablera ......................... 49-6tableseg ....................... 44-3tablew.......................... 49-1tablewa........................ 49-6tablewkt ...................... 49-1tablexseg ..................... 44-3tambour<strong>in</strong>e ................ 43-14tan ............................... 18-1tanh ............................. 18-1tan<strong>in</strong>v .......................... 18-1tan<strong>in</strong>v2 ........................ 21-5tempest........................ 11-5tempo ........................ 11-10tigoto ...........................14-1time<strong>in</strong>stk........................9-1time<strong>in</strong>sts ........................9-1timek .............................9-1times..............................9-1timout ..........................14-1tival ...............................5-1tone..............................50-1tonek............................50-1tonex............................50-3trigger..........................11-8trirand..........................46-2turnoff ...........................7-1turnon ............................6-4Uunirand ........................46-2upsamp ........................61-1Vv Statement................69-18vbap16.......................60-11vbap16move..............60-11vbap4.........................60-11vbap4move................60-11vbap8 ........................ 60-11vbap8move ............... 60-11vbapls<strong>in</strong>it .................. 60-11vbapz ........................ 60-11vbapzmove ............... 60-11vco .............................. 36-3vdelay ......................... 55-6vdelay3 ....................... 55-6veloc ........................... 24-1vibes ........................... 43-3v<strong>in</strong>cr............................ 66-6vlowres ..................... 50-10voice ........................... 43-7vpvoc .......................... 44-1Wweibull........................ 46-2wgbow ........................ 42-5wgbowedbar ............. 42-11wgbrass....................... 42-8wgclar......................... 42-9wgflute........................ 42-6wgpluck ...................... 42-3wgpluck2 .................... 42-4wguide1 ...................... 57-1wguide2 ...................... 57-1wrap............................ 54-1Xxadsr ........................... 32-3x-class noise generators ....................................... 46-2xtratim......................... 31-1xy<strong>in</strong> ........................... 11-10Zzacl.............................. 62-6zak<strong>in</strong>it ......................... 62-2zamod.......................... 62-6zar ............................... 62-5zarg ............................. 62-5zaw.............................. 62-3zawm........................... 62-3zfilter2....................... 50-22zir................................ 62-5ziw .............................. 62-3ziwm ........................... 62-3zkcl ............................. 62-6zkmod ......................... 62-6zkr ............................... 62-5zkw ............................. 62-3zkwm .......................... 62-3The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page xvii


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page xviii


1 PREFACEby Barry Vercoe, MIT Media LabRealiz<strong>in</strong>g music by digital computer <strong>in</strong>volves synthesiz<strong>in</strong>g audio signals with discrete po<strong>in</strong>ts orsamples representative of cont<strong>in</strong>uous waveforms. There are many ways to do this, each afford<strong>in</strong>ga different manner of control. Direct synthesis generates waveforms by sampl<strong>in</strong>g a storedfunction represent<strong>in</strong>g a s<strong>in</strong>gle cycle; additive synthesis generates the many partials of a complextone, each with its own loudness envelope; subtractive synthesis beg<strong>in</strong>s with a complex tone andfilters it. Non-l<strong>in</strong>ear synthesis uses frequency modulation and waveshap<strong>in</strong>g to give simplesignals complex characteristics, while sampl<strong>in</strong>g and storage of a natural sound allows it to beused at will.S<strong>in</strong>ce comprehensive moment-by-moment specification of sound can be tedious, control isga<strong>in</strong>ed <strong>in</strong> two ways: 1) from the <strong>in</strong>struments <strong>in</strong> an orchestra, and 2) from the events with<strong>in</strong> ascore. An orchestra is really a computer program that can produce sound, while a score is a bodyof data which that program can react to. Whether a rise-time characteristic is a fixed constant <strong>in</strong>an <strong>in</strong>strument, or a variable of each note <strong>in</strong> the score, depends on how the user wants to controlit.The <strong>in</strong>struments <strong>in</strong> a <strong>Csound</strong> orchestra (.orc) are def<strong>in</strong>ed <strong>in</strong> a simple syntax that <strong>in</strong>vokes complexaudio process<strong>in</strong>g rout<strong>in</strong>es. A score (.sco) passed to this orchestra conta<strong>in</strong>s numerically codedpitch and control <strong>in</strong>formation, <strong>in</strong> standard numeric score format. Although many users arecontent with this format, higher level score process<strong>in</strong>g languages are often convenient.The programs mak<strong>in</strong>g up the <strong>Csound</strong> system have a long history of development, beg<strong>in</strong>n<strong>in</strong>g withthe Music 4 program written at Bell Telephone Laboratories <strong>in</strong> the early 1960’s by MaxMathews. That <strong>in</strong>itiated the stored table concept and much of the term<strong>in</strong>ology that has s<strong>in</strong>ceenabled computer music researchers to communicate. Valuable additions were made at Pr<strong>in</strong>cetonby the late Godfrey W<strong>in</strong>ham <strong>in</strong> Music 4B; my own Music 360 (1968) was very <strong>in</strong>debted to hiswork. With Music 11 (1973) I took a different tack: the two dist<strong>in</strong>ct networks of control andaudio signal process<strong>in</strong>g stemmed from my <strong>in</strong>tensive <strong>in</strong>volvement <strong>in</strong> the preced<strong>in</strong>g years <strong>in</strong>hardware synthesizer concepts and design. This division has been reta<strong>in</strong>ed <strong>in</strong> <strong>Csound</strong>.Because it is written entirely <strong>in</strong> C, <strong>Csound</strong> is easily <strong>in</strong>stalled on any mach<strong>in</strong>e runn<strong>in</strong>g Unix or C.At MIT it runs on VAX/DECstations under Ultrix 4.2, on SUNs under OS 4.1, SGI’s under 5.0,on IBM PC’s under DOS 6.2 and W<strong>in</strong>dows 3.1, and on the Apple Mac<strong>in</strong>tosh under Th<strong>in</strong>kC 5.0.With this s<strong>in</strong>gle language for def<strong>in</strong><strong>in</strong>g the audio signal process<strong>in</strong>g, and portable audio formatslike AIFF and WAV, users can move easily from mach<strong>in</strong>e to mach<strong>in</strong>e.The 1991 version added phase vocoder, FOF, and spectral data types. 1992 saw MIDI converterand control units, enabl<strong>in</strong>g <strong>Csound</strong> to be run from MIDI score-files and external keyboards. In1994 the sound analysis programs (lpc, pvoc) were <strong>in</strong>tegrated <strong>in</strong>to the ma<strong>in</strong> load module,enabl<strong>in</strong>g all <strong>Csound</strong> process<strong>in</strong>g to be run from a s<strong>in</strong>gle executable, and Cscore could pass scoresThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-1


directly to the orchestra for iterative performance. The 1995 release <strong>in</strong>troduced an expandedMIDI set with MIDI-based l<strong>in</strong>seg, butterworth filters, granular synthesis, and an improvedspectral-based pitch tracker. Of special importance was the addition of run-time event generat<strong>in</strong>gtools (Cscore and MIDI) allow<strong>in</strong>g run-time sens<strong>in</strong>g and response setups that enable <strong>in</strong>teractivecomposition and experiment. It appeared that real-time software synthesis was now show<strong>in</strong>gsome real promise.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-2


1.1 Where to Get Public <strong>Csound</strong> and the <strong>Csound</strong><strong>Manual</strong>Public <strong>Csound</strong> is available for download via anonymous ftp from :• ftp://ftp.maths.bath.ac.uk/pub/dreamor• ftp://ftp.musique.umontreal.ca/pub/mirrors/dreamThe Acrobat Edition and HTML Edition of this manual is available for browser download from:• http://www.lakewoodsound.com/csoundor via anonymous ftp from:• ftp://ftp.csounds.com/manualThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-3


1.2 How to Install <strong>Csound</strong>1.2.1 MACINTOSHDetailed <strong>in</strong>structions for <strong>in</strong>stall<strong>in</strong>g and configur<strong>in</strong>g <strong>Csound</strong> on Mac<strong>in</strong>tosh systems may beobta<strong>in</strong>ed from:• http://mitpress.mit.edu/e-books/csound/fpage/gs/mac/a/a.html1.2.2 WINDOWS 95/98Detailed <strong>in</strong>structions for <strong>in</strong>stall<strong>in</strong>g and configur<strong>in</strong>g <strong>Csound</strong> on W<strong>in</strong>dows 95 or W<strong>in</strong>dows 98systems may be obta<strong>in</strong>ed from:• http://mitpress.mit.edu/e-books/csound/fpage/gs/pc/pc.html1.2.3 MS-DOS AND WINDOWS 3.XDetailed <strong>in</strong>structions for <strong>in</strong>stall<strong>in</strong>g and configur<strong>in</strong>g <strong>Csound</strong> on MS-DOS or W<strong>in</strong>dows 3.x systemsmay be obta<strong>in</strong>ed from:• http://hem.passagen.se/rasmuse/PC<strong>in</strong>stal.htm1.2.4 LINUX (DEVELOPERS’ VERSION)1.2.4.1 Introduction to the Developers’ L<strong>in</strong>ux VersionBuild<strong>in</strong>g <strong>Csound</strong> for UNIX and L<strong>in</strong>ux mach<strong>in</strong>es has been possible thanks to John Fitch’s<strong>Csound</strong>.tar.gz source file kept at:• ftp://ftp.maths.bath.ac.uk/pub/dream/newestThis source tree builds <strong>Csound</strong> on a variety of UNIX-type systems, <strong>in</strong>clud<strong>in</strong>g the NeXT, Sun’sSolaris, SGI mach<strong>in</strong>es, and Intel-based L<strong>in</strong>ux. It should be noted that John also ma<strong>in</strong>ta<strong>in</strong>s aL<strong>in</strong>ux b<strong>in</strong>ary at the Bath repository. That version is built from his canonical sources.In 1998 a group of developers prepared a new version of <strong>Csound</strong> for L<strong>in</strong>ux. This version (oftenreferred to as the "unofficial" distribution) aims to deliver a modern package for L<strong>in</strong>ux users. Itoffers a variety of amenities specific to L<strong>in</strong>ux systems, <strong>in</strong>clud<strong>in</strong>g these items:• Enhanced makefile system• ‘autoconf’ and ‘configure’ supported for site-specific build• Support for Jaroslav Kysela’s ALSA sound drivers• Support for 64-bit Alpha systems• Full MIDI and real-time audio support• Builds shared library (libcsound.so) for greatly reduced memory footpr<strong>in</strong>t• Includes Rob<strong>in</strong> Whittle’s random number generator• Provided <strong>in</strong> various popular L<strong>in</strong>ux distribution packag<strong>in</strong>g formats• Utilizes .csoundrc resource file• Provides a high-priority scheduler for improved real-time i/oThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-4


• Includes support for full-duplex under the OSS/Free and OSS/L<strong>in</strong>ux drivers• CVS and bug-track<strong>in</strong>g system established for developersThis distribution’s code base orig<strong>in</strong>ates with the sources provided by John Fitch at the Bath site.Every effort is made to ensure compatibility with those sources at the opcode level, and usersshould have no trouble runn<strong>in</strong>g most orc/sco files or .csd files made for <strong>Csound</strong> on otheroperat<strong>in</strong>g systems.The makefile structure has been provided by Nicola Bernard<strong>in</strong>i. He also ma<strong>in</strong>ta<strong>in</strong>s the CVSrepository. Other features have been added by developers Ed Hall (Alpha port), Fred Floberg(scheduler), Rob<strong>in</strong> Whittle, and Steve Kersten (full-duplex under OSS driver). RPM and DEBpackages are sporadically available from Damien Miller and Guenter Geiger.Build<strong>in</strong>g the developers’ version is quite simple, us<strong>in</strong>g the familiar ‘./configure; make depend;make; make <strong>in</strong>stall’ command sequence. Instructions for compil<strong>in</strong>g and <strong>in</strong>stall<strong>in</strong>g <strong>Csound</strong> areprovided with the package, along with other relevant documentation. A mail-list has beenestablished for developers and users of this package, and a bug-track<strong>in</strong>g system has been set upby Damien Miller.1.2.4.2 Prepar<strong>in</strong>g L<strong>in</strong>ux Audio for <strong>Csound</strong>As long as the basic L<strong>in</strong>ux audio system is properly configured and <strong>in</strong>stalled, no special effortsneed to be made <strong>in</strong> order to enjoy audio output from sound. The default real-time audio outputdevice (devaudio) is def<strong>in</strong>ed as /dev/dsp <strong>in</strong> <strong>Csound</strong> itself, although other audio devices(/dev/audio, /dev/dspW) can be specified if so desired.1.2.4.3 Us<strong>in</strong>g the Developers’ VersionThis version is designed to be opcode-compatible with any other version of <strong>Csound</strong>. However,some new options have been added which may require clarification.Real-time audio output can be as simple as this:csound -o devaudio -V 75 my.orc my.scoThe ‘-V’ flag is a L<strong>in</strong>ux-specific output volume control from Jonathan Mohr. Note that it willwork only with the OSS/Free and OSS/L<strong>in</strong>ux drivers.Here we get a little more complicated:csound --sched --oss<strong>in</strong>=/dev/dsp0 --ossout=/dev/dsp1 my.*This example <strong>in</strong>vokes Fred Floberg’s high-priority scheduler (which will automatically disablegraphics output) and Steve Kersten’s support for full-duplex us<strong>in</strong>g either the OSS/Free driver<strong>in</strong>cluded with the L<strong>in</strong>ux kernel or the commercially available OSS/L<strong>in</strong>ux driver. L<strong>in</strong>ux users canuse the asterisk as a wildcard for the orc/sco extensions. However, if you have my.orc, my.sco,and my.txt with<strong>in</strong> the same directory the compiler will get confused and the wildcard won’twork.If more than one soundcard is present <strong>in</strong> the system, ALSA users have the option of choos<strong>in</strong>gwhich card will function for either audio <strong>in</strong>put or output. The command sequence then appearsso:csound --<strong>in</strong>card=1 --outcard=2 my.orc your.scoThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-5


The standard advice regard<strong>in</strong>g audio buffer sett<strong>in</strong>gs holds true for L<strong>in</strong>ux as well as for any otherversion. If the audio output is choppy you may need to adjust the value for the ‘–b’ flag whichcontrols the sample frame size for the software audio buffer. The best sett<strong>in</strong>g will depend uponvarious aspects of your mach<strong>in</strong>e system, <strong>in</strong>clud<strong>in</strong>g CPU speed, memory limits, hard-diskperformance, etc.Supported options for MIDI <strong>in</strong>clude the ‘-Q’ (MIDI output device) and ‘-K’ (MIDI <strong>in</strong>put port)flags from Gabriel Maldonado’s Direct<strong>Csound</strong>. Here is an example which uses one of Gabriel’sopcodes, requir<strong>in</strong>g the use of a MIDI output port:csound -Q0 -n my_moscil.orc my_moscil.scoThe ‘-Q0’ flag selects the first available MIDI output device, ‘-n’ cancels writ<strong>in</strong>g the output todisk.It should be noted that, for L<strong>in</strong>ux at least, <strong>in</strong> the opcode for this <strong>in</strong>strument (moscil) the samplerate determ<strong>in</strong>es the tempo of events. Sett<strong>in</strong>g the control rate (kr) to equal the sample rate (sr),sr=kr a higher sample rate will result <strong>in</strong> a slower performance. When sr=390000 (yes, you readthat correctly, it’s a sample rate of three hundred and n<strong>in</strong>ety thousand) then the MIDI eventperformance output is approximately 60 BPM (beats per m<strong>in</strong>ute). At that sample rate a scoretempo statement of ‘t 0 60’will actually mean 60 bpm. In essence, the sample rate acts as arestra<strong>in</strong>t or throttle on the tempo of the MIDI event stream.Us<strong>in</strong>g MIDI for real-time <strong>in</strong>put is simple:csound --sched -o devaudio -M/dev/midi my_midi_<strong>in</strong>.*With correctly written orc/sco files this example will allow real-time control of <strong>Csound</strong> viawhatever controll<strong>in</strong>g device is hooked up to /dev/midi. If more than one MIDI device is present<strong>in</strong> the mach<strong>in</strong>e the user can specify which to use:csound --sched -o devaudio -M/dev/midi01 my_midi_<strong>in</strong>.*That sequence will select the second MIDI device for MIDI <strong>in</strong>put.Here we use a Type 0 standard MIDI file for the controll<strong>in</strong>g <strong>in</strong>put:csound --sched -o devaudio -T -F/home/midfiles/my_type_0.mid my_cool.orcmy_cool.scoIn these last two examples the score file provides only the necessary function tables and a placeholderto <strong>in</strong>dicate how long <strong>Csound</strong> should stay active:f1 0 8192 10 1f0 240e; a s<strong>in</strong>e wave; stay active for 240 secondsHowever, the ‘-T’ flag will halt performance as soon as the end of the MIDI file is reached.1.2.4.4 AvailabilityThe L<strong>in</strong>ux developers version of <strong>Csound</strong> is available <strong>in</strong> source and b<strong>in</strong>ary distributions. Thema<strong>in</strong> distribution sites are at AIMI <strong>in</strong> Italy:• http://AIMI.dist.unige.it/AIMICSOUND/AIMICSOUND_home.htmlThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-6


and the ftp server for the Music Technology Department at Bowl<strong>in</strong>g Green State University <strong>in</strong>the USA:• ftp://mustec.bgsu.edu/pub/l<strong>in</strong>uxDeveloper Maurizio Umberto Puxeddu has also established a distribution po<strong>in</strong>t, though at thistime it is version-specific and not browsable. For more <strong>in</strong>formation regard<strong>in</strong>g his site, and formore <strong>in</strong>formation generally regard<strong>in</strong>g L<strong>in</strong>ux <strong>Csound</strong>, see this Web page:• http://www.bright.net/~dlphilp/l<strong>in</strong>ux_csound.html1.2.4.5 CreditsFirst thanks go to Barry Vercoe for creat<strong>in</strong>g <strong>Csound</strong> and allow<strong>in</strong>g it to be freely and publiclydistributed and to John Fitch for ma<strong>in</strong>ta<strong>in</strong><strong>in</strong>g the canonical source packages (<strong>in</strong>clud<strong>in</strong>g his ownbuild for L<strong>in</strong>ux).Special thanks go to the follow<strong>in</strong>g persons for their development assistance and/or spiritualguidance:• Paul Barton-Davis• Nicola Bernard<strong>in</strong>i• Richard Boulanger• Fred Floberg• Ed Hall• Steve Kersten• Gabriel Maldonado• Damien Miller• Maurizio Umberto Puxeddu• Larry Troxler• Rob<strong>in</strong> WhittleMy apologies to anyone I’ve left out. Please send corrections and emendations of this documentto me at my email address below.Dave Phillipsdlphilp@bright.netSeptember 19991.2.5 OTHER PLATFORMSFor <strong>in</strong>formation on availability of <strong>Csound</strong> for other platforms, see The <strong>Csound</strong> Frontpage:• http://mitpress.mit.edu/e-books/csound/frontpage.htmlThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-7


1.3 How to use the <strong>Csound</strong> <strong>Manual</strong>The <strong>Csound</strong> <strong>Manual</strong> is arranged as a <strong>Reference</strong> manual (not a tutorial), s<strong>in</strong>ce that is the form theuser will eventually f<strong>in</strong>d most helpful when <strong>in</strong>vent<strong>in</strong>g <strong>in</strong>struments. <strong>Csound</strong> can be a demand<strong>in</strong>gexperience at first. Hence it is highly advisable to peruse the tutorials <strong>in</strong>cluded <strong>in</strong> the Supplementto this <strong>Manual</strong>. Once the basic concepts are grasped from the beg<strong>in</strong>n<strong>in</strong>g tutorial, the reader mightlet himself <strong>in</strong>to the rema<strong>in</strong>der of the text by locat<strong>in</strong>g the <strong>in</strong>formation presented <strong>in</strong> the <strong>Reference</strong>entries that follow.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-8


1.4 The <strong>Csound</strong> Mail<strong>in</strong>g ListA <strong>Csound</strong> Mail<strong>in</strong>g List exists to discuss <strong>Csound</strong>. It is run by John ffitch of Bath University, UK.To have your name put on the mail<strong>in</strong>g list send an empty message to:csound-subscribe@lists.bath.ac.ukPosts sent tocsound@lists.bath.ac.ukgo to all subscribed members of the list.1.4.1 BUG REPORTSSuspected bugs <strong>in</strong> the code may be submitted to the list.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-9


This page <strong>in</strong>tentionally left blankThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Preface Page 1-10


2 SYNTAX OF THE ORCHESTRAAn orchestra statement <strong>in</strong> <strong>Csound</strong> has the format:label: result opcode argument1, argument2, ... ;commentsThe label is optional and identifies the basic statement that follows as the potential target of a gotooperation (see Program Control Statements). A label has no effect on the statement per se.Comments are optional and are for the purpose of lett<strong>in</strong>g the user document his orchestra code.Comments always beg<strong>in</strong> with a semicolon (;) and extend to the end of the l<strong>in</strong>e.The rema<strong>in</strong>der (result, opcode, and arguments) form the basic statement. This also is optional,i.e. a l<strong>in</strong>e may have only a label or comment or be entirely blank. If present, the basic statementmust be complete on one l<strong>in</strong>e, and is term<strong>in</strong>ated by a carriage return and l<strong>in</strong>e feed. Occasionally<strong>in</strong> this manual, a statement is divided between two l<strong>in</strong>es. This is for pr<strong>in</strong>t<strong>in</strong>g convenience only,and does not apply to the HTML Edition. In orchestra files, statements must be complete on onel<strong>in</strong>e, without a carriage return or l<strong>in</strong>e feed before the end of the statement.The opcode determ<strong>in</strong>es the operation to be performed; it usually takes some number of <strong>in</strong>putvalues (or arguments, with a maximum value of about 800); and it usually has a result fieldvariable to which it sends output values at some fixed rate. There are four possible rates:1. once only, at orchestra setup time (effectively a permanent assignment);2. once at the beg<strong>in</strong>n<strong>in</strong>g of each note (at <strong>in</strong>itialization (<strong>in</strong>it) time: i-rate);3. once every performance-time control loop (perf-time control rate, or k-rate);4. once each sound sample of every control loop (perf-time audio rate, or a-rate).The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-1


2.1 Directories and FilesMany generators and the <strong>Csound</strong> command itself specify filenames to be read from or written to.These are optionally full pathnames, whose target directory is fully specified. When not a fullpath, filenames are sought <strong>in</strong> several directories <strong>in</strong> order, depend<strong>in</strong>g on their type and on thesett<strong>in</strong>g of certa<strong>in</strong> environment variables. The latter are optional, but they can serve to partitionand organize the directories so that source files can be shared rather than duplicated <strong>in</strong> severaluser directories. The environment variables can def<strong>in</strong>e directories for soundfiles SFDIR, soundsamples SSDIR, sound analysis SADIR, and <strong>in</strong>clude files for orchestra and score files INCDIR.The search order is:1. Soundfiles be<strong>in</strong>g written are placed <strong>in</strong> SFDIR (if it exists), else the current directory.2. Soundfiles for read<strong>in</strong>g are sought <strong>in</strong> the current directory, then SSDIR, then SFDIR.3. Analysis control files for read<strong>in</strong>g are sought <strong>in</strong> the current directory, then SADIR.4. Files of code to be <strong>in</strong>cluded <strong>in</strong> orchestra and score files (with #<strong>in</strong>clude) are sought first <strong>in</strong>the current directory, then <strong>in</strong> the same directory as the orchestra or score file (asappropriate), then f<strong>in</strong>ally INCDIR.Beg<strong>in</strong>n<strong>in</strong>g with <strong>Csound</strong> version 3.54, the file “csound.txt“ conta<strong>in</strong>s the messages (<strong>in</strong> b<strong>in</strong>aryformat) that <strong>Csound</strong> uses to provide <strong>in</strong>formation to the user dur<strong>in</strong>g performance. This allows forthe messages to be <strong>in</strong> any language, although the default is English. This file must be placed <strong>in</strong>the same directory as the <strong>Csound</strong> executable. Alternatively, this file may be stored <strong>in</strong> SFDIR,SSDIR, or SADIR. Unix users may also keep this file <strong>in</strong> “usr/local/lib/”. The environmentvariable CSSTRNGS may be used to def<strong>in</strong>e the directory <strong>in</strong> which the database resides. This canbe overridden with the -j command l<strong>in</strong>e option. (New <strong>in</strong> version 3.55)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-2


2.2 NomenclatureThroughout this document, opcodes are <strong>in</strong>dicated <strong>in</strong> boldface and their argument and resultmnemonics, when mentioned <strong>in</strong> the text, are given <strong>in</strong> italics. Argument names are generallymnemonic (amp, phs), and the result is usually denoted by the letter r. Both are preceded by atype qualifier i, k, a, or x (e.g. kamp, iphs, ar). The prefix i denotes scalar values valid at note <strong>in</strong>ittime; prefixes k or a denote control (scalar) and audio (vector) values, modified and referencedcont<strong>in</strong>uously throughout performance (i.e. at every control period while the <strong>in</strong>strument is active).Arguments are used at the prefix-listed times; results are created at their listed times, then rema<strong>in</strong>available for use as <strong>in</strong>puts elsewhere. With few exceptions, argument rates may not exceed therate of the result. The validity of <strong>in</strong>puts is def<strong>in</strong>ed by the follow<strong>in</strong>g:•arguments with prefix i must be valid at <strong>in</strong>it time;•arguments with prefix k can be either control or <strong>in</strong>it values (which rema<strong>in</strong> valid);•arguments with prefix a must be vector <strong>in</strong>puts;•arguments with prefix x may be either vector or scalar (the compiler will dist<strong>in</strong>guish).All arguments, unless otherwise stated, can be expressions whose results conform to the above.Most opcodes (such as l<strong>in</strong>en and oscil) can be used <strong>in</strong> more than one mode, which one be<strong>in</strong>gdeterm<strong>in</strong>ed by the prefix of the result symbol.Thoughout this manual, the term “opcode” is used to <strong>in</strong>dicate a command that usually producesan a-, k-, or i-rate output, and always forms the basis of a complete <strong>Csound</strong> orchestra statement.Items such as “+” or “s<strong>in</strong>(x)” or, “( a >= b ? c : d)” are called “operators.”In the <strong>Csound</strong> orchestra, statements fall <strong>in</strong>to twelve major categores, consist<strong>in</strong>g of sixty-five subcategories.Each is <strong>in</strong> a separate chapter of this manual. The categories (and correspond<strong>in</strong>gchapter numbers) are as follows:Orchestra Syntax3: Orchestra Header Statements4: Instrument Block Statements5: Variable InitializationInstrument Control6: Instrument Invocation7: Duration Control Statements8: Real-time Performance Control9: Time Read<strong>in</strong>g10: Clock Control11: Sens<strong>in</strong>g and Control12: Conditional Values13: Macros14: Program Flow Control15: Re<strong>in</strong>itializationThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-3


Mathematical Operations16: Arithmetic and Logic Operations17: Mathematical Functions18: Trigonometric Functions19: Amplitude Functions20: Random Functions21: Opcode Equivalents of FunctionsPitch Converters22: Functions23: Tun<strong>in</strong>g OpcodesMIDI Support24: Converters25: Controller Input26: Slider Banks27: Generic I/O28: Note-on/Note-off29: MIDI Message Output30: Real-time Messages31: MIDI Event ExtendersSignal Generators32: L<strong>in</strong>ear and Exponential Generators33: Table Access34: Phasors35: Basic Oscillators36: Dynamic Spectrum Oscillators37: Additive Synthesis/Resynthesis38: FM Synthesis39: Sample Playback40: Granular Synthesis41: Waveguide Physical Model<strong>in</strong>g42: Models and Emulations43: STFT Resynthesis (Vocod<strong>in</strong>g)44: LPC Resynthesis45: Random (Noise) GeneratorsFunction Table Control46: Tables Queries47: Table Selection48: Read/Write OperationsSignal Modifiers49: Standard Filters50: Specialized Filters51: Envelope Modifiers52: Amplitude Modifiers53: Signal Limiters54: DelayThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-4


55: Reverberation56: Waveguides57: Special Effects58: Convolution and Morph<strong>in</strong>g59: Pann<strong>in</strong>g and Spatialization60: Sample Level OperatorsZak Patch System61: Zak Patch SystemOperations Us<strong>in</strong>g Spectral Data Types62: Operations Us<strong>in</strong>g Spectral Data TypesSignal Input and Output63: Input64: Output65: File I/O66: Sound File Queries67: Pr<strong>in</strong>t<strong>in</strong>g and DisplayThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-5


2.3 Orchestra Statement TypesAn orchestra program <strong>in</strong> <strong>Csound</strong> is comprised of orchestra header statements which set variousglobal parameters, followed by a number of <strong>in</strong>strument blocks represent<strong>in</strong>g different <strong>in</strong>strumenttypes. An <strong>in</strong>strument block, <strong>in</strong> turn, is comprised of ord<strong>in</strong>ary statements that set values, controlthe logical flow, or <strong>in</strong>voke the various signal process<strong>in</strong>g subrout<strong>in</strong>es that lead to audio output.An orchestra header statement operates once only, at orchestra setup time. It is most commonlyan assignment of some value to a global reserved symbol , e.g. sr = 20000. All orchestra headerstatements belong to a pseudo <strong>in</strong>strument 0, an <strong>in</strong>it pass of which is run prior to all other<strong>in</strong>struments at score time 0. Any ord<strong>in</strong>ary statement can serve as an orchestra header statement,e.g. gifreq = cpspch(8.09) provided it is an <strong>in</strong>it-time only operation.An ord<strong>in</strong>ary statement runs at either <strong>in</strong>it time or performance time or both. Operations whichproduce a result formally run at the rate of that result (that is, at <strong>in</strong>it time for i-rate results; atperformance time for k- and a-rate results), with the sole exception of the <strong>in</strong>it opcode. Mostgenerators and modifiers, however, produce signals that depend not only on the <strong>in</strong>stantaneousvalue of their arguments but also on some preserved <strong>in</strong>ternal state. These performance-time unitstherefore have an implicit <strong>in</strong>it-time component to set up that state. The run time of an operationwhich produces no result is apparent <strong>in</strong> the opcode.Arguments are values that are sent to an operation. Most arguments will accept arithmeticexpressions composed of constants, variables, reserved symbols, value converters, arithmeticoperations, and conditional values.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-6


2.4 Constants and Variablesconstants are float<strong>in</strong>g po<strong>in</strong>t numbers, such as 1, 3.14159, or -73.45. They are availablecont<strong>in</strong>uously and do not change <strong>in</strong> value.variables are named cells conta<strong>in</strong><strong>in</strong>g numbers. They are available cont<strong>in</strong>uously and may beupdated at one of the four update rates (setup only, i-rate, k-rate, or a-rate). i- and k-rate variablesare scalars (i.e. they take on only one value at any given time) and are primarily used to store andrecall controll<strong>in</strong>g data, that is, data that changes at the note rate (for i-rate variables) or at thecontrol rate (for k-rate variables). i- and k-variables are therefore useful for stor<strong>in</strong>g noteparameter values, pitches, durations, slow-mov<strong>in</strong>g frequencies, vibratos, etc. a-rate variables, onthe other hand, are arrays or vectors of <strong>in</strong>formation. Though renewed on the same perf-timecontrol pass as k-rate variables, these array cells represent a f<strong>in</strong>er resolution of time by divid<strong>in</strong>gthe control period <strong>in</strong>to sample periods (see ksmps). a-rate variables are used to store and recalldata chang<strong>in</strong>g at the audio sampl<strong>in</strong>g rate (e.g. output signals of oscillators, filters, etc.).A further dist<strong>in</strong>ction is that between local and global variables. local variables are private to aparticular <strong>in</strong>strument, and cannot be read from or written <strong>in</strong>to by any other <strong>in</strong>strument. Theirvalues are preserved, and they may carry <strong>in</strong>formation from pass to pass (e.g. from <strong>in</strong>itializationtime to performance time) with<strong>in</strong> a s<strong>in</strong>gle <strong>in</strong>strument. Local variable names beg<strong>in</strong> with the letterp, i, k, or a. The same local variable name may appear <strong>in</strong> two or more different <strong>in</strong>strumentblocks without conflict.global variables are cells that are accessible by all <strong>in</strong>struments. The names are either like localnames preceded by the letter g, or are special reserved symbols. Global variables are used forbroadcast<strong>in</strong>g general values, for communicat<strong>in</strong>g between <strong>in</strong>struments (semaphores), or forsend<strong>in</strong>g sound from one <strong>in</strong>strument to another (e.g. mix<strong>in</strong>g prior to reverberation).Given these dist<strong>in</strong>ctions, there are eight forms of local and global variables:Type When Renewable Local Globalreserved symbols permanent -- rsymbolscore parameter fields i-time pnumber --v-set symbols i-time vnumber gvnumber<strong>in</strong>it variables i-time <strong>in</strong>ame g<strong>in</strong>ameMIDI controllers any time cnumber --control signals p-time, k-rate kname gknameaudio signals p-time, a-rate aname ganamespectral data types k-rate wname --The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-7


where rsymbol is a special reserved symbol (e.g. sr, kr), number is a positive <strong>in</strong>teger referr<strong>in</strong>g toa score pfield or sequence number, and name is a str<strong>in</strong>g of letters and/or digits with local orglobal mean<strong>in</strong>g. As might be apparent, score parameters are local i-rate variables whose valuesare copied from the <strong>in</strong>vok<strong>in</strong>g score statement just prior to the <strong>in</strong>it pass through an <strong>in</strong>strument,while MIDI controllers are variables which can be updated asynchronously from a MIDI file orMIDI device.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-8


2.5 ExpressionsExpressions may be composed to any depth. Each part of an expression is evaluated at its ownproper rate. For <strong>in</strong>stance, if the terms with<strong>in</strong> a sub-expression all change at the control rate orslower, the sub-expression will be evaluated only at the control rate; that result might then beused <strong>in</strong> an audio-rate evaluation. For example, <strong>in</strong>k1 + abs(<strong>in</strong>t(p5) + frac(p5) * 100/12 + sqrt(k1))the 100/12 would be evaluated at orch <strong>in</strong>it, the p5 expressions evaluated at note i-time, and therema<strong>in</strong>der of the expression evaluated every k-period. The whole might occur <strong>in</strong> a unit generatorargument position, or be part of an assignment statement.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-9


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Syntax of the Orchestra Page 2-10


3 ORCHESTRA SYNTAX: ORCHESTRA HEADERSTATEMENTS3.1 sr, kr, ksmps, nchnlssr = iargkr = iargksmps = iargnchnls = iarg3.1.1 DESCRIPTIONThese statements are global value assignments, made at the beg<strong>in</strong>n<strong>in</strong>g of an orchestra, before any<strong>in</strong>strument block is def<strong>in</strong>ed. Their function is to set certa<strong>in</strong> reserved symbol variables that arerequired for performance. Once set, these reserved symbols can be used <strong>in</strong> expressions anywhere<strong>in</strong> the orchestra.sr = (optional) – set sampl<strong>in</strong>g rate to iarg samples per second per channel. The default value is44100.kr = (optional) – set control rate to iarg samples per second. The default value is 4410.ksmps = (optional) – set the number of samples <strong>in</strong> a control period to. This value must equalsr/kr. The default value is 10.nchnls = (optional) – set number of channels of audio output to iarg. (1 = mono, 2 = stereo, 4 =quadraphonic.) The default value is 1 (mono).In addition, any global variable can be <strong>in</strong>itialized by an <strong>in</strong>it-time assignment anywhere beforethe first <strong>in</strong>str statement. All of the above assignments are run as <strong>in</strong>strument 0 (i- pass only) atthe start of real performance.Beg<strong>in</strong>n<strong>in</strong>g with <strong>Csound</strong> version 3.46, either sr, kr, or ksmps may be omitted. <strong>Csound</strong> willattempt to calculate the omitted value from the specified values, but it should evaluate to an<strong>in</strong>teger.3.1.2 EXAMPLEsr = 10000kr = 500ksmps = 20gi1 = sr/2.ga <strong>in</strong>it 0itranspose = octpch(.0l)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Orchestra Header Statements Page 3-1


3.2 strset, psetstrsetpsetiarg, “str<strong>in</strong>gtext”con1, con2, con3,...3.2.1 DESCRIPTIONAllow certa<strong>in</strong> global parameters to be <strong>in</strong>itialized at orchestra load time, rather than <strong>in</strong>strument<strong>in</strong>itialization or performance time.3.2.2 INITIALIZATIONiarg – numeric value to be associated with an alphanumeric str<strong>in</strong>gcon1, con2, etc. – preset values for a MIDI <strong>in</strong>strumentstrset (optional) allows a str<strong>in</strong>g, such as a filename, to be l<strong>in</strong>ked with a numeric value. Its use isoptional.pset (optional) def<strong>in</strong>es and <strong>in</strong>itializes numeric arrays at orchestra load time. It may be used as anorchestra header statement (i.e. <strong>in</strong>strument 0) or with<strong>in</strong> an <strong>in</strong>strument. When def<strong>in</strong>ed with<strong>in</strong> an<strong>in</strong>strument, it is not part of its i-time or performance operation, and only one statement is allowedper <strong>in</strong>strument. These values are available as i-time defaults. When an <strong>in</strong>strument is triggeredfrom MIDI it only gets p1 and p2 from the event, and p3, p4, etc. will receive the actual presetvalues.3.2.3 EXAMPLESThe follow<strong>in</strong>g statement, used <strong>in</strong> the orchestra header, will allow the numeric value 10 tosubstituted anywhere the soundfile asound.wav is called for.strset 10, “asound.wav”The example below illustrates pset as used with<strong>in</strong> an <strong>in</strong>strument.<strong>in</strong>str 1pset 0,0,3,4,5,6 ; pfield substitutesa1 oscil 10000, 440, p6The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Orchestra Header Statements Page 3-2


3.3 seedseedival3.3.1 DESCRIPTIONSets the global seed value for all x-class noise generators, as well as other opcodes that use arandom call, such as gra<strong>in</strong>. rand, randi, randh, rnd(x), and birnd(x) are not affected by seed.3.3.2 INITIALIZATIONival – value to be used as the random generator(s) seed value3.3.3 PERFORMANCEUse of seed will provide predictable results from an orchestra us<strong>in</strong>g with random generators,when required from multiple performances.When specify<strong>in</strong>g a seed value, ival should be an <strong>in</strong>teger between 0 and 2 32 . If ival = 0, the valueof ival will be derived from the system clock.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Orchestra Header Statements Page 3-3


3.4 ftgengir ftgen ifn, itime, isize, igen, iarga[, iargb...iargz]3.4.1 DESCRIPTIONGenerate a score function table from with<strong>in</strong> the orchestra.3.4.2 INITIALIZATIONgir – either a requested or automatically assigned table number above 100. If used with<strong>in</strong> an<strong>in</strong>strument, may be local variable ir.ifn – requested table number If ifn is zero, the number is assigned automatically and the valueplaced <strong>in</strong> gir. Any other value is used as the table numberitime – is ignored, but otherwise corresponds to p2 <strong>in</strong> the score f statement.isize – table size. Corresponds to p3 of the score f statement.igen – function table GEN rout<strong>in</strong>e. Corresponds to p4 of the score f statement.iarga-iargz – function table arguments. Correspond to p5 through pn of the score f statement.3.4.3 PERFORMANCEThis is equivalent to table generation <strong>in</strong> the score with the f statement.3.4.4 AUTHORBarry VercoeMIT, Cambridge, Mass1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Orchestra Header Statements Page 3-4


3.5 massign, ctrl<strong>in</strong>itmassignctrl<strong>in</strong>itichnl, <strong>in</strong>snumichnl, ictlno1, ival1[, ictlno2, ival2 [, ictlno3,ival3[,..ival32]]3.5.1 DESCRIPTIONInitialize MIDI controllers for a <strong>Csound</strong> orchestra.3.5.2 INITIALIZATIONichnl – MIDI channel number<strong>in</strong>snum – <strong>Csound</strong> orchestra <strong>in</strong>strument numberictlno1, ictlno2, etc. – MIDI contoller numbersival1, ival2, etc. – <strong>in</strong>itial value for correspond<strong>in</strong>g MIDI contoller number3.5.3 PERFORMANCEmassign assigns a MIDI channel number to a <strong>Csound</strong> <strong>in</strong>strumentctrl<strong>in</strong>it sets <strong>in</strong>itial values for a set of MIDI controllers.3.5.4 AUTHORSBarry Vercoe – Mike BerryMIT, Cambridge, MassNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Orchestra Header Statements Page 3-5


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Orchestra Header Statements Page 3-6


4 ORCHESTRA SYNTAX: INSTRUMENT BLOCKSTATEMENTS4.1 <strong>in</strong>str, end<strong>in</strong><strong>in</strong>str i, j, ..... < body. of. <strong>in</strong>strument.end<strong>in</strong>4.1.1 DESCRIPTIONThese statements delimit an <strong>in</strong>strument block. They must always occur <strong>in</strong> pairs.<strong>in</strong>str – beg<strong>in</strong> an <strong>in</strong>strument block def<strong>in</strong><strong>in</strong>g <strong>in</strong>struments i, j, ...i, j, ... must be numbers, not expressions. Any positive <strong>in</strong>teger is legal, and <strong>in</strong> any order, butexcessively high numbers are best avoided.end<strong>in</strong> – end the current <strong>in</strong>strument block.Note:There may be any number of <strong>in</strong>strument blocks <strong>in</strong> an orchestra.Instruments can be def<strong>in</strong>ed <strong>in</strong> any order (but they will always be both <strong>in</strong>itialized and performed<strong>in</strong> ascend<strong>in</strong>g <strong>in</strong>strument number order).Instrument blocks cannot be nested (i.e. one block cannot conta<strong>in</strong> another).The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Instrument Block Statements Page 4-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Instrument Block Statements Page 4-2


5 ORCHESTRA SYNTAX: VARIABLEINITIALIZATION5.1 =, <strong>in</strong>it, tival, divzir = iargkr = kargar = xargkr <strong>in</strong>it iargar <strong>in</strong>it iargir tivalir divz ia, ib, isubstkr divz ka, kb, ksubstar divz xa, xb, ksubst5.1.1 DESCRIPTION= (simple assignment) – Put the value of the expression iarg (karg, xarg) <strong>in</strong>to the named result.This provides a means of sav<strong>in</strong>g an evaluated result for later use.<strong>in</strong>it – Put the value of the i-time expression iarg <strong>in</strong>to a k- or a-rate variable, i.e., <strong>in</strong>itialize theresult. Note that <strong>in</strong>it provides the only case of an <strong>in</strong>it-time statement be<strong>in</strong>g permitted to write<strong>in</strong>to a perf-time (k- or a-rate) result cell; the statement has no effect at perf-time.tival – Put the value of the <strong>in</strong>strument’s <strong>in</strong>ternal “tie-<strong>in</strong>” flag <strong>in</strong>to the named i-rate variable.Assigns 1 if this note has been “tied” onto a previously held note ( see i Statement); assigns 0 ifno tie actually took place. ( see also tigoto)divz – Whenever b is not zero, set the result to the value a / b; when b is zero, set it to the valueof subst <strong>in</strong>stead.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Variable Initialization Page 5-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Orchestra Syntax: Variable Initialization Page 5-2


6 INSTRUMENT CONTROL: INSTRUMENTINVOCATION6.1 schedule, schedwhenscheduleschedwhen<strong>in</strong>snum, iwhen, idur [, p4, p5,…]ktrigger, k<strong>in</strong>st, kwhen, kdur [, p4, p5,…]6.1.1 DESCRIPTIONAdds a new score event6.1.2 INITIALIZATION<strong>in</strong>snum – <strong>in</strong>strument number. Equivalent to p1 <strong>in</strong> a score i statement.iwhen – start time of the new event. Equivalent to p2 <strong>in</strong> a score i statement.idur – duration of event. Equivalent to p3 <strong>in</strong> a score i statement.6.1.3 PERFORMANCEktrigger – trigger value for new eventschedule adds a new score event. The arguments, <strong>in</strong>clud<strong>in</strong>g options, are the same as <strong>in</strong> a score.The iwhen time (p2) is measured from the time of this event.If the duration is zero or negative the new event is of MIDI type, and <strong>in</strong>herits the release subeventfrom the schedul<strong>in</strong>g <strong>in</strong>struction.In the case of schedwhen, the event is only scheduled when the k-rate value ktrigger is first nonzero.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Instrument Invocation Page 6-1


6.1.4 EXAMPLE;; Double hit and 1sec separation<strong>in</strong>str 1schedule 2, 1, 0.5, p4, p5a1 shaker p4, 60, 0.999, 0, 100, 0outa1end<strong>in</strong><strong>in</strong>str 2a1 marimba p4, cpspch(p5), p6, p7, 2, 6.0, 0.05, 1, 0.1outa1end<strong>in</strong><strong>in</strong>str 3kr table kr, 1schedwhen kr, 1, 0.25, 1, p4, p5end<strong>in</strong>6.1.5 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKNovember, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.491)Based on work by Gabriel MaldonadoThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Instrument Invocation Page 6-2


6.2 schedkwhenschedkwhenktrigger, km<strong>in</strong>tim, kmaxnum, k<strong>in</strong>snum, kwhen, kdur[, kp4,kp5, …]6.2.1 DESCRIPTIONAdds a new score event generated by a k-rate trigger.6.2.2 PERFORMANCEktrigger – triggers a new score event. If ktrigger = 0, no new event is triggered.km<strong>in</strong>tim – m<strong>in</strong>imum time between generated events, <strong>in</strong> seconds. If km<strong>in</strong>tim = kmaxnum, no new event is generated. If kmaxnum is= 0. If kwhen > 0, the <strong>in</strong>strument will not be<strong>in</strong>itialized until the actual time when it should start perform<strong>in</strong>g.kdur – duration of event. Equivalent to p3 <strong>in</strong> a score i statement. If kdur = 0, the <strong>in</strong>strument willonly do an <strong>in</strong>itialization pass, with no performance. If kdur is negative, a held note is <strong>in</strong>itiated.(See ihold and i statement.)kp4, kp5, etc. – Equivalent to p4, p5, etc., <strong>in</strong> a score i statement.Note: While wait<strong>in</strong>g for events to be triggered by schedkwhen, the performance must be keptgo<strong>in</strong>g, or <strong>Csound</strong> may quit if no score events are expected. To guarantee cont<strong>in</strong>ued performance,an f0 statement may be used <strong>in</strong> the score.6.2.3 AUTHORRasmus EkmanEMSStockholm, SwedenNew <strong>in</strong> <strong>Csound</strong> version 3.59The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Instrument Invocation Page 6-3


6.3 turnonturnon<strong>in</strong>snum[,itime]6.3.1 DESCRIPTIONActivate an <strong>in</strong>strument, for an <strong>in</strong>def<strong>in</strong>ite time.6.3.2 INITIALIZATION<strong>in</strong>snum – <strong>in</strong>strument number to be activateditime – delay, <strong>in</strong> seconds, after which <strong>in</strong>strument <strong>in</strong>snum will be activated. Default is 0.6.3.3 PERFORMANCEturnon activates <strong>in</strong>strument <strong>in</strong>snum after a delay of itime seconds, or immediately if itime is notspecified. Instrument is active until explicitly turned off. (See turnoff.)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Instrument Invocation Page 6-4


7 INSTRUMENT CONTROL: DURATIONCONTROL STATEMENTS7.1 ihold, turnoffiholdturnoff7.1.1 DESCRIPTIONThese statements permit the current note to modify its own duration.ihold – this i-time statement causes a f<strong>in</strong>ite-duration note to become a “held” note. It thus has thesame effect as a negative p3 ( see score i Statement), except that p3 here rema<strong>in</strong>s positive andthe <strong>in</strong>strument reclassifies itself to be<strong>in</strong>g held <strong>in</strong>def<strong>in</strong>itely. The note can be turned off explicitlywith turnoff, or its space taken over by another note of the same <strong>in</strong>strument number (i.e. it is tied<strong>in</strong>to that note). Effective at i-time only; no-op dur<strong>in</strong>g a re<strong>in</strong>it pass.turnoff – this p-time statement enables an <strong>in</strong>strument to turn itself off. Whether of f<strong>in</strong>ite durationor “held”, the note currently be<strong>in</strong>g performed by this <strong>in</strong>strument is immediately removed fromthe active note list. No other notes are affected.7.1.2 EXAMPLEThe follow<strong>in</strong>g statements will cause a note to term<strong>in</strong>ate when a control signal passes a certa<strong>in</strong>threshold (here the Nyquist frequency).k1 expon 440, p3/10,880 ; beg<strong>in</strong> gliss and cont<strong>in</strong>ueif k1 < sr/2 kgoto cont<strong>in</strong> ; until Nyquist detectedturnoff; then quitcont<strong>in</strong>:a1 oscil a1, k1, 1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Duration Control Statements Page 7-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Duration Control Statements Page 7-2


8 INSTRUMENT CONTROL: REAL-TIMEPERFORMANCE CONTROL8.1 activeir active <strong>in</strong>snum8.1.1 DESCRIPTIONReturns the number of active <strong>in</strong>stances of an <strong>in</strong>strument.8.1.2 INITIALIZATION<strong>in</strong>snum – number of the <strong>in</strong>strument to be reported8.1.3 PERFORMANCEactive returns the number of active <strong>in</strong>stances of <strong>in</strong>strument number <strong>in</strong>snum at the time it iscalled.8.1.4 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKJuly, 1999New <strong>in</strong> <strong>Csound</strong> version 3.57The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Real-time Performance Control Page 8-1


8.2 cpuprc, maxalloc, prealloccpuprcmaxallocprealloc<strong>in</strong>snum, ipercent<strong>in</strong>snum, icount<strong>in</strong>snum, icount8.2.1 DESCRIPTIONControl allocation of cpu resources on a per-<strong>in</strong>strument basis, to optimize real-time output.8.2.2 INITIALIZATION<strong>in</strong>snum – <strong>in</strong>strument numberipercent – percent of cpu process<strong>in</strong>g-time to assign. Can also be expressed as a fractional value.icount – number of <strong>in</strong>strument allocations8.2.3 PERFORMANCEcpuprc sets the cpu process<strong>in</strong>g-time percent usage of an <strong>in</strong>strument, <strong>in</strong> order to avoid bufferunderrun <strong>in</strong> real-time performances, enabl<strong>in</strong>g a sort of polyphony theshold. The user must setipercent value for each <strong>in</strong>strument to be activated <strong>in</strong> real-time. Assum<strong>in</strong>g that the total theoreticalprocess<strong>in</strong>g time of the cpu of the computer is 100%, this percent value can only be def<strong>in</strong>edempirically, because there are too many factors that contribute to limit<strong>in</strong>g real-time polyphony <strong>in</strong>different computers.For example, if ipercent is set to 5% for <strong>in</strong>strument 1, the maximum number of voices that canbe allocated <strong>in</strong> real-time, is 20 (5% * 20 = 100%). If the user attempts to play a further notewhile the 20 previous notes are still play<strong>in</strong>g, <strong>Csound</strong> <strong>in</strong>hibits the allocation of that note and willdisplay the follow<strong>in</strong>g warn<strong>in</strong>g message:can’t allocate last note because it exceeds 100% of cpu timeIn order to avoid audio buffer underruns, it is suggested to set the maximum number of voicesslightly lower than the real process<strong>in</strong>g power of the computer. Sometimes an <strong>in</strong>strument canrequire more process<strong>in</strong>g time than normal. If, for example, the <strong>in</strong>strument conta<strong>in</strong>s an oscillatorwhich reads a table that doesn’t fit <strong>in</strong> cache memory, it will be slower than normal. In addition,any program runn<strong>in</strong>g concurrently <strong>in</strong> multitask<strong>in</strong>g, can subtract process<strong>in</strong>g power to vary<strong>in</strong>gdegrees.At the start, all <strong>in</strong>struments are set to a default value of ipercent = 0.0% (i.e. zero process<strong>in</strong>g timeor rather <strong>in</strong>f<strong>in</strong>ite cpu process<strong>in</strong>g-speed). This sett<strong>in</strong>g is OK for deferred-time sessions.maxalloc limits the number of allocations of an <strong>in</strong>strument. prealloc creates space for<strong>in</strong>struments but does not run them.All <strong>in</strong>stances of cpuprc, maxalloc, and prealloc must be def<strong>in</strong>ed <strong>in</strong> the header section, not <strong>in</strong> the<strong>in</strong>strument body.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Real-time Performance Control Page 8-2


8.2.4 EXAMPLEsr = 44100kr = 441ksmps = 100nchnls = 2cpuprc 1, 2.5<strong>in</strong>str 1...body...end<strong>in</strong><strong>in</strong>str 2....body...end<strong>in</strong>; set <strong>in</strong>str 1 to 2.5% of processor power,; i.e. maximum 40 voices (2.5% * 40 = 100%)cpuprc 2, 33.333 ; set <strong>in</strong>str 2 to 33.333% of processor power,; i.e. maximum 3 voices (33.333% * 3 = 100%)8.2.5 AUTHORGabriel MaldonadoItalyJuly, 1999New <strong>in</strong> <strong>Csound</strong> version 3.57The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Real-time Performance Control Page 8-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Real-time Performance Control Page 8-4


9 INSTRUMENT CONTROL: TIME READING9.1 timek, times, time<strong>in</strong>stk, time<strong>in</strong>stsirkrirkrkrkrtimektimektimestimestime<strong>in</strong>stktime<strong>in</strong>sts9.1.1 DESCRIPTIONOpcodes to read absolute time s<strong>in</strong>ce the start of the performance or of an <strong>in</strong>stance of an<strong>in</strong>strument – <strong>in</strong> two formats.9.1.2 PERFORMANCEtimek is for time <strong>in</strong> krate cycles. So with:sr = 44100kr = 6300ksmps = 7then after half a second, the timek opcode would report 3150. It will always report an <strong>in</strong>teger.Time <strong>in</strong> seconds is available with times. This would return 0.5 after half a second.times and timek can also operate only at the start of the <strong>in</strong>stance of the <strong>in</strong>strument. Both producean i-rate variable (start<strong>in</strong>g with i or gi) as their output.timek and times can both produce a k-rate variable for output.There are no <strong>in</strong>put parameters.time<strong>in</strong>stk and time<strong>in</strong>sts are similar to timek and times, except they return the time s<strong>in</strong>ce thestart of this <strong>in</strong>stance of the <strong>in</strong>strument.9.1.3 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Time Read<strong>in</strong>g Page 9-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Time Read<strong>in</strong>g Page 9-2


10 INSTRUMENT CONTROL: CLOCK CONTROL10.1 clockon, clockoff, readclockclockon<strong>in</strong>umclockoff<strong>in</strong>umir readclock <strong>in</strong>um10.1.1 DESCRIPTIONStarts and stops one of a number of <strong>in</strong>ternal clocks, and reads the value of a clock.10.1.2 INITIALIZATION<strong>in</strong>um – the number of a clock. There are 32 clocks numbered 0 through 31. All other values aremapped to clock number 32.ir – value at i-time, of the clock specified by <strong>in</strong>um10.1.3 PERFORMANCEBetween a clockon and a clockoff, the CPU time used, is accumulated <strong>in</strong> the clock. Theprecision is mach<strong>in</strong>e dependent, but is the millisecond range on UNIX and W<strong>in</strong>dows systems.readclock reads the current value of a clock at <strong>in</strong>itialization time.Note: there is no way to zero a clock.10.1.4 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKJuly, 1999New <strong>in</strong> <strong>Csound</strong> version 3.56The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Clock Control Page 10-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Clock Control Page 10-2


11 INSTRUMENT CONTROL: SENSING ANDCONTROL11.1 pitchkoct, pitch asig, iupdte, ilo, ihi, idbthresh[, ifrqs, iconf,\\kampistrt, iocts, iq, <strong>in</strong>ptls, irolloff, iskip]11.1.1 DESCRIPTIONUs<strong>in</strong>g the same techniques as spectrum and specptrk, pitch tracks the pitch of the signal <strong>in</strong>octave po<strong>in</strong>t decimal form, and amplitude <strong>in</strong> dB.11.1.2 INITIALIZATIONiupdte – length of period, <strong>in</strong> seconds, that outputs are updatedilo, ihi – range <strong>in</strong> which pitch is detected, expressed <strong>in</strong> octave po<strong>in</strong>t decimalidbthresh – amplitude, expressed <strong>in</strong> decibels, necessary for the pitch to be detected. Once startedit cont<strong>in</strong>ues until it is 6 dB down.ifrqs – number of divisions of an octave. Default is 12 and is limited to 120.iconf – the number of conformations needed for an octave jump. Default is 10.istrt – start<strong>in</strong>g pitch for tracker. Default value is (ilo + ihi)/2.iocts – number of octave decimations <strong>in</strong> spectrum. Default is 6.iq – Q of analysis filters. Default is 10.<strong>in</strong>ptls – number of harmonics, used <strong>in</strong> match<strong>in</strong>g. Computation time <strong>in</strong>creases with the number ofharmonics. Default is 4.irolloff – amplitude rolloff for the set of filters expressed as fraction per octave. Values must bepositive. Default is 0.6.iskip – if non-zero, skips <strong>in</strong>itializationThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-1


11.1.3 PERFORMANCEpitch analyzes the <strong>in</strong>put signal, asig, to give a pitch/amplitude pair of outputs, for the strongestfrequency <strong>in</strong> the signal. The value is updated every iupdte seconds.The number of partials and rolloff fraction can effect the pitch track<strong>in</strong>g, so some experimentationmay be necessary. Suggested values are 4 or 5 harmonics, with rolloff 0.6, up to 10 or 12harmonics with rolloff 0.75 for complex timbres, with a weak fundamental.11.1.4 AUTHORJohn ffitchUniversity of Bath, Codemist Ltd.Bath, UKApril, 1999New <strong>in</strong> <strong>Csound</strong> version 3.54The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-2


11.2 pitchamdfkcps, pitchamdf asig, im<strong>in</strong>cps, imaxcps [, icps[, imedi[, idowns[,//krmsiexcps]]]]11.2.1 DESCRIPTIONFollows the pitch of a signal based on the AMDF method (Average Magnitude DifferenceFunction). Outputs pitch and amplitude track<strong>in</strong>g signals. The method is quite fast and should run<strong>in</strong> real-time. This technique usually works best for monophonic signals.11.2.2 INITIALIZATIONim<strong>in</strong>cps – estimated m<strong>in</strong>imum frequency (expressed <strong>in</strong> Hz) present <strong>in</strong> the signalimaxcps – estimated maximum frequency present <strong>in</strong> the signalicps – estimated <strong>in</strong>itial frequency of the signal. If 0, icps = (im<strong>in</strong>cps+imaxcps) / 2. The default is0.imedi – size of median filter applied to the output kcps. The size of the filter will be imedi*2+1.If 0, no median filter<strong>in</strong>g will be applied. The default is 1.idowns – downsampl<strong>in</strong>g factor for asig. Must be an <strong>in</strong>teger. A factor of idowns>1 results <strong>in</strong>faster performance, but may result <strong>in</strong> worse pitch detection. Useful range is 1 – 4. The default is1.iexcps – how frequently pitch analysis is executed, expressed <strong>in</strong> Hz. If 0, iexcps is set to im<strong>in</strong>cps.This is usually reasonable, but experimentation with other values may lead to better results.Default is 0.11.2.3 PERFORMANCEkcps – pitch track<strong>in</strong>g outputkrms – amplitude track<strong>in</strong>g outputpitchamdf usually works best for monophonic signals, and is quite reliable if appropriate <strong>in</strong>itialvalues are chosen. Sett<strong>in</strong>g im<strong>in</strong>cps and imaxcps as narrow as possible to the range of the signal’spitch, results <strong>in</strong> better detedtion and performance.Because this process can only detect pitch after an <strong>in</strong>itial delay, sett<strong>in</strong>g icps close to the signal’sreal <strong>in</strong>itial pitch prevents spurious data at the beg<strong>in</strong>n<strong>in</strong>g.The median filter prevents kcps from jump<strong>in</strong>g. Experiment to determ<strong>in</strong>e the optimum value forimedi for a given signal.Other <strong>in</strong>itial values can usually be left at the default sett<strong>in</strong>gs. Lowpass filter<strong>in</strong>g of asig beforepass<strong>in</strong>g it to pitchamdf, can improve preformance, especially with complex waveforms.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-3


11.2.4 EXAMPLEg<strong>in</strong>put ftgen 1, 0, 0, -1, "<strong>in</strong>put.wav", 0, 4, 0 ; <strong>in</strong>put signalgiwave ftgen 2, 0, 1024, 10, 1, 1, 1, 1 ; synth wave<strong>in</strong>str 1asig loscil 1, 1, g<strong>in</strong>put, 1 ; get <strong>in</strong>put signal; with orig<strong>in</strong>al freqasig tone asig, 1000 ; lowpass-filterkcps, krms pitchamdf asig, 150, 500, 200; extract pitch; and envelopeasig1 oscil krms, kcps, iwave ; "resynthesize"; with some waveformoutasig1end<strong>in</strong>11.2.5 AUTHORPeter NeubäckerMunich, GermanyAugust, 1999New <strong>in</strong> <strong>Csound</strong> version 3.59The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-4


11.3 tempestktemp tempest k<strong>in</strong>, iprd, im<strong>in</strong>dur, imemdur, ihp, ithresh, ihtim,ixfdbak, istartempo, ifn[, idisprd, itweek]11.3.1 DESCRIPTIONEstimate the tempo of beat patterns <strong>in</strong> a control signal.11.3.2 INITIALIZATIONiprd – period between analyses (<strong>in</strong> seconds). Typically about .02 seconds.im<strong>in</strong>dur – m<strong>in</strong>imum duration (<strong>in</strong> seconds) to serve as a unit of tempo. Typically about .2seconds.imemdur – duration (<strong>in</strong> seconds) of the k<strong>in</strong> short-term memory buffer which will be scanned forperiodic patterns. Typically about 3 seconds.ihp – half-power po<strong>in</strong>t (<strong>in</strong> Hz) of a low-pass filter used to smooth <strong>in</strong>put k<strong>in</strong> prior to otherprocess<strong>in</strong>g. This will tend to suppress activity that moves much faster. Typically 2 Hz.ithresh- loudness threshold by which the low-passed k<strong>in</strong> is center-clipped before be<strong>in</strong>g placed <strong>in</strong>the short-term buffer as tempo-relevant data. Typically at the noise floor of the <strong>in</strong>com<strong>in</strong>g data.ihtim – half-time (<strong>in</strong> seconds) of an <strong>in</strong>ternal forward-mask<strong>in</strong>g filter that masks new k<strong>in</strong> data <strong>in</strong>the presence of recent, louder data. Typically about .005 seconds.ixfdbak – proportion of this unit’s anticipated value to be mixed with the <strong>in</strong>com<strong>in</strong>g k<strong>in</strong> prior toall process<strong>in</strong>g. Typically about .3.istartempo – <strong>in</strong>itial tempo (<strong>in</strong> beats per m<strong>in</strong>ute). Typically 60.ifn – table number of a stored function (drawn left-to-right) by which the short-term memorydata is attenuated over time.idisprd (optional) – if non-zero, display the short-term past and future buffers every idisprdseconds (normally a multiple of iprd). The default value is 0 (no display).itweek (optional) – f<strong>in</strong>e-tune adjust this unit so that it is stable when analyz<strong>in</strong>g events controlledby its own output. The default value is 1 (no change).11.3.3 PERFORMANCEtempest exam<strong>in</strong>es k<strong>in</strong> for amplitude periodicity, and estimates a current tempo. The <strong>in</strong>put is firstlow-pass filtered, then center-clipped, and the residue placed <strong>in</strong> a short-term memory buffer(attenuated over time) where it is analyzed for periodicity us<strong>in</strong>g a form of autocorrelation. Theperiod, expressed as a tempo <strong>in</strong> beats per m<strong>in</strong>ute, is output as ktemp. The period is also used<strong>in</strong>ternally to make predictions about future amplitude patterns, and these are placed <strong>in</strong> a bufferadjacent to that of the <strong>in</strong>put. The two adjacent buffers can be periodically displayed, and thepredicted values optionally mixed with the <strong>in</strong>com<strong>in</strong>g signal to simulate expectation.This unit is useful for sens<strong>in</strong>g the metric implications of any k-signal (e.g.- the RMS of an audioThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-5


signal, or the second derivative of a conduct<strong>in</strong>g gesture), before send<strong>in</strong>g to a tempo statement.11.3.4 EXAMPLEksum specsum wsignal, 1 ; sum the amps of a spectrumktemp tempest ksum, .02, .1, 3, 2, 800, .005, 0, 60, 4, .1, .995; and look for beatsThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-6


11.4 followar follow asig, idt11.4.1 DESCRIPTIONEnvelope follower unit generator.11.4.2 INITIALIZATIONidt – This is the period, <strong>in</strong> seconds, that the average amplitude of asig is reported. If thefrequency of asig is low then idt must be large (more than half the period of asig )11.4.3 PERFORMANCEasig – This is the signal from which to extract the envelope.11.4.4 EXAMPLEk1 l<strong>in</strong>e 0, p3, 30000 ; Make k1 a simple envelopea1 oscil k1, 1000, 1 ; Make a simple signal us<strong>in</strong>g k1ak1 follow a1, .02 ; ak1 is now like k1a2 oscil ak1, 1000, 1 ; Make a simple signal us<strong>in</strong>g ak1out a2 ; Both a1 and a2 are the sameTo avoid zipper noise, by discont<strong>in</strong>uities produced from complex envelope track<strong>in</strong>g, a lowpassfilter could be used, to smooth the estimated envelope.11.4.5 AUTHORParis SmaragdisMIT, Cambridge1995The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-7


11.5 triggerkout trigger ksig, kthreshold, kmode11.5.1 DESCRIPTIONInforms when a krate signal crosses a threshold.11.5.2 PERFORMANCEksig – <strong>in</strong>put signalkthreshold – trigger thresholdkmode – can be 0 , 1 or 2Normally trigger outputs zeroes: only each time ksig crosses kthreshold trigger outputs a 1.There are three modes of us<strong>in</strong>g ktrig:• kmode = 0 – (down-up) ktrig outputs a 1 when current value of ksig is higher thankthreshold, while old value of ksig was equal to or lower than kthreshold.• kmode = 1 – (up-down) ktrig outputs a 1 when current value of ksig is lower thankthreshold while old value of ksig was equal or higher than kthreshold.• kmode = 2 – (both) ktrig outputs a 1 <strong>in</strong> both the two previous cases.11.5.3 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.49The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-8


11.6 peakkr peak ksigkr peak asig11.6.1 DESCRIPTIONThese opcodes ma<strong>in</strong>ta<strong>in</strong> the output k-rate variable as the peak absolute level so far received.11.6.2 PERFORMANCEkr – Output equal to the highest absolute value received so far. This is effectively an <strong>in</strong>put to theopcode as well, s<strong>in</strong>ce it reads kr <strong>in</strong> order to decide whether to write someth<strong>in</strong>g higher <strong>in</strong>to it.ksig – k-rate <strong>in</strong>put signal.asig – a-rate <strong>in</strong>put signal.11.6.3 DEPRECATED NAMEPrior to <strong>Csound</strong> version 3.63, the k-rate version of peak was called peakk. peak is now usedwith either k- or a-rate <strong>in</strong>put.11.6.4 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-9


11.7 xy<strong>in</strong>, tempokx, ky xy<strong>in</strong> iprd, ixm<strong>in</strong>, ixmax, iym<strong>in</strong>, iymax[, ix<strong>in</strong>it, iy<strong>in</strong>it]tempo ktempo, istartempo11.7.1 DESCRIPTIONSense the cursor position <strong>in</strong> an output w<strong>in</strong>dow. Apply tempo control to an un<strong>in</strong>terpreted score.When xy<strong>in</strong> is called the position of the mouse with<strong>in</strong> the output w<strong>in</strong>dow is used to reply to therequest. This simple mechanism does mean that only one xy<strong>in</strong> can be used accurately at once.The position of the mouse is reported <strong>in</strong> the output w<strong>in</strong>dow.11.7.2 INITIALIZATIONiprd- period of cursor sens<strong>in</strong>g (<strong>in</strong> seconds). Typically .1 seconds.xm<strong>in</strong>, xmax, ym<strong>in</strong>, ymax – edge values for the x-y coord<strong>in</strong>ates of a cursor <strong>in</strong> the <strong>in</strong>put w<strong>in</strong>dow.ix<strong>in</strong>it, iy<strong>in</strong>it (optional) – <strong>in</strong>itial x-y coord<strong>in</strong>ates reported; the default values are 0,0. If these valuesare not with<strong>in</strong> the given m<strong>in</strong>-max range, they will be coerced <strong>in</strong>to that range.istartempo – <strong>in</strong>itial tempo (<strong>in</strong> beats per m<strong>in</strong>ute). Typically 60.11.7.3 PERFORMANCExy<strong>in</strong> samples the cursor x-y position <strong>in</strong> an <strong>in</strong>put w<strong>in</strong>dow every iprd seconds. Output values arerepeated (not <strong>in</strong>terpolated) at the k-rate, and rema<strong>in</strong> fixed until a new change is registered <strong>in</strong> thew<strong>in</strong>dow. There may be any number of <strong>in</strong>put w<strong>in</strong>dows. This unit is useful for real-time control,but cont<strong>in</strong>uous motion should be avoided if iprd is unusually small.tempo allows the performance speed of <strong>Csound</strong> scored events to be controlled from with<strong>in</strong> anorchestra. It operates only <strong>in</strong> the presence of the <strong>Csound</strong> -t flag. When that flag is set, scoredevents will be performed from their un<strong>in</strong>terpreted p2 and p3 (beat) parameters, <strong>in</strong>itially at thegiven command-l<strong>in</strong>e tempo. When a tempo statement is activated <strong>in</strong> any <strong>in</strong>strument (ktempo 0.),the operat<strong>in</strong>g tempo will be adjusted to ktempo beats per m<strong>in</strong>ute. There may be any number oftempo statements <strong>in</strong> an orchestra, but co<strong>in</strong>cident activation is best avoided.11.7.4 EXAMPLEkx,ky xy<strong>in</strong> .05, 30, 0, 120, 0, 75 ; sample the cursortempo kx, 75 ; and control the tempo of performanceThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-10


11.8 follow2ar follow2 asig, katt, krel11.8.1 DESCRIPTIONA controllable envelope extractor us<strong>in</strong>g the algorithm attributed to Jean-Marc Jot.11.8.2 PERFORMANCEasig – the <strong>in</strong>put signal whose envelope is followedkatt – the attack rate (60dB attack time <strong>in</strong> seconds)krel – the decay rate (60dB decay time <strong>in</strong> seconds)The output tracks the amplitude envelope of the <strong>in</strong>put signal. The rate at which the output growsto follow the signal is controlled by the katt, and the rate at which it decreases <strong>in</strong> response to alower amplitude, is controlled by the krel. This gives a smoother envelope than follow.11.8.3 EXAMPLEa1 follow2 a<strong>in</strong>, 0.01, .111.8.4 AUTHORJohn ffitchUniversity of Bath, Codemist Ltd.Bath, UKFebruary, 2000New <strong>in</strong> <strong>Csound</strong> version 4.03The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-11


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Sens<strong>in</strong>g and Control Page 11-12


12 INSTRUMENT CONTROL: CONDITIONALVALUES12.1 >, =, b ? v1 : v2)(a < b ? v1 : v2)(a >= b ? v1 : v2)(a


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Conditional Values Page 12-2


13 INSTRUMENT CONTROL: MACROS13.1 #def<strong>in</strong>e, $NAME, #undef#def<strong>in</strong>e NAME # replacement text ##def<strong>in</strong>e NAME(a’ b’ c’) # replacement text #$NAME.#undef NAME13.1.1 DESCRIPTIONMacros are textual replacements which are made <strong>in</strong> the orchestra as it is be<strong>in</strong>g read. The macrosystem <strong>in</strong> <strong>Csound</strong> is a very simple one, and uses the characters # and $ to def<strong>in</strong>e and call macros.This can save typ<strong>in</strong>g, and can lead to a coherent structure and consistent style. This is similar to,but <strong>in</strong>dependent of, the macro system <strong>in</strong> the score language.#def<strong>in</strong>e NAME – def<strong>in</strong>es a simple macro. The name of the macro must beg<strong>in</strong> with a letter andcan consist of any comb<strong>in</strong>ation of letters and numbers. Case is significant. This form is limit<strong>in</strong>g,<strong>in</strong> that the variable names are fixed. More flexibility can be obta<strong>in</strong>ed by us<strong>in</strong>g a macro witharguments, described below.#def<strong>in</strong>e NAME(a’ b’ c’) – def<strong>in</strong>es a macro with arguments. This can be used <strong>in</strong> more complexsituations. The name of the macro must beg<strong>in</strong> with a letter and can consist of any comb<strong>in</strong>ation ofletters and numbers. With<strong>in</strong> the replacement text, the arguments can be substituted by the form:$A. In fact, the implementation def<strong>in</strong>es the arguments as simple macros. There may be up to 5arguments, and the names may be any choice of letters. Remember that case is significant <strong>in</strong>macro names.$NAME. – calls a def<strong>in</strong>ed macro. To use a macro, the name is used follow<strong>in</strong>g a $ character.The name is term<strong>in</strong>ated by the first character which is neither a letter nor a number. If it isnecessary for the name not to term<strong>in</strong>ate with a space, a period, which will be ignored, can beused to term<strong>in</strong>ate the name. The str<strong>in</strong>g, $NAME., is replaced by the replacement text from thedef<strong>in</strong>ition. The replacement text can also <strong>in</strong>clude macro calls.#undef NAME – undef<strong>in</strong>es a macro name. If a macro is no longer required, it can be undef<strong>in</strong>edwith #undef NAME.13.1.2 INITIALIZATION# replacement text # – The replacement text is any character str<strong>in</strong>g (not conta<strong>in</strong><strong>in</strong>g a #) and canextend over multiple l<strong>in</strong>es. The replacement text is enclosed with<strong>in</strong> the # characters, whichensure that additional characters are not <strong>in</strong>advertently captured.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Macros Page 13-1


13.1.3 PERFORMANCESome care is needed with textual replacement macros, as they can sometimes do strange th<strong>in</strong>gs.They take no notice of any mean<strong>in</strong>g, so spaces are significant. This is why, unlike the Cprogramm<strong>in</strong>g language, the def<strong>in</strong>ition has the replacement text surrounded by # characters. Usedcarefully, this simple macro system is a powerful concept, but it can be abused.13.1.4 EXAMPLES13.1.4.1 Simple Macro#def<strong>in</strong>e REVERB #ga = ga+a1out a1#<strong>in</strong>str 1a1$REVERB.end<strong>in</strong>oscil<strong>in</strong>str 2a1$REVERB.end<strong>in</strong>repluckThis will get expanded before compilation <strong>in</strong>to:<strong>in</strong>str 1a1ga = ga+a1out a1end<strong>in</strong>oscil<strong>in</strong>str 2a1ga = ga+a1out a1end<strong>in</strong>repluck13.1.4.2 Macro With Arguments#def<strong>in</strong>e REVERB(A) #ga = ga+$A.out $A.#<strong>in</strong>str 1a1$REVERB(a1)end<strong>in</strong>oscil<strong>in</strong>str 2a2$REVERB(a2)end<strong>in</strong>repluckThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Macros Page 13-2


This will get expanded before compilation <strong>in</strong>to:<strong>in</strong>str 1a1ga = ga+a1out a1end<strong>in</strong><strong>in</strong>str 2a2ga = ga+a2out a2end<strong>in</strong>13.1.5 AUTHORoscilrepluckJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Macros Page 13-3


13.2 #<strong>in</strong>clude#<strong>in</strong>clude“filename”13.2.1 DESCRIPTION:It is sometimes convenient to have the orchestra arranged <strong>in</strong> a number of files, for example witheach <strong>in</strong>strument <strong>in</strong> a separate file. This style is supported by the #<strong>in</strong>clude facility which is partof the macro system. A l<strong>in</strong>e conta<strong>in</strong><strong>in</strong>g the text#<strong>in</strong>clude “filename”where the character “ can be replaced by any suitable character. For most uses the double quotesymbol will probably be the most convenient. The file name can <strong>in</strong>clude a full path.This takes <strong>in</strong>put from the named file until it ends, when <strong>in</strong>put reverts to the previous <strong>in</strong>put.There is currently a limit of 20 on the depth of <strong>in</strong>cluded files and macros.Another suggested use of #<strong>in</strong>clude would be to def<strong>in</strong>e a set of macros which are part of thecomposer’s style.An extreme form would be to have each <strong>in</strong>strument def<strong>in</strong>es as a macro, with the <strong>in</strong>strumentnumber as a parameter. Then an entire orchestra could be constructed from a number of#<strong>in</strong>clude statements followed by macro calls.#<strong>in</strong>clude “clar<strong>in</strong>et”#<strong>in</strong>clude “flute”#<strong>in</strong>clude “bassoon”$CLARINET(1)$FLUTE(2)$BASSOON(3)It must be stressed that these changes are at the textual level and so take no cognizance of anymean<strong>in</strong>g.13.2.2 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Macros Page 13-4


14 INSTRUMENT CONTROL: PROGRAM FLOWCONTROL14.1 igoto, tigoto, kgoto, goto, if, timoutigototigotokgotogotoifififtimoutlabellabellabellabelia R ib igoto labelka R kb kgoto labelia R ib goto labelistrt, idur, label14.1.1 DESCRIPTIONwhere label is <strong>in</strong> the same <strong>in</strong>strument block and is not an expression, and where R is one of theRelational operators (


timout – conditional branch dur<strong>in</strong>g p-time, depend<strong>in</strong>g on elapsed note time. istrt and idurspecify time <strong>in</strong> seconds. The branch to label will become effective at time istrt, and will rema<strong>in</strong>so for just idur seconds. Note that timout can be re<strong>in</strong>itialized for multiple activation with<strong>in</strong> as<strong>in</strong>gle note ( see example under re<strong>in</strong>it).14.1.2 EXAMPLEif k3 p5 + 10 kgoto nextThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Program Flow Control Page 14-2


15 INSTRUMENT CONTROL: REINITIALIZATION15.1 re<strong>in</strong>it, rigoto, rireturnre<strong>in</strong>itrigotorireturnlabellabel15.1.1 DESCRIPTIONThese statements permit an <strong>in</strong>strument to re<strong>in</strong>itialize itself dur<strong>in</strong>g performance.re<strong>in</strong>it – whenever this statement is encountered dur<strong>in</strong>g a p-time pass, performance is temporarilysuspended while a special Initialization pass, beg<strong>in</strong>n<strong>in</strong>g at label and cont<strong>in</strong>u<strong>in</strong>g to rireturn orend<strong>in</strong>, is executed. Performance will then be resumed from where it left off.rigoto – similar to igoto, but effective only dur<strong>in</strong>g a re<strong>in</strong>it pass (i.e., no-op at standard i-time).This statement is useful for bypass<strong>in</strong>g units that are not to be re<strong>in</strong>itialized.rireturn – term<strong>in</strong>ates a re<strong>in</strong>it pass (i.e., no-op at standard i-time). This statement, or an end<strong>in</strong>,will cause normal performance to be resumed.15.1.2 EXAMPLEThe follow<strong>in</strong>g statements will generate an exponential control signal whose value moves from440 to 880 exactly ten times over the duration p3.reset: timout 0, p3 /10, cont<strong>in</strong> ; after p3/10 seconds,re<strong>in</strong>it reset ; re<strong>in</strong>it both timoutcont<strong>in</strong>: expon 440, p3/10,880 ; and exponrireturn; then resume perfThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Re<strong>in</strong>itialization Page 15-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Instrument Control: Re<strong>in</strong>itialization Page 15-2


16 MATHEMATICAL OPERATIONS:ARITHMETIC AND LOGIC OPERATIONS16.1 -, +, &&, ||, *, /, ^, %- a (no rate restriction)+ a (no rate restriction)a && b (logical AND; not audio-rate)a || b (logical OR; not audio-rate)a + b (no rate restriction)a - b (no rate restriction)a * b (no rate restriction)a / b (no rate restriction)a ^ b (b not audio-rate)a % b (no rate restriction)16.1.1 DESCRIPTIONwhere the arguments a and b may be further expressions.Arithmetic operators perform operations of change-sign (negate), don’t-change-sign, logicalAND logical OR, add, subtract, multiply and divide. Note that a value or an expression may fallbetween two of these operators, either of which could take it as its left or right argument, as <strong>in</strong>a + b * c.In such cases three rules apply:1. * and / b<strong>in</strong>d to their neighbors more strongly than + and -. Thus the above expression istaken asa + (b * c)with * tak<strong>in</strong>g b and c and then + tak<strong>in</strong>g a and b * c.2. + and - b<strong>in</strong>d more strongly than &&, which <strong>in</strong> turn is stronger than ||:a && b – c || dis taken as(a && (b – c)) || d3. When both operators b<strong>in</strong>d equally strongly, the operations are done left to right:a – b – cis taken as(a – b) – cParentheses may be used as above to force particular group<strong>in</strong>gs.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Arithmetic and Logic Operations Page 16-1


The operator ^ raises a to the b power. b may not be audio-rate. Use with caution as precedencemay not work correctly. See Section 5.2. New <strong>in</strong> <strong>Csound</strong> version 3.493.The operator % returns the value of a reduced by b, so that the result, <strong>in</strong> absolute value, is that ofthe absolute value of b, by repeated subtraction. This is the same as modulus function <strong>in</strong> <strong>in</strong>tegers.New <strong>in</strong> <strong>Csound</strong> version 3.50.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Arithmetic and Logic Operations Page 16-2


17 MATHEMATICAL OPERATIONS:MATHEMATICAL FUNCTIONS17.1 <strong>in</strong>t, frac, i, abs, exp, log, log10, sqrt<strong>in</strong>t(x)frac(x)i(x)abs(x)exp(x)log(x)log10(x)sqrt(x)(<strong>in</strong>it- or control-rate args only)(<strong>in</strong>it- or control-rate args only)(control-rate args only)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)17.1.1 DESCRIPTIONWhere the argument with<strong>in</strong> the parentheses may be an expression. These functions performarithmetic translation from units of one k<strong>in</strong>d to units of another. The result can then be a term <strong>in</strong>a further expression.<strong>in</strong>t(x) – returns the <strong>in</strong>teger part of x.frac(x) – returns the fractional part of x.i(x) – returns an <strong>in</strong>it-type equivalent of the argument (k-rate)abs(x) – returns the absolute value of x.exp(x) – returns e raised to the xth power.log(x) – returns the natural log of x (x positive only).log10(x) – returns the base 10 log of x (x positive only).sqrt(x) – returns the square root of x (x non-negative).Note that for log, log10, and sqrt the argument value is restricted.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Mathematical Functions Page 17-1


17.2 powoftwo, logbtwopowoftwo(x) (<strong>in</strong>it-rate or control-rate args only)logbtwo(x) (<strong>in</strong>it-rate or control-rate args only)17.2.1 DESCRIPTIONPower-of-two operations.17.2.2 PERFORMANCEpowoftwo() function returns 2 ^ x and allows positive and negatives numbers as argument. Therange of values admitted <strong>in</strong> powoftwo() is -5 to +5 allow<strong>in</strong>g a precision more f<strong>in</strong>e than one cent<strong>in</strong> a range of ten octaves. If a greater range of values is required, use the slower opcode pow.logbtwo() returns the logarithm base two of x. The range of values admitted as argument is .25 to4 (i.e. from -2 octave to +2 octave response). This function is the <strong>in</strong>verse of powoftwo().These functions are fast, because they read values stored <strong>in</strong> tables. Also they are very usefulwhen work<strong>in</strong>g with tun<strong>in</strong>g ratios. They work at i- and k-rate.17.2.3 AUTHORSGabriel MaldonadoItalyJune, 1998John ffitchUniversity of Bath, Codemist, Ltd.Bath, UKJuly, 1999New <strong>in</strong> <strong>Csound</strong> version 3.57The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Mathematical Functions Page 17-2


18 MATHEMATICAL OPERATIONS:TRIGONOMETRIC FUNCTIONS18.1 s<strong>in</strong>, cos, tan, s<strong>in</strong><strong>in</strong>v, cos<strong>in</strong>v, tan<strong>in</strong>v, s<strong>in</strong>h, cosh, tanhs<strong>in</strong>(x)cos(x)tan(x)s<strong>in</strong><strong>in</strong>v(x)cos<strong>in</strong>v(x)tan<strong>in</strong>v(x)s<strong>in</strong>h(x)cosh(x)tanh(x)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)18.1.1 DESCRIPTIONWhere the argument with<strong>in</strong> the parentheses may be an expression. These functions performtrigonometric conversions. The result can then be a term <strong>in</strong> a further expression.s<strong>in</strong>(x) – returns the s<strong>in</strong>e of x (x <strong>in</strong> radians).cos(x) – returns the cos<strong>in</strong>e of x (x <strong>in</strong> radians).tan (x) – returns the tangent of x.s<strong>in</strong><strong>in</strong>v(x) – returns the arcs<strong>in</strong>e of x.cos<strong>in</strong>v(x) – returns the arcos<strong>in</strong>e of x.tan<strong>in</strong>v(x) – returns the arctangent of x.s<strong>in</strong>h(x) – returns the hyperbolic s<strong>in</strong>e of x.cosh(x) – returns the hyperbolic cos<strong>in</strong>e of x.tanh (x) – returns the hyperbolic tangent of x .The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Trigonometric Functions Page 18-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Trigonometric Functions Page 18-2


19 MATHEMATICAL OPERATIONS: AMPLITUDEFUNCTIONS19.1 dbamp, ampdbdbamp(x)ampdb(x)(<strong>in</strong>it- or control-rate args only)(no rate restriction)19.1.1 DESCRIPTIONWhere the argument with<strong>in</strong> the parentheses may be an expression. These functions performconversions between raw amplitude values and their decibel equivelents. The result can then be aterm <strong>in</strong> a further expression.dbamp(x) – returns the decibel equivalent of the raw amplitude x.ampdb(x) – returns the amplitude equivalent of the decibel value x. Thus:60 dB = 100066 dB = 1995.26272 dB = 3891.0778 dB = 7943.27984 dB = 15848.92690 dB = 31622.764The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Amplitude Functions Page 19-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Amplitude Functions Page 19-2


20 MATHEMATICAL OPERATIONS: RANDOMFUNCTIONS20.1 rnd, birndrnd(x)birnd(x)(<strong>in</strong>it- or control-rate args only)(<strong>in</strong>it- or control-rate args only)20.1.1 DESCRIPTIONWhere the argument with<strong>in</strong> the parentheses may be an expression. These value converterssample a global random sequence, but do not reference seed. The result can be a term <strong>in</strong> afurther expression.20.1.2 PERFORMANCErnd(x) – returns a random number <strong>in</strong> the unipolar range 0 to x.birnd(x) – returns a random number <strong>in</strong> the bipolar range -x to x. rnd and birnd obta<strong>in</strong> valuesfrom a global pseudo-random number generator, then scale them <strong>in</strong>to the requested range. Thes<strong>in</strong>gle global generator will thus distribute its sequence to these units throughout theperformance, <strong>in</strong> whatever order the requests arrive20.1.3 AUTHORBarry VercoeMITCambridge, Massachusetts1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Random Functions Page 20-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Operations: Random Functions Page 20-2


21 MATHEMATICAL FUNCTIONS: OPCODEEQUIVALENTS OF FUNCTIONS21.1 sumar sum asig1, asig2[, asig3...asigN]21.1.1 DESCRIPTIONSums any number of a-rate signals.21.1.2 PERFORMANCEasig1, etc. – a-rate signals to be summed (mixed or added).21.1.3 AUTHORGabriel MaldonadoItalyApril, 1999New <strong>in</strong> <strong>Csound</strong> version 3.54The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Functions: Opcode Equivalents of Functions Page 21-1


21.2 productar product asig1, asig2[, asig3...asigN]21.2.1 DESCRIPTIONMultiplies any number of a-rate signals.21.2.2 PERFORMANCEasig1, etc. – a-rate signals to be multiplied.21.2.3 AUTHORGabriel MaldonadoItalyApril, 1999New <strong>in</strong> <strong>Csound</strong> version 3.54The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Functions: Opcode Equivalents of Functions Page 21-2


21.3 powir pow iarg, ipowir = iarg ^ ipowkr pow karg, kpow[, <strong>in</strong>orm]ar pow aarg, kpow[, <strong>in</strong>orm]21.3.1 DESCRIPTIONComputes xarg to the power of kpow (or ipow) and scales the result by <strong>in</strong>orm.21.3.2 INITIALIZATION<strong>in</strong>orm – The number to divide the result (default to 1). This is especially useful if you are do<strong>in</strong>gpowers of a- or k- signals where samples out of range are extremely common!iarg – i-rate baseipow – i-rate exponent21.3.3 PERFORMANCEkarg – k-rate base.kpow – k-rate exponentaarg – a-rate base.21.3.4 EXAMPLESi2t2 pow 2,2 ; Computes 2^2.kl<strong>in</strong>e l<strong>in</strong>e 0, 1, 4kexp pow kl<strong>in</strong>e, 2, 4This feeds a l<strong>in</strong>ear function to pow and scales that to the l<strong>in</strong>e’s peak value. The output will be anexponential curve with the same range as the <strong>in</strong>put l<strong>in</strong>e.iamp pow 10, 2a1 oscil iamp, 100, 1a2 pow a1, 2, iampouta2This will output a s<strong>in</strong>e with its negative part folded over the amplitude axis. The peak value willbe iamp = 10^2 = 100.The first l<strong>in</strong>e could also be written:i2t2 = 2 ^ 2Use ^ with caution <strong>in</strong> arithmetical statements, as the precedence may not be correct. Thisoperator is new as of <strong>Csound</strong> version 3.493.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Functions: Opcode Equivalents of Functions Page 21-3


21.3.5 DEPRECATED NAMESpow was orig<strong>in</strong>ally three opcodes called ipow, kpow, and apow. As of <strong>Csound</strong> version 3.48those names are deprecated, and the three seperate opcodes replaced by pow.21.3.6 AUTHORParis SmaragdisMIT, Cambridge1995The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Functions: Opcode Equivalents of Functions Page 21-4


21.4 tan<strong>in</strong>v2ir tan<strong>in</strong>v2 ix, iykr tan<strong>in</strong>v2 kx, kyar tan<strong>in</strong>v2 ax, ay21.4.1 DESCRIPTIONReturns the arctangent of iy/ix, ky/kx, or ay/ax. If either x or y is zero, tan<strong>in</strong>v2 returns zero.21.4.2 INITIALIZATIONix, iy – values to be converted21.4.3 PERFORMANCEkx, ky – control rate signals to be convertedax, ay – audio rate signals to be converted21.4.4 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Functions: Opcode Equivalents of Functions Page 21-5


21.5 mac, macaar mac asig1, ksig1, asig2[, ksig2, asig3, ...asigN, ksigN]ar maca asig1, asig2[, asig3, asig4, asig5, ...asigN]21.5.1 DESCRIPTIONMultiply and accumulate k- and/or a-rate signals.21.5.2 PERFORMANCEksig1, etc. – k-rate <strong>in</strong>put signalsasig1, etc. – a-rate <strong>in</strong>put signalsmac multiplies and accumulates a- and k-rate signals. It is equivalent to:ar = asig1 + ksig1*asig2 + ksig2+asig3 + ...maca multiplies and accumulates a-rate signals only. It is equivalent to:ar = asig1 + asig2*asig3 + asig4+asig5 + ...21.5.3 AUTHORJohn ffitchUniversity of Bath, Codemist, Ltd.Bath, UKMay, 1999New <strong>in</strong> <strong>Csound</strong> version 3.55The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Mathematical Functions: Opcode Equivalents of Functions Page 21-6


22 PITCH CONVERTERS: FUNCTIONS22.1 octpch, pchoct, cpspch, octcps, cpsoctoctpch (pch) (<strong>in</strong>it- or control-rate args only)pchoct (oct) (<strong>in</strong>it- or control-rate args only)cpspch (pch) (<strong>in</strong>it- or control-rate args only)octcps (cps) (<strong>in</strong>it- or control-rate args only)cpsoct (oct) (no rate restriction)22.1.1 DESCRIPTIONwhere the argument with<strong>in</strong> the parentheses may be a further expression.These are really value converters with a special function of manipulat<strong>in</strong>g pitch data.Data concern<strong>in</strong>g pitch and frequency can exist <strong>in</strong> any of the follow<strong>in</strong>g forms:Nameoctave po<strong>in</strong>t pitch-class (8ve.pc)octave po<strong>in</strong>t decimalcycles per secondAbbreviationpchoctcps (Hz)The first two forms consist of a whole number, represent<strong>in</strong>g octave registration, followed by aspecially <strong>in</strong>terpreted fractional part. For pch, the fraction is read as two decimal digitsrepresent<strong>in</strong>g the 12 equal-tempered pitch classes from .00 for C to.11 for B. For oct, the fractionis <strong>in</strong>terpreted as a true decimal fractional part of an octave. The two fractional forms are thusrelated by the factor 100/12. In both forms, the fraction is preceded by a whole number octave<strong>in</strong>dex such that 8.00 represents Middle C, 9.00 the C above, etc. Thus A440 can be representedalternatively by 440 (cps),8.09 (pch), 8.75 (oct), or 7.21 (pch), etc. Microtonal divisions of thepch semitone can be encoded by us<strong>in</strong>g more than two decimal places.The mnemonics of the pitch conversion units are derived from morphemes of the forms<strong>in</strong>volved, the second morpheme describ<strong>in</strong>g the source and the first morpheme the object (result).Thuscpspch(8.09)will convert the pitch argument 8.09 to its cps (or Hertz) equivalent, giv<strong>in</strong>g the value of 440.S<strong>in</strong>ce the argument is constant over the duration of the note, this conversion will take place at i-time, before any samples for the current note are produced. By contrast, the conversioncpsoct(8.75 + k1)which gives the value of A440 transposed by the octave <strong>in</strong>terval k1 will repeat the calculationevery, k-period s<strong>in</strong>ce that is the rate at which k1 varies.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Pitch Converters: Functions Page 22-1


Note: The conversion from pch or oct <strong>in</strong>to cps is not a l<strong>in</strong>ear operation but <strong>in</strong>volves anexponential process that could be time-consum<strong>in</strong>g when executed repeatedly. <strong>Csound</strong> now uses abuilt-<strong>in</strong> table lookup to do this efficiently, even at audio rates.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Pitch Converters: Functions Page 22-2


23 PITCH CONVERTERS: TUNING OPCODES23.1 cps2pch, cpsxpchicps cps2pch ipch, iequalicps cpsxpch ipch, iequal, irepeat, ibase23.1.1 DESCRIPTIONConverts a pitch-class notation <strong>in</strong>to cycles-per-second (Hz) for equal divisions of the octave (forcps2pch) or for equal divisions of any <strong>in</strong>terval. There is a restriction of no more than 100 equaldivisions.23.1.2 INITIALIZATIONipch – Input number of the form 8ve.pc, <strong>in</strong>dicat<strong>in</strong>g an ‘octave’ and which note <strong>in</strong> the octave.iequal – if positive, the number of equal <strong>in</strong>tervals <strong>in</strong>to which the ‘octave’ is divided. Must be lessthan or equal to 100. If negative, is the number of a table of frequency multipliers.irepeat – Number <strong>in</strong>dicat<strong>in</strong>g the <strong>in</strong>terval which is the ‘octave.’ The <strong>in</strong>teger 2 corresponds tooctave divisions, 3 to a twelfth, 4 is two octaves, and so on. This need not be an <strong>in</strong>teger, but mustbe positive.ibase – The frequency which corresponds to pitch 0.0Note:1. The follow<strong>in</strong>g are essentially the sameia = cpspch(8.02)ib cps2pch 8.02, 12ic cpsxpch 8.02, 12, 2, 1.021975039062. These are opcodes not functions.3. Negative values of ipch are allowed, but not negative irepeat, iequal or ibase.23.1.3 EXAMPLE<strong>in</strong>ote cps2pch p5, 19 ; convert oct.pch to; cps <strong>in</strong> 19ET<strong>in</strong>ote cpsxpch p5, 12, 3, 261.62561 ; Pierce scale centered; on middle A<strong>in</strong>ote cpsxpch p5, 21, 4, 16.35160062496 ; 10.5ET scaleThe use of a table allows exotic scales by mapp<strong>in</strong>g frequencies <strong>in</strong> a table. For example the table:f2 0 16 -2 1 1.1 1.2 1.3 1.4 1.6 1.7 1.8 1.9can be used with:ip cps2pch p4, -2to get a 10 note scale of unequal divisions.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Pitch Converters: Tun<strong>in</strong>g Opcodes Page 23-1


23.1.4 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd. Gabriel MaldonadoItaly1998 (New <strong>in</strong> <strong>Csound</strong> version 3.492)Bath, UK1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Pitch Converters: Tun<strong>in</strong>g Opcodes Page 23-2


24 MIDI SUPPORT: CONVERTERS24.1 notnum, veloc, cpsmidi, cpsmidib, octmidi, octmidib,pchmidi, pchmidib, ampmidi, aftouch, pchbend,midictrlival notnumival veloc [ilow, ihigh]icps cpsmidiicps cpsmidib [irange]kcps cpsmidib [irange]ioct octmidiioct octmidib [irange]koct octmidib [irange]ipch pchmidiipch pchmidib [irange]kpch pchmidib [irange]iamp ampmidi iscal[, ifn]kaft aftouch [im<strong>in</strong>[, imax]]ibend pchbend [im<strong>in</strong>[, imax]]kbend pchbend [im<strong>in</strong>[, imax]]ival midictrl <strong>in</strong>um[im<strong>in</strong>[, imax]]kval midictrl <strong>in</strong>um[im<strong>in</strong>[, imax]]24.1.1 DESCRIPTIONGet a value from the MIDI event that activated this <strong>in</strong>strument, or from a cont<strong>in</strong>uous MIDIcontroller, and convert it to a locally useful format.24.1.2 INITIALIZATIONiscal – i-time scal<strong>in</strong>g factor.ifn (optional) – function table number of a normalized translation table, by which the <strong>in</strong>com<strong>in</strong>gvalue is first <strong>in</strong>terpreted. The default value is 0, denot<strong>in</strong>g no translation.<strong>in</strong>um, ictlno - MIDI controller number<strong>in</strong>itial – the <strong>in</strong>itial value of the controllerilow, ihigh – low and high ranges for mapp<strong>in</strong>girange – the pitch bend range <strong>in</strong> semitonesichnl – the MIDI channelim<strong>in</strong>, imax – set m<strong>in</strong>imum and maximum limits on values obta<strong>in</strong>edThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Converters Page 24-1


24.1.3 PERFORMANCEnotnum, veloc – get the MIDI byte value (0 – 127) denot<strong>in</strong>g the note number or velocity of thecurrent event.cpsmidi, octmidi, pchmidi – get the note number of the current MIDI event, expressed <strong>in</strong> cps,oct, or pch units for local process<strong>in</strong>g.cpsmidib, octmidib, pchmidib – get the note number of the current MIDI event, modify it bythe current pitch-bend value, and express the result <strong>in</strong> cps, oct, or pch units. Available as an i-time value or as a cont<strong>in</strong>uous k-rate value.ampmidi – get the velocity of the current MIDI event, optionally pass it through a normalizedtranslation table, and return an amplitude value <strong>in</strong> the range 0 – iscal.aftouch, pchbend – get the current after-touch, or pitch-bend value for this channel, rescaled tothe range 0 – iscal. Note that this access to pitch-bend data is <strong>in</strong>dependent of the MIDI pitch,enabl<strong>in</strong>g the value here to be used for any arbitrary purpose.midictrl – get the current value (0 – 127) of a specified MIDI controller.24.1.4 AUTHORBarry Vercoe – Mike BerryMIT – MillsMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Converters Page 24-2


24.2 cpstmidicpscpstmid ifn24.2.1 DESCRIPTIONThis unit is similar to cpsmidi, but allows fully customized micro-tun<strong>in</strong>g scales.24.2.2 INITIALIZATIONifn – function table conta<strong>in</strong><strong>in</strong>g the parameters (numgrades, <strong>in</strong>terval, basefreq, basekeymidi) andthe tun<strong>in</strong>g ratios.24.2.3 PERFORMANCEInit-rate onlycpsmid requires five parameters. The first, ifn, is the function table number of the tun<strong>in</strong>g ratios,and the other parameters must be stored <strong>in</strong> the function table itself. The function table ifn shouldbe generated by GEN2, with normalization <strong>in</strong>hibited. The first four values stored <strong>in</strong> this functionare:1. numgrades – the number of grades of the micro-tun<strong>in</strong>g scale2. <strong>in</strong>terval – the frequency range covered before repeat<strong>in</strong>g the grade ratios,for example 2 forone octave, 1.5 for a fifth etc.3. basefreq – the base frequency of the scale <strong>in</strong> Hz4. basekeymidi – the MIDI note number to which basefreq is assigned unmodifiedAfter these four values, the user can beg<strong>in</strong> to <strong>in</strong>sert the tun<strong>in</strong>g ratios. For example, for a standard12 note scale with the base frequency of 261 Hz assigned to the key number 60, thecorrespond<strong>in</strong>g f statement <strong>in</strong> the score to generate the table should be:; numgrades basefreq tun<strong>in</strong>g-ratios (equal temp); <strong>in</strong>terval basekeymidif1 0 64 -2 12 2 261 60 1 1.0594630943591.122462048309 1.189207115003 ..etc...Another example with a 24 note scale with a base frequency of 440 assigned to the key number48, and a repetition <strong>in</strong>terval of 1.5:; numgrades basefreq tun<strong>in</strong>g-ratios .......; <strong>in</strong>terval basekeymidif1 0 64 -2 24 1.5 440 48 1 1.01 1.02 1.03..etc...24.2.4 AUTHORGabriel MaldonadoItaly1998 (New <strong>in</strong> <strong>Csound</strong> version 3.492)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Converters Page 24-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Converters Page 24-4


25 MIDI SUPPORT: CONTROLLER INPUT25.1 <strong>in</strong>itc7, <strong>in</strong>itc14, <strong>in</strong>itc21<strong>in</strong>itc7<strong>in</strong>itc14<strong>in</strong>itc21ichan, ictlno, ivalueichan, ictlno1, ictlno2, ivalueichan, ictlno1, ictlno2, ictlno3, ivalue25.1.1 DESCRIPTIONInitializes MIDI controller ictlno with ivalue25.1.2 INITIALIZATIONichan - MIDI channelictlno – controller number (<strong>in</strong>itc7)ictlno1 – most significant byte controller numberictlno2 – <strong>in</strong> <strong>in</strong>itc14 least significant byte controller number; <strong>in</strong> <strong>in</strong>itc21 Medium Significant Bytecontroller numberictlno3 – least significant byte controller numberivalue – float<strong>in</strong>g po<strong>in</strong>t value (must be with<strong>in</strong> 0 to 1)25.1.3 PERFORMANCE<strong>in</strong>itc7, <strong>in</strong>itc14, <strong>in</strong>itc21 can be used together with both midicXX and ctrlXX opcodes for<strong>in</strong>itializ<strong>in</strong>g the first controller’s value. ivalue argument must be set with a number with<strong>in</strong> 0 to 1.An error occurs if it is not. Use the follow<strong>in</strong>g formula to set ivalue accord<strong>in</strong>g with midicXX andctrlXX m<strong>in</strong> and max range:ivalue = (<strong>in</strong>itial_value – m<strong>in</strong>) / (max – m<strong>in</strong>)25.1.4 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Controller Input Page 25-1


25.2 midic7, midic14, midic21, ctrl7, ctrl14, ctrl21idest midic7 ictlno, im<strong>in</strong>, imax [, ifn]kdest midic7 ictlno, km<strong>in</strong>, kmax [, ifn]idest midic14 ictlno1, ictlno2, im<strong>in</strong>, imax [, ifn]kdest midic14 ictlno1, ictlno2, km<strong>in</strong>, kmax [, ifn]idest midic21 ictlno1, ictlno2, ictlno3, im<strong>in</strong>, imax [, ifn]kdest midic21 ictlno1, ictlno2, ictlno3, km<strong>in</strong>, kmax [, ifn]idest ctrl7 ichan, ictlno, im<strong>in</strong>, imax [,ifn]kdest ctrl7 ichan, ictlno, km<strong>in</strong>, kmax [,ifn]idest ctrl14 ichan, ictlno1, ictlno2, im<strong>in</strong>, imax [,ifn]kdest ctrl14 ichan, ictlno1, ictlno2, km<strong>in</strong>, kmax [,ifn]idest ctrl21 ichan, ictlno1, ictlno2, ictlno3, im<strong>in</strong>, imax [,ifn]kdest ctrl21 ichan, ictlno1, ictlno2, ictlno3, km<strong>in</strong>, kmax [,ifn]25.2.1 DESCRIPTIONAllow precise MIDI <strong>in</strong>put controller signal.25.2.2 INITIALIZATIONidest – output signalictlno – MIDI controller number (1-127)ictlno1 – most-significant byte controller number (1-127)ictlno2 – <strong>in</strong> midic14: least-significant byte controller number (1-127); <strong>in</strong> midic21: midsignificantbyte controller number (1-127)ictlno3 – least-significant byte controller number (1-127)im<strong>in</strong> – user-def<strong>in</strong>ed m<strong>in</strong>imum float<strong>in</strong>g-po<strong>in</strong>t value of outputimax – user-def<strong>in</strong>ed maximum float<strong>in</strong>g-po<strong>in</strong>t value of outputifn (optional) – table to be read when <strong>in</strong>dex<strong>in</strong>g is required. Table must be normalized. Output isscaled accord<strong>in</strong>g to imax and im<strong>in</strong> val.25.2.3 PERFORMANCEkdest – output signalkm<strong>in</strong> – user-def<strong>in</strong>ed m<strong>in</strong>imum float<strong>in</strong>g-po<strong>in</strong>t value of outputkmax – user-def<strong>in</strong>ed maximum float<strong>in</strong>g-po<strong>in</strong>t value of outputThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Controller Input Page 25-2


midic7 (i- and k-rate 7 bit MIDI control) allows float<strong>in</strong>g po<strong>in</strong>t 7 bit MIDI signal scaled with am<strong>in</strong>imum and a maximum range. It also allows optional non-<strong>in</strong>terpolated table <strong>in</strong>dex<strong>in</strong>g. Inmidic7 m<strong>in</strong>imum and maximum values can be varied at k-rate. midic14 (i- and k-rate 14 bitMIDI control) do the same as the above with 14 bit precision. midic21 (i- and k-rate 21 bit MIDIcontrol) do the same as the above with 21 bit precision. midic14 and midic21 can use optional<strong>in</strong>terpolated table <strong>in</strong>dex<strong>in</strong>g. They require two or three MIDI controllers as <strong>in</strong>put.ctrl7, ctrl14, ctrl21 are very similar to midicXX opcodes the only differences are:• ctrlXX UGs can be <strong>in</strong>cluded <strong>in</strong> score oriented <strong>in</strong>struments without <strong>Csound</strong> crashes.• They need the additional parameter ichan conta<strong>in</strong><strong>in</strong>g the MIDI channel of the controller.MIDI channel is the same for all the controller used <strong>in</strong> a s<strong>in</strong>gle ctrl14 or ctrl21 opcode.25.2.4 DEPRECATED NAMESThe opcode names imidic7, imidic14, imidic21, ictrl7, ictrl14, and ictrl21 have beendeprecated <strong>in</strong> <strong>Csound</strong> version 3.52. Instead use imidic7, imidic14, imidic21, ictrl7, ictrl14, andictrl21, respectively, with i-rate outputs.25.2.5 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Controller Input Page 25-3


25.3 chanctrlival chanctrl ichnl, ictlno[,ilow,ihigh]kval chanctrl ichnl, ictlno[,ilow,ihigh]25.3.1 DESCRIPTIONGet the current value of a controller and optionally map it onto specified range.25.3.2 INITIALIZATIONichnl – the MIDI channelictlno – the MIDI controller numberilow, ihigh – low and high ranges for mapp<strong>in</strong>g25.3.3 AUTHORMike BerryMills CollegeMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Controller Input Page 25-4


26 MIDI SUPPORT: SLIDER BANKS26.1 slider8, slider16, slider32, slider64, slider8f, slider16f,slider32f, slider64f, s16b14, s32b14i1, ..., i8 slider8 ichan, ictlnum1, im<strong>in</strong>1, imax1, ifn1, ....,\\ictlnum8, im<strong>in</strong>8, imax8, ifn8k1, ..., k8 slider8 ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1,\\..., ictlnum8, im<strong>in</strong>8, imax8, <strong>in</strong>it8, ifn8i1, ..., i16 slider16 ichan, ictlnum1, im<strong>in</strong>1, imax1, ifn1, ....,\\ictlnum16, im<strong>in</strong>16, imax16, ifn16k1, ..., k16 slider16 ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1,\\...., ictlnum16, im<strong>in</strong>16, imax16, <strong>in</strong>it16, ifn16i1, ..., i32 slider32 ichan, ictlnum1, im<strong>in</strong>1, imax1, ifn1, ....,\\ictlnum32, im<strong>in</strong>32, imax32, ifn32k1, ..., k32 slider32 ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, fn1,\\...., ictlnum32, im<strong>in</strong>32, imax32, <strong>in</strong>it32, ifn32i1, ..., i64 slider64 ichan, ictlnum1, im<strong>in</strong>1, imax1, ifn1, ....,\\ictlnum64, im<strong>in</strong>64, imax64, ifn64k1, ..., k64 slider64 ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1,\\...., ictlnum64, im<strong>in</strong>64, imax64, <strong>in</strong>it64, ifn64k1, ..., k8 slider8f ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1,\\icutoff1, ...., ictlnum8, im<strong>in</strong>8, imax8, <strong>in</strong>it8,\\ifn8, icutoff8k1, ..., k16 slider16f ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1,\\icutoff1, .... ,ictlnum16, im<strong>in</strong>16, imax16,\\<strong>in</strong>it16, ifn16, icutoff16k1, ..., k32 slider32f ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1,\\icutoff1, .... , ictlnum32, im<strong>in</strong>32, imax32,\\<strong>in</strong>it32, ifn32, icutoff32k1, ..., k64 slider64f ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1,\\icutoff1, .... , ictlnum64, im<strong>in</strong>64, imax64,\\<strong>in</strong>it64, ifn64, icutoff64i1, ..., i16 s16b14 ichan, ictlno_msb1, ictlno_lsb1, im<strong>in</strong>1, imax1,\\<strong>in</strong>itvalue1, ifn1, ....., ictlno_msb16,\\ictlno_lsb16, im<strong>in</strong>16, imax16, <strong>in</strong>itvalue16, ifn16k1, ..., k16 s16b14 ichan, ictlno_msb1, ictlno_lsb1, im<strong>in</strong>1, imax1,\\ifn1, ictlno_msb16, ictlno_lsb16, im<strong>in</strong>16,\\imax16, ifn16i1, ..., i32 s32b14 ichan, ictlno_msb1, ictlno_lsb1, im<strong>in</strong>1, imax1,\\<strong>in</strong>itvalue1, ifn1, ....., ictlno_msb32,\\ictlno_lsb32, im<strong>in</strong>32, imax32, <strong>in</strong>itvalue32, ifn32k1, ..., k32 s32b14 ichan, ictlno_msb1, ictlno_lsb1, im<strong>in</strong>1, imax1,\\ifn1, ...., ictlno_msb32, ictlno_lsb32, im<strong>in</strong>32,\\imax32, ifn3226.1.1 DESCRIPTIONMIDI slider control banksThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Slider Banks Page 26-1


26.1.2 INITIALIZATIONi1 ... i64 – output valuesichan – MIDI channel (1-16)ictlnum1 ... ictlnum64 – MIDI control numberictlno_msb1 .... ictlno_msb32 – MIDI control number (most significant byte)ictlno_lsb1 .... ictlno_lsb32 – MIDI control number (least significant byte)im<strong>in</strong>1 ... im<strong>in</strong>64 – m<strong>in</strong>imum values for each controllerimax1 ... imax64 – maximum values for each controller<strong>in</strong>it1 ... <strong>in</strong>it64 – <strong>in</strong>itial value for each controllerifn1 ... ifn64 – function table for conversion for each controllericutoff1 ... icutoff64 – low-pass filter cutoff frequency for each controller26.1.3 PERFORMANCEk1 ... k64 – output valuessliderN and sliderNf are banks of MIDI controllers, useful when us<strong>in</strong>g MIDI mixer such asKawai MM-16 or others for chang<strong>in</strong>g whatever sound parameter <strong>in</strong> real-time. The raw MIDIcontrol messages at the <strong>in</strong>put port are converted to agree with im<strong>in</strong>N and imaxN, and an <strong>in</strong>itialvalue can be set. Also, an optional non-<strong>in</strong>terpolated function table with a custom translationcurve is allowed, useful for enabl<strong>in</strong>g exponential response curves.When no function table translation is required, set the ifnN value to 0, else set ifnN to a validfunction table number. When table translation is enabled (i.e. sett<strong>in</strong>g ifnN value to a non-zeronumber referr<strong>in</strong>g to an already allocated function table), <strong>in</strong>itN value should be set equal to im<strong>in</strong>Nor imaxN value, else the <strong>in</strong>itial output value will not be the same as specified <strong>in</strong> <strong>in</strong>itN argument.slider8 allows a bank of 8 different MIDI control message numbers, slider16 does the same witha bank of 16 controls, and so on.sliderNf filter the signal before output, for elim<strong>in</strong>at<strong>in</strong>g discont<strong>in</strong>uities due to the low resolutionof the MIDI (7 bit); the cutoff frequency can be set separately for each controller (suggestedrange: .1 to 5 Hz).As the <strong>in</strong>put and output arguments are many, you can split the l<strong>in</strong>e us<strong>in</strong>g ‘\’ (backslash) character(new <strong>in</strong> 3.47 version) to improve the readability. Us<strong>in</strong>g these opcodes is considerably moreefficient than us<strong>in</strong>g the separate ones (ctrl7 and tonek) when more controllers are required.In the i-rate version of sliderN, there is not an <strong>in</strong>itial value <strong>in</strong>put argument, because the output isgotten directly from current status of <strong>in</strong>ternal controller array of <strong>Csound</strong>.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Slider Banks Page 26-2


sNb14 opcode is the 14-bit version of this bank of controllers.Warn<strong>in</strong>g: sliderNf opcodes do not output the required <strong>in</strong>itial value immediately, but only aftersome k-cycles, because the filter slightly delays the output.26.1.4 DEPRECATED NAMESThe opcode names islider8, islider16, islider32, islider64, is16b14, and is32b14 have beendeprecated as of <strong>Csound</strong> version 3.52. Use slider8, slider16, slider32, slider64, s16b14, ands32b14, respectively, for i-rate output.26.1.5 AUTHORGabriel MaldonadoItalyDecember 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.50)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Slider Banks Page 26-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Slider Banks Page 26-4


27 MIDI SUPPORT: GENERIC I/O27.1 midi<strong>in</strong>kstatus, kchan, kdata1, kdata2midi<strong>in</strong>27.1.1 DESCRIPTIONReturns a generic MIDI message received by the MIDI IN port27.1.2 PERFORMANCEkstatus – the type of MIDI message. Can be:• 128 (note off),• 144 (note on),• 160 (polyphonic aftertouch),• 176 (control change),• 192 (program change),• 208 (channel aftertouch),• 224 (pitch bend)• 0 if no MIDI messages are pend<strong>in</strong>g <strong>in</strong> the MIDI IN buffer.kchan – MIDI channel (1-16)kdata1, kdata2 – message-dependent data valuesmidi<strong>in</strong> has no <strong>in</strong>put arguments, because it reads at the MIDI <strong>in</strong> port implicitly. It works at k-rate.Normally (i.e., when no messages are pend<strong>in</strong>g) kstatus is zero, only when MIDI data are present<strong>in</strong> the MID IN buffer, is kstatus set to the type of the relevant messages.27.1.3 AUTHORGabriel MaldonadoItaly1998 (New <strong>in</strong> <strong>Csound</strong> version 3.492)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Generic I/O Page 27-1


27.2 midioutmidioutkstatus, kchan, kdata1, kdata227.2.1 DESCRIPTIONSends a generic MIDI message to the MIDI OUT port27.2.2 PERFORMANCEkstatus – the type of MIDI message. Can be:• 128 (note off),• 144 (note on),• 160 (polyphonic aftertouch),• 176 (control change),• 192 (program change),• 208 (channel aftertouch),• 224 (pitch bend)• 0 when no MIDI messages must be sent to the MIDI OUT port.kchan – MIDI channel (1-16)kdata1, kdata2 – message-dependent data valuesmidiout has no output arguments, because it sends a message to the MIDI OUT port implicitly.It works at k-rate. It sends a MIDI message only when kstatus is non-zero.Warn<strong>in</strong>g: Normally kstatus should be set to 0. Only when the user <strong>in</strong>tends to send a MIDImessage, can it be set to the correspond<strong>in</strong>g message type number.27.2.3 AUTHORGabriel MaldonadoItaly1998 (New <strong>in</strong> <strong>Csound</strong> version 3.492)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Generic I/O Page 27-2


28 MIDI SUPPORT: NOTE-ON/NOTE-OFF28.1 noteon, noteoff, noteondur, noteondur2noteon ichn, <strong>in</strong>um, ivelnoteoff ichn, <strong>in</strong>um, ivelnoteondur ichn, <strong>in</strong>um, ivel, idurnoteondur2 ichn, <strong>in</strong>um, ivel, idur28.1.1 DESCRIPTIONSend note-on and note-off messages to the MIDI OUT port.28.1.2 INITIALIZATIONichn – MIDI channel number (0-15)<strong>in</strong>um – note number (0-127)ivel – velocity (0-127)28.1.3 PERFORMANCEnoteon (i-rate note on) and noteoff (i-rate note off) are the simplest MIDI OUT opcodes. noteonsends a MIDI noteon message to MIDI OUT port, and noteoff sends a noteoff message. Anoteon opcode must always be followed by an noteoff with the same channel and number <strong>in</strong>sidethe same <strong>in</strong>strument, otherwise the note will play endlessly. These noteon and noteoff are usefulonly when <strong>in</strong>troduc<strong>in</strong>g a timout statement to play a non-zero duration MIDI note. For mostpurposes it is better to use noteondur and noteondur2.noteondur and noteondur2 (i-rate note on with duration) send a noteon and a noteoff MIDImessage both with the same channel, number and velocity. Noteoff message is sent after idurseconds are elapsed by the time noteondur was active.noteondur differs from noteondur2 <strong>in</strong> that noteondur truncates note duration when current<strong>in</strong>strument is deactivated by score or by real-time play<strong>in</strong>g, while noteondur2 will extendperformance time of current <strong>in</strong>strument until idur seconds have elapsed. In real-time play<strong>in</strong>g it issuggested to use noteondur also for undef<strong>in</strong>ed durations, giv<strong>in</strong>g a large idur value.Any number of noteondur or noteondur2 opcodes can appear <strong>in</strong> the same <strong>Csound</strong> <strong>in</strong>strument,allow<strong>in</strong>g chords to be played by a s<strong>in</strong>gle <strong>in</strong>strument.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Note-on/Note-off Page 28-1


28.1.4 NAME CHANGESPrior to <strong>Csound</strong> version 3.52 (February, 1999), these opcodes were called ion, ioff, iondur, andiodur2. ondur and ondur2 changed to noteondur and noteondur2 <strong>in</strong> <strong>Csound</strong> version 3.53.28.1.5 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Note-on/Note-off Page 28-2


28.2 moscil, midionmoscilmidionkchn, knum, kvel, kdur, kpausekchn, knum, kvel28.2.1 DESCRIPTIONSend a stream of note-on and note-off messages to the MIDI OUT port.28.2.2 PERFORMANCEkchn – MIDI channel number (0-15)knum – note number (0-127)kvel – velocity (0-127)kdur – note duration <strong>in</strong> secondskpause – pause duration after each noteoff and before new note <strong>in</strong> secondsmoscil and midion are the most powerful MIDI OUT opcodes. moscil (MIDI oscil) plays astream of notes of kdur duration. Channel, pitch, velocity, duration and pause can be controlledat k-rate, allow<strong>in</strong>g very complex algorithmically generated melodic l<strong>in</strong>es. When current<strong>in</strong>strument is deactivated, the note played by current <strong>in</strong>stance of moscil is forcedly truncated.midion (k-rate note on) plays MIDI notes with current kchn, knum and kvel. These argumentscan be varied at k-rate. Each time the MIDI converted value of any of these arguments changes,last MIDI note played by current <strong>in</strong>stance of midion is immediately turned off and a new notewith the new argument values is activated. This opcode, as well as moscil, can generate verycomplex melodic textures if controlled by complex k-rate signals.Any number of moscil or midion opcodes can appear <strong>in</strong> the same <strong>Csound</strong> <strong>in</strong>strument, allow<strong>in</strong>g acounterpo<strong>in</strong>t-style polyphony with<strong>in</strong> a s<strong>in</strong>gle <strong>in</strong>strument.28.2.3 DEPRECATED NAMESmidion was orig<strong>in</strong>ally called kon. As of <strong>Csound</strong> version 3.493, that name is deprecated. midionshould be used <strong>in</strong>stead of kon.28.2.4 AUTHORGabriel MaldonadoItalyMay 1997 (moscil new <strong>in</strong> <strong>Csound</strong> version 3.47)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Note-on/Note-off Page 28-3


28.3 midion2midion2kchn, knum, kvel, ktrig28.3.1 DESCRIPTIONSends noteon and noteoff messages to the MIDI out port when triggered by a value different thanzero.28.3.2 PERFORMANCEkchn – MIDI channelknum – MIDI note numberkvel – note velocityktrig – trigger <strong>in</strong>put signal (normally 0)Similar to midion, this opcode sends noteon and noteoff messages to the MIDI out port, but onlywhen ktrig is non-zero. This opcode is can work together with the output of the trigger opcode.28.3.3 AUTHORGabriel MaldonadoItaly1998 (New <strong>in</strong> <strong>Csound</strong> version 3.492)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Note-on/Note-off Page 28-4


29 MIDI SUPPORT: MIDI MESSAGE OUTPUT29.1 outic, outkc, outic14, outkc14, outipb, outkpb, outiat,outkat, outipc, outkpc, outipat, outkpatouticoutkcoutic14outkc14outipboutkpboutiatoutkatoutipcoutkpcoutipatoutkpatichn, <strong>in</strong>um, ivalue, im<strong>in</strong>, imaxkchn, knum, kvalue, km<strong>in</strong>, kmaxichn, imsb, ilsb, ivalue, im<strong>in</strong>, imaxkchn, kmsb, klsb, kvalue, km<strong>in</strong>, kmaxichn, ivalue, im<strong>in</strong>, imaxkchn, kvalue, km<strong>in</strong>, kmaxichn, ivalue, im<strong>in</strong>, imaxkchn, kvalue, km<strong>in</strong>, kmaxichn, iprog, im<strong>in</strong>, imaxkchn, kprog, km<strong>in</strong>, kmaxichn, <strong>in</strong>otenum, ivalue, im<strong>in</strong>, imaxkchn, knotenum, kvalue, km<strong>in</strong>, kmax29.1.1 DESCRIPTIONSend a s<strong>in</strong>gle Channel message to the MIDI OUT port.29.1.2 PERFORMANCEichn, kchn – MIDI channel number (0-15)<strong>in</strong>um, knum – controller number (0-127 for example 1 = ModWheel; 2 = BreathControl etc.)ivalue, kvalue – float<strong>in</strong>g po<strong>in</strong>t valueim<strong>in</strong>, km<strong>in</strong> – m<strong>in</strong>imum float<strong>in</strong>g po<strong>in</strong>t value (converted <strong>in</strong> MIDI <strong>in</strong>teger value 0)imax, kmax – maximum float<strong>in</strong>g po<strong>in</strong>t value (converted <strong>in</strong> MIDI <strong>in</strong>teger value 127 (7 bit) or16383 (14 bit))imsb, kmsb – most significant byte controller number when us<strong>in</strong>g 14 bit parametersilsb, klsb – least significant byte controller number when us<strong>in</strong>g 14 bit parametersiprog, kprog – program change number <strong>in</strong> float<strong>in</strong>g po<strong>in</strong>t<strong>in</strong>otenum, knotenum – MIDI note number (used <strong>in</strong> polyphonic aftertouch messages)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: MIDI Message Output Page 29-1


outic and outkc (i- and k-rate MIDI controller output) send controller messages to MIDI OUTdevice. outic14 and outkc14 (i and k-rate MIDI 14 bit controller output) send a pair of controllermessages. These opcodes can drive 14 bit parameters on MIDI <strong>in</strong>struments that recognize them.The first control message conta<strong>in</strong>s the most significant byte of i(k)value argument while thesecond message conta<strong>in</strong>s the less significant byte. i(k)msb and i(k)lsb are the number of the mostand less significant controller.outipb and outkpb (i- and k-rate pitch bend output) send pitch bend messages.outiat and outkat (i- and k-rate aftertouch output) send aftertouch messages. outiat and outkat(i- and k-rate aftertouch output) send aftertouch messages.outipc and outkpc (i- and k-rate program change output) send program change messages.outipat and outkpat (i- and k-rate polyphonic aftertouch output) send polyphonic aftertouchmessages.These opcodes can drive a different value of a parameter for each note currently active. Theywork only with MIDI <strong>in</strong>struments which recognize them.N.B. All these opcodes can scale the i(k)value float<strong>in</strong>g-po<strong>in</strong>t argument accord<strong>in</strong>g with i(k)maxand i(k)m<strong>in</strong> values. For example, sett<strong>in</strong>g i(k)m<strong>in</strong> = 1.0 and i(k)max = 2.0, when i(k)valueargument receives a 2.0 value, the opcode will send a 127 value to MIDI OUT device, whilewhen receiv<strong>in</strong>g a 1.0 it will send a 0 value. i-rate opcodes send their message once dur<strong>in</strong>g<strong>in</strong>strument <strong>in</strong>itialization. k-rate opcodes send a message each time the MIDI converted value ofargument i(k)value changes.29.1.3 DEPRECATED NAMESPrior to <strong>Csound</strong> version 3.52, these opcodes were named ioutc, koutc, ioutc14, koutc14,ioutpb, koutpb, ioutat, koutat, ioutpc, koutpc, ioutpat, and koutpat. The current names wereadopted with version 3.52 (February, 1999) to avoid name space pollution.29.1.4 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: MIDI Message Output Page 29-2


29.2 nrpnnrpnkchan, kparmnum, kparmvalue29.2.1 DESCRIPTIONSends a NPRN (Non Registered Parameter Number) message to the MIDI OUT port each timeone of the <strong>in</strong>put arguments changes.29.2.2 PERFORMANCEkchan – MIDI channelkparmnum – number of NRPN parameterkparmvalue – value of NRPN parameterThis opcode sends new message when the MIDI translated value of one of the <strong>in</strong>put argumentschanges. It operates at k-rate. Useful with the MIDI <strong>in</strong>struments that recognize NRPNs (forexample with the newest sound-cards with <strong>in</strong>ternal MIDI synthesizer such as SB AWE32,AWE64, GUS etc. <strong>in</strong> which each patch parameter can be changed dur<strong>in</strong>g the performance viaNRPN)29.2.3 AUTHORGabriel MaldonadoItaly1998 (New <strong>in</strong> <strong>Csound</strong> version 3.492)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: MIDI Message Output Page 29-3


29.3 mdelaymdelaykstatus, kchan, kd1, kd2, kdelay29.3.1 DESCRIPTIONA MIDI delay opcode.29.3.2 PERFORMANCEkstatus – status byte of MIDI message to be delayedkchan – MIDI channel (1-16)kd1 – first MIDI data bytekd2 – second MIDI data bytekdelay – delay time <strong>in</strong> secondsEach time that kstatus is other than zero, mdelay outputs a MIDI message to the MIDI out portafter kdelay seconds. This opcode is useful <strong>in</strong> implement<strong>in</strong>g MIDI delays. Several <strong>in</strong>stances ofmdelay can be present <strong>in</strong> the same <strong>in</strong>strument with different argument values, so complex andcolorful MIDI echoes can be implemented. Further, the delay time can be changed at k-rate.29.3.3 AUTHORGabriel MaldonadoItalyNovember, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.492)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: MIDI Message Output Page 29-4


30 MIDI SUPPORT: REAL-TIME MESSAGES30.1 mclock, mrtmsgmclockmrtmsgifreqimsgtype30.1.1 DESCRIPTIONSend system real-time messages to the MIDI OUT port.30.1.2 INITIALIZATIONifreq – clock message frequency rate <strong>in</strong> Hzimsgtype – type of real-time message:• 1 sends a START message (0xFA)• 2 sends a CONTINUE message (0xFB)• 0 sends a STOP message (0xFC)• -1 sends a SYSTEM RESET message (0xFF)• -2 sends an ACTIVE SENSING message (0xFE)30.1.3 PERFORMANCEmclock (MIDI clock) sends a MIDI CLOCK message (0xF8) every 1/ifreq seconds. So ifreq isthe frequency rate of CLOCK message <strong>in</strong> Hz.mrtmsg (MIDI real-time message) sends a real-time message once, <strong>in</strong> <strong>in</strong>it stage of current<strong>in</strong>strument. imsgtype parameter is a flag to <strong>in</strong>dicate the message type (see above).30.1.4 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Real-time Messages Page 30-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Real-time Messages Page 30-2


31 MIDI SUPPORT: EVENT EXTENDERS31.1 xtratim, releasekflagxtratimreleaseiextradur31.1.1 DESCRIPTIONExtend the duration of real-time generated events and handle their extra life (see also l<strong>in</strong>enr).31.1.2 INITIALIZATIONiextradur – additional duration of current <strong>in</strong>strument <strong>in</strong>stance31.1.3 PERFORMANCExtratim extends current MIDI-activated note duration of iextradur seconds after thecorrespond<strong>in</strong>g note-off message has deactivated current note itself. This opcode has no outputarguments.release outputs current note state. If current note is <strong>in</strong> the release stage (i.e. if its duration hasbeen extended with xtratim opcode and if it has only just deactivated), kflag output argument isset to 1, else (<strong>in</strong> susta<strong>in</strong> stage of current note) is set to 0. These two opcodes are useful forimplement<strong>in</strong>g complex release-oriented envelopes.31.1.4 EXAMPLE<strong>in</strong>str 1 ;allows complex ADSR envelope with MIDI events<strong>in</strong>um notnumicps cpsmidiiamp ampmidi 4000;;------- complex envelope block ------xtratim 1 ;extra-time, i.e. release durkrel <strong>in</strong>it 0krel release ;outputs release-stage flag (0 or 1 values)if (krel .5) kgoto rel ;if <strong>in</strong> release-stage goto release section;;************ attack and susta<strong>in</strong> section ***********kmp1 l<strong>in</strong>seg 0, .03, 1, .05, 1, .07, 0, .08, .5, 4, 1, 50, 1kmp = kmp1*iampkgoto done;;--------- release section --------rel:kmp2 l<strong>in</strong>seg 1, .3, .2, .7, 0kmp = kmp1*kmp2*iampdone:;------a1 oscili kmp, icps, 1out a1end<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Event Extenders Page 31-1


31.1.5 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 MIDI Support: Event Extenders Page 31-2


32 SIGNAL GENERATORS: LINEAR ANDEXPONENTIAL GENERATORS32.1 l<strong>in</strong>e, expon, l<strong>in</strong>seg, l<strong>in</strong>segr, expseg, expsegr, expsegakr l<strong>in</strong>e ia, idur1, ibar l<strong>in</strong>e ia, idur1, ibkr expon ia, idur1, ibar expon ia, idur1, ibkr l<strong>in</strong>seg ia, idur1, ib[, idur2, ic[...]]ar l<strong>in</strong>seg ia, idur1, ib[, idur2, icI...]]kr l<strong>in</strong>segr ia, idur1, ib[, idur2, ic[...]], irel, izar l<strong>in</strong>segr ia, idur1, ib[, idur2, icI...]], irel, izkr expseg ia, idur1, ib[, idur2, ic[...]]ar expseg ia, idur1, ib[, idur2, ic[...]]kr expsegr ia, idur1, ib[, idur2, ic[...]], irel, izar expsegr ia, idur1, ib[, idur2, ic[...]], irel, izar expsega ia, idur1, ib[, idur2, ic[...]]32.1.1 DESCRIPTIONOutput values kr or ar trace a straight l<strong>in</strong>e (exponential curve) or a series of l<strong>in</strong>e segments (orexponential segments) between specified po<strong>in</strong>ts.32.1.2 INITIALIZATIONia- start<strong>in</strong>g value. Zero is illegal for exponentials.ib, ic, etc. – value after dur1 seconds, etc. For exponentials, must be non-zero and must agree <strong>in</strong>sign with ia.idur1 – duration <strong>in</strong> seconds of first segment. A zero or negative value will cause all <strong>in</strong>itializationto be skipped.idur2, idur3, etc. – duration <strong>in</strong> seconds of subsequent segments. A zero or negative value willterm<strong>in</strong>ate the <strong>in</strong>itialization process with the preced<strong>in</strong>g po<strong>in</strong>t, permitt<strong>in</strong>g the last-def<strong>in</strong>ed l<strong>in</strong>e orcurve to be cont<strong>in</strong>ued <strong>in</strong>def<strong>in</strong>itely <strong>in</strong> performance. The default is zero.irel, iz - duration <strong>in</strong> seconds and f<strong>in</strong>al value of a note releas<strong>in</strong>g segment.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: L<strong>in</strong>ear and Exponential Generators Page 32-1


32.1.3 PERFORMANCEThese units generate control or audio signals whose values can pass through 2 or more specifiedpo<strong>in</strong>ts. The sum of dur values may or may not equal the <strong>in</strong>strument’s performance time: a shorterperformance will truncate the specified pattern, while a longer one will cause the last-def<strong>in</strong>edsegment to cont<strong>in</strong>ue on <strong>in</strong> the same direction.l<strong>in</strong>segr, expsegr are amongst the <strong>Csound</strong> “r” units that conta<strong>in</strong> a note-off sensor and release timeextender. When each senses an event term<strong>in</strong>ation or MIDI noteoff, it immediately extends theperformance time of the current <strong>in</strong>strument by irel seconds, and sets out to reach the value iz bythe end of that period (no matter which segment the unit is <strong>in</strong>). “r” units can also be modified byMIDI noteoff velocities (see veloffs). For two or more extenders <strong>in</strong> an <strong>in</strong>strument, extension isby the greatest period.expsega is almost identical to expseg, but more precise when def<strong>in</strong><strong>in</strong>g segments with very shortdurations (i.e., <strong>in</strong> a percussive attack phase) at audio rate. Note that expseg does not operatecorrectly at audio rate when segments are shorter than a k-period. In this situation, expsegashould be used <strong>in</strong>stead of expseg.32.1.4 EXAMPLEk2 expseg 440, p3/2,880, p3/2,440This statement creates a control signal which moves exponentially from 440 to 880 and back,over the duration p3.32.1.5 AUTHORGabriel Maldonado (expsega)ItalyJune, 1998New <strong>in</strong> <strong>Csound</strong> version 3.57The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: L<strong>in</strong>ear and Exponential Generators Page 32-2


32.2 adsr, madsr, xadsr, mxadsrkr adsr iatt, idec, islev, irel[, idel]kr madsr iatt, idec, islev, irel[, idel]kr xadsr iatt, idec, islev, irel[, idel]kr mxadsr iatt, idec, islev, irel[, idel]ar adsr iatt, idec, islev, irel[, idel]ar madsr iatt, idec, islev, irel[, idel]ar xadsr iatt, idec, islev, irel[, idel]ar mxadsr iatt, idec, islev, irel[, idel]32.2.1 DESCRIPTIONCalculates the classical ADSR envelope32.2.2 INITIALIZATIONiatt – duration of attack phaseidec – duration of decayislev – level for susta<strong>in</strong> phaseirel – duration of release phaseidel – period of zero before the envelope starts32.2.3 PERFORMANCEThe envelope is the range 0 to 1 and may need to be scaled further. The envelope may bedescribed as:The length of the susta<strong>in</strong> is calculated from the length of the note. This means adsr is notsuitable for use with MIDI events. The opcode madsr uses the l<strong>in</strong>segr mechanism, and so can beused <strong>in</strong> MIDI applications. The opcodes xadsr and mxadsr are identical to adsr and madsr,respectively, except they use exponential, rather than l<strong>in</strong>ear, l<strong>in</strong>e segments. adsr and madsr new<strong>in</strong> <strong>Csound</strong> version 3.49. xadsr and mxadsr new <strong>in</strong> <strong>Csound</strong> version 3.51.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: L<strong>in</strong>ear and Exponential Generators Page 32-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: L<strong>in</strong>ear and Exponential Generators Page 32-4


33 SIGNAL GENERATORS: TABLE ACCESS33.1 table, tablei, table3, oscil1, oscil1i, oscilnir table <strong>in</strong>dx, ifn[, ixmode[, ixoff[, iwrap]]]ir tablei <strong>in</strong>dx, ifn[, ixmode[, ixoff[, iwrap]]]ir table3 <strong>in</strong>dx, ifn[, ixmode[, ixoff[, iwrap]]]kr table kndx, ifn[, ixmode[, ixoff[, iwrap]]]kr tablei kndx, ifn[, ixmode[, ixoff[, iwrap]]]kr table3 kndx, ifn[, ixmode[, ixoff[, iwrap]]]ar table andx, ifn[, ixmode[, ixoff[, iwrap]]]ar tablei andx, ifn[, ixmode[, ixoff[, iwrap]]]ar table3 andx, ifn[, ixmode[, ixoff[, iwrap]]]kr oscil1 idel, kamp, idur, ifnkr oscil1i idel, kamp, idur, ifnar osciln kamp, ifrq, ifn, itimes33.1.1 DESCRIPTIONTable values are accessed by direct <strong>in</strong>dex<strong>in</strong>g or by <strong>in</strong>cremental sampl<strong>in</strong>g.33.1.2 INITIALIZATIONifn – function table number. tablei, oscil1i require the extended guard po<strong>in</strong>t.ixmode (optional) – <strong>in</strong>dex data mode. The default value is 0.• 0 = raw <strong>in</strong>dex• 1 = normalized (0 to 1)ixoff (optional) – amount by which <strong>in</strong>dex is to be offset. For a table with orig<strong>in</strong> at center, usetablesize/2 (raw) or .5 (normalized). The default value is 0.iwrap (optional) – wraparound <strong>in</strong>dex flag. The default value is 0.• 0 = nowrap (<strong>in</strong>dex < 0 treated as <strong>in</strong>dex=0; <strong>in</strong>dex tablesize sticks at <strong>in</strong>dex=size)• 1 = wraparoundidel – delay <strong>in</strong> seconds before oscil1 <strong>in</strong>cremental sampl<strong>in</strong>g beg<strong>in</strong>s.idur – duration <strong>in</strong> seconds to sample through the oscil1 table just once. A zero or negative valuewill cause all <strong>in</strong>itialization to be skipped.ifrq, itimes - rate and number of times through the stored table.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Table Access Page 33-1


33.1.3 PERFORMANCEtable <strong>in</strong>vokes table lookup on behalf of <strong>in</strong>it, control or audio <strong>in</strong>dices. These <strong>in</strong>dices can be rawentry numbers (0,l,2...size – 1) or scaled values (0 to 1-e). Indices are first modified by the offsetvalue then checked for range before table lookup (see iwrap). If <strong>in</strong>dex is likely to be full scale, orif <strong>in</strong>terpolation is be<strong>in</strong>g used, the table should have an extended guard po<strong>in</strong>t. table <strong>in</strong>dexed by aperiodic phasor ( see phasor) will simulate an oscillator.oscil1 accesses values by sampl<strong>in</strong>g once through the function table at a rate determ<strong>in</strong>ed by idur.For the first idel seconds, the po<strong>in</strong>t of scan will reside at the first location of the table; it will thenbeg<strong>in</strong> mov<strong>in</strong>g through the table at a constant rate, reach<strong>in</strong>g the end <strong>in</strong> another idur seconds; fromthat time on (i.e. after idel + idur seconds) it will rema<strong>in</strong> po<strong>in</strong>t<strong>in</strong>g at the last location. Each valueobta<strong>in</strong>ed from sampl<strong>in</strong>g is then multiplied by an amplitude factor kamp before be<strong>in</strong>g written <strong>in</strong>tothe result.osciln will sample several times through the stored table at a rate of ifrq times per second, afterwhich it will output zeros. Generates audio signals only, with output values scaled by kamp.tablei and oscil1i are <strong>in</strong>terpolat<strong>in</strong>g units <strong>in</strong> which the fractional part of <strong>in</strong>dex is used to<strong>in</strong>terpolate between adjacent table entries. The smoothness ga<strong>in</strong>ed by <strong>in</strong>terpolation is at somesmall cost <strong>in</strong> execution time (see also oscili, etc.), but the <strong>in</strong>terpolat<strong>in</strong>g and non-<strong>in</strong>terpolat<strong>in</strong>gunits are otherwise <strong>in</strong>terchangeable. Note that when tablei uses a periodic <strong>in</strong>dex whose modulo nis less than the power of 2 table length, the <strong>in</strong>terpolation process requires that there be an (n+1)th table value that is a repeat of the 1st (see f Statement <strong>in</strong> score). table3 is experimental, andis identical to tablei, except that it uses cubic <strong>in</strong>terpolation. (New <strong>in</strong> <strong>Csound</strong> version 3.50.)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Table Access Page 33-2


34 SIGNAL GENERATORS: PHASORS34.1 phasorkr phasor kcps[, iphs]ar phasor xcps[, iphs]34.1.1 DESCRIPTIONProduce a normalized mov<strong>in</strong>g phase value.34.1.2 INITIALIZATIONiphs (optional) – <strong>in</strong>itial phase, expressed as a fraction of a cycle (0 to 1). A negative value willcause phase <strong>in</strong>itialization to he skipped. The default value is zero.34.1.3 PERFORMANCEAn <strong>in</strong>ternal phase is successively accumulated <strong>in</strong> accordance with the kcps or xcps frequency toproduce a mov<strong>in</strong>g phase value, normalized to lie <strong>in</strong> the range 0.


34.2 phasorbnkkrarphasorbnk kcps, kndx, icnt[, iphs]phasorbnk xcps, kndx, icnt[, iphs]34.2.1 DESCRIPTIONProduce an arbitrary number of normalized mov<strong>in</strong>g phase values, accessable by an <strong>in</strong>dex.34.2.2 INITIALIZATIONicnt – maximum number of phasors to be used.iphs – <strong>in</strong>itial phase, expressed as a fraction of a cycle (0 to 1). If -1 <strong>in</strong>itialization is skipped. Ifiphas>1 each phasor will be <strong>in</strong>itialized with a random value.34.2.3 PERFORMANCEkndx – <strong>in</strong>dex value to access <strong>in</strong>dividual phasorsFor each <strong>in</strong>dependent phasor, an <strong>in</strong>ternal phase is successively accumulated <strong>in</strong> accordance withthe kcps or xcps frequency to produce a mov<strong>in</strong>g phase value, normalized to lie <strong>in</strong> the range 0


34.2.5 AUTHORPeter NeubäckerMunich, GermanyAugust, 1999New <strong>in</strong> <strong>Csound</strong> version 3.58The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Phasors Page 34-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Phasors Page 34-4


35 SIGNAL GENERATORS: BASIC OSCILLATORS35.1 oscil, oscili, oscil3kr oscil kamp, kcps, ifn[, iphs]kr oscili kamp, kcps, ifn[, iphs]kr oscil3 kamp, kcps, ifn[, iphs]ar oscil xamp, xcps, ifn[, iphs]ar oscili xamp, xcps, ifn[, iphs]ar oscil3 xamp, xcps, ifn[, iphs]35.1.1 DESCRIPTIONTable ifn is <strong>in</strong>crementally sampled modulo the table length and the value obta<strong>in</strong>ed is multipliedby amp.35.1.2 INITIALIZATIONifn – function table number. Requires a wrap-around guard po<strong>in</strong>t.iphs (optional) – <strong>in</strong>itial phase of sampl<strong>in</strong>g, expressed as a fraction of a cycle (0 to 1). A negativevalue will cause phase <strong>in</strong>itialization to be skipped. The default value is 0.35.1.3 PERFORMANCEThe oscil units output periodic control (or audio) signals consist<strong>in</strong>g of the value ofkamp(xamp)times the value returned from control rate (audio rate) sampl<strong>in</strong>g of a stored functiontable. The <strong>in</strong>ternal phase is simultaneously advanced <strong>in</strong> accordance with the kcps or xcps <strong>in</strong>putvalue. While the amplitude and frequency <strong>in</strong>puts to the k-rate oscils are scalar only, thecorrespond<strong>in</strong>g <strong>in</strong>puts to the audio-rate oscils may each be either scalar or vector, thus permitt<strong>in</strong>gamplitude and frequency modulation at either sub-audio or audio frequencies.oscili differs from oscil <strong>in</strong> that the standard procedure of us<strong>in</strong>g a truncated phase as a sampl<strong>in</strong>g<strong>in</strong>dex is here replaced by a process that <strong>in</strong>terpolates between two successive lookups.Interpolat<strong>in</strong>g generators will produce a noticeably cleaner output signal, but they may take asmuch as twice as long to run. Adequate accuracy can also be ga<strong>in</strong>ed without the time cost of<strong>in</strong>terpolation by us<strong>in</strong>g large stored function tables of 2K, 4K or 8K po<strong>in</strong>ts if the space isavailable. oscil3 is experimental, and is identical to oscili, except that it uses cubic <strong>in</strong>terpolation.(New <strong>in</strong> <strong>Csound</strong> version 3.50.)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Basic Oscillators Page 35-1


35.1.4 EXAMPLEk1 oscil 10, 5, 1 ; 5 Hz vibratoa1 oscil 5000, 440 + k1, 1 ; around A440 + -10 HzThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Basic Oscillators Page 35-2


35.2 poscil, poscil3ar poscil kamp, kcps, ifn [,iphs]kr poscil kamp, kcps, ifn [,iphs]ar poscil3 kamp, kcps, ifn [,iphs]kr poscil3 kamp, kcps, ifn [,iphs]35.2.1 DESCRIPTIONHigh precision oscillators. poscil3 uses cubic <strong>in</strong>terpolation.35.2.2 INITIALIZATIONifn – function table numberiphs(optional) – <strong>in</strong>itial phase (<strong>in</strong> samples)35.2.3 PERFORMANCEar – output signalkamp – amplitudekcps – frequencyposcil (precise oscillator) is the same as oscili, but allows much more precise frequency control,especially when us<strong>in</strong>g long tables and low frequency values. It uses float<strong>in</strong>g-po<strong>in</strong>t table <strong>in</strong>dex<strong>in</strong>g,<strong>in</strong>stead of <strong>in</strong>teger math, like oscil and oscili. It is only a bit slower than oscili.35.2.4 AUTHORGabriel Maldonado (poscil)John ffitch (poscil3)University of Bath/Codemist Ltd.ItalyBath, UK1998 (New <strong>in</strong> <strong>Csound</strong> version 3.52) February, 1999 (New <strong>in</strong> <strong>Csound</strong> version 3.52)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Basic Oscillators Page 35-3


35.3 lfokr lfo kamp, kcps[, itype]ar lfo kamp, kcps[, itype]35.3.1 DESCRIPTIONA low frequency oscillator of various shapes.35.3.2 INITIALIZATIONitype -- determ<strong>in</strong>e the waveform of the oscillator. Default is 0.• 0: s<strong>in</strong>e• 1: triangles• 2: square (bipolar)• 3: square (unipolar)• 4: saw-tooth• 5: saw-tooth(down)The s<strong>in</strong>e wave is implemented as a 4096 table and l<strong>in</strong>ear <strong>in</strong>terpolation. The others are calculated.35.3.3 PERFORMANCEkamp – amplitude of outputkcps – frequency of oscillator35.3.4 EXAMPLE<strong>in</strong>str 1kp lfo 10, 5, 4ar oscil p4, p5+kp, 1outarend<strong>in</strong>35.3.5 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKNovember, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.491)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Basic Oscillators Page 35-4


36 SIGNAL GENERATORS: DYNAMIC SPECTRUMOSCILLATORS36.1 buzz, gbuzzar buzz xamp, xcps, knh, ifn[, iphs]ar gbuzz xamp, xcps, knh, klh, kr, ifn[, iphs]36.1.1 DESCRIPTIONOutput is a set of harmonically related cos<strong>in</strong>e partials.36.1.2 INITIALIZATIONifn – table number of a stored function conta<strong>in</strong><strong>in</strong>g (for buzz) a s<strong>in</strong>e wave, or (for gbuzz) a cos<strong>in</strong>ewave. In either case a large table of at least 8192 po<strong>in</strong>ts is recommended.iphs (optional) – <strong>in</strong>itial phase of the fundamental frequency, expressed as a fraction of a cycle (0to 1). A negative value will cause phase <strong>in</strong>itialization to be skipped. The default value is zero36.1.3 PERFORMANCEThe buzz units generate an additive set of harmonically related cos<strong>in</strong>e partials of fundamentalfrequency xcps, and whose amplitudes are scaled so their summation peak equals xamp. Theselection and strength of partials is determ<strong>in</strong>ed by the follow<strong>in</strong>g control parameters:knh – total number of harmonics requested. New <strong>in</strong> <strong>Csound</strong> version 3.57, knh defaults to one. Ifknh is negative, the absolute value is used.klh – lowest harmonic present. Can be positive, zero or negative. In gbuzz the set of partials canbeg<strong>in</strong> at any partial number and proceeds upwards; if klh is negative, all partials below zero willreflect as positive partials without phase change (s<strong>in</strong>ce cos<strong>in</strong>e is an even function), and will addconstructively to any positive partials <strong>in</strong> the set.kr – specifies the multiplier <strong>in</strong> the series of amplitude coefficients. This is a power series: if theklhth partial has a strength coefficient of A, the (klh + n)th partial will have a coefficient of A *(kr ** n), i.e. strength values trace an exponential curve. kr may be positive, zero or negative,and is not restricted to <strong>in</strong>tegers.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Dynamic Spectrum Oscillators Page 36-1


uzz and gbuzz are useful as complex sound sources <strong>in</strong> subtractive synthesis. buzz is a specialcase of the more general gbuzz <strong>in</strong> which klh = kr = 1; it thus produces a set of knh equal-strengthharmonic partials, beg<strong>in</strong>n<strong>in</strong>g with the fundamental. (This is a band-limited pulse tra<strong>in</strong>; if thepartials extend to the Nyquist, i.e. knh = <strong>in</strong>t (sr / 2 / fundamental freq.), the result is a real pulsetra<strong>in</strong> of amplitude xamp.) Although both knh and klh may be varied dur<strong>in</strong>g performance, their<strong>in</strong>ternal values are necessarily <strong>in</strong>teger and may cause “pops” due to discont<strong>in</strong>uities <strong>in</strong> the output;kr, however, can be varied dur<strong>in</strong>g performance to good effect. Both buzz and gbuzz can beamplitude- and/or frequency-modulated by either control or audio signals.N.B. These two units have their analogs <strong>in</strong> GEN11, <strong>in</strong> which the same set of cos<strong>in</strong>es can bestored <strong>in</strong> a function table for sampl<strong>in</strong>g by an oscillator. Although computationally more efficient,the stored pulse tra<strong>in</strong> has a fixed spectral content, not a time-vary<strong>in</strong>g one as above.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Dynamic Spectrum Oscillators Page 36-2


36.2 vcoar vco kamp, kfqc, iwave, kpw, ifn, imaxd36.2.1 DESCRIPTIONImplementation of a band limited, analog modeled oscillator, based on <strong>in</strong>tegration of bandlimited impulses. vco can be used to simulate a variety of analog wave forms.36.2.2 INITIALIZATIONiwave – determ<strong>in</strong>es the waveform :• 1: sawtooth• 2: Square/PWM• 3: triangle/Saw/Rampifn – should be the table number of a of a stored s<strong>in</strong>e wave.imaxd – is the maximum delay time. A time of 1/ifqc may be required for the pwm and trianglewaveform. To bend the pitch down this value must be as large as 1/(m<strong>in</strong>imum frequency).36.2.3 PERFORMANCEkamp – determ<strong>in</strong>es the amplitudekfqc – is the frequency of the wavekpw – determ<strong>in</strong>es the pulse width when iwave is set to 2, and determ<strong>in</strong>es Saw/Ramp characterwhen iwave is set to 3. The value of kpw should be between 0 and 1. A value of .5 will generate asquare wave or a triangle wave depend<strong>in</strong>g on iwave.36.2.4 EXAMPLE<strong>in</strong>str 10idur = p3 ; Durationiamp = p4 ; Amplitudeifqc = cpspch(p5) ; Frequencyiwave = p6 ; Selected wave form 1=Saw, 2=Square/PWM, 3=Tri/Saw-Ramp-Modis<strong>in</strong>e = 1imaxd = 1/ifqc*2 ; Allows pitch bend down of two octaveskpw1 oscil .25, ifqc/200, 1kpw = kpw1 + .5asig vco iamp, ifqc, iwave, kpw, 1, imaxdouts asig, asig ; Output and amplificationend<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Dynamic Spectrum Oscillators Page 36-3


f1 0 65536 10 1; Sta Dur Amp Pitch Wavei10 0 2 20000 5.00 1i10 + . . . 2i10 . . . . 3i10 . 2 20000 7.00 1i10 . . . . 2i10 . . . . 3i10 . 2 20000 9.00 1i10 . . . . 2i10 . . . . 3i10 . 2 20000 11.00 1i10 . . . . 2i10 . . . . 3e36.2.5 AUTHORHans MikelsonDecember, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.50)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Dynamic Spectrum Oscillators Page 36-4


37 SIGNAL GENERATORS: ADDITIVESYNTHESIS/RESYNTHESIS37.1 adsynar adsyn kamod, kfmod, ksmod, ifilcod37.1.1 DESCRIPTIONOutput is an additive set of <strong>in</strong>dividually controlled s<strong>in</strong>usoids us<strong>in</strong>g an oscillator bank.37.1.2 INITIALIZATIONifilcod – <strong>in</strong>teger or character-str<strong>in</strong>g denot<strong>in</strong>g a control-file derived from analysis of an audiosignal. An <strong>in</strong>teger denotes the suffix of a file adsyn.m; a character-str<strong>in</strong>g (<strong>in</strong> double quotes) givesa filename, optionally a full pathname. If not fullpath, the file is sought first <strong>in</strong> the currentdirectory, then <strong>in</strong> the one given by the environment variable SADIR (if def<strong>in</strong>ed). adsyn controlconta<strong>in</strong>s breakpo<strong>in</strong>t amplitude and frequency envelope values organized for oscillatorresynthesis. Memory usage depends on the size of the file <strong>in</strong>volved, which are read and heldentirely <strong>in</strong> memory dur<strong>in</strong>g computation but are shared by multiple calls.37.1.3 PERFORMANCEadsyn synthesizes complex time-vary<strong>in</strong>g timbres through the method of additive synthesis. Anynumber of s<strong>in</strong>usoids, each <strong>in</strong>dividually controlled <strong>in</strong> frequency and amplitude, can be summedby high-speed arithmetic to produce a high-fidelity result.Component s<strong>in</strong>usoids are described by a control file describ<strong>in</strong>g amplitude and frequency tracks<strong>in</strong> millisecond breakpo<strong>in</strong>t fashion. Tracks are def<strong>in</strong>ed by sequences of 16-bit b<strong>in</strong>ary <strong>in</strong>tegers:-1, time, amp, time, amp,...-2, time, freq, time, freq,...such as from hetrodyne filter analysis of an audio file. (for details see hetro.) The <strong>in</strong>stantaneousamplitude and frequency values are used by an <strong>in</strong>ternal fixed-po<strong>in</strong>t oscillator that adds eachactive partial <strong>in</strong>to an accumulated output signal. While there is a practical limit (limit removed <strong>in</strong>version 3.47) on the number of contribut<strong>in</strong>g partials, there is no restriction on their behavior overtime. Any sound that can be described <strong>in</strong> terms of the behavior of s<strong>in</strong>usoids can be synthesizedby adsyn alone.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Additive Synthesis/Resynthesis Page 37-1


Sound described by an adsyn control file can also be modified dur<strong>in</strong>g re-synthesis. The signalskamod, kfmod, ksmod will modify the amplitude, frequency, and speed of contribut<strong>in</strong>g partials.These are multiply<strong>in</strong>g factors, with kfmod modify<strong>in</strong>g the frequency and ksmod modify<strong>in</strong>g thespeed with which the millisecond breakpo<strong>in</strong>t l<strong>in</strong>e-segments are traversed. Thus .7, 1.5, and 2 willgive rise to a softer sound, a perfect fifth higher, but only half as long. The values 1,1,1 willleave the sound unmodified. Each of these <strong>in</strong>puts can be a control signal.kfmod is a control-rate transposition factor: a value of 1 <strong>in</strong>curs no transposition, 1.5 transposes upa perfect fifth, and .5 down an octave.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Additive Synthesis/Resynthesis Page 37-2


37.2 adsyntar adsynt kamp, kcps, iwfn, ifreqfn, iampfn, icnt[, iphs]37.2.1 DESCRIPTIONPerforms additive synthesis with an arbitrary number of partials, not necessarily harmonic.37.2.2 INITIALIZATIONiwfn – table conta<strong>in</strong><strong>in</strong>g a waveform, usually a s<strong>in</strong>e. Table values are not <strong>in</strong>terpolated forperformance reasons, so larger tables provide better quality.ifreqfn – table conta<strong>in</strong><strong>in</strong>g frequency values for each partial. ifreqfn may conta<strong>in</strong> beg<strong>in</strong>n<strong>in</strong>gfrequency values for each partial, but is usually used for generat<strong>in</strong>g parameters at runtime withtablew. Frequencies must be relative to kcps. Size must be at least icnt.iampfn – table conta<strong>in</strong><strong>in</strong>g amplitude values for each partial. iampfn may conta<strong>in</strong> beg<strong>in</strong>n<strong>in</strong>gamplitude values for each partial, but is usually used for generat<strong>in</strong>g parameters at runtime withtablew. Amplitudes must be relative to kamp. Size must be at least icnt.icnt – number of partials to be generatediphs – <strong>in</strong>itial phase of each oscillator, if iphs = -1, <strong>in</strong>itialization is skipped. If iphs > 1, all phaseswill be <strong>in</strong>itialized with a random value.37.2.3 PERFORMANCEkamp – amplitude of notekcps – base frequency of note. Partial frequencies will be relative to kcps.Frequency and amplitude of each partial is given <strong>in</strong> the two tables provided. The purpose of thisopcode is to have an <strong>in</strong>strument generate synthesis parameters at k-rate and write them to globalparameter tables with the tablew opcode.37.2.4 EXAMPLESThese two <strong>in</strong>struments perform additive synthesis. The output of each sounds like a Tibetanbowl. The first one is static, as parameters are only generated at <strong>in</strong>it-time. In the second one,parameters are cont<strong>in</strong>uously changed.gifrqs ftgen 2, 0, 32, 7, 0, 32, 0 ; generate two emty tables; for adsyntgiamps ftgen 3, 0, 32, 7, 0, 32, 0 ; for freqency and amp; parameters<strong>in</strong>str 1; generates parameters at <strong>in</strong>it timeicnt = 10 ; generate 10 voices<strong>in</strong>dex = 0 ; <strong>in</strong>it loop <strong>in</strong>dexThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Additive Synthesis/Resynthesis Page 37-3


loop:; loop only executed at; <strong>in</strong>it timeifreq pow <strong>in</strong>dex + 1, 1.5 ; def<strong>in</strong>e non-harmonicpartialsiamp = 1 / (<strong>in</strong>dex+1) ; def<strong>in</strong>e amplitudestableiw ifreq, <strong>in</strong>dex, gifrqs ; write to tablestableiw iamp, <strong>in</strong>dex, giamps ; used by adsynt<strong>in</strong>dex = <strong>in</strong>dex + 1if (<strong>in</strong>dex < icnt) igoto loop ; do loopasig adsynt 5000, 150, giwave, gifrqs, giamps, icntoutasigend<strong>in</strong><strong>in</strong>str 2; generates paramaters; every k-cycleicnt = 10 ; generate 10 voicesk<strong>in</strong>dex = 0 ; reset loop <strong>in</strong>dexloop:; loop executed every; k-cyclekspeed pow k<strong>in</strong>dex + 1, 1.6 ; generate lfo for; frequencieskphas phasorbnk kspeed * 0.7, k<strong>in</strong>dex, icnt ; <strong>in</strong>dividual phase foreach voiceklfo table kphas, giwave, 1kdepth pow 1.4, k<strong>in</strong>dex ; arbitrary parametertwiddl<strong>in</strong>g...kfreq pow k<strong>in</strong>dex + 1, 1.5kfreq = kfreq + klfo*0.006*kdepthtablew kfreq, k<strong>in</strong>dex, gifrqs ; write freqs to table for; adsyntkspeed pow k<strong>in</strong>dex + 1, 0.8 ; generate lfo foramplitudeskphas phasorbnk kspeed*0.13, k<strong>in</strong>dex, icnt, 2 ; <strong>in</strong>dividual phase for; each voiceklfo table kphas, giwave, 1kamp pow 1 / (k<strong>in</strong>dex + 1), 0.4 ; arbitrary parameter; twiddl<strong>in</strong>g...kamp = kamp * (0.3+0.35*(klfo+1))tablew kamp, k<strong>in</strong>dex, giamps ; write amps to table for; adsyntk<strong>in</strong>dex = k<strong>in</strong>dex + 1if (k<strong>in</strong>dex < icnt) kgoto loop ; do loopgiwave ftgen 1, 0, 1024, 10, 1 ; generate a s<strong>in</strong>ewave; tableasig adsynt 5000, 150, giwave, gifrqs, giamps, icntoutasigend<strong>in</strong>37.2.5 AUTHORPeter NeubäckerMunich, GermanyAugust, 1999New <strong>in</strong> <strong>Csound</strong> version 3.58The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Additive Synthesis/Resynthesis Page 37-4


37.3 hsboscilar hsboscil kamp, ktone, kbrite, ibasfreq, iwfn, ioctfn \\[, ioctcnt[, iphs]]37.3.1 DESCRIPTIONAn oscillator which takes tonality and brightness as arguments, relative to a base frequency.37.3.2 INITIALIZATIONibasfreq – base frequency to which tonality and brighness are relativeiwfn – function table of the waveform, usually a s<strong>in</strong>eioctfn – function table used for weight<strong>in</strong>g the octaves, usually someth<strong>in</strong>g like:f1 0 1024 -19 1 0.5 270 0.5ioctcnt – number of octaves used for brightness blend<strong>in</strong>g. Must be <strong>in</strong> the range 2 to 10. Default is3.iphs – <strong>in</strong>itial phase of the oscillator. If iphs = -1, <strong>in</strong>itialization is skipped.37.3.3 PERFORMANCEkamp – amplitude of notektone – cyclic tonality parameter relative to ibasfreq <strong>in</strong> logarithmic octave, range 0 to 1, values >1 can be used, and are <strong>in</strong>ternally reduced to frac(ktone).kbrite – brightness parameter relative to ibasfreq, achieved by weight<strong>in</strong>g ioctcnt octaves. It isscaled <strong>in</strong> such a way, that a value of 0 corresponds to the orignal value of ibasfreq, 1 correspondsto one octave above ibasfreq, -2 corresponds to two octaves below ibasfreq, etc. kbrite may befractional.hsboscil takes tonality and brightness as arguments, relative to a base frequency (ibasfreq).Tonality is a cyclic parameter <strong>in</strong> the logarithmic octave, brightness is realized by mix<strong>in</strong>g multipleweighted octaves. It is useful when tone space is understood <strong>in</strong> a concept of polar coord<strong>in</strong>ates.Mak<strong>in</strong>g ktone a l<strong>in</strong>e, and kbrite a constant, produces Risset’s glissando.Oscillator table iwfn is always read <strong>in</strong>terpolated. Performance time requires about ioctcnt *oscili.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Additive Synthesis/Resynthesis Page 37-5


37.3.4 EXAMPLESgiwave ftgen 1, 0, 1024, 10, 1, 1, 1, 1 ; synth wavegiblend ftgen 2, 0, 1024, -19, 1, 0.5, 270, 0.5 ; blend<strong>in</strong>g w<strong>in</strong>dow<strong>in</strong>str 1; endless glissandoktona l<strong>in</strong>e 0,10,1asig hsboscil 10000, ktona, 0, 200, giwave, giblend, 5out asigend<strong>in</strong><strong>in</strong>str 2; MIDI <strong>in</strong>strument: all octaves sound alike,itona octmidi ; velocity is mapped to brightnessibrite ampmidi 3ibase = cpsoct(6)kenv expon 20000, 1, 100asig hsboscil kenv, itona, ibrite, ibase, giwave, giblend, 5out asigend<strong>in</strong>37.3.5 AUTHORPeter NeubäckerMunich, GermanyAugust, 1999New <strong>in</strong> <strong>Csound</strong> version 3.58The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Additive Synthesis/Resynthesis Page 37-6


38 SIGNAL GENERATORS: FM SYNTHESIS38.1 foscil, fosciliar foscil xamp, kcps, xcar, xmod, kndx, ifn[, iphs]ar foscili xamp, kcps, xcar, xmod, kndx, ifn[, iphs]38.1.1 DESCRIPTIONBasic frequency modulated oscillators.38.1.2 INITIALIZATIONifn – function table number. Requires a wrap-around guard po<strong>in</strong>t.iphs (optional) – <strong>in</strong>itial phase of waveform <strong>in</strong> table ifn, expressed as a fraction of a cycle (0 to 1).A negative value will cause phase <strong>in</strong>itialization to be skipped. The default value is 0.38.1.3 PERFORMANCEfoscil is a composite unit that effectively banks two oscils <strong>in</strong> the familiar Chown<strong>in</strong>g FM setup,where<strong>in</strong> the audio-rate output of one generator is used to modulate the frequency <strong>in</strong>put of another(the “carrier”). Effective carrier frequency = kcps * kcar, and modulat<strong>in</strong>g frequency = kcps *xmod. For <strong>in</strong>tegral values of xcar and xmod, the perceived fundamental will be the m<strong>in</strong>imumpositive value of kcps * (xcar – n * xmod), n = 1,1,2,... The <strong>in</strong>put kndx is the <strong>in</strong>dex of modulation(usually time-vary<strong>in</strong>g and rang<strong>in</strong>g 0 to 4 or so) which determ<strong>in</strong>es the spread of acoustic energyover the partial positions given by n = 0,1,2,.., etc. ifn should po<strong>in</strong>t to a stored s<strong>in</strong>e wave.Previous to version 3.50, xcar and xmod could be k-rate only.foscili differs from foscil <strong>in</strong> that the standard procedure of us<strong>in</strong>g a truncated phase as a sampl<strong>in</strong>g<strong>in</strong>dex is here replaced by a process that <strong>in</strong>terpolates between two successive lookups.Interpolat<strong>in</strong>g generators will produce a noticeably cleaner output signal, but they may take asmuch as twice as long to run. Adequate accuracy can also be ga<strong>in</strong>ed without the time cost of<strong>in</strong>terpolation by us<strong>in</strong>g large stored function tables of 2K, 4K or 8K po<strong>in</strong>ts if the space isavailable.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: FM Synthesis Page 38-1


38.2 fmvoicear fmvoice kamp, kfreq, kvowel, ktilt, kvibamt, kvibrate, ifn1, \\ifn2, ifn3, ifn4, ivibfn38.2.1 DESCRIPTIONFM S<strong>in</strong>g<strong>in</strong>g Voice Synthesis38.2.2 INITIALIZATIONifn1, ifn2, ifn3,ifn3 -- Tables, usually of s<strong>in</strong>ewaves.38.2.3 PERFORMANCEkamp – Amplitude of note.kfreq – Frequency of note played.kvowel -- the vowel be<strong>in</strong>g sung, <strong>in</strong> the range 0-64ktilt -- the spectral tilt of the sound <strong>in</strong> the range 0 to 99kvibamt -- Depth of vibratokvibrate -- Rate of vibrato38.2.4 EXAMPLEk1 l<strong>in</strong>e 0, p3, 64a1 fmvoice 31129.60, 110, k1, 0, 0.005, 6, 1,1,1,1,138.2.5 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: FM Synthesis Page 38-2


38.3 fmbell, fmrhode, fmwurlie, fmmetal, fmb3, fmpercfla1 fmbell kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,\\ifn3, ifn4, ivfna1 fmrhode kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,\\ifn3, ifn4, ivfna1 fmwurlie kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,\\ifn3, ifn4, ivfna1 fmmetal kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,\\ifn3, ifn4, ivfna1 fmb3 kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,\\ifn3, ifn4, ivfna1 fmpercfl kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,\\ifn3, ifn4, ivfn38.3.1 DESCRIPTIONA family of FM sounds, all us<strong>in</strong>g 4 basic oscillators and various architectures, as used <strong>in</strong> theTX81Z synthesizer.38.3.2 INITIALIZATIONAll these opcodes take 5 tables for <strong>in</strong>itialization. The first 4 are the basic <strong>in</strong>puts and the last isthe low frequency oscillator (LFO) used for vibrato. The last table should usually be a s<strong>in</strong>ewave.For the other opcodes the <strong>in</strong>itial waves should be as <strong>in</strong> the table:ifn1 ifn2 ifn3 ifn4fmbell s<strong>in</strong>ewave s<strong>in</strong>ewave s<strong>in</strong>ewave s<strong>in</strong>ewavefmrhode s<strong>in</strong>ewave s<strong>in</strong>ewave s<strong>in</strong>ewave fwavblnkfmwurlie s<strong>in</strong>ewave s<strong>in</strong>ewave s<strong>in</strong>ewave fwavblnkfmmetal s<strong>in</strong>ewave twopeaks twopeaks s<strong>in</strong>ewavefmb3 s<strong>in</strong>ewave s<strong>in</strong>ewave s<strong>in</strong>ewave s<strong>in</strong>ewavefmpercfl s<strong>in</strong>ewave s<strong>in</strong>ewave s<strong>in</strong>ewave s<strong>in</strong>ewaveThe sounds produced are then:fmbellfmrhodefmwurliefmmetalfmb3fmpercflTubular BellFender Rhodes Electric PianoWurlitzer Electric Piano“Heavy Metal”Hammond B3 organPercussive FluteThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: FM Synthesis Page 38-3


38.3.3 PERFORMANCEkamp – Amplitude of note.kfreq – Frequency of note played.kc1, kc2 -- Controls for the synthesizer, as <strong>in</strong> the table:kc1 kc2 Algorithmfmbell Mod <strong>in</strong>dex 1 Crossfade of two outputs 5fmrhode Mod <strong>in</strong>dex 1 Crossfade of two outputs 5fmwurlie Mod <strong>in</strong>dex 1 Crossfade of two outputs 5fmmetal Total mod <strong>in</strong>dex Crossfade of two modulators 3fmb3 Total mod <strong>in</strong>dex Crossfade of two modulators 4fmpercfl Total mod <strong>in</strong>dex Crossfade of two modulators 4kvdepth -- Vibrator depthkvrate -- Vibrator rate38.3.4 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: FM Synthesis Page 38-4


39 SIGNAL GENERATORS: SAMPLE PLAYBACK39.1 loscil, loscil3ar[,ar2] loscil xamp, kcps, ifn[, ibas[,imod1,ibeg1,iend1 \\[, imod2,ibeg2,iend2]]]ar[,ar2] loscil3 xamp, kcps, ifn[, ibas[,imod1,ibeg1,iend1 \\[, imod2,ibeg2,iend2]]]39.1.1 DESCRIPTIONRead sampled sound (mono or stereo) from a table, with optional susta<strong>in</strong> and release loop<strong>in</strong>g.39.1.2 INITIALIZATIONifn – function table number, typically denot<strong>in</strong>g an AIFF sampled sound segment with prescribedloop<strong>in</strong>g po<strong>in</strong>ts. The source file may be mono or stereo.ibas (optional) – base frequency <strong>in</strong> Hz of the recorded sound. This optionally overrides thefrequency given <strong>in</strong> the AIFF file, but is required if the file did not conta<strong>in</strong> one. The default valueis 261.626 Hz, i.e. middle C. (New <strong>in</strong> <strong>Csound</strong> 4.03).imod1, imod2 (optional) – play modes for the susta<strong>in</strong> and release loops. A value of 1 denotesnormal loop<strong>in</strong>g, 2 denotes forward & backward loop<strong>in</strong>g, 0 denotes no loop<strong>in</strong>g. The default value(-1) will defer to the mode and the loop<strong>in</strong>g po<strong>in</strong>ts given <strong>in</strong> the source file.ibeg1, iend1, ibeg2, iend2 (optional, dependent on mod1, mod2) – beg<strong>in</strong> and end po<strong>in</strong>ts of thesusta<strong>in</strong> and release loops. These are measured <strong>in</strong> sample frames from the beg<strong>in</strong>n<strong>in</strong>g of the file,so will look the same whether the sound segment is monaural or stereo.39.1.3 PERFORMANCEloscil samples the ftable audio at a-rate determ<strong>in</strong>ed by kcps, then multiplies the result by xamp.The sampl<strong>in</strong>g <strong>in</strong>crement for kcps is dependent on the table’s base-note frequency ibas, and isautomatically adjusted if the orchestra sr value differs from that at which the source wasrecorded. In this unit, ftable is always sampled with <strong>in</strong>terpolation.If sampl<strong>in</strong>g reaches the susta<strong>in</strong> loop endpo<strong>in</strong>t and loop<strong>in</strong>g is <strong>in</strong> effect, the po<strong>in</strong>t of sampl<strong>in</strong>g willbe modified and loscil will cont<strong>in</strong>ue read<strong>in</strong>g from with<strong>in</strong> that loop segment. Once the <strong>in</strong>strumenthas received a turnoff signal (from the score or from a MIDI noteoff event), the next susta<strong>in</strong>endpo<strong>in</strong>t encountered will be ignored and sampl<strong>in</strong>g will cont<strong>in</strong>ue towards the release loop endpo<strong>in</strong>t,or towards the last sample (henceforth to zeros).The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Sample Playback Page 39-1


loscil is the basic unit for build<strong>in</strong>g a sampl<strong>in</strong>g synthesizer. Given a sufficient set of recordedpiano tones, for example, this unit can resample them to simulate the miss<strong>in</strong>g tones. Locat<strong>in</strong>g thesound source nearest a desired pitch can be done via table lookup. Once a sampl<strong>in</strong>g <strong>in</strong>strumenthas begun, its turnoff po<strong>in</strong>t may be unpredictable and require an external release envelope; this isoften done by gat<strong>in</strong>g the sampled audio with l<strong>in</strong>enr, which will extend the duration of a turnedoff<strong>in</strong>strument by a specific period while it implements a decay.loscil3 is experimental. It is identical to loscil, except that it uses cubic <strong>in</strong>terpolation. New <strong>in</strong><strong>Csound</strong> version 3.50.39.1.4 EXAMPLE<strong>in</strong>um notnumicps cpsmidiiamp ampmidi 3000, 1ifno table <strong>in</strong>um, 2 ;notnum to choose an audio sampleibas table <strong>in</strong>um, 3kamp l<strong>in</strong>enr iamp, 0, .05, .01 ;at noteoff, extend by 50 ms.asig loscil kamp, icps, ifno, cpsoct(ibas/12. + 3)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Sample Playback Page 39-2


39.2 lposcil, lposcil3ar lposcil kamp, kfreqratio, kloop, kend, ifn [,iphs]ar lposcil3 kamp, kfreqratio, kloop, kend, ifn [,iphs]39.2.1 DESCRIPTIONRead sampled sound (mono or stereo) from a table, with optional susta<strong>in</strong> and release loop<strong>in</strong>g,and high precision. lposcil3 uses cubic <strong>in</strong>terpolation.39.2.2 INITIALIZATIONifn – function table numberiphs(optional) – <strong>in</strong>itial phase (<strong>in</strong> samples)39.2.3 PERFORMANCEkamp – amplitudekfreqratio – multiply factor of table frequency (for example: 1 = orig<strong>in</strong>al frequency, 1.5 = a fifthup , .5 = an octave down)kloop – loop po<strong>in</strong>t (<strong>in</strong> samples)kend – end loop po<strong>in</strong>t (<strong>in</strong> samples)lposcil (loop<strong>in</strong>g precise oscillator) allows vary<strong>in</strong>g at k-rate, the start<strong>in</strong>g and end<strong>in</strong>g po<strong>in</strong>t of asample conta<strong>in</strong>ed <strong>in</strong> a table (GEN01). This can be useful when read<strong>in</strong>g a sampled loop of awavetable, where repeat speed can be varied dur<strong>in</strong>g the performance.39.2.4 AUTHORGabriel Maldonado (lposcil)John ffitch (lposcil3)University of Bath/Codemist Ltd.ItalyBath, UK1998 (New <strong>in</strong> <strong>Csound</strong> version 3.52) February, 1999 (New <strong>in</strong> <strong>Csound</strong> version 3.52)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Sample Playback Page 39-3


39.3 sfload, sfplist, sfilist, sfpassign, sfpreset, sfplay,sfplaym, sf<strong>in</strong>str, sf<strong>in</strong>strmir sfload "filename"sfpassign istartndx, ifilhandleir sfpreset iprog, ibank, ifilhandle, iprendxsfplistsfilistifilhandleifilhandlea1, a2 sfplay ivel, <strong>in</strong>otnum, xamp, xfreq, iprendx [, iflag]`a1 sfplaym ivel, <strong>in</strong>otnum, xamp, xfreq, iprendx [, iflag]a1, a2 sf<strong>in</strong>str ivel, <strong>in</strong>otnum, xamp, xfreq, <strong>in</strong>strnum, ifilhandle [,iflag]a1 sf<strong>in</strong>strm ivel, <strong>in</strong>otnum, xamp, xfreq, <strong>in</strong>strnum, ifilhandle [,iflag]39.3.1 DESCRIPTION<strong>Csound</strong> support for the SoundFont2 (SF2) sample file format. These opcodes allow managementthe sample-structure of SF2 files. In order to understand the usage of these opcodes, the usermust have some knowledge of the SF2 format, so a brief description of this format can be found<strong>in</strong> the Appendix.Note that sfload, sfpassign, and sfpreset are placed <strong>in</strong> the header section of a <strong>Csound</strong> orchestra.39.3.2 INITIALIZATIONir – output to be used by other SF2 opcodes. For sfload, ir is ifilhandle. For sfpreset, ir isiprendx.filename – name of the SF2 file, with its complete path. It must be typed with<strong>in</strong> double-quotes.Use “/” to separate directories. This applies to DOS and W<strong>in</strong>dows as well, where us<strong>in</strong>g abackslash will generate an error.ifilhandle – unique number generated by sfload opcode to be used as an identifier for a SF2 file.Several SF2 files can be loaded and activated at the same time.istartndx – start<strong>in</strong>g <strong>in</strong>dex preset by the user <strong>in</strong> bulk preset assignments (see below).iprendx – preset <strong>in</strong>dexiprog – program number of a bank of presets <strong>in</strong> a SF2 fileibank – number of a specific bank of a SF2 fileivel – velocity value<strong>in</strong>otnum – MIDI note number valueiflag – flag regard<strong>in</strong>g the behavior of xfreq and <strong>in</strong>otnum<strong>in</strong>strnum – number of an <strong>in</strong>strument of a SF2 file.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Sample Playback Page 39-4


39.3.3 PERFORMANCExamp – amplitude correction factorxfreq – frequency value or frequency multiplier, depend<strong>in</strong>g by iflag. When iflag = 0, xfreq is amultiplier of a the default frequency, assigned by SF2 preset to the <strong>in</strong>otenum value. When iflag =1, xfreq is the absolute frequency of the output sound, <strong>in</strong> Hz. Default is 0.sfload loads an entire SF2 file <strong>in</strong>to memory. It returns a file handle to be used by other opcodes.Several <strong>in</strong>stances of sfload can placed <strong>in</strong> the header section of an orchestra, allow<strong>in</strong>g use of morethan one SF2 file <strong>in</strong> a s<strong>in</strong>gle orchestra.sfplist pr<strong>in</strong>ts a list of all presets of a previously loaded SF2 file to the console.sfilist pr<strong>in</strong>ts a list of all <strong>in</strong>struments of a previously loaded SF2 file to the console.sfpassign assigns all presets of a previously loaded SF2 file to a sequence of progressive <strong>in</strong>dexnumbers, to be used later with the opcodes sfplay and sfplaym. istartndx specifies the start<strong>in</strong>g<strong>in</strong>dex number. Any number of sfpassign <strong>in</strong>stances can be placed <strong>in</strong> the header section of anorchestra, each one assign<strong>in</strong>g presets belong<strong>in</strong>g to different SF2 files. The user must take carethat preset <strong>in</strong>dex numbers of different SF2 files do not overlap.sfpreset assigns an exist<strong>in</strong>g preset of a previously loaded SF2 file to an <strong>in</strong>dex number, to be usedlater with the opcodes sfplay and sfplaym. The user must previously know the program and thebank numbers of the preset <strong>in</strong> order to fill the correspond<strong>in</strong>g arguments. Any number of sfpreset<strong>in</strong>stances can be placed <strong>in</strong> the header section of an orchestra, each one assign<strong>in</strong>g a differentpreset belong<strong>in</strong>g to the same (or different) SF2 file to different <strong>in</strong>dex numbers.sfplay plays a preset, generat<strong>in</strong>g a stereo sound. ivel does not directly affect the amplitude of theoutput, but <strong>in</strong>forms sfplay about which sample should be chosen <strong>in</strong> multi-sample, velocity-splitpresets.When iflag = 0, <strong>in</strong>otnum sets the frequency of the output accord<strong>in</strong>g to the MIDI note numberused, and xfreq is used as a multiplier. When iflag = 1, the frequency of the output, is set directlyby xfreq. This allows the user to use any k<strong>in</strong>d of micro-tun<strong>in</strong>g based scales. However, thismethod is designed to work correctly only with presets tuned to the default equal temperament.Attempts to use this method with a preset already hav<strong>in</strong>g non-standard tun<strong>in</strong>gs, or with drum-kitbasedpresets, could give unexpected results.Adjustment of the amplitude can be done by vary<strong>in</strong>g the xamp argument, which acts as amultiplier.Notice that both xamp and xfreq can use k-rate as well as a-rate signals. Both arguments must usevariables of the same rate, or sfplay will not work correctly. iprendx must conta<strong>in</strong> the number ofa previously assigned preset, or <strong>Csound</strong> will crash.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Sample Playback Page 39-5


sfplaym is a mono version of sfplay. It should be used with mono preset, or with the stereopresets <strong>in</strong> which stereo output is not required. It is faster than sfplay.sf<strong>in</strong>str plays an SF2 <strong>in</strong>strument <strong>in</strong>stead of a preset (an SF2 <strong>in</strong>strument is the base of a presetlayer). <strong>in</strong>strnum specifies the <strong>in</strong>strument number, and the user must be sure that the specifiednumber belongs to an exist<strong>in</strong>g <strong>in</strong>strument of a determ<strong>in</strong>ate soundfont bank. Notice that bothxamp and xfreq can operate at k-rate as well as a-rate, but both arguments must work at the samerate.sf<strong>in</strong>strm plays is a mono version of sf<strong>in</strong>str. This is the fastest opcode of the SF2 family.These opcodes only support the sample structure of SF2 files. The modulator structure of theSoundFont2 format is not supported <strong>in</strong> <strong>Csound</strong>. Any modulation or process<strong>in</strong>g to the sample datais left to the <strong>Csound</strong> user, bypass<strong>in</strong>g all restrictions forced by the SF2 standard.39.3.4 AUTHORGabriel MaldonadoItalyMay, 2000 (New <strong>in</strong> <strong>Csound</strong> Version 4.06)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Sample Playback Page 39-6


40 SIGNAL GENERATORS: GRANULARSYNTHESIS40.1 fof, fof2ar fof xamp, xfund, xform, koct, kband, kris, kdur, kdec,\\iolaps, ifna, ifnb, itotdur[, iphs[, ifmode]]ar fof2 xamp, xfund, xform, koct, kband, kris, kdur, kdec,\\iolaps, ifna, ifnb, itotdur, kphs, kgliss40.1.1 DESCRIPTIONAudio output is a succession of s<strong>in</strong>usoid bursts <strong>in</strong>itiated at frequency xfund with a spectral peakat xform. For xfund above 25 Hz these bursts produce a speech-like formant with spectralcharacteristics determ<strong>in</strong>ed by the k-<strong>in</strong>put parameters. For lower fundamentals this generatorprovides a special form of granular synthesis.fof2 implements k-rate <strong>in</strong>cremental <strong>in</strong>dex<strong>in</strong>g <strong>in</strong>to ifna function with each successive burst.40.1.2 INITIALIZATIONiolaps – number of preallocated spaces needed to hold overlapp<strong>in</strong>g burst data. Overlaps arefrequency dependent, and the space required depends on the maximum value of xfund * kdur.Can be over-estimated at no computation cost. Uses less than 50 bytes of memory per iolap.ifna, ifnb- table numbers of two stored functions. The first is a s<strong>in</strong>e table for s<strong>in</strong>eburst synthesis(size of at least 4096 recommended). The second is a rise shape, used forwards and backwards toshape the s<strong>in</strong>eburst rise and decay; this may be l<strong>in</strong>ear (GEN07) or perhaps a sigmoid (GEN19).itotdur – total time dur<strong>in</strong>g which this fof will be active. Normally set to p3. No new s<strong>in</strong>eburst iscreated if it cannot complete its kdur with<strong>in</strong> the rema<strong>in</strong><strong>in</strong>g itotdur.iphs (optional) – <strong>in</strong>itial phase of the fundamental, expressed as a fraction of a cycle (0 to 1). Thedefault value is 0.ifmode (optional) – formant frequency mode. If zero, each s<strong>in</strong>eburst keeps the xform frequency itwas launched with. If non-zero, each is <strong>in</strong>fluenced by xform cont<strong>in</strong>uously. The default value is 0.40.1.3 PERFORMANCExamp – peak amplitude of each s<strong>in</strong>eburst, observed at the true end of its rise pattern. The risemay exceed this value given a large bandwidth (say, Q < 10) and/or when the bursts areoverlapp<strong>in</strong>g.xfund – the fundamental frequency (<strong>in</strong> Hertz) of the impulses that create new s<strong>in</strong>ebursts.xform – the formant frequency, i.e. freq of the s<strong>in</strong>usoid burst <strong>in</strong>duced by each xfund impulse.This frequency can be fixed for each burst or can vary cont<strong>in</strong>uously (see ifmode).The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-1


koct – octaviation <strong>in</strong>dex, normally zero. If greater than zero, lowers the effective xfund frequencyby attenuat<strong>in</strong>g odd-numbered s<strong>in</strong>ebursts. Whole numbers are full octaves, fractions transitional.kband – the formant bandwidth (at -6dB), expressed <strong>in</strong> Hz. The bandwidth determ<strong>in</strong>es the rate ofexponential decay throughout the s<strong>in</strong>eburst, before the envelop<strong>in</strong>g described below is applied.kris, kdur, kdec – rise, overall duration, and decay times (<strong>in</strong> seconds) of the s<strong>in</strong>usoid burst. Thesevalues apply an enveloped duration to each burst, <strong>in</strong> similar fashion to a <strong>Csound</strong> l<strong>in</strong>en generatorbut with rise and decay shapes derived from the ifnb <strong>in</strong>put. kris <strong>in</strong>versely determ<strong>in</strong>es theskirtwidth (at -40 dB) of the <strong>in</strong>duced formant region. kdur affects the density of s<strong>in</strong>eburstoverlaps, and thus the speed of computation. Typical values for vocal imitation are .003,.02,.007.In the fof2 implementation, kphs allows k-rate <strong>in</strong>dex<strong>in</strong>g of function table ifna with eachsuccessive burst, mak<strong>in</strong>g it suitable for time-warp<strong>in</strong>g applications. Values of for kphs arenormalized from 0 to 1, 1 be<strong>in</strong>g the end of the function table ifna. kgliss – sets the end pitch ofeach gra<strong>in</strong> relative to the <strong>in</strong>itial pitch, <strong>in</strong> octaves. Thus kgliss = 2 means that the gra<strong>in</strong> ends twooctaves above its <strong>in</strong>itial pitch, while kgliss = -5/3 has the gra<strong>in</strong> end<strong>in</strong>g a perfect major sixthbelow. Note: There are no optional parameters <strong>in</strong> fof2<strong>Csound</strong>’s fof generator is loosely based on Michael Clarke’s C-cod<strong>in</strong>g of IRCAM’s CHANTprogram (Xavier Rodet et al.). Each fof produces a s<strong>in</strong>gle formant, and the output of four or moreof these can be summed to produce a rich vocal imitation. fof synthesis is a special form ofgranular synthesis, and this implementation aids transformation between vocal imitation andgranular textures. Computation speed depends on kdur, xfund, and the density of any overlaps.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-2


40.2 fogar fog xamp, xdens, xtrans, xspd, koct, kband, kris, kdur,\\kdec, iolaps, ifna, ifnb, itotdur[, iphs[, itmode]]40.2.1 DESCRIPTIONAudio output is a succession of gra<strong>in</strong>s derived from data <strong>in</strong> a stored function table ifna. The localenvelope of these gra<strong>in</strong>s and their tim<strong>in</strong>g is based on the model of fof synthesis and permitsdetailed control of the granular synthesis.40.2.2 INITIALIZATIONiolaps – number of pre-located spaces needed to hold overlapp<strong>in</strong>g gra<strong>in</strong> data. Overlaps aredensity dependent, and the space required depends on the maximum value of xdens* kdur. Canbe over-estimated at no computation cost. Uses less than 50 bytes of memory per iolaps.ifna, ifnb – table numbers of two stored functions. The first is the data used for granulation,usually from a soundfile (GEN01). The second is a rise shape, used forwards and backwards toshape the gra<strong>in</strong> rise and decay; this is normally a sigmoid (GEN19) but may be l<strong>in</strong>ear (GEN07).itotdur – total time dur<strong>in</strong>g which this fog will be active. Normally set to p3. No new gra<strong>in</strong> iscreated if it cannot complete its kdur with<strong>in</strong> the rema<strong>in</strong><strong>in</strong>g itotdur.iphs (optional) – <strong>in</strong>itial phase of the fundamental, expressed as a fraction of a cycle (0 to 1). Thedefault value is 0.itmode (optional) – transposition mode. If zero, each gra<strong>in</strong> keeps the xtrans value it was launchedwith. if non-zero, each is <strong>in</strong>fluenced by xtrans cont<strong>in</strong>uously. The default value is 0.40.2.3 PERFORMANCExamp – amplitude factor. Amplitude is also dependent on the number of overlapp<strong>in</strong>g gra<strong>in</strong>s, the<strong>in</strong>teraction of the rise shape (ifnb) and the exponential decay (kband), and the scal<strong>in</strong>g of the gra<strong>in</strong>waveform (ifna). The actual amplitude may therefore exceed xamp.xdens – density. The frequency of gra<strong>in</strong>s per second.xtrans – transposition factor. The rate at which data from the stored function table ifna is readwith<strong>in</strong> each gra<strong>in</strong>. This has the effect of transpos<strong>in</strong>g the orig<strong>in</strong>al material. A value of 1 producesthe orig<strong>in</strong>al pitch. Higher values transpose upwards, lower values downwards. Negative valuesresult <strong>in</strong> the function table be<strong>in</strong>g read backwards.xspd – speed. The rate at which successive gra<strong>in</strong>s advance through the stored function table ifna.xspd is <strong>in</strong> the form of an <strong>in</strong>dex (0 to 1) to ifna. This determ<strong>in</strong>es the movement of a po<strong>in</strong>ter usedas the start<strong>in</strong>g po<strong>in</strong>t for read<strong>in</strong>g data with<strong>in</strong> each gra<strong>in</strong>. (xtrans determ<strong>in</strong>es the rate at which datais read start<strong>in</strong>g from this po<strong>in</strong>ter.)koct – octaviation <strong>in</strong>dex. The operation of this parameter is identical to that <strong>in</strong> fof.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-3


kband, kris, kdur, kdec – gra<strong>in</strong> envelope shape. These parameters determ<strong>in</strong>e the exponentialdecay (kband), and the rise (kris), overall duration (kdur,) and decay (kdec ) times of the gra<strong>in</strong>envelope. Their operation is identical to that of the local envelope parameters <strong>in</strong> fof.The <strong>Csound</strong> fog generator is by Michael Clarke, extend<strong>in</strong>g his earlier work based on IRCAM’sfof algorithm.40.2.4 EXAMPLE;p4 = transposition factor;p5 = speed factor;p6 = function table for gra<strong>in</strong> datai1 = sr/ftlen(p6) ;scal<strong>in</strong>g to reflect sample rate and table lengtha1 phasor i1*p5 ;<strong>in</strong>dex for speeda2 fog 5000, 100, p4, a1, 0, 0, , .01, .02, .01, 2, p6, 1, p3, 0, 140.2.5 AUTHORMichael ClarkHuddersfieldMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-4


40.3 gra<strong>in</strong>ar gra<strong>in</strong> xamp, xpitch, xdens, kampoff, kpitchoff, kgdur, igfn,\\iwfn, imgdur [, igrnd]40.3.1 DESCRIPTIONGenerates granular synthesis textures.40.3.2 INITIALIZATIONigfn – The ftable number of the gra<strong>in</strong> waveform. This can be just a s<strong>in</strong>e wave or a sampledsound.iwfn – Ftable number of the amplitude envelope used for the gra<strong>in</strong>s (see also GEN20).imgdur – Maximum gra<strong>in</strong> duration <strong>in</strong> seconds. This the biggest value to be assigned to kgdur.igrn – (optional) if non-zero, turns off gra<strong>in</strong> offset randomness. This means that all gra<strong>in</strong>s willbeg<strong>in</strong> read<strong>in</strong>g from the beg<strong>in</strong>n<strong>in</strong>g of the igfn table. If zero (the default), gra<strong>in</strong>s will start read<strong>in</strong>gfrom random igfn table positions.40.3.3 PERFORMANCExamp – Amplitude of each gra<strong>in</strong>.xpitch – Gra<strong>in</strong> pitch. To use the orig<strong>in</strong>al frequency of the <strong>in</strong>put sound, use the formula:sndsr / ftlen(igfn) where sndsr is the orig<strong>in</strong>al sample rate of the igfn sound.xdens – Density of gra<strong>in</strong>s measured <strong>in</strong> gra<strong>in</strong>s per second. If this is constant then the output issynchronous granular synthesis, very similar to fof. If xdens has a random element (like addednoise), then the result is more like asynchronous granular synthesis.kampoff – Maximum amplitude deviation from kamp. This means that the maximum amplitude agra<strong>in</strong> can have is kamp + kampoff and the m<strong>in</strong>imum is kamp. If kampoff is set to zero then thereis no random amplitude for each gra<strong>in</strong>.kpitchoff – Maximum pitch deviation from kpitch <strong>in</strong> Hz. Similar to kampoff.kgdur – Gra<strong>in</strong> duration <strong>in</strong> seconds. The maximum value for this should be declared <strong>in</strong> imgdur. Ifkgdur at any po<strong>in</strong>t becomes greater than imgdur, it will be truncated to imgdur.The gra<strong>in</strong> generator is based primarily on work and writ<strong>in</strong>gs of Barry Truax and Curtis Roads.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-5


40.3.4 EXAMPLEA texture with gradually shorter gra<strong>in</strong>s and wider amp and pitch spread;;;;;;;;;;;;;;; gra<strong>in</strong>test.orc<strong>in</strong>str 1<strong>in</strong>snd = 10ibasfrq = 32000 / ftlen(<strong>in</strong>snd) ; Use orig<strong>in</strong>al sample rate of <strong>in</strong>snd filekamp expseg 8000, p3/2, 8000, p3/2, 16000kpitch l<strong>in</strong>e ibasfrq, p3, ibasfrq * .8kdens l<strong>in</strong>e 600, p3, 200kaoff l<strong>in</strong>e 0, p3, 5000kpoff l<strong>in</strong>e 0, p3, ibasfrq * .5kgdur l<strong>in</strong>e .4, p3, .1imaxgdur = .5ar gra<strong>in</strong> kamp, kpitch, kdens, kaoff, kpoff, kgdur, <strong>in</strong>snd, 5, imaxgdur, 0.0out arend<strong>in</strong>;;;;;;;;;;;;;;; gra<strong>in</strong>test.scof5 0 512 20 2; Hann<strong>in</strong>g w<strong>in</strong>dowf10 0 65536 1 “Sound.wav” 0 0 0i1 0 10e40.3.5 AUTHORParis SmaragdisMITMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-6


40.4 granuleasig granule xamp, ivoice, iratio, imode, ithd, ifn, ipshift,\\igskip, igskip_os, ilength, kgap, igap_os, kgsize,\\igsize_os, iatt, idec [,iseed[,ipitch1[,ipitch2\\[,ipitch3[,ipitch4[,ifnenv]]]]]]40.4.1 DESCRIPTIONThe granule unit generator is more complex than gra<strong>in</strong>, but does add new possibilities.granule is a <strong>Csound</strong> unit generator which employs a wavetable as <strong>in</strong>put to produce granularlysynthesized audio output. Wavetable data may be generated by any of the GEN subrout<strong>in</strong>es suchas GEN01 which reads an audio data file <strong>in</strong>to a wavetable. This enable a sampled sound to beused as the source for the gra<strong>in</strong>s. Up to 128 voices are implemented <strong>in</strong>ternally. The maximumnumber of voices can be <strong>in</strong>creased by redef<strong>in</strong><strong>in</strong>g the variable MAXVOICE <strong>in</strong> the gra<strong>in</strong>4.h file.granule has a build-<strong>in</strong> random number generator to handle all the random offset parameters.Threshold<strong>in</strong>g is also implemented to scan the source function table at <strong>in</strong>itialization stage. Thisfacilitates features such as skipp<strong>in</strong>g silence passage between sentences.The characteristics of the synthesis are controlled by 22 parameters. xamp is the amplitude of theoutput and it can be either audio rate or control rate variable.40.4.2 PERFORMANCExamp – amplitude.ivoice – number of voices.iratio – ratio of the speed of the gskip po<strong>in</strong>ter relative to output audio sample rate. e.g. 0.5 willbe half speed.imode – +1 gra<strong>in</strong> po<strong>in</strong>ter move forward (same direction of the gskip po<strong>in</strong>ter), -1 backward(oppose direction to the gskip po<strong>in</strong>ter) or 0 for random.ithd – threshold, if the sampled signal <strong>in</strong> the wavetable is smaller then ithd, it will be skipped.ifn – function table number of sound source.ipshift – pitch shift control. If ipshift is 0, pitch will be set randomly up and down an octave. Ifipshift is 1, 2, 3 or 4, up to four different pitches can be set amount the number of voices def<strong>in</strong>ed<strong>in</strong> ivoice. The optional parameters ipitch1, ipitch2, ipitch3 and ipitch4 are used to quantify thepitch shifts.igskip – <strong>in</strong>itial skip from the beg<strong>in</strong>n<strong>in</strong>g of the function table <strong>in</strong> sec.igskip_os – gskip po<strong>in</strong>ter random offset <strong>in</strong> sec, 0 will be no offset.ilength – length of the table to be used start<strong>in</strong>g from igskip <strong>in</strong> sec.kgap – gap between gra<strong>in</strong>s <strong>in</strong> sec.igap_os – gap random offset <strong>in</strong> % of the gap size, 0 gives no offset.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-7


kgsize – gra<strong>in</strong> size <strong>in</strong> sec.igsize_os – gra<strong>in</strong> size random offset <strong>in</strong> % of gra<strong>in</strong> size, 0 gives no offset.iatt – attack of the gra<strong>in</strong> envelope <strong>in</strong> % of gra<strong>in</strong> size.idec – decade of the gra<strong>in</strong> envelope <strong>in</strong> % of gra<strong>in</strong> size.[iseed] – optional, seed for the random number generator, default is 0.5.[ipitch1], [ipitch2], [ipitch3], [ipitch4]- optional, pitch shift parameter, used when ipshift is setto 1, 2, 3 or 4. Time scal<strong>in</strong>g technique is used <strong>in</strong> pitch shift with l<strong>in</strong>ear <strong>in</strong>terpolation between datapo<strong>in</strong>ts. Default value is 1, the orig<strong>in</strong>al pitch.40.4.3 EXAMPLE40.4.3.1 Orchestra file:sr = 44100kr = 4410ksmps = 10nchnls = 2<strong>in</strong>str 1;k1a1a2end<strong>in</strong>l<strong>in</strong>seg 0,0.5,1,(p3-p2-1),1,0.5,0granule p4*k1,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,\p16,p17,p18,p19,p20,p21,p22,p23,p24granule p4*k1,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,\p16,p17,p18,p19, p20+0.17,p21,p22,p23,p24outs a1,a240.4.3.2 Score file:; f statement read sound file s<strong>in</strong>e.aiff <strong>in</strong> the SFDIR; directory <strong>in</strong>to f-table 1f1 0 524288 1 “s<strong>in</strong>e.aiff” 1 0i1 0 10 2000 64 0.5 0 0 1 4 0 0.005 10 0.01 50 0.02 50 30 30 0.39 \1 1.42 0.29 2eThe above example reads a sound file called s<strong>in</strong>e.aiff <strong>in</strong>to wavetable number 1 with 524,288samples. It generates 10 seconds of stereo audio output us<strong>in</strong>g the wavetable. In the orchestra file,all parameters required to control the synthesis are passed from the score file. A l<strong>in</strong>seg functiongenerator is used to generate an envelope with 0.5 second of l<strong>in</strong>ear attack and decay. Stereoeffect is generated by us<strong>in</strong>g different seeds for the two granule function calls. In the example,0.17 is added to p20 before pass<strong>in</strong>g <strong>in</strong>to the second granule call to ensure that all of the randomoffset events are different from the first one.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-8


In the score file, the parameters are <strong>in</strong>terpreted as:p5 (ivoice) the number of voices is set to 64p6 (iratio) is set to 0.5, it scan the wavetable at half of the speedof the audio output ratep7 (imode) is set to 0, the gra<strong>in</strong> po<strong>in</strong>ter only move forwardp8 (ithd) is set to 0, skipp<strong>in</strong>g the threshold<strong>in</strong>g processp9 (ifn) is set to 1, function table number 1 is usedp10 (ipshift) is set to 4, four different pitches are go<strong>in</strong>g to begeneratedp11 (igskip) is set to 0 and p12 (igskip_os) is set to 0.005, noskipp<strong>in</strong>g <strong>in</strong>to the wavetable and a 5 mSec random offset is usedp13 (ilength) is set to 10, 10 seconds of the wavetable is to be usedp14 (kgap) is set to 0.01 and p15 (igap_os) is set to 50, 10 mSec gapwith 50% random offset is to be usedp16 (kgsize) is set to 0.02 and p17 (igsize_os) is set to 50, 20 mSecgra<strong>in</strong> with 50% random offset is usedp18 (iatt) and p19 (idec) are set to 30, 30% of l<strong>in</strong>ear attack anddecade is applied to the gra<strong>in</strong>p20 (iseed) seed for the random number generator is set to 0.39p21 - p 24 are pitches set to 1 which is the orig<strong>in</strong>al pitch, 1.42which is a 5th up, 0.29 which is a 7th down and f<strong>in</strong>ally 2 which isan octave up.40.4.4 AUTHORAllan LeeBelfast1996The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-9


40.5 sndwarp, sndwarpstar[,ac] sndwarp xamp, xtimewarp, xresample, ifn1, ibeg,\\iwsize, irandw, ioverlap, ifn2, itimemodear1,ar2[,ac1,ac2]sndwarpst xamp, xtimewarp, xresample, ifn1, ibeg,\\iwsize, irandw, ioverlap, ifn2, itimemode40.5.1 DESCRIPTIONsndwarp reads sound samples from a table and applies time-stretch<strong>in</strong>g and/or pitchmodification. Time and frequency modification are <strong>in</strong>dependent from one another. For example,a sound can be stretched <strong>in</strong> time while rais<strong>in</strong>g the pitch! The w<strong>in</strong>dow size and overlap argumentsare important to the result and should be experimented with. In general they should be as smallas possible. For example, start with iwsize=sr/10 and ioverlap=15. Try irandw=iwsize*.2. If youcan get away with less overlaps, the program will be faster. But too few may cause an audibleflutter <strong>in</strong> the amplitude. The algorithm reacts differently depend<strong>in</strong>g upon the <strong>in</strong>put sound andthere are no fixed rules for the best use <strong>in</strong> all circumstances. But with proper tun<strong>in</strong>g, excellentresults can be achieved.40.5.2 INITIALIZATIONifn1 – the number of the table hold<strong>in</strong>g the sound samples which will be subjected to the sndwarpprocess<strong>in</strong>g. GEN01 is the appropriate function generator to use to store the sound samples from apre-exist<strong>in</strong>g soundfile.ibeg – the time <strong>in</strong> seconds to beg<strong>in</strong> read<strong>in</strong>g <strong>in</strong> the table (or soundfile). When itimemode is nonzero,the value of xtimewarp is offset by ibeg.iwsize – the w<strong>in</strong>dow size <strong>in</strong> samples used <strong>in</strong> the time scal<strong>in</strong>g algorithm.irandw – the bandwidth of a random number generator. The random numbers will be added toiwsize.ioverlap – determ<strong>in</strong>es the density of overlapp<strong>in</strong>g w<strong>in</strong>dows.ifn2 – a function used to shape the w<strong>in</strong>dow. It is usually used to create a ramp of some k<strong>in</strong>d fromzero at the beg<strong>in</strong>n<strong>in</strong>g and back down to zero at the end of each w<strong>in</strong>dow. Try us<strong>in</strong>g a half a s<strong>in</strong>e(i.e.: f1 0 16384 9 .5 1 0) which works quite well. Other shapes can also be used.40.5.3 PERFORMANCEar – s<strong>in</strong>gle channel of output from the sndwarp unit generator while ar1 and ar2 are the stereo(left and right) outputs from sndwarpst. sndwarp assumes that the function table hold<strong>in</strong>g thesampled signal is a mono one while sndwarpst assumes that it is stereo. This simply means thatsndwarp will <strong>in</strong>dex the table by s<strong>in</strong>gle-sample frame <strong>in</strong>crements and sndwarpst will <strong>in</strong>dex thetable by a two-sample frame <strong>in</strong>crement. The user must be aware then that if a mono signal isused with sndwarpst or a stereo one with sndwarp, time and pitch will be altered accord<strong>in</strong>gly.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-10


ac – <strong>in</strong> sndwarp and ac1, ac2 <strong>in</strong> sndwarpst, are s<strong>in</strong>gle layer (no overlaps), unw<strong>in</strong>dowedversions of the time and/or pitch altered signal. They are supplied <strong>in</strong> order to be able to balancethe amplitude of the signal output, which typically conta<strong>in</strong>s many overlapp<strong>in</strong>g and w<strong>in</strong>dowedversions of the signal, with a clean version of the time-scaled and pitch-shifted signal. Thesndwarp process can cause noticeable changes <strong>in</strong> amplitude, (up and down), due to a timedifferential between the overlaps when time-shift<strong>in</strong>g is be<strong>in</strong>g done. When used with a balanceunit, ac, ac1, ac2 can greatly enhance the quality of sound. They are optional, but note that <strong>in</strong>sndwarpst they must both be present <strong>in</strong> the syntax (use both or neither). An example of how touse this is given below.xamp – the value by which to scale the amplitude (see note on the use of this when us<strong>in</strong>g ac, ac1,ac2).xtimewarp – determ<strong>in</strong>es how the <strong>in</strong>put signal will be stretched or shrunk <strong>in</strong> time. There are twoways to use this argument depend<strong>in</strong>g upon the value given for itimemode. When the value ofitimemode is 0, xitimewarp will scale the time of the sound. For example, a value of 2 willstretch the sound by 2 times. When itimemode is any non-zero value then xtimewarp is used as atime po<strong>in</strong>ter <strong>in</strong> a similar way <strong>in</strong> which the time po<strong>in</strong>ter works <strong>in</strong> lpread and pvoc. An examplebelow illustrates this. In both cases, the pitch will not be altered by this process. Pitch shift<strong>in</strong>g isdone <strong>in</strong>dependently us<strong>in</strong>g xresample.xresample – the factor by which to change the pitch of the sound. For example, a value of 2 willproduce a sound one octave higher than the orig<strong>in</strong>al. The tim<strong>in</strong>g of the sound, however, will notbe altered.40.5.4 EXAMPLEThe below example shows a slow<strong>in</strong>g down or stretch<strong>in</strong>g of the sound stored <strong>in</strong> the stored table(ifn1). Over the duration of the note, the stretch<strong>in</strong>g will grow from no change from the orig<strong>in</strong>al toa sound which is ten times “slower” than the orig<strong>in</strong>al. At the same time the overall pitch willmove upward over the duration by an octave.iw<strong>in</strong>dfun=1isampfun=2ibeg=0iw<strong>in</strong>dsize=2000iw<strong>in</strong>drand=400ioverlap=10awarp l<strong>in</strong>e 1, p3, 10aresamp l<strong>in</strong>e 1, p3, 2kenv l<strong>in</strong>e 1, p3, .1asig sndwarp kenv,awarp,aresamp,isampfun,ibeg,iw<strong>in</strong>dsize,iw<strong>in</strong>drand, \\ioverlap,iw<strong>in</strong>dfun,0Now, here’s an example us<strong>in</strong>g xtimewarp as a time po<strong>in</strong>ter and us<strong>in</strong>g stereo:itimemode = 1atime l<strong>in</strong>e 0, p3, 10ar1, ar2 sndwarpst kenv, atime, aresamp, sampfun, ibeg, \\iw<strong>in</strong>dsize, iw<strong>in</strong>drand, ioverlap, \\iw<strong>in</strong>dfun, itimemodeThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-11


In the above, atime advances the time po<strong>in</strong>ter used <strong>in</strong> the sndwarp from 0 to 10 over theduration of the note. If p3 is 20 then the sound will be two times slower than the orig<strong>in</strong>al. Ofcourse you can use a more complex function than just a s<strong>in</strong>gle straight l<strong>in</strong>e to control the timefactor.Now the same as above but us<strong>in</strong>g the balance function with the optional outputs:asig,acmpabalsndwarp 1,awarp,aresamp,isampfun,ibeg,iw<strong>in</strong>dsize,iw<strong>in</strong>drand,\\ioverlap,iw<strong>in</strong>dfun,itimemodebalance asig, acmpasig1,asig2,acmp1,acmp2 sndwarpst 1, atime, aresamp, sampfun,\\ibeg, iw<strong>in</strong>dsize, iw<strong>in</strong>drand, \\ioverlap, iw<strong>in</strong>dfun, itimemodeabal1 balance asig1, acmp1abal2 balance asig2, acmp2In the above two examples notice the use of the balance unit. The output of balance can then bescaled, enveloped, sent to an out or outs, and so on. Notice that the amplitude arguments tosndwarp and sndwarpst are “1” <strong>in</strong> these examples. By scal<strong>in</strong>g the signal after the sndwarpprocess, abal, abal1, and abal2 should conta<strong>in</strong> signals that have nearly the same amplitude as theorig<strong>in</strong>al <strong>in</strong>put signal to the sndwarp process. This makes it much easier to predict the levels andavoid samples out of range or sample values that are too small.More advice: Only use the stereo version when you really need to be process<strong>in</strong>g a stereo file. It issomewhat slower than the mono version and if you use the balance function it is slower aga<strong>in</strong>.There is noth<strong>in</strong>g wrong with us<strong>in</strong>g a mono sndwarp <strong>in</strong> a stereo orchestra and send<strong>in</strong>g the resultto one or both channels of the stereo output!40.5.5 AUTHORRichard KarpenSeattle, Wash1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Granular Synthesis Page 40-12


41 SIGNAL GENERATORS: SCANNED SYNTHESISScanned synthesis is a variant of physical model<strong>in</strong>g, where a network of masses connected byspr<strong>in</strong>gs is used to generate a dynamic waveform. The opcode scanu def<strong>in</strong>es the mass/spr<strong>in</strong>gnetwork and sets it <strong>in</strong> motion. The opcode scans follows a predef<strong>in</strong>ed path (trajectory) aroundthe network and outputs the detected waveform. Several scans <strong>in</strong>stances may follow differentpaths around the same network.These are highly efficient mechanical modell<strong>in</strong>g algorithms for both synthesis and sonicanimation via algorithmic process<strong>in</strong>g. They should run <strong>in</strong> real-time. Thus, the output is usefuleither directly as audio, or as controller values for other parameters.The <strong>Csound</strong> implementation adds support for a scann<strong>in</strong>g path or matrix. Essentially, this offersthe possibility of reconnect<strong>in</strong>g the masses <strong>in</strong> different orders, caus<strong>in</strong>g the signal to propagatequite differently. They do not necessarily need to be connected to their direct neighbors.Essentially, the matrix has the effect of “mold<strong>in</strong>g” this surface <strong>in</strong>to a radically different shape.To produce the matrices, the table format is straightforward. For example, for 4 masses we havethe follow<strong>in</strong>g grid describ<strong>in</strong>g the possible connections:1 2 3 41234Whenever two masses are connected, the po<strong>in</strong>t they def<strong>in</strong>e is 1. If two masses are not connected,then the po<strong>in</strong>t they def<strong>in</strong>e is 0. For example, a unidirectional str<strong>in</strong>g has the follow<strong>in</strong>gconnections: (1,2), (2,3), (3,4). If it is bidirectional, it also has (2,1), (3,2), (4,3)). For theunidirectional str<strong>in</strong>g, the matrix appears:1 2 3 41 0 1 0 02 0 0 1 03 0 0 0 14 0 0 0 0The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Scanned Synthesis Page 41-1


The above table format of the connection matrix is for conceptual convenience only. The actualvalues shown <strong>in</strong> te table are obta<strong>in</strong>ed by scans from an ASCII file us<strong>in</strong>g GEN23. The actualASCII file is created from the table model row by row. Therefore the ASCII file for the exampletable shown above becomes:0100001000010000This marix example is very small and simple. In practice, most scanned synthesis <strong>in</strong>strumentswill use many more masses than four, so their matrices will be much larger and more complex.See the example <strong>in</strong> the scans documentation.Please note that the generated dynamic wavetables are very unstable. Certa<strong>in</strong> values for masses,center<strong>in</strong>g, and damp<strong>in</strong>g can cause the system to “blow up” and the most <strong>in</strong>terest<strong>in</strong>g sounds toemerge from your loudspeakers!The supplement to this manual conta<strong>in</strong>s a tutorial on scanned synthesis. The tutorial, examples,and other <strong>in</strong>formation on scanned synthesis is available from the Scanned Synthesis page atcSounds.com (http://www.csounds.com/scanned).Scanned synthesis developed by Bill Verplank, Max Mathews and Rob Shaw at IntervalResearch between 1998 and 2000.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Scanned Synthesis Page 41-2


41.1 scanuscanu<strong>in</strong>it, irate, ifnvel, ifnmass, ifnstif, ifncentr,ifndamp, kmass, kstif, kcentr, kdamp, ileft, iright,kpos, kstrngth, a<strong>in</strong>, idisp, id41.1.1 DESCRIPTIONCompute the waveform and the wavetable for use <strong>in</strong> scanned synthesis.41.1.2 INITIALIZATION<strong>in</strong>it – the <strong>in</strong>itial position of the masses. If this is a negative number, then the absolute of <strong>in</strong>itsignifies the table to use as a hammer shape. If <strong>in</strong>it > 0, the length of it should be the same as the<strong>in</strong>tended mass number, otherwise it can be anyth<strong>in</strong>g.ifnvel – the ftable that conta<strong>in</strong>s the <strong>in</strong>itial velocity for each mass. It should have the same size asthe <strong>in</strong>tended mass number.ifnmass – ftable that conta<strong>in</strong>s the mass of each mass. It should have the same size as the <strong>in</strong>tendedmass number.ifnstif – ftable that conta<strong>in</strong>s the spr<strong>in</strong>g stiffness of each connection. It should have the same sizeas the square of the <strong>in</strong>tended mass number. The data order<strong>in</strong>g is a row after row dump of theconnection matrix of the system.ifncentr – ftable that conta<strong>in</strong>s the center<strong>in</strong>g force of each mass. It should have the same size asthe <strong>in</strong>tended mass number.ifndamp – the ftable that conta<strong>in</strong>s the damp<strong>in</strong>g factor of each mass. It should have the same sizeas the <strong>in</strong>tended mass number.ileft – If <strong>in</strong>it < 0, the position of the left hammer (ileft = 0 is hit at leftmost, ileft = 1 is hit atrightmost).iright – If <strong>in</strong>it < 0, the position of the right hammer (iright = 0 is hit at leftmost, iright = 1 is hitat rightmost).idisp – If 0, no display of the masses is provided.id – If positive, the ID of the opcode. This will be used to po<strong>in</strong>t the scann<strong>in</strong>g opcode to theproper waveform maker. If this value is negative, the absolute of this value is the wavetable onwhich to write the waveshape. That wavetable can be used later from an other opcode to generatesound. The <strong>in</strong>itial contents of this table will be destroyed.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Scanned Synthesis Page 41-3


41.1.3 PERFORMANCEkmass – scales the masseskstif – scales the spr<strong>in</strong>g stiffnesskcentr – scales the center<strong>in</strong>g forcekdamp – scales the damp<strong>in</strong>gkpos – position of an active hammer along the str<strong>in</strong>g (kpos = 0 is leftmost, kpos = 1 is rightmost).The shape of the hammer is determ<strong>in</strong>ed by <strong>in</strong>it and the power it pushes with is kstrngth.kstrngth – power that the active hammer usesa<strong>in</strong> – audio <strong>in</strong>put that adds to the velocity of the masses. Amplitude should not be too great.41.1.4 EXAMPLEFor an example, see the documentation on scans.41.1.5 AUTHORParis SmaragdisMIT Media LabBoston, Massachussetts USAMarch, 2000 (New <strong>in</strong> <strong>Csound</strong> version 4.05)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Scanned Synthesis Page 41-4


41.2 scansar scans kamp, kfreq, ifn, id[, iorder]41.2.1 DESCRIPTIONGenerate audio output us<strong>in</strong>g scanned synthesis.41.2.2 INITIALIZATIONifn – ftable conta<strong>in</strong><strong>in</strong>g the scann<strong>in</strong>g trajectory. This is a series of numbers that conta<strong>in</strong>s addressesof masses. The order of these addresses is used as the scan path. It should not conta<strong>in</strong> valuesgreater than the number of masses, or negative numbers. See the <strong>in</strong>troduction to the scannedsynthesis section.id – ID number of the scanu opcode's waveform to useiorder (optional) – order of <strong>in</strong>terpolation used <strong>in</strong>ternally. It can take any value <strong>in</strong> the range 1 to 4,and defaults to 4, which is quartic <strong>in</strong>terpolation. The sett<strong>in</strong>g of 2 is quadratic and 1 is l<strong>in</strong>ear. Thehigher numbers are slower, but not necessarily better.41.2.3 PERFORMANCEkamp – output amplitude. Note that the result<strong>in</strong>g amplitude is also dependent on <strong>in</strong>stantaneousvalue <strong>in</strong> the wavetable. This number is effectively the scal<strong>in</strong>g factor of the wavetable.kfreq – frequency of the scan rate41.2.4 EXAMPLEHere is a simple example of scanned synthesis. The user must supply the matrix file "str<strong>in</strong>g-128". This file, as well as several other matrices, is available <strong>in</strong> a zipped file from the ScannedSynthesis page at cSounds.com (http://www.csounds.com/scanned).;orchestra ------------------------------------------sr = 44100kr = 4410ksmps = 10nchnls = 1<strong>in</strong>str 1a0 = 0scanu 1,.01, 6, 2, 3, 4, 5, 2, .1, .1, -.01, .1, .5, 0, 0,a0, 1, 2a1 scans ampdb(p4), cpspch(p5), 7, 2outa1end<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Scanned Synthesis Page 41-5


;score ----------------------------------------------; Initial conditionf1 0 128 7 0 64 1 64 0; Massesf2 0 128 -7 1 128 1; Spr<strong>in</strong>g matricesf3 0 16384 -23 "str<strong>in</strong>g-128"; Center<strong>in</strong>g forcef4 0 128 -7 0 128 2; Damp<strong>in</strong>gf5 0 128 -7 1 128 1; Initial velocityf6 0 128 -7 0 128 0; Trajectoriesf7 0 128 -5 .001 128 128; Note listi1 0 10 86 6.00i1 11 14 86 7.00i1 15 20 86 5.00e41.2.5 AUTHORParis SmaragdisMIT Media LabBoston, Massachussetts USAMarch, 2000 (New <strong>in</strong> <strong>Csound</strong> version 4.05)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Scanned Synthesis Page 41-6


42 SIGNAL GENERATORS: WAVEGUIDEPHYSICAL MODELING42.1 pluckar pluck kamp, kcps, icps, ifn, imeth [, iparm1, iparm2]42.1.1 DESCRIPTIONAudio output is a naturally decay<strong>in</strong>g plucked str<strong>in</strong>g or drum sound based on the Karplus-Strongalgorithms.42.1.2 INITIALIZATIONicps – <strong>in</strong>tended pitch value <strong>in</strong> Hz, used to set up a buffer of 1 cycle of audio samples which willbe smoothed over time by a chosen decay method. icps normally anticipates the value of kcps,but may be set artificially high or low to <strong>in</strong>fluence the size of the sample buffer.ifn – table number of a stored function used to <strong>in</strong>itialize the cyclic decay buffer. If ifn = 0, arandom sequence will be used <strong>in</strong>stead.imeth – method of natural decay. There are six, some of which use parameters values that follow.1. simple averag<strong>in</strong>g. A simple smooth<strong>in</strong>g process, un<strong>in</strong>fluenced by parameter values.2. stretched averag<strong>in</strong>g. As above, with smooth<strong>in</strong>g time stretched by a factor of iparm1 ( = 1 ).3. simple drum. The range from pitch to noise is controlled by a ‘roughness factor’ <strong>in</strong> iparm1(0 to 1). Zero gives the plucked str<strong>in</strong>g effect, while 1 reverses the polarity of every sample(octave down, odd harmonics). The sett<strong>in</strong>g .5 gives an optimum snare drum.4. stretched drum. Comb<strong>in</strong>es both roughness and stretch factors. iparm1 is roughness (0 to 1),and iparm2 the stretch factor ( = 1 ).5. weighted averag<strong>in</strong>g. As method 1, with iparm1 weight<strong>in</strong>g the current sample (the statusquo) and iparm2 weight<strong>in</strong>g the previous adjacent one. iparm1 + iparm2must be


Plucked str<strong>in</strong>gs (1,2,5,6) are best realized by start<strong>in</strong>g with a random noise source, which is rich <strong>in</strong><strong>in</strong>itial harmonics. Drum sounds (methods 3,4) work best with a flat source (wide pulse), whichproduces a deep noise attack and sharp decay.The orig<strong>in</strong>al Karplus-Strong algorithm used a fixed number of samples per cycle, which causedserious quantization of the pitches available and their <strong>in</strong>tonation. This implementation resamplesa buffer at the exact pitch given by kcps, which can be varied for vibrato and glissando effects.For low values of the orch sampl<strong>in</strong>g rate (e.g. sr = 10000), high frequencies will store only veryfew samples (sr / icps). S<strong>in</strong>ce this may cause noticeable noise <strong>in</strong> the resampl<strong>in</strong>g process, the<strong>in</strong>ternal buffer has a m<strong>in</strong>imum size of 64 samples. This can be further enlarged by sett<strong>in</strong>g icps tosome artificially lower pitch.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-2


42.2 wgpluckar wgpluck icps, iamp, kpick, iplk, idamp, ifilt, axcite42.2.1 DESCRIPTIONA high fidelity simulation of a plucked str<strong>in</strong>g, us<strong>in</strong>g <strong>in</strong>terpolat<strong>in</strong>g delay-l<strong>in</strong>es.42.2.2 INITIALIZATIONicps – frequency of plucked str<strong>in</strong>giamp – amplitude of str<strong>in</strong>g pluckiplk – po<strong>in</strong>t along the str<strong>in</strong>g, where it is plucked, <strong>in</strong> the range of 0 to 1. 0 = no pluckidamp – damp<strong>in</strong>g of the note. This controls the overall decay of the str<strong>in</strong>g. The greater the valueof idamp1, the faster the decay. Negative values will cause an <strong>in</strong>crease <strong>in</strong> output over time.ifilt – control the attenuation of the filter at the bridge. Higher values cause the higher harmonicsto decay faster.42.2.3 PERFORMANCEkpick – proportion of the way along the po<strong>in</strong>t to sample the outputaxcite – signal which excites the str<strong>in</strong>gA str<strong>in</strong>g of frequency icps is plucked with amplitude iamp at po<strong>in</strong>t iplk. The decay of the virtualstr<strong>in</strong>g is controlled by idamp and ifilt which simulate the bridge. The oscillation is sampled at thepo<strong>in</strong>t kpick, and excited by the signal axcite.42.2.4 EXAMPLESThe follow<strong>in</strong>g example produces a moderately long note with rapidly decay<strong>in</strong>g upper partials:<strong>in</strong>str 1axcite oscil 1, 1, 1apluck wgpluck 220, 120, .5, 0, 10, 1000, axciteout apluckend<strong>in</strong>whereas the follow<strong>in</strong>g produces a shorter, brighter note:<strong>in</strong>str 1axcite oscil 1, 1, 1apluck wgpluck 220, 120, .5, 0, 30, 10, axciteout apluckend<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-3


42.3 repluck, wgpluck2ar wgpluck2 iplk, xam, icps, kpick, kreflar repluck iplk, xam, icps, kpick, krefl, axcite42.3.1 DESCRIPTIONwgpluck2 is an implementation of the physical model of the plucked str<strong>in</strong>g, with control over thepluck po<strong>in</strong>t, the pickup po<strong>in</strong>t and the filter. repluck is the same operation, but with an additionalaudio signal, axcite, used to excite the ‘str<strong>in</strong>g’. Both opcodes are based on the Karplus-Strongalgorithms.42.3.2 INITIALIZATIONicps - The str<strong>in</strong>g plays at icps pitch.iplck – The po<strong>in</strong>t of pluck is iplk, which is a fraction of the way up the str<strong>in</strong>g (0 to 1). A pluckpo<strong>in</strong>t of zero means no <strong>in</strong>itial pluck.42.3.3 PERFORMANCExamp – Amplitude of note.kpick – Proportion of the way along the str<strong>in</strong>g to sample the output.kabsp – absorption coefficient at the bridge where 1 means total absorption and 0 is noabsorption.42.3.4 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UK1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-4


42.4 wgbowar wgbow kamp, kfreq, kpres, krat, kvibf, kvamp, ifn[, im<strong>in</strong>freq]42.4.1 DESCRIPTIONAudio output is a tone similar to a bowed str<strong>in</strong>g, us<strong>in</strong>g a physical model developed from PerryCook, but re-coded for <strong>Csound</strong>.42.4.2 INITIALIZATIONifn - table of shape of vibrato, usually a s<strong>in</strong>e table, created by a functionim<strong>in</strong>freq – lowest frequency at which the <strong>in</strong>strument will play. If it is omitted it is taken to bethe same as the <strong>in</strong>itial kfreq. If im<strong>in</strong>freq is negative, <strong>in</strong>itialization will be skipped.42.4.3 PERFORMANCEA note is played on a str<strong>in</strong>g-like <strong>in</strong>strument, with the arguments as below.kamp – Amplitude of note.kfreq – Frequency of note played.kpres – a parameter controll<strong>in</strong>g the pressure of the bow on the str<strong>in</strong>g. Values should be about 3.The useful range is approximately 1 to 5.krat – the position of the bow along the str<strong>in</strong>g. Usual play<strong>in</strong>g is about 0.127236. The suggestedrange is 0.025 to 0.23.kvibf – frequency of vibrato <strong>in</strong> Hertz. Suggested range is 0 to 12kvamp - amplitude of the vibrato42.4.4 EXAMPLEkv l<strong>in</strong>seg 0, 0.5, 0, 1, 1, p3-0.5, 1a1 wgbow 31129.60, 440, 3.0, 0.127236, 6.12723, kv*0.01, 1outa142.4.5 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-5


42.5 wgflutear wgflute kamp, kfreq, kjet, iatt, idetk, knga<strong>in</strong>, kvibf, kvamp,\\ifn[, im<strong>in</strong>freq[, kjetrf[, kendrf]]]42.5.1 DESCRIPTIONAudio output is a tone similar to a flute, us<strong>in</strong>g a physical model developed from Perry Cook, butre-coded for <strong>Csound</strong>.42.5.2 INITIALIZATIONiatt - time <strong>in</strong> seconds to reach full blow<strong>in</strong>g pressure. 0.1 seems to correspond to reasonableplay<strong>in</strong>g.idetk – time <strong>in</strong> seconds taken to stop blow<strong>in</strong>g. 0.1 is a smooth end<strong>in</strong>gifn - table of shape of vibrato, usually a s<strong>in</strong>e table, created by a functionim<strong>in</strong>freq – lowest frequency at which the <strong>in</strong>strument will play. If it is omitted it is taken to bethe same as the <strong>in</strong>itial kfreq. If im<strong>in</strong>freq is negative, <strong>in</strong>itialization will be skipped.42.5.3 PERFORMANCEkamp – Amplitude of note.kfreq – Frequency of note played. While it can be varied <strong>in</strong> performance, I have not tried it.kjet – a parameter controll<strong>in</strong>g the air jet. Values should be positive, and about 0.3. The usefulrange is approximately 0.08 to 0.56.knga<strong>in</strong> – amplitude of the noise component, about 0 to 0.5kvibf – frequency of vibrato <strong>in</strong> Hertz. Suggested range is 0 to 12kvamp - amplitude of the vibratokjetrf – amount of reflection <strong>in</strong> the breath jet that powers the flute. Default value is 0.5.kendrf – reflection coefficient of the breath jet. Default value is 0.5. Both ijetrf and iendrf areused <strong>in</strong> the calculation of the pressure differential.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-6


42.5.4 EXAMPLEa1 wgflute 31129.60, 440, 0.32, 0.1, 0.1, 0.15, 5.925, 0.05, 1outa142.5.5 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-7


42.6 wgbrassar wgbrass kamp, kfreq, ktens, iatt, kvibf, kvamp, ifn[, im<strong>in</strong>freq]42.6.1 DESCRIPTIONAudio output is a tone related to a brass <strong>in</strong>strument, us<strong>in</strong>g a physical model developed fromPerry Cook, but re-coded for <strong>Csound</strong>. [NOTE: This is rather poor, and at present uncontrolled.Needs revision, and possibly more parameters].42.6.2 INITIALIZATIONiatt -- time taken to reach full pressureifn – table of shape of vibrato, usually a s<strong>in</strong>e table, created by a functionim<strong>in</strong>freq – lowest frequency at which the <strong>in</strong>strument will play. If it is omitted it is taken to bethe same as the <strong>in</strong>itial kfreq. If im<strong>in</strong>freq is negative, <strong>in</strong>itialization will be skipped.42.6.3 PERFORMANCEA note is played on a brass-like <strong>in</strong>strument, with the arguments as below.kamp – Amplitude of note.kfreq – Frequency of note played.ktens – lip tension of the player. Suggested value is about 0.4kvibf – frequency of vibrato <strong>in</strong> Hertz. Suggested range is 0 to 12kvamp - amplitude of the vibrato42.6.4 EXAMPLEa1 wgbrass 31129.60, 440, 0.1, 6.137, 0.05, 1outa142.6.5 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-8


42.7 wgclarar wgclar kamp, kfreq, kstiff, iatt, idetk, knga<strong>in</strong>, kvibf, \\kvamp, ifn[, im<strong>in</strong>freq]42.7.1 DESCRIPTIONAudio output is a tone similar to a clar<strong>in</strong>et, us<strong>in</strong>g a physical model developed from Perry Cook,but re-coded for <strong>Csound</strong>.42.7.2 INITIALIZATIONiatt - time <strong>in</strong> seconds to reach full blow<strong>in</strong>g pressure. 0.1 seems to correspond to reasonableplay<strong>in</strong>g. A longer time gives a def<strong>in</strong>ite <strong>in</strong>itial w<strong>in</strong>d sound.idetk – time <strong>in</strong> seconds taken to stop blow<strong>in</strong>g. 0.1 is a smooth end<strong>in</strong>gifn - table of shape of vibrato, usually a s<strong>in</strong>e table, created by a functionim<strong>in</strong>freq – lowest frequency at which the <strong>in</strong>strument will play. If it is omitted it is taken to bethe same as the <strong>in</strong>itial kfreq. If im<strong>in</strong>freq is negative, <strong>in</strong>itialization will be skipped.42.7.3 PERFORMANCEA note is played on a clar<strong>in</strong>et-like <strong>in</strong>strument, with the arguments as below.kamp – Amplitude of note.kfreq – Frequency of note played.kstiff – a stiffness parameter for the reed. Values should be negative, and about -0.3. The usefulrange is approximately -0.44 to -0.18.knga<strong>in</strong> – amplitude of the noise component, about 0 to 0.5kvibf – frequency of vibrato <strong>in</strong> Hertz. Suggested range is 0 to 12kvamp - amplitude of the vibratoThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-9


42.7.4 EXAMPLEa1 wgclar 31129.60, 440, -0.3, 0.1, 0.1, 0.2, 5.735, 0.1, 1outa142.7.5 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-10


42.8 wgbowedbararwgbowedbar kamp, kfreq, kpos, kbowpres, kga<strong>in</strong>[, kconst, ktvel,kbowpos, ilow]42.8.1 DESCRIPTIONA physical model of a bowed bar, belong<strong>in</strong>g to the Perry Cook family of waveguide <strong>in</strong>struments.42.8.2 INITIALIZATIONilow (optional) – lowest frequency required42.8.3 PERFORMANCEkamp – amplitude of signalkfreq – frequency of signalkpos – position of the bow on the bar, <strong>in</strong> the range 0 to 1kbowpres – pressure of the bow (as <strong>in</strong> wgbowed)kga<strong>in</strong> – ga<strong>in</strong> of filter. A value of about 0.809 is suggested.kconst (optional) – an <strong>in</strong>tegration constant. Default is zero.ktvel (optional) – either 0 or 1. When ktvel = 0, the bow velocity follows an ADSR styletrajectory. When ktvel = 1, the value of the bow velocity decays <strong>in</strong> an exponentially.kbowpos (optional) – the position on the bow, which affects the bow velocity trajectory.42.8.4 EXAMPLE;orchestra ----------------<strong>in</strong>str 1; pos = [0, 1]; bowpress = [1, 10]; ga<strong>in</strong> = [0.8, 1]; <strong>in</strong>tr = [0,1]; trackvel = [0, 1]; bowpos = [0, 1]kb l<strong>in</strong>e 0.5, p3, 0.1kp l<strong>in</strong>e 0.6, p3, 0.7kc l<strong>in</strong>e 1, p3, 1a1 wgbowedbar p4, cpspch(p5), kb, kp, 0.995, p6, 0, kc, 50outend<strong>in</strong>a1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-11


;score -------------------i1 0 3 32000 7.00 0e42.8.5 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 4.07The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Waveguide Physical Model<strong>in</strong>g Page 42-12


43 SIGNAL GENERATORS: MODELS ANDEMULATIONS43.1 mooga1 moog kamp, kfreq, kfiltq, kfiltrate, kvibf, kvamp, iafn,\\iwfn, ivfn43.1.1 DESCRIPTIONAn emulation of a m<strong>in</strong>i-Moog synthesizer.43.1.2 INITIALIZATIONiafn, iwfn, ivfn – three table numbers conta<strong>in</strong><strong>in</strong>g the attack waveform (unlooped), the ma<strong>in</strong>loop<strong>in</strong>g wave form, and the vibrato waveform. The files mandpluk.aiff and impuls20.aiff aresuitable for the first two, and a s<strong>in</strong>e wave for the last.43.1.3 PERFORMANCEkamp – Amplitude of note.kfreq – Frequency of note played.kfiltq – Q of the filter, <strong>in</strong> the range 0.8 to 0.9kfiltrate - rate control for the filter <strong>in</strong> the range 0 to 0.0002kvibf – frequency of vibrato <strong>in</strong> Hertz. Suggested range is 0 to 12kvamp – amplitude of the vibrato43.1.4 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-1


43.2 shakerar shaker kamp, kfreq, kbeans, kdamp, ktimes[, idecay]43.2.1 DESCRIPTIONAudio output is a tone related to the shak<strong>in</strong>g of a maraca or similar gourd <strong>in</strong>strument. Themethod is a physically <strong>in</strong>spired model developed from Perry Cook, but re-coded for <strong>Csound</strong>.43.2.2 INITIALIZATIONidecay – If present <strong>in</strong>dicates for how long at the end of the note the shaker is to be damped. Thedefault value is zero.43.2.3 PERFORMANCEA note is played on a maraca-like <strong>in</strong>strument, with the arguments as below.kamp – Amplitude of note.kfreq – Frequency of note played.kbeans – The number of beans <strong>in</strong> the gourd. A value of 8 seems suitable,kdamp -- The damp<strong>in</strong>g value of the shaker. Values of 0.98 to 1 seems suitable, with 0.99 areasonable default.ktimes -- Number of times shaken.The argument knum was redundant, so was removed <strong>in</strong> version 3.49.43.2.4 EXAMPLEa1 shaker 31129.60, 440, 8, 0.999, 100, 0outs a1, a143.2.5 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-2


43.3 marimba, vibesar marimba kamp, kfreq, ihrd, ipos, imp, kvibf, kvamp, ivibfn, \\idec[, idoubles[, itriples]]ar vibes kamp, kfreq, ihrd, ipos, imp, kvibf, kvamp, ivibfn, \\idec43.3.1 DESCRIPTIONAudio output is a tone related to the strik<strong>in</strong>g of a wooden or metal block as found <strong>in</strong> a marimbaor vibraphone. The method is a physical model developed from Perry Cook, but re-coded for<strong>Csound</strong>.43.3.2 INITIALIZATIONihrd – the hardness of the stick used <strong>in</strong> the strike. A range of 0 to 1 is used. 0.5 is a suitablevalue.ipos – where the block is hit, <strong>in</strong> the range 0 to 1.imp – a table of the strike impulses. The file “marmstk1.wav” is a suitable function frommeasurements, and can be loaded with a GEN01 table.ivfn – shape of vibrato, usually a s<strong>in</strong>e table, created by a functionidec – time before end of note when damp<strong>in</strong>g is <strong>in</strong>troducedidoubles – percentage of double strikes. Default is 40%.itriples – percentage of triple strikes. Default is 20%.43.3.3 PERFORMANCEkamp – Amplitude of note.kfreq – Frequency of note played.kvibf – frequency of vibrato <strong>in</strong> Hertz. Suggested range is 0 to 12kvamp – amplitude of the vibrato43.3.4 EXAMPLEa1 marimba 31129.60, 440, 0.5, 0.561, 2, 6.0, 0.05, 1, 0.1a2 vibes 31129.60, 440, 0.5, 0.561, 2, 4.0, 0.2, 1, 0.1a1outs a1, a2The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-3


43.3.5 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-4


43.4 mandolar mandol kamp, kfreq, kpluck, kdetune, kga<strong>in</strong>, ksize, ifn\\[, im<strong>in</strong>freq]43.4.1 DESCRIPTIONAn emulation of a mandol<strong>in</strong>.43.4.2 INITIALIZATIONifn -- table number conta<strong>in</strong><strong>in</strong>g the pluck wave form. The file mandpluk.aiff is suitable for this.im<strong>in</strong>freq -- Lowest frequency to be played on the note. If it is omitted it is taken to be the sameas the <strong>in</strong>itial kfreq.43.4.3 PERFORMANCEkamp – Amplitude of note.kfreq – Frequency of note played.kpluck – The pluck position, <strong>in</strong> range 0 to 1. Suggest 0.4.kga<strong>in</strong> – the loopga<strong>in</strong> of the model, <strong>in</strong> the range 0.97 to 1.kdetune - The proportional detun<strong>in</strong>g between the two str<strong>in</strong>gs. Suggested range 1 and 0.9.ksize – The size of the body of the mandol<strong>in</strong>. Range 0 to 2.43.4.4 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-5


43.5 gogobelar gogobel kamp, kfreq, ihrd, ipos, imp, kvibf, kvamp, ivibfn43.5.1 DESCRIPTIONAudio output is a tone related to the strik<strong>in</strong>g of a cow bell or similar. The method is a physicalmodel developed from Perry Cook, but re-coded for <strong>Csound</strong>.43.5.2 INITIALIZATIONihrd -- the hardness of the stick used <strong>in</strong> the strike. A range of 0 to 1 is used. 0.5 is a suitablevalue.ipos -- where the block is hit, <strong>in</strong> the range 0 to 1.imp – a table of the strike impulses. The file “marmstk1.wav” is a suitable function frommeasurements, and can be loaded with a GEN01 table.ivfn – shape of vibrato, usually a s<strong>in</strong>e table, created by a function.43.5.3 PERFORMANCEA note is played on a cowbell-like <strong>in</strong>strument, with the arguments as below.kamp – Amplitude of note.kfreq – Frequency of note played.kvibf – frequency of vibrato <strong>in</strong> Hertz. Suggested range is 0 to 12kvamp - amplitude of the vibrato43.5.4 EXAMPLEa1 gogobel 31129.60, 440, p4, 0.561, 3, 6.0, 0.3, 1outs a1, a243.5.5 NAME CHANGEPrior to <strong>Csound</strong> version 3.52 (February, 1999), this opcode was called agogobel.43.5.6 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-6


43.6 voicear voice kamp, kfreq, kphoneme, kform, kvibf, kvamp, ifn, ivfn43.6.1 DESCRIPTIONAn emulation of a human voice.43.6.2 INITIALIZATIONifn, ivfn – two table numbers conta<strong>in</strong><strong>in</strong>g the carrier wave form and the vibrato waveform. Thefiles “impuls20.aiff”, “ahh.aiff”, “eee.aiff”, or “ooo.aiff” are suitable for the first of these, and as<strong>in</strong>e wave for the second. These files are available from:ftp://ftp.maths.bath.ac.uk/pub/dream/documentation/sounds/modell<strong>in</strong>g/43.6.3 PERFORMANCEkamp – Amplitude of note.kfreq – Frequency of note played. It can be varied <strong>in</strong> performance.kphoneme – an <strong>in</strong>teger <strong>in</strong> the range 0 to 16, which select the formants for the sounds:“eee”,”ihh”,”ehh”,”aaa”,“ahh”,”aww”,”ohh”,”uhh”,“uuu”,”ooo”,”rrr”,”lll”,“mmm”,”nnn”,”nng”,”ngg”.At present the phonemes“fff”,”sss”,”thh”,”shh”,“xxx”,”hee”,”hoo”,”hah”,“bbb”,”ddd”,”jjj”,”ggg”,“vvv”,”zzz”,”thz”,”zhh”are not available (!)kform – Ga<strong>in</strong> on the phoneme. values 0.0 to 1.2 recommended.kvibf – frequency of vibrato <strong>in</strong> Hertz. Suggested range is 0 to 12kvamp – amplitude of the vibrato43.6.4 AUTHORJohn ffitch (after Perry Cook)University of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-7


43.7 lorenzax, ay, lorenz ks, kr, kb, kh, ix, iy, iz, iskipaz43.7.1 DESCRIPTIONImplements the Lorenz system of equations. The Lorenz system is a chaotic-dynamic systemwhich was orig<strong>in</strong>ally used to simulate the motion of a particle <strong>in</strong> convection currents andsimplified weather systems. Small differences <strong>in</strong> <strong>in</strong>itial conditions rapidly lead to diverg<strong>in</strong>gvalues. This is sometimes expressed as the butterfly effect. If a butterfly flaps its w<strong>in</strong>gs <strong>in</strong>Australia, it will have an effect on the weather <strong>in</strong> Alaska. This system is one of the milestones <strong>in</strong>the development of chaos theory. It is useful as a chaotic audio source or as a low frequencymodulation source.43.7.2 INITIALIZATIONix, iy, iz – the <strong>in</strong>itial coord<strong>in</strong>ates of the particleiskip – used to skip generated values. If iskip is set to 5, only every fifth value generated isoutput. This is useful <strong>in</strong> generat<strong>in</strong>g higher pitched tones.43.7.3 PERFORMANCEksv – the Prandtl number or sigmakrv – the Rayleigh numberkbv – the ratio of the length and width of the box <strong>in</strong> which the convection currents are generatedkh – the step size used <strong>in</strong> approximat<strong>in</strong>g the differential equation. This can be used to control thepitch of the systems. Values of .1-.001 are typical.The equations are approximated as follows:x = x + h*(s*(y - x))y = y + h*(-x*z + r*x - y)z = z + h*(x*y - b*z)The historical values of these parameters are:ks = 10kr = 28kb = 8/3The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-8


43.7.4 EXAMPLEksv = p4krv = p5kbv = p6<strong>in</strong>str 20ax, ay, az lorenz ksv, krv, kbv, .01, .6, .6, .6, 1end<strong>in</strong>;score; start dur S R Vi20 5 1 10 28 2.667e43.7.5 AUTHORHans MikelsonFebruary 1999 (New <strong>in</strong> <strong>Csound</strong> version 3.53)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-9


43.8 planetax, ay, az planet kmass1, kmass2, ksep, ix, iy, iz, ivx, \\ivy, ivz, idelta, ifriction43.8.1 DESCRIPTIONplanet simulates a planet orbit<strong>in</strong>g <strong>in</strong> a b<strong>in</strong>ary star system. The outputs are the x, y and zcoord<strong>in</strong>ates of the orbit<strong>in</strong>g planet. It is possible for the planet to achieve escape velocity by aclose encounter with a star. This makes this system somewhat unstable.43.8.2 INITIALIZATIONix, iy, iz – the <strong>in</strong>itial x, y and z coord<strong>in</strong>ates of the planetivx, ivy, ivz – the <strong>in</strong>itial velocity vector components for the planet.idelta – the step size used to approximate the differential equation.ifriction – a value for friction, which can used to keep the system from blow<strong>in</strong>g up43.8.3 PERFORMANCEkmass1 – the mass of the first starkmass2 – the mass of the second starksep – determ<strong>in</strong>es the distance between the two starsax, ay, az – the output x, y, and z coord<strong>in</strong>ates of the planet43.8.4 EXAMPLE<strong>in</strong>str 1idur = p3iamp = p4km1 = p5km2 = p6ksep = p7ix = p8iy = p9iz = p10ivx = p11ivy = p12ivz = p13ih = p14ifric = p15kamp l<strong>in</strong>seg 0, .002, iamp, idur-.004, iamp, .002, 0ax,ay,az planetoutskm1, km2, ksep, ix, iy, iz, ivx, ivy, ivz, ih, ifricax*kamp, ay*kampend<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-10


; Sta Dur Amp M1 M2 Sep X Y Z VX VY VZ h Fricti1 0 1 5000 .5 .35 2.2 0 .1 0 .5 .6 -.1 .5 -0.1i1 + . . .5 0 0 0 .1 0 .5 .6 -.1 .5 0.1i1 . . . .4 .3 2 0 .1 0 .5 .6 -.1 .5 0.0i1 . . . .3 .3 2 0 .1 0 .5 .6 -.1 .5 0.1i1 . . . .25 .3 2 0 .1 0 .5 .6 -.1 .5 1.0i1 . . . .2 .5 2 0 .1 0 .5 .6 -.1 .1 1.043.8.5 AUTHORHans MikelsonDecember 1998New <strong>in</strong> <strong>Csound</strong> version 3.50The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-11


43.9 cabasa, crunch, sekere, sandpaper, stixar cabasa iamp, idettack[, knum, kdamp, kmaxshake]ar crunch iamp, idettack[, knum, kdamp, kmaxshake]ar sekere iamp, idettack[, knum, kdamp, kmaxshake]ar sandpaper iamp, idettack[, knum, kdamp, kmaxshake]ar stix iamp, idettack[, knum, kdamp, kmaxshake]43.9.1 DESCRIPTIONSemi-physical models of various percussion sounds.43.9.2 INITIALIZATIONiamp – Amplitude of output. Note: As these <strong>in</strong>struments are stochastic, this is only aapproximation.idettack – period of time over which all sound is stopped43.9.3 PERFORMANCEknum – The number of beads, teeth, bells, timbrels, etc. If, zero the default value is:cabasa = 512.0000crunch = 7.0000sekere = 64.0000sandpaper = 128.0000stix = 30.0000kdamp – the damp<strong>in</strong>g factor of the <strong>in</strong>strument. The value is used as an adjustment around thedefaults, with 1 be<strong>in</strong>g no damp<strong>in</strong>g. If zero, the default values are used. The defaults are:cabasa = 0.9970crunch = 0.99806sekere = 0.9990sandpaper = 0.9990stix = 0.9980kmaxshake – amount of energy to add back <strong>in</strong>to the system. The value should be <strong>in</strong> range 0 to 1.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-12


43.9.4 EXAMPLE;orchestra ---------------sr = 44100kr = 4410ksmps = 10nchnls = 1gknum <strong>in</strong>it 0 ;<strong>in</strong>itialize optional argumentsgkdamp <strong>in</strong>it 0 ; for use with all <strong>in</strong>strumentsgkmaxshake <strong>in</strong>it 0<strong>in</strong>str 01;an example of a cabasaa1 cabasa p4, 0.01, gknum, gkdamp, gkmaxshakeouta1end<strong>in</strong><strong>in</strong>str 02;an example of a cruncha1 crunch p4, 0.01, gknum, gkdamp, gkmaxshakeouta1end<strong>in</strong><strong>in</strong>str 03;an example of a sekerea1 sekere p4, 0.01, gknum, gkdamp, gkmaxshakeouta1end<strong>in</strong><strong>in</strong>str 04;an example of sandpaper blocksa1 l<strong>in</strong>e 2, p3, 2 ;preset amplitude <strong>in</strong>creasea2 sandpaper p4, 0.01, gknum, gkdamp, gkmaxshakea3 product a1, a2 ;<strong>in</strong>crease amplitudeouta3end<strong>in</strong><strong>in</strong>str 05;an example of stixa1 l<strong>in</strong>e 20, p3, 20 ;preset amplitude <strong>in</strong>creasea2 stix p4, 0.01, gknum, gkdamp, gkmaxshakea3 product a1, a2 ;<strong>in</strong>crease amplitudeouta3end<strong>in</strong>;score -------------------i1 0 1 26000i2 2 1 26000i3 4 1 26000i4 6 1 26000i5 8 1 26000e43.9.5 AUTHORJohn ffitchUniversity of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 4.07The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-13


43.10 guiro, tambour<strong>in</strong>e, bamboo, dripwater, sleighbellsar guiro iamp, idettack[, knum, kdamp, kmaxshake, kfreq, kfreq1]ar tambour<strong>in</strong>e iamp, idettack[, knum, kdamp, kmaxshake, kfreq, kfreq1,kfreq2]ar bamboo iamp, idettack[, knum, kdamp, kmaxshake, kfreq, kfreq1,kfreq2]ar dripwater iamp, idettack[, knum, kdamp, kmaxshake, kfreq, kfreq1,kfreq2]ar sleighbells iamp, idettack[, knum, kdamp, kmaxshake, kfreq, kfreq1,kfreq2]43.10.1 DESCRIPTIONSemi-physical models of various percussion sounds.43.10.2 INITIALIZATIONiamp – Amplitude of output. Note: As these <strong>in</strong>struments are stochastic, this is only aapproximation.idettack – period of time over which all sound is stopped43.10.3 PERFORMANCEknum – The number of beads, teeth, bells, timbrels, etc. If, zero the default value is:guiro = 128.0000tambour<strong>in</strong>e = 32.0000bamboo = 1.2500dripwater = 10.0000sleighbells = 32.0000kdamp – the damp<strong>in</strong>g factor of the <strong>in</strong>strument. The value is used as an adjustment around thedefaults, with 1 be<strong>in</strong>g no damp<strong>in</strong>g. If zero, the default values are used. The defaults are:guiro = 1.0000tambour<strong>in</strong>e = 0.9985bamboo = 0.9999dripwater = 0.9950sleighbells = 0.9994kmaxshake – amount of energy to add back <strong>in</strong>to the system. The value should be <strong>in</strong> range 0 to 1.kfreq – the ma<strong>in</strong> resonant frequency. The default values are:guiro = 2500.0000tambour<strong>in</strong>e = 2300.0000bamboo = 2800.0000dripwater = 450.0000sleighbells = 2500.0000kfreq1 – the first resonant frequency. The default values are:tambour<strong>in</strong>e = 5600.0000bamboo = 2240.0000dripwater = 600.0000sleighbells = 5300.0000The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-14


kfreq2 – the second resonant frequency. The default values are:tambour<strong>in</strong>e = 8100.0000bamboo = 3360.0000dripwater = 750.0000sleighbells = 6500.000043.10.4 EXAMPLE;orchestra ---------------sr = 44100kr = 4410ksmps = 10nchnls = 1<strong>in</strong>str 01;example of a guiroa1 guiro p4, 0.01outa1end<strong>in</strong><strong>in</strong>str 02;example of a tambour<strong>in</strong>ea1 tambour<strong>in</strong>e p4, 0.01outa1end<strong>in</strong><strong>in</strong>str 03;example of bambooa1 bamboo p4, 0.01outa1end<strong>in</strong><strong>in</strong>str 04;example of a water dripa1 l<strong>in</strong>e 5, p3, 5 ;preset an amplitude boosta2 dripwater p4, 0.01, 0, .9a3 product a1, a2 ;<strong>in</strong>crease amplitudeouta3end<strong>in</strong><strong>in</strong>str 05;an example of sleighbellsa1 sleighbells p4, 0.01outa1end<strong>in</strong>;score -------------------i1 0 1 20000i2 2 1 20000i3 4 1 20000i4 6 1 20000i5 8 1 20000e43.10.5 AUTHORJohn ffitchUniversity of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 4.07The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-15


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Models and Emulations Page 43-16


44 SIGNAL GENERATORS: STFT RESYNTHESIS(VOCODING)44.1 pvoc, vpvocar pvoc ktimpnt, kfmod, ifilcod [, ispecwp, iextractmode,\\ifreqlim, igatefn]ar vpvoc ktimpnt, kfmod, ifile[, ispecwp[, ifn]]44.1.1 DESCRIPTIONOutput is an additive set of <strong>in</strong>dividually controlled s<strong>in</strong>usoids, us<strong>in</strong>g phase vocoder resynthesis.44.1.2 INITIALIZATIONifilcod – <strong>in</strong>teger or character-str<strong>in</strong>g denot<strong>in</strong>g a control-file derived from analysis of an audiosignal. An <strong>in</strong>teger denotes the suffix of a file pvoc.m; a character-str<strong>in</strong>g (<strong>in</strong> double quotes) givesa filename, optionally a full pathname. If not fullpath, the file is sought first <strong>in</strong> the currentdirectory, then <strong>in</strong> the one given by the environment variable SADIR (if def<strong>in</strong>ed).pvoc controlconta<strong>in</strong>s breakpo<strong>in</strong>t amplitude and frequency envelope values organized for fft resynthesis.Memory usage depends on the size of the file <strong>in</strong>volved, which is read and held entirely <strong>in</strong>memory dur<strong>in</strong>g computation, but are shared by multiple calls (see also lpread).ispecwp (optional) – if non-zero, attempts to preserve the spectral envelope while its frequencycontent is varied by kfmod. The default value is zero.iextractmode (optional) – determ<strong>in</strong>es if spectral extraction will be carried out, and if so, whethercomponents that have changes <strong>in</strong> frequency below ifreqlim or above ifreqlim will be discarded.A value for iextractmode of 1 will cause pvadd to synthesize only those components where thefrequency difference between analysis frames is greater than ifreqlim. A value of 2 foriextractmode will cause pvadd to synthesize only those components where the frequencydifference between frames is less than ifreqlim. The default values for iextractmode and ifreqlimare 0, <strong>in</strong> which case a simple resynthesis will be done. See examples under pvadd for how to usespectral extraction.igatefn – is the number of a stored function which will be applied to the amplitudes of theanalysis b<strong>in</strong>s before resynthesis takes place. If igatefn is greater than 0, the amplitudes of eachb<strong>in</strong> will be scaled by igatefn through a simple mapp<strong>in</strong>g process. First, the amplitudes of all of theb<strong>in</strong>s <strong>in</strong> all of the frames <strong>in</strong> the entire analysis file are compared to determ<strong>in</strong>e the maximumamplitude value. This value is then used create normalized amplitudes as <strong>in</strong>deces <strong>in</strong>to the storedfunction igatefn. The maximum amplitude will map to the last po<strong>in</strong>t <strong>in</strong> the function. Anamplitude of 0 will map to the first po<strong>in</strong>t <strong>in</strong> the function. Values between 0 and 1 will mapaccord<strong>in</strong>gly to po<strong>in</strong>ts along the function table. See examples under pvadd for how to useamplitude gat<strong>in</strong>g.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) Page 44-1


ifn (optional) – optional function table conta<strong>in</strong><strong>in</strong>g control <strong>in</strong>formation for vpvoc. If ifn = 0,control is derived <strong>in</strong>ternally from a previous tableseg or tablexseg unit. Default is 0. (New <strong>in</strong><strong>Csound</strong> version 3.59)44.1.3 PERFORMANCEpvoc implements signal reconstruction us<strong>in</strong>g an fft-based phase vocoder. The control data stemsfrom a precomputed analysis file with a known frame rate. The passage of time through this fileis specified by ktimpnt, which represents the time <strong>in</strong> seconds. ktimpnt must always be positive,but can move forwards or backwards <strong>in</strong> time, be stationary or discont<strong>in</strong>uous, as a po<strong>in</strong>ter <strong>in</strong>to theanalysis file. kfmod is a control-rate transposition factor: a value of 1 <strong>in</strong>curs no transposition, 1.5transposes up a perfect fifth, and .5 down an octave.This implementation of pvoc was orignally written by Dan Ellis. It is based <strong>in</strong> part on the systemof Mark Dolson, but the pre-analysis concept is new. The spectral extraction and amplitudegat<strong>in</strong>g (new <strong>in</strong> <strong>Csound</strong> version 3.56) were added by Richard Karpen based on functions <strong>in</strong>SoundHack by Tom Erbe.vpvoc is identical to pvoc except that it takes the result of a previous tableseg, tablexseg anduses the result<strong>in</strong>g function table (passed <strong>in</strong>ternally to the vpvoc), as an envelope over themagnitudes of the analysis data channels. Optionally, a table specified by ifn, may be used. Theresult is spectral envelop<strong>in</strong>g. The function size used <strong>in</strong> the tableseg should be framesize/2, whereframesize is the number of b<strong>in</strong>s <strong>in</strong> the phase vocoder analysis file that is be<strong>in</strong>g used by thevpvoc. Each location <strong>in</strong> the table will be used to scale a s<strong>in</strong>gle analysis b<strong>in</strong>. By us<strong>in</strong>g differentfunctions for ifn1, ifn2, etc.. <strong>in</strong> the tableseg, the spectral envelope becomes a dynamicallychang<strong>in</strong>g one. See also tableseg and tablexseg.44.1.4 EXAMPLEThe follow<strong>in</strong>g example us<strong>in</strong>g vpvoc, shows the use of functions such asf 1 0 256 5 .001 128 1 128 .001f 2 0 256 5 1 128 .001 128 1f 3 0 256 7 1 256 1to scale the amplitudes of the separate analysis b<strong>in</strong>s.ktime l<strong>in</strong>e 0, p3,3 ; time po<strong>in</strong>ter, <strong>in</strong> seconds, <strong>in</strong>to filetablexseg 1, p3*.5, 2, p3*.5, 3apv vpvoc ktime,1, “pvoc.file”The result would be a time-vary<strong>in</strong>g “spectral envelope” applied to the phase vocoder analysisdata. S<strong>in</strong>ce this amplifies or attenuates the amount of signal at the frequencies that are pairedwith the amplitudes which are scaled by these functions, it has the effect of apply<strong>in</strong>g veryaccurate filters to the signal. In this example the first table would have the effect of a band- passfilter , gradually be band-rejected over half the note’s duration, and then go towards nomodification of the magnitudes over the second half.44.1.5 AUTHORSDan Ellis (pvoc)Richard Karpen (vpvoc)Seattle, Washngton1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) Page 44-2


44.2 pvread, pvbufread, pv<strong>in</strong>terp, pvcross, tableseg,tablexsegkfr, kamp pvread ktimpnt, ifile, ib<strong>in</strong>pvbufread ktimpnt, ifilear pv<strong>in</strong>terp ktimpnt, kfmod, ifile, kfreqscale1, kfreqscale2,\\kampscale1, kampscale2, kfreq<strong>in</strong>terp, kamp<strong>in</strong>terpar pvcross ktimpnt, kfmod, ifile, kamp1, kamp2[, ispecwp]tableseg ifn1, idur1, ifn2[, idur2, ifn3[...]]tablexseg ifn1, idur1, ifn2[, idur2, ifn3[...]]44.2.1 DESCRIPTIONpvread reads from a pvoc file and returns the frequency and amplitude from a s<strong>in</strong>gle analysischannel or b<strong>in</strong>. The returned values can be used anywhere else <strong>in</strong> the <strong>Csound</strong> <strong>in</strong>strument. Forexample, one can use them as arguments to an oscillator to synthesize a s<strong>in</strong>gle component froman analyzed signal or a bank of pvreads can be used to resynthesize the analyzed sound us<strong>in</strong>gadditive synthesis by pass<strong>in</strong>g the frequency and magnitude values to a bank of oscillators.pvbufread reads from a pvoc file and makes the retrieved data available to any follow<strong>in</strong>gpv<strong>in</strong>terp and pvcross units that appear <strong>in</strong> an <strong>in</strong>strument before a subsequent pvbufread (just aslpread and lpreson work together). The data is passed <strong>in</strong>ternally and the unit has no output of itsown. pv<strong>in</strong>terp and pvcross allow the <strong>in</strong>terprocess<strong>in</strong>g of two phase vocoder analysis files prior tothe resynthesis which these units do also. Both of these units receive data from one of the filesfrom a previously called pvbufread unit. The other file is read by the pv<strong>in</strong>terp and/or pvcrossunits. S<strong>in</strong>ce each of these units has its own time-po<strong>in</strong>ter the analysis files can be read at differentspeeds and directions from one another. pv<strong>in</strong>terp does not allow for the use of the ispecwpprocess as with the pvoc and vpvoc units.pv<strong>in</strong>terp <strong>in</strong>terpolates between the amplitudes and frequencies, on a b<strong>in</strong> by b<strong>in</strong> basis, of twophase vocoder analysis files (one from a previously called pvbufread unit and the other fromwith<strong>in</strong> its own argument list), allow<strong>in</strong>g for user def<strong>in</strong>ed transitions between analyzed sounds. Italso allows for general scal<strong>in</strong>g of the amplitudes and frequencies of each file separately beforethe <strong>in</strong>terpolated values are calculated and sent to the resynthesis rout<strong>in</strong>es. The kfmod argument <strong>in</strong>pv<strong>in</strong>terp performs its frequency scal<strong>in</strong>g on the frequency values after their derivation from theseparate scal<strong>in</strong>g and subsequent <strong>in</strong>terpolation is performed so that this acts as an overall scal<strong>in</strong>gvalue of the new frequency components.pvcross applies the amplitudes from one phase vocoder analysis file to the data from a secondfile and then performs the resynthesis. The data is passed, as described above, from a previouslycalled pvbufread unit. The two k-rate amplitude arguments are used to scale the amplitudes ofeach files separately before they are added together and used <strong>in</strong> the resynthesis (see below forfurther explanation). The frequencies of the first file are not used at all <strong>in</strong> this process. This unitsimply allows for cross-synthesis through the application of the amplitudes of the spectra of onesignal to the frequencies of a second signal. Unlike pv<strong>in</strong>terp, pvcross does allow for the use ofthe ispecwp as <strong>in</strong> pvoc and vpvoc.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) Page 44-3


tableseg and tablexseg are like l<strong>in</strong>seg and expseg but <strong>in</strong>terpolate between values <strong>in</strong> a storedfunction tables. The result is a new function table passed <strong>in</strong>ternally to any follow<strong>in</strong>g vpvocwhich occurs before a subsequent tableseg or tablexseg (much like lpread/lpreson pairs work).The uses of these are described below under vpvoc.44.2.2 INITIALIZATIONifile – the pvoc number (n <strong>in</strong> pvoc.n) or the name <strong>in</strong> quotes of the analysis file made us<strong>in</strong>gpvanal. (See pvoc.)ib<strong>in</strong> – the number of the analysis channel from which to return frequency <strong>in</strong> Hz and magnitude.ifn1, ifn2, ifn3, etc. – function table numbers for tableseg and tablexseg. ifn1, ifn2, and so on,must be the same size.idur1, idur2, etc. – durations for tableseg and tablexseg, dur<strong>in</strong>g which <strong>in</strong>terpolation from onetable to the next will take place.44.2.3 PERFORMANCEkfreq, kamp – outputs of the pvread unit. These values, retrieved from a phase vocoder analysisfile, represent the values of frequency and amplitude from a s<strong>in</strong>gle analysis channel specified <strong>in</strong>the ib<strong>in</strong> argument. Interpolation between analysis frames is performed at k-rate resolution anddependent of course upon the rate and direction of ktimpnt.ktimpnt, kfmod, ispecwp – used for pvread exactly the same as for pvoc (see above descriptionof pv<strong>in</strong>terp for its special use of kfmod).kfreqscale1, kfreqscale2, kampscale1, kampscale2 – used <strong>in</strong> pv<strong>in</strong>terp to scale the frequenciesand amplitudes stored <strong>in</strong> each frame of the phase vocoder analysis file. kfreqscale1 andkampscale1 scale the frequencies and amplitudes of the data from the file read by the previouslycalled pvbufread (this data is passed <strong>in</strong>ternally to the pv<strong>in</strong>terp unit). kfreqscale2 and kampscale2scale the frequencies and amplitudes of the file named by ifile <strong>in</strong> the pv<strong>in</strong>terp argument list andread with<strong>in</strong> the pv<strong>in</strong>terp unit. By us<strong>in</strong>g these arguments it is possible to adjust these valuesbefore apply<strong>in</strong>g the <strong>in</strong>terpolation. For example, if file1 is much louder than file2, it might bedesirable to scale down the amplitudes of file1 or scale up those of file2 before <strong>in</strong>terpolat<strong>in</strong>g.Likewise one can adjust the frequencies of each to br<strong>in</strong>g them more <strong>in</strong> accord with one another(or just the opposite, of course!) before the <strong>in</strong>terpolation is performed.kfreq<strong>in</strong>terp, kamp<strong>in</strong>terp – used <strong>in</strong> pv<strong>in</strong>terp to determ<strong>in</strong>e the <strong>in</strong>terpolation distance between thevalues of one phase vocoder file and the values of a second file. When the value of kfreq<strong>in</strong>terp is0, the frequency values will be entirely those from the first file (read by the pvbufread), postscal<strong>in</strong>g by the kfreqscale1 argument. When the value of kfreq<strong>in</strong>terp is 1 the frequency values willbe those of the second file (read by the pv<strong>in</strong>terp unit itself), post scal<strong>in</strong>g by kfreqscale2. Whenkfreq<strong>in</strong>terp is between 0 and 1 the frequency values will be calculated, on a b<strong>in</strong>, by b<strong>in</strong> basis, asthe percentage between each pair of frequencies (<strong>in</strong> other words, kfreq<strong>in</strong>terp=.5 will cause thefrequencies values to be half way between the values <strong>in</strong> the set of data from the first file and theset of data from the second file). kamp<strong>in</strong>terp1 and kamp<strong>in</strong>terp2 work <strong>in</strong> the same way upon theamplitudes of the two files. S<strong>in</strong>ce these are k-rate arguments, the percentages can change overtime mak<strong>in</strong>g it possible to create many k<strong>in</strong>ds of transitions between sounds.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) Page 44-4


44.2.4 EXAMPLEThe example below shows the use pvread to synthesize a s<strong>in</strong>gle component from a phasevocoder analysis file. It should be noted that the kfreq and kamp outputs can be used for any k<strong>in</strong>dof synthesis, filter<strong>in</strong>g, process<strong>in</strong>g, and so on.ktime l<strong>in</strong>e 0, p3, 3kfreq, kamp pvread ktime, “pvoc.file”, 7 ; read;data from 7th analysis b<strong>in</strong>.asig oscili kamp, kfreq, 1 ; function 1;is a stored s<strong>in</strong>eThe example below shows an example us<strong>in</strong>g pvbufread with pv<strong>in</strong>terp to <strong>in</strong>terpolate betweenthe sound of an oboe and the sound of a clar<strong>in</strong>et. The value of k<strong>in</strong>terp returned by a l<strong>in</strong>seg is usedto determ<strong>in</strong>e the tim<strong>in</strong>g of the transitions between the two sounds. The <strong>in</strong>terpolation offrequencies and amplitudes are controlled by the same factor <strong>in</strong> this example, but for othereffects it might be <strong>in</strong>terest<strong>in</strong>g to not have them synchronized <strong>in</strong> this way. In this example thesound will beg<strong>in</strong> as a clar<strong>in</strong>et, transform <strong>in</strong>to the oboe and then return aga<strong>in</strong> to the clar<strong>in</strong>et sound.The value of kfreqscale2 is 1.065 because the oboe <strong>in</strong> this case is a semitone higher <strong>in</strong> pitch thanthe clar<strong>in</strong>et and this br<strong>in</strong>gs them approximately to the same pitch. The value of kampscale2 is .75because the analyzed clar<strong>in</strong>et was somewhat louder than the analyzed oboe. The sett<strong>in</strong>g of thesetwo parameters make the transition quite smooth <strong>in</strong> this case, but such adjustments are by nomeans necessary or even advocated.ktime1 l<strong>in</strong>e 0, p3, 3.5 ; used as <strong>in</strong>dex <strong>in</strong> the “oboe.pvoc” filektime2 l<strong>in</strong>e 0, p3, 4.5 ; used as <strong>in</strong>dex <strong>in</strong> the “clar.pvoc” filek<strong>in</strong>terp l<strong>in</strong>seg 1, p3*.15, 1, p3*.35, 0, p3*.25, 0, p3*.15, 1, p3*.1, 1pvbufread ktime1, “oboe.pvoc”apv pv<strong>in</strong>terp ktime2,1,”clar.pvoc”,1,1.065,1,.75,1-k<strong>in</strong>terp,1-k<strong>in</strong>terpBelow is an example us<strong>in</strong>g pvbufread with pvcross. In this example the amplitudes used <strong>in</strong> theresynthesis gradually change from those of the oboe to those of the clar<strong>in</strong>et. The frequencies, ofcourse, rema<strong>in</strong> those of the clar<strong>in</strong>et throughout the process s<strong>in</strong>ce pvcross does not use thefrequency data from the file read by pvbufread.ktime1 l<strong>in</strong>e 0, p3, 3.5 ; used as <strong>in</strong>dex <strong>in</strong> the “oboe.pvoc” filektime2 l<strong>in</strong>e 0, p3, 4.5 ; used as <strong>in</strong>dex <strong>in</strong> the “clar.pvoc” filekcross expon .001, p3, 1pvbufread ktime1, “oboe.pvoc”apv pvcross ktime2, 1, “clar.pvoc”, 1-kcross, kcross44.2.5 AUTHORRichard KarpenSeattle, Wash1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) Page 44-5


44.3 pvaddar pvadd ktimpnt, kfmod, ifilcod, ifn, ib<strong>in</strong>s[, ib<strong>in</strong>offset, \\ib<strong>in</strong><strong>in</strong>cr, iextractmode, ifreqlim, igatefn]44.3.1 DESCRIPTIONpvadd reads from a pvoc file and uses the data to perform additive synthesis us<strong>in</strong>g an <strong>in</strong>ternalarray of <strong>in</strong>terpolat<strong>in</strong>g oscillators. The user supplies the wave table (usually one period of a s<strong>in</strong>ewave), and can choose which analysis b<strong>in</strong>s will be used <strong>in</strong> the re-synthesis.44.3.2 INITIALIZATIONifilcod – <strong>in</strong>teger or character-str<strong>in</strong>g denot<strong>in</strong>g a control-file derived from analysis of an audiosignal. An <strong>in</strong>teger denotes the suffix of a file pvoc.m; a character-str<strong>in</strong>g (<strong>in</strong> double quotes) givesa filename, optionally a full pathname. If not fullpath, the file is sought first <strong>in</strong> the currentdirectory, then <strong>in</strong> the one given by the environment variable SADIR (if def<strong>in</strong>ed). pvoc controlfiles conta<strong>in</strong> data organized for fft resynthesis. Memory usage depends on the size of the files<strong>in</strong>volved, which are read and held entirely <strong>in</strong> memory dur<strong>in</strong>g computation but are shared bymultiple calls (see also lpread).ifn – table number of a stored function conta<strong>in</strong><strong>in</strong>g a s<strong>in</strong>e waveib<strong>in</strong>s – number of b<strong>in</strong>s that will be used <strong>in</strong> the resynthesis (each b<strong>in</strong> counts as one oscillator <strong>in</strong>the re-synthesis)ib<strong>in</strong>offset (optional) – is the first b<strong>in</strong> used (it is optional and defaults to 0).ib<strong>in</strong><strong>in</strong>cr (optional) – sets an <strong>in</strong>crement by which pvadd counts up from ib<strong>in</strong>offset for ib<strong>in</strong>scomponents <strong>in</strong> the re-synthesis (see below for a further explanation).iextractmode (optional) – determ<strong>in</strong>es if spectral extraction will be carried out and if so whethercomponents that have changes <strong>in</strong> frequency below ifreqlim or above ifreqlim will be discarded.A value for iextractmode of 1 will cause pvadd to synthesize only those components where thefrequency difference between analysis frames is greater than ifreqlim. A value of 2 foriextractmode will cause pvadd to synthesize only those components where the frequencydifference between frames is less than ifreqlim. The default values for iextractmode and ifreqlimare 0, <strong>in</strong> which case a simple resynthesis will be done. See examples below.igatefn (optional) – is the number of a stored function which will be applied to the amplitudes ofthe analysis b<strong>in</strong>s before resynthesis takes place. If igatefn is greater than 0 the amplitudes ofeach b<strong>in</strong> will be scaled by igatefn through a simple mapp<strong>in</strong>g process. First, the amplitudes of allof the b<strong>in</strong>s <strong>in</strong> all of the frames <strong>in</strong> the entire analysis file are compared to determ<strong>in</strong>e the maximumamplitude value. This value is then used create normalized amplitudes as <strong>in</strong>deces <strong>in</strong>to the storedfunction igatefn. The maximum amplitude will map to the last po<strong>in</strong>t <strong>in</strong> the function. Anamplitude of 0 will map to the first po<strong>in</strong>t <strong>in</strong> the function. Values between 0 and 1 will mapaccord<strong>in</strong>gly to po<strong>in</strong>ts along the function table.This will be made clearer <strong>in</strong> the examples below.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) Page 44-6


44.3.3 PERFORMANCEktimpnt and kfmod are used <strong>in</strong> the same way as <strong>in</strong> pvoc.44.3.4 EXAMPLESktime l<strong>in</strong>e 0, p3, p3asig pvadd ktime, 1, “oboe.pvoc”, 1, 100, 2In the above, ib<strong>in</strong>s is 100 and ib<strong>in</strong>offset is 2. Us<strong>in</strong>g these sett<strong>in</strong>gs the resynthesis will conta<strong>in</strong> 100components beg<strong>in</strong>n<strong>in</strong>g with b<strong>in</strong> #2 (b<strong>in</strong>s are counted start<strong>in</strong>g with 0). That is, resynthesis will bedone us<strong>in</strong>g b<strong>in</strong>s 2-101 <strong>in</strong>clusive. It is usually a good idea to beg<strong>in</strong> with b<strong>in</strong> 1 or 2 s<strong>in</strong>ce the 0thand often 1st b<strong>in</strong> have data that is neither necessary nor even helpful for creat<strong>in</strong>g good cleanresynthesis.ktime l<strong>in</strong>e 0, p3, p3asig pvadd ktime, 1, “oboe.pvoc”, 1, 100, 2, 2The above is the same as the previous example with the addition of the value 2 used for theoptional ib<strong>in</strong><strong>in</strong>cr argument. This result will still result <strong>in</strong> 100 components <strong>in</strong> the resynthesis, butpvadd will count through the b<strong>in</strong>s by 2 <strong>in</strong>stead of by 1. It will use b<strong>in</strong>s 2, 4, 6, 8, 10, and so on.For ib<strong>in</strong>s=10, ib<strong>in</strong>offset=10, and ib<strong>in</strong><strong>in</strong>cr=10, pvadd would use b<strong>in</strong>s 10, 20, 30, 40, up to and<strong>in</strong>clud<strong>in</strong>g 100.Below is an example us<strong>in</strong>g spectral extraction. In this example iextractmode is one and ifreqlimis 9. This will cause pvadd to synthesize only those b<strong>in</strong>s where the frequency deviation, averagedover 6 frames, is greater than 9.ktime l<strong>in</strong>e 0, p3, p3asig pvadd ktime, 1, "oboe.pvoc", 1, 100, 2, 2, 1, 9If iextractmode were 2 <strong>in</strong> the above, then only those b<strong>in</strong>s with an average frequency deviation ofless than 9 would be synthesized. If tuned correctly, this technique can be used to separate thepitched parts of the spectrum from the noisy parts. In practice, this depends greatly on the type ofsound, the quality of the record<strong>in</strong>g and digitization, and also on the analysis w<strong>in</strong>dow size andframe <strong>in</strong>crement.Next is an example us<strong>in</strong>g amplitude gat<strong>in</strong>g. The last 2 <strong>in</strong> the argument list stands for f2 <strong>in</strong> thescore.asig pvadd ktime, 1, “oboe.pvoc”, 1, 100, 2, 2, 0, 0, 2Suppose the score for the above were to conta<strong>in</strong>:f2 0 512 7 0 256 1 256 1Then those b<strong>in</strong>s with amplitudes of 50% of the maximum or greater would be left unchanged,while those with amplitudes less than 50% of the maximum would be scaled down. In this casethe lower the amplitude the more severe the scal<strong>in</strong>g down would be. But suppose the scoreconta<strong>in</strong>s:f2 0 512 5 1 512 .001In this case, lower amplitudes will be left unchanged and greater ones will be scaled down,turn<strong>in</strong>g the sound “upside-down” <strong>in</strong> terms of the amplitude spectrum! Functions can bearbitrarily complex. Just remember that the normalized amplitude values of the analysis arethemselves the <strong>in</strong>deces <strong>in</strong>to the function.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) Page 44-7


F<strong>in</strong>ally, both spectral extraction and amplitude gat<strong>in</strong>g can be used together. The example belowwill synthesize only those components that with a frequency deviation of less than 5Hz per frameand it will scale the amplitudes accord<strong>in</strong>g to F2.asig pvadd ktime, 1, “oboe.pvoc”, 1, 100, 1, 1, 2, 5, 244.3.5 USEFUL HINTS:By us<strong>in</strong>g several pvadd units together, one can gradually fade <strong>in</strong> different parts of theresynthesis, creat<strong>in</strong>g various “filter<strong>in</strong>g” effects. The author uses pvadd to synthesis one b<strong>in</strong> at atime to have control over each separate component of the re-synthesis.If any comb<strong>in</strong>ation of ib<strong>in</strong>s, ib<strong>in</strong>offset, and ib<strong>in</strong><strong>in</strong>cr, creates a situation where pvadd is asked toused a b<strong>in</strong> number greater than the number of b<strong>in</strong>s <strong>in</strong> the analysis, it will just use all of theavailable b<strong>in</strong>s, and give no compla<strong>in</strong>t. So to use every b<strong>in</strong> just make ib<strong>in</strong>s a big number (i.e.2000).Expect to have to scale up the amplitudes by factors of 10-100, by the way.44.3.6 AUTHORRichard KarpenSeattle, Wash1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48, additional arguments version 3.56)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: STFT Resynthesis (Vocod<strong>in</strong>g) Page 44-8


45 SIGNAL GENERATORS: LPC RESYNTHESIS45.1 lpread, lpreson, lpfresonkrmsr,krmso,lpread ktimpnt, ifilcod[, <strong>in</strong>poles[, ifrmrate]]kerr,kcpsarlpreson asigar lpfreson asig, kfrqratio45.1.1 DESCRIPTIONThese units, used as a read/reson pair, use a control file of time-vary<strong>in</strong>g filter coefficients todynamically modify the spectrum of an audio signal.45.1.2 INITIALIZATIONifilcod – <strong>in</strong>teger or character-str<strong>in</strong>g denot<strong>in</strong>g a control-file (reflection coefficients and fourparameter values) derived from n-pole l<strong>in</strong>ear predictive spectral analysis of a source audio signal.An <strong>in</strong>teger denotes the suffix of a file lp.m; a character-str<strong>in</strong>g (<strong>in</strong> double quotes) gives afilename, optionally a full pathname. If not fullpath, the file is sought first <strong>in</strong> the currentdirectory, then <strong>in</strong> that of the environment variable SADIR (if def<strong>in</strong>ed). Memory usage dependson the size of the file, which is held entirely <strong>in</strong> memory dur<strong>in</strong>g computation but shared bymultiple calls (see also adsyn, pvoc).<strong>in</strong>poles, ifrmrate (optional) – number of poles, and frame rate per second <strong>in</strong> the lpc analysis.These arguments are required only when the control file does not have a header; they are ignoredwhen a header is detected. The default value for both is zero.45.1.3 PERFORMANCElpread accesses a control file of time-ordered <strong>in</strong>formation frames, each conta<strong>in</strong><strong>in</strong>g n-pole filtercoefficients derived from l<strong>in</strong>ear predictive analysis of a source signal at fixed time <strong>in</strong>tervals (e.g.1/100 of a second), plus four parameter values:krmsr - root-mean-square (rms) of the residual of analysis,krmso - rms of the orig<strong>in</strong>al signal,kerr - the normalized error signal,kcps - pitch <strong>in</strong> Hz.lpread gets its values from the control file accord<strong>in</strong>g to the <strong>in</strong>put value ktimpnt (<strong>in</strong> seconds). Ifktimpnt proceeds at the analysis rate, time-normal synthesis will result; proceed<strong>in</strong>g at a faster,slower, or variable rate will result <strong>in</strong> time-warped synthesis. At each k-period, lpread<strong>in</strong>terpolates between adjacent frames to more accurately determ<strong>in</strong>e the parameter values(presented as output) and the filter coefficient sett<strong>in</strong>gs (passed <strong>in</strong>ternally to a subsequentlpreson).The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: LPC Resynthesis Page 45-1


The error signal kerr (between 0 and 1) derived dur<strong>in</strong>g predictive analysis reflects thedeterm<strong>in</strong>istic/random nature of the analyzed source. This will emerge low for pitched (periodic)material and higher for noisy material. The transition from voiced to unvoiced speech, forexample, produces an error signal value of about .001. Dur<strong>in</strong>g synthesis, the error signal valuecan be used to determ<strong>in</strong>e the nature of the lpreson driv<strong>in</strong>g function: for example, by arbitrat<strong>in</strong>gbetween pitched and non-pitched <strong>in</strong>put, or even by determ<strong>in</strong><strong>in</strong>g a mix of the two. In normalspeech resynthesis, the pitched <strong>in</strong>put to lpreson is a wideband periodic signal or pulse tra<strong>in</strong>derived from a unit such as buzz, and the non-pitched source is usually derived from rand.However, any audio signal can be used as the driv<strong>in</strong>g function, the only assumption of theanalysis be<strong>in</strong>g that it has a flat response.lpfreson is a formant shifted lpreson, <strong>in</strong> which kfrqratio is the (Hz) ratio of shifted to orig<strong>in</strong>alformant positions. This permits synthesis <strong>in</strong> which the source object changes its apparentacoustic size. lpfreson with kfrqratio = 1 is equivalent to lpreson.Generally, lpreson provides a means whereby the time-vary<strong>in</strong>g content and spectral shap<strong>in</strong>g of acomposite audio signal can be controlled by the dynamic spectral content of another. There canbe any number of lpread/lpreson (or lpfreson) pairs <strong>in</strong> an <strong>in</strong>strument or <strong>in</strong> an orchestra; theycan read from the same or different control files <strong>in</strong>dependently.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: LPC Resynthesis Page 45-2


45.2 lpslot, lp<strong>in</strong>terplpslotlp<strong>in</strong>terpolislotislot1, islot2, kmix45.2.1 DESCRIPTIONInterpolate between two lpc analysis files.45.2.2 INITIALIZATIONislot – number of slot to be selected [0


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: LPC Resynthesis Page 45-4


46 SIGNAL GENERATORS: RANDOM (NOISE)GENERATORS46.1 rand, randh, randikr rand xamp [, iseed[, isize[, ioffset]]]kr randh kamp, kcps[, iseed[, isize[, ioffset]]]kr randi kamp, kcps[, iseed[, isize[, ioffset]]]ar rand xamp [, iseed[, isize[, ioffset]]]ar randh xamp, xcps[, iseed[, isize[, ioffset]]]ar randi xamp, xcps[, iseed[, isize[, ioffset]]]46.1.1 DESCRIPTIONOutput is a controlled random number series between +amp and -amp46.1.2 INITIALIZATIONiseed (optional) – seed value for the recursive pseudo-random formula. A value between 0 and+1 will produce an <strong>in</strong>itial output of kamp * iseed. A value greater than 1 will be used directly,without scal<strong>in</strong>g. A negative value will cause seed re-<strong>in</strong>itialization to be skipped. The default seedvalue is .5.isize – if zero, a 16 bit number is generated. If non-zero, a 31-bit random number is generated.Default is 0.46.1.3 PERFORMANCEkoffset (optional) – a base value added to the random result. New <strong>in</strong> <strong>Csound</strong> version 4.03.The <strong>in</strong>ternal pseudo-random formula produces values which are uniformly distributed over therange kamp to -kamp. rand will thus generate uniform white noise with an RMS value of kamp /root 2.The rema<strong>in</strong><strong>in</strong>g units produce band-limited noise: the cps parameters permit the user to specifythat new random numbers are to be generated at a rate less than the sampl<strong>in</strong>g or controlfrequencies. randh will hold each new number for the period of the specified cycle; randi willproduce straight-l<strong>in</strong>e <strong>in</strong>terpolation between each new number and the next.46.1.4 EXAMPLEi1 = octpch(p5) ; center pitch, to be modifiedk1 randh 1,10 ;10 time/sec by random displacements up to 1 octavea1 oscil 5000, cpsoct(i1+k1), 1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Random (Noise) Generators Page 46-1


46.2 x-class noise generatorsir l<strong>in</strong>rand krangekr l<strong>in</strong>rand krangear l<strong>in</strong>rand krangeir trirand krangekr trirand krangear trirand krangeir exprand krangekr exprand krangear exprand krangeir bexprnd krangekr bexprnd krangear bexprnd krangeir cauchy kalphakr cauchy kalphaar cauchy kalphair pcauchy kalphakr pcauchy kalphaar pcauchy kalphair poisson klambdakr poisson klambdaar poisson klambdair gauss krangekr gauss krangear gauss krangeir weibull ksigma, ktaukr weibull ksigma, ktauar weibull ksigma, ktauir betarand krange, kalpha, kbetakr betarand krange, kalpha, kbetaar betarand krange, kalpha, kbetair unirand krangekr unirand krangear unirand krange46.2.1 DESCRIPTIONAll of the follow<strong>in</strong>g opcodes operate <strong>in</strong> i-, k- and a-rate.l<strong>in</strong>rand krange – L<strong>in</strong>ear distribution random number generator. krange is the range of therandom numbers (0 – krange). Outputs only positive numbers.trirand krange – Same as above only outputs both negative and positive numbers.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Random (Noise) Generators Page 46-2


exprand krange – Exponential distribution random number generator. krange is the range of therandom numbers (0 – krange). Outputs only positive numbers.bexprnd krange – Same as above, only extends to negative numbers too with an exponentialdistribution.cauchy kalpha -Cauchy distribution random number generator. kalpha controls the spread fromzero (big kalpha = big spread). Outputs both positive and negative numbers.pcauchy kalpha – Same as above, outputs positive numbers only.poisson klambda – Poisson distribution random number generator. klambda is the mean of thedistribution. Outputs only positive numbers.gauss krange – Gaussian distribution random number generator. krange is the range of therandom numbers (-krange – 0 – krange). Outputs both positive and negative numbers.weibull ksigma, ktau – Weibull distribution random number generator. ksigma scales the spreadof the distribution and ktau, if greater than one numbers near ksigma are favored, if smaller thanone small values are favored and if t equals 1 the distribution is exponential. Outputs onlypositive numbers.betarand krange, kalpha, kbeta – Beta distribution random number generator. krange is therange of the random numbers (0 – krange). If kalpha is smaller than one, smaller values favorvalues near 0. If kbeta is smaller than one, smaller values favor values near krange. If bothkalpha and kbeta equal one we have uniform distribution. If both kalpha and kbeta are greaterthan one we have a sort of Gaussian distribution. Outputs only positive numbers.unirand krange – Uniform distribution random number generator. krange is the range of therandom numbers (0 – krange).For more detailed explanation of these distributions, see:1. C. Dodge – T.A. Jerse 1985. Computer music. Schirmer books. pp.265 – 2862. D. Lorra<strong>in</strong>. A panoply of stochastic cannons. In C. Roads, ed. 1989. Music mach<strong>in</strong>e . Cambridge,Massachusetts: MIT press, pp. 351 – 379.46.2.2 EXAMPLEa1 trirand 32000 ; Audio noise with triangle distributionk1 cauchy 10000 ; Control noise with Cauchy dist.i1 betarand 30000, .5, .5 ; i-time random value, beta dist.46.2.3 DEPRECATED NAMESThese opcode names orig<strong>in</strong>ally started with i, k, or a to denote the rate at which the opcodeoperated. These names are deprecated as of <strong>Csound</strong> version 3.49. The current form should nowbe used; the previous form will not work.46.2.4 AUTHORParis SmaragdisMIT, Cambridge1995The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Random (Noise) Generators Page 46-3


46.3 p<strong>in</strong>kishar p<strong>in</strong>kish x<strong>in</strong>[, imethod, <strong>in</strong>umbands, iseed, iskip]DescriptionGenerates approximate p<strong>in</strong>k noise (-3dB/oct response) by one of two different methods:• a multirate noise generator after Moore, coded by Mart<strong>in</strong> Gardner• a filter bank designed by Paul Kellet46.3.1 INITIALIZATIONimethod (optional) – selects filter method:• 0 = Gardner method (default).• 1 = Kellet filter bank.• 2 = A somewhat faster filter bank by Kellet, with less accurate response.<strong>in</strong>umbands (optional) – only effective with Gardner method. The number of noise bands togenerate. Maximum is 32, m<strong>in</strong>imum is 4. Higher levels give smoother spectrum, but above 20bands there will be almost DC-like slow fluctuations. Default value is 20.iseed (optional) – only effective with Gardner method. If non-zero, seeds the random generator.If zero, the generator will be seeded from current time. Default is 0.iskip (optional) – if non-zero, skip (re)<strong>in</strong>itialization of <strong>in</strong>ternal state (useful for tied notes).Default is 0.46.3.2 PERFORMANCEx<strong>in</strong> – for Gardner method: k- or a-rate amplitude. For Kellet filters: normally a-rate uniformrandom noise from rand (31-bit) or unirand, but can be any a-rate signal. The output peak valuevaries widely (±15%) even over long runs, and will usually be well below the <strong>in</strong>put amplitude.Peak values may also occasionally overshoot <strong>in</strong>put amplitude or noise.p<strong>in</strong>kish attempts to generate p<strong>in</strong>k noise (i.e., noise with equal energy <strong>in</strong> each octave), by one oftwo different methods.The first method, by Moore & Gardner, adds several (up to 32) signals of white noise, generatedat octave rates (sr, sr/2, sr/4 etc). It obta<strong>in</strong>s pseudo-random values from an <strong>in</strong>ternal 32-bitgenerator. This random generator is local to each opcode <strong>in</strong>stance and seedable (similar to rand).The second method is a lowpass filter with a response approximat<strong>in</strong>g -3dB/oct. If the <strong>in</strong>put isuniform white noise, it outputs p<strong>in</strong>k noise. Any signal may be used as <strong>in</strong>put for this method. Thehigh quality filter is slower, but has less ripple and a slightly wider operat<strong>in</strong>g frequency rangethan less computationally <strong>in</strong>tense versions. With the Kellet filters, seed<strong>in</strong>g is not used.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Random (Noise) Generators Page 46-4


The Gardner method output has some frequency response anomalies <strong>in</strong> the low-mid and highmidfrequency ranges. More low-frequency energy can be generated by <strong>in</strong>creas<strong>in</strong>g the number ofbands. It is also a bit faster. The ref<strong>in</strong>ed Kellet filter has very smooth spectrum, but a morelimited effective range. The level <strong>in</strong>creases slightly at the high end of the spectrum.46.3.3 EXAMPLEKellet-filtered noise for a tied note (iskip is non-zero).<strong>in</strong>str 1awhite unirand 2.0awhite = awhite - 1.0 ; Normalize to +/-1.0ap<strong>in</strong>k p<strong>in</strong>kish awhite, 1, 0, 0, 1out ap<strong>in</strong>k * 30000end<strong>in</strong>46.3.4 AUTHORSPhil BurkeJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKMay, 2000 (New <strong>in</strong> <strong>Csound</strong> version 4.06)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Random (Noise) Generators Page 46-5


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Generators: Random (Noise) Generators Page 46-6


47 FUNCTION TABLE CONTROL: TABLEQUERIES47.1 ftlen, ftlptim, ftsr, nsampftlen(x)ftlptim(x)ftsr(x)nsamp(x)(<strong>in</strong>it-rate args only)(<strong>in</strong>it-rate args only)(<strong>in</strong>it-rate args only)(<strong>in</strong>it-rate args only)47.1.1 DESCRIPTIONWhere the argument with<strong>in</strong> the parentheses may be an expression. These value converters return<strong>in</strong>formation about a stored function table. The result can be a term <strong>in</strong> a further expression.47.1.2 PERFORMANCEftlen(x) – returns the size (number of po<strong>in</strong>ts, exclud<strong>in</strong>g guard po<strong>in</strong>t) of stored function tablenumber x. While most units referenc<strong>in</strong>g a stored table will automatically take its size <strong>in</strong>toaccount (so tables can be of arbitrary length), this function reports the actual size, if that isneeded. Note that ftlen will always return a power-of-2 value, i.e. the function table guard po<strong>in</strong>t(see f Statement) is not <strong>in</strong>cluded. As of <strong>Csound</strong> version 3.53, ftlen works with deferred functiontables (see GEN01).ftlptim(x) - returns the loop segment start-time (<strong>in</strong> seconds) of stored function table number x.This reports the duration of the direct recorded attack and decay parts of a sound sample, priorto its looped segment. Returns zero (and a warn<strong>in</strong>g message) if the sample does not conta<strong>in</strong>loop po<strong>in</strong>ts.ftsr(x) – returns the sampl<strong>in</strong>g-rate of a GEN01 or GEN22 generated table. The sampl<strong>in</strong>g-rate isdeterm<strong>in</strong>ed from the header of the orig<strong>in</strong>al file. If the orig<strong>in</strong>al file has no header, or the table wasnot created by these two GENs ftsr returns 0. New <strong>in</strong> <strong>Csound</strong> version 3.49.nsamp(x) – returns the number of samples loaded <strong>in</strong>to stored function table number x by GEN01or GEN23. This is useful when a sample is shorter than the power-of-two function table thatholds it. New <strong>in</strong> <strong>Csound</strong> version 3.49.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Table Queries Page 47-1


47.1.3 AUTHORSBarry VercoeMITCambridge, Massachusetts1997Gabriel Maldonado (ftsr, nsamp)ItalyOctober, 1998The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Table Queries Page 47-2


47.2 tablengir tableng ifnkr tableng kfn47.2.1 DESCRIPTIONInterrogates a function table for length.47.2.2 INITIALIZATIONifn – Table number to be <strong>in</strong>terrogated47.2.3 PERFORMANCEkfn – Table number to be <strong>in</strong>terrogatedtableng returns the length of the specified table. This will be a power of two number <strong>in</strong> mostcircumstances. It will not show whether a table has a guardpo<strong>in</strong>t or not. It seems this <strong>in</strong>formationis not available <strong>in</strong> the table’s data structure. If the specified table is not found, then 0 will bereturned.Likely to be useful for sett<strong>in</strong>g up code for table manipulation operations, such as tablemix andtablecopy.47.2.4 NAME CHANGESAs of <strong>Csound</strong> version 3.52, the name of the opcode itablegpw has been changed to tableng.47.2.5 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Table Queries Page 47-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Table Queries Page 47-4


48 FUNCTION TABLE CONTROL: TABLESELECTION48.1 tablekt, tableiktkr tablekt kndx, kfn[, ixmode[, ixoff[, iwrap]]]ar tablekt xndx, kfn[, ixmode[, ixoff[, iwrap]]]kr tableikt kndx, kfn[, ixmode[, ixoff[, iwrap]]]ar tableikt xndx, kfn[, ixmode[, ixoff[, iwrap]]]48.1.1 DESCRIPTIONk-rate control over table numbers.The standard <strong>Csound</strong> opcodes table and tablei, when produc<strong>in</strong>g a k- or a-rate result, can onlyuse an <strong>in</strong>it-time variable to select the table number. tablekt and tableikt accept k-rate control aswell as i-time. In all other respects they are similar to the orig<strong>in</strong>al opcodes.48.1.2 INITIALIZATION<strong>in</strong>dx – Index <strong>in</strong>to table, either a positive number rangeifn – Table number. Must be >= 1. Floats are rounded down to an <strong>in</strong>teger. If a table number doesnot po<strong>in</strong>t to a valid table, or the table has not yet been loaded (GEN01) then an error will resultand the <strong>in</strong>strument will be de-activated.ixmode – if 0, xndx and ixoff ranges match the length of the table. if non-zero xndx and ixoff havea 0 to 1 range. Default is 0ixoff – if 0, total <strong>in</strong>dex is controlled directly by xndx, i.e. the <strong>in</strong>dex<strong>in</strong>g starts from the start of thetable. If non-zero, start <strong>in</strong>dex<strong>in</strong>g from somewhere else <strong>in</strong> the table. Value must be positive andless than the table length (ixmode = 0) or less than 1 (ixmode !=0). Default is 0.iwrap – if iwrap = 0, Limit mode: when total <strong>in</strong>dex is below 0, then f<strong>in</strong>al <strong>in</strong>dex is 0.Total <strong>in</strong>dexabove table length results <strong>in</strong> a f<strong>in</strong>al <strong>in</strong>dex of the table length – high out of range total <strong>in</strong>dexesstick at the upper limit of the table. If iwrap !=0, Wrap mode: total <strong>in</strong>dex is wrapped modulo thetable length so that all total <strong>in</strong>dexes map <strong>in</strong>to the table. For <strong>in</strong>stance, <strong>in</strong> a table of length 8, xndx =5 and ixoff = 6 gives a total <strong>in</strong>dex of 11, which wraps to a f<strong>in</strong>al <strong>in</strong>dex of 3. Default is 0.48.1.3 PERFORMANCEkndx – Index <strong>in</strong>to table, either a positive number rangexndx – match<strong>in</strong>g the table length (ixmode = 0) or a 0 to 1 range (ixmode != 0)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Table Selection Page 48-1


kfn – Table number. Must be >= 1. Floats are rounded down to an <strong>in</strong>teger. If a table numberdoes not po<strong>in</strong>t to a valid table, or the table has not yet been loaded (GEN01) then an error willresult and the <strong>in</strong>strument will be de-activated.48.1.4 AUTHORRob<strong>in</strong> WhittleAustralia1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Table Selection Page 48-2


49 FUNCTION TABLE CONTROL: READ/WRITEOPERATIONS49.1 tableiw, tablew, tablewkttableiwtablewtablewtablewkttablewktisig, <strong>in</strong>dx, ifn[, ixmode[, ixoff[, iwgmode]]]ksig, kndx, ifn[, ixmode[, ixoff[, iwgmode]]]asig, andx, ifn[, ixmode[, ixoff[, iwgmode]]]ksig, kndx, kfn[, ixmode[, ixoff[, iwgmode]]]asig, andx, kfn[, ixmode[, ixoff[, iwgmode]]]49.1.1 DESCRIPTIONThese opcodes operate on exist<strong>in</strong>g function tables, chang<strong>in</strong>g their contents. tableiw is used whenall <strong>in</strong>puts are <strong>in</strong>it time variables or constants and you only want to run it at the <strong>in</strong>itialization ofthe <strong>in</strong>strument. tablew is for writ<strong>in</strong>g at k- or at a-rates, with the table number be<strong>in</strong>g specified at<strong>in</strong>it time. tablewkt is the same, but uses a k-rate variable for select<strong>in</strong>g the table number. Thevalid comb<strong>in</strong>ations of variable types are shown by the first letter of the variable names.49.1.2 INITIALIZATIONisig, ksig, asig- The value to be written <strong>in</strong>to the table.<strong>in</strong>dx, kndx, andx – Index <strong>in</strong>to table, either a positive number range match<strong>in</strong>g the table length(ixmode = 0) or a 0 to 1 range (ixmode != 0)ifn, kfn – Table number. Must be = 1. Floats are rounded down to an <strong>in</strong>teger. If a table numberdoes not po<strong>in</strong>t to a valid table, or the table has not yet been loaded (GEN01) then an error willresult and the <strong>in</strong>strument will be de-activated.ixmode – Default is 0.• 0 : xndx and ixoff ranges match the length of the table.• !=0 : xndx and ixoff have a 0 to 1 range.ixoff – Default is 0.• 0: Total <strong>in</strong>dex is controlled directly by xndx. i.e. the <strong>in</strong>dex<strong>in</strong>g starts from the start of the table.• !=0: Start <strong>in</strong>dex<strong>in</strong>g from somewhere else <strong>in</strong> the table. Value must be positive and less thanthe table length (ixmode = 0) or less than 1 (ixmode !=0).iwgmode – Default is 0.• 0: Limit mode• 1: Wrap mode• 2: Guardpo<strong>in</strong>t mode.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Read/Write Operations Page 49-1


49.1.3 PERFORMANCE49.1.3.1 Limit mode (0)Limit the total <strong>in</strong>dex (ndx + ixoff) to between 0 and the guard po<strong>in</strong>t. For a table of length 5, thismeans that locations 0 to 3 and location 4 (the guard po<strong>in</strong>t) can be written. A negative total <strong>in</strong>dexwrites to location 0. Total <strong>in</strong>dexes 4 write to location 4.49.1.3.2 Wrap mode (1)Wrap total <strong>in</strong>dex value <strong>in</strong>to locations 0 to E, where E is one less than either the table length orthe factor of 2 number which is one less than the table length. For example, wrap <strong>in</strong>to a 0 to 3range – so that total <strong>in</strong>dex 6 writes to location 2.49.1.3.3 Guardpo<strong>in</strong>t mode (2)The guardpo<strong>in</strong>t is written at the same time as location 0 is written – with the same value.This facilitates writ<strong>in</strong>g to tables which are <strong>in</strong>tended to be read with <strong>in</strong>terpolation for produc<strong>in</strong>gsmooth cyclic waveforms. In addition, before it is used, the total <strong>in</strong>dex is <strong>in</strong>cremented by half therange between one location and the next, before be<strong>in</strong>g rounded down to the <strong>in</strong>teger address of atable location.Normally (igwmode = 0 or 1) for a table of length 5 – which has locations 0 to 3 as the ma<strong>in</strong>table and location 4 as the guard po<strong>in</strong>t, a total <strong>in</strong>dex <strong>in</strong> the range of 0 to 0.999 will write tolocation 0. (“0.999” means just less than 1.0.) 1.0 to 1.999 will write to location 1, etc. A similarpattern holds for all total <strong>in</strong>dexes 0 to 4.999 (igwmode = 0) or to 3.999 (igwmode = 1). igwmode= 0 enables locations 0 to 4 to be written – with the guardpo<strong>in</strong>t (4) be<strong>in</strong>g written with apotentially different value from location 0.With a table of length 5 and the iwgmode = 2, then when the total <strong>in</strong>dex is <strong>in</strong> the range 0 to0.499, it will write to locations 0 and 4. Range 0.5 to 1.499 will write to location 1 etc. 3.5 to 4.0will also write to locations 0 and 4.This way, the writ<strong>in</strong>g operation most closely approximates the results of <strong>in</strong>terpolated read<strong>in</strong>g.Guard po<strong>in</strong>t mode should only be used with tables that have a guardpo<strong>in</strong>t.Guardpo<strong>in</strong>t mode is accomplished by add<strong>in</strong>g 0.5 to the total <strong>in</strong>dex, round<strong>in</strong>g to the next lowest<strong>in</strong>teger, wrapp<strong>in</strong>g it modulo the factor of two which is one less than the table length, writ<strong>in</strong>g thetable (locations 0 to 3 <strong>in</strong> our example) and then writ<strong>in</strong>g to the guard po<strong>in</strong>t if <strong>in</strong>dex == 0.tablew has no output value. The last three parameters are optional and have default values of 0.49.1.3.4 Caution with k-rate table numbers :The follow<strong>in</strong>g notes also apply to the tablekt and tableikt opcodes which can now have theirtable number changed at k-rate.At k-rate or a-rate, if a table number of < 1 is given, or the table number po<strong>in</strong>ts to a non-existenttable, or to one which has a length of 0 (it is to be loaded from a file later) then an error willresult and the <strong>in</strong>strument will be deactivated. kfn and afn must be <strong>in</strong>itialized at the appropriaterate us<strong>in</strong>g <strong>in</strong>it. Attempt<strong>in</strong>g to load an i-rate value <strong>in</strong>to kfn or afn will result <strong>in</strong> an error.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Read/Write Operations Page 49-2


49.1.4 CHANGED NAMEAs of <strong>Csound</strong> version 3.52, the opcode name itablew is changed to tableiw.49.1.5 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Read/Write Operations Page 49-3


49.2 tablegpw, tablemix, tablecopy, tableigpw, tableimix,tableicopytablegpw kfntablemix kdft, kdoff, klen, ks1ft, ks1off, ks1g, ks2ft, \\ks2off, ks2gtablecopy kdft, ksfttableigpw ifntableimix idft, idoff, ilen, is1ft, is1off, is1g, is2ft, \\is2off, is2gtableicopy idft, isft49.2.1 DESCRIPTIONThese opcodes allow tables to be copied and mixed.49.2.2 INITIALIZATIONifn – Function table number49.2.3 PERFORMANCEkfn – Function table numberkdft – Dest<strong>in</strong>ation function table numberkdoff – Offset to start writ<strong>in</strong>g from. Can be negative.kdft – Number of dest<strong>in</strong>ation function table.ksft – Number of source function table.klen – Number of write operations to perform. Negative means work backwards.ks1ft, ks2ft – Source function tables. These can be the same as the dest<strong>in</strong>ation table, if care isexercised about direction of copy<strong>in</strong>g data.ks1off, ks2off –Offsets to start read<strong>in</strong>g from <strong>in</strong> source tables.ks1g, ks2g – Ga<strong>in</strong>s to apply when read<strong>in</strong>g from the source tables. The results are added and thesum is written to the dest<strong>in</strong>ation table.tablgpw – For writ<strong>in</strong>g the table’s guard po<strong>in</strong>t, with the value which is <strong>in</strong> location 0. Doesnoth<strong>in</strong>g if table does not exist.Likely to be useful after manipulat<strong>in</strong>g a table with tablemix or tablecopy.tablemix – This opcode mixes from two tables, with separate ga<strong>in</strong>s <strong>in</strong>to the dest<strong>in</strong>ation table.Writ<strong>in</strong>g is done for klen locations, usually stepp<strong>in</strong>g forward through the table – if klen is positive.If it is negative, then the writ<strong>in</strong>g and read<strong>in</strong>g order is backwards – towards lower <strong>in</strong>dexes <strong>in</strong> thetables. This bi-directional option makes it easy to shift the contents of a table sideways byread<strong>in</strong>g from it and writ<strong>in</strong>g back to it with a different offset.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Read/Write Operations Page 49-4


If klen is 0, no writ<strong>in</strong>g occurs. Note that the <strong>in</strong>ternal <strong>in</strong>teger value of klen is derived from theANSI C floor() function – which returns the next most negative <strong>in</strong>teger. Hence a fractionalnegative klen value of -2.3 would create an <strong>in</strong>ternal length of 3, and cause the copy<strong>in</strong>g to startfrom the offset locations and proceed for two locations to the left.The total <strong>in</strong>dex for table read<strong>in</strong>g and writ<strong>in</strong>g is calculated from the start<strong>in</strong>g offset for each table,plus the <strong>in</strong>dex value, which starts at 0 and then <strong>in</strong>crements (or decrements) by 1 as mix<strong>in</strong>gproceeds.These total <strong>in</strong>dexes can potentially be very large, s<strong>in</strong>ce there is no restriction on the offset or theklen. However each total <strong>in</strong>dex for each table is ANDed with a length mask (such as 0000 0111for a table of length 8) to form a f<strong>in</strong>al <strong>in</strong>dex which is actually used for read<strong>in</strong>g or writ<strong>in</strong>g. So noread<strong>in</strong>g or writ<strong>in</strong>g can occur outside the tables. This is the same as “wrap” mode <strong>in</strong> table readand write. These opcodes do not read or write the guardpo<strong>in</strong>t. If a table has been rewritten withone of these, then if it has a guardpo<strong>in</strong>t which is supposed to conta<strong>in</strong> the same value as thelocation 0, then call tablegpw afterwards.The <strong>in</strong>dexes and offsets are all <strong>in</strong> table steps – they are not normalized to 0 – 1. So for a table oflength 256, klen should be set to 256 if all the table was to be read or written.The tables do not need to be the same length – wrapp<strong>in</strong>g occurs <strong>in</strong>dividually for each table.tablecopy – Simple, fast table copy opcodes. Takes the table length from the dest<strong>in</strong>ation table,and reads from the start of the source table. For speed reasons, does not check the source length –just copies regardless – <strong>in</strong> “wrap” mode. This may read through the source table several times. Asource table with length 1 will cause all values <strong>in</strong> the dest<strong>in</strong>ation table to be written to its value.tablecopy cannot read or write the guardpo<strong>in</strong>t. To read it use table, with ndx = the table length.Likewise use table write to write it.To write the guardpo<strong>in</strong>t to the value <strong>in</strong> location 0, use tablegpw.This is primarily to change function tables quickly <strong>in</strong> a real-time situation.49.2.4 NAME CHANGESAs of <strong>Csound</strong> version 3.52, the names of the opcodes itablegpw, itablemix, and itablecopy,have been changed to tableigpw, tableimix, and tableicopy, respectively.49.2.5 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Read/Write Operations Page 49-5


49.3 tablera, tablewaar tablera kfn, kstart, koffkstart tablewa kfn, asig, koff49.3.1 DESCRIPTIONThese opcodes read and write tables <strong>in</strong> sequential locations to and from an a-rate variable. Somethought is required before us<strong>in</strong>g them. They have at least two major, and quite different,applications which are discussed below.49.3.2 INITIALIZATIONar – a-rate dest<strong>in</strong>ation for read<strong>in</strong>g ksmps values from a table.kfn – i- or k-rate number of the table to read or write.kstart – Where <strong>in</strong> table to read or write.asig – a-rate signal to read from when writ<strong>in</strong>g to the table.koff – i- or k-rate offset <strong>in</strong>to table. Range unlimited – see explanation at end of this section.49.3.3 PERFORMANCEIn one application, these are <strong>in</strong>tended to be used <strong>in</strong> pairs, or with several tablera opcodes beforea tablewa – all shar<strong>in</strong>g the same kstart variable.These read from and write to sequential locations <strong>in</strong> a table at audio rates, with ksmps floatsbe<strong>in</strong>g written and read each cycle.tablera starts read<strong>in</strong>g from location kstart. tablewa starts writ<strong>in</strong>g to location kstart, and thenwrites to kstart with the number of the location one more than the one it last wrote. (Note that fortablewa, kstart is both an <strong>in</strong>put and output variable.) If the writ<strong>in</strong>g <strong>in</strong>dex reaches the end of thetable, then no further writ<strong>in</strong>g occurs and zero is written to kstart.For <strong>in</strong>stance, if the table’s length was 16 (locations 0 to 15), and ksmps was 5. Then thefollow<strong>in</strong>g steps would occur with repetitive runs of the tablewa opcode, assum<strong>in</strong>g that kstartstarted at 0.Run no. Initial F<strong>in</strong>al locations writtenkstart kstart1 0 5 0 1 2 3 42 5 10 5 6 7 8 93 10 15 10 11 12 13 144 15 0 15This is to facilitate process<strong>in</strong>g table data us<strong>in</strong>g standard a-rate orchestra code between thetablera and tablewa opcodes. They allow all <strong>Csound</strong> k-rate operators to be used (with caution)on a-rate variables – someth<strong>in</strong>g that would only be possible otherwise by ksmps = 1, downsampand upsamp.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Read/Write Operations Page 49-6


Several cautions:•The k-rate code <strong>in</strong> the process<strong>in</strong>g loop is really runn<strong>in</strong>g at a-rate, so time dependantfunctions like port and oscil work faster than normal – their code is expect<strong>in</strong>g to berunn<strong>in</strong>g at k-rate.•This system will produce undesirable results unless the ksmps fits with<strong>in</strong> the table length.For <strong>in</strong>stance a table of length 16 will accommodate 1 to 16 samples, so this example willwork with ksmps = 1 to 16.Both these opcodes generate an error and deactivate the <strong>in</strong>strument if a table with length


The above example shows a process<strong>in</strong>g loop, which runs every k-cycle, read<strong>in</strong>g each location <strong>in</strong>the table ktabsource, and writ<strong>in</strong>g the log of those values <strong>in</strong>to the same locations of table ktabdest.This enables whole tables, parts of tables (with offsets and different control loops) and data fromseveral tables at once to be manipulated with a-rate code and written back to another (or to thesame) table. This is a bit of a fudge, but it is faster than do<strong>in</strong>g it with k-rate table read and writecode.Another application is:kzero = 0kloop = 0kzero tablewa 23, asignal, 0 ; ksmps a-rate samples written; <strong>in</strong>to locations 0 to (ksmps -1) of table 23.lab1: ktemp table kloop, 23 ; Start a loop which runs ksmps times,; <strong>in</strong> which each cycle processes one of[ Some code to manipulate ] ; table 23’s values with k-rate orchestra[ the value of ktemp. ] ; code.tablew ktemp, kloop, 23kloop = kloop + 1if kloop < ksmps goto lab1; Write the processed value to the table.; Increment the kloop, which is both the; po<strong>in</strong>ter <strong>in</strong>to the table and the loop; counter. Keep loop<strong>in</strong>g until all values; <strong>in</strong> the table have been processed.asignal tablera 23, 0, 0 ; Copy the table contents back; to an a-rate variable.koff – This is an offset which is added to the sum of kstart and the <strong>in</strong>ternal <strong>in</strong>dex variable whichsteps through the table. The result is then ANDed with the lengthmask (000 0111 for a table oflength 8 – or 9 with guardpo<strong>in</strong>t) and that f<strong>in</strong>al <strong>in</strong>dex is used to read or write to the table. koff canbe any value. It is converted <strong>in</strong>to a long us<strong>in</strong>g the ANSI floor() function so that -4.3 becomes -5.This is what we would want when us<strong>in</strong>g offsets which range above and below zero.Ideally this would be an optional variable, default<strong>in</strong>g to 0, however with the exist<strong>in</strong>g <strong>Csound</strong>orchestra read code, such default parameters must be <strong>in</strong>it time only. We want k-rate here, so wecannot have a default.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Function Table Control: Read/Write Operations Page 49-8


50 SIGNAL MODIFIERS: STANDARD FILTERS50.1 port, portk, tone, tonek, atone, atonek, reson, resonk,areson, aresonkkr port ksig, ihtim[, isig]kr portk ksig, khtim[, isig]kr tonek ksig, khp[, iskip]kr atonek ksig, khp[, iskip]kr resonk ksig, kcf, kbw[, iscl, iskip]kr aresonk ksig, kcf, kbw[, iscl, iskip]ar tone asig, khp[, iskip]ar atone asig, khp[, iskip]ar reson asig, kcf, kbw[, iscl, iskip]ar areson asig, kcf, kbw[, iscl, iskip]50.1.1 DESCRIPTIONA control or audio signal is modified by a low- or band-pass recursive filter with variablefrequency response.50.1.2 INITIALIZATIONisig – <strong>in</strong>itial (i.e. previous) value for <strong>in</strong>ternal feedback. The default value is 0.iskip – <strong>in</strong>itial disposition of <strong>in</strong>ternal data space. S<strong>in</strong>ce filter<strong>in</strong>g <strong>in</strong>corporates a feedback loop ofprevious output, the <strong>in</strong>itial status of the storage space used is significant. A zero value will clearthe space; a non-zero value will allow previous <strong>in</strong>formation to rema<strong>in</strong>. The default value is 0.iscl – coded scal<strong>in</strong>g factor for resonators. A value of 1 signifies a peak response factor of 1, i.e.all frequencies other than kcf are attenuated <strong>in</strong> accordance with the (normalized) response curve.A value of 2 raises the response factor so that its overall RMS value equals 1. (This <strong>in</strong>tendedequalization of <strong>in</strong>put and output power assumes all frequencies are physically present; hence it ismost applicable to white noise.) A zero value signifies no scal<strong>in</strong>g of the signal, leav<strong>in</strong>g that tosome later adjustment ( see balance). The default value is 0.50.1.3 PERFORMANCEport applies portamento to a step-valued control signal. At each new step value, ksig is low-passfiltered to move towards that value at a rate determ<strong>in</strong>ed by ihtim. ihtim is the “half-time” of thefunction (<strong>in</strong> seconds), dur<strong>in</strong>g which the curve will traverse half the distance towards the newvalue, then half as much aga<strong>in</strong>, etc., theoretically never reach<strong>in</strong>g its asymptote. With portk, thehalf-time can be varied at the control rate.tone implements a first-order recursive low-pass filter <strong>in</strong> which the variable khp (<strong>in</strong> Hz)determ<strong>in</strong>es the response curve’s half-power po<strong>in</strong>t. Half power is def<strong>in</strong>ed as peak power / root 2.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-1


eson is a second-order filter <strong>in</strong> which kcf controls the center frequency, or frequency position ofthe peak response, and kbw controls its bandwidth (the frequency difference between the upperand lower half-power po<strong>in</strong>ts).atone, areson are filters whose transfer functions are the complements of tone and reson. atoneis thus a form of high-pass filter and areson a notch filter whose transfer functions represent the“filtered out” aspects of their complements. Note, however, that power scal<strong>in</strong>g is not normalized<strong>in</strong> atone, areson, but rema<strong>in</strong>s the true complement of the correspond<strong>in</strong>g unit. Thus an audiosignal, filtered by parallel match<strong>in</strong>g reson and areson units, would under addition simplyreconstruct the orig<strong>in</strong>al spectrum. This property is particularly useful for controlled mix<strong>in</strong>g ofdifferent sources ( see lpreson). Complex response curves such as those with multiple peaks canbe obta<strong>in</strong>ed by us<strong>in</strong>g a bank of suitable filters <strong>in</strong> series. (The resultant response is the product ofthe component responses.) In such cases, the comb<strong>in</strong>ed attenuation may result <strong>in</strong> a serious loss ofsignal power, but this can be rega<strong>in</strong>ed by the use of balance.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-2


50.2 tonex, atonex, resonxar tonex asig, khp[, <strong>in</strong>umlayer, iskip]ar atonex asig, khp[, <strong>in</strong>umlayer, iskip]ar resonx asig, kcf, kbw[, <strong>in</strong>umlayer, iscl, iskip]50.2.1 DESCRIPTIONtonex, atonex and resonx are equivalent to filters consist<strong>in</strong>g of more layers of tone, atone andreson, with the same arguments, serially connected. Us<strong>in</strong>g a stack of a larger number of filtersallows a sharper cutoff. They are faster than us<strong>in</strong>g a larger number <strong>in</strong>stances <strong>in</strong> a <strong>Csound</strong>orchestra of the old opcodes, because only one <strong>in</strong>itialization and ‘k’ cycle are needed at time, andthe audio loop falls entirely <strong>in</strong>side the cache memory of processor.50.2.2 INITIALIZATION<strong>in</strong>umlayer – number of elements <strong>in</strong> the filter stack.. Default value is 4.iskip – <strong>in</strong>itial disposition of <strong>in</strong>ternal data space. S<strong>in</strong>ce filter<strong>in</strong>g <strong>in</strong>corporates a feedback loop ofprevious output, the <strong>in</strong>itial status of the storage space used is significant. A zero value will clearthe space; a non-zero value will allow previous <strong>in</strong>formation to rema<strong>in</strong>. The default value is 0.iscl – coded scal<strong>in</strong>g factor for resonators. A value of 1 signifies a peak response factor of 1, i.e.all frequencies other than kcf are attenuated <strong>in</strong> accordance with the (normalized) response curve.A value of 2 raises the response factor so that its overall RMS value equals 1. (This <strong>in</strong>tendedequalization of <strong>in</strong>put and output power assumes all frequencies are physically present; hence it ismost applicable to white noise.) A zero value signifies no scal<strong>in</strong>g of the signal, leav<strong>in</strong>g that tosome later adjustment ( see balance). The default value is 0.50.2.3 PERFORMANCEasig – <strong>in</strong>put signalkhp – the response curve’s half-power po<strong>in</strong>t. Half power is def<strong>in</strong>ed as peak power / root 2.kcf – the center frequency of the filter, or frequency position of the peak response.kbw – bandwidth of the filter (the Hz difference between the upper and lower half-power po<strong>in</strong>ts)50.2.4 AUTHORGabriel Maldonado (adapted by John ffitch)ItalyNew <strong>in</strong> <strong>Csound</strong> version 3.49The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-3


50.3 resonr, resonzar resonr asig, kcf, kbw[,iscl, iskip]ar resonz asig, kcf, kbw[,iscl, iskip]50.3.1 DESCRIPTIONImplementations of a second-order, two-pole two-zero bandpass filter with variable frequencyresponse.50.3.2 INITIALIZATIONThe optional <strong>in</strong>itialization variables for resonr and resonz are identical to the i-time variables forreson.iskip – <strong>in</strong>itial disposition of <strong>in</strong>ternal data space. S<strong>in</strong>ce filter<strong>in</strong>g <strong>in</strong>corporates a feedback loop ofprevious output, the <strong>in</strong>itial status of the storage space used is significant. A zero value will clearthe space; a non-zero value will allow previous <strong>in</strong>formation to rema<strong>in</strong>. The default value is 0.iscl – coded scal<strong>in</strong>g factor for resonators. A value of 1 signifies a peak response factor of 1, i.e.all frequencies other than kcf are attenuated <strong>in</strong> accordance with the (normalized) response curve.A value of 2 raises the response factor so that its overall RMS value equals 1. This <strong>in</strong>tendedequalization of <strong>in</strong>put and output power assumes all frequencies are physically present; hence it ismost applicable to white noise. A zero value signifies no scal<strong>in</strong>g of the signal, leav<strong>in</strong>g that tosome later adjustment (see balance). The default value is 0.50.3.3 PERFORMANCEresonr and resonz are variations of the classic two-pole bandpass resonator (reson). Both filtershave two zeroes <strong>in</strong> their transfer functions, <strong>in</strong> addition to the two poles. resonz has its zeroeslocated at z = 1 and z = -1. resonr has its zeroes located at +sqrt(R) and -sqrt(R), where R is theradius of the poles <strong>in</strong> the complex z-plane. The addition of zeroes to resonr and resonz results <strong>in</strong>the improved selectivity of the magnitude response of these filters at cutoff frequencies close to0, at the expense of less selectivity of frequencies above the cutoff peak.resonr and resonz are very close to constant-ga<strong>in</strong> as the center frequency is swept, result<strong>in</strong>g <strong>in</strong> amore efficient control of the magnitude response than with traditional two-pole resonators suchas reson.resonr and resonz produce a sound that is considerably different from reson, especially forlower center frequencies; trial and error is the best way of determ<strong>in</strong><strong>in</strong>g which resonator is bestsuited for a particular application.asig – <strong>in</strong>put signal to be filteredkcf – cutoff or resonant frequency of the filter, measured <strong>in</strong> Hzkbw – bandwidth of the filter (the Hz difference between the upper and lower half-power po<strong>in</strong>ts)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-4


50.3.4 EXAMPLE; Orchestra file for resonant filter sweep of a sawtooth-like waveform.; The outputs of reson, resonr, and resonz are scaled by coefficients; specified <strong>in</strong> the score, so that each filter can be heard on its own; from the same <strong>in</strong>strument.sr = 44100kr = 4410ksmps = 10nchnls = 1<strong>in</strong>str 1idur = p3ibegfreq = p4 ; beg<strong>in</strong>n<strong>in</strong>g of sweep frequencyiendfreq = p5 ; end<strong>in</strong>g of sweep frequencyibw = p6 ; bandwidth of filters <strong>in</strong> Hzifreq = p7 ; frequency of gbuzz that is to be filterediamp = p8 ; amplitude to scale output byires = p9 ; coefficient to scale amount of reson <strong>in</strong> outputiresr = p10 ; coefficient to scale amount of resonr <strong>in</strong> outputiresz = p11 ; coefficient to scale amount of resonz <strong>in</strong> output; Frequency envelope for reson cutoffkfreq l<strong>in</strong>seg ibegfreq, idur * .5, iendfreq, idur * .5, ibegfreq; Amplitude envelope to prevent click<strong>in</strong>gkenv l<strong>in</strong>seg 0, .1, iamp, idur - .2, iamp, .1, 0; Number of harmonics for gbuzz scaled to avoid alias<strong>in</strong>giharms = (sr*.4)/ifreqasig gbuzz 1, ifreq, iharms, 1, .9, 1 ; “Sawtooth” waveforma<strong>in</strong> = kenv * asig ; output scaled by amp; envelopeares reson a<strong>in</strong>, kfreq, ibw, 1aresr resonr a<strong>in</strong>, kfreq, ibw, 1aresz resonz a<strong>in</strong>, kfreq, ibw, 1outares * ires + aresr * iresr + aresz * ireszend<strong>in</strong>; Score file for abovef1 0 8192 9 1 1 .25; cos<strong>in</strong>e table for gbuzz generatori1 0 10 1 3000 200 100 4000 1 0 0 ; reson output with bw = 200i1 10 10 1 3000 200 100 4000 0 1 0 ; resonr output with bw = 200i1 20 10 1 3000 200 100 4000 0 0 1 ; resonz output with bw = 200i1 30 10 1 3000 50 200 8000 1 0 0 ; reson output with bw = 50i1 40 10 1 3000 50 200 8000 0 1 0 ; resonr output with bw = 50i1 50 10 1 3000 50 200 8000 0 0 1 ; resonz output with bw = 50eThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-5


50.3.5 TECHNICAL HISTORYresonr and resonz were orig<strong>in</strong>ally described <strong>in</strong> an article by Julius O. Smith and James B.Angell [1]. Smith and Angell recommended the resonz form (zeros at +1 and -1) whencomputational efficiency was the ma<strong>in</strong> concern, as it has one less multiply per sample, whileresonr (zeroes at + and – the square root of the pole radius R) was recommended for situationswhen a perfectly constant-ga<strong>in</strong> center peak was required.Ken Steiglitz, <strong>in</strong> a later article [2], demonstrated that resonz had constant ga<strong>in</strong> at the true peak ofthe filter, as opposed to resonr, which displayed constant ga<strong>in</strong> at the pole angle. Steiglitz alsorecommended resonz for its sharper notches <strong>in</strong> the ga<strong>in</strong> curve at zero and Nyquist frequency.Steiglitz’s recent book [3] features a thorough technical discussion of reson and resonz, whileDodge and Jerse’s textbook [4] illustrates the differences <strong>in</strong> the response curves of reson andresonz.50.3.6 REFERENCES1. Smith, Julius O. and Angell, James B., “A Constant-Ga<strong>in</strong> Resonator Tuned by a S<strong>in</strong>gleCoefficient,” Computer Music Journal, vol. 6, no. 4, pp. 36-39, W<strong>in</strong>ter 1982.2. Steiglitz, Ken, “A Note on Constant-Ga<strong>in</strong> Digital Resonators,” Computer Music Journal,vol. 18, no. 4, pp. 8-10, W<strong>in</strong>ter 1994.3. Ken Steiglitz, A Digital Signal Process<strong>in</strong>g Primer, with Applications to Digital Audioand Computer Music. Addison-Wesley Publish<strong>in</strong>g Company, Menlo Park, CA, 1996.4. Dodge, Charles and Jerse, Thomas A., Computer Music: Synthesis, Composition, andPerformance. New York: Schirmer Books, 1997, 2nd edition, pp. 211-214.50.3.7 AUTHORSean CostelloSeattle, Wash<strong>in</strong>gton1999New <strong>in</strong> <strong>Csound</strong> version 3.55The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-6


50.4 resonyar resony asig, kbf, kbw, <strong>in</strong>um, ksep[, isepmode, iscl, iskip]50.4.1 DESCRIPTIONA bank of second-order bandpass filters, connected <strong>in</strong> parallel.50.4.2 INITIALIZATION<strong>in</strong>um – number of filtersisepmode – if isepmode = 0, the separation of center frequencies of each filter is generatedlogarithmically (us<strong>in</strong>g octave as unit of measure). If isepmode != 0, the separation of centerfrequencies of each filter is generated l<strong>in</strong>early (us<strong>in</strong>g Hertz). Default value is 0.iscl – coded scal<strong>in</strong>g factor for resonators. A value of 1 signifies a peak response factor of 1, i.e.all frequencies other than kcf are attenuated <strong>in</strong> accordance with the (normalized) response curve.A value of 2 raises the response factor so that its overall RMS value equals 1. (This <strong>in</strong>tendedequalization of <strong>in</strong>put and output power assumes all frequencies are physically present; hence it ismost applicable to white noise.) A zero value signifies no scal<strong>in</strong>g of the signal, leav<strong>in</strong>g that tosome later adjustment (e.g. balance). The default value is 0.iskip – <strong>in</strong>itial disposition of <strong>in</strong>ternal data space. S<strong>in</strong>ce filter<strong>in</strong>g <strong>in</strong>corporates a feedback loop ofprevious output, the <strong>in</strong>itial status of the storage space used is significant. A zero value will clearthe space; a non-zero value will allow previous <strong>in</strong>formation to rema<strong>in</strong>. The default value is 0.50.4.3 PERFORMANCEasig – audio <strong>in</strong>put signalkbf – base frequency, i.e. center frequency of lowest filter <strong>in</strong> Hzkbw – bandwidth <strong>in</strong> Hzksep – separation of the center frequency of filters <strong>in</strong> octavesresony is a bank of second-order bandpass filters, with k-rate variant frequency separation, basefrequency and bandwidth, connected <strong>in</strong> parallel (i.e. the result<strong>in</strong>g signal is a mix of the output ofeach filter). The center frequency of each filter depends of kbf and ksep variables. The maximumnumber of filters is set to 100.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-7


50.4.4 EXAMPLEIn this example the global variable gk1 modifies kbf, gk2 modifies kbw, gk3 <strong>in</strong>um, gk4 ksep, andgk5 the ma<strong>in</strong> volume.<strong>in</strong>str 1a1 sound<strong>in</strong> "myfile.aif"a2 resony a1, gk1, gk2, i(gk3), gk4, 2outend<strong>in</strong>50.4.5 AUTHORGabriel MaldonadoItaly1999New <strong>in</strong> <strong>Csound</strong> version 3.56a2 * gk5The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-8


50.5 lowres, lowresxar lowres asig, kcutoff, kresonance [,iskip]ar lowresx asig, kcutoff, kresonance [, <strong>in</strong>umlayer, iskip]50.5.1 DESCRIPTIONlowres is a resonant lowpass filter. lowresx is equivalent to more layer of lowres, with the samearguments, serially connected.50.5.2 INITIALIZATION<strong>in</strong>umlayer – number of elements <strong>in</strong> a lowresx stack. Default value is 4. There is no maximum.iskip – <strong>in</strong>itial disposition of <strong>in</strong>ternal data space. A zero value will clear the space; a non-zerovalue will allow previous <strong>in</strong>formation to rema<strong>in</strong>. The default value is 0.50.5.3 PERFORMANCEasig – <strong>in</strong>put signalkcutoff – filter cutoff frequency po<strong>in</strong>tkresonance – resonance amountlowres is a resonant lowpass filter derived from a Hans Mikelson orchestra. This implementationis much faster than implement<strong>in</strong>g it <strong>in</strong> <strong>Csound</strong> language, and it allows kr lower than sr. kcutoff isnot <strong>in</strong> Hz and kresonance is not <strong>in</strong> dB, so experiment for the f<strong>in</strong>d<strong>in</strong>g best results.lowresx is equivalent to more layer of lowres, with the same arguments, serially connected.Us<strong>in</strong>g a stack of a larger number of filters allows a sharper cutoff. This is faster than us<strong>in</strong>g alarger number of <strong>in</strong>stances of lowres <strong>in</strong> a <strong>Csound</strong> orchestra, because only one <strong>in</strong>itialization and kcycle are needed at time, and the audio loop falls entirely <strong>in</strong>side the cache memory of processor.Based on an orchestra by Hans Mikelson.50.5.4 AUTHORGabriel Maldonado (adapted by John ffitch)ItalyNew <strong>in</strong> <strong>Csound</strong> version 3.49The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-9


50.6 vlowresar vlowres asig, kfco, kres, iord, ksep50.6.1 DESCRIPTIONA bank of filters <strong>in</strong> which the cutoff frequency can be separated under user control50.6.2 INITIALIZATIONiord – total number of filters (1 to 10)50.6.3 PERFORMANCEasig – <strong>in</strong>put signalkfco – frequency cutoff (not <strong>in</strong> Hz)ksep – frequency cutoff separation for each filtervlowres (variable resonant lowpass filter) allows a variable response curve <strong>in</strong> resonant filters. Itcan be thought of as a bank of lowpass resonant filters, each with the same resonance, seriallyconnected. The frequency cutoff of each filter can vary with the kcfo and ksep parameters.50.6.4 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.49The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-10


50.7 lowpass2ar lowpass2 asig, kcf, kq[, iskip]50.7.1 DESCRIPTIONImplementation of resonant second-order lowpass filter.50.7.2 INITIALIZATIONiskip – <strong>in</strong>itial disposition of <strong>in</strong>ternal data space. A zero value will clear the space; a non-zerovalue will allow previous <strong>in</strong>formation to rema<strong>in</strong>. The default value is 050.7.3 PERFORMANCEasig – <strong>in</strong>put signal to be filteredkcf – cutoff or resonant frequency of the filter, measured <strong>in</strong> Hzkq – Q of the filter, def<strong>in</strong>ed, for bandpass filters, as bandwidth/cutoff. kq should be between 1and 500lowpass2 is a second order IIR lowpass filter, with k-rate controls for cutoff frequency (kcf) andQ (kq). As kq is <strong>in</strong>creased, a resonant peak forms around the cutoff frequency, transform<strong>in</strong>g thelowpass filter response <strong>in</strong>to a response that is similar to a bandpass filter, but with more lowfrequency energy. This corresponds to an <strong>in</strong>crease <strong>in</strong> the magnitude and “sharpness” of theresonant peak. For high values of kq, a scal<strong>in</strong>g function such as balance may be required. Inpractice, this allows for the simulation of the voltage-controlled filters of analog synthesizers, orfor the creation of a pitch of constant amplitude while filter<strong>in</strong>g white noise.50.7.4 EXAMPLE; Orchestra file for resonant filter sweep of a sawtooth-like waveform.sr = 44100kr = 2205ksmps = 20nchnls = 1<strong>in</strong>str 1idur = p3ifreq = p4iamp = p5 * .5iharms = (sr*.4) / ifreq; Sawtooth-like waveformasig gbuzz 1, ifreq, iharms, 1, .9, 1; Envelope to control filter cutoffkfreq l<strong>in</strong>seg 1, idur * 0.5, 5000, idur * 0.5, 1afilt lowpass2 asig, kfreq, 30The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-11


; Simple amplitude envelopekenv l<strong>in</strong>seg 0, .1, iamp, idur -.2, iamp, .1, 0outasig * kenvend<strong>in</strong>; Score file for abovef1 0 8192 9 1 1 .25i1 0 5 100 1000i1 5 5 200 1000e50.7.5 AUTHORSean CostelloSeattle, Wash<strong>in</strong>gtonAugust, 1999New <strong>in</strong> <strong>Csound</strong> version 4.0The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-12


50.8 biquad, rezzy, moogvcfar biquad asig, kb0, kb1, kb2, ka0, ka1, ka2[, iskip]ar rezzy asig, xfco, xres[, imode]ar moogvcf asig, xfco, xres[, iscale]50.8.1 DESCRIPTIONImplementation of a sweepable general purpose filter and two sweepable, resonant low-passfilters.50.8.2 INITIALIZATIONiskip (optional) – if non-zero, <strong>in</strong>itialization will be skipped. Default value 0. (New <strong>in</strong> <strong>Csound</strong>version 3.50)imode (optional) – if zero rezzy is low-pass, if nonzero, high-pass. Default value is 0. (New <strong>in</strong><strong>Csound</strong> version 3.50)iscale (optional) – <strong>in</strong>ternal scal<strong>in</strong>g factor. Use if asig is not <strong>in</strong> the range +/-1. Input is firstdivided by iscale, then output is multiplied iscale. Default value is 1. (New <strong>in</strong> <strong>Csound</strong> version3.50)50.8.3 PERFORMANCEasig – <strong>in</strong>put signalxfco – filter cut-off frequency <strong>in</strong> Hz. As of version 3.50, may i-,k-, or a-rate.xres – amount of resonance. For rezzy, values of 1 to 100 are typical. Resonance should be oneor greater. For moogvcf, self-oscillation occurs when xres is approximately one. As of version3.50, may i-,k-, or a-rate.biquad is a general purpose biquadratic digital filter of the form:a0*y(n) + a1*y[n-1] + a2*y[n-2] = b0*x[n] + b1*x[n-1] + b2*x[n-2]This filter has the follow<strong>in</strong>g frequency response:B(Z) b0 + b1*Z -1 + b2*Z -2H(Z) = ---- = ------------------A(Z) a0 + a1*Z -1 + a2*Z -2This type of filter is often encountered <strong>in</strong> digital signal process<strong>in</strong>g literature. It allows six userdef<strong>in</strong>edk-rate coefficients.rezzy is a resonant low-pass filter created empirically by Hans Mikelson.moogvcf is a digital emulation of the Moog diode ladder filter configuration. This emulation isbased loosely on the paper “Analyz<strong>in</strong>g the Moog VCF with Considerations for DigitalImplementation” by Stilson and Smith (CCRMA). This version was orig<strong>in</strong>ally coded <strong>in</strong> <strong>Csound</strong>by Josep Comajuncosas. Some modifications and conversion to C were done by Hans Mikelson.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-13


Note: This filter requires that the <strong>in</strong>put signal be normalized to one.50.8.4 EXAMPLES;biquad examplekfcon = *3.14159265*kfco/srkalpha = -2*krez*cos(kfcon)*cos(kfcon)+krez*krez*cos(2*kfcon)kbeta = *krez*s<strong>in</strong>(2*kfcon)-2*krez*cos(kfcon)*s<strong>in</strong>(kfcon)kgama = +cos(kfcon)km1 = *kgama+kbeta*s<strong>in</strong>(kfcon)km2 = *kgama-kbeta*s<strong>in</strong>(kfcon)kden = (km1*km1+km2*km2)kb0 = .5*(kalpha*kalpha+kbeta*kbeta)/kdenkb1 = kb0kb2 = 0ka0 = 1ka1 = -2*krez*cos(kfcon)ka2 = krez*krezayn biquad axn, kb0, kb1, kb2, ka0, ka1, ka2outs ayn*iamp/2, ayn*iamp/2; Sta Dur Amp Pitch Fco Rezi14 8.0 1.0 20000 6.00 1000 .8i14 + 1.0 20000 6.03 2000 .95;rezzy examplekfco expseg 100+.01*ifco, .2*idur, ifco+100, .5*idur, ifco*.1+100,.3*idur, .001*ifco+100apulse1 buzzasaw <strong>in</strong>teg apulse1axn = asaw-.5ayn rezzy axn, kfco, krezouts ayn*iamp, ayn*iamp; Sta Dur Amp Pitch Fco Rezi10 0.0 1.0 20000 6.00 1000 2i10 + 1.0 20000 6.03 2000 101,ifqc, sr/2/ifqc, 1 ; Avoid alias<strong>in</strong>g;moogvcf exampleapulse1 buzz 1,ifqc, sr/2/ifqc, 1 ; Avoid alias<strong>in</strong>gasaw <strong>in</strong>teg apulse1ax = asaw-.5ayn moogvcf ax, kfco, krezouts ayn*iamp, ayn*iamp; Sta Dur Amp Pitch Fco Rezi11 4.0 1.0 20000 6.00 1000 .4i11 + 1.0 20000 6.03 2000 .750.8.5 AUTHORHans MikelsonOctober 1998New <strong>in</strong> <strong>Csound</strong> version 3.49The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-14


50.9 svfilteralow, ahigh, aband svfilter asig, kcf, kq[, iscl]50.9.1 DESCRIPTIONImplementation of a resonant second order filter, with simultaneous lowpass, highpass andbandpass outputs.50.9.2 INITIALIZATIONiscl – coded scal<strong>in</strong>g factor, similar to that <strong>in</strong> reson. A non-zero value signifies a peak responsefactor of 1, i.e. all frequencies other than kcf are attenuated <strong>in</strong> accordance with the (normalized)response curve. A zero value signifies no scal<strong>in</strong>g of the signal, leav<strong>in</strong>g that to some lateradjustment (see balance). The default value is 0.50.9.3 PERFORMANCEsvfilter is a second order state-variable filter, with k-rate controls for cutoff frequency and Q. AsQ is <strong>in</strong>creased, a resonant peak forms around the cutoff frequency. svfilter has simultaneouslowpass, highpass, and bandpass filter outputs; by mix<strong>in</strong>g the outputs together, a variety offrequency responses can be generated. The state-variable filter, or “multimode” filter was acommon feature <strong>in</strong> early analog synthesizers, due to the wide variety of sounds available fromthe <strong>in</strong>teraction between cutoff, resonance, and output mix ratios. svfilter is well suited to theemulation of “analog” sounds, as well as other applications where resonant filters are called for.asig – Input signal to be filtered.kcf – Cutoff or resonant frequency of the filter, measured <strong>in</strong> Hz.kq – Q of the filter, which is def<strong>in</strong>ed (for bandpass filters) as bandwidth/cutoff. kq should be <strong>in</strong> arange between 1 and 500. As kq is <strong>in</strong>creased, the resonance of the filter <strong>in</strong>creases, whichcorresponds to an <strong>in</strong>crease <strong>in</strong> the magnitude and “sharpness” of the resonant peak. When us<strong>in</strong>gsvfilter without any scal<strong>in</strong>g of the signal (where iscl is either absent or 0), the volume of theresonant peak <strong>in</strong>creases as Q <strong>in</strong>creases. For high values of Q, it is recommended that iscl be setto a non-zero value, or that an external scal<strong>in</strong>g function such as balance is used.svfilter is based upon an algorithm <strong>in</strong> Hal Chamberl<strong>in</strong>’s Musical Applications ofMicroprocessors (Hayden Books, 1985).50.9.4 EXAMPLE; Orchestra file for resonant filter sweep of a sawtooth-like waveform.; The separate outputs of the filter are scaled by values from the score,; and are mixed together.sr = 44100kr = 2205ksmps = 20nchnls = 1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-15


<strong>in</strong>str 1idur = p3ifreq = p4iamp = p5ilowamp = p6; determ<strong>in</strong>es amount of lowpass output <strong>in</strong> signalihighamp = p7; determ<strong>in</strong>es amount of highpass output <strong>in</strong> signalibandamp = p8; determ<strong>in</strong>es amount of bandpass output <strong>in</strong> signaliq = p9 ; value of qiharms = (sr*.4) / ifreqasig gbuzz 1, ifreq, iharms, 1, .9, 1 ; Sawtooth-like; waveformkfreq l<strong>in</strong>seg 1, idur * 0.5, 4000, idur * 0.5, 1 ; Envelope tocontrol; filter cutoffalow, ahigh, abandsvfilter asig, kfreq, iqaout1 = alow * ilowampaout2 = ahigh * ihighampaout3 = aband * ibandampasum = aout1 + aout2 + aout3kenv l<strong>in</strong>seg 0, .1, iamp, idur -.2, iamp, .1, 0 ; Simple amplitude; envelopeout asum * kenvend<strong>in</strong>; Score file for abovef1 0 8192 9 1 1 .25i1 0 5 100 1000 1 0 0 5 ; lowpass sweepi1 5 5 200 1000 1 0 0 30 ; lowpass sweep, octave higher, higher qi1 10 5 100 1000 0 1 0 5 ; highpass sweepi1 15 5 200 1000 0 1 0 30 ; highpass sweep, octave higher, higher qi1 20 5 100 1000 0 0 1 5 ; bandpass sweepi1 25 5 200 1000 0 0 1 30 ; bandpass sweep, octave higher, higher qi1 30 5 200 2000 .4 .6 0 ; notch sweep - notch formed by comb<strong>in</strong><strong>in</strong>g; highpass and lowpass outputse50.9.5 AUTHORSean CostelloSeattle, Wash<strong>in</strong>gton1999New <strong>in</strong> <strong>Csound</strong> version 3.55The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-16


50.10 hilbertar1, ar2 hilbert asig50.10.1 DESCRIPTIONAn IIR implementation of a Hilbert transformer.50.10.2 PERFORMANCEasig – <strong>in</strong>put signalar1 – cos<strong>in</strong>e output of asigar2 – s<strong>in</strong>e output of asighilbert is an IIR filter based implementation of a broad-band 90 degree phase differencenetwork. The <strong>in</strong>put to hilbert is an audio signal, with a frequency range from 15 Hz to 15 kHz.The outputs of hilbert have an identical frequency response to the <strong>in</strong>put (i.e. they sound thesame), but the two outputs have a constant phase difference of 90 degrees, plus or m<strong>in</strong>us somesmall amount of error, throughout the entire frequency range. The outputs are <strong>in</strong> quadrature.hilbert is useful <strong>in</strong> the implementation of many digital signal process<strong>in</strong>g techniques that requirea signal <strong>in</strong> phase quadrature. ar1 corresponds to the cos<strong>in</strong>e output of hilbert, while ar2corresponds to the s<strong>in</strong>e output. The two outputs have a constant phase difference throughout theaudio range that corresponds to the phase relationship between cos<strong>in</strong>e and s<strong>in</strong>e waves.Internally, hilbert is based on two parallel 6th-order allpass filters. Each allpass filterimplements a phase lag that <strong>in</strong>creases with frequency; the difference between the phase lags ofthe parallel allpass filters at any given po<strong>in</strong>t is approximately 90 degrees.Unlike an FIR-based Hilbert transformer, the output of hilbert does not have a l<strong>in</strong>ear phaseresponse. However, the IIR structure used <strong>in</strong> hilbert is far more efficient to compute, and thenonl<strong>in</strong>ear phase response can be used <strong>in</strong> the creation of <strong>in</strong>terest<strong>in</strong>g audio effects, as <strong>in</strong> the secondexample below.50.10.3 EXAMPLESThe first example implements frequency shift<strong>in</strong>g, or s<strong>in</strong>gle sideband amplitude modulation.Frequency shift<strong>in</strong>g is similar to r<strong>in</strong>g modulation, except the upper and lower sidebands areseparated <strong>in</strong>to <strong>in</strong>dividual outputs. By us<strong>in</strong>g only one of the outputs, the <strong>in</strong>put signal can be“detuned,” where the harmonic components of the signal are shifted out of harmonic alignmentwith each other, e.g. a signal with harmonics at 100, 200, 300, 400 and 500 Hz, shifted up by 50Hz, will have harmonics at 150, 250, 350, 450, and 550 Hz.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-17


sr = 44100kr = 4410ksmps = 10nchnls = 2<strong>in</strong>str 1idur = p3ibegshift = p4 ; <strong>in</strong>itial amount of frequency shift-; can be positive or negativeiendshift = p5 ; f<strong>in</strong>al amount of frequency shift-; can be positive or negativekfreq l<strong>in</strong>seg ibegshift, idur, iendshift ; A simple envelope; for determ<strong>in</strong><strong>in</strong>g; the amount of; frequency shift.a<strong>in</strong> sound<strong>in</strong> “supertest.wav” ; Use the sound of your choice.areal, aimag hilbert a<strong>in</strong> ; Phase quadrature output derived from; <strong>in</strong>put signal.as<strong>in</strong> oscili 1, kfreq, 1 ; Quadrature oscillator.acos oscili 1, kfreq, 1, .25amod1 = areal * acos ; Trigonometric identity-; see references for further; details.amod2 = aimag * as<strong>in</strong>; Both sum and difference; frequencies can be; output at once.aupshift = (amod1 + amod2) * 0.7 ; aupshift corresponds to; the sum frequencies, whileadownshift = (amod1 - amod2) * 0.7 ; adownshift corresponds to; the difference frequencies.; Notice that the add<strong>in</strong>g of; the two together is; identical to the output of; r<strong>in</strong>g modulation.outsend<strong>in</strong>; a simple scoref1 0 16384 10 1i1 0 29 0 200i1 30 29 0 -200eaupshift, aupshift; s<strong>in</strong>e table for quadrature oscillator; start<strong>in</strong>g with no shift, end<strong>in</strong>g with all; frequencies shifted up by 200 Hz.; start<strong>in</strong>g with no shift, end<strong>in</strong>g with all; frequencies shifted up by 200 Hz.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-18


The second example is a variation of the first, but with the output be<strong>in</strong>g fed back <strong>in</strong>to the <strong>in</strong>put.With very small shift amounts (i.e. between 0 and +-6 Hz), the result is a sound that has beendescribed as a “barberpole phaser” or “Shepard tone phase shifter. Several notches appear <strong>in</strong> thespectrum, and are constantly swept <strong>in</strong> the direction opposite that of the shift, produc<strong>in</strong>g afilter<strong>in</strong>g effect that is rem<strong>in</strong>iscent of Risset’s “endless glissando.”sr = 44100kr = 44100 ; kr MUST be set to sr for “barberpole”effectksmps = 1nchnls = 2<strong>in</strong>str 2afeedback <strong>in</strong>it 0 ; <strong>in</strong>itialization of feedbackidur = p3ibegshift = p4 ; <strong>in</strong>itial amount of frequency shift –; can be positive or negativeiendshift = p5 ; f<strong>in</strong>al amount of frequency shift - can be; positive or negativeifeed = p6 ; amount of feedback - the higher the; number, the more pronounced; the effect. Experiment to see at what; po<strong>in</strong>t oscillation occurs; (often a factor of 1.4 is the maximum; feedback before oscillation).kfreql<strong>in</strong>seg ibegshift, idur, iendshifta<strong>in</strong>sound<strong>in</strong> “supertest.wav”areal, aimag hilbert a<strong>in</strong> + afeedbackas<strong>in</strong> oscili 1, kfreq, 1acos oscili 1, kfreq, 1, .25amod1 = areal * acosamod2 = aimag * as<strong>in</strong>aupshift = (amod1 + amod2) * 0.7adownshift = (amod1 - amod2) * 0.7afeedback = (amod1 - amod2) * .5 * ifeed ; feedback taken from; downshift outputoutsaupshift, aupshiftend<strong>in</strong>; a simple scoref1 0 16384 10 1i2 0 29 -.3 -.3 1.4i2 30 30 .1 .1 1.4; s<strong>in</strong>e table for quadrature oscillator; upwards sweep, at a rate of .3 times a second,; lots of feedback; downwards sweep, .3 times a second,; lots of feedbacki2 60 29 5 -5 1.4 ; sweep goes from .3 time a second,; descend<strong>in</strong>g <strong>in</strong> pitch,; to .3 times a second ascend<strong>in</strong>g <strong>in</strong> pitch, with a; large amount of feedback.eThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-19


50.10.4 TECHNICAL HISTORYThe use of phase-difference networks <strong>in</strong> frequency shifters was pioneered by Harald Bode [1].Bode and Bob Moog provide an excellent description of the implementation and use of afrequency shifter <strong>in</strong> the analog realm [2]. This would be an excellent first source for those thatwish to explore the possibilities of s<strong>in</strong>gle sideband modulation. Bernie Hutch<strong>in</strong>s provides moreapplications of the frequency shifter, as well as a detailed technical analysis [3]. A recent paperby Scott Wardle [4] describes a digital implementation of a frequency shifter, as well as someunique applications.50.10.5 REFERENCES1. H. Bode, “Solid State Audio Frequency Spectrum Shifter.” AES Prepr<strong>in</strong>t No. 395 (1965).2. H. Bode and R.A. Moog, “A High-Accuracy Frequency Shfiter for Professional AudioApplications.” Journal of the Audio Eng<strong>in</strong>eer<strong>in</strong>g Society, July/August 1972, vol. 20, no. 6, p.453.3. B. Hutch<strong>in</strong>s. Musical Eng<strong>in</strong>eer’s Handbook (Ithaca, NY: Electronotes, 1975), ch. 6a.4. S. Wardle, “A Hilbert-Transformer Frequency Shifter for Audio.” Available onl<strong>in</strong>e athttp://www.iua.upf.es/dafx98/papers/.50.10.6 AUTHORSean CostelloSeattle, Wash<strong>in</strong>gton1999New <strong>in</strong> <strong>Csound</strong> version 3.55The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-20


50.11 butterhp, butterlp, butterbp, butterbrar butterhp asig, kfreq [,iskip]ar butterlp asig, kfreq [,iskip]ar butterbp asig, kfreq, kband [,iskip]ar butterbr asig, kfreq, kband [,iskip]50.11.1 DESCRIPTIONImplementations of second-order high-pass, low-pass, band-pass and band-reject Butterworthfilters. Note: these opcodes can also be written butlp, buthp, butbp, butbr.50.11.2 PERFORMANCEThese filters are Butterworth second-order IIR filters. They are slightly slower than the orig<strong>in</strong>alfilters <strong>in</strong> <strong>Csound</strong>, but they offer an almost flat passband and very good precision and stopbandattenuation.asig – Input signal to be filtered.kfreq – Cutoff or center frequency for each of the filters.kband – Bandwidth of the bandpass and bandreject filters.iskip – Skip <strong>in</strong>itialization if present and non zero50.11.3 EXAMPLEasig rand 10000 ; White noise signalalpf butterlp asig, 1000 ; cutt<strong>in</strong>g frequencies above1Kahpf butterhp asig, 500 ; pass<strong>in</strong>g frequencies above 500Hzabpf butterbp asig, 2000, 100 ; pass<strong>in</strong>g only 1950 to 2050 Hzabrf butterbr asig, 4500, 200 ; cutt<strong>in</strong>g only 4400 to 4600 Hz50.11.4 AUTHORParis SmaragdisMIT, Cambridge1995The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-21


50.12 filter2, zfilter2ar filter2 asig, iM,iN,ib0,ib1,..., ibM,ia1,ia2,...,iaNkr filter2 ksig, iM,iN,ib0,ib1,...,ibM,ia1,ia2,...,iaNar zfilter2 asig, kdamp,kfreq,iM,iN,ib0,ib1,...,ibM,ia1,ia2,...,iaN50.12.1 DESCRIPTIONGeneral purpose custom filter with time-vary<strong>in</strong>g pole control. The filter coefficients implementthe follow<strong>in</strong>g difference equation:(1)*y(n) = b0*x[n] + b1*x[n-1] +...+ bM*x[n-M] - a1*y[n-1] -...- aN*y[n-N]the system function for which is represented by:B(Z) b0 + b1*Z -1 + ... + bM*Z -MH(Z) = ---- = ---------------------------------A(Z) 1 + a1*Z -1 + ... + aN*Z -N50.12.2 INITIALIZATIONAt <strong>in</strong>itialization the number of zeros and poles of the filter are specified along with thecorrespond<strong>in</strong>g zero and pole coefficients. The coefficients must be obta<strong>in</strong>ed by an external filterdesignapplication such as Matlab and specified directly or loaded <strong>in</strong>to a table via GEN01. Withzfilter2, the roots of the characteristic polynomials are solved at <strong>in</strong>itialization so that the polecontroloperations can be implemented efficiently.50.12.3 PERFORMANCEThe filter2 opcodes perform filter<strong>in</strong>g us<strong>in</strong>g a transposed form-II digital filter lattice with notime-vary<strong>in</strong>g control. zfilter2 uses the additional operations of radial pole-shear<strong>in</strong>g and angularpole-warp<strong>in</strong>g <strong>in</strong> the Z plane.Pole shear<strong>in</strong>g <strong>in</strong>creases the magnitude of poles along radial l<strong>in</strong>es <strong>in</strong> the Z-plane. This has theaffect of alter<strong>in</strong>g filter r<strong>in</strong>g times. The k-rate variable kdamp is the damp<strong>in</strong>g parameter. Positivevalues (0.01 to 0.99) <strong>in</strong>crease the r<strong>in</strong>g-time of the filter (hi-Q), negative values (-0.01 to -0.99)decrease the r<strong>in</strong>g-time of the filter, (lo-Q).Pole warp<strong>in</strong>g changes the frequency of poles by mov<strong>in</strong>g them along angular paths <strong>in</strong> the Z plane.This operation leaves the shape of the magnitude response unchanged but alters the frequenciesby a constant factor (preserv<strong>in</strong>g 0 and p). The k-rate variable kfreq determ<strong>in</strong>es the frequencywarp factor. Positive values (0.01 to 0.99) <strong>in</strong>crease frequencies toward p and negative values (-0.01 to -0.99) decrease frequencies toward 0.S<strong>in</strong>ce filter2 implements generalized recursive filters, it can be used to specify a large range ofgeneral DSP algorithms. For example, a digital waveguide can be implemented for musical<strong>in</strong>strument model<strong>in</strong>g us<strong>in</strong>g a pair of delayr and delayw opcodes <strong>in</strong> conjunction with the filter2opcode.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-22


50.12.4 EXAMPLEA first-order l<strong>in</strong>ear-phase lowpass l<strong>in</strong>ear-phase FIR filter operat<strong>in</strong>g on a k-rate signal:k1 filter2 ksig, 2, 0, 0.5, 0.5 ;; k-rate FIR filterA controllable second-order IIR filter operat<strong>in</strong>g on an a-rate signal:a1 zfilter2 asig, kdamp, kfreq, 1, 2, 1, ia1, ia2 ; controllable a-rate; IIR filter50.12.5 DEPRECATED NAMESThe k-rate version of filter2 was orig<strong>in</strong>ally called kfilter2. As of <strong>Csound</strong> version 3.493, thisname is deprecated. filter2 should be used <strong>in</strong>stead of kfilter2. The opcode determ<strong>in</strong>es its ratefrom the output argument.50.12.6 AUTHORMichael A. CaseyMITCambridge, Mass.1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-23


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Standard Filters Page 50-24


51 SIGNAL MODIFIERS: SPECIALIZED FILTERS51.1 nlfiltar nlfilt a<strong>in</strong>, ka, kb, kd, kL, kC51.1.1 DESCRIPTIONImplements the filter Y{n} =a Y{n-1} + b Y{n-2} + d Y^2{n-L} + X{n} – C described <strong>in</strong>Dobson and Fitch (ICMC’96)51.1.2 EXAMPLE1. Non-l<strong>in</strong>ear effect:a = b = 0d = 0.8, 0.9, 0.7C = 0.4, 0.5, 0.6L = 20This affects the lower register most but there are audible effects over the whole range. Wesuggest that it may be useful for color<strong>in</strong>g drums, and for add<strong>in</strong>g arbitrary highlights to notes2. Low Pass with non-l<strong>in</strong>ear:a = 0.4b = 0.2d = 0.7C = 0.11L = 20, ... 200There are <strong>in</strong>stability problems with this variant but the effect is more pronounced of the lowerregister, but is otherwise much like the pure comb. Short values of L can add attack to a sound.3. High Pass with non-l<strong>in</strong>ear: The range of parameters area = 0.35b = -0.3d = 0.95C = 0,2, ... 0.4L = 2004. High Pass with non-l<strong>in</strong>ear: The range of parameters area = 0.7b = -0.2, ... 0.5d = 0.9C = 0.12, ... 0.24L = 500, 10The high pass version is less likely to oscillate. It adds sc<strong>in</strong>tillation to medium-high registers.With a large delay L it is a little like a reverberation, while with small values there appear to beformant-like regions. There are arbitrary color changes and resonances as the pitch changes.Works well with <strong>in</strong>dividual notes.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Specialized Filters Page 51-1


Warn<strong>in</strong>g: The “useful” ranges of parameters are not yet mapped.51.1.3 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UK1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Specialized Filters Page 51-2


51.2 pareqar pareq asig, kc, iv, iq, imode51.2.1 DESCRIPTIONImplementation of Zoelzer’s parametric equalizer filters, with some modifications by the author.The formula for the low shelf filter is:omega = 2*pi*f/srK = tan(omega/2)b0 = 1 + sqrt(2*V)*K + V*K^2b1 = 2*(V*K^2 - 1)b2 = 1 - sqrt(2*V)*K + V*K^2a0 = 1 + K/Q + K^2a1 = 2*(K^2 - 1)a2 = 1 - K/Q + K^2The formula for the high shelf filter is:omega = 2*pi*f/srK = tan((pi-omega)/2)b0 = 1 + sqrt(2*V)*K + V*K^2b1 = -2*(V*K^2 - 1)b1 = 1 - sqrt(2*V)*K + V*K^2a0 = 1 + K/Q + K^2a1 = -2*(K^2 - 1)a2 = 1 - K/Q + K^2The formula for the peak<strong>in</strong>g filter is:omega = 2*pi*f/srK = tan(omega/2)b0 = 1 + V*K/2 + K^2b1 = 2*(K^2 - 1)b2 = 1 - V*K/2 + K^2a0 = 1 + K/Q + K^2a1 = 2*(K^2 - 1)a2 = 1 - K/Q + K^2The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Specialized Filters Page 51-3


51.2.2 INITIALIZATIONiv – amount of boost or cut. Positive values give boost, negative values give cut.iq – Q of the filter (sqrt(.5) is no resonance)imode – operat<strong>in</strong>g mode• 0 = Peak<strong>in</strong>g• 1 = Low Shelv<strong>in</strong>g• 2 = High Shelv<strong>in</strong>g51.2.3 PERFORMANCEkc – center frequency <strong>in</strong> peak<strong>in</strong>g mode, corner frequency <strong>in</strong> shelv<strong>in</strong>g mode.asig – the <strong>in</strong>com<strong>in</strong>g signal51.2.4 EXAMPLE<strong>in</strong>str 15ifc = p4 ; Center / Shelfiq = p5 ; Quality factor sqrt(.5) is no resonanceiv = ampdb(p6) ; Volume Boost/Cutimode = p7 ; Mode 0=Peak<strong>in</strong>g EQ, 1=Low Shelf, 2=High Shelfkfc l<strong>in</strong>seg ifc*2, p3, ifc/2asig rand 5000 ; Random number source for test<strong>in</strong>gaout pareq asig, kfc, iv, iq, imode ; Parametric equalizationouts aout, aout; Output the resultsend<strong>in</strong>; SCORE:; Sta Dur Fcenter Q Boost/Cut(dB) Modei15 0 1 10000 .2 12 1i15 + . 5000 .2 12 1i15 . . 1000 .707 -12 2i15 . . 5000 .1 -12 0e51.2.5 AUTHORHans MikelsonDecember, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.50)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Specialized Filters Page 51-4


51.3 dcblockar dcblock asig[, ig]51.3.1 DESCRIPTIONImplements the DC block<strong>in</strong>g filterY[i] = X[i] – X[i-1] + (iga<strong>in</strong> * Y[i=1])Based on work by Perry Cook.51.3.2 INITIALIZATIONiga<strong>in</strong> – the ga<strong>in</strong> of the filter, which defaults to 0.9951.3.3 PERFORMANCEa<strong>in</strong> – audio signal <strong>in</strong>put51.3.4 AUTHORJohn ffitchUniversity of Bath, Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.49The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Specialized Filters Page 51-5


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Specialized Filters Page 51-6


52 SIGNAL MODIFIERS: ENVELOPE MODIFIERS52.1 l<strong>in</strong>en, l<strong>in</strong>enr, envlpx, envlpxrkr l<strong>in</strong>en kamp, irise, idur, idecar l<strong>in</strong>en xamp, irise, idur, ideckr l<strong>in</strong>enr kamp, irise, idec, iatdecar l<strong>in</strong>enr xamp, irise, idec, iatdeckr envlpx kamp, irise, idur, idec, ifn, iatss, iatdec[,ixmod]ar envlpx xamp, irise, idur, idec, ifn, iatss, iatdec[,ixmod]kr envlpxr kamp, irise, idec, ifn, iatss, iatdec[, ixmod[, ir<strong>in</strong>d]]ar envlpxr xamp, irise, idec, ifn, iatss, iatdec[, ixmod[, ir<strong>in</strong>d]]52.1.1 DESCRIPTIONl<strong>in</strong>en – apply a straight l<strong>in</strong>e rise and decay pattern to an <strong>in</strong>put amp signal.envlpx – apply an envelope consist<strong>in</strong>g of 3 segments:1. stored function rise shape2. modified exponential pseudo steady state3. exponential decay.l<strong>in</strong>enr, envlpxr - as above, except that the f<strong>in</strong>al segment is entered only on sens<strong>in</strong>g a MIDI noterelease, and the note is then extended by the decay time52.1.2 INITIALIZATIONirise – rise time <strong>in</strong> seconds. A zero or negative value signifies no rise modification.idur – overall duration <strong>in</strong> seconds. A zero or negative value will cause <strong>in</strong>itialization to beskipped.idec – decay time <strong>in</strong> seconds. Zero means no decay. An idec > idur will cause a truncated decay.ir<strong>in</strong>d (optional) – <strong>in</strong>dependence flag. If left zero, the release time (idec) will <strong>in</strong>fluence theextended life of the current note follow<strong>in</strong>g a note-off. If non-zero, the idec time is quite<strong>in</strong>dependent of the note extension (see below). The default value is 0.ifn – function table number of stored rise shape with extended guard po<strong>in</strong>t.iatss – attenuation factor, by which the last value of the envlpx rise is modified dur<strong>in</strong>g the note’spseudo steady state. A factor l causes an exponential growth, and < l an exponential decay. A 1will ma<strong>in</strong>ta<strong>in</strong> a true steady state at the last rise value. Note that this attenuation is not by fixedrate (as <strong>in</strong> a piano), but is sensitive to a note’s duration. However, if iatss is negative (or if steadystate < 4 k-periods) a fixed attenuation rate of abs(iatss) per second will be used. 0 is illegal.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Envelope Modifiers Page 52-1


iatdec – attenuation factor by which the clos<strong>in</strong>g steady state value is reduced exponentially overthe decay period. This value must be positive and is normally of the order of .01. A large orexcessively small value is apt to produce a cutoff which is audible. A zero or negative value isillegal.ixmod (optional, between +- .9 or so) – exponential curve modifier, <strong>in</strong>fluenc<strong>in</strong>g the steepness ofthe exponential trajectory dur<strong>in</strong>g the steady state. Values less than zero will cause an acceleratedgrowth or decay towards the target (e.g. subito piano). Values greater than zero will cause aretarded growth or decay. The default value is zero (unmodified exponential).52.1.3 PERFORMANCERise modifications are applied for the first irise seconds, and decay from time idur – idec. Ifthese periods are separated <strong>in</strong> time there will be a steady state dur<strong>in</strong>g which amp will beunmodified (l<strong>in</strong>en) or modified by the first exponential pattern (envlpx). If l<strong>in</strong>en rise and decayperiods overlap then both modifications will be <strong>in</strong> effect for that time; <strong>in</strong> envlpx that will cause atruncated decay. If the overall duration idur is exceeded <strong>in</strong> performance, the f<strong>in</strong>al decay willcont<strong>in</strong>ue on <strong>in</strong> the same direction, go<strong>in</strong>g negative for l<strong>in</strong>en but tend<strong>in</strong>g asymptotically to zero <strong>in</strong>envlpx.l<strong>in</strong>enr is unique with<strong>in</strong> <strong>Csound</strong> <strong>in</strong> conta<strong>in</strong><strong>in</strong>g a note-off sensor and release time extender.When it senses either a score event term<strong>in</strong>ation or a MIDI noteoff, it will immediately extend theperformance time of the current <strong>in</strong>strument by idec seconds, then execute an exponential decaytowards the factor iatdec. For two or more units <strong>in</strong> an <strong>in</strong>strument, extension is by the greatestidec.l<strong>in</strong>enr, envlpxr are examples of the special <strong>Csound</strong> “r” units that conta<strong>in</strong> a note-off sensor andrelease time extender. Unless made <strong>in</strong>dependent by ir<strong>in</strong>d, when each senses a score eventterm<strong>in</strong>ation or a MIDI noteoff, it will immediately extend the performance time of the current<strong>in</strong>strument by idec seconds, then beg<strong>in</strong> a decay (as described above) from wherever it was at thetime. These “r” units can also be modified by MIDI noteoff velocities (see veloffs). If the ir<strong>in</strong>dflag is on (non-zero), the overall performance time is unaffected by note-off and veloff data.52.1.4 MULTIPLE “R” UNITSWhen two or more “r” units occur <strong>in</strong> the same <strong>in</strong>strument it is usual to have only one of them<strong>in</strong>fluence the overall note duration. This is normally the master amplitude unit. Other unitscontroll<strong>in</strong>g, say, filter motion can still be sensitive to note-off commands while not affect<strong>in</strong>g theduration by mak<strong>in</strong>g them <strong>in</strong>dependent (ir<strong>in</strong>d non-zero). Depend<strong>in</strong>g on their own idec (releasetime) values, <strong>in</strong>dependent “r” units may or may not reach their f<strong>in</strong>al dest<strong>in</strong>ations before the<strong>in</strong>strument term<strong>in</strong>ates. If they do, they will simply hold their target values until term<strong>in</strong>ation. Iftwo or more “r” units are simultaneously master, note extension is by the greatest idec.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Envelope Modifiers Page 52-2


53 SIGNAL MODIFIERS: AMPLITUDEMODIFIERS53.1 rms, ga<strong>in</strong>, balancekr rms asig[, ihp, iskip]ar ga<strong>in</strong> asig, krms[, ihp, iskip]ar balance asig, acomp[, ihp, iskip]53.1.1 DESCRIPTIONThe rms power of asig can be <strong>in</strong>terrogated, set, or adjusted to match that of a comparator signal.53.1.2 INITIALIZATIONihp (optional) – half-power po<strong>in</strong>t (<strong>in</strong> Hz) of a special <strong>in</strong>ternal low-pass filter. The default value is10.iskip (optional) – <strong>in</strong>itial disposition of <strong>in</strong>ternal data space ( see reson). The default value is 0.53.1.3 PERFORMANCErms output values kr will trace the rms value of the audio <strong>in</strong>put asig. This unit is not a signalmodifier, but functions rather as a signal power-gauge.ga<strong>in</strong> provides an amplitude modification of asig so that the output ar has rms power equal tokrms. rms and ga<strong>in</strong> used together (and given match<strong>in</strong>g ihp values) will provide the same effectas balance.balance outputs a version of asig, amplitude-modified so that its rms power is equal to that of acomparator signal acomp. Thus a signal that has suffered loss of power (e.g., <strong>in</strong> pass<strong>in</strong>g througha filter bank) can be restored by match<strong>in</strong>g it with, for <strong>in</strong>stance, its own source. It should be notedthat ga<strong>in</strong> and balance provide amplitude modification only – output signals are not altered <strong>in</strong>any other respect.53.1.4 EXAMPLEasrc buzz 10000,440, sr/440, 1 ; band-limited pulse tra<strong>in</strong>a1 reson asrc, 1000,100 ; sent througha2 reson a1,3000,500 ; 2 filtersaf<strong>in</strong> balance a2, asrc ; then balanced with sourceThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Amplitude Modifiers Page 53-1


53.2 damar dam asig, kthreshold, icomp1, icomp2, irtime, iftime53.2.1 DESCRIPTIONThis opcode dynamically modifies a ga<strong>in</strong> value applied to the <strong>in</strong>put sound ‘a<strong>in</strong>’ by compar<strong>in</strong>g itspower level to a given threshold level. The signal will be compressed/expanded with differentfactors regard<strong>in</strong>g that it is over or under the threshold.53.2.2 INITIALIZATIONicomp1 – compression ratio for upper zone.icomp2 – compression ratio for lower zone.irtime – ga<strong>in</strong> rise time <strong>in</strong> seconds. Time over which the ga<strong>in</strong> factor is allowed to raise of one unit.iftime – ga<strong>in</strong> fall time <strong>in</strong> seconds. Time over which the ga<strong>in</strong> factor is allowed to decrease of oneunit.53.2.3 PERFORMANCEasig – <strong>in</strong>put signalkthreshold – level of <strong>in</strong>put signal which acts as the threshold. Can be changed at k-time (e.g. forduck<strong>in</strong>g)Note on the compression factors: A compression ratio of one leaves the sound unchanged.Sett<strong>in</strong>g the ratio to a value smaller than one will compress the signal (reduce its volume) whilesett<strong>in</strong>g the ratio to a value greater than one will expand the signal (augment its volume).53.2.4 AUTHORMarc ResiboisBelgium1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Amplitude Modifiers Page 53-2


53.3 clipar clip asig, imeth, ilimit[, iarg]53.3.1 DESCRIPTIONClips an a-rate signal to a predef<strong>in</strong>ed limit, <strong>in</strong> a “soft” manner, us<strong>in</strong>g one of three methods.53.3.2 INITIALIZATIONimeth – selects the clipp<strong>in</strong>g method. The default is 0. The methods are:• 0 = Bram de Jong method (default)• 1 = s<strong>in</strong>e clipp<strong>in</strong>g• 2 = tanh clipp<strong>in</strong>gilimit – limit<strong>in</strong>g valueiarg (optional) – when imeth = 0, <strong>in</strong>dicates the po<strong>in</strong>t at which clipp<strong>in</strong>g starts, <strong>in</strong> the range 0 – 1.Not used when imeth = 1 or imeth = 2. Default is 0.5.53.3.3 PERFORMANCEasig – a-rate <strong>in</strong>put signalThe Bram de Jong method (imeth = 0) applies the algorithm:|x| > a: f(x) = s<strong>in</strong>(x) * (a+(x-a)/(1+((x-a)/(1-a)) 2|x| > 1: f(x) = s<strong>in</strong>(x) * (a+1)/2This method requires that asig be normalized to 1.The second method (imeth = 1) is the s<strong>in</strong>e clip:|x| < limit:f(x) = limit * s<strong>in</strong>(π*x/(2*limit))f(x) = limit * s<strong>in</strong>(x)The third method (imeth = 0) is the tanh clip:|x| < limit:f(x) = limit * tanh(x/limit)/tanh(1)f(x) = limit * s<strong>in</strong>(x)Note: Method 1 appears to be non-functional at release of <strong>Csound</strong> version 4.07.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Amplitude Modifiers Page 53-3


53.3.4 EXAMPLEa1 sound<strong>in</strong>a2 oscil 25000, 1asig clip a1+a2, 0, 30000, .75outasig53.3.5 AUTHORJohn ffitchUniversity of Bath, Codemist Ltd.Bath, UKAugust, 2000New <strong>in</strong> <strong>Csound</strong> version 4.07The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Amplitude Modifiers Page 53-4


54 SIGNAL MODIFIERS: SIGNAL LIMITERS54.1 limit, mirror, wrapir limit isig, ilow, ihighkr limit ksig, klow, khighar limit asig, klow, khighir wrap isig, ilow, ihighkr wrap ksig, klow, khighar wrap asig, klow, khighir mirror isig, ilow, ihighkr mirror ksig, klow, khighar mirror asig, klow, khigh54.1.1 DESCRIPTIONWraps the signal <strong>in</strong> various ways.54.1.2 INITIALIZATIONisig – <strong>in</strong>put signalilow – low thresholdihigh – high threshold54.1.3 PERFORMANCExsig – <strong>in</strong>put signalxlow – low thresholdxhigh – high thresholdlimit sets lower and upper limits on the xsig value they process. If xhigh is lower than xlow, thenthe output will be the average of the two – it will not be affected by xsig. mirror “reflects” thesignal that exceeds the low and high thresholds. wrap wraps-around the signal that exceeds thelow and high thresholds.These opcodes are useful <strong>in</strong> several situations, such as table <strong>in</strong>dex<strong>in</strong>g or for clipp<strong>in</strong>g andmodel<strong>in</strong>g i-rate, k-rate or a-rate signals. wrap is also useful for wrap-around of table data whenthe maximum <strong>in</strong>dex is not a power of two (see table and tablei). Another use of wrap is <strong>in</strong>cyclical event repeat<strong>in</strong>g, with arbitrary cycle length.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Signal Limiters Page 54-1


54.1.4 AUTHORSGabriel Maldonado (wrap, mirror)Rob<strong>in</strong> Whittle (limit)ItalyAustraliaNew <strong>in</strong> <strong>Csound</strong> version 3.49 New <strong>in</strong> <strong>Csound</strong> version 3.46The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Signal Limiters Page 54-2


55 SIGNAL MODIFIERS: DELAY55.1 delayr, delayw, delay, delay1ar delayr idlt[, iskip]delayw asigar delay asig, idlt[, iskip]ar delay1 asig[, iskip]55.1.1 DESCRIPTIONA signal can be read from or written <strong>in</strong>to a delay path, or it can be automatically delayed bysome time <strong>in</strong>terval.55.1.2 INITIALIZATIONidlt – requested delay time <strong>in</strong> seconds. This can be as large as available memory will permit. Thespace required for n seconds of delay is 4n * sr bytes. It is allocated at the time the <strong>in</strong>strument isfirst <strong>in</strong>itialized, and returned to the pool at the end of a score section.iskip (optional) – <strong>in</strong>itial disposition of delay-loop data space ( see reson). The default value is 0.55.1.3 PERFORMANCEdelayr reads from an automatically established digital delay l<strong>in</strong>e, <strong>in</strong> which the signal retrievedhas been resident for idlt seconds. This unit must be paired with and precede an accompany<strong>in</strong>gdelayw unit. Any other <strong>Csound</strong> statements can <strong>in</strong>tervene.delayw writes asig <strong>in</strong>to the delay area established by the preced<strong>in</strong>g delayr unit. Viewed as apair, these two units permit the formation of modified feedback loops, etc. However, there is alower bound on the value of idlt, which must be at least 1 control period (or 1/kr).delayr/delayw pairs may be <strong>in</strong>terleaved. Beg<strong>in</strong>n<strong>in</strong>g another delayr/delayw pair beforeterm<strong>in</strong>at<strong>in</strong>g a previous pair is no longer excluded. For the <strong>in</strong>terleaved pairs, the first delayr unitis associated with the first delayw unit, the second delayr unit with the second delayw unit, andso on. In this way, it is possible to implement cross-coupled feedback that is completed with<strong>in</strong>the same control-rate cycle. See Example 2. (This feature added <strong>in</strong> <strong>Csound</strong> version 3.57 by JensGroh and John ffitch).delay is a composite of the above two units, both read<strong>in</strong>g from and writ<strong>in</strong>g <strong>in</strong>to its own storagearea. It can thus accomplish signal time-shift, although modified feedback is not possible. Thereis no m<strong>in</strong>imum delay period.delay1 is a special form of delay that serves to delay the audio signal asig by just one sample. Itis thus functionally equivalent to “delay asig, 1/sr” but is more efficient <strong>in</strong> both time and space.This unit is particularly useful <strong>in</strong> the fabrication of generalized non-recursive filters.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Delay Page 55-1


55.1.4 EXAMPLESExample 1:tigoto cont<strong>in</strong> ; except on a tie,a2 delay a1, .05, 0 ; beg<strong>in</strong> 50 msec clean delay of sigcont<strong>in</strong>:Example 2:a<strong>in</strong>put1 = .....a<strong>in</strong>put2 = .....;Read delayed signal, first delayr <strong>in</strong>stance:adly1 delayr 0.11;Read delayed signal, second delayr <strong>in</strong>stance:adly2 delayr 0.07;Do some cross-coupled manipulation:afdbk1 = 0.7 * adly1 + 0.7 * adly2 + a<strong>in</strong>put1afdbk2 = -0.7 * adly1 + 0.7 * adly2 + a<strong>in</strong>put2;Feed back signal associated with first delayr <strong>in</strong>stance:delayw afdbk1;Feed back signal associated with second delayr <strong>in</strong>stance:delayw afdbk2outs adly1, adly2The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Delay Page 55-2


55.2 deltap, deltapi, deltapn, deltap3ar deltap kdltar deltapi xdltar deltapn xnumsampsar deltap3 xdlt55.2.1 DESCRIPTIONTap a delay l<strong>in</strong>e at variable offset times.55.2.2 PERFORMANCEThese units can tap <strong>in</strong>to a delayr/delayw pair, extract<strong>in</strong>g delayed audio from the idlt seconds ofstored sound. There can be any number of deltap and/or deltapi units between a read/write pair.Each receives an audio tap with no change of orig<strong>in</strong>al amplitude.deltap extracts sound by read<strong>in</strong>g the stored samples directly; deltapi extracts sound by<strong>in</strong>terpolated readout. By <strong>in</strong>terpolat<strong>in</strong>g between adjacent stored samples deltapi represents aparticular delay time with more accuracy, but it will take about twice as long to run.The arguments kdlt, xdlt specify the tapped delay time <strong>in</strong> seconds. Each can range from 1 ControlPeriod to the full delay time of the read/write pair; however, s<strong>in</strong>ce there is no <strong>in</strong>ternal check foradherence to this range, the user is wholly responsible. Each argument can be a constant, avariable, or a time-vary<strong>in</strong>g signal; the xdlt argument <strong>in</strong> deltapi implies that an audio-vary<strong>in</strong>gdelay is permitted there. deltapn is identical to deltapi, except delay time is specified <strong>in</strong> numberof samples, <strong>in</strong>stead of seconds (Hans Mikelson). deltap3 is experimental, and uses cubic<strong>in</strong>terpolation. (New <strong>in</strong> <strong>Csound</strong> version 3.50.)These units can provide multiple delay taps for arbitrary delay path and feedback networks. Theycan deliver either constant-time or time-vary<strong>in</strong>g taps, and are useful for build<strong>in</strong>g chorus effects,harmonizers, and Doppler shifts. Constant-time delay taps (and some slowly chang<strong>in</strong>g ones) donot need <strong>in</strong>terpolated readout; they are well served by deltap. Medium-paced or fast vary<strong>in</strong>gdlt’s, however, will need the extra services of deltapi.delayr/delayw pairs may be <strong>in</strong>terleaved. To associate a delay tap unit with a specific delayrunit, it not only has to be located between that delayr and the appropriate delayw unit, but mustalso precede any follow<strong>in</strong>g delayr units. See Example 2. (This feature added <strong>in</strong> <strong>Csound</strong> version3.57 by Jens Groh and John ffitch).N.B. k-rate delay times are not <strong>in</strong>ternally <strong>in</strong>terpolated, but rather lay down stepped time-shifts ofaudio samples; this will be found quite adequate for slowly chang<strong>in</strong>g tap times. For medium tofast-paced changes, however, one should provide a higher resolution audio-rate timeshift as<strong>in</strong>put.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Delay Page 55-3


55.2.3 EXAMPLESExample 1:asource buzz 1, 440, 20, 1atime l<strong>in</strong>seg 1, p3/2,.01, p3/2,1 ; trace a distance <strong>in</strong> secsampfac = 1/atime/atime ; and calc an amp factoradump delayr 1 ; set maximum distanceamove deltapi atime ; move sound source pastdelayw asource ; the listenerout amove * ampfacExample 2:a<strong>in</strong>put1 = .....a<strong>in</strong>put2 = .....kdlyt1 = .....kdlyt2 = .....;Read delayed signal, first delayr <strong>in</strong>stance:adump delayr 4.0adly1 deltap kdlyt1 ;associated with first delayr <strong>in</strong>stance;Read delayed signal, second delayr <strong>in</strong>stance:adump delayr 4.0adly2 deltap kdlyt2 ; associated with second delayr <strong>in</strong>stance;Do some cross-coupled manipulation:afdbk1 = 0.7 * adly1 + 0.7 * adly2 + a<strong>in</strong>put1afdbk2 = -0.7 * adly1 + 0.7 * adly2 + a<strong>in</strong>put2;Feed back signal, associated with first delayr <strong>in</strong>stance:delayw afdbk1;Feed back signal, associated with second delayr <strong>in</strong>stance:delayw afdbk2outs adly1, adly2The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Delay Page 55-4


55.3 multitapar multitap asig, itime1, iga<strong>in</strong>1, itime2, iga<strong>in</strong>2 . . .55.3.1 DESCRIPTIONMultitap delay l<strong>in</strong>e implementation.55.3.2 INITIALIZATIONThe arguments itime and iga<strong>in</strong> set the position and ga<strong>in</strong> of each tap.The delay l<strong>in</strong>e is fed by asig.55.3.3 EXAMPLEa1 oscil 1000, 100, 1a2 multitap a1, 1.2, .5, 1.4, .2outa2This results <strong>in</strong> two delays, one with length of 1.2 and ga<strong>in</strong> of .5, and one with length of 1.4 andga<strong>in</strong> of .2.55.3.4 AUTHORParis SmaragdisMIT, Cambridge1996The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Delay Page 55-5


55.4 vdelay, vdelay3ar vdelay asig, adel, imaxdel [, iskip]ar vdelay3 asig, adel, imaxdel [, iskip]55.4.1 DESCRIPTIONThis is an <strong>in</strong>terpolat<strong>in</strong>g variable time delay, it is not very different from the exist<strong>in</strong>gimplementation (deltapi), it is only easier to use. vdelay3 is experimental, and is the same asvdelay, except that it uses cubic <strong>in</strong>terpolation. (New <strong>in</strong> Version 3.50.)55.4.2 INITIALIZATIONimaxdel – Maximum value of delay <strong>in</strong> milliseconds. If adel ga<strong>in</strong>s a value greater than imaxdel itis folded around imaxdel. This should not happen.iskip – Skip <strong>in</strong>itialization if present and non-zero55.4.3 PERFORMANCEWith this unit generator it is possible to do Doppler effects or chorus<strong>in</strong>g and flang<strong>in</strong>g.asig – Input signal.adel – Current value of delay <strong>in</strong> milliseconds. Note that l<strong>in</strong>ear functions have no pitch changeeffects. Fast chang<strong>in</strong>g values of adel will cause discont<strong>in</strong>uities <strong>in</strong> the waveform result<strong>in</strong>g noise.55.4.4 EXAMPLEf1 0 8192 10 1ims = 100 ; Maximum delay time <strong>in</strong> mseca1 oscil 10000, 1737, 1 ; Make a signala2 oscil ims/2, 1/p3, 1 ; Make an LFOa2 = a2 + ims/2 ; Offset the LFO so that it is positivea3 vdelay a1, a2, ims ; Use the LFO to control delay timeout a3Two important po<strong>in</strong>ts here. First, the delay time must be always positive. And second, eventhough the delay time can be controlled <strong>in</strong> k-rate, it is not advised to do so, s<strong>in</strong>ce sudden timechanges will create clicks.55.4.5 AUTHORParis SmaragdisMIT, Cambridge1995The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Delay Page 55-6


56 SIGNAL MODIFIERS: REVERBERATION56.1 comb, alpass, reverbar comb asig, krvt, ilpt[, iskip]ar alpass asig, krvt, ilpt[, iskip]ar reverb asig, krvt[, iskip]56.1.1 DESCRIPTIONAn <strong>in</strong>put signal is reverberated for krvt seconds with “colored” (comb), flat (alpass), or “naturalroom” (reverb) frequency response.56.1.2 INITIALIZATIONilpt – loop time <strong>in</strong> seconds, which determ<strong>in</strong>es the “echo density” of the reverberation. This <strong>in</strong>turn characterizes the “color” of the comb filter whose frequency response curve will conta<strong>in</strong> ilpt* sr/2 peaks spaced evenly between 0 and sr/2 (the Nyquist frequency). Loop time can be aslarge as available memory will permit. The space required for an n second loop is 4n* sr bytes.comb and alpass delay space is allocated and returned as <strong>in</strong> delay.iskip (optional) – <strong>in</strong>itial disposition of delay-loop data space ( cf. reson). The default value is 0.56.1.3 PERFORMANCEThese filters reiterate <strong>in</strong>put with an echo density determ<strong>in</strong>ed by loop time ilpt. The attenuationrate is <strong>in</strong>dependent and is determ<strong>in</strong>ed by krvt, the reverberation time (def<strong>in</strong>ed as the time <strong>in</strong>seconds for a signal to decay to 1/1000, or 60dB down from its orig<strong>in</strong>al amplitude). Output froma comb filter will appear only after ilpt seconds; alpass output will beg<strong>in</strong> to appear immediately.A standard reverb unit is composed of four comb filters <strong>in</strong> parallel followed by two alpass units<strong>in</strong> series. Loop times are set for optimal “natural room response.” Core storage requirements forthis unit are proportional only to the sampl<strong>in</strong>g rate, each unit requir<strong>in</strong>g approximately 3K wordsfor every 10KC. The comb, alpass, delay, tone and other <strong>Csound</strong> units provide the means forexperiment<strong>in</strong>g with alternate reverberator designsS<strong>in</strong>ce output from the standard reverb will beg<strong>in</strong> to appear only after 1/20 second or so of delay,and often with less than three-fourths of the orig<strong>in</strong>al power, it is normal to output both the sourceand the reverberated signal. If krvt is <strong>in</strong>advertently set to a non-positive number, krvt will bereset automatically to 0.01. (New <strong>in</strong> <strong>Csound</strong> version 4.07.) Also, s<strong>in</strong>ce the reverberated soundwill persist long after the cessation of source events, it is normal to put reverb <strong>in</strong> a separate<strong>in</strong>strument to which sound is passed via a global variable, and to leave that <strong>in</strong>strument runn<strong>in</strong>gthroughout the performance.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Reverberation Page 56-1


56.1.4 EXAMPLEga1 <strong>in</strong>it 0; <strong>in</strong>it an audio receiver/mixer<strong>in</strong>str 1 ; <strong>in</strong>str (there may be many copies)a1 oscili 8000, cpspch(p5), 1 ; generate a source signalout a1 ; output the direct soundga1 =ga1 + a1 ; and add to audio receiverend<strong>in</strong><strong>in</strong>str 99 ; (highest <strong>in</strong>str number executed last)a3 reverb ga1, 1.5 ; reverberate whatever is <strong>in</strong> ga1out a3 ; and output the resultga1 = 0 ; empty the receiver for the next passend<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Reverberation Page 56-2


56.2 reverb2, nreverbar reverb2 asig, ktime, khdif [,iskip]ar nreverb asig, ktime, khdif [,iskip]56.2.1 DESCRIPTIONThis is a reverberator consist<strong>in</strong>g of 6 parallel comb-lowpass filters be<strong>in</strong>g fed <strong>in</strong>to a series of 5allpass filters. nreverb replaces reverb2 (version 3.48) and so both opcodes are identical.56.2.2 INITIALISATIONiskip – Skip <strong>in</strong>itialization if present and non zero56.2.3 PERFORMANCEThe <strong>in</strong>put signal asig is reverberated for ktime seconds. The parameter khdif controls the highfrequency diffusion amount. The values of khdif should be from 0 to 1. If khdif is set to 0 the allthe frequencies decay with the same speed. If khdif is 1, high frequencies decay faster than lowerones. If ktime is <strong>in</strong>advertently set to a non-positive number, ktime will be reset automatically to0.01. (New <strong>in</strong> <strong>Csound</strong> version 4.07.)56.2.4 EXAMPLEa1 oscil 10000, 100, 1a2 reverb2 a1, 2.5, .3out a1 + a2 * .2This results <strong>in</strong> a 2.5 sec reverb with faster high frequency attenuation.56.2.5 AUTHORSParis Smaragdis (reverb2)MIT, Cambridge1995Richard Karpen (nreverb)Seattle, Wash1998The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Reverberation Page 56-3


56.3 nestedapar nestedap asig, imode, imaxdel, idel1, iga<strong>in</strong>1[, idel2, iga<strong>in</strong>2\\[, idel3, iga<strong>in</strong>3]]56.3.1 DESCRIPTIONThree different nested all-pass filters, useful for implement<strong>in</strong>g reverbs.56.3.2 INITIALIZATIONimode – operat<strong>in</strong>g mode of the filter:1 = simple all-pass filter2 = s<strong>in</strong>gle nested all-pass filter3 = double nested all-pass filteridel1, idel2, idel3 – delay times of the filter stages. Delay times are <strong>in</strong> seconds and must begreater than zero. idel1 must be greater than the sum of idel2 and idel3.iga<strong>in</strong>1, iga<strong>in</strong>2, iga<strong>in</strong>3 – ga<strong>in</strong> of the filter stages.imaxdel – will be necessary if k-rate delays are implemented. Not currently used.56.3.3 PERFORMANCEasig – <strong>in</strong>put signalIf imode = 1, the filter takes the form:idel1, iga<strong>in</strong>1If imode = 2, the filter takes the form:idel1, iga<strong>in</strong>1idel2, iga<strong>in</strong>2The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Reverberation Page 56-4


If imode = 3, the filter takes the form:idel2,iga<strong>in</strong>2idel1, iga<strong>in</strong>1idel3,iga<strong>in</strong>356.3.4 EXAMPLE<strong>in</strong>str 5<strong>in</strong>snd = p4gasig disk<strong>in</strong> <strong>in</strong>snd, 1end<strong>in</strong><strong>in</strong>str 10imax = 1idel1 = p4iga<strong>in</strong>1 =p5idel2 = p6iga<strong>in</strong>2 =p7idel3 = p8iga<strong>in</strong>3 =p9idel4 = p10iga<strong>in</strong>4 =p11idel5 = p12iga<strong>in</strong>5 =p13idel6 = p14iga<strong>in</strong>6 =p15afdbk <strong>in</strong>it 0aout1 nestedap gasig+afdbk*.4, 3, imax, idel1, iga<strong>in</strong>1, idel2,\\iga<strong>in</strong>2, idel3, iga<strong>in</strong>3aout2 nestedap aout1, 2, imax, idel4, iga<strong>in</strong>4, idel5, iga<strong>in</strong>5aout nestedap aout2, 1, imax, idel6, iga<strong>in</strong>6afdbk butterlp aout, 1000outsgasig+(aout+aout1)/2, gasig-(aout+aout1)/2gasig = 0end<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Reverberation Page 56-5


;Scoref1 0 8192 10 1; Disk<strong>in</strong>; Sta Dur Sound<strong>in</strong>i5 0 3 1; Reverb; St Dur Del1 Gn1 Del2 Gn2 Del3 Gn3 Del4 Gn4 Del5 Gn5 Del6 Gn6i10 0 4 97 .11 23 .07 43 .09 72 .2 53 .2 119 .3e56.3.5 AUTHORHans MikelsonFebruary 1999New <strong>in</strong> <strong>Csound</strong> version 3.53The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Reverberation Page 56-6


57 SIGNAL MODIFIERS: WAVEGUIDES57.1 wguide1, wguide2ar wguide1 asig, xfreq, xcutoff, kfeedback;ar wguide2 asig, xfreq1, xfreq2, kcutoff1, kcutoff2, kfeedback1,\kfeedback257.1.1 DESCRIPTIONSimple waveguide blocks57.1.2 PERFORMANCEasig – the <strong>in</strong>put of excitation noisexfreq – the frequency (i.e. the <strong>in</strong>verse of delay time) Changed to x-rate <strong>in</strong> <strong>Csound</strong> version 3.59.kcutoff1, kcutoff2 – the filter cutoff frequency <strong>in</strong> Hzxcutoff – the filter cutoff frequency <strong>in</strong> Hz. Changed to x-rate for wguide1 <strong>in</strong> <strong>Csound</strong> version3.59.kfeedback – the feedback factorwguide1 is the most elemental waveguide model, consist<strong>in</strong>g of one delayl<strong>in</strong>e and one first-orderlowpass filter.wguide2 is a model of beaten plate consist<strong>in</strong>g of two parallel delayl<strong>in</strong>es and two first-orderlowpass filters. The two feedback l<strong>in</strong>es are mixed and sent to the delay aga<strong>in</strong> each cycle.Implement<strong>in</strong>g waveguide algorithms as opcodes, <strong>in</strong>stead of as orc <strong>in</strong>str, allows the user to set krdifferent than sr, allow<strong>in</strong>g better performance particularly when us<strong>in</strong>g real-time.wguide1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Waveguides Page 57-1


wguide257.1.3 AUTHORGabriel MaldonadoItalyOctober, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.49)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Waveguides Page 57-2


57.2 stresonar streson asig, kfr, ifdbga<strong>in</strong>An audio signal is modified by a str<strong>in</strong>g resonator with variable fundamental frequency.57.2.1 INITIALIZATIONifdbga<strong>in</strong> – feedback ga<strong>in</strong>, between 0 and 1, of the <strong>in</strong>ternal delay l<strong>in</strong>e. A value close to 1 creates aslower decay and a more pronounced resonance. Small values may leave the <strong>in</strong>putsignal unaffected. Depend<strong>in</strong>g on the filter frequency, typical values are > .9.57.2.2 PERFORMANCEstreson passes the <strong>in</strong>put asig through a network composed of comb, low-pass and all-pass filters,similar to the one used <strong>in</strong> some versions of the Karplus-Strong algorithm, creat<strong>in</strong>g a str<strong>in</strong>gresonator effect. The fundamental frequency of the “str<strong>in</strong>g” is controlled by the k-rate variablekfr. This opcode can be used to simulate sympathetic resonances to an <strong>in</strong>put signal.streson is an adaptation of the Str<strong>in</strong>gFlt object of the SndObj Sound Object Library developedby the author.57.2.3 AUTHORVictor Lazzar<strong>in</strong>iMusic DepartmentNational University of Ireland, MaynoothMaynooth, Co. Kildare1998 (New <strong>in</strong> <strong>Csound</strong> version 3.494)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Waveguides Page 57-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Waveguides Page 57-4


58 SIGNAL MODIFIERS: SPECIAL EFFECTS58.1 harmonar harmon asig, kestfrq, kmaxvar, kgenfreq1, kgenfreq2, imode,\\im<strong>in</strong>frq, iprd58.1.1 DESCRIPTIONAnalyze an audio <strong>in</strong>put and generate harmoniz<strong>in</strong>g voices <strong>in</strong> synchrony.58.1.2 INITIALIZATIONimode – <strong>in</strong>terpret<strong>in</strong>g mode for the generat<strong>in</strong>g frequency <strong>in</strong>puts kgenfreq1, kgenfreq2. 0: <strong>in</strong>putvalues are ratios with respect to the audio signal analyzed frequencies. 1: <strong>in</strong>put values are theactual requested frequencies <strong>in</strong> Hz.im<strong>in</strong>frq – the lowest expected frequency (<strong>in</strong> Hz) of the audio <strong>in</strong>put. This parameter determ<strong>in</strong>eshow much of the <strong>in</strong>put is saved for the runn<strong>in</strong>g analysis, and sets a lower bound on the <strong>in</strong>ternalpitch tracker.iprd – period of analysis (<strong>in</strong> seconds). S<strong>in</strong>ce the <strong>in</strong>ternal pitch analysis can be time-consum<strong>in</strong>g,the <strong>in</strong>put is typically analyzed only each 20 to 50 milliseconds.58.1.3 PERFORMANCEThis unit is a harmonizer, able to provide up to two additional voices with the same amplitudeand spectrum as the <strong>in</strong>put. The <strong>in</strong>put analysis is assisted by two th<strong>in</strong>gs: an <strong>in</strong>put estimatedfrequency kestfrq (<strong>in</strong> Hz), and a fractional maximum variance kmaxvar about that estimate whichserves to limit the size of the search. Once the real <strong>in</strong>put frequency is determ<strong>in</strong>ed, the most recentpulse shape is used to generate the other voices at their requested frequencies.The three frequency <strong>in</strong>puts can be derived <strong>in</strong> various ways from a score file or MIDI source. Thefirst is the expected pitch, with a variance parameter allow<strong>in</strong>g for <strong>in</strong>flections or <strong>in</strong>accuracies; ifthe expected pitch is zero the harmonizer will be silent. The second and third pitches control theoutput frequencies; if either is zero the harmonizer will output only the non-zero request; if bothare zero the harmonizer will be silent. When the requested frequency is higher than the <strong>in</strong>put, theprocess requires additional computation due to overlapped output pulses. This is currentlylimited for efficiency reasons, with the result that only one voice can be higher than the <strong>in</strong>put atany one time.This unit is useful for supply<strong>in</strong>g a background chorus effect on demand, or for correct<strong>in</strong>g thepitch of a faulty <strong>in</strong>put vocal. There is essentially no delay between <strong>in</strong>put and output. Output<strong>in</strong>cludes only the generated parts, and does not <strong>in</strong>clude the <strong>in</strong>put.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-1


58.1.4 EXAMPLEasig1 <strong>in</strong> ; get the live <strong>in</strong>putkcps1 cpsmidib ; and its target pitchasig2 harmon asig1, kcps1, .3, kcps1, kcps1 * 1.25, 1, 110, .04 ; addmaj 3rdout asig2 ; output just the corrected and added voices58.1.5 AUTHORBarry VercoeMIT, Cambridge, Mass1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-2


58.2 flangerar flanger asig, adel, kfeedback[, imaxd ]58.2.1 DESCRIPTIONA user controlled flanger.58.2.2 INITIALIZATIONimaxd(optional) – maximum delay <strong>in</strong> seconds (needed for <strong>in</strong>itial memory allocation)58.2.3 PERFORMANCEasig – <strong>in</strong>put signaladel – delay <strong>in</strong> secondskfeedback – feedback amount (<strong>in</strong> normal tasks this should not exceed 1, even if bigger values areallowed)This unit is useful for generat<strong>in</strong>g choruses and flangers. The delay must be varied at a-rateconnect<strong>in</strong>g adel to an oscillator output. Also the feedback can vary at k-rate. This opcode isimplemented to allow kr different than sr (else delay could not be lower than ksmps) enhanc<strong>in</strong>greal-time performance. This unit is very similar to wguide1, the only difference is flanger doesnot have the lowpass filter.58.2.4 AUTHORGabriel MaldonadoItalyNew <strong>in</strong> <strong>Csound</strong> version 3.49flangerThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-3


58.3 distort1ar distort1 asig[, kprega<strong>in</strong>[, kpostga<strong>in</strong>[, kshape1[, kshape2]]]]58.3.1 DESCRIPTIONImplementation of modified hyperbolic tangent distortion. distort1 can be used to generate waveshap<strong>in</strong>g distortion based on a modification of the tanh function.exp(asig * (prega<strong>in</strong> + shape1)) - exp(asig*(prega<strong>in</strong>+shape2))aout = -----------------------------------------------------------exp(asig*prega<strong>in</strong>)+ exp(-asig*prega<strong>in</strong>)58.3.2 PERFORMANCEasig – is the <strong>in</strong>put signal.kprega<strong>in</strong> – determ<strong>in</strong>es the amount of ga<strong>in</strong> applied to the signal before waveshap<strong>in</strong>g. A value of 1gives slight distortion.kpostga<strong>in</strong> – determ<strong>in</strong>es the amount of ga<strong>in</strong> applied to the signal after waveshap<strong>in</strong>g.kshape1 – determ<strong>in</strong>es the shape of the positive part of the curve. A value of 0 gives a flat clip,small positive values give sloped shap<strong>in</strong>g.kshape2 – determ<strong>in</strong>es the shape of the negative part of the curve.All arguments except asig, were made optional <strong>in</strong> <strong>Csound</strong> version 3.52.58.3.3 EXAMPLEgadist <strong>in</strong>it 0<strong>in</strong>str 1iamp = p4ifqc = cpspch(p5)asig pluck iamp, ifqc, ifqc, 0, 1gadist = gadist + asigend<strong>in</strong><strong>in</strong>str 50kpre <strong>in</strong>it p4kpost <strong>in</strong>it p5kshap1 <strong>in</strong>it p6kshap2 <strong>in</strong>it p7aout distort1 gadist, kpre, kpost, kshap1, kshap2outs aout, aoutgadist = 0end<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-4


; Sta Dur Amp Pitchi1 0.0 3.0 10000 6.00i1 0.5 2.5 10000 7.00i1 1.0 2.0 10000 7.07i1 1.5 1.5 10000 8.00; Sta Dur PreGa<strong>in</strong> PostGa<strong>in</strong> Shape1 Shape2i50 0 3 2 1 0 0e58.3.4 AUTHORHans MikelsonDecember 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.50)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-5


58.4 phaser1, phaser2ar phaser1 asig, kfreq, iord, kfeedback[, iskip]ar phaser2 asig, kfreq, kq, iord, imode, ksep, kfeedback58.4.1 DESCRIPTIONAn implementation of iord number of first-order (phaser1) or second-order (phaser2) allpassfilters <strong>in</strong> series.58.4.2 INITIALIZATIONiord – the number of allpass stages <strong>in</strong> series. For phaser1, these are first-order filters, and iordcan range from 1 to 4999. For phaser2, these are second-order filters, and iord can range from 1to 2499. With higher orders, the computation time <strong>in</strong>creases.iskip – used to control <strong>in</strong>itial disposition of <strong>in</strong>ternal data space. S<strong>in</strong>ce filter<strong>in</strong>g <strong>in</strong>corporates afeedback loop of previous output, the <strong>in</strong>itial status of the storage space used is significant. A zerovalue will clear the space; a non-zero value will allow previous <strong>in</strong>formation to rema<strong>in</strong>. Thedefault value is 0.imode – used <strong>in</strong> calculation of notch frequencies.58.4.3 PERFORMANCEkfreq – frequency (<strong>in</strong> Hz) of the filter(s). For phaser1, this is the frequency at which each filter<strong>in</strong> the series shifts its <strong>in</strong>put by 90 degrees. For phaser2, this is the center frequency of the notchof the first allpass filter <strong>in</strong> the series. This frequency is used as the base frequency from whichthe frequencies of the other notches are derived.kq – Q of each notch. Higher Q values result <strong>in</strong> narrow notches. A Q between 0.5 and 1 results <strong>in</strong>the strongest “phas<strong>in</strong>g” effect, but higher Q values can be used for special effects.kfeedback – amount of the output which is fed back <strong>in</strong>to the <strong>in</strong>put of the allpass cha<strong>in</strong>. Withlarger amounts of feedback, more prom<strong>in</strong>ent notches appear <strong>in</strong> the spectrum of the output.kfeedback must be between -1 and +1. for stability.ksep – scal<strong>in</strong>g factor used, <strong>in</strong> conjunction with imode, to determ<strong>in</strong>e the frequencies of theadditional notches <strong>in</strong> the output spectrum.phaser1 implements iord number of first-order allpass sections, serially connected, all shar<strong>in</strong>gthe same coefficient. Each allpass section can be represented by the follow<strong>in</strong>g differenceequation:y(n) = C * x(n) + x(n-1) - C * y(n-1)where x(n) is the <strong>in</strong>put, x(n-1) is the previous <strong>in</strong>put, y(n) is the output, y(n-1) is the previousoutput, and C is a coefficient which is calculated from the value of kfreq, us<strong>in</strong>g the bil<strong>in</strong>ear z-transform.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-6


By slowly vary<strong>in</strong>g kfreq, and mix<strong>in</strong>g the output of the allpass cha<strong>in</strong> with the <strong>in</strong>put, the classic“phase shifter” effect is created, with notches mov<strong>in</strong>g up and down <strong>in</strong> frequency. This works bestwith iord between 4 and 16. When the <strong>in</strong>put to the allpass cha<strong>in</strong> is mixed with the output, 1 notchis generated for every 2 allpass stages, so that with iord = 6, there will be 3 notches <strong>in</strong> the output.With higher values for iord, modulat<strong>in</strong>g kfreq will result <strong>in</strong> a form of nonl<strong>in</strong>ear pitch modulation.phaser2 implements iord number of second-order allpass sections, connected <strong>in</strong> series. The useof second-order allpass sections allows for the precise placement of the frequency, width, anddepth of notches <strong>in</strong> the frequency spectrum. iord is used to directly determ<strong>in</strong>e the number ofnotches <strong>in</strong> the spectrum; e.g. for iord = 6, there will be 6 notches <strong>in</strong> the output spectrum.There are two possible modes for determ<strong>in</strong><strong>in</strong>g the notch frequencies. When imode = 1, the notchfrequencies are determ<strong>in</strong>ed the follow<strong>in</strong>g function:frequency of notch N = kbf + (ksep * kbf * N-1)For example, with imode = 1 and ksep = 1, the notches will be <strong>in</strong> harmonic relationship with thenotch frequency determ<strong>in</strong>ed by kfreq (i.e. if there are 8 notches, with the first at 100 Hz, the nextnotches will be at 200, 300, 400, 500, 600, 700, and 800 Hz). This is useful for generat<strong>in</strong>g a“comb filter<strong>in</strong>g” effect, with the number of notches determ<strong>in</strong>ed by iord. Different values of ksepallow for <strong>in</strong>harmonic notch frequencies and other special effects. ksep can be swept to create anexpansion or contraction of the notch frequencies. A useful visual analogy for the effect ofsweep<strong>in</strong>g ksep would be the bellows of an accordion as it is be<strong>in</strong>g played – the notches will beseperated, then compressed together, as ksep changes.When imode = 2, the subsequent notches are powers of the <strong>in</strong>put parameter ksep times the <strong>in</strong>itialnotch frequency specified by kfreq. This can be used to set the notch frequencies to octaves andother musical <strong>in</strong>tervals. For example, the follow<strong>in</strong>g l<strong>in</strong>es will generate 8 notches <strong>in</strong> the outputspectrum, with the notches spaced at octaves of kfreq:aphs phaser2 a<strong>in</strong>, kfreq, 0.5, 8, 2, 2, 0aout = a<strong>in</strong> + aphsWhen imode = 2, the value of ksep must be greater than 0. ksep can be swept to create acompression and expansion of notch frequencies (with more dramatic effects than when imode =1).58.4.4 EXAMPLES; Orchestra for demonstration of phaser1 and phaser2sr = 44100kr = 4410ksmps = 10nchnls = 1<strong>in</strong>str 1; demonstration of phase shift<strong>in</strong>g; abilities of phaser1.; Input mixed with output of; phaser1 to generate notches.; Shows the effects of different; iorder values on the soundThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-7


idur = p3iamp = p4 * .05iorder = p5 ; number of 1st-order stages <strong>in</strong>; phaser1 network.; Divide iorder by 2 to get the; number of notches.ifreq = p6 ; frequency of modulation of; phaser1ifeed = p7 ; amount of feedback for phaser1kamp l<strong>in</strong>seg 0, .2, iamp, idur - .2, iamp, .2, 0iharms = (sr*.4) / 100asig gbuzz 1, 100, iharms, 1, .95, 2 ; "Sawtooth" waveform; modulation oscillator for phaser1 ugen.kfreq oscili 5500, ifreq, 1kmod = kfreq + 5600aphs phaser1 asig, kmod, iorder, ifeedout(asig + aphs) * iampend<strong>in</strong><strong>in</strong>str 2; demonstration of phase shift<strong>in</strong>g; abilities of phaser2. Input; mixed with output of phaser2 to; generate notches. Demonstrates; the <strong>in</strong>teraction of imode and; ksep.idur = p3iamp = p4 * .04iorder = p5 ; number of 2nd-order stages <strong>in</strong>; phaser2 networkifreq = p6 ; not usedifeed = p7 ; amount of feedback for phaser2imode = p8 ; mode for frequency scal<strong>in</strong>gisep = p9 ; used with imode to determ<strong>in</strong>e; notch frequencieskamp l<strong>in</strong>seg 0, .2, iamp, idur - .2, iamp, .2, 0iharms = (sr*.4) / 100asig gbuzz 1, 100, iharms, 1, .95, 2 ; "Sawtooth" waveform; exponentially decay<strong>in</strong>g function, to control notch frequencieskl<strong>in</strong>e expseg 1, idur, .005aphs phaser2 asig, kl<strong>in</strong>e * 2000, .5, iorder, imode, isep, ifeedout(asig + aphs) * iampend<strong>in</strong>; score file for abovef1 0 16384 9 .5 -1 0 ; <strong>in</strong>verted half-s<strong>in</strong>e, used; for modulat<strong>in</strong>g phaser1 frequencyf2 0 8192 9 1 1 .25 ; cos<strong>in</strong>e wave for gbuzzThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-8


; phaser1i1 0 5 7000 4 .2 .9i1 6 5 7000 6 .2 .9i1 12 5 7000 8 .2 .9i1 18 5 7000 16 .2 .9i1 24 5 7000 32 .2 .9i1 30 5 7000 64 .2 .9; phaser2, imode=1i2 37 10 7000 8 .2 .9 1 .33i2 48 10 7000 8 .2 .9 1 2; phaser2, imode=2i2 60 10 7000 8 .2 .9 2 .33i2 72 10 7000 8 .2 .9 2 2e58.4.5 TECHNICAL HISTORYA general description of the differences between flang<strong>in</strong>g and phas<strong>in</strong>g can be found <strong>in</strong> Hartmann[1]. An early implementation of first-order allpass filters connected <strong>in</strong> series can be found <strong>in</strong>Beigel [2], where the bil<strong>in</strong>ear z-transform is used for determ<strong>in</strong><strong>in</strong>g the phase shift frequency ofeach stage. Cron<strong>in</strong> [3] presents a similar implementation for a four-stage phase shift<strong>in</strong>g network.Chamberl<strong>in</strong> [4] and Smith [5] both discuss us<strong>in</strong>g second-order allpass sections for greater controlover notch depth, width, and frequency.58.4.6 REFERENCES1. Hartmann, W.M. “Flang<strong>in</strong>g and Phasers.” Journal of the Audio Eng<strong>in</strong>eer<strong>in</strong>g Society, Vol. 26,No. 6, pp. 439-443, June 1978.2. Beigel, Michael I. “A Digital ‘Phase Shifter’ for Musical Applications, Us<strong>in</strong>g the Bell Labs(Alles-Fischer) Digital Filter Module.” Journal of the Audio Eng<strong>in</strong>eer<strong>in</strong>g Society, Vol. 27,No. 9, pp. 673-676,September 1979.3. Cron<strong>in</strong>, Dennis. “Exam<strong>in</strong><strong>in</strong>g Audio DSP Algorithms.” Dr. Dobb’s Journal, July 1994, p. 78-83.4. Chamberl<strong>in</strong>, Hal. Musical Applications of Microprocessors. Second edition. Indianapolis,Indiana: Hayden Books, 1985.5. Smith, Julius O. “An Allpass Approach to Digital Phas<strong>in</strong>g and Flang<strong>in</strong>g.” Proceed<strong>in</strong>gs of the1984 ICMC, p. 103-108.58.4.7 AUTHORSean CostelloSeattle, Wash<strong>in</strong>gton1999New <strong>in</strong> <strong>Csound</strong> version 4.0The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-9


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Special Effects Page 58-10


59 SIGNAL MODIFIERS: CONVOLUTION ANDMORPHING59.1 convolvear1[,ar2] convolve a<strong>in</strong>, ifilcod, ichannel[,ar3][,ar4]59.1.1 DESCRIPTIONOutput is the convolution of signal a<strong>in</strong> and the impulse response conta<strong>in</strong>ed <strong>in</strong> ifilcod. If morethan one output signal is supplied, each will be convolved with the same impulse response. Notethat it is considerably more efficient to use one <strong>in</strong>stance of the operator when process<strong>in</strong>g a mono<strong>in</strong>put to create stereo, or quad, outputs. Note: this opcode can also be written convle.59.1.2 INITIALIZATIONifilcod – <strong>in</strong>teger or character-str<strong>in</strong>g denot<strong>in</strong>g an impulse response data file. An <strong>in</strong>teger denotesthe suffix of a file convolve.m; a character str<strong>in</strong>g (<strong>in</strong> double quotes) gives a filename, optionally afull pathname. If not a fullpath, the file is sought first <strong>in</strong> the current directory, then <strong>in</strong> the onegiven by the environment variable SADIR (if def<strong>in</strong>ed). The data file conta<strong>in</strong>s the Fouriertransform of an impulse response. Memory usage depends on the size of the data file, which isread and held entirely <strong>in</strong> memory dur<strong>in</strong>g computation, but which is shared by multiple calls.59.1.3 PERFORMANCEconvolve implements Fast Convolution. The output of this operator is delayed with respect to the<strong>in</strong>put. The follow<strong>in</strong>g formulas should be used to calculate the delay:For (1/kr)


The author <strong>in</strong>tends to create a higher-level operator at some stage, that would mix the wet & drysignals, us<strong>in</strong>g the correct amount of delay automatically.59.1.4 EXAMPLE- Create frequency doma<strong>in</strong> impulse response file:c:\ <strong>Csound</strong> -Ucvanal l1_44.wav l1_44.cv- Determ<strong>in</strong>e duration of impulse response. For high accuracy, determ<strong>in</strong>e the number of sampleframes <strong>in</strong> the impulse response soundfile, and then compute the duration with:duration = (sample frames)/(sample rate of soundfile)This is due to the fact that the SNDINFO utility only reports the duration to the nearest 10ms. Ifyou have a utility that reports the duration to the required accuracy, then you can simply use thereported value directly.c:\ snd<strong>in</strong>fo l1_44.wavlength = 60822 samples, sample rate = 44100Duration = 60822/44100 = 1.379s.- Determ<strong>in</strong>e <strong>in</strong>itial delay, if any, of impulse response. If the impulse response has not had the<strong>in</strong>itial delay removed, then you can skip this step. If it has been removed, then the only way youwill know the <strong>in</strong>itial delay is if the <strong>in</strong>formation has been provided separately. For this example,let’s assume that the <strong>in</strong>itial delay is 60ms. (0.06s)- Determ<strong>in</strong>e the required delay to apply to the dry signal, to align it with the convolved signal:If kr = 441:1/kr = 0.0023, which is


adry sound<strong>in</strong> “anechoic.wav” ; <strong>in</strong>put (dry) audioawet1,awet2 convolve adry,”l1_44.cv” ; stereo convolved (wet) audioadrydel delay (1-imix)*adry,idel ; Delay dry signal, to align itwith; convolved signal. Apply level; adjustment here too.outs ivol*(adrydel+imix*awet1),ivol*(adrydel+imix*awet2); Mix wet & dry signals, and outputend<strong>in</strong>59.1.5 AUTHORGreg Sullivan1996The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Convolution and Morph<strong>in</strong>g Page 59-3


59.2 cross2ar cross2 a<strong>in</strong>1, a<strong>in</strong>2, isize, ioverlap, iw<strong>in</strong>, kbias59.2.1 DESCRIPTIONThis is an implementation of cross synthesis us<strong>in</strong>g FFT’s.59.2.2 INITIALIZATIONisize – This is the size of the FFT to be performed. The larger the size the better thefrequency response but a sloppy time response.ioverlap – This is the overlap factor of the FFT’s, must be a power of two. The best sett<strong>in</strong>gsare 2 and 4. A big overlap takes a long time to compile.iw<strong>in</strong> – This is the ftable that conta<strong>in</strong>s the w<strong>in</strong>dow to be used <strong>in</strong> the analysis.59.2.3 PERFORMANCEa<strong>in</strong>1 – The stimulus sound. Must have high frequencies for best results.a<strong>in</strong>2 – The modulat<strong>in</strong>g sound. Must have a mov<strong>in</strong>g frequency response (like speech) for bestresults.kbias – The amount of cross synthesis. 1 is the normal, 0 is no cross synthesis.59.2.4 EXAMPLESa1 oscil 10000, 1, 1a2 rand 10000a3 cross2 a2, a1, 2048, 4, 2, 1out a3If ftable one is a speech sound, this will result <strong>in</strong> speak<strong>in</strong>g white noise.ftable 2 must be a w<strong>in</strong>dow function (GEN20).59.2.5 AUTHORParis SmaragdisMIT, Cambridge1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Convolution and Morph<strong>in</strong>g Page 59-4


60 SIGNAL MODIFIERS: PANNING ANDSPATIALIZATION60.1 pana1, a2, a3, a4 pan asig, kx, ky, ifn[, imode[, ioffset]]60.1.1 DESCRIPTIONDistribute an audio signal amongst four channels with localization control.60.1.2 INITIALIZATIONifn – function table number of a stored pattern describ<strong>in</strong>g the amplitude growth <strong>in</strong> a speakerchannel as sound moves towards it from an adjacent speaker. Requires extended guard-po<strong>in</strong>t.imode (optional) – mode of the kx, ky position values. 0 signifies raw <strong>in</strong>dex mode, 1 means the<strong>in</strong>puts are normalized (0 – 1). The default value is 0.ioffset (optional) – offset <strong>in</strong>dicator for kx, ky. 0 <strong>in</strong>fers the orig<strong>in</strong> to be at channel 3 (left rear); 1requests an axis shift to the quadraphonic center. The default value is 0.60.1.3 PERFORMANCEpan takes an <strong>in</strong>put signal asig and distributes it amongst four outputs (essentially quad speakers)accord<strong>in</strong>g to the controls kx and ky. For normalized <strong>in</strong>put (mode=1) and no offset, the four outputlocations are <strong>in</strong> order: left-front at (0,1), right-front at (1,1), left-rear at the orig<strong>in</strong> (0,0), and rightrearat (1,0). In the notation (kx, ky), the coord<strong>in</strong>ates kx and ky, each rang<strong>in</strong>g 0 – 1, thus controlthe ‘rightness’ and ‘forwardness’ of a sound location.Movement between speakers is by amplitude variation, controlled by the stored function tableifn. As kx goes from 0 to 1, the strength of the right-hand signals will grow from the left-mosttable value to the right-most, while that of the left-hand signals will progress from the right-mosttable value to the left-most. For a simple l<strong>in</strong>ear pan, the table might conta<strong>in</strong> the l<strong>in</strong>ear function 0– 1. A more correct pan that ma<strong>in</strong>ta<strong>in</strong>s constant power would be obta<strong>in</strong>ed by stor<strong>in</strong>g the firstquadrant of a s<strong>in</strong>usoid. S<strong>in</strong>ce pan will scale and truncate kx and ky <strong>in</strong> simple table lookup, amedium-large table (say 8193) should be used.kx, ky values are not restricted to 0 – 1. A circular motion pass<strong>in</strong>g through all four speakers(<strong>in</strong>scribed) would have a diameter of root 2, and might be def<strong>in</strong>ed by a circle of radius R = root1/2 with center at (.5,.5). kx, ky would then come from Rcos(angle), Rs<strong>in</strong>(angle), with an implicitorig<strong>in</strong> at (.5,.5) (i.e. ioffset = 1). Unscaled raw values operate similarly. Sounds can thus belocated anywhere <strong>in</strong> the polar or Cartesian plane; po<strong>in</strong>ts ly<strong>in</strong>g outside the speaker square areprojected correctly onto the square’s perimeter as for a listener at the center.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-1


60.1.4 EXAMPLE<strong>in</strong>str 1k1 phasor 1/p3 ; fraction of circlek2 tablei k1, 1, 1 ; s<strong>in</strong> of angle (s<strong>in</strong>usoid <strong>in</strong> f1)k3 tablei k1, 1, 1, .25, 1 ; cos of angle (s<strong>in</strong> offset 1/4 circle)a1 oscili 10000,440, 1 ; audio signal..a1,a2,a3,a4 pan a1, k2/2, k3/2, 2, 1, 1; sent <strong>in</strong> a circle (f2=1st quad s<strong>in</strong>)outq a1, a2, a3, a4end<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-2


60.2 locsig, locsenda1, a2 locsig asig, kdegree, kdistance, kreverbsenda1, a2, a3, a4 locsig asig, kdegree, kdistance, kreverbsenda1, a2 locsenda1, a2, a3, a4 locsend60.2.1 DESCRIPTIONlocsig takes an <strong>in</strong>put signal and distributes it among 2 or 4 channels us<strong>in</strong>g values <strong>in</strong> degrees tocalculate the balance between adjacent channels. It also takes arguments for distance (used toattenuate signals that are to sound as if they are some distance further than the loudspeakeritself), and for the amount the signal that will be sent to reverberators. This unit is based upon theexample <strong>in</strong> the Charles Dodge/Thomas Jerse book, Computer Music, page 320.locsend depends upon the existence of a previously def<strong>in</strong>ed locsig. The number of output signalsmust match the number <strong>in</strong> the previous locsig. The output signals from locsend are derived fromthe values given for distance and reverb <strong>in</strong> the locsig and are ready to be sent to local or globalreverb units (see example below). The reverb amount and the balance between the 2 or 4channels are calculated <strong>in</strong> the same way as described <strong>in</strong> the Dodge book (an essential text!).60.2.2 PERFORMANCEkdegree – value between 0 and 360 for placement of the signal <strong>in</strong> a 2 or 4 channel spaceconfigured as: a1=0, a2=90, a3=180, a4=270 (kdegree=45 would balanced the signal equallybetween a1 and a2). locsig maps kdegree to s<strong>in</strong> and cos functions to derive the signal balances(i.e.: asig=1, kdegree=45, a1=a2=.707).kdistance – value >= 1 used to attenuate the signal and to calculate reverb level to simulatedistance cues. As kdistance gets larger the sound should get softer and somewhat morereverberant (assum<strong>in</strong>g the use of locsend <strong>in</strong> this case).kreverbsend – the percentage of the direct signal that will be factored along with the distance anddegree values to derive signal amounts that can be sent to a reverb unit such as reverb, orreverb2.60.2.3 EXAMPLEasig some audio signalkdegree l<strong>in</strong>e 0, p3, 360kdistance l<strong>in</strong>e 1, p3, 10a1, a2, a3, a4 locsig asig, kdegree, kdistance, .1ar1, ar2, ar3, ar4 locsendga1 = ga1+ar1ga2 = ga2+ar2ga3 = ga3+ar3ga4 = ga4+ar4outq a1, a2, a3, a4end<strong>in</strong><strong>in</strong>str 99 ; reverb <strong>in</strong>strumenta1 reverb2 ga1, 2.5, .5a2 reverb2 ga2, 2.5, .5The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-3


a3 reverb2 ga3, 2.5, .5a4 reverb2 ga4, 2.5, .5outq a1, a2, a3, a4ga1 = 0ga2 = 0ga3 = 0ga4 = 0In the above example, the signal, asig, is sent around a complete circle once dur<strong>in</strong>g the durationof a note while at the same time it becomes more and more “distant” from the listeners’ location.locsig sends the appropriate amount of the signal <strong>in</strong>ternally to locsend. The outputs of thelocsend are added to global accumulators <strong>in</strong> a common <strong>Csound</strong> style and the global signals areused as <strong>in</strong>puts to the reverb units <strong>in</strong> a separate <strong>in</strong>strument.locsig is useful for quad and stereo pann<strong>in</strong>g as well as fixed placed of sounds anywhere betweentwo loudspeakers. Below is an example of the fixed placement of sounds <strong>in</strong> a stereo field.<strong>in</strong>str 1a1, a2 locsig asig, p4, p5, .1ar1, ar2 locsendga1 = ga1+ar1ga2 = ga2+ar2outs a1, a2end<strong>in</strong><strong>in</strong>str 99; reverb....end<strong>in</strong>A few notes:;place the sound <strong>in</strong> the left speaker and neari1 0 1 0 1;place the sound <strong>in</strong> the right speaker and fari1 1 1 90 25;place the sound equally between left and right and <strong>in</strong> the middle grounddistancei1 2 1 45 12eThe next example shows a simple <strong>in</strong>tuitive use of the distance value to simulate Doppler shift.The same value is used to scale the frequency as is used as the distance <strong>in</strong>put to locsig.kdistance l<strong>in</strong>e 1, p3, 10kfreq = (ifreq * 340) / (340 + kdistance)asig oscili iamp, kfreq, 1kdegree l<strong>in</strong>e 0, p3, 360a1, a2, a3, a4 locsig asig, kdegree, kdistance, .1ar1, ar2, ar3, ar4 locsend60.2.4 AUTHORRichard KarpenSeattle, Wash1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-4


60.3 space, spsend, spdista1, a2, a3, a4 space asig, ifn, ktime, kreverbsend [,kx, ky]a1, a2, a3, a4 spsendk1 spdist ifn, ktime, [,kx, ky]60.3.1 DESCRIPTIONspace takes an <strong>in</strong>put signal and distributes it among 4 channels us<strong>in</strong>g Cartesian xy coord<strong>in</strong>ates tocalculate the balance of the outputs. The xy coord<strong>in</strong>ates can be def<strong>in</strong>ed <strong>in</strong> a separate text file andaccessed through a Function statement <strong>in</strong> the score us<strong>in</strong>g GEN28, or they can be specified us<strong>in</strong>gthe optional kx, ky arguments. There advantages to the former are:1. A graphic user <strong>in</strong>terface can be used to draw and edit the trajectory through the Cartesianplane2. The file format is <strong>in</strong> the form time1 X1 Y1 time2 X2 Y2 time3 X3 Y3 allow<strong>in</strong>g the user todef<strong>in</strong>e a time-tagged trajectory.space then allows the user to specify a time po<strong>in</strong>ter (much as is used for pvoc, lpread and someother units) to have detailed control over the f<strong>in</strong>al speed of movement.spsend depends upon the existence of a previously def<strong>in</strong>ed space. The output signals fromspsend are derived from the values given for XY and reverb <strong>in</strong> the space and are ready to be sentto local or global reverb units (see example below).spdist uses the same xy data as space, also either from a text file us<strong>in</strong>g GEN28 or from x and yarguments given to the unit directly. The purpose of this unit is to make available the values fordistance that are calculated from the xy coord<strong>in</strong>ates. In the case of space the xy values are usedto determ<strong>in</strong>e a distance which is used to attenuate the signal and prepare it for use <strong>in</strong> spsend. Butit is also useful to have these values for distance available to scale the frequency of the signalbefore it is sent to the space unit.60.3.2 PERFORMANCEThe configuration of the XY coord<strong>in</strong>ates <strong>in</strong> space places the signal <strong>in</strong> the follow<strong>in</strong>g way:• a1 is -1, 1• a2 is 1, 1• a3 is -1, -1• a4 is 1, -1.This assumes a loudspeaker set up as a1 is left front, a2 is right front, a3 is left back, a4 is rightback. Values greater than 1 will result <strong>in</strong> sounds be<strong>in</strong>g attenuated as if <strong>in</strong> the distance. spaceconsiders the speakers to be at a distance of 1; smaller values of XY can be used, but space willnot amplify the signal <strong>in</strong> this case. It will, however balance the signal so that it can sound as if itwere with<strong>in</strong> the 4 speaker space. x=0, y=1, will place the signal equally balanced between leftand right front channels, x=y=0 will place the signal equally <strong>in</strong> all 4 channels, and so on.Although there must be 4 output signal from space, it can be used <strong>in</strong> a 2 channel orchestra. If theXYs are kept so that Y>=1, it should work well to do pann<strong>in</strong>g and fixed localization <strong>in</strong> a stereofield.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-5


ifn – number of the stored function created us<strong>in</strong>g GEN28. This function generator reads a textfile which conta<strong>in</strong>s sets of three values represent<strong>in</strong>g the xy coord<strong>in</strong>ates and a time-tag for whenthe signal should be placed at that location. The file should look like:0 -1 11 1 12 4 42.1 -4 -43 10 -105 -40 0If that file were named “move” then the GEN28 call <strong>in</strong> the score would like:f1 0 0 28 “move”GEN28 takes 0 as the size and automatically allocates memory. It creates values to 10milliseconds of resolution. So <strong>in</strong> this case there will be 500 values created by <strong>in</strong>terpolat<strong>in</strong>g X1 toX2 to X3 and so on, and Y1 to Y2 to Y3 and so on, over the appropriate number of values thatare stored <strong>in</strong> the function table. In the above example, the sound will beg<strong>in</strong> <strong>in</strong> the left front, over1 second it will move to the right front, over another second it move further <strong>in</strong>to the distance butstill <strong>in</strong> the left front, then <strong>in</strong> just 1/10th of a second it moves to the left rear, a bit distant. F<strong>in</strong>allyover the last .9 seconds the sound will move to the right rear, moderately distant, and it comes torest between the two left channels (due west!), quite distant. S<strong>in</strong>ce the values <strong>in</strong> the table areaccessed through the use of a time-po<strong>in</strong>ter <strong>in</strong> the space unit, the actual tim<strong>in</strong>g can be made tofollow the file’s tim<strong>in</strong>g exactly or it can be made to go faster or slower through the sametrajectory. If you have access to the GUI that allows one to draw and edit the files, there is noneed to create the text files manually. But as long as the file is ASCII and <strong>in</strong> the format shownabove, it doesn’t matter how it is made!IMPORTANT: If ifn is 0 then space will take its values for the xy coord<strong>in</strong>ates from kx and ky.ktime – <strong>in</strong>dex <strong>in</strong>to the table conta<strong>in</strong><strong>in</strong>g the xy coord<strong>in</strong>ates. If used like:ktime l<strong>in</strong>e 0, 5, 5a1, a2, a3, a4 space asig, 1, ktime, ...with the file “move” described above, the speed of the signal’s movement will be exactly asdescribed <strong>in</strong> that file. However:ktime l<strong>in</strong>e 0, 10, 5the signal will move at half the speed specified. Or <strong>in</strong> the case of:ktime l<strong>in</strong>e 5, 15, 0the signal will move <strong>in</strong> the reverse direction as specified and 3 times slower! F<strong>in</strong>ally:ktime l<strong>in</strong>e 2, 10, 3will cause the signal to move only from the place specified <strong>in</strong> l<strong>in</strong>e 3 of the text file to the placespecified <strong>in</strong> l<strong>in</strong>e 5 of the text file, and it will take 10 seconds to do it.kreverbsend – the percentage of the direct signal that will be factored along with the distance asderived from the XY coord<strong>in</strong>ates to calculate signal amounts that can be sent to reverb units suchas reverb, or reverb2.kx, ky – when ifn is 0, space and spdist will use these values as the XY coord<strong>in</strong>ates to localizethe signal. They are optional and both default to 0.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-6


60.3.3 EXAMPLE<strong>in</strong>str 1asig some audio signalktime l<strong>in</strong>e 0, p3, p10a1,a2,a3,a4 space asig,1, ktime, .1ar1,ar2,ar3,ar4 spsendga1 = ga1+ar1ga2 = ga2+ar2ga3 = ga3+ar3ga4 = ga4+ar4outqend<strong>in</strong>a1, a2, a3, a4<strong>in</strong>str 99 ; reverb <strong>in</strong>strumenta1 reverb2 ga1, 2.5, .5a2 reverb2 ga2, 2.5, .5a3 reverb2 ga3, 2.5, .5a4 reverb2 ga4, 2.5, .5ga1 = 0ga2 = 0ga3 = 0ga4 = 0outqa1, a2, a3, a4In the above example, the signal, asig, is moved accord<strong>in</strong>g to the data <strong>in</strong> Function #1 <strong>in</strong>dexed byktime. space sends the appropriate amount of the signal <strong>in</strong>ternally to spsend. The outputs of thespsend are added to global accumulators <strong>in</strong> a common <strong>Csound</strong> style and the global signals areused as <strong>in</strong>puts to the reverb units <strong>in</strong> a separate <strong>in</strong>strument.space can useful for quad and stereo pann<strong>in</strong>g as well as fixed placed of sounds anywherebetween two loudspeakers. Below is an example of the fixed placement of sounds <strong>in</strong> a stereofield us<strong>in</strong>g XY values from the score <strong>in</strong>stead of a function table.<strong>in</strong>str 1...a1,a2,a3,a4 space asig, 0, 0, .1, p4, p5ar1,ar2,ar3,ar4 spsendga1 = ga1+ar1ga2 = ga2+ar2outs a1, a2end<strong>in</strong>....<strong>in</strong>str 99 ; reverb....end<strong>in</strong>A few notes: p4 and p5 are the X and Y values;place the sound <strong>in</strong> the left speaker and neari1 0 1 -1 1;place the sound <strong>in</strong> the right speaker and fari1 1 1 45 45The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-7


;place the sound equally between left and right and <strong>in</strong> the middle grounddistancei1 2 1 0 12eThe next example shows a simple <strong>in</strong>tuitive use of the distance values returned by spdist tosimulate Doppler shift.ktime l<strong>in</strong>e 0, p3, 10kdistspdist 1, ktimekfreq = (ifreq * 340) / (340 + kdist)asig oscili iamp, kfreq, 1a1, a2, a3, a4 space asig, 1, ktime, .1ar1, ar2, ar3, ar4 spsendThe same function and time values are used for both spdist and space. This <strong>in</strong>sures that thedistance values used <strong>in</strong>ternally <strong>in</strong> the space unit will be the same as those returned by spdist togive the impression of a Doppler shift!60.3.4 AUTHORRichard KarpenSeattle, Wash1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-8


60.4 hrtferaLeft, aRight hrtferasig, kAz, kElev, “HRTFcompact”60.4.1 DESCRIPTIONOutput is b<strong>in</strong>aural (headphone) 3D audio.60.4.2 INITIALIZATIONkAz – azimuth value <strong>in</strong> degrees. Positive values represent position on the right, negative valuesare positions on the left.kElev – elevation value <strong>in</strong> degrees. Positive values represent position above horizontal, negativevalues are positions above horizontal.At present, the only file which can be used with hrtfer is HRTFcompact. It must be passed to theopcode as the last argument with<strong>in</strong> quotes as shown above.HRTFcompact my be obta<strong>in</strong>ed via anonymous ftp from:ftp://ftp.maths.bath.ac.uk/pub/dream/utilities/Analysis/HRTFcompact60.4.3 PERFORMANCEThese unit generators place a mono <strong>in</strong>put signal <strong>in</strong> a virtual 3D space around the listener byconvolv<strong>in</strong>g the <strong>in</strong>put with the appropriate HRTF data specified by the opcode’s azimuth andelevation values. hrtfer allows these values to be k-values, allow<strong>in</strong>g for dynamic spatialization.hrtfer can only place the <strong>in</strong>put at the requested position because the HRTF is loaded <strong>in</strong> at i-time(remember that currently, <strong>Csound</strong> has a limit of 20 files it can hold <strong>in</strong> memory, otherwise itcauses a segmentation fault). The output will need to be scaled either by us<strong>in</strong>g balance or bymultiply<strong>in</strong>g the output by some scal<strong>in</strong>g constant.Note – the sampl<strong>in</strong>g rate of the orchestra must be 44.1kHz. This is because 44.1kHz is thesampl<strong>in</strong>g rate at which the HRTFs were measured. In order to be used at a different rate, theHRTFs would need to be re-sampled at the desired rate.60.4.4 EXAMPLEkazl<strong>in</strong>seg 0, p3, -360 ; move the sound <strong>in</strong> circlekell<strong>in</strong>seg -40, p3, 45 ; around the listener, chang<strong>in</strong>g; elevation as its turn<strong>in</strong>gasrcsound<strong>in</strong> “sound<strong>in</strong>.1”aleft,aright hrtfer asrc, kaz, kel, “HRTFcompact”aleftscale = aleft * 200arightscale = aright * 200outs aleftscale, arightscaleThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-9


60.4.5 AUTHORSEli Breder & David MacIntyreMontreal1996The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-10


60.5 vbapls<strong>in</strong>it, vbap4, vbap8, vbap16, vbap4move,vbap8move, vbap16move, vbapz, vbapzmovevbapls<strong>in</strong>it idim, ilsnum, idir1, idir2,...ar1, ar2, ar3, ar4 vbap4 asig, iazim, ielev, ispreadar1, ar2, ar3, ar4, vbap8 asig, iazim, ielev, ispreadar5, ar6, ar7, ar8ar1, ar2, ar3, ar4, vbap16 asig, iazim, ielev, ispreadar5, ar6, ar7, ar8,ar9, ar10, ar11, ar12,ar13, ar14, ar15, ar16ar1, ar2, ar3, ar4 vbap4move asig, ispread, ifldnum, ifld1, ifld2,...ar1, ar2, ar3, ar4, vbap8move asig, ispread, ifldnum, ifld1, ifld2,...ar5, ar6, ar7, ar8ar1, ar2, ar3, ar4,ar5, ar6, ar7, ar8,ar9, ar10, ar11, ar12,ar13, ar14, ar15, ar16vbap16move asig, ispread, ifldnum, ifld1, ifld2,...vbapzvbapzmove<strong>in</strong>umchnls, istartndx, asig, iazim,ielev, ispread<strong>in</strong>umchnls, istartndx, ispread, ifldnum,ifld1, ifld2,...60.5.1 DESCRIPTIONDistribute an audio signal among 2 to 16 output channels or write it to a ZAK array, all withlocalization control.60.5.2 INITIALIZATIONidim – dimensionality of loudspeaker array. Either 2 or 3.ilsnum – number of loudspeakers. In two dimensions, the number can vary from 2 to 16. In threedimensions, the number can vary from 3 and 16.idir1, idir2, etc. – directions of loudspeakers. Number of directions must be less than or equal to16. In two-dimensional loudspeaker position<strong>in</strong>g, idirn is the azimuth angle respective to nthchannel. In three-dimensional loudspeaker position<strong>in</strong>g, fields are the azimuth and elevationangles of each loudspeaker consequently (azi1, ele1, azi2, ele2, etc.).iazim – azimuth angle of the virtual sourceThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-11


ielev – elevation angle of the virtual sourceispread – spread<strong>in</strong>g of the virtual source (range 0 - 100). If value is zero, conventional amplitudepann<strong>in</strong>g is used. When ispread is <strong>in</strong>creased, the number of loudspeakers used <strong>in</strong> pann<strong>in</strong>g<strong>in</strong>creases. If value is 100, the sound is applied to all loudspeakers.ifldnum – number of fields (absolute value must be 2 or larger). If ifldnum is positive, the virtualsource movement is a polyl<strong>in</strong>e specified by given directions. Each transition is performed <strong>in</strong> anequal time <strong>in</strong>terval. If ifldnum is negative, specified angular velocities are applied to the virtualsource dur<strong>in</strong>g specified relative time <strong>in</strong>tervals (see below).ifld1, ifld2, etc. – azimuth angles or angular velocities, and relative durations of movementphases (see below).<strong>in</strong>umchnls – number of channels to write to the ZA array. Must be <strong>in</strong> the range 2 – 256.istartndx – first <strong>in</strong>dex or position <strong>in</strong> the ZA array to use60.5.3 PERFORMANCEasig – audio signal to be pannedvbap4, vbap8, and vbap16 take an <strong>in</strong>put signal, asig, and distribute it among 2 to 16 outputs,accord<strong>in</strong>g to the controls iazim and ielev, and the configured loudspeaker placement. If idim = 2,ielev is set to zero. The distribution is performed us<strong>in</strong>g Vector Base Amplitude Pann<strong>in</strong>g (VBAP -See reference). VBAP distributes the signal us<strong>in</strong>g loudspeaker data configured with vbapls<strong>in</strong>it.The signal is applied to, at most, two loudspeakers <strong>in</strong> 2-D loudspeaker configurations, and threeloudspeakers <strong>in</strong> 3-D loudspeaker configurations. If the virtual source is panned outside the regionspanned by loudspeakers, the nearest loudspeakers are used <strong>in</strong> pann<strong>in</strong>g.vbap4move, vbap8move, and vbap16move allow the use of mov<strong>in</strong>g virtual sources. If ifldnumis positive, the fields represent directions of virtual sources and equal times, iazi1, [iele1,] iazi2,[iele2,], etc. The position of the virtual source is <strong>in</strong>terpolated between directions start<strong>in</strong>g from thefirst direction and end<strong>in</strong>g at the last. Each <strong>in</strong>terval is <strong>in</strong>terpolated <strong>in</strong> time that is fractiontotal_time / number_of_<strong>in</strong>tervals of the duration of the sound event.If ifldnum is negative, the fields represent angular velocities and equal times. The first field is,however, the start<strong>in</strong>g direction, iazi1, [iele1,] iazi_vel1, [iele_vel1,] iazi_vel2, [iele_vel2,] ....Each velocity is applied to the note that is fraction total_time / number_of_velocities of theduration of the sound event. If the elevation of the virtual source becomes greater than 90degrees or less than 0 degrees, the polarity of angular velocity is changed. Thus the elevationalangular velocity produces a virtual source that moves up and down between 0 and 90 degrees.The opcodes vbapz and vbapzmove are the multiple channel analogs of the above opcodes,work<strong>in</strong>g an <strong>in</strong>umchnls and us<strong>in</strong>g a ZAK array for output.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-12


60.5.4 EXAMPLE2-D pann<strong>in</strong>g example with stationary virtual sources:sr = 4100kr = 441ksmps = 100nchnls = 4vbapls<strong>in</strong>it 2, 6, 0, 45, 90, 135, 200, 245, 290, 315<strong>in</strong>str 1asig oscil 20000, 440, 1a1,a2,a3,a4,a5,a6,a7,a8 vbap8 asig, p4, 0, 20 ;p4 = azimuth;render twice with alternate outq statements; to obta<strong>in</strong> two 4 channel .wav files:outq a1,a2,a3,a4; outq a5,a6,a7,a8end<strong>in</strong>60.5.5 REFERENCEVille Pulkki: “Virtual Sound Source Position<strong>in</strong>g Us<strong>in</strong>g Vector Base Amplitude Pann<strong>in</strong>g”Journal of the Audio Eng<strong>in</strong>eer<strong>in</strong>g Society,1997 June, Vol. 45/6, p. 456.60.5.6 AUTHORSVille PulkkiSibelius Academy Computer Music StudioLaboratory of Acoustics and Audio Signal Process<strong>in</strong>gHels<strong>in</strong>ki University of TechnologyHels<strong>in</strong>ki, F<strong>in</strong>landMay, 2000 (New <strong>in</strong> <strong>Csound</strong> version 4.06)John ffitch (vbapz, vbabzmove)University of Bath/Codemist Ltd.Bath, UKMay, 2000 (New <strong>in</strong> <strong>Csound</strong> version 4.06)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-13


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Pann<strong>in</strong>g and Spatialization Page 60-14


61 SIGNAL MODIFIERS: SAMPLE LEVELOPERATORS61.1 samphold, downsamp, upsamp, <strong>in</strong>terp, <strong>in</strong>teg, diffkr downsamp asig[, iwlen]ar upsamp ksigar <strong>in</strong>terp ksig[, iskip]kr <strong>in</strong>teg ksig[, iskip]ar <strong>in</strong>teg asig[, iskip]kr diff ksig[, iskip]ar diff asig[, iskip]kr samphold xsig, kgate[, ival, ivstor]ar samphold asig, xgate[, ival, ivstor]61.1.1 DESCRIPTIONModify a signal by up- or down-sampl<strong>in</strong>g, <strong>in</strong>tegration, and differentiation.61.1.2 INITIALIZATIONiwlen (optional) – w<strong>in</strong>dow length <strong>in</strong> samples over which the audio signal is averaged todeterm<strong>in</strong>e a downsampled value. Maximum length is ksmps; 0 and 1 imply no w<strong>in</strong>dowaverag<strong>in</strong>g. The default value is 0.iskip (optional) – <strong>in</strong>itial disposition of <strong>in</strong>ternal save space ( see reson). The default value is 0.ival, ivstor (optional) – controls <strong>in</strong>itial disposition of <strong>in</strong>ternal save space. If ivstor is zero the<strong>in</strong>ternal “hold” value is set to ival ; else it reta<strong>in</strong>s its previous value. Defaults are 0,0 (i.e. <strong>in</strong>it tozero)61.1.3 PERFORMANCEdownsamp converts an audio signal to a control signal by downsampl<strong>in</strong>g. It produces one kvalfor each audio control period. The optional w<strong>in</strong>dow <strong>in</strong>vokes a simple averag<strong>in</strong>g process tosuppress foldover.upsamp, <strong>in</strong>terp convert a control signal to an audio signal. The first does it by simple repetitionof the kval, the second by l<strong>in</strong>ear <strong>in</strong>terpolation between successive kvals. upsamp is a slightlymore efficient form of the assignment, `asig = ksig’.<strong>in</strong>teg, diff perform <strong>in</strong>tegration and differentiation on an <strong>in</strong>put control signal or audio signal.Each is the converse of the other, and apply<strong>in</strong>g both will reconstruct the orig<strong>in</strong>al signal. S<strong>in</strong>cethese units are special cases of low-pass and high-pass filters, they produce a scaled (and phaseshifted) output that is frequency-dependent. Thus diff of a s<strong>in</strong>e produces a cos<strong>in</strong>e, with amplitude2 * s<strong>in</strong>(pi * Hz / sr) that of the orig<strong>in</strong>al (for each component partial); <strong>in</strong>teg will <strong>in</strong>versely affectthe magnitudes of its component <strong>in</strong>puts. With this understand<strong>in</strong>g, these units can provide usefulsignal modification.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Sample Level Operators Page 61-1


samphold performs a sample-and-hold operation on its <strong>in</strong>put accord<strong>in</strong>g to the value of gate. Ifgate 0, the <strong>in</strong>put samples are passed to the output; If gate = 0, the last output value is repeated.The controll<strong>in</strong>g gate can be a constant, a control signal, or an audio signal.61.1.4 EXAMPLEasrc buzz 10000,440,20, 1 ; band-limited pulse tra<strong>in</strong>adif diff asrc ; emphasize the highsanew balance adif, asrc ; but reta<strong>in</strong> the poweragate reson asrc,0,440 ; use a lowpass of the orig<strong>in</strong>alasamp samphold anew, agate ; to gate the new audiosigaout tone asamp,100 ; smooth out the rough edgesThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Sample Level Operators Page 61-2


61.2 ntrpolir ntrpol isig1, isig2, ipo<strong>in</strong>t [, im<strong>in</strong>, imax]kr ntrpol ksig1, ksig2, kpo<strong>in</strong>t [, im<strong>in</strong>, imax]ar ntrpol asig1, asig2, kpo<strong>in</strong>t [, im<strong>in</strong>, imax]61.2.1 DESCRIPTIONCalculates the weighted mean value (i.e. l<strong>in</strong>ear <strong>in</strong>terpolation) of two <strong>in</strong>put signals61.2.2 INITIALIZATIONim<strong>in</strong> – m<strong>in</strong>imum xpo<strong>in</strong>t value (optional, default 0)imax – maximum xpo<strong>in</strong>t value (optional, default 1)61.2.3 PERFORMANCExsig1, xsig2 – <strong>in</strong>put signalsxpo<strong>in</strong>t – <strong>in</strong>terpolation po<strong>in</strong>t between the two valuesntrpol opcode outputs the l<strong>in</strong>ear <strong>in</strong>terpolation between two <strong>in</strong>put values. xpo<strong>in</strong>t is the distance ofevaluation po<strong>in</strong>t from the first value. With the default values of im<strong>in</strong> and imax, (0 and 1) a zerovalue <strong>in</strong>dicates no distance from the first value and the maximum distance from the second one.With a 0.5 value, ntrpol will output the mean value of the two <strong>in</strong>puts, <strong>in</strong>dicat<strong>in</strong>g the exact halfpo<strong>in</strong>t between xsig1 and xsig2. A 1 value <strong>in</strong>dicates the maximum distance from the first valueand no distance from the second one. The range of xpo<strong>in</strong>t can be also def<strong>in</strong>ed with im<strong>in</strong> and imaxto make its management easier.These opcodes are useful for crossfad<strong>in</strong>g two signals.61.2.4 AUTHORGabriel MaldonadoItalyOctober, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.49)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Sample Level Operators Page 61-3


61.3 foldar fold asig, k<strong>in</strong>cr61.3.1 DESCRIPTIONAdds artificial foldover to an audio signal.61.3.2 PERFORMANCEasig – <strong>in</strong>put signalk<strong>in</strong>cr – amount of foldover expressed <strong>in</strong> multiple of sampl<strong>in</strong>g rate. Must be >= 1fold is an opcode which creates artificial foldover. For example, when k<strong>in</strong>cr is equal to 1 withsr=44100, no foldover is added. When k<strong>in</strong>cr is set to 2, the foldover is equivalent to adownsampl<strong>in</strong>g to 22050, when it is set to 4, to 11025 etc. Fractional values of k<strong>in</strong>cr are possible,allow<strong>in</strong>g a cont<strong>in</strong>uous variation of foldover amount. This can be used for a wide range of specialeffects.61.3.3 EXAMPLE<strong>in</strong>str 1kfreq l<strong>in</strong>e 1,p3,200a1 oscili 10000, 100, 1k1 <strong>in</strong>it 8.5a1 fold a1, kfreqout a1end<strong>in</strong>61.3.4 AUTHORGabriel MaldonadoItaly1999New <strong>in</strong> <strong>Csound</strong> version 3.56The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Modifiers: Sample Level Operators Page 61-4


62 ZAK PATCH SYSTEMThe zak opcodes are used to create a system for i-rate, k-rate or a-rate patch<strong>in</strong>g. The zak systemcan be thought of as a global array of variables. These opcodes are useful for perform<strong>in</strong>g flexiblepatch<strong>in</strong>g or rout<strong>in</strong>g from one <strong>in</strong>strument to another. The system is similar to a patch<strong>in</strong>g matrix ona mix<strong>in</strong>g console or to a modulation matrix on a synthesizer. It is also useful whenever an arrayof variables is required.The zak system is <strong>in</strong>itialized by the zak<strong>in</strong>it opcode, which is usually placed just after the otherglobal <strong>in</strong>itializations: sr, kr, ksmps, nchnls. The zak<strong>in</strong>it opcode def<strong>in</strong>es two areas of memory,one area for i- and k-rate patch<strong>in</strong>g, and the other area for a-rate patch<strong>in</strong>g. The zak<strong>in</strong>it opcodemay only be called once. Once the zak space is <strong>in</strong>itialized, other zak opcodes can be used to readfrom, and write to the zak memory space, as well as perform various other tasks.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Zak Patch System Page 62-1


62.1 zak<strong>in</strong>itzak<strong>in</strong>itisizea, isizek62.1.1 DESCRIPTIONEstablishes zak space. Must be called only once.62.1.2 INITIALIZATIONisizea – the number of audio rate locations for a-rate patch<strong>in</strong>g. Each location is actually an arraywhich is ksmps long.isizek – the number of locations to reserve for floats <strong>in</strong> the zk space. These can be written andread at i- and k-rates.62.1.3 PERFORMANCEAt least one location each is always allocated for both za and zk spaces. There can be thousandsor tens of thousands za and zk ranges, but most pieces probably only need a few dozen forpatch<strong>in</strong>g signals. These patch<strong>in</strong>g locations are referred to by number <strong>in</strong> the other zak opcodes.To run zak<strong>in</strong>it only once, put it outside any <strong>in</strong>strument def<strong>in</strong>ition, <strong>in</strong> the orchestra file header,after sr, kr, ksmps, and nchnls.62.1.4 EXAMPLEzak<strong>in</strong>it 10 30reserves memory for locations 0 to 30 of zk space and for locations 0 to 10 of a-rate za space.With ksmps = 8, this would take 31 floats for zk and 80 floats for za space.62.1.5 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Zak Patch System Page 62-2


62.2 ziw, zkw, zaw, ziwm, zkwm, zawmziwzkwzawziwmzkwmzawmisig, <strong>in</strong>dxksig, kndxasig, kndxisig, <strong>in</strong>dx [, imix]ksig, kndx [, imix]asig, kndx [, imix]62.2.1 DESCRIPTIONWrite to a location <strong>in</strong> zk space at either i-rate or k-rate, or a location <strong>in</strong> za space at a-rate. Writ<strong>in</strong>gcan be with, or without, mix<strong>in</strong>g.62.2.2 INITIALIZATION<strong>in</strong>dx – po<strong>in</strong>ts to the zk location to which to write.isig – <strong>in</strong>itializes the value of the zk location.62.2.3 PERFORMANCEkndx – po<strong>in</strong>ts to the zk or za location to which to write.ksig – value to be written to the zk location.asig – value to be written to the za location.ziw writes isig <strong>in</strong>to the zk variable specified by <strong>in</strong>dx.zkw writes ksig <strong>in</strong>to the zk variable specified by kndx.zaw writes asig <strong>in</strong>to the za variable specified by kndx.These opcodes are fast, and always check that the <strong>in</strong>dex is with<strong>in</strong> the range of zk or za space. Ifnot, an error is reported, 0 is returned, and no writ<strong>in</strong>g takes place.ziwm, zkwm, and zawm are mix<strong>in</strong>g opcodes, i.e. they add the signal to the current value of thevariable. If no imix is specified, mix<strong>in</strong>g always occurs, but if imix is specified, imix = 0 willcause overwrit<strong>in</strong>g, like ziw, zkw, and zaw, and any other value will cause mix<strong>in</strong>g.Caution: When us<strong>in</strong>g the mix<strong>in</strong>g opcodes ziwm, zkwm, and zawm, care must be taken that thevariables mixed to, are zeroed at the end (or start) of each k or a cycle. Cont<strong>in</strong>u<strong>in</strong>g to add signalsto them, can cause their values can drift to astronomical figures.One approach would be to establish certa<strong>in</strong> ranges of zk or za variables to be used for mix<strong>in</strong>g,then use zkcl or zacl to clear those ranges.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Zak Patch System Page 62-3


62.2.4 EXAMPLES<strong>in</strong>str 1zkw kzoom, p8 ; p8 <strong>in</strong> the score l<strong>in</strong>e determ<strong>in</strong>es where; <strong>in</strong> zk space kzoom iswrittenend<strong>in</strong><strong>in</strong>str 2zkw kzoom, 7 ; always writes kzoom to zk location 7end<strong>in</strong><strong>in</strong>str 3kxxx phasor 1kdest = 40+kxxx*16 ; This will write azoom to; locations 40 to 55zawazoom,kdest ; on a one second scan cycleend<strong>in</strong>62.2.5 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Zak Patch System Page 62-4


62.3 zir, zkr, zar, zargir zir <strong>in</strong>dxkr zkr kndxar zar kndxar zarg kndx, kga<strong>in</strong>62.3.1 DESCRIPTIONRead from a location <strong>in</strong> zk space at i-rate or k-rate, or a location <strong>in</strong> za space at a-rate.62.3.2 INITIALIZATIONkndx – po<strong>in</strong>ts to the zk or za location to be read.kga<strong>in</strong> – multiplier for the a-rate signal.62.3.3 PERFORMANCEzir reads the signal at <strong>in</strong>dx location <strong>in</strong> zk space.zkr reads the array of floats at kndx <strong>in</strong> zk space.zar reads the array of floats at kndx <strong>in</strong> za space, which are ksmps number of a-rate floats to beprocessed <strong>in</strong> a k cycle.zarg is similar to zar, but multiplies the a-rate signal by a k-rate value kga<strong>in</strong>.62.3.4 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Zak Patch System Page 62-5


62.4 zkmod, zamod, zkcl, zaclkr zkmod ksig, kzkmodar zamod asig, kzamodzkcl kfirst, klastzacl kfirst, klast62.4.1 DESCRIPTIONClear and modulate the za and zk spaces.62.4.2 PERFORMANCEksig – the <strong>in</strong>put signalkzkmod – controls which zk variable is used for modulation. A positive value means additivemodulation, a negative value means multiplicative modulation. A value of 0 means no change toksig. kzkmod can be i-rate or k-ratekfirst – first zk or za location <strong>in</strong> the range to clear.klast – last zk or za location <strong>in</strong> the range to clear.zkmod facilitates the modulation of one signal by another, where the modulat<strong>in</strong>g signal comesfrom a zk variable. Either additive or multiplicative modulation can be specified.zamod modulates one a-rate signal by a second one, which comes from a za variable. Thelocation of the modulat<strong>in</strong>g variable is controlled by the i-rate or k-rate variable kzamod. This isthe a-rate version of zkmodzkcl clears one or more variables <strong>in</strong> the zk space. This is useful for those variables which areused as accumulators for mix<strong>in</strong>g k-rate signals at each cycle, but which must be cleared beforethe next set of calculations.zacl clears one or more variables <strong>in</strong> the za space. This is useful for those variables which areused as accumulators for mix<strong>in</strong>g a-rate signals at each cycle, but which must be cleared beforethe next set of calculations.62.4.3 EXAMPLESk1 zkmod ksig, 23 ; adds value at location 23 to ksiga1 zamod asig, -402 ; multiplies asig by value at location 40262.4.4 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Zak Patch System Page 62-6


63 OPERATIONS USING SPECTRAL DATA TYPESThese units generate and process non-standard signal data types, such as down-sampled timedoma<strong>in</strong>control signals and audio signals, and their frequency-doma<strong>in</strong> (spectral) representations.The new data types (d-, w-) are self-def<strong>in</strong><strong>in</strong>g, and the contents are not processable by any other<strong>Csound</strong> units. These unit generators are experimental, and subject to change between releases;they will also be jo<strong>in</strong>ed by others later.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Operations Us<strong>in</strong>g Spectral Data Types Page 63-1


63.1 specaddm, specdiff, specscal, spechist, specfiltwsig specaddm wsig1, wsig2[, imul2]wsig specdiff wsig<strong>in</strong>wsig specscal wsig<strong>in</strong>, ifscale, ifthreshwsig spechist wsig<strong>in</strong>wsig specfilt wsig<strong>in</strong>, ifhtim63.1.1 INITIALIZATIONimul2 (optional) – if non-zero, scale the wsig2 magnitudes before add<strong>in</strong>g. The default value is 0.63.1.2 PERFORMANCEspecaddm – do a weighted add of two <strong>in</strong>put spectra. For each channel of the two <strong>in</strong>put spectra,the two magnitudes are comb<strong>in</strong>ed and written to the output accord<strong>in</strong>g to: magout = mag1<strong>in</strong> +mag2<strong>in</strong> * imul2. The operation is performed whenever the <strong>in</strong>put wsig1 is sensed to be new. Thisunit will (at Initialization) verify the consistency of the two spectra (equal size, equal period,equal mag types).specdiff – f<strong>in</strong>d the positive difference values between consecutive spectral frames. At each newframe of wsig<strong>in</strong>, each magnitude value is compared with its predecessor, and the positivechanges written to the output spectrum. This unit is useful as an energy onset detector.specscal – scale an <strong>in</strong>put spectral datablock with spectral envelopes. Function tables ifthresh andifscale are <strong>in</strong>itially sampled across the (logarithmic) frequency space of the <strong>in</strong>put spectrum; theneach time a new <strong>in</strong>put spectrum is sensed the sampled values are used to scale each of itsmagnitude channels as follows: if ifthresh is non-zero, each magnitude is reduced by itscorrespond<strong>in</strong>g table-value (to not less than zero); then each magnitude is rescaled by thecorrespond<strong>in</strong>g ifscale value, and the result<strong>in</strong>g spectrum written to wsig.spechist - accumulate the values of successive spectral frames. At each new frame of wsig<strong>in</strong>, theaccumulations-to-date <strong>in</strong> each magnitude track are written to the output spectrum. This unit thusprovides a runn<strong>in</strong>g histogram of spectral distribution.specfilt – filter each channel of an <strong>in</strong>put spectrum. At each new frame of wsig<strong>in</strong>, each magnitudevalue is <strong>in</strong>jected <strong>in</strong>to a 1st-order lowpass recursive filter, whose half-time constant has been<strong>in</strong>itially set by sampl<strong>in</strong>g the ftable ifhtim across the (logarithmic) frequency space of the <strong>in</strong>putspectrum. This unit effectively applies a persistence factor to the data occurr<strong>in</strong>g <strong>in</strong> each spectralchannel, and is useful for simulat<strong>in</strong>g the energy <strong>in</strong>tegration that occurs dur<strong>in</strong>g auditoryperception. It may also be used as a time-attenuated runn<strong>in</strong>g histogram of the spectraldistribution.63.1.3 EXAMPLEwsig2 specdiff wsig1 ; sense onsetswsig3 specfilt wsig2, 2 ; absorb slowlyspecdisp wsig2, .1; & display both spectraspecdisp wsig3, .1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Operations Us<strong>in</strong>g Spectral Data Types Page 63-2


63.2 specptrkkoct, specptrk wsig, kvar, ilo, ihi, istr, idbthresh, <strong>in</strong>ptls,//kampirolloff[, iodd, iconfs, <strong>in</strong>terp, ifprd, iwtflg]63.2.1 DESCRIPTIONEstimate the pitch of the most prom<strong>in</strong>ent complex tone <strong>in</strong> the spectrum.63.2.2 INITIALIZATIONilo, ihi, istr – pitch range conditioners (low, high, and start<strong>in</strong>g) expressed <strong>in</strong> decimal octave form.idbthresh – energy threshold (<strong>in</strong> decibels) for pitch track<strong>in</strong>g to occur. Once begun, track<strong>in</strong>g willbe cont<strong>in</strong>uous until the energy falls below one half the threshold (6 dB down), whence the koctand kamp outputs will be zero until the full threshold is aga<strong>in</strong> surpassed. idbthresh is a guid<strong>in</strong>gvalue. At <strong>in</strong>itialization it is first converted to the idbout mode of the source spectrum (and the 6dB down po<strong>in</strong>t becomes .5, .25, or 1/root 2 for modes 0, 2 and 3). The values are also furtherscaled to allow for the weighted partial summation used dur<strong>in</strong>g correlation.The actualthreshold<strong>in</strong>g is done us<strong>in</strong>g the <strong>in</strong>ternal weighted and summed kamp value that is visible as thesecond output parameter.<strong>in</strong>ptls, irolloff – number of harmonic partials used as a match<strong>in</strong>g template <strong>in</strong> the spectrally-basedpitch detection, and an amplitude rolloff for the set expressed as some fraction per octave (l<strong>in</strong>ear,so don’t roll off to negative). S<strong>in</strong>ce the partials and rolloff fraction can affect the pitchfollow<strong>in</strong>g, some experimentation will be useful: try 4 or 5 partials with .6 rolloff as an <strong>in</strong>itialsett<strong>in</strong>g; raise to 10 or 12 partials with rolloff .75 for complex timbres like the bassoon (weakfundamental). Computation time is dependent on the number of partials sought. The maximumnumber is 16.iodd (optional) – if non-zero, employ only odd partials <strong>in</strong> the above set (e.g. <strong>in</strong>ptls of 4 wouldemploy partials 1,3,5,7). This improves the track<strong>in</strong>g of some <strong>in</strong>struments like the clar<strong>in</strong>et Thedefault value is 0 (employ all partials).iconfs (optional) – number of confirmations required for the pitch tracker to jump an octave, proratedfor fractions of an octave (i.e. the value 12 implies a semitone change needs 1 confirmation(two hits) at the spectrum generat<strong>in</strong>g iprd). This parameter limits spurious pitch analyses suchas octave errors. A value of 0 means no confirmations required; the default value is 10.<strong>in</strong>terp (optional) – if non-zero, <strong>in</strong>terpolate each output signal (koct, kamp) between <strong>in</strong>com<strong>in</strong>gwsig frames. The default value is 0 (repeat the signal values between frames).ifprd (optional) – if non-zero, display the <strong>in</strong>ternally computed spectrum of candidatefundamentals. The default value is 0 (no display).iwtftg (optional) – wait flag. If non-zero, hold each display until released by the user. The defaultvalue is 0 (no wait).The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Operations Us<strong>in</strong>g Spectral Data Types Page 63-3


63.2.3 PERFORMANCEAt note <strong>in</strong>itialization this unit creates a template of <strong>in</strong>ptls harmonically related partials (oddpartials, if iodd non-zero) with amplitude rolloff to the fraction irolloff per octave. At each newframe of wsig, the spectrum is cross-correlated with this template to provide an <strong>in</strong>ternal spectrumof candidate fundamentals (optionally displayed). A likely pitch/amp pair (koct, kamp, <strong>in</strong>decimal octave and summed idbout form) is then estimated. koct varies from the previous koct byno more than plus or m<strong>in</strong>us kvar decimal octave units. It is also guaranteed to lie with<strong>in</strong> the hardlimit range ilo – ihi (decimal octave low and high pitch). kvar can be dynamic, e.g. onset ampdependent. Pitch resolution uses the orig<strong>in</strong>at<strong>in</strong>g spectrum ifrqs b<strong>in</strong>s/octave, with furtherparabolic <strong>in</strong>terpolation between adjacent b<strong>in</strong>s. Sett<strong>in</strong>gs of root magnitude, ifrqs = 24, iq = 15should capture all the <strong>in</strong>flections of <strong>in</strong>terest. Between frames, the output is either repeated or<strong>in</strong>terpolated at the k-rate. (See spectrum.)63.2.4 EXAMPLEa1,a2 <strong>in</strong>s ; read a stereo clar<strong>in</strong>et <strong>in</strong>putkrms rms a1, 20 ; f<strong>in</strong>d a monaural rms valuekvar = 0.6 + krms/8000 ; & use to gate the pitchvariancewsig spectrum a1, .01, 7, 24, 15, 0, 3 ; get a 7-oct spectrum, 24bibs/octspecdisp wsig, .2; display this and now estimatekoct,ka spectrk wsig, kvar, 7.0, 10, 9, 20, 4, .7, 1, 5, 1, .2 ; the; pch and ampaosc oscil ka*ka*10, cpsoct(koct),2 ; & generate \ new tone withthesekoct = (koct


63.3 specsum, specdispksum specsum wsig[, <strong>in</strong>terp]specdisp wsig, iprd[, iwtflg]63.3.1 INITIALIZATION<strong>in</strong>terp (optional) – if non-zero, <strong>in</strong>terpolate the output signal (koct or ksum). The default value is 0(repeat the signal value between changes).iwtflg (optional) – wait flag. If non-zero, hold each display until released by the user. The defaultvalue is 0 (no wait).63.3.2 PERFORMANCEspecsum – sum the magnitudes across all channels of the spectrum. At each new frame of wsig,the magnitudes are summed and released as a scalar ksum signal. Between frames, the output iseither repeated or <strong>in</strong>terpolated at the k-rate. This unit produces a k-signal summation of themagnitudes present <strong>in</strong> the spectral data, and is thereby a runn<strong>in</strong>g measure of its moment-tomomentoverall strength.specdisp – display the magnitude values of spectrum wsig every iprd seconds (rounded to some<strong>in</strong>tegral number of wsig’s orig<strong>in</strong>at<strong>in</strong>g iprd).63.3.3 EXAMPLEksum specsum wsig, 1 ; sum the spec b<strong>in</strong>s, and ksmoothif ksum < 2000 kgoto zero ; if sufficient amplitudekoct specptrk wsig ; pitch-track the signalkgoto cont<strong>in</strong>zero: koct = 0 ; else output zerocont<strong>in</strong>:.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Operations Us<strong>in</strong>g Spectral Data Types Page 63-5


63.4 spectrumwsig spectrum xsig, iprd, iocts, ifrqs, iq[,ihann, idbout, idsprd,ids<strong>in</strong>rs]63.4.1 DESCRIPTIONGenerate a constant-Q, exponentially-spaced DFT across all octaves of a multiply-downsampledcontrol or audio <strong>in</strong>put signal.63.4.2 INITIALIZATIONihann (optional) – apply a Hamm<strong>in</strong>g or Hann<strong>in</strong>g w<strong>in</strong>dow to the <strong>in</strong>put. The default is 0(Hamm<strong>in</strong>g w<strong>in</strong>dow)idbout (optional) – coded conversion of the DFT output: 0 = magnitude, 1 = dB, 2 = magsquared, 3 = root magnitude. The default value is 0 (magnitude).idisprd (optional) – if non-zero, display the composite downsampl<strong>in</strong>g buffer every idisprdseconds. The default value is 0 (no display).ids<strong>in</strong>es (optional) – if non-zero, display the Hamm<strong>in</strong>g or Hann<strong>in</strong>g w<strong>in</strong>dowed s<strong>in</strong>usoids used <strong>in</strong>DFT filter<strong>in</strong>g. The default value is 0 (no s<strong>in</strong>usoid display).63.4.3 PERFORMANCEThis unit first puts signal asig or ksig through iocts of successive octave decimation anddownsampl<strong>in</strong>g, and preserves a buffer of down-sampled values <strong>in</strong> each octave (optionallydisplayed as a composite buffer every idisprd seconds). Then at every iprd seconds, thepreserved samples are passed through a filter bank (ifrqs parallel filters per octave, exponentiallyspaced, with frequency/bandwidth Q of iq), and the output magnitudes optionally converted(idbout ) to produce a band-limited spectrum that can be read by other units.The stages <strong>in</strong> this process are computationally <strong>in</strong>tensive, and computation time varies directlywith iocts, ifrqs, iq, and <strong>in</strong>versely with iprd. Sett<strong>in</strong>gs of ifrqs = 12, iq = 10, idbout = 3, and iprd =.02 will normally be adequate, but experimentation is encouraged. ifrqs currently has a maximumof 120 divisions per octave. For audio <strong>in</strong>put, the frequency b<strong>in</strong>s are tuned to co<strong>in</strong>cide with A440.This unit produces a self-def<strong>in</strong><strong>in</strong>g spectral datablock wsig, whose characteristics used (iprd,iocts, ifrqs, idbout) are passed via the data block itself to all derivative wsigs. There can be anynumber of spectrum units <strong>in</strong> an <strong>in</strong>strument or orchestra, but all wsig names must be unique.63.4.4 EXAMPLEasig <strong>in</strong> ; get external audiowsig spectrum asig,.02,6,12,33,0,1,1 ; downsample <strong>in</strong> 6 octs & calca 72 pt dft (Q 33, dB out) every 20 msecsThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Operations Us<strong>in</strong>g Spectral Data Types Page 63-6


64 SIGNAL INPUT AND OUTPUT: INPUT64.1 <strong>in</strong>, <strong>in</strong>s, <strong>in</strong>q, <strong>in</strong>h, <strong>in</strong>o, sound<strong>in</strong>, disk<strong>in</strong>ar1 <strong>in</strong>ar1, ar2 <strong>in</strong>sar1, ar2, <strong>in</strong>qar3, ar4ar1, ar2, <strong>in</strong>har3, ar4,ar5, ar6ar1, ar2, <strong>in</strong>oar3, ar4,ar5, ar6,ar7, ar8ar1 sound<strong>in</strong> ifilcod[, iskptim[, iformat]]ar1, ar2 sound<strong>in</strong> ifilcod[, iskptim[, iformat]]ar1, ar2, sound<strong>in</strong> ifilcod[, iskptim[, iformat]]ar3, ar4ar1[,ar2 disk<strong>in</strong> ifilcod, kpitch[, iskiptim [,iwraparound[, iformat]]][,a3,ar4]]64.1.1 DESCRIPTIONThese units read audio data from an external device or stream.64.1.2 INITIALIZATIONifilcod – <strong>in</strong>teger or character-str<strong>in</strong>g denot<strong>in</strong>g the source soundfile name. An <strong>in</strong>teger denotes thefile sound<strong>in</strong>.filcod ; a character-str<strong>in</strong>g (<strong>in</strong> double quotes, spaces permitted) gives the filenameitself, optionally a full pathname. If not a full path, the named file is sought first <strong>in</strong> the currentdirectory, then <strong>in</strong> that given by the environment variable SSDIR (if def<strong>in</strong>ed) then by SFDIR. Seealso GEN01.iskptim (optional) – time <strong>in</strong> seconds of <strong>in</strong>put sound to be skipped. The default value is 0.iformat (optional) – specifies the audio data file format:1 = 8-bit signed char (high-order 8 bits of a 16-bit <strong>in</strong>teger),2 = 8-bit A-law bytes,3 = 8-bit U-law bytes,4 = 16-bit short <strong>in</strong>tegers,5 = 32-bit long <strong>in</strong>tegers,6 = 32-bit floats.If iformat = 0 it is taken from the soundfile header, and if no header from the <strong>Csound</strong> -ocommand flag. The default value is 0.iwraparound – 1=on, 0=off (wraps around to end of file either direction)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Input Page 64-1


kpitch – can be any real number. a negative number signifies backwards playback. The givennumber is a pitch ratio, where:1 = norm pitch,2 = oct higher,3 = 12th higher, etc;.5 = oct lower,.25 = 2oct lower, etc;-1 = norm pitch backwards,-2 = oct higher backwards, etc..64.1.3 PERFORMANCE<strong>in</strong>, <strong>in</strong>s, <strong>in</strong>q, <strong>in</strong>h, <strong>in</strong>o – copy the current values from the standard audio <strong>in</strong>put buffer. If thecommand-l<strong>in</strong>e flag -i is set, sound is read cont<strong>in</strong>uously from the audio <strong>in</strong>put stream (e.g. sta<strong>in</strong> ora soundfile) <strong>in</strong>to an <strong>in</strong>ternal buffer. Any number of these units can read freely from this buffer.sound<strong>in</strong> is functionally an audio generator that derives its signal from a pre-exist<strong>in</strong>g file. Thenumber of channels read <strong>in</strong> is controlled by the number of result cells, a1, a2, etc., which mustmatch that of the <strong>in</strong>put file. A sound<strong>in</strong> unit opens this file whenever the host <strong>in</strong>strument is<strong>in</strong>itialized, then closes it aga<strong>in</strong> each time the <strong>in</strong>strument is turned off. There can be any numberof sound<strong>in</strong> units with<strong>in</strong> a s<strong>in</strong>gle <strong>in</strong>strument or orchestra; also, two or more of them can readsimultaneously from the same external file.disk<strong>in</strong> is identical to sound<strong>in</strong>, except that it can alter the pitch of the sound that is be<strong>in</strong>g read.64.1.4 AUTHORSBarry Vercoe, Matt Ingols/Mike BerryMIT, Mills College1993-1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Input Page 64-2


64.2 <strong>in</strong>x, <strong>in</strong>32, <strong>in</strong>ch, <strong>in</strong>zar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8,ar9, ar10, ar11, ar12, ar13, ar14, ar15, ar16ar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8,ar9, ar10, ar11, ar12, ar13, ar14, ar15, ar16,ar17, ar18, ar19, ar20, ar21, ar22, ar23, ar24,ar25, ar26, ar27, ar28, ar29, ar30, ar31, ar32ar1<strong>in</strong>x<strong>in</strong>32<strong>in</strong>ch ksig1<strong>in</strong>zksig164.2.1 DESCRIPTIONThese units read multi-channel audio data from an external device or stream.64.2.2 PERFORMANCE<strong>in</strong>x and <strong>in</strong>32 read 16 and 32 channel <strong>in</strong>puts, respectively.<strong>in</strong>ch reads from a numbered channel determ<strong>in</strong>ed by ksig1 <strong>in</strong>to a1.<strong>in</strong>z reads audio samples <strong>in</strong> nchnls <strong>in</strong>to a ZAK array start<strong>in</strong>g at ksig1.64.2.3 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKMay, 2000 (New <strong>in</strong> <strong>Csound</strong> version 4.06)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Input Page 64-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Input Page 64-4


65 SIGNAL INPUT AND OUTPUT: OUTPUT65.1 soundout, soundouts, out, outs1, outs2, outs, outq1,outq2, outq3, outq4, outq, outh, outosoundoutsoundoutsoutouts1outs2outsoutq1outq2outq3outq4outqouthoutoasig, ifilcod[, iskptim]asig, ifilcod[, iskptim]asigasigasigasig1, asig2asigasigasigasigasig1, asig2, asig3, asig4asig1, asig2, asig3, asig4, asig5, asig6asig1, asig2, asig3, asig4, asig5, asig6, asig7, asig865.1.1 DESCRIPTIONThese units write audio data to an external device or stream.65.1.2 INITIALIZATIONifilcod – <strong>in</strong>teger or character-str<strong>in</strong>g denot<strong>in</strong>g the dest<strong>in</strong>ation soundfile name. An <strong>in</strong>teger denotesthe file sound<strong>in</strong>.filcod; a character-str<strong>in</strong>g (<strong>in</strong> double quotes, spaces permitted) gives the filenameitself, optionally a full pathname. If not a full path, the named file is sought first <strong>in</strong> the currentdirectory, then <strong>in</strong> that given by the environment variable SSDIR (if def<strong>in</strong>ed) then by SFDIR. Seealso GEN01.iskptim (optional) – time <strong>in</strong> seconds of <strong>in</strong>put sound to be skipped. The default value is 0.65.1.3 PERFORMANCEout, outs, outq, outh, outo - send audio samples to an accumulat<strong>in</strong>g output buffer (created atthe beg<strong>in</strong>n<strong>in</strong>g of performance) which serves to collect the output of all active <strong>in</strong>struments beforethe sound is written to disk. There can be any number of these output units <strong>in</strong> an <strong>in</strong>strument. Thetype (mono, stereo, quad, hex, or oct) should agree with nchnls, but as of version 3.50, willattempt to change and <strong>in</strong>correct opcode, to arguer with nchnls statement. Units can be chosen todirect sound to any particular channel: outs1 sends to stereo channel 1, outq3 to quad channel 3,etc.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Output Page 65-1


soundout and soundouts write audio output to a disk file. soundouts is currently notimplemented.65.1.4 AUTHORSBarry Vercoe, Matt Ingols/Mike BerryMIT, Mills College1993-1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Output Page 65-2


65.2 outx, out32, outc, outch, outzoutxout32asig1, asig2, asig3, asig4, asig5, asig6, asig7, asig8,asig9, asig10, asig11, asig12, asig13, asig14, asig15,asig16asig1, asig2, asig3, asig4, asig5, asig6, asig7, asig8,asig10, asig11, asig12, asig13, asig14, asig15, asig16,asig17, asig18, asig19, asig20, asig21, asig22, asig23,asig24, asig25, asig26, asig27, asig28, asig29, asig30,asig31, asig32outc asig1[, asig2,...]outch ksig1, asig1, ksig2, asig2, ...outz ksig165.2.1 DESCRIPTIONThese units write multi-channel audio data to an external device or stream.65.2.2 PERFORMANCEoutx and out32 output 16 and 32 channels of audio.outc outputs as many channels as provided. Any channels greater than nchnls are ignored, andzeros are added as necessaryoutch outputs asig1 on the channel determ<strong>in</strong>ed by ksig1, asig2 on the channel determ<strong>in</strong>ed byksig2, etc.outz outputs from a ZAK array, for nchnls of audio.65.2.3 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKMay, 2000 (New <strong>in</strong> <strong>Csound</strong> version 4.06)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Output Page 65-3


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Output Page 65-4


66 SIGNAL INPUT AND OUTPUT: FILE I/O66.1 dumpk, dumpk2, dumpk3, dumpk4, readk, readk2,readk3, readk4dumpk ksig, ifilname, iformat, iprddumpk2 ksig1, ksig2, ifilname, iformat, iprddumpk3 ksig1, ksig2, ksig3, ifilname, iformat, iprddumpk4 ksig1, ksig2, ksig3, ksig4, ifilname, iformat, iprdkr1 readk ifilname, iformat, iprd[, ipol]kr1,kr2 readk2 ifilname, iformat, iprd[, ipol]kr1,kr2, readk3 ifilname, iformat, iprd[, ipol]kr3kr1,kr2, readk4 ifilname, iformat, iprd[, ipol]kr3, kr466.1.1 DESCRIPTIONPeriodically write orchestra control-signal values to a named external file <strong>in</strong> a specific format.66.1.2 INITIALIZATIONifilname – character str<strong>in</strong>g(<strong>in</strong> double quotes, spaces permitted ) denot<strong>in</strong>g the external file name.May either be a full path name with target directory specified or a simple filename to be createdwith<strong>in</strong> the current directoryiformat – specifies the output data format:1 = 8-bit signed char(high order 8 bits of a 16-bit <strong>in</strong>teger,4 = 16-bit short <strong>in</strong>tegers,5 = 32bit long <strong>in</strong>tegers,6 = 32-bit floats, 7=ASCII long <strong>in</strong>tegers,8 = ASCII floats (2 decimal places).Note that A-law and U-law output are not available, and that all formats except the last two areb<strong>in</strong>ary. The output file conta<strong>in</strong>s no header <strong>in</strong>formation.iprd – the period of ksig output i seconds, rounded to the nearest orchestra control period. Avalue of 0 implies one control period (the enforced m<strong>in</strong>imum), which will create an output filesampled at the orchestra control rate.ipol (optional) – if non-zero, and iprd implies more than one control period, <strong>in</strong>terpolate the k-signals between the periodic reads from the external file. The default value is 0 (repeat eachsignal between frames). Currently not supported.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: File I/O Page 66-1


66.1.3 PERFORMANCEThese units allow up to four generated control signal values to be read or saved <strong>in</strong> a namedexternal file. The file conta<strong>in</strong>s no self-def<strong>in</strong><strong>in</strong>g header <strong>in</strong>formation, but is a regularly sampledtime series, suitable for later <strong>in</strong>put or analysis. There may be any number of readk units <strong>in</strong> an<strong>in</strong>strument or orchestra, and they may read from the same or different files. There may be anynumber of dumpk units <strong>in</strong> an <strong>in</strong>strument or orchestra, but each must write to a different file.66.1.4 OPCODE HISTORYdumpk opcodes were orig<strong>in</strong>ally called kdump. As of <strong>Csound</strong> version 3.493 that name isdeprecated. dumpk should be used <strong>in</strong>stead of kdump. The readk opcodes were orig<strong>in</strong>ally calledkread, but were not implemented until <strong>Csound</strong> version 3.52. However, the optional readkargument, ipol is ignored. This situation is expected to be corrected <strong>in</strong> a later release.66.1.5 EXAMPLEknum = knum+1 ; at each k-periodktemp tempest krms, .02, .1, 3, 2, 800, .005, 0, 60, 4, .1, .995;estimate the tempokoct specptrk wsig, 6, .9, 0 ;and the pitchdumpk3 knum, ktemp, cpsoct(koct), “what happened when”, 8 0;& save themThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: File I/O Page 66-2


66.2 fout, foutk, fouti, foutir, fiopenfout “ifilename”, iformat, aout1[, aout2, aout3,...,aoutN]foutk “ifilename”, iformat, kout1[, kout2, kout3,....,koutN]fouti ihandle, iformat, iflag, iout1[, iout2,iout3,....,ioutN]foutir ihandle, iformat, iflag, iout1[, iout2,\\iout3,....,ioutN]ihandle fiopen “ifilename”,imode66.2.1 DESCRIPTIONfout, foutk, fouti and foutir output N a-, k-, or i-rate signals to a specified file of N channels.fiopen can be used to open a file <strong>in</strong> one of the specified modes.66.2.2 INITIALIZATIONifilename – a double-quote delimited str<strong>in</strong>g file nameiformat – a flag to choose output file format:• for fout and foutk only:• 0 – 32-bit float<strong>in</strong>g po<strong>in</strong>t samples without header (b<strong>in</strong>ary PCM multichannel file)• 1 – 16-bit <strong>in</strong>tegers without header (b<strong>in</strong>ary PCM multichannel file)• 2 – 16-bit <strong>in</strong>tegers with .wav type header (Microsoft WAV mono or stereo file)• for fouti and foutir only:• 0 – float<strong>in</strong>g po<strong>in</strong>t <strong>in</strong> text format• 1 – 32-bit float<strong>in</strong>g po<strong>in</strong>t <strong>in</strong> b<strong>in</strong>ary formatiflag – choose the mode of writ<strong>in</strong>g to the ASCII file (valid only <strong>in</strong> ASCII mode; <strong>in</strong> b<strong>in</strong>ary modeiflag has no mean<strong>in</strong>g, but it must be present anyway). iflag can be a value chosen among thefollow<strong>in</strong>g:• 0 – l<strong>in</strong>e of text without <strong>in</strong>strument prefix• 1 – l<strong>in</strong>e of text with <strong>in</strong>strument prefix (see below)• 2 – reset the time of <strong>in</strong>strument prefixes to zero (to be used only <strong>in</strong> some particular cases.See below)iout,..., ioutN – values to be written to the fileimode – choose the mode of open<strong>in</strong>g the file. imode can be a value chosen among the follow<strong>in</strong>g:• 0 – open a text file for writ<strong>in</strong>g• 1 – open a text file for read<strong>in</strong>g• 2 – open a b<strong>in</strong>ary file for writ<strong>in</strong>g• 3 – open a b<strong>in</strong>ary file for read<strong>in</strong>gThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: File I/O Page 66-3


66.2.3 PERFORMANCEaout1,... aoutN – signals to be written to the filekout1,...koutN – signals to be written to the filefout (file output) writes samples of audio signals to a file with any number of channels. Channelnumber depends by the number of aoutN variables (i.e. a mono signal with only an a-rateargument, a stereo signal with two a-rate arguments etc.) Maximum number of channels is fixedto 64. Multiple fout opcodes can be present <strong>in</strong> the same <strong>in</strong>strument, referr<strong>in</strong>g to different files.Notice that, unlike out, outs and outq, fout does not zero the audio variable, so you must zero itafter call<strong>in</strong>g fout, if polyphony is to be used. You can use <strong>in</strong>cr and clear opcodes for this task.foutk operates <strong>in</strong> the same way as fout, but with k-rate signals. iformat can be set only to 0 or 1.fouti and foutir write i-rate values to a file. The ma<strong>in</strong> use of these opcodes is to generate a scorefile dur<strong>in</strong>g a real-time session. For this purpose, the user should set iformat to 0 (text file output)and iflag to 1, which enable the output of a prefix consist<strong>in</strong>g of the str<strong>in</strong>gs <strong>in</strong>um, actiontime, andduration, before the values of iout1...ioutN arguments. The arguments <strong>in</strong> the prefix refer to<strong>in</strong>strument number, action time and duration of current note.The difference between fouti and foutir is that, <strong>in</strong> the case of fouti, when iflag is set to 1, theduration of the first opcode is undef<strong>in</strong>ed (so it is replaced by a dot). Whereas, foutir is def<strong>in</strong>ed atthe end of note, so the correspond<strong>in</strong>g text l<strong>in</strong>e is written only at the end of the current note (<strong>in</strong>order to recognize its duration). The correspond<strong>in</strong>g file is l<strong>in</strong>ked by the ihandle value generatedby the fiopen opcode (see below). So fouti and foutir can be used to generate a <strong>Csound</strong> scorewhile play<strong>in</strong>g a real-time session.fiopen opens a file to be used by the fout family of opcodes. It must be def<strong>in</strong>ed <strong>in</strong> the headersection, external to any <strong>in</strong>struments. It returns a number, ihandle, which is unequivocallyreferr<strong>in</strong>g to the opened file.Notice that fout and foutk can use either a str<strong>in</strong>g conta<strong>in</strong><strong>in</strong>g a file pathname, or a handle-numbergenerated by fiopen. Whereas, with fouti and foutir, the target file can be only specified bymeans of a handle-number.66.2.4 AUTHORGabriel MaldonadoItaly1999New <strong>in</strong> <strong>Csound</strong> version 3.56The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: File I/O Page 66-4


66.3 f<strong>in</strong>, f<strong>in</strong>k, f<strong>in</strong>if<strong>in</strong>f<strong>in</strong>kf<strong>in</strong>i“ifilename”, iskipframes, iformat, a<strong>in</strong>1[, a<strong>in</strong>2,\\a<strong>in</strong>3,...,a<strong>in</strong>N]“ifilename”, iskipframes, iformat, k<strong>in</strong>1[, k<strong>in</strong>2,\\k<strong>in</strong>3,...,k<strong>in</strong>N]“ifilename”, iskipframes, iformat, <strong>in</strong>1[, <strong>in</strong>2,\\<strong>in</strong>3,...,<strong>in</strong>N]66.3.1 DESCRIPTIONRead signals from a file (at a-, k-, and i-rate)66.3.2 INITIALIZATIONifilename – <strong>in</strong>put file name (can be a str<strong>in</strong>g or a handle number generated by fiopen)iskipframes – number of frames to skip at the start (every frame conta<strong>in</strong>s a sample of eachchannel)iformat – a number specify<strong>in</strong>g the <strong>in</strong>put file formatfor f<strong>in</strong> and f<strong>in</strong>k:• 0 – 32 bit float<strong>in</strong>g po<strong>in</strong>ts without header• 1 – 16 bit <strong>in</strong>tegers without headerand for f<strong>in</strong>i:• 0 – float<strong>in</strong>g po<strong>in</strong>ts <strong>in</strong> text format (loop; see below)• 1 – float<strong>in</strong>g po<strong>in</strong>ts <strong>in</strong> text format (no loop; see below)• 2 – 32 bit float<strong>in</strong>g po<strong>in</strong>ts <strong>in</strong> b<strong>in</strong>ary format (no loop)66.3.3 PERFORMANCEf<strong>in</strong> (file <strong>in</strong>put) is the complement of fout: it reads a multichannel file to generate audio ratesignals. At the present time no header is supported for the file format. The user must be sure thatthe number of channels of the <strong>in</strong>put file is the same as the number of a<strong>in</strong>X arguments. f<strong>in</strong>k is thesame as f<strong>in</strong>, but operates at k-rate.f<strong>in</strong>i is the complement of fouti and foutir, it reads the values each time the correspond<strong>in</strong>g<strong>in</strong>strument note is activated. When iformat is set to 0, if the end of file is reached, the file po<strong>in</strong>teris zeroed, restart<strong>in</strong>g the scan from the beg<strong>in</strong>n<strong>in</strong>g. When iformat is set to 1 or 2, no loop<strong>in</strong>g isenabled, so at the end of file, the correspond<strong>in</strong>g variables will be filled with zeroes.66.3.4 AUTHORGabriel MaldonadoItaly1999New <strong>in</strong> <strong>Csound</strong> version 3.56The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: File I/O Page 66-5


66.4 v<strong>in</strong>cr, clearv<strong>in</strong>crclear66.4.1 DESCRIPTIONasig, a<strong>in</strong>cravar1[,avar2, avar3,...,avarN]v<strong>in</strong>cr <strong>in</strong>crements an audio variable of another signal, i.e. accumulates output. clear zeroes a listof audio signals.66.4.2 PERFORMANCEasig – audio variable to be <strong>in</strong>crementeda<strong>in</strong>cr – <strong>in</strong>crement<strong>in</strong>g signalavar1 [,avar2, avar3,...,avarN] – signals to be zeroedv<strong>in</strong>cr (variable <strong>in</strong>crement) and clear are <strong>in</strong>tended to be used together. v<strong>in</strong>cr stores the result ofthe sum of two audio variables <strong>in</strong>to the first variable itself (which is <strong>in</strong>tended to be used as anaccumulator <strong>in</strong> polyphony). The accumulator variable can be used for output signal by means offout opcode. After the disk writ<strong>in</strong>g operation, the accumulator variable should be set to zero bymeans of clear opcode (or it will explode).66.4.3 AUTHORGabriel MaldonadoItaly1999New <strong>in</strong> <strong>Csound</strong> version 3.56The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: File I/O Page 66-6


67 SIGNAL INPUT AND OUTPUT: SOUND FILEQUERIES67.1 filelen, filesr, filenchnls, filepeakir filelen “ifilcod”ir filesr “ifilcod”ir filenchnls “ifilcod”ir filepeak “ifilcod”[, ichnl]67.1.1 DESCRIPTIONObta<strong>in</strong>s <strong>in</strong>formation about a sound file.67.1.2 INITIALIZATIONifilecod – sound file to be queriedichnl – channel to be used <strong>in</strong> calculat<strong>in</strong>g the peak value. Default is 0.• ichnl = 0 returns peak value of all channels• ichnl > 0 returns peak value of ichnl67.1.3 PERFORMANCEfilelen returns the length of the sound file ifilcod <strong>in</strong> seconds. filesr returns the sample rate of thesound file ifilcod. filenchnls returns the number of channels <strong>in</strong> the sound file ifilcod. filepeakreturns the peak absolute value of the sound file ifilcod. Currently, filepeak supports only AIFF-C float files.67.1.4 AUTHORMatt IngallsJuly, 1999New <strong>in</strong> <strong>Csound</strong> version 3.57The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Sound File Queries Page 67-1


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Sound File Queries Page 67-2


68 SIGNAL INPUT AND OUTPUT: PRINTING ANDDISPLAY68.1 pr<strong>in</strong>t, display, dispfftpr<strong>in</strong>t iarg[, iarg,...]display xsig, iprd[, <strong>in</strong>prds[, iwtflg]]dispfft xsig, iprd, iwsiz[, iwtyp[, idbouti[, iwtflg]]]68.1.1 DESCRIPTIONThese units will pr<strong>in</strong>t orchestra <strong>in</strong>it-values, or produce graphic display of orchestra controlsignals and audio signals. Uses X11 w<strong>in</strong>dows if enabled, else (or if -g flag is set) displays areapproximated <strong>in</strong> ASCII characters.68.1.2 INITIALIZATIONiprd – the period of display <strong>in</strong> seconds.iwsiz – size of the <strong>in</strong>put w<strong>in</strong>dow <strong>in</strong> samples. A w<strong>in</strong>dow of iwsiz po<strong>in</strong>ts will produce a Fouriertransform of iwsiz/2 po<strong>in</strong>ts, spread l<strong>in</strong>early <strong>in</strong> frequency from 0 to sr/2. iwsiz must be a power of2, with a m<strong>in</strong>imum of 16 and a maximum of 4096. The w<strong>in</strong>dows are permitted to overlap.iwtyp (optional) – w<strong>in</strong>dow type. 0 = rectangular, 1 = Hann<strong>in</strong>g. The default value is 0(rectangular).idbout (optional) – units of output for the Fourier coefficients. 0 = magnitude, 1 = decibels. Thedefault is 0 (magnitude).iwtflg (optional) – wait flag. If non-zero, each display is held until released by the user. Thedefault value is 0 (no wait).68.1.3 PERFORMANCEpr<strong>in</strong>t – pr<strong>in</strong>t the current value of the i-time arguments (or expressions) iarg at every i-passthrough the <strong>in</strong>strument.display – display the audio or control signal xsig every iprd seconds, as an amplitude vs. timegraph.dispfft – display the Fourier Transform of an audio or control signal (asig or ksig) every iprdseconds us<strong>in</strong>g the Fast Fourier Transform method.68.1.4 EXAMPLEk1 envlpx l, .03, p3, .05, l, .5, .0l ; generate a note envelopedisplay k1, p3 ; and display entire shapeThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Pr<strong>in</strong>t<strong>in</strong>g and Display Page 68-1


68.2 pr<strong>in</strong>tk, pr<strong>in</strong>tkspr<strong>in</strong>tkpr<strong>in</strong>tksispace, kval [, itime]“txtstr<strong>in</strong>g”, itime, kval1, kval2, kval3, kval468.2.1 DESCRIPTIONThese opcodes are <strong>in</strong>tended to facilitate the debugg<strong>in</strong>g of orchestra code.68.2.2 INITIALIZATIONispace – number of spaces to <strong>in</strong>sert before pr<strong>in</strong>t<strong>in</strong>g. (Max 130.)itime – time <strong>in</strong> seconds between pr<strong>in</strong>t<strong>in</strong>gs. (Default 1 second.)“txtstr<strong>in</strong>g” – text to be pr<strong>in</strong>ted. Can be up to 130 characters and must be <strong>in</strong> double quotes.68.2.3 PERFORMANCEkvalx – The k-rate values to be pr<strong>in</strong>ted. These are specified <strong>in</strong> “txtstr<strong>in</strong>g” with the standard Cvalue specifier %f, <strong>in</strong> the order given. Use 0 for those which are not used.pr<strong>in</strong>tk pr<strong>in</strong>ts one k-rate value on every k cycle, every second or at <strong>in</strong>tervals specified. First the<strong>in</strong>strument number is pr<strong>in</strong>ted, then the absolute time <strong>in</strong> seconds, then a specified number ofspaces, then the kval value. The variable number of spaces enables different values to be spacedout across the screen – so they are easier to view.pr<strong>in</strong>tks pr<strong>in</strong>ts numbers and text, with up to four pr<strong>in</strong>table numbers – which can be i- or k-ratevalues. pr<strong>in</strong>tks is highly flexible, and if used together with cursor position<strong>in</strong>g codes, could beused to write specific values to locations <strong>in</strong> the screen as the <strong>Csound</strong> process<strong>in</strong>g proceeds.A special mode of operation allows this pr<strong>in</strong>tks to convert kval1 <strong>in</strong>put parameter <strong>in</strong>to a 0 to 255value and to use it as the first character to be pr<strong>in</strong>ted. This enables a <strong>Csound</strong> program to sendarbitrary characters to the console. To achieve this, make the first character of the str<strong>in</strong>g a # andthen, if desired cont<strong>in</strong>ue with normal text and format specifiers. Three more format specifies maybe used – they access kval2, kval3 and kval4.Both these opcodes can be run on every k cycle they are run <strong>in</strong> the <strong>in</strong>strument. To everyaccomplish this, set itime to 0.When itime is not 0, the opcode pr<strong>in</strong>t on the first k cycle it is called, and subsequently whenevery itime period has elapsed. The time cycles start from the time the opcode is <strong>in</strong>itialized –typically the <strong>in</strong>itialization of the <strong>in</strong>strument.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Pr<strong>in</strong>t<strong>in</strong>g and Display Page 68-2


68.2.4 PRINT OUTPUT FORMATTINGStandard C language pr<strong>in</strong>tf() control characters may be used, but must be prefaced with anadditional backslash:\\n or \\N\\t or \\TNewl<strong>in</strong>eTabThe standard C language %f format is used to pr<strong>in</strong>t kval1, kval2, kval3, and kval4. For example:%f pr<strong>in</strong>ts with full precision: 123.456789%6.2f pr<strong>in</strong>ts 1234.56%5.0p pr<strong>in</strong>ts 1234568.2.5 EXAMPLESThe follow<strong>in</strong>g:pr<strong>in</strong>tks \”Volume = %6.2f Freq = %8.3f\n\”, 0.1, kvol, kfreq, 0, 0would pr<strong>in</strong>t:Volume = 1234.56 Freq = 12345.678The follow<strong>in</strong>g:pr<strong>in</strong>tks \”#x\\y = %6.2\n\”, 0.1, kxy, 0, 0, 0would pr<strong>in</strong>t a tab character followed by:x\y = 1234.5668.2.6 AUTHORRob<strong>in</strong> WhittleAustraliaMay 1997The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Pr<strong>in</strong>t<strong>in</strong>g and Display Page 68-3


68.3 pr<strong>in</strong>tk2pr<strong>in</strong>tk2kvar [, numspaces]68.3.1 INITIALIZATIONnumspaces – number of space characters pr<strong>in</strong>ted before the value of kvar68.3.2 PERFORMANCEkvar - signal to be pr<strong>in</strong>tedDerived from Rob<strong>in</strong> Whittle’s pr<strong>in</strong>tk, pr<strong>in</strong>ts a new value of kvar each time kvar changes. Usefulfor monitor<strong>in</strong>g MIDI control changes when us<strong>in</strong>g sliders.WARNING! don’t use this opcode with normal, cont<strong>in</strong>uously variant k-signals, because it canhang the computer, as the rate of pr<strong>in</strong>t<strong>in</strong>g is too fast.68.3.3 AUTHORGabriel MaldonadoItaly1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Signal Input and Output: Pr<strong>in</strong>t<strong>in</strong>g and Display Page 68-4


69 THE STANDARD NUMERIC SCORE69.1 Preprocess<strong>in</strong>g of Standard ScoresA Score (a collection of score statements) is divided <strong>in</strong>to time-ordered sections by the sstatement. Before be<strong>in</strong>g read by the orchestra, a score is preprocessed one section at a time.Each section is normally processed by 3 rout<strong>in</strong>es: Carry, Tempo, and Sort.69.1.1 CARRYWith<strong>in</strong> a group of consecutive i statements whose p1 whole numbers correspond, any pfield leftempty will take its value from the same pfield of the preced<strong>in</strong>g statement. An empty pfield canbe denoted by a s<strong>in</strong>gle po<strong>in</strong>t (.) delimited by spaces. No po<strong>in</strong>t is required after the last nonemptypfield. The output of Carry preprocess<strong>in</strong>g will show the carried values explicitly. The CarryFeature is not affected by <strong>in</strong>terven<strong>in</strong>g comments or blank l<strong>in</strong>es; it is turned off only by a non-istatement or by an i statement with unlike p1 whole number.Three additional features are available for p2 alone: +, ^ + x, and ^ – x. The symbol + <strong>in</strong> p2 willbe given the value of p2 + p3 from the preced<strong>in</strong>g i statement. This enables note action times tobe automatically determ<strong>in</strong>ed from the sum of preced<strong>in</strong>g durations. The + symbol can itself becarried. It is legal only <strong>in</strong> p2. E.g.: the statementsi1 0 .5 100i . +iwill result <strong>in</strong>i1 0 .5 100i1 .5 .5 100i1 1 .5 100The symbols ^ + x and ^ – x determ<strong>in</strong>e the current p2 by add<strong>in</strong>g or subtract<strong>in</strong>g, respectively, thevalue of x from the preced<strong>in</strong>g p2. These may be used <strong>in</strong> p2 only.The Carry feature should be used liberally. Its use, especially <strong>in</strong> large scores, can greatly reduce<strong>in</strong>put typ<strong>in</strong>g and will simplify later changes.69.1.2 TEMPOThis operation time warps a score section accord<strong>in</strong>g to the <strong>in</strong>formation <strong>in</strong> a t statement. Thetempo operation converts p2 (and, for i statements, p3) from orig<strong>in</strong>al beats <strong>in</strong>to real seconds,s<strong>in</strong>ce those are the units required by the orchestra. After time warp<strong>in</strong>g, score files will be seen tohave orchestra-readable format demonstrated by the follow<strong>in</strong>g: i p1 p2beats p2seconds p3beatsp3seconds p4 p5 ....The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-1


69.1.3 SORTThis rout<strong>in</strong>e sorts all action-time statements <strong>in</strong>to chronological order by p2 value. It also sortsco<strong>in</strong>cident events <strong>in</strong>to precedence order. Whenever an f statement and an i statement have thesame p2 value, the f statement will precede. Whenever two or more i statements have the samep2 value, they will be sorted <strong>in</strong>to ascend<strong>in</strong>g p1 value order. If they also have the same p1 value,they will be sorted <strong>in</strong>to ascend<strong>in</strong>g p3 value order. Score sort<strong>in</strong>g is done section by section (see sstatement). Automatic sort<strong>in</strong>g implies that score statements may appear <strong>in</strong> any order with<strong>in</strong> asection.69.1.4 N.B.The operations Carry, Tempo and Sort are comb<strong>in</strong>ed <strong>in</strong> a 3-phase s<strong>in</strong>gle pass over a score file, toproduce a new file <strong>in</strong> orchestra-readable format ( see the Tempo example). Process<strong>in</strong>g can be<strong>in</strong>voked either explicitly by the Scsort command, or implicitly by <strong>Csound</strong> which processes thescore before call<strong>in</strong>g the orchestra. Source-format files and orchestra-readable files are both <strong>in</strong>ASCII character form, and may be either perused or further modified by standard text editors.User-written rout<strong>in</strong>es can be used to modify score files before or after the above processes,provided the f<strong>in</strong>al orchestra-readable statement format is not violated. Sections of differentformats can be sequentially batched; and sections of like format can be merged for automaticsort<strong>in</strong>g.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-2


69.2 Next-P and Previous-P SymbolsAt the close of any of the operations Carry, Tempo, and Sort, three additional score features are<strong>in</strong>terpreted dur<strong>in</strong>g file writeout: next-p, previous-p, and ramp<strong>in</strong>g.i statement pfields conta<strong>in</strong><strong>in</strong>g the symbols npx or ppx (where x is some <strong>in</strong>teger) will be replacedby the appropriate pfield value found on the next i statement (or previous i statement) that hasthe same p1. For example, the symbol np7 will be replaced by the value found <strong>in</strong> p7 of the nextnote that is to be played by this <strong>in</strong>strument. np and pp symbols are recursive and can referenceother np and pp symbols which can reference others, etc. <strong>Reference</strong>s must eventually term<strong>in</strong>ate<strong>in</strong> a real number or a ramp symbol. Closed loop references should be avoided. np and ppsymbols are illegal <strong>in</strong> p1,p2 and p3 (although they may reference these). np and pp symbols maybe Carried. np and pp references cannot cross a Section boundary. Any forward or backwardreference to a non-existent note-statement will be given the value zero.E.g.: the statementsi1 0 1 10 np4 pp5i1 1 1 20i1 1 1 30will result <strong>in</strong>i1 0 1 10 20 0i1 1 1 20 30 20i1 2 1 30 0 30np and pp symbols can provide an <strong>in</strong>strument with contextual knowledge of the score, enabl<strong>in</strong>git to glissando or crescendo, for <strong>in</strong>stance, toward the pitch or dynamic of some future event(which may or may not be immediately adjacent). Note that while the Carry feature willpropagate np and pp through unsorted statements, the operation that <strong>in</strong>terprets these symbols isact<strong>in</strong>g on a time-warped and fully sorted version of the score.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-3


69.3 Ramp<strong>in</strong>gi statement pfields conta<strong>in</strong><strong>in</strong>g the symbol < will be replaced by values derived from l<strong>in</strong>ear<strong>in</strong>terpolation of a time-based ramp. Ramps are anchored at each end by the first real numberfound <strong>in</strong> the same pfield of a preced<strong>in</strong>g and follow<strong>in</strong>g note played by the same <strong>in</strong>strument. E.g.:the statementsi1 0 1 100i1 1 1


69.4 Score Macros#def<strong>in</strong>e NAME # replacement text ##def<strong>in</strong>e NAME(a’ b’ c’) # replacement text #$NAME.#undef NAME69.4.1 DESCRIPTIONMacros are textual replacements which are made <strong>in</strong> the score as it is be<strong>in</strong>g presented to thesystem. The macro system <strong>in</strong> <strong>Csound</strong> is a very simple one, and uses the characters # and $ todef<strong>in</strong>e and call macros. This can allow for simpler score writ<strong>in</strong>g, and provide an elementaryalternative to full score generation systems. The score macro system is similar to, but<strong>in</strong>dependent of, the macro system <strong>in</strong> the orchestra language.#def<strong>in</strong>e NAME – def<strong>in</strong>es a simple macro. The name of the macro must beg<strong>in</strong> with a letter andcan consist of any comb<strong>in</strong>ation of letters and numbers. Case is significant. This form is limit<strong>in</strong>g,<strong>in</strong> that the variable names are fixed. More flexibility can be obta<strong>in</strong>ed by us<strong>in</strong>g a macro witharguments, described below.#def<strong>in</strong>e NAME(a’ b’ c’) – def<strong>in</strong>es a macro with arguments. This can be used <strong>in</strong> more complexsituations. The name of the macro must beg<strong>in</strong> with a letter and can consist of any comb<strong>in</strong>ation ofletters and numbers. With<strong>in</strong> the replacement text, the arguments can be substituted by the form:$A. In fact, the implementation def<strong>in</strong>es the arguments as simple macros. There may be up to 5arguments, and the names may be any choice of letters. Remember that case is significant <strong>in</strong>macro names.$NAME. – calls a def<strong>in</strong>ed macro. To use a macro, the name is used follow<strong>in</strong>g a $ character.The name is term<strong>in</strong>ated by the first character which is neither a letter nor a number. If it isnecessary for the name not to term<strong>in</strong>ate with a space, a period, which will be ignored, can beused to term<strong>in</strong>ate the name. The str<strong>in</strong>g, $NAME., is replaced by the replacement text from thedef<strong>in</strong>ition. The replacement text can also <strong>in</strong>clude macro calls.#undef NAME – undef<strong>in</strong>es a macro name. If a macro is no longer required, it can be undef<strong>in</strong>edwith #undef NAME.69.4.2 INITIALIZATION# replacement text # – The replacement text is any character str<strong>in</strong>g (not conta<strong>in</strong><strong>in</strong>g a #) and canextend over multiple l<strong>in</strong>es. The replacement text is enclosed with<strong>in</strong> the # characters, whichensure that additional characters are not <strong>in</strong>advertently captured.69.4.3 PERFORMANCESome care is needed with textual replacement macros, as they can sometimes do strange th<strong>in</strong>gs.They take no notice of any mean<strong>in</strong>g, so spaces are significant. This is why, unlike the Cprogramm<strong>in</strong>g language, the def<strong>in</strong>ition has the replacement text surrounded by # characters. Usedcarefully, this simple macro system is a powerful concept, but it can be abused.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-5


69.4.4 ANOTHER USE FOR MACROSWhen writ<strong>in</strong>g a complex score it is sometimes all too easy to forget to what the various<strong>in</strong>strument numbers refer. One can use macros to give names to the numbers. For example#def<strong>in</strong>e Flute#def<strong>in</strong>e Whoop#i1##i2#$Flute. 0 10 4000 440$Whoop. 5 169.4.5 EXAMPLES69.4.5.1 Simple Macroa note-event has a set of p-fields which are repeated:#def<strong>in</strong>e ARGS # 1.01 2.33 138#i1 0 1 8.001000 $ARGSi1 0 1 8.011500 $ARGSi1 0 1 8.021200 $ARGSi1 0 1 8.031000 $ARGSThis will get expanded before sort<strong>in</strong>g <strong>in</strong>to:i1 0 1 8.00 1000 1.01 2.33 138i1 0 1 8.01 1500 1.01 2.33 138i1 0 1 8.02 1200 1.01 2.33 138i1 0 1 8.03 1000 1.01 2.33 138This can save typ<strong>in</strong>g, and is makes revisions easier. If there were two sets of p-fields one couldhave a second macro (there is no real limit on the number of macros one can def<strong>in</strong>e).#def<strong>in</strong>e ARGS1 # 1.01 2.33 138##def<strong>in</strong>e ARGS2 # 1.41 10.33 1.00#i1 0 1 8.001000 $ARGS1i1 0 1 8.011500 $ARGS2i1 0 1 8.021200 $ARGS1i1 0 1 8.031000 $ARGS269.4.5.2 Macros with arguments#def<strong>in</strong>e ARG(A) # 2.345 1.03 $A 234.9#i1 0 1 8.00 1000 $ARG(2.0)i1 + 1 8.01 1200 $ARG(3.0)which expands toi1 0 1 8.00 1000 2.345 1.03 2.0 234.9i1 + 1 8.01 1200 2.345 1.03 3.0 234.969.4.6 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-6


69.5 Multiple File ScoreIt is sometimes convenient to have the score <strong>in</strong> more than one file. This use is supported by the#<strong>in</strong>clude facility which is part of the macro system. A l<strong>in</strong>e conta<strong>in</strong><strong>in</strong>g the text#<strong>in</strong>clude “filename”where the character “ can be replaced by any suitable character. For most uses the double quotesymbol will probably be the most convenient. The file name can <strong>in</strong>clude a full path.This takes <strong>in</strong>put from the named file until it ends, when <strong>in</strong>put reverts to the previous <strong>in</strong>put.There is currently a limit of 20 on the depth of <strong>in</strong>cluded files and macros.A suggested use of #<strong>in</strong>clude would be to def<strong>in</strong>e a set of macros which are part of the composer’sstyle. It could also be used to provide repeated sections.s#<strong>in</strong>clude “section1”;; Repeat thats#<strong>in</strong>clude “section1”Alternative methods of do<strong>in</strong>g repeats, use the r, m, and n statements.69.5.1 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-7


69.6 Evaluation of ExpressionsIn earlier versions of <strong>Csound</strong> the numbers presented <strong>in</strong> a score were used as given. There areoccasions when some simple evaluation would be easier. This need is <strong>in</strong>creased when there aremacros. To assist <strong>in</strong> this area the syntax of an arithmetic expressions with<strong>in</strong> square brackets [ ]has been <strong>in</strong>troduced. Expressions built from the operations +, -, *, /, %, and ^ are allowed,together with group<strong>in</strong>g with ( ). The expressions can <strong>in</strong>clude numbers, and naturally macroswhose values are numeric or arithmetic str<strong>in</strong>gs. All calculations are made <strong>in</strong> float<strong>in</strong>g po<strong>in</strong>tnumbers. Note that unary m<strong>in</strong>us is not yet supported.New <strong>in</strong> <strong>Csound</strong> version 3.56 are @x (next power-of-two greater than or equal to x) and @@x(next power-of-two-plus-one greater than or equal to x).69.6.1 EXAMPLEr3 CNTi1 0 [0.3*$CNT.]i1 + [($CNT./3)+0.2]eAs the three copies of the section have the macro $CNT. with the different values of 1, 2 and 3,this expands tosi1 0 0.3i1 0.3 0.533333si1 0 0.6i1 0.6 0.866667si1 0 0.9i1 0.9 1.2eThis is an extreme form, but the evaluation system can be used to ensure that repeated sectionsare subtly different.69.6.2 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-8


69.7 f Statement (or Function Table Statement)f p1 p2 p3 p4 ...69.7.1 DESCRIPTIONThis causes a GEN subrout<strong>in</strong>e to place values <strong>in</strong> a stored function table for use by <strong>in</strong>struments.69.7.2 P FIELDSp1 Table number (from 1 to 200) by which the stored function will beknown. A negative number requests that the table be destroyed.p2 Action time of function generation (or destruction) <strong>in</strong> beats.p3 Size of function table (i.e. number of po<strong>in</strong>ts) Must be a power of 2,or a power-of-2 plus 1 (see below). Maximum table size is 16777216(2**24) po<strong>in</strong>ts.p4 Number of the GEN rout<strong>in</strong>e to be called (see GEN ROUTINES). A negativevalue will cause rescal<strong>in</strong>g to be omitted.p5 |p6 | Parameters whose mean<strong>in</strong>g is determ<strong>in</strong>ed by the particular GEN| rout<strong>in</strong>e.. |. |69.7.3 SPECIAL CONSIDERATIONSFunction tables are arrays of float<strong>in</strong>g-po<strong>in</strong>t values. Arrays can be of any length <strong>in</strong> powers of 2;space allocation always provides for 2**n po<strong>in</strong>ts plus an additional guard po<strong>in</strong>t. The guard po<strong>in</strong>tvalue, used dur<strong>in</strong>g <strong>in</strong>terpolated lookup, can be automatically set to reflect the table’s purpose: Ifsize is an exact power of 2, the guard po<strong>in</strong>t will be a copy of the first po<strong>in</strong>t; this is appropriate for<strong>in</strong>terpolated wrap-around lookup as <strong>in</strong> oscili, etc., and should even be used for non-<strong>in</strong>terpolat<strong>in</strong>goscil for safe consistency. If size is set to 2**n + 1, the guard po<strong>in</strong>t value automatically extendsthe contour of table values; this is appropriate for s<strong>in</strong>gle-scan functions such <strong>in</strong> envplx, oscil1,oscil1i, etc.Table space is allocated <strong>in</strong> primary memory, along with <strong>in</strong>strument data space. The maximumtable number has a soft limit of 200; this can be extended if required.An exist<strong>in</strong>g function table can be removed by an f statement conta<strong>in</strong><strong>in</strong>g a negative p1 and anappropriate action time. A function table can also be removed by the generation of another tablewith the same p1. Functions are not automatically erased at the end of a score section.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-9


p2 action time is treated <strong>in</strong> the same way as <strong>in</strong> i statements with respect to sort<strong>in</strong>g andmodification by t statements. If an f statement and an i statement have the same p2, the sortergives the f statement precedence so that the function table will be available dur<strong>in</strong>g note<strong>in</strong>itialization.An f 0 statement (zero p1, positive p2) may be used to create an action time with no associatedaction. Such time markers are useful for padd<strong>in</strong>g out a score section (see s statement)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-10


69.8 i Statement (Instrument or Note Statement)i p1 p2 p3 p4 ...69.8.1 DESCRIPTIONThis statement calls for an <strong>in</strong>strument to be made active at a specific time and for a certa<strong>in</strong>duration. The parameter field values are passed to that <strong>in</strong>strument prior to its <strong>in</strong>itialization, andrema<strong>in</strong> valid throughout its Performance.69.8.2 P FIELDSp1p2p3Instrument number (from 1 to 200), usually a non-negative <strong>in</strong>teger. Anoptional fractional part can provide an additional tag for specify<strong>in</strong>gties between particular notes of consecutive clusters. A negative p1(<strong>in</strong>clud<strong>in</strong>g tag) can be used to turn off a particular `held’ note.Start<strong>in</strong>g time <strong>in</strong> arbitrary units called beats.Duration time <strong>in</strong> beats (usually positive). A negative value will<strong>in</strong>itiate a held note (see also ihold). A zero value will <strong>in</strong>voke an<strong>in</strong>itialization pass without performance (see also <strong>in</strong>str).p4 |p5 | Parameters whose significance is determ<strong>in</strong>ed by the <strong>in</strong>strument.. |. |69.8.3 SPECIAL CONSIDERATIONSBeats are evaluated as seconds, unless there is a t statement <strong>in</strong> this score section or a -t flag <strong>in</strong>the command l<strong>in</strong>e.Start<strong>in</strong>g or action times are relative to the beg<strong>in</strong>n<strong>in</strong>g of a section ( see s statement), which isassigned time 0.Note statements with<strong>in</strong> a section may be placed <strong>in</strong> any order. Before be<strong>in</strong>g sent to an orchestra,unordered score statements must first be processed by Sorter, which will reorder them byascend<strong>in</strong>g p2 value. Notes with the same p2 value will be ordered by ascend<strong>in</strong>g p1; if the samep1, then by ascend<strong>in</strong>g p3.Notes may be stacked, i.e., a s<strong>in</strong>gle <strong>in</strong>strument can perform any number of notes simultaneously.(The necessary copies of the <strong>in</strong>strument’s data space will be allocated dynamically by theorchestra loader.) Each note will normally turn off when its p3 duration has expired, or on receiptof a MIDI noteoff signal. An <strong>in</strong>strument can modify its own duration either by chang<strong>in</strong>g its p3value dur<strong>in</strong>g note <strong>in</strong>itialization, or by prolong<strong>in</strong>g itself through the action of a l<strong>in</strong>enr unit.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-11


An <strong>in</strong>strument may be turned on and left to perform <strong>in</strong>def<strong>in</strong>itely either by giv<strong>in</strong>g it a negative p3or by <strong>in</strong>clud<strong>in</strong>g an ihold <strong>in</strong> its i-time code. If a held note is active, an i statement with match<strong>in</strong>gp1 will not cause a new allocation but will take over the data space of the held note. The newpfields (<strong>in</strong>clud<strong>in</strong>g p3) will now be <strong>in</strong> effect, and an i-time pass will be executed <strong>in</strong> which theunits can either be newly <strong>in</strong>itialized or allowed to cont<strong>in</strong>ue as required for a tied note (seetigoto). A held note may be succeeded either by another held note or by a note of f<strong>in</strong>ite duration.A held note will cont<strong>in</strong>ue to perform across section end<strong>in</strong>gs (see s statement). It is halted onlyby turnoff or by an i statement with negative match<strong>in</strong>g p1 or by an e statement.It is possible to have multiple <strong>in</strong>stances (usually, but not necessarily, notes of different pitches)of the same <strong>in</strong>strument, held simultaneously, via negative p3 values. The <strong>in</strong>strument can then befed new parameters from the score. This is useful for avoid<strong>in</strong>g long hard-coded l<strong>in</strong>segs, and canbe accomplished by add<strong>in</strong>g a decimal part to the <strong>in</strong>strument number.For example, to hold three copies of <strong>in</strong>strument 10 <strong>in</strong> a simple chord:i10.1 0 -1 7.00i10.2 0 -1 7.04i10.3 0 -1 7.07Subsequent i statements can refer to the same sound<strong>in</strong>g note <strong>in</strong>stances, and if the <strong>in</strong>strumentdef<strong>in</strong>ition is done properly, the new p-fields can be used to alter the character of the notes <strong>in</strong>progress. For example, to bend the previous chord up an octave and release it:i10.1 1 1 8.00i10.2 1 1 8.04i10.3 1 1 8.07The <strong>in</strong>strument def<strong>in</strong>ition has to take this <strong>in</strong>to account, however, especially if clicks are to beavoided (see the example below).Note that the decimal <strong>in</strong>strument number notation cannot be used <strong>in</strong> conjunction with real-timeMIDI. In this case, the <strong>in</strong>strument would be monophonic while a note was held.Notes be<strong>in</strong>g tied to previous <strong>in</strong>stances of the same <strong>in</strong>strument, should skip most <strong>in</strong>itialization bymeans of tigoto, except for the values entered <strong>in</strong> score. For example, all table read<strong>in</strong>g opcodes <strong>in</strong>the <strong>in</strong>strument, should usually be skipped, as they store their phase <strong>in</strong>ternally. If this is suddenlychanged, there will be audible clicks <strong>in</strong> the output.Note that many opcodes (such as delay and reverb) are prepared for optional <strong>in</strong>itialization. Touse this feature, the tival flag is suitable. Therefore, they need not be hidden by a tigoto jump.Beg<strong>in</strong>n<strong>in</strong>g with <strong>Csound</strong> version 3.53, str<strong>in</strong>gs are recognized <strong>in</strong> p- fields for opcodes that acceptthem (convolve, adsyn, disk<strong>in</strong>, etc.). There may be only one str<strong>in</strong>g per score l<strong>in</strong>e.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-12


69.8.4 EXAMPLEHere is an <strong>in</strong>strument which can f<strong>in</strong>d out whether it is tied to a previous note (tival returns 1),and whether it is held (negative p3). Attack and release are handled accord<strong>in</strong>gly:<strong>in</strong>str 10icps <strong>in</strong>it cpspch(p4) ;Get target pitch from score eventiportime <strong>in</strong>it abs(p3)/7 ; Portamento time dep on note lengthiamp0 <strong>in</strong>it p5 ; Set default ampsiamp1 <strong>in</strong>it p5iamp2 <strong>in</strong>it p5itie tival ; Check if this note is tied,if itie == 1 igoto nofade<strong>in</strong> ; if not fade <strong>in</strong>iamp0 <strong>in</strong>it 0nofade<strong>in</strong>:if p3 < 0 igoto nofadeout ; Check if this note is held,; if not fade outiamp2 <strong>in</strong>it 0nofadeout:; Now do amp from the set values:kamp l<strong>in</strong>seg iamp0, .03, iamp1, abs(p3)-.03, iamp2; Skip rest of <strong>in</strong>itialization on tied note:tigoto tieskipkcps <strong>in</strong>it icps ; Init pitch for untied notekcps port icps, iportime, icps ; Drift towards target pitchkpw oscil .4, rnd(1), 1, rnd(.7) ; A simple triangle-saw oscilar vco kamp, kcps, 3, kpw+.5, 1, 1/icps; (Used <strong>in</strong> test<strong>in</strong>g - one may set ipch to cpspch(p4+2); and view output spectrum); ar oscil kamp, kcps, 1outartieskip:; Skip some <strong>in</strong>itialization on tied noteend<strong>in</strong>The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-13


A simple score us<strong>in</strong>g three <strong>in</strong>stances of the above <strong>in</strong>strument:f1 0 8192 10 1; S<strong>in</strong>ei10.1 0 -1 7.00 10000i10.2 0 -1 7.04i10.3 0 -1 7.07i10.1 1 -1 8.00i10.2 1 -1 8.04i10.3 1 -1 8.07i10.1 2 1 7.11i10.2 2 1 8.04i10.3 2 1 8.07eAdditional text (<strong>Csound</strong> version 4.0) expla<strong>in</strong><strong>in</strong>g tied notes, edited by Rasmus Ekman from a noteby David Kirsh, posted to the <strong>Csound</strong> mail<strong>in</strong>g list. Example <strong>in</strong>strument by Rasmus Ekman.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-14


69.9 a Statement (or Advance Statement)ap1 p2 p369.9.1 DESCRIPTIONThis causes score time to be advanced by a specified amount without produc<strong>in</strong>g sound samples.69.9.2 P FIELDSp1 Carries no mean<strong>in</strong>g. Usually zero.p2 Action time, <strong>in</strong> beats, at which advance is to beg<strong>in</strong>.p3 Number of beats to advance without produc<strong>in</strong>g sound.p4 |p5 | These carry no mean<strong>in</strong>g.p6 |..69.9.3 SPECIAL CONSIDERATIONSThis statement allows the beat count with<strong>in</strong> a score section to be advanced without generat<strong>in</strong>g<strong>in</strong>terven<strong>in</strong>g sound samples. This can be of use when a score section is <strong>in</strong>complete (the beg<strong>in</strong>n<strong>in</strong>gor middle is miss<strong>in</strong>g) and the user does not wish to generate and listen to a lot of silence.p2, action time, and p3, number of beats, are treated as <strong>in</strong> i statements, with respect to sort<strong>in</strong>gand modification by t statements.An a statement will be temporarily <strong>in</strong>serted <strong>in</strong> the score by the Score Extract feature when theextracted segment beg<strong>in</strong>s later than the start of a Section. The purpose of this is to preserve thebeat count and time count of the orig<strong>in</strong>al score for the benefit of the peak amplitude messageswhich are reported on the user console.Whenever an a statement is encountered by a perform<strong>in</strong>g orchestra, its presence and effect willbe reported on the user’s console.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-15


69.10 t Statement (Tempo Statement)tp1 p2 p3 p4 ... (unlimited)69.10.1 DESCRIPTIONThis statement sets the tempo and specifies the accelerations and decelerations for the currentsection. This is done by convert<strong>in</strong>g beats <strong>in</strong>to seconds.69.10.2 P FIELDSp1Must be zero.p2Initial tempo on beats per m<strong>in</strong>ute.p3, p5, p7,... Times <strong>in</strong> beats per m<strong>in</strong>ute (<strong>in</strong> non-decreas<strong>in</strong>g order).p4, p6, p8,... Tempi for the referenced beat times.69.10.3 SPECIAL CONSIDERATIONSTime and Tempo-for-that-time are given as ordered couples that def<strong>in</strong>e po<strong>in</strong>ts on a “tempo vs.time” graph. (The time-axis here is <strong>in</strong> beats so is not necessarily l<strong>in</strong>ear.) The beat-rate of aSection can be thought of as a movement from po<strong>in</strong>t to po<strong>in</strong>t on that graph: motion between twopo<strong>in</strong>ts of equal height signifies constant tempo, while motion between two po<strong>in</strong>ts of unequalheight will cause an accelerando or ritardando accord<strong>in</strong>gly. The graph can conta<strong>in</strong>discont<strong>in</strong>uities: two po<strong>in</strong>ts given equal times but different tempi will cause an immediate tempochange.Motion between different tempos over non-zero time is <strong>in</strong>verse l<strong>in</strong>ear. That is, an accelerandobetween two tempos M1 and M2 proceeds by l<strong>in</strong>ear <strong>in</strong>terpolation of the s<strong>in</strong>gle-beat durationsfrom 60/M1 to 60/M2.The first tempo given must be for beat 0.A tempo, once assigned, will rema<strong>in</strong> <strong>in</strong> effect from that time-po<strong>in</strong>t unless <strong>in</strong>fluenced by asucceed<strong>in</strong>g tempo, i.e. the last specified tempo will be held to the end of the section.A t statement applies only to the score section <strong>in</strong> which it appears. Only one t statement ismean<strong>in</strong>gful <strong>in</strong> a section; it can be placed anywhere with<strong>in</strong> that section. If a score section conta<strong>in</strong>sno t statement, then beats are <strong>in</strong>terpreted as seconds (i.e. with an implicit t 0 60 statement).N.B. If the <strong>Csound</strong> command <strong>in</strong>cludes a -t flag, the <strong>in</strong>terpreted tempo of all score t statementswill be overridden by the command-l<strong>in</strong>e tempo.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-16


69.11 b Statementbp169.11.1 DESCRIPTIONThis statement resets the clock for subsequent i statements.69.11.2 P FIELDSp1Specifies how the clock is to be set.69.11.3 SPECIAL CONSIDERATIONSp1 is the number of beats by which p2 values of subsequent i statements are modified. If p1 ispositive, the clock is reset forward, and subsequent notes appear later, the number of beatsspecified by p1 be<strong>in</strong>g added to the note’s p2. If p1 is negative, the clock is reset backward, andsubsequent notes appear earlier, the number of beats specified by p1 be<strong>in</strong>g subtracted from thenote’s p2. There is no cumulative affect. The clock is reset with each b statement. If p1 = 0, theclock is returned to its orig<strong>in</strong>al position, and subsequent notes appear at their specified p2.69.11.4 EXAMPLEi1 0 2i1 10 888b 5; set the clock "forward"i2 1 1 440 ; start time = 6i2 2 1 480 ; start time = 7b –1; set the clock backi3 3 2 3.1415 ; start time = 2i3 5.5 1 1.1111 ; start time = 4.5b 0; reset clock to normali4 10 200 7 ; start time = 10Explanation suggested and example provided by Paul W<strong>in</strong>kler. (<strong>Csound</strong> version 4.0)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-17


69.12 v Statementvp169.12.1 DESCRIPTIONThe v statement provides for locally variable time warp<strong>in</strong>g of score events.69.12.2 P FIELDSp1Time warp factor (must be positive).69.12.3 SPECIAL CONSIDERATIONSThe v statement takes effect with the follow<strong>in</strong>g i statement, and rema<strong>in</strong>s <strong>in</strong> effect until the nextv, s, or e statement.69.12.4 EXAMPLESThe value of p1 is used as a multiplier for the start times (p2) of subsequent i statements.i1 0 1 ;note1v2i1 1 1 ;note2In this example, the second note occurs two beats after the first note, and is twice as long.Although the v statement is similar to the t statement, the v statement is local <strong>in</strong> operation.That is, v affects only the follow<strong>in</strong>g notes, and its effect may be cancelled or changed by anotherv statement.Carried values (see Section 14.1.1) are unaffected by the v statement.i1 0 1 ;note1v2i1 1 . ;note2i1 2 . ;note3v1i1 3 . ;note4i1 4 . ;note5eIn this example, note2 and note4 occur simultaneously, while note3 actually occurs before note2,that is, at its orig<strong>in</strong>al place. Durations are unaffected.i1 0 1v2i. + .i. . .In this example, the v statement has no effect.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-18


69.13 s Statementsanyth<strong>in</strong>g69.13.1 DESCRIPTIONThe s statement marks the end of a section.69.13.2 P FIELDSAll p-fields are ignored.69.13.3 SPECIAL CONSIDERATIONSSort<strong>in</strong>g of the i, f and a statements by action time is done section by section.Time warp<strong>in</strong>g for the t statement is done section by section.All action times with<strong>in</strong> a section are relative to its beg<strong>in</strong>n<strong>in</strong>g. A section statement establishes anew relative time of 0, but has no other re<strong>in</strong>itializ<strong>in</strong>g effects (e.g. stored function tables arepreserved across section boundaries).A section is considered complete when all action times and f<strong>in</strong>ite durations have been satisfied(i.e., the “length” of a section is determ<strong>in</strong>ed by the last occurr<strong>in</strong>g action or turn-off). A sectioncan be extended by the use of an f0 statement.A section end<strong>in</strong>g automatically <strong>in</strong>vokes a Purge of <strong>in</strong>active <strong>in</strong>strument and data spaces.Note: S<strong>in</strong>ce score statements are processed section by section, the amount of memory requireddepends on the maximum number of score statements <strong>in</strong> a section. Memory allocation isdynamic, and the user will be <strong>in</strong>formed as extra memory blocks are requested dur<strong>in</strong>g scoreprocess<strong>in</strong>g.For the end of the f<strong>in</strong>al section of a score, the s statement is optional; the e statement may beused <strong>in</strong>stead.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-19


69.14 e Statementeanyth<strong>in</strong>g69.14.1 DESCRIPTIONThis statement may be used to mark the end of the last section of the score.69.14.2 P FIELDSAll pfields are ignored.69.14.3 SPECIAL CONSIDERATIONSThe e statement is contextually identical to an s statement. Additionally, the e statementterm<strong>in</strong>ates all signal generation (<strong>in</strong>clud<strong>in</strong>g <strong>in</strong>def<strong>in</strong>ite performance) and closes all <strong>in</strong>put andoutput files.If an e statement occurs before the end of a score, all subsequent score l<strong>in</strong>es will be ignored.The e statement is optional <strong>in</strong> a score file yet to be sorted. If a score file has no e statement,then Sort process<strong>in</strong>g will supply one.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-20


69.15 r Statement (Repeat Statement)rp1 p269.15.1 DESCRIPTIONStarts a repeated section, which lasts until the next s, r or e statement.69.15.2 P FIELDSp1p2Number of times to repeat the section.Macro(name) to advance with each repetition (optional).69.15.3 SPECIAL CONSIDERATIONSIn order that the sections may be more flexible than simple edit<strong>in</strong>g, the macro named p2 is giventhe value of 1 for the first time through the section, 2 for the second, and 3 for the third. This canbe used to change p-field parameters, or ignored.WARNING: Because of serious problems of <strong>in</strong>teraction with macro expansion, sections muststart and end <strong>in</strong> the same file, and not <strong>in</strong> a macro.69.15.4 EXAMPLEIn the follow<strong>in</strong>g example, the section is repeated 3 times. The macro NN is used and advancedwith each repetition.r3 NN ;start of repeated section – use macro NNsome code...s ;end repeat - go back to previous r if repetitions < 369.15.5 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-21


69.16 m Statement (Mark Statement)mp169.16.1 DESCRIPTIONSets a named mark <strong>in</strong> the score, which can be referenced by an n statement.69.16.2 P FIELDSp1Name of mark.69.16.3 SPECIAL CONSIDERATIONSThis can be helpful <strong>in</strong> sett<strong>in</strong>g a up verse and chorus structure <strong>in</strong> the score. Names may conta<strong>in</strong>letters and numerals.69.16.4 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-22


69.17 n Statementnp169.17.1 DESCRIPTIONRepeats a section from the referenced m statement.69.17.2 P FIELDSp1Name of mark to repeat.69.17.3 SPECIAL CONSIDERATIONSThis can be helpful <strong>in</strong> sett<strong>in</strong>g a up verse and chorus structure <strong>in</strong> the score. Names may conta<strong>in</strong>letters and numerals.69.17.4 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKApril, 1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-23


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The Standard Numeric Score Page 69-24


70 GEN ROUTINESThe GEN subrout<strong>in</strong>es are function-draw<strong>in</strong>g procedures called by f statements to construct storedwavetables. They are available throughout orchestra performance, and can be <strong>in</strong>voked at anypo<strong>in</strong>t <strong>in</strong> the score as given by p2. p1 assigns a table number, and p3 the table size ( see fstatement). p4 specifies the GEN rout<strong>in</strong>e to be called; each GEN rout<strong>in</strong>e will assign specialmean<strong>in</strong>g to the pfield values that follow.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-1


70.1 GEN01f# time size 1 filcod skiptime format channel70.1.1 DESCRIPTIONThis subrout<strong>in</strong>e transfers data from a soundfile <strong>in</strong>to a function table.70.1.2 INITIALIZATIONsize – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or a power-of-2 plus 1 (see fstatement), with the one exception: allocation of table size can be deferred by sett<strong>in</strong>g thisparameter to 0. See Notes, below. The maximum table size is 16777216 (2 24 ) po<strong>in</strong>ts. Read<strong>in</strong>gstops at end-of-file or when the table is full. Table locations not filled will conta<strong>in</strong> zeros.filcod – <strong>in</strong>teger or character-str<strong>in</strong>g denot<strong>in</strong>g the source soundfile name. An <strong>in</strong>teger denotes thefile sound<strong>in</strong>.filcod ; a character-str<strong>in</strong>g (<strong>in</strong> double quotes, spaces permitted) gives the filenameitself, optionally a full pathname. If not a full path, the file is sought first <strong>in</strong> the current directory,then <strong>in</strong> that given by the environment variable SSDIR (if def<strong>in</strong>ed) then by SFDIR. See alsosound<strong>in</strong>.skiptime – beg<strong>in</strong> read<strong>in</strong>g at skiptime seconds <strong>in</strong>to the file.channel – channel number to read <strong>in</strong>. 0 denotes read all channels. An AIFF source can be monoor stereo.format – specifies the audio data-file format:1 - 8-bit signed character 4 - 16-bit short <strong>in</strong>tegers2 - 8-bit A-law bytes 5 - 32-bit long <strong>in</strong>tegers3 - 8-bit U-law bytes 6 - 32-bit floatsIf format = 0 the sample format is taken from the soundfile header, or by default from the<strong>Csound</strong> -o command flag.70.1.3 NOTESIf the source soundfile is of type AIFF, allocation of table size can be deferred by sett<strong>in</strong>g size to0. The size allocated is then the number of po<strong>in</strong>ts (or samples) <strong>in</strong> the file, which is probably not apower-of-2. In this case, the table generated is usable only by loscil Us<strong>in</strong>g the form “@N” forsize, where N = the number of samples <strong>in</strong> the sound file, will give the lowest power of 2 greaterthan or equal to N. Us<strong>in</strong>g the form “@@N”, adds one to that number, giv<strong>in</strong>g a power-of-2 plus 1sized table.If p4 is positive, the table will be post-normalized (rescaled to a maximum absolute value of 1after generation). A negative p4 will cause rescal<strong>in</strong>g to be skipped.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-2


70.1.4 EXAMPLESf 1 0 8192 1 23 0 4f 2 0 0 -1 “trumpet A#5” 0 4The tables are filled from 2 files, “sound<strong>in</strong>.23” and “trumpet A#5”, expected <strong>in</strong> SSDIR orSFDIR. The first table is pre-allocated; the second is allocated dynamically, and its rescal<strong>in</strong>g is<strong>in</strong>hibited. .The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-3


70.2 GEN02f # time size 2 v1 v2 v3 . . .70.2.1 DESCRIPTIONThis subrout<strong>in</strong>e transfers data from immediate pfields <strong>in</strong>to a function table.70.2.2 INITIALIZATIONsize – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or a power-of-2 plus 1 ( see fstatement). The maximum tablesize is 16777216 (2 24 ) po<strong>in</strong>ts.v1, v2, v3, ... – values to be copied directly <strong>in</strong>to the table space. The number of values is limitedby the compile-time variable PMAX, which controls the maximum pfields (currently 150). Thevalues copied may <strong>in</strong>clude the table guard po<strong>in</strong>t; any table locations not filled will conta<strong>in</strong> zeros.70.2.3 NOTEIf p4 is positive, the table will be post-normalized (rescaled to a maximum absolute value of 1after generation). A negative p4 will cause rescal<strong>in</strong>g to be skipped.70.2.4 EXAMPLEf 1 0 16 -2 0 1 2 3 4 5 6 7 8 9 10 11 0This calls upon GEN02 to place 12 values plus an explicit wrap-around guard value <strong>in</strong>to a tableof size next-highest power of 2. Rescal<strong>in</strong>g is <strong>in</strong>hibited.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-4


70.3 GEN03f# time size 3 xval1 xval2 c0 c1 c2 . . . cn70.3.1 DESCRIPTIONThis subrout<strong>in</strong>e generates a stored function table by evaluat<strong>in</strong>g a polynomial <strong>in</strong> x over a fixed<strong>in</strong>terval and with specified coefficients.70.3.2 INITIALIZATIONsize - number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or a power-of-2 plus 1 ( ).xval1, xval2 - left and right values of the x <strong>in</strong>terval over which the polynomial is def<strong>in</strong>ed (xval1


70.4 GEN04f # time size 4 source# sourcemode70.4.1 DESCRIPTIONThis subrout<strong>in</strong>e generates a normaliz<strong>in</strong>g function by exam<strong>in</strong><strong>in</strong>g the contents of an exist<strong>in</strong>g table.70.4.2 INITIALIZATIONsize - number of po<strong>in</strong>ts <strong>in</strong> the table. Should be power-of-2 plus 1. Must not exceed (except by 1)the size of the source table be<strong>in</strong>g exam<strong>in</strong>ed; limited to just half that size if the sourcemode is oftype offset (see below).source # – table number of stored function to be exam<strong>in</strong>ed.sourcemode – a coded value, specify<strong>in</strong>g how the source table is to be scanned to obta<strong>in</strong> thenormaliz<strong>in</strong>g function. Zero <strong>in</strong>dicates that the source is to be scanned from left to right. Non-zero<strong>in</strong>dicates that the source has a bipolar structure; scann<strong>in</strong>g will beg<strong>in</strong> at the mid-po<strong>in</strong>t andprogress outwards, look<strong>in</strong>g at pairs of po<strong>in</strong>ts equidistant from the center.70.4.3 NOTEThe normaliz<strong>in</strong>g function derives from the progressive absolute maxima of the source tablebe<strong>in</strong>g scanned. The new table is created left-to-right, with stored values equal to 1/(absolutemaximum so far scanned). Stored values will thus beg<strong>in</strong> with 1/(first value scanned), then getprogressively smaller as new maxima are encountered. For a source table which is normalized(values


70.5 GEN05, GEN07f # time size 5 a n1 b n2 c . . .f # time size 7 a n1 b n2 c . . .70.5.1 DESCRIPTIONThese subrout<strong>in</strong>es are used to construct functions from segments of exponential curves (GEN05)or straight l<strong>in</strong>es (GEN07).70.5.2 INITIALIZATIONsize - number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or power-of-2 plus 1 (see f statement).a, b, c, etc. – ord<strong>in</strong>ate values, <strong>in</strong> odd-numbered pfields p5, p7, p9, . . . For GEN05 these must benonzero and must be alike <strong>in</strong> sign. No such restrictions exist for GEN07.n1, n2, etc. – length of segment (no. of storage locations), <strong>in</strong> even-numbered pfields. Cannot benegative, but a zero is mean<strong>in</strong>gful for specify<strong>in</strong>g discont<strong>in</strong>uous waveforms (e.g. <strong>in</strong> the examplebelow). The sum n1 + n2 + .... will normally equal size for fully specified functions. If the sum issmaller, the function locations not <strong>in</strong>cluded will be set to zero; if the sum is greater, only the firstsize locations will be stored.70.5.3 NOTEIf p4 is positive, functions are post-normalized (rescaled to a maximum absolute value of 1 aftergeneration). A negative p4 will cause rescal<strong>in</strong>g to be skipped.Discrete-po<strong>in</strong>t l<strong>in</strong>ear <strong>in</strong>terpolation implies an <strong>in</strong>crease or decrease along a segment by equaldifferences between adjacent locations; exponential <strong>in</strong>terpolation implies that the progression isby equal ratio. In both forms the <strong>in</strong>terpolation from a to b is such as to assume that the value bwill be atta<strong>in</strong>ed <strong>in</strong> the n + 1th location. For discont<strong>in</strong>uous functions, and for the segmentencompass<strong>in</strong>g the end location, this value will not actually be reached, although it mayeventually appear as a result of f<strong>in</strong>al scal<strong>in</strong>g.70.5.4 EXAMPLEf 1 0 256 7 0 128 1 0 -1 128 0This describes a s<strong>in</strong>gle-cycle sawtooth whose discont<strong>in</strong>uity is mid-way <strong>in</strong> the stored function.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-7


70.6 GEN06f # time size 6 a n1 b n2 c n3 d . . .70.6.1 DESCRIPTIONThis subrout<strong>in</strong>e will generate a function comprised of segments of cubic polynomials, spann<strong>in</strong>gspecified po<strong>in</strong>ts just three at a time.70.6.2 INITIALIZATIONsize – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power off or power-of-2 plus 1 (see f statement).a, c, e, ... – local maxima or m<strong>in</strong>ima of successive segments, depend<strong>in</strong>g on the relation of thesepo<strong>in</strong>ts to adjacent <strong>in</strong>flexions. May be either positive or negative.b, d, f, ... – ord<strong>in</strong>ate values of po<strong>in</strong>ts of <strong>in</strong>flexion at the ends of successive curved segments. Maybe positive or negative.n1, n2, n3... – number of stored values between specified po<strong>in</strong>ts. Cannot be negative, but a zerois mean<strong>in</strong>gful for specify<strong>in</strong>g discont<strong>in</strong>uities. The sum n1 + n2 + ... will normally equal size forfully specified functions. (for details, see GEN05).70.6.3 NOTEGEN06 constructs a stored function from segments of cubic polynomial functions. Segmentsl<strong>in</strong>k ord<strong>in</strong>ate values <strong>in</strong> groups of 3: po<strong>in</strong>t of <strong>in</strong>flexion, maximum/m<strong>in</strong>imum, po<strong>in</strong>t of <strong>in</strong>flexion.The first complete segment encompasses b, c, d and has length n2 + n3, the next encompasses d,e, f and has length n4 + n5, etc. The first segment (a, b with length n1) is partial with only one<strong>in</strong>flexion; the last segment may be partial too. Although the <strong>in</strong>flexion po<strong>in</strong>ts b, d, f ... each figure<strong>in</strong> two segments (to the left and right), the slope of the two segments rema<strong>in</strong>s <strong>in</strong>dependent at thatcommon po<strong>in</strong>t (i.e. the 1st derivative will likely be discont<strong>in</strong>uous). When a, c, e... are alternatelymaximum and m<strong>in</strong>imum, the <strong>in</strong>flexion jo<strong>in</strong>s will be relatively smooth; for successive maxima orsuccessive m<strong>in</strong>ima the <strong>in</strong>flexions will be comb-like.70.6.4 EXAMPLEf 1 0 65 6 0 16 .5 16 1 16 0 16 -1This creates a curve runn<strong>in</strong>g 0 to 1 to -1, with a m<strong>in</strong>imum, maximum and m<strong>in</strong>imum at thesevalues respectively. Inflexions are at .5 and 0, and are relatively smooth.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-8


70.7 GEN08f # time size 8 a n1 b n2 c n3 d . . .70.7.1 DESCRIPTIONThis subrout<strong>in</strong>e will generate a piecewise cubic spl<strong>in</strong>e curve, the smoothest possible through allspecified po<strong>in</strong>ts.70.7.2 INITIALIZATIONsize – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or power-of-2 plus 1 (see f statement).a, b, c ... – ord<strong>in</strong>ate values of the function.n1, n2, n3 ... – length of each segment measured <strong>in</strong> stored values. May not be zero, but may befractional. A particular segment may or may not actually store any values; stored values will begenerated at <strong>in</strong>tegral po<strong>in</strong>ts from the beg<strong>in</strong>n<strong>in</strong>g of the function. The sum n1 + n2 + ... willnormally equal size for fully specified functions.70.7.3 NOTEGEN08 constructs a stored table from segments of cubic polynomial functions. Each segmentruns between two specified po<strong>in</strong>ts but depends as well on their neighbors on each side.Neighbor<strong>in</strong>g segments will agree <strong>in</strong> both value and slope at their common po<strong>in</strong>t. (The commonslope is that of a parabola through that po<strong>in</strong>t and its two neighbors). The slope at the two ends ofthe function is constra<strong>in</strong>ed to be zero (flat).H<strong>in</strong>t: to make a discont<strong>in</strong>uity <strong>in</strong> slope or value <strong>in</strong> the function as stored, arrange a series of po<strong>in</strong>ts<strong>in</strong> the <strong>in</strong>terval between two stored values; likewise for a non-zero boundary slope.70.7.4 EXAMPLESf 1 0 65 8 0 16 0 16 1 16 0 16 0This example creates a curve with a smooth hump <strong>in</strong> the middle, go<strong>in</strong>g briefly negative outsidethe hump then flat at its ends.f 2 0 65 8 0 16 0 .1 0 15.9 1 15.90 .1 0 16 0This example is similar, but does not go negative.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-9


70.8 GEN09, GEN10, GEN19f # time size 9 pna stra phsa pnb strb phsb . . .f # time size 10 str1 str2 str3 str4 . . . .f # time size 19 pna stra phsa dcoa pnb strb \\phsb dcob . . .70.8.1 DESCRIPTIONThese subrout<strong>in</strong>es generate composite waveforms made up of weighted sums of simples<strong>in</strong>usoids. The specification of each contribut<strong>in</strong>g partial requires 3 pfields us<strong>in</strong>g GEN09, 1 us<strong>in</strong>gGEN10, and 4 us<strong>in</strong>g GEN19.70.8.2 INITIALIZATIONsize - number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or power-of-2 plus 1 (see f statement).pna, pnb, etc. – partial no. (relative to a fundamental that would occupy size locations per cycle)of s<strong>in</strong>usoid a, s<strong>in</strong>usoid b, etc. Must be positive, but need not be a whole number, i.e., nonharmonicpartials are permitted. Partials may be <strong>in</strong> any order.stra, strb, etc. – strength of partials pna, pnb, etc. These are relative strengths, s<strong>in</strong>ce thecomposite waveform may be rescaled later. Negative values are permitted and imply a 180degree phase shift.phsa, phsb, etc. – <strong>in</strong>itial phase of partials pna, pnb, etc., expressed <strong>in</strong> degrees.dcoa, dcob, etc. – DC offset of partials pna, pnb, etc. This is applied after strength scal<strong>in</strong>g, i.e. avalue of 2 will lift a 2-strength s<strong>in</strong>usoid from range [-2,2] to range [0,4] (before later rescal<strong>in</strong>g).str1, str2, str3, etc. – relative strengths of the fixed harmonic partial numbers 1,2,3, etc.,beg<strong>in</strong>n<strong>in</strong>g <strong>in</strong> p5. Partials not required should be given a strength of zero.70.8.3 NOTEThese subrout<strong>in</strong>es generate stored functions as sums of s<strong>in</strong>usoids of different frequencies. Thetwo major restrictions on GEN10 that the partials be harmonic and <strong>in</strong> phase do not apply toGEN09 or GEN19.In each case the composite wave, once drawn, is then rescaled to unity if p4 was positive. Anegative p4 will cause rescal<strong>in</strong>g to be skipped.70.8.4 EXAMPLESf 1 0 1024 9 1 3 0 3 1 0 9 .3333180f 2 0 1024 19 .5 1 270 1f 1 comb<strong>in</strong>es partials l, 3 and 9 <strong>in</strong> the relative strengths <strong>in</strong> which they are found <strong>in</strong> a square wave,except that partial 9 is upside down. f 2 creates a ris<strong>in</strong>g sigmoid [0 – 2]. Both will be rescaled.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-10


70.9 GEN11f # time size 11 nh [lh [r]]70.9.1 DESCRIPTIONThis subrout<strong>in</strong>e generates an additive set of cos<strong>in</strong>e partials, <strong>in</strong> the manner of <strong>Csound</strong> generatorsbuzz and gbuzz.70.9.2 INITIALIZATIONsize - number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or power-of-2 plus 1 (see f statement).nh - number of harmonics requested. Must be positive.lh (optional) – lowest harmonic partial present. Can be positive, zero or negative. The set ofpartials can beg<strong>in</strong> at any partial number and proceeds upwards; if lh is negative, all partialsbelow zero will reflect <strong>in</strong> zero to produce positive partials without phase change (s<strong>in</strong>ce cos<strong>in</strong>e isan even function), and will add constructively to any positive partials <strong>in</strong> the set. The defaultvalue is 1r (optional) – multiplier <strong>in</strong> an amplitude coefficient series. This is a power series: if the lhthpartial has a strength coefficient of A the (lh + n)th partial will have a coefficient of A * r n, i.e.strength values trace an exponential curve. r may be positive, zero or negative, and is notrestricted to <strong>in</strong>tegers. The default value is 1.70.9.3 NOTEThis subrout<strong>in</strong>e is a non-time-vary<strong>in</strong>g version of the <strong>Csound</strong> buzz and gbuzz generators, and issimilarly useful as a complex sound source <strong>in</strong> subtractive synthesis. With lh and r present itparallels gbuzz; with both absent or equal to 1 it reduces to the simpler buzz (i.e. nh equalstrengthharmonic partials beg<strong>in</strong>n<strong>in</strong>g with the fundamental).Sampl<strong>in</strong>g the stored waveform with an oscillator is more efficient than us<strong>in</strong>g dynamic buzz units.However, the spectral content is <strong>in</strong>variant, and care is necessary lest the higher partials exceedthe Nyquist dur<strong>in</strong>g sampl<strong>in</strong>g to produce foldover.70.9.4 EXAMPLESf 1 0 2049 11 4f 2 0 2049 11 4 1 1f 3 0 2049 -11 7 3 .5The first two tables will conta<strong>in</strong> identical band-limited pulse waves of four equal-strengthharmonic partials beg<strong>in</strong>n<strong>in</strong>g with the fundamental. The third table will sum seven consecutiveharmonics, beg<strong>in</strong>n<strong>in</strong>g with the third, and at progressively weaker strengths (1, .5, .25, .125 . . .).It will not be post-normalized.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-11


70.10 GEN12f # time size -12 x<strong>in</strong>t70.10.1 DESCRIPTIONThis generates the log of a modified Bessel function of the second k<strong>in</strong>d, order 0, suitable for use<strong>in</strong> amplitude-modulated FM.70.10.2 INITIALIZATIONsize - number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or a power-of-2 plus 1 (see fstatement). The normal value is power-of-2 plus 1.x<strong>in</strong>t – specifies the x <strong>in</strong>terval [0 to +<strong>in</strong>t] over which the function is def<strong>in</strong>ed.70.10.3 NOTEThis subrout<strong>in</strong>e draws the natural log of a modified Bessel function of the second k<strong>in</strong>d, order 0(commonly written as I subscript 0), over the x-<strong>in</strong>terval requested. The call should have rescal<strong>in</strong>g<strong>in</strong>hibited.The function is useful as an amplitude scal<strong>in</strong>g factor <strong>in</strong> cycle-synchronous amplitude-modulatedFM. (See Palam<strong>in</strong> & Palam<strong>in</strong>, J. Audio Eng. Soc., 36/9, Sept. 1988, pp.671-684.) The algorithmis <strong>in</strong>terest<strong>in</strong>g because it permits the normally symmetric FM spectrum to be made asymmetricaround a frequency other than the carrier, and is thereby useful for formant position<strong>in</strong>g. By us<strong>in</strong>ga table lookup <strong>in</strong>dex of I(r – 1/r), where I is the FM modulation <strong>in</strong>dex and r is an exponentialparameter affect<strong>in</strong>g partial strengths, the Palam<strong>in</strong> algorithm becomes relatively efficient,requir<strong>in</strong>g only oscils, table lookups, and a s<strong>in</strong>gle exp call.70.10.4 EXAMPLEf 1 0 2049 -12 20This draws an unscaled ln(I0(x)) from 0 to 20.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-12


70.11 GEN13, GEN14f # time size 13 x<strong>in</strong>t xamp h0 h1 h2 . . . hnf # time size 14 x<strong>in</strong>t xamp h0 h1 h2 . . . hn70.11.1 DESCRIPTIONThese subrout<strong>in</strong>es use Chebyshev coefficients to generate stored polynomial functions which,under waveshap<strong>in</strong>g, can be used to split a s<strong>in</strong>usoid <strong>in</strong>to harmonic partials hav<strong>in</strong>g a pre-def<strong>in</strong>ablespectrum.70.11.2 INITIALIZATIONsize – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or a power-of-2 plus 1 (see fstatement). The normal value is power-of-2 plus 1.x<strong>in</strong>t – provides the left and right values [-x<strong>in</strong>t, +x<strong>in</strong>t] of the x <strong>in</strong>terval over which the polynomialis to be drawn. These subrout<strong>in</strong>es both call GEN03 to draw their functions; the p5 value here istherefor expanded to a negative-positive p5,p6 pair before GEN03 is actually called. The normalvalue is 1.xamp - amplitude scal<strong>in</strong>g factor of the s<strong>in</strong>usoid <strong>in</strong>put that is expected to produce the follow<strong>in</strong>gspectrum.h0, h1, h2, .... hn – relative strength of partials 0 (DC), 1 (fundamental), 2 ... that will result whena s<strong>in</strong>usoid of amplitudexamp * <strong>in</strong>t(size/2)/x<strong>in</strong>tis waveshaped us<strong>in</strong>g this function table. These values thus describe a frequency spectrumassociated with a particular factor xamp of the <strong>in</strong>put signal.70.11.3 NOTE:GEN13 is the function generator normally employed <strong>in</strong> standard waveshap<strong>in</strong>g. It stores apolynomial whose coefficients derive from the Chebyshev polynomials of the first k<strong>in</strong>d, so that adriv<strong>in</strong>g s<strong>in</strong>usoid of strength xamp will exhibit the specified spectrum at output. Note that theevolution of this spectrum is generally not l<strong>in</strong>ear with vary<strong>in</strong>g xamp. However, it is bandlimited(the only partials to appear will be those specified at generation time); and the partials will tendto occur and to develop <strong>in</strong> ascend<strong>in</strong>g order (the lower partials dom<strong>in</strong>at<strong>in</strong>g at low xamp, and thespectral richness <strong>in</strong>creas<strong>in</strong>g for higher values of xamp). A negative hn value implies a 180 degreephase shift of that partial; the requested full-amplitude spectrum will not be affected by this shift,although the evolution of several of its component partials may be. The pattern +,+,-,-,+,+,... forh0,h1,h2... will m<strong>in</strong>imize the normalization problem for low xamp values (see above), but doesnot necessarily provide the smoothest pattern of evolution.GEN14 stores a polynomial whose coefficients derive from Chebyshevs of the second k<strong>in</strong>d.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-13


70.11.4 EXAMPLEf 1 0 1025 13 1 1 0 5 0 3 0 1This creates a function which, under waveshap<strong>in</strong>g, will split a s<strong>in</strong>usoid <strong>in</strong>to 3 odd-harmonicpartials of relative strength 5:3:1.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-14


70.12 GEN15f # time size 15 x<strong>in</strong>t xamp h0 phs0 h1 phs1 h2phs2 . . .70.12.1 DESCRIPTIONThis subrout<strong>in</strong>e creates two tables of stored polynomial functions, suitable for use <strong>in</strong> phasequadrature operations.70.12.2 INITIALIZATIONsize - number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or a power-of-2 plus 1 (see fstatement). The normal value is power-of-2 plus 1.x<strong>in</strong>t – provides the left and right values [-x<strong>in</strong>t, +x<strong>in</strong>t] of the x <strong>in</strong>terval over which the polynomialis to be drawn. This subrout<strong>in</strong>e will eventually call GEN03 to draw both functions; this p5 valueis therefor expanded to a negative-positive p5, p6 pair before GEN03 is actually called. Thenormal value is 1.xamp - amplitude scal<strong>in</strong>g factor of the s<strong>in</strong>usoid <strong>in</strong>put that is expected to produce the follow<strong>in</strong>gspectrum.h0, h1, h2, ... hn – relative strength of partials 0 (DC), 1 (fundamental), 2 ... that will result whena s<strong>in</strong>usoid of amplitudexamp * <strong>in</strong>t(size/2)/x<strong>in</strong>tis waveshaped us<strong>in</strong>g this function table. These values thus describe a frequency spectrumassociated with a particular factor xamp of the <strong>in</strong>put signal.phs0, phs1, ... - phase <strong>in</strong> degrees of desired harmonics h0, h1, ... when the two functions ofGEN15 are used with phase quadrature.70.12.3 NOTEGEN15 creates two tables of equal size, labeled f # and f # + 1. Table # will conta<strong>in</strong> aChebyshev function of the first k<strong>in</strong>d, drawn us<strong>in</strong>g GEN03 with partial strengths h0cos(phs0),h1cos(phs1), ... Table #+1 will conta<strong>in</strong> a Chebyshev function of the 2nd k<strong>in</strong>d by call<strong>in</strong>g GEN14with partials h1s<strong>in</strong>(phs1), h2s<strong>in</strong>(phs2),... (note the harmonic displacement). The two tables canbe used <strong>in</strong> conjunction <strong>in</strong> a waveshap<strong>in</strong>g network that exploits phase quadrature.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-15


70.13 GEN17f # time size 17 x1 a x2 b x3 c . . .70.13.1 DESCRIPTIONThis subrout<strong>in</strong>e creates a step function from given x-y pairs.70.13.2 INITIALIZATIONsize – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or a power-of-2 plus 1 (see fstatement). The normal value is power-of-2 plus 1.x1, x2, x3, etc. – x-ord<strong>in</strong>ate values, <strong>in</strong> ascend<strong>in</strong>g order, 0 first.a, b, c, etc. – y-values at those x-ord<strong>in</strong>ates, held until the next x-ord<strong>in</strong>ate.70.13.3 NOTEThis subrout<strong>in</strong>e creates a step function of x-y pairs whose y-values are held to the right. Theright-most y-value is then held to the end of the table. The function is useful for mapp<strong>in</strong>g one setof data values onto another, such as MIDI note numbers onto sampled sound ftable numbers (see loscil).70.13.4 EXAMPLEf 1 0 128 -17 0 1 12 2 24 3 36 4 48 5 60 6 72 784 8This describes a step function with 8 successively <strong>in</strong>creas<strong>in</strong>g levels, each 12 locations wideexcept the last which extends its value to the end of the table. Rescal<strong>in</strong>g is <strong>in</strong>hibited. Index<strong>in</strong>g<strong>in</strong>to this table with a MIDI note-number would retrieve a different value every octave up to theeighth, above which the value returned would rema<strong>in</strong> the same.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-16


70.14 GEN20f # time size 20 w<strong>in</strong>dow max [opt]70.14.1 DESCRIPTIONThis subrout<strong>in</strong>e generates functions of different w<strong>in</strong>dows. These w<strong>in</strong>dows are usually used forspectrum analysis or for gra<strong>in</strong> envelopes.70.14.2 INITIALIZATIONsize – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 ( + 1).w<strong>in</strong>dow – Type of w<strong>in</strong>dow to generate.• 1 = Hamm<strong>in</strong>g• 2 = Hann<strong>in</strong>g• 3 = Bartlett (triangle)• 4 = Blackman (3-term)• 5 = Blackman-Harris (4-term)• 6 = Gaussian• 7 = Kaiser• 8 = Rectangle• 9 = Syncmax – For negative p4 this will be the absolute value at w<strong>in</strong>dow peak po<strong>in</strong>t. If p4 is positive orp4 is negative and p6 is miss<strong>in</strong>g the table will be post-rescaled to a maximum value of 1.opt – Optional argument required by the Kaiser w<strong>in</strong>dow.70.14.3 EXAMPLESf 1 0 1024 20 5This creates a function which conta<strong>in</strong>s a 4 – term Blackman – Harris w<strong>in</strong>dow with maximumvalue of 1.f 1 0 1024 -20 2 456This creates a function that conta<strong>in</strong>s a Hann<strong>in</strong>g w<strong>in</strong>dow with a maximum value of 456.f 1 0 1024 -20 1This creates a function that conta<strong>in</strong>s a Hamm<strong>in</strong>g w<strong>in</strong>dow with a maximum value of 1.f 1 0 1024 20 7 1 2This creates a function that conta<strong>in</strong>s a Kaiser w<strong>in</strong>dow with a maximum value of 1. The extraargument specifies how “open” the w<strong>in</strong>dow is, for example a value of 0 results <strong>in</strong> a rectangularw<strong>in</strong>dow and a value of 10 <strong>in</strong> a Hamm<strong>in</strong>g like w<strong>in</strong>dow.For diagrams, see Appendix. Section 76.4.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-17


70.14.4 AUTHORSParis SmaragdisMIT, Cambridge1995John ffitchUniversity of Bath/Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.2The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-18


70.15 GEN21f # time size 21 type level [arg1 [arg2]]70.15.1 DESCRIPTIONThis generates tables of different random distributions. (See also x-class noise generators.)time and size are the usual GEN function arguments. level def<strong>in</strong>es the amplitude. Note thatGEN21 is not self-normaliz<strong>in</strong>g as are most other GEN functions. type def<strong>in</strong>es the distribution tobe used as follows:• 1 = Uniform (positive numbers only)• 2 = L<strong>in</strong>ear (positive numbers only)• 3 = Triangle (positive and negative numbers)• 4 = Exponential (positive numbers only)• 5 = Biexponential (positive and negative numbers)• 6 = Gaussian (positive and negative numbers)• 7 = Cauchy (positive and negative numbers)• 8 = Positive Cauchy (positive numbers only)• 9 = Beta (positive numbers only)• 10 = Weibull (positive numbers only)• 11 = Poisson (positive numbers only)Of all these cases only 9 (Beta) and 10 (Weibull) need extra arguments. Beta needs twoarguments and Weibull one.70.15.2 EXAMPLESf1 0 1024 21 1f1 0 1024 21 6f1 0 1024 21 9 1 1 2f1 0 1024 21 10 1 2; Uniform (white noise); Gaussian; Beta (note that level precedes arguments); WeibullAll of the above additions were designed by the author between May and December 1994, underthe supervision of Dr. Richard Boulanger.70.15.3 AUTHORSParis SmaragdisMIT, Cambridge1995John ffitchUniversity of Bath/Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.2The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-19


70.16 GEN23f # time size -23 “filename.txt”70.16.1 DESCRIPTIONThis subrout<strong>in</strong>e reads numeric values from an external ASCII file70.16.2 INITIALIZATION“filename.txt” – numeric values conta<strong>in</strong>ed <strong>in</strong> “filename.txt” (which <strong>in</strong>dicates the completepathname of the character file to be read), can be separated by spaces, tabs, newl<strong>in</strong>e characters orcommas. Also, words that conta<strong>in</strong>s non-numeric characters can be used as comments s<strong>in</strong>ce theyare ignored.size – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 , power of 2 + 1, or zero. If size = 0,table size is determ<strong>in</strong>ed by the number of numeric values <strong>in</strong> filename.txt. (New <strong>in</strong> <strong>Csound</strong>version 3.57)70.16.3 NOTEAll characters follow<strong>in</strong>g ‘;’ (comment) are ignored until next l<strong>in</strong>e (numbers too).70.16.4 AUTHORGabriel MaldonadoItalyFebruary, 1998New <strong>in</strong> <strong>Csound</strong> version 3.47The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-20


70.17 GEN25, GEN27f # time size 25 x1 y1 x2 y2 x3 . . .f # time size 27 x1 y1 x2 y2 x3 . . .70.17.1 DESCRIPTIONThese subrout<strong>in</strong>es are used to construct functions from segments of exponential curves (GEN25)or straight l<strong>in</strong>es (GEN27) <strong>in</strong> breakpo<strong>in</strong>t fashion.70.17.2 INITIALIZATIONsize - number of po<strong>in</strong>ts <strong>in</strong> the table. Must be a power of 2 or power-of-2 plus 1 (see f statement.x1, x2, x3, etc. – locations <strong>in</strong> table at which to atta<strong>in</strong> the follow<strong>in</strong>g y value. Must be <strong>in</strong> <strong>in</strong>creas<strong>in</strong>gorder. If the last value is less than size, then the rest will be set to zero. Should not be negativebut can be zero.y1, y2, y3,, etc. – Breakpo<strong>in</strong>t values atta<strong>in</strong>ed at the location specified by the preced<strong>in</strong>g x value.For GEN25 these must be non-zero and must be alike <strong>in</strong> sign. No such restrictions exist forGEN27.70.17.3 NOTEIf p4 is positive, functions are post-normalized (rescaled to a maximum absolute value of 1 aftergeneration). A negative p4 will cause rescal<strong>in</strong>g to be skipped.70.17.4 EXAMPLEf 1 0 257 27 0 0 100 1 200 -1 256 0This describes a function which beg<strong>in</strong>s at 0, rises to 1 at the 100th table location, falls to -1, bythe 200th location, and returns to 0 by the end of the table. The <strong>in</strong>terpolation is l<strong>in</strong>ear.70.17.5 AUTHORJohn ffitchUniversity of Bath/Codemist Ltd.Bath, UKNew <strong>in</strong> <strong>Csound</strong> version 3.49The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-21


70.18 GEN28f # time size 28 ifilcod70.18.1 DESCRIPTIONThis function generator reads a text file which conta<strong>in</strong>s sets of three values represent<strong>in</strong>g the xycoord<strong>in</strong>ates and a time-tag for when the signal should be placed at that location, allow<strong>in</strong>g theuser to def<strong>in</strong>e a time-tagged trajectory. The file format is <strong>in</strong> the form:time1 X1 Y1time2 X2 Y2time3 X3 Y3The configuration of the XY coord<strong>in</strong>ates <strong>in</strong> space places the signal <strong>in</strong> the follow<strong>in</strong>g way:• a1 is -1, 1• a2 is 1, 1• a3 is -1, -1• a4 is 1, -1.This assumes a loudspeaker set up as a1 is left front, a2 is right front, a3 is left back, a4 is rightback. Values greater than 1 will result <strong>in</strong> sounds be<strong>in</strong>g attenuated as if <strong>in</strong> the distance. GEN28creates values to 10 milliseconds of resolution.70.18.2 INITIALIZATIONsize – number of po<strong>in</strong>ts <strong>in</strong> the table. Must be 0. GEN28 takes 0 as the size and automaticallyallocates memory.ifilcod – character-str<strong>in</strong>g denot<strong>in</strong>g the source soundfile name. A character-str<strong>in</strong>g (<strong>in</strong> doublequotes, spaces permitted) gives the filename itself, optionally a full pathname. If not a full path,the named file is sought <strong>in</strong> the current directory.70.18.3 EXAMPLEf1 0 0 28 “move”The file “move” should look like:0 -1 11 1 12 4 42.1 -4 -43 10 -105 -40 0S<strong>in</strong>ce GEN28 creates values to 10 milliseconds of resolution, there will be 500 values created by<strong>in</strong>terpolat<strong>in</strong>g X1 to X2 to X3 and so on, and Y1 to Y2 to Y3 and so on, over the appropriatenumber of values that are stored <strong>in</strong> the function table. The sound will beg<strong>in</strong> <strong>in</strong> the left front, over1 second it will move to the right front, over another second it move further <strong>in</strong>to the distance butstill <strong>in</strong> the left front, then <strong>in</strong> just 1/10th of a second it moves to the left rear, a bit distant. F<strong>in</strong>allyover the last .9 seconds the sound will move to the right rear, moderately distant, and it comes torest between the two left channels (due west!), quite distant.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-22


70.18.4 AUTHORRichard KarpenSeattle, Wash1998 (New <strong>in</strong> <strong>Csound</strong> version 3.48)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-23


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 GEN Rout<strong>in</strong>es Page 70-24


71 THE CSOUND COMMAND<strong>Csound</strong> is a command for pass<strong>in</strong>g an orchestra file and score file to <strong>Csound</strong> to generate asoundfile. The score file can be <strong>in</strong> one of many different formats, accord<strong>in</strong>g to user preference.Translation, sort<strong>in</strong>g, and formatt<strong>in</strong>g <strong>in</strong>to orchestra-readable numeric text is handled by variouspreprocessors; all or part of the score is then sent on to the orchestra. Orchestra performance is<strong>in</strong>fluenced by command flags, which set the level of displays and console reports, specify 1/0filenames and sample formats, and declare the nature of real-time sens<strong>in</strong>g and control.71.1 Order of PrecedenceWith some recent additions to <strong>Csound</strong>, there are now three places (and <strong>in</strong> some cases four) whereoptions for <strong>Csound</strong> performance may be set. They are processed <strong>in</strong> the follow<strong>in</strong>g order:1. <strong>Csound</strong>’s own defaults2. .csoundrc file3. <strong>Csound</strong> command l<strong>in</strong>e4. tag <strong>in</strong> a .csd file5. Orchestra header (for sr, kr, ksmps, nchnls)The last assignment of an option will override any earlier ones.71.2 Generic FlagsThese are generic <strong>Csound</strong> command flags. Various platform implementations may not react thesame way to different flags!The format of a command is:csound [-flags] orchname scorenamewhere the arguments are of 2 types: flag arguments (beg<strong>in</strong>n<strong>in</strong>g with a “-”), and name arguments(such as filenames). Certa<strong>in</strong> flag arguments take a follow<strong>in</strong>g name or numeric argument. Theavailable flags are:-U unam run utility program unam-C use Cscore process<strong>in</strong>g of scorefile-I i-time only orch run-n no sound onto disk-i fnam sound <strong>in</strong>put filename-o fnam sound output filename-b N sample frames (or -kprds) per software sound I/O buffer-B N samples per hardware sound I/O buffer-A create an AIFF format output soundfile-W create a WAV format output soundfile-J create an IRCAM format output soundfile-h no header on output soundfileThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The <strong>Csound</strong> Command Page 71-1


-c 8-bit signed_char sound samples-a alaw sound samples-8 8-bit unsigned_char sound samples-u ulaw sound samples-s short_<strong>in</strong>t sound samples-l long_<strong>in</strong>t sound samples-f float sound samples-r N orchestra srate override-k N orchestra krate override-v verbose orch translation-m N TTY message level. Sum of: 1=note amps, 2=out-of-range msg,4=warn<strong>in</strong>gs-d suppress all displays-g suppress graphics, use ASCII displays-G suppress graphics, use Postscript displays-S score is <strong>in</strong> Scot format-x fnam extract from score.srt us<strong>in</strong>g extract file ‘fnam’-t N use un<strong>in</strong>terpreted beats of the score, <strong>in</strong>itially at tempo N-L dnam read L<strong>in</strong>e-oriented real-time score events from device ‘dnam’-M dnam read MIDI real-time events from device ‘dnam’-F fnam read MIDI file event stream from file ‘fnam’-P N MIDI susta<strong>in</strong> pedal threshold (N = 0-128)-R cont<strong>in</strong>ually rewrite header while writ<strong>in</strong>g soundfile (WAV/AIFF)-H/H1 generates a rotat<strong>in</strong>g l<strong>in</strong>e progress report-H2 generates a . every time a buffer is written-H3 reports the size of the output <strong>in</strong> seconds. In W<strong>in</strong>dows, writes the<strong>in</strong>formation to the w<strong>in</strong>dow title bar.-H4 sounds a bell for every buffer of the output written-N notify (r<strong>in</strong>g the bell) when score or MIDI track is done-T term<strong>in</strong>ate the performance when MIDI track is done-D defer GEN01 soundfile loads until performance time-z List opcodes <strong>in</strong> this version-z1 List opcodes with arguments <strong>in</strong> this version-- fnam Log all text output to file fnam-j fnam derive console messages from database fnam-Z Switch on dither<strong>in</strong>g of audio conversion from <strong>in</strong>ternal float<strong>in</strong>g po<strong>in</strong>tto 32, 16 and 8 bit formats. (New <strong>in</strong> <strong>Csound</strong> version4.05)71.3 PC W<strong>in</strong>dows Specific flags-j num set the number of console text rows (default 25)-J num set the number of console text columns (default 80)-K num enables MIDI IN. num (optional) = MIDI IN port device id number-q num WAVE OUT device id number (use only if more than one WAVE device is<strong>in</strong>stalled)-p num number of WAVE OUT buffers (default 4; max. 40)-O suppresses all console text output for better real-time performance-e allows any sample rate (use only with WAVE cards support<strong>in</strong>g thisfeature)-y doesn’t wait for keypress on exit-E allows graphic display for WCSHELL by Riccardo Bianch<strong>in</strong>i-Q num enable MIDI OUT. num (optional) = MIDI OUT port device id number-Y suppresses real-time WAVE OUT for better MIDI OUT tim<strong>in</strong>g performance-* yields control to the system until audio output buffer is fullThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The <strong>Csound</strong> Command Page 71-2


71.4 Mac<strong>in</strong>tosh Specific Flags-q sampdir set the directory for f<strong>in</strong>d<strong>in</strong>g samples-Q analdir set the directory for f<strong>in</strong>d<strong>in</strong>g analyses-X snddir set the directory for sav<strong>in</strong>g sound files-V num set screen buffer size-E num set number of graphs saved-p play on f<strong>in</strong>ish<strong>in</strong>g-e num set rescal<strong>in</strong>g factor-w set record<strong>in</strong>g of MIDI data-y num set rate for progress display-Y num set rate for profile display71.5 DescriptionFlags may appear anywhere <strong>in</strong> the command l<strong>in</strong>e, either separately or bundled together. A flagtak<strong>in</strong>g a Name or Number will f<strong>in</strong>d it <strong>in</strong> that argument, or <strong>in</strong> the immediately subsequent one.The follow<strong>in</strong>g are thus equivalent commands:csound –nm3 orchname –Sxxfilename scorenamecsound –n –m 3 orchname –x xfilename –S scorenameAll flags and names are optional. The default values are:csound –s –otest –b1024 –B1024 –m7 –P128 orchname scorenamewhere orchname is a file conta<strong>in</strong><strong>in</strong>g <strong>Csound</strong> orchestra code, and scorename is a file of score data<strong>in</strong> standard numeric score format, optionally presorted and time-warped. If scorename is omitted,there are two default options:1. if real-time <strong>in</strong>put is expected (-L, -M or -F), a dummy score file is substituted consist<strong>in</strong>gof the s<strong>in</strong>gle statement ‘f 0 3600’ (i.e. listen for RT <strong>in</strong>put for one hour)2. else <strong>Csound</strong> uses the previously processed score.srt <strong>in</strong> the current directory.<strong>Csound</strong> reports on the various stages of score and orchestra process<strong>in</strong>g as it goes, do<strong>in</strong>g varioussyntax and error checks along the way. Once the actual performance has begun, any errormessages will derive from either the <strong>in</strong>strument loader or the unit generators themselves. A<strong>Csound</strong> command may <strong>in</strong>clude any rational comb<strong>in</strong>ation of the follow<strong>in</strong>g flag arguments, withdefault values as described:<strong>Csound</strong> -UInvoke Utility Preprocess<strong>in</strong>g programs: snd<strong>in</strong>fo, hetro, lpanal, pvanal, cvanal, and pvlook.<strong>Csound</strong> -Ii-time only. Allocate and <strong>in</strong>itialize all <strong>in</strong>struments as per the score, but skip all p-timeprocess<strong>in</strong>g (no k-signals or a-signals, and thus no amplitudes and no sound). Provides a fastvalidity check of the score pfields and orchestra i-variables.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The <strong>Csound</strong> Command Page 71-3


<strong>Csound</strong> -nNo sound. Do all process<strong>in</strong>g, but bypass writ<strong>in</strong>g of sound to disk. This flag does not changethe execution <strong>in</strong> any other way.<strong>Csound</strong> -i isfnameInput soundfile name. If not a full pathname, the file will be sought first <strong>in</strong> the currentdirectory, then <strong>in</strong> that given by the environment variable SSDIR (if def<strong>in</strong>ed), then by SFDIR.The name std<strong>in</strong> will cause audio to be read from standard <strong>in</strong>put. If RTAUDIO is enabled, thename devaudio will request sound from the host audio <strong>in</strong>put device.<strong>Csound</strong> -o osfnameOutput soundfile name. If not a full pathname, the soundfile will be placed <strong>in</strong> the directorygiven by the environment variable SFDIR (if def<strong>in</strong>ed), else <strong>in</strong> the current directory. Thename stdout will cause audio to be written to standard output. If no name is given, the defaultname will be test. If RTAUDIO is enabled, the name devaudio will send to the host audiooutput device.<strong>Csound</strong> -b NumbNumber of audio sample-frames per sound i/o software buffer. Large is efficient, but smallwill reduce audio I/O delay. The default is 1024. In real-time performance, <strong>Csound</strong> waits onaudio I/O on Numb boundaries. It also processes audio (and polls for other <strong>in</strong>put like MIDI)on orchestra ksmps boundaries. The two can be made synchronous. For convenience, ifNumb = -N (is negative) the effective value is ksmps * N (audio synchronous with k-periodboundaries). With N small (e.g. 1) poll<strong>in</strong>g is then frequent and also locked to fixed DACsample boundaries.<strong>Csound</strong> -B NumbNumber of audio sample-frames held <strong>in</strong> the DAC hardware buffer. This is a threshold onwhich software audio I/O (above) will wait before return<strong>in</strong>g. A small number reduces audioI/O delay; but the value is often hardware limited, and small values will risk data lattes. Thedefault is 1024.<strong>Csound</strong> -hNo header on output soundfile. Don’t write a file header, just b<strong>in</strong>ary samples.<strong>Csound</strong> {-c, -a, -u, -s, -l, -f}Audio sample format of the output soundfile. One of:• c = 8-bit signed character• a = 8-bit a-law• u = 8-bit u-law• s = short <strong>in</strong>teger• l = long <strong>in</strong>teger• f = s<strong>in</strong>gle-precision float (not playable, but can be read by -i, sound<strong>in</strong> and GEN01)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The <strong>Csound</strong> Command Page 71-4


<strong>Csound</strong> -AWrite an AIFF output soundfile. Restricts the above formats to c, s, l, or f (AIFC).<strong>Csound</strong> –WWrite a .wav output soundfile.<strong>Csound</strong> –JWrite an IRCAM output soundfile.<strong>Csound</strong> -vVerbose translate and run. Pr<strong>in</strong>ts details of orch translation and performance, enabl<strong>in</strong>g errorsto be more clearly located.<strong>Csound</strong> -m NumbMessage level for standard (term<strong>in</strong>al) output. Takes the sum of 3 pr<strong>in</strong>t control flags, turnedon by the follow<strong>in</strong>g values:• 1 = note amplitude messages• 2 = samples out of range message• 4 = warn<strong>in</strong>g messages. The default value is m7 (all messages on).<strong>Csound</strong> -dSuppress all displays.<strong>Csound</strong> -gRecast graphic displays <strong>in</strong>to ASCII characters, suitable for any term<strong>in</strong>al.<strong>Csound</strong> -SInterpret scorename as a Scot format file and create a standard score file (named “score”)from it, then sort and perform that.<strong>Csound</strong> -x xfileExtract a portion of the sorted score score.srt, accord<strong>in</strong>g to xfile (see Extract).<strong>Csound</strong> -t NumbUse the un<strong>in</strong>terpreted beats of score.srt for this performance, and set the <strong>in</strong>itial tempo atNumb beats per m<strong>in</strong>ute. When this flag is set, the tempo of score performance is alsocontrollable from with<strong>in</strong> the orchestra. The flag –t0 will prevent <strong>Csound</strong> from delet<strong>in</strong>g thesorted score file, score.srt, upon exit.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The <strong>Csound</strong> Command Page 71-5


<strong>Csound</strong> -L devnameRead L<strong>in</strong>e-oriented real-time score events from device devname. The name std<strong>in</strong> will permitscore events to be typed at your term<strong>in</strong>al, or piped from another process. Each l<strong>in</strong>e-event isterm<strong>in</strong>ated by a carriage-return. Events are coded just like those <strong>in</strong> a standard numeric score,except that an event with p2=0 will be performed immediately, and an event with p2=T willbe performed T seconds after arrival. Events can arrive at any time, and <strong>in</strong> any order. Thescore carry feature is legal here, as are held notes (p3 negative) and str<strong>in</strong>g arguments, butramps and pp or np references are not.<strong>Csound</strong> -M devnameRead MIDI events from device devname.<strong>Csound</strong> -F mfnameRead MIDI events from MIDI file mfname.<strong>Csound</strong> -P NumbSet MIDI susta<strong>in</strong> pedal threshold (0 – 128). The official switch value of 64 is normally toolow, and is more realistic above 100. The default value of 128 will block all pedal <strong>in</strong>fo.<strong>Csound</strong> -NNotify (r<strong>in</strong>g the bell) when score or MIDI track is done.<strong>Csound</strong> -TTerm<strong>in</strong>ate the performance when MIDI track is done.<strong>Csound</strong> –j fnamUse database fnam for messages to pr<strong>in</strong>t to console dur<strong>in</strong>g performance. (New <strong>in</strong> version3.55)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The <strong>Csound</strong> Command Page 71-6


71.5.1 PC/WINDOWS-SPECIFIC FLAGS<strong>Csound</strong> -K numMIDI device id number (optional, use only if MIDI devices are more than one)<strong>Csound</strong> -q numWAVE OUT device id number (optional, use only if WAVE OUT devices are more thanone)<strong>Csound</strong> -p numnumber of WAVE OUT buffers (optional; default=4, maximum=40). -b (buffer length) and -p flags are related each other. F<strong>in</strong>d<strong>in</strong>g the optimum values for “-b” and “-p” flags requiressome experimentation: more buffer length means more latency delay but also more safetyfrom dropouts and sound <strong>in</strong>terruptions (flag “-B” is now obsolete, don’t use it). You now candrastically reduce buffer length and delay by us<strong>in</strong>g -e flag and ‘rounded’ sr and kr.Note that sometimes a smaller buffer length can handle sound flow better than a larger. Onlyexperiments can lead you toward optimal ‘-b’ values. -b and -p flags value can now bereduced considerably by us<strong>in</strong>g “rounded” ar and kr values (for example ar=32000 andkr=320; ar=40000 and kr=400 and so on) together with -e flag. This feature has been testedonly with a SB16 ASP and with an AWE32 card. Support by other cards is unknown.Reduc<strong>in</strong>g “-b” and “-p” flag values means reduc<strong>in</strong>g latency delay and so a more <strong>in</strong>teractivereal-time play<strong>in</strong>g.<strong>Csound</strong> -j numconsole virtual text rows number.<strong>Csound</strong> -J numconsole virtual text columns number.<strong>Csound</strong> -O (uppercase letter)suppresses all pr<strong>in</strong>tf for better real-time performance. This switch is better than ‘-m0’because ‘-m0’ still leaves some message output to the console. Use both switches togetherfor maximum performance speed.<strong>Csound</strong> -eallows arbitrary output sample rate (for cards that support this feature).<strong>Csound</strong> -ydoesn’t wait for keypress on exit.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The <strong>Csound</strong> Command Page 71-7


<strong>Csound</strong> -Egraphic display for WCSHELL by Riccardo Bianch<strong>in</strong>i.<strong>Csound</strong> -Q numenables MIDI OUT operations and optionally chooses device id num (if num argument ispresent). This flag allows parallel MIDI OUT and DAC performance. Unfortunately the realtimetim<strong>in</strong>g implemented <strong>in</strong> <strong>Csound</strong> is completely managed by DAC buffer sample flow. SoMIDI OUT operations can present some time irregularities. These irregularities can be fullyelim<strong>in</strong>ated when suppress<strong>in</strong>g DAC operations themselves (see -Y flag).<strong>Csound</strong> -Ydisables WAVE OUT (for better MIDI OUT tim<strong>in</strong>g performances). This enhances tim<strong>in</strong>g ofMIDI out operations when used <strong>in</strong> conjunction with “-Q” flag. Low k-rates (max. kr=1000)are recommended for use with the “-Y” flag. As <strong>in</strong> W<strong>in</strong>95 maximum timer resolution is1/1000 of second, unpredictable results can occur when us<strong>in</strong>g it at k-rates greater than 1000.Also it is very important to set only kr values <strong>in</strong> which the follow<strong>in</strong>g division: 1000/krproduces <strong>in</strong>teger results (some example: kr = 10; 20; 50; 100; 125; 200; 250 etc.) becauseW<strong>in</strong>95 timer only handles <strong>in</strong>teger periods <strong>in</strong> milliseconds.If you use a kr value that produces a non-<strong>in</strong>teger result <strong>in</strong> the above formula, <strong>Csound</strong> seemsto run normally but times will be not reliable. A value of kr=200 works well on mostcomputers. Maybe with slower computers a lower value works better. Experiment! Valuesgreater than 200 <strong>in</strong>crease the overhead affect<strong>in</strong>g the entire system, and do not give a notableprecision improvement. A time resolution of 1/200 of sec is precise enough for almost allMIDI applications. The sr/kr/ksmps ratio must be respected, or an error message will stop theperformance, even if sr value is mean<strong>in</strong>gless when us<strong>in</strong>g “-Y” flag.<strong>Csound</strong> -*compels <strong>Csound</strong> to yield control to system until audio output buffer content passes a certa<strong>in</strong>threshold. Below this threshold <strong>Csound</strong> cont<strong>in</strong>ues process<strong>in</strong>g, while over this threshold<strong>Csound</strong> yields control to W<strong>in</strong>dows. This gives a big enhancement <strong>in</strong> multitask<strong>in</strong>g processes.Enabl<strong>in</strong>g this option reduces polyphony a bit when us<strong>in</strong>g short buffer space. So the usershould <strong>in</strong>crease the number (‘-p’ flag) and the length (‘-b’ flag) of buffers when sett<strong>in</strong>g ‘-*’flag. Experiment to f<strong>in</strong>d best values. Do not use this flag when time response to gesturalactions is critical.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 The <strong>Csound</strong> Command Page 71-8


72 UNIFIED FILE FORMAT FOR ORCHESTRASAND SCORES72.1 DescriptionThe Unified File <strong>Format</strong>, <strong>in</strong>troduced <strong>in</strong> <strong>Csound</strong> version 3.50, enables the orchestra and scorefiles, as well as command l<strong>in</strong>e flags, to be comb<strong>in</strong>ed <strong>in</strong> one file. The file has the extension .csd.This format was orig<strong>in</strong>ally <strong>in</strong>troduced by Michael Gog<strong>in</strong>s <strong>in</strong> AX<strong>Csound</strong>.The file is a structured data file which uses markup language, similar to any SGML such asHTML. Start tags () and end tags () are used to delimit the various elements. Thefile is saved as a text file.72.2 Structured Data File <strong>Format</strong>72.2.1 ELEMENTSThe <strong>Csound</strong> Element is used to alert the csound compiler to the .csd format. The file must beg<strong>in</strong>with the start tag . The last l<strong>in</strong>e of the file must be the end tag. The rema<strong>in</strong><strong>in</strong>g elements are def<strong>in</strong>ed below.72.2.1.1 Options<strong>Csound</strong> command l<strong>in</strong>e flags are put <strong>in</strong> the Options Element. This section is delimited by the starttag and the end tag L<strong>in</strong>es beg<strong>in</strong>n<strong>in</strong>g with # or ; are treated ascomments. For precedence of flags, options, and header statements, see Section 67.1.72.2.1.2 Instruments (Orchestra)The <strong>in</strong>strument def<strong>in</strong>itions (orchestra) are put <strong>in</strong>to the Instruments Element. The statements andsyntax <strong>in</strong> this section are identical to the <strong>Csound</strong> orchestra file, and have the same requirements,<strong>in</strong>clud<strong>in</strong>g the header statements (sr, kr, etc.) This Instruments Element is delimited with the starttag and the end tag .72.2.1.3 Score<strong>Csound</strong> score statements are put <strong>in</strong> the Score Element. The statements and syntax <strong>in</strong> this sectionare identical to the <strong>Csound</strong> score file, and have the same requirements. The Score Element isdelimited by the start tag and the end tag .The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Unified File <strong>Format</strong> for Orchestras and Scores Page 72-1


72.2.1.4 ExampleBelow is a sample file, test.csd, which renders a .wav file at 44.1 kHz sample rate conta<strong>in</strong><strong>in</strong>gone second of a 1 kHz s<strong>in</strong>e wave. Displays are suppressed. test.csd was created from two files,tone.orc and tone.sco, with the addition of command l<strong>in</strong>e flags.; test.csd – a <strong>Csound</strong> structured data file-W -d -o tone.wav; orig<strong>in</strong>ally tone.orcsr = 44100kr = 4410ksmps = 10nchnls = 1<strong>in</strong>str 1a1 oscil p4, p5, 1 ; simple oscillatorouta1end<strong>in</strong>; orig<strong>in</strong>ally tone.scof1 0 8192 10 1i1 0 1 20000 1000 ;play one second of one kHz tonee72.3 Command L<strong>in</strong>e Parameter FileIf the file .csoundrc exists, it will be used to set the command l<strong>in</strong>e parameters. These can beoverridden. It uses the same form as a .csd file. L<strong>in</strong>es beg<strong>in</strong>n<strong>in</strong>g with # or ; are treated ascomments.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Unified File <strong>Format</strong> for Orchestras and Scores Page 72-2


73 SCORE FILE PREPROCESSING73.1 The Extract FeatureThis feature will extract a segment of a sorted numeric score file accord<strong>in</strong>g to <strong>in</strong>structions takenfrom a control file. The control file conta<strong>in</strong>s an <strong>in</strong>strument list and two time po<strong>in</strong>ts, from and to,<strong>in</strong> the form:<strong>in</strong>struments 1 2 from 1:27.5 to 2:2The component labels may be abbreviated as i, f and t. The time po<strong>in</strong>ts denote the beg<strong>in</strong>n<strong>in</strong>g andend of the extract <strong>in</strong> terms of:[section no.] : [beat no.].each of the three parts is also optional. The default values for miss<strong>in</strong>g i, f or t are:all <strong>in</strong>struments, beg<strong>in</strong>n<strong>in</strong>g of score, end of score.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Score File Preprocess<strong>in</strong>g Page 73.1


73.2 Independent Pre-Process<strong>in</strong>g with ScsortAlthough the result of all score preprocess<strong>in</strong>g is reta<strong>in</strong>ed <strong>in</strong> the file score.srt after orchestraperformance (it exists as soon as score preprocess<strong>in</strong>g has completed), the user may sometimeswant to run these phases <strong>in</strong>dependently. The commandscot filenamewill process the Scot formatted filename, and leave a standard numeric score result <strong>in</strong> a filenamed score for perusal or later process<strong>in</strong>g.The commandscscort < <strong>in</strong>file > outfilewill put a numeric score <strong>in</strong>file through Carry, Tempo, and Sort preprocess<strong>in</strong>g, leav<strong>in</strong>g the result<strong>in</strong> outfile.Likewise extract, also normally <strong>in</strong>voked as part of the <strong>Csound</strong> command, can be <strong>in</strong>voked as astandalone program:extract xfile < score.sort > score.extractThis command expects an already sorted score. An unsorted score should first be sent throughScsort then piped to the extract program:scsort < scorefile | extract xfile > score.extractThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Score File Preprocess<strong>in</strong>g Page 73.2


74 UTILITY PROGRAMSThe <strong>Csound</strong> Utilities are soundfile preprocess<strong>in</strong>g programs that return <strong>in</strong>formation on asoundfile or create some analyzed version of it for use by certa<strong>in</strong> <strong>Csound</strong> generators. Thoughdifferent <strong>in</strong> goals, they share a common soundfile access mechanism and are describable as a set.The Soundfile Utility programs can be <strong>in</strong>voked <strong>in</strong> two equivalent forms:csound –U utilname [flags] filenames ...utilname [flags] filenames ...In the first, the utility is <strong>in</strong>voked as part of the <strong>Csound</strong> executable, while <strong>in</strong> the second it is calledas a standalone program. The second is smaller by about 200K, but the two forms are identical <strong>in</strong>function. The first is convenient <strong>in</strong> not requir<strong>in</strong>g the ma<strong>in</strong>tenance and use of several <strong>in</strong>dependentprograms – one program does all. When us<strong>in</strong>g this form, a -U flag detected <strong>in</strong> the command l<strong>in</strong>ewill cause all subsequent flags and names to be <strong>in</strong>terpreted as per the named utility; i.e. <strong>Csound</strong>generation will not occur, and the program will term<strong>in</strong>ate at the end of utility process<strong>in</strong>g.Directories. Filenames are of two k<strong>in</strong>ds, source soundfiles and resultant analysis files. Each hasa hierarchical nam<strong>in</strong>g convention, <strong>in</strong>fluenced by the directory from which the Utility is <strong>in</strong>voked.Source soundfiles with a full pathname (beg<strong>in</strong>s with dot (.), slash (/), or for Th<strong>in</strong>kC <strong>in</strong>cludes acolon (:)), will be sought only <strong>in</strong> the directory named. Soundfiles without a path will be soughtfirst <strong>in</strong> the current directory, then <strong>in</strong> the directory named by the SSDIR environment variable (ifdef<strong>in</strong>ed), then <strong>in</strong> the directory named by SFDIR. An unsuccessful search will return a “cannotopen” error.Resultant analysis files are written <strong>in</strong>to the current directory, or to the named directory if a pathis <strong>in</strong>cluded. It is tidy to keep analysis files separate from sound files, usually <strong>in</strong> a separatedirectory known to the SADIR variable. Analysis is conveniently run from with<strong>in</strong> the SADIRdirectory. When an analysis file is later <strong>in</strong>voked by a <strong>Csound</strong> generator it is sought first <strong>in</strong> thecurrent directory, then <strong>in</strong> the directory def<strong>in</strong>ed by SADIR.Soundfile <strong>Format</strong>s. <strong>Csound</strong> can read and write audio files <strong>in</strong> a variety of formats. Write formatsare described by <strong>Csound</strong> command flags. On read<strong>in</strong>g, the format is determ<strong>in</strong>ed from thesoundfile header, and the data automatically converted to float<strong>in</strong>g-po<strong>in</strong>t dur<strong>in</strong>g <strong>in</strong>ternalprocess<strong>in</strong>g. When <strong>Csound</strong> is <strong>in</strong>stalled on a host with local soundfile conventions (SUN, NeXT,Mac<strong>in</strong>tosh) it may conditionally <strong>in</strong>clude local packag<strong>in</strong>g code which creates soundfiles notportable to other hosts. However, <strong>Csound</strong> on any host can always generate and read AIFF files,which is thus a portable format. Sampled sound libraries are typically AIFF, and the variableSSDIR usually po<strong>in</strong>ts to a directory of such sounds. If def<strong>in</strong>ed, the SSDIR directory is <strong>in</strong> thesearch path dur<strong>in</strong>g soundfile access. Note that some AIFF sampled sounds have an audio loop<strong>in</strong>gfeature for susta<strong>in</strong>ed performance; the analysis programs will traverse any loop segment onceonly.For soundfiles without headers, an SR value may be supplied by a command flag (or its default).If both header and flag are present, the flag value will over-ride.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-1


When sound is accessed by the audio Analysis programs , only a s<strong>in</strong>gle channel is read. Forstereo or quad files, the default is channel one; alternate channels may be obta<strong>in</strong>ed on request.AuthorDan EllisMIT Media LabCambrige, Massachussetts1990The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-2


74.1 snd<strong>in</strong>fo74.1.1 DESCRIPTIONget basic <strong>in</strong>formation about one or more soundfiles.orcsound –U snd<strong>in</strong>fo soundfilenames ...snd<strong>in</strong>fo soundfilenames ...snd<strong>in</strong>fo will attempt to f<strong>in</strong>d each named file, open it for read<strong>in</strong>g, read <strong>in</strong> the soundfile header,then pr<strong>in</strong>t a report on the basic <strong>in</strong>formation it f<strong>in</strong>ds. The order of search across soundfiledirectories is as described above. If the file is of type AIFF, some further details are listed first.74.1.2 EXAMPLEcsound –U snd<strong>in</strong>fo test Bosendorfer/”BOSEN mf A0 st” foo foo2where the environment variables SFDIR = /u/bv/sound, and SSDIR = /so/bv/Samples,might produce the follow<strong>in</strong>g:util SNDINFO:/u/bv/sound/test:srate 22050, monaural, 16 bit shorts, 1.10 secondsheadersiz 1024, datasiz 48500 (24250 sample frames)/so/bv/Samples/Bosendorfer/BOSEN mf A0 st: AIFF, 197586 stereo samples,base Frq 261.6 (MIDI 60), sustnLp: mode 1, 121642 to197454, relesLp: mode 0AIFF soundfile, loop<strong>in</strong>g with modes 1, 0srate 44100, stereo, 16 bit shorts, 4.48 secondsheadersiz 402, datasiz 790344 (197586 sample frames)/u/bv/sound/foo:no recognizable soundfile header/u/bv/sound/foo2:couldn’t f<strong>in</strong>dThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-3


74.2 hetro74.2.1 DESCRIPTIONhetrodyne filter analysis for the <strong>Csound</strong> adsyn generator.orcsound –U hetro [flags] <strong>in</strong>filename outfilenamehetro [flags] <strong>in</strong>filename outfilenamehetro takes an <strong>in</strong>put soundfile, decomposes it <strong>in</strong>to component s<strong>in</strong>usoids, and outputs adescription of the components <strong>in</strong> the form of breakpo<strong>in</strong>t amplitude and frequency tracks.Analysis is conditioned by the control flags below. A space is optional between flag and value.-s srate sampl<strong>in</strong>g rate of the audio <strong>in</strong>put file. This will over-ride the srate of the soundfile header,which otherwise applies. If neither is present, the default is 10000. Note that for adsyn synthesisthe srate of the source file and the generat<strong>in</strong>g orchestra need not be the same.-c channel channel number sought. The default is 1.-b beg<strong>in</strong> beg<strong>in</strong>n<strong>in</strong>g time (<strong>in</strong> seconds) of the audio segment to be analyzed. The default is 0.0-d duration duration (<strong>in</strong> seconds) of the audio segment to be analyzed. The default of 0.0 meansto the end of the file. Maximum length is 32.766 seconds.-f begfreq estimated start<strong>in</strong>g frequency of the fundamental, necessary to <strong>in</strong>itialize the filteranalysis. The default is 100 (cps).-h partials number of harmonic partials sought <strong>in</strong> the audio file. Default is 10, maximum is afunction of memory available.-M maxamp maximum amplitude summed across all concurrent tracks. The default is 32767.-m m<strong>in</strong>amp amplitude threshold below which a s<strong>in</strong>gle pair of amplitude/frequency tracks isconsidered dormant and will not contribute to output summation. Typical values: 128 (48 dBdown from full scale), 64 (54 dB down), 32 (60 dB down), 0 (no threshold<strong>in</strong>g). The defaultthreshold is 64 (54 dB down).-n brkpts <strong>in</strong>itial number of analysis breakpo<strong>in</strong>ts <strong>in</strong> each amplitude and frequency track, prior tothreshold<strong>in</strong>g (-m) and l<strong>in</strong>ear breakpo<strong>in</strong>t consolidation. The <strong>in</strong>itial po<strong>in</strong>ts are spread evenly overthe duration. The default is 256.-l cutfreq substitute a 3rd order Butterworth low-pass filter with cutoff frequency cutfreq (<strong>in</strong> Hz),<strong>in</strong> place of the default averag<strong>in</strong>g comb filter. The default is 0 (don’t use).The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-4


74.2.2 EXAMPLEhetro -s44100 -b.5 -d2.5 -h16 -M24000 audiofile.test adsynfile7This will analyze 2.5 seconds of channel 1 of a file “audiofile.test”, recorded at 44.1 kHz,beg<strong>in</strong>n<strong>in</strong>g .5 seconds from the start, and place the result <strong>in</strong> a file “adsynfile7”. We request justthe first 16 harmonics of the sound, with 256 <strong>in</strong>itial breakpo<strong>in</strong>t values per amplitude or frequencytrack, and a peak summation amplitude of 24000. The fundamental is estimated to beg<strong>in</strong> at 100Hz. Amplitude threshold<strong>in</strong>g is at 54 dB down.The Butterworth LPF is not enabled.74.2.3 FILE FORMATThe output file conta<strong>in</strong>s time-sequenced amplitude and frequency values for each partial of anadditive complex audio source. The <strong>in</strong>formation is <strong>in</strong> the form of breakpo<strong>in</strong>ts (time, value, time,value, ....) us<strong>in</strong>g 16-bit <strong>in</strong>tegers <strong>in</strong> the range 0 – 32767. Time is given <strong>in</strong> milliseconds, andfrequency <strong>in</strong> Hertz (Hz). The breakpo<strong>in</strong>t data is exclusively non-negative, and the values -1 and -2 uniquely signify the start of new amplitude and frequency tracks. A track is term<strong>in</strong>ated by thevalue 32767. Before be<strong>in</strong>g written out, each track is data-reduced by amplitude threshold<strong>in</strong>g andl<strong>in</strong>ear breakpo<strong>in</strong>t consolidation.A component partial is def<strong>in</strong>ed by two breakpo<strong>in</strong>t sets: an amplitude set, and a frequency set.With<strong>in</strong> a composite file these sets may appear <strong>in</strong> any order (amplitude, frequency, amplitude ....;or amplitude, amplitude..., then frequency, frequency,...). Dur<strong>in</strong>g adsyn resynthesis the sets areautomatically paired (amplitude, frequency) from the order <strong>in</strong> which they were found. Thereshould be an equal number of each.A legal adsyn control file could have follow<strong>in</strong>g format:-1 time1 value1 ... timeK valueK 32767 ; amplitude breakpo<strong>in</strong>ts for partial 1-2 time1 value1 ... timeL valueL 32767 ; frequency breakpo<strong>in</strong>ts for partial 1-1 time1 value1 ... timeM valueM 32767 ; amplitude breakpo<strong>in</strong>ts for partial 2-2 time1 value1 ... timeN valueN 32767 ; frequency breakpo<strong>in</strong>ts for partial 2-2 time1 value1 ..........-2 time1 value1 .......... ; pairable tracks for partials 3 and 4-1 time1 value1 ..........-1 time2 value1 ..........The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-5


74.3 lpanal74.3.1 DESCRIPTIONl<strong>in</strong>ear predictive analysis for the <strong>Csound</strong> lp generatorsorcsound –U lpanal [flags] <strong>in</strong>filename outfilenamelpanal [flags] <strong>in</strong>filename outfilenamelpanal performs both lpc and pitch-track<strong>in</strong>g analysis on a soundfile to produce a time-orderedsequence of frames of control <strong>in</strong>formation suitable for <strong>Csound</strong> resynthesis. Analysis isconditioned by the control flags below. A space is optional between the flag and its value.-a [alternate storage] asks lpanal to write a file with filter poles values rather than the usual filtercoefficient files. When lpread / lpreson are used with pole files, automatic stabilization isperformed and the filter should not get wild. (This is the default <strong>in</strong> the W<strong>in</strong>dows GUI) – Changedby Marc Resibois.-s srate sampl<strong>in</strong>g rate of the audio <strong>in</strong>put file. This will over-ride the srate of the soundfile header,which otherwise applies. If neither is present, the default is 10000.-c channel channel number sought. The default is 1.-b beg<strong>in</strong> beg<strong>in</strong>n<strong>in</strong>g time (<strong>in</strong> seconds) of the audio segment to be analyzed. The default is 0.0-d duration duration (<strong>in</strong> seconds) of the audio segment to be analyzed. The default of 0.0 meansto the end of the file.-p npoles number of poles for analysis. The default is 34, the maximum 50.-h hopsize hop size (<strong>in</strong> samples) between frames of analysis. This determ<strong>in</strong>es the number offrames per second (srate / hopsize) <strong>in</strong> the output control file. The analysis framesize is hopsize *2 samples. The default is 200, the maximum 500.-C str<strong>in</strong>g text for the comments field of the lpfile header. The default is the null str<strong>in</strong>g.-P m<strong>in</strong>cps lowest frequency (<strong>in</strong> Hz) of pitch track<strong>in</strong>g. -P0 means no pitch track<strong>in</strong>g.-Q maxcps highest frequency (<strong>in</strong> Hz) of pitch track<strong>in</strong>g. The narrower the pitch range, the moreaccurate the pitch estimate. The defaults are -P70, -Q200.-v verbosity level of term<strong>in</strong>al <strong>in</strong>formation dur<strong>in</strong>g analysis.• 0 = none• 1 = verbose• 2 = debugThe default is 0.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-6


74.3.2 EXAMPLElpanal –a –p26 –d2.5 –P100 –Q400 audiofile.test lpfil22will analyze the first 2.5 seconds of file “audiofile.test”, produc<strong>in</strong>g srate/200 frames per second,each conta<strong>in</strong><strong>in</strong>g 26-pole filter coefficients and a pitch estimate between 100 and 400 Hertz.Stabilized (-a) output will be placed <strong>in</strong> “lpfil22” <strong>in</strong> the current directory.74.3.3 FILE FORMATOutput is a file comprised of an identifiable header plus a set of frames of float<strong>in</strong>g po<strong>in</strong>t analysisdata. Each frame conta<strong>in</strong>s four values of pitch and ga<strong>in</strong> <strong>in</strong>formation, followed by npoles filtercoefficients. The file is readable by <strong>Csound</strong>’s lpread.lpanal is an extensive modification of Paul Lanksy’s lpc analysis programs.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-7


74.4 pvanal74.4.1 DESCRIPTIONFourier analysis for the <strong>Csound</strong> pvoc generatororcsound –U pvanal [flags] <strong>in</strong>filename outfilenamepvanal [flags] <strong>in</strong>filename outfilenamepvanal converts a soundfile <strong>in</strong>to a series of short-time Fourier transform (STFT) frames atregular timepo<strong>in</strong>ts (a frequency-doma<strong>in</strong> representation). The output file can be used by pvoc togenerate audio fragments based on the orig<strong>in</strong>al sample, with timescales and pitches arbitrarilyand dynamically modified. Analysis is conditioned by the flags below. A space is optionalbetween the flag and its argument.-s srate sampl<strong>in</strong>g rate of the audio <strong>in</strong>put file. This will over-ride the srate of the soundfile header,which otherwise applies. If neither is present, the default is 10000.-c channel channel number sought. The default is 1.-b beg<strong>in</strong> beg<strong>in</strong>n<strong>in</strong>g time (<strong>in</strong> seconds) of the audio segment to be analyzed. The default is 0.0-d duration duration (<strong>in</strong> seconds) of the audio segment to be analyzed. The default of 0.0 meansto the end of the file.-n frmsiz STFT frame size, the number of samples <strong>in</strong> each Fourier analysis frame. Must be apower of two, <strong>in</strong> the range 16 to 16384. For clean results, a frame must be larger than the longestpitch period of the sample. However, very long frames result <strong>in</strong> temporal “smear<strong>in</strong>g” orreverberation. The bandwidth of each STFT b<strong>in</strong> is determ<strong>in</strong>ed by sampl<strong>in</strong>g rate / frame size. Thedefault framesize is the smallest power of two that corresponds to more than 20 milliseconds ofthe source (e.g. 256 po<strong>in</strong>ts at 10 kHz sampl<strong>in</strong>g, giv<strong>in</strong>g a 25.6 ms frame).-w w<strong>in</strong>dfact W<strong>in</strong>dow overlap factor. This controls the number of Fourier transform frames persecond. <strong>Csound</strong>’s pvoc will <strong>in</strong>terpolate between frames, but too few frames will generate audibledistortion; too many frames will result <strong>in</strong> a huge analysis file. A good compromise for w<strong>in</strong>dfactis 4, mean<strong>in</strong>g that each <strong>in</strong>put po<strong>in</strong>t occurs <strong>in</strong> 4 output w<strong>in</strong>dows, or conversely that the offsetbetween successive STFT frames is framesize/4. The default value is 4. Do not use this flag with-h.-h hopsize STFT frame offset. Converse of above, specify<strong>in</strong>g the <strong>in</strong>crement <strong>in</strong> samples betweensuccessive frames of analysis (see also lpanal). Do not use with -w.74.4.2 EXAMPLEpvanal asound pvfilewill analyze the soundfile “asound” us<strong>in</strong>g the default frmsiz and w<strong>in</strong>dfact to produce the file“pvfile” suitable for use with pvoc.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-8


74.4.3 FILESThe output file has a special pvoc header conta<strong>in</strong><strong>in</strong>g details of the source audio file, the analysisframe rate and overlap. Frames of analysis data are stored as float, with the magnitude and‘frequency’ (<strong>in</strong> Hz) for the first N/2 + 1 Fourier b<strong>in</strong>s of each frame <strong>in</strong> turn. ‘Frequency’ encodesthe phase <strong>in</strong>crement <strong>in</strong> such a way that for strong harmonics it gives a good <strong>in</strong>dication of the truefrequency. For low amplitude or rapidly mov<strong>in</strong>g harmonics it is less mean<strong>in</strong>gful.74.4.4 DIAGNOSTICSPr<strong>in</strong>ts total number of frames, and frames completed on every 20th.74.4.5 AUTHORDan EllisMIT Media LabCambrige, Massachussetts1990The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-9


74.5 cvanal74.5.1 DESCRIPTIONImpulse Response Fourier Analysis for convolve operator<strong>Csound</strong> -U cvanal [flags] <strong>in</strong>filename outfilenamecvanal converts a soundfile <strong>in</strong>to a s<strong>in</strong>gle Fourier transform frame. The output file can be used bythe convolve operator to perform Fast Convolution between an <strong>in</strong>put signal and the orig<strong>in</strong>alimpulse response. Analysis is conditioned by the flags below. A space is optional between theflag and its argument.-s rate sampl<strong>in</strong>g rate of the audio <strong>in</strong>put file. This will over-ride the srate of the soundfile header,which otherwise applies. If neither is present, the default is 10000.-c channel channel number sought. If omitted, the default is to process all channels. If a value isgiven, only the selected channel will be processed.-b beg<strong>in</strong> beg<strong>in</strong>n<strong>in</strong>g time (<strong>in</strong> seconds) of the audio segment to be analyzed. The default is 0.0-d duration duration (<strong>in</strong> seconds) of the audio segment to be analyzed. The default of 0.0 meansto the end of the file.74.5.2 EXAMPLEcvanal asound cvfilewill analyze the soundfile “asound” to produce the file “cvfile” for the use with convolve.To use data that is not already conta<strong>in</strong>ed <strong>in</strong> a soundfile, a soundfile converter that accepts textfiles may be used to create a standard audio file, e.g., the .DAT format for SOX. This is usefulfor implement<strong>in</strong>g FIR filters.74.5.3 FILESThe output file has a special convolve header, conta<strong>in</strong><strong>in</strong>g details of the source audio file. Theanalysis data is stored as ‘float’, <strong>in</strong> rectangular (real/imag<strong>in</strong>ary) form.Note: The analysis file is not system <strong>in</strong>dependent! Ensure that the orig<strong>in</strong>al impulserecord<strong>in</strong>g/data is reta<strong>in</strong>ed. If/when required, the analysis file can be recreated.74.5.4 AUTHORGreg Sullivan(Based on algorithm given <strong>in</strong> ‘Elements Of Computer Music’, by F. Richard Moore.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-10


74.6 pvlook74.6.1 DESCRIPTIONView formatted text output of STFT analysis files created with pvanal.orcsound –U pvlook [flags] <strong>in</strong>filenamepvlook [flags] <strong>in</strong>filenamepvlook reads a file, and frequency and amplitude trajectories for each of the analysis b<strong>in</strong>s, <strong>in</strong>readable text form. The file is assumed to be an STFT analysis file created by pvanal. Bydefault, the entire file is processed.-bb n beg<strong>in</strong> at analysis b<strong>in</strong> number n, numbered from 1. Default is 1.-eb n end at analysis b<strong>in</strong> number n. Defaults to the highest.-bf n beg<strong>in</strong> at analysis frame number n, numbered from 1. Defaults to 1.-ef n end at analysis frame number n. Defaults to the highest.-i pr<strong>in</strong>ts values as <strong>in</strong>tegers. Defaults to float<strong>in</strong>g po<strong>in</strong>t.74.6.2 EXAMPLEenakis 259% ../csound -U pvlook test.pvUs<strong>in</strong>g csound.txt<strong>Csound</strong> Version 3.57 (Aug 3 1999)util PVLOOK:; B<strong>in</strong>s <strong>in</strong> Analysis: 513; First B<strong>in</strong> Shown: 1; Number of B<strong>in</strong>s Shown: 513; Frames <strong>in</strong> Analysis: 1184; First Frame Shown: 1; Number of Data Frames Shown: 1184B<strong>in</strong> 1 Freqs.0.000 87.891 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-11


0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 -87.891 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 87.891 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-12


0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000B<strong>in</strong> 1 Amps. 0.180 0.066 0.252 0.248 0.245 0.246 0.246 0.2490.252 0.251 0.250 0.248 0.244 0.245 0.248 0.250 0.254 0.2510.248 0.247 0.244 0.246 0.249 0.250 0.253 0.251 0.247 0.2460.245 0.246 0.250 0.251 0.252 0.250 0.247 0.245 0.246 0.2470.251 0.252 0.250 0.249 0.246 0.245 0.248 0.249 0.252 0.2530.249 0.248 0.245 0.245 0.249 0.251 0.252 0.252 0.249 0.2460.246 0.245 0.249 0.252 0.252 0.251 0.249 0.245 0.246 0.2480.250 0.253 0.251 0.249 0.247 0.244 0.247 0.249 0.250 0.2530.251 0.248 0.247 0.245 0.247 0.250 0.252 0.252 0.251 0.2470.246 0.246 0.247 0.251 0.252 0.251 0.249 0.246 0.245 0.2480.249 0.252 0.252 0.249 0.248 0.246 0.245 0.249 0.250 0.2520.252 0.249 0.247 0.246 0.246 0.249 0.252 0.252 0.251 0.2480.245 0.246 0.247 0.249 0.253 0.251 0.249 0.247 0.245 0.2460.248 0.250 0.253 0.251 0.248 0.247 0.244 0.246 0.250 0.2510.252 0.250 0.247 0.246 0.246 0.248 0.251 0.252 0.251 0.2500.246 0.245 0.247 0.248 0.251 0.252 0.250 0.248 0.246 0.245The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-13


0.248 0.249 0.252 0.252 0.248 0.247 0.245 0.245 0.249 0.2510.251 0.251 0.248 0.246 0.246 0.247 0.250 0.252 0.251 0.2500.248 0.244 0.246 0.248 0.250 0.253 0.251 0.248 0.247 0.2450.247 0.249 0.250 0.252 0.250 0.247 0.246 0.245 0.247 0.2510.252 0.251 0.250 0.246 0.245 0.247 0.248 0.252 0.252 0.2490.248 0.245 0.245 0.248 0.249 0.251 0.252 0.248 0.247 0.2450.245 0.249 0.250 0.251 0.251 0.248 0.246 0.245 0.246 0.2490.252 0.251 0.250 0.247 0.244 0.246 0.247 0.249 0.252 0.2510.249 0.247 0.244 0.247 0.249 0.250 0.252 0.250 0.247 0.2460.245 0.247 0.250 0.251 0.251 0.250 0.246 0.245 0.246 0.2480.251 0.252 0.250 0.249 0.245 0.245 0.247 0.248 0.251 0.2520.249 0.247 0.245 0.245 0.248 0.250 0.251 0.251 0.247 0.2460.245 0.245 0.249 0.251 0.251 0.250 0.247 0.245 0.246 0.2460.249 0.252 0.251 0.249 0.247 0.244 0.247 0.248 0.250 0.2520.250 0.247 0.246 0.245 0.247 0.250 0.251 0.252 0.249 0.2460.245 0.245 0.247 0.251 0.251 0.250 0.249 0.246 0.245 0.2470.248 0.251 0.251 0.249 0.248 0.245 0.245 0.248 0.249 0.2510.251 0.248 0.246 0.245 0.245 0.249 0.251 0.251 0.251 0.2470.245 0.245 0.246 0.249 0.251 0.250 0.249 0.247 0.244 0.2460.248 0.250 0.252 0.250 0.247 0.246 0.245 0.247 0.249 0.2500.251 0.249 0.246 0.246 0.245 0.247 0.250 0.250 0.250 0.2490.245 0.245 0.246 0.248 0.251 0.251 0.249 0.248 0.245 0.2450.247 0.249 0.251 0.251 0.248 0.246 0.245 0.245 0.248 0.2500.251 0.250 0.247 0.245 0.245 0.246 0.249 0.251 0.250 0.2490.246 0.244 0.246 0.247 0.250 0.251 0.250 0.248 0.246 0.2450.247 0.249 0.250 0.251 0.249 0.247 0.246 0.245 0.247 0.2500.250 0.251 0.248 0.245 0.245 0.246 0.248 0.251 0.251 0.2490.248 0.245 0.245 0.247 0.249 0.251 0.251 0.248 0.247 0.2450.245 0.248 0.249 0.250 0.250 0.247 0.246 0.246 0.246 0.2490.251 0.250 0.250 0.246 0.245 0.246 0.247 0.250 0.251 0.2490.248 0.246 0.244 0.246 0.248 0.250 0.251 0.249 0.247 0.2460.245 0.247 0.250 0.250 0.251 0.249 0.245 0.245 0.246 0.2480.251 0.250 0.250 0.248 0.245 0.245 0.247 0.248 0.251 0.2500.248 0.247 0.245 0.246 0.248 0.250 0.251 0.250 0.247 0.2460.245 0.246 0.249 0.251 0.250 0.249 0.246 0.245 0.246 0.2470.250 0.251 0.250 0.249 0.246 0.244 0.246 0.248 0.250 0.2510.249 0.247 0.246 0.245 0.247 0.249 0.250 0.251 0.287 0.3310.178 0.008 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.0000.140 1.265 2.766 3.289 3.296 3.293 3.296 3.296 3.290 3.2933.292 3.291 3.297 3.295 3.294 3.296 3.291 3.292 3.294 3.2913.296 3.297 3.292 3.295 3.292 3.290 3.295 3.293 3.294 3.2973.292 3.293 3.294 3.290 3.295 3.295 3.292 3.296 3.293 3.2913.294 3.291 3.293 3.297 3.292 3.295 3.294 3.288 3.293 3.2933.292 3.297 3.294 3.292 3.295 3.290 3.292 3.295 3.292 3.2953.295 3.290 3.294 3.292 3.292 3.297 3.293 3.293 3.295 3.2903.292 3.293 3.290 3.296 3.296 3.292 3.295 3.291 3.290 3.2943.291 3.294 3.296 3.291 3.293 3.293 3.290 3.295 3.294 3.2933.296 3.291 3.291 3.293 3.290 3.294 3.296 3.292 3.295 3.293The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-14


3.288 3.293 3.292 3.292 3.297 3.292 3.293 3.294 3.289 3.2923.294 3.291 3.296 3.293 3.291 3.294 3.291 3.292 3.296 3.2923.294 3.295 3.289 3.292 3.292 3.291 3.296 3.294 3.292 3.2953.290 3.290 3.293 3.291 3.295 3.296 3.291 3.294 3.291 3.2893.294 3.292 3.293 3.295 3.291 3.292 3.293 3.290 3.294 3.2953.292 3.294 3.291 3.289 3.293 3.291 3.293 3.296 3.292 3.2933.293 3.288 3.292 3.293 3.292 3.296 3.293 3.291 3.294 3.2893.292 3.295 3.291 3.294 3.293 3.289 3.292 3.291 3.290 3.2953.293 3.292 3.294 3.289 3.291 3.293 3.290 3.295 3.294 3.2903.293 3.290 3.289 3.294 3.291 3.293 3.295 3.290 3.292 3.2923.289 3.293 3.293 3.292 3.295 3.291 3.289 3.292 3.290 3.2923.295 3.291 3.293 3.292 3.288 3.292 3.291 3.291 3.295 3.2913.291 3.292 3.289 3.291 3.294 3.291 3.294 3.292 3.289 3.2923.290 3.290 3.295 3.292 3.293 3.294 3.289 3.291 3.292 3.2903.294 3.293 3.291 3.293 3.289 3.290 3.293 3.291 3.294 3.2953.290 3.292 3.291 3.289 3.294 3.293 3.292 3.294 3.290 3.2903.292 3.289 3.293 3.294 3.291 3.293 3.291 3.289 3.292 3.2913.291 3.295 3.291 3.291 3.292 3.288 3.292 3.293 3.291 3.2953.292 3.290 3.292 3.289 3.291 3.294 3.291 3.293 3.292 3.2883.291 3.291 3.290 3.295 3.292 3.291 3.293 3.289 3.290 3.2923.290 3.294 3.293 3.290 3.292 3.290 3.289 3.293 3.291 3.2923.294 3.290 3.290 3.291 3.289 3.293 3.293 3.291 3.293 3.2903.288 3.291 3.290 3.292 3.294 3.290 3.292 3.291 3.288 3.2913.291 3.291 3.294 3.291 3.290 3.291 3.288 3.291 3.293 3.2913.293 3.292 3.288 3.291 3.290 3.290 3.294 3.291 3.291 3.2923.288 3.290 3.291 3.290 3.294 3.293 3.290 3.292 3.289 3.2893.293 3.290 3.292 3.293 3.289 3.291 3.290 3.289 3.293 3.2923.291 3.293 3.289 3.289 3.291 3.289 3.292 3.293 3.290 3.2923.290 3.288 3.292 3.291 3.291 3.294 3.290 3.290 3.291 3.2883.291 3.292 3.291 3.293 3.291 3.288 3.291 3.289 3.290 3.2933.290 3.292 3.292 3.288 3.291 3.291 3.290 3.293 3.291 3.2903.292 3.288 3.289 3.292 3.290 3.292 3.293 3.289 3.291 3.2893.288 3.293 3.291 3.291 3.292 3.288 3.289 3.290 3.288 3.2923.293 3.290 3.292 3.289 3.288 3.291 3.290 3.291 3.293 3.2893.290 3.290 3.287 3.291 3.291 3.290 3.293 3.290 3.288 3.2903.288 3.290 3.293 3.291 3.292 3.291 3.288 3.290 3.289 3.2893.293 3.290 3.290 3.291 3.287 3.289 3.291 3.289 3.292 3.2913.288 3.290 3.288 3.288 3.292 3.290 3.291 3.292 3.288 3.2893.290 3.288 3.292 3.292 3.290 3.292 3.289 3.288 3.291 3.2893.291 3.293 3.289 3.291 3.290 3.287 3.291 3.290 3.290 3.2933.289 3.289 3.290 3.287 3.290 3.292 3.290 3.292 3.290 3.2873.290 3.289 3.289 3.292 3.290 3.290 3.291 3.287 3.289 3.2903.289 3.292 3.291 3.289 3.291 3.288etc…74.6.3 AUTHORRichard KarpenSeattle, Wash1993 (New <strong>in</strong> <strong>Csound</strong> version 3.57)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-15


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Utility Programs Page 74-16


75 CSCORECscore is a program for generat<strong>in</strong>g and manipulat<strong>in</strong>g numeric score files. It comprises a numberof function subprograms, called <strong>in</strong>to operation by a user-written control program, and can be<strong>in</strong>voked either as a standalone score preprocessor, or as part of the <strong>Csound</strong> run-time system:Cscore scorefile<strong>in</strong> scorefileoutor<strong>Csound</strong> -C [otherflags] orchname scorenameThe available function programs augment the C language library functions; they can read eitherstandard or pre-sorted score files, can massage and expand the data <strong>in</strong> various ways, then makeit available for performance by a <strong>Csound</strong> orchestra.The user-written control program is also <strong>in</strong> C, and is compiled and l<strong>in</strong>ked to the functionprograms (or the entire <strong>Csound</strong>) by the user. It is not essential to know the C language well towrite this program, s<strong>in</strong>ce the function calls have a simple syntax, and are powerful enough to domost of the complicated work. Additional power can come from C later as the need arises.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.1


75.1 Events, Lists, and OperationsAn event <strong>in</strong> Cscore is equivalent to one statement of a standard numeric score or time-warpedscore (see any score.srt), stored <strong>in</strong>ternally <strong>in</strong> time-warped format. It is either created <strong>in</strong>-l<strong>in</strong>e, orread <strong>in</strong> from an exist<strong>in</strong>g score file (either format). Its ma<strong>in</strong> components are an opcode and anarray of pfield values. It is stored somewhere <strong>in</strong> memory, organized by a structure that starts asfollows:typedef struct {CSHDR h; /* space-manag<strong>in</strong>g header */long op; /* opcode—t, w, f, i, a, s or e */long pcnt; /* number of pfields p1, p2, p3 ... */long strlen; /* length of optional str<strong>in</strong>g argument */char *strarg; /* address of optional str<strong>in</strong>g argument */float p2orig; /* unwarped p2, p3 */float p3orig;float offtim; /* storage used dur<strong>in</strong>g performance */float p[1]; /* array of pfields p0, p1, p2 ... */} EVENT;Any function subprogram that creates, reads, or copies an event will return a po<strong>in</strong>ter to thestorage structure hold<strong>in</strong>g the event data. The event po<strong>in</strong>ter can be used to access any componentof the structure, <strong>in</strong> the form of e-op or e-p[n]. Each newly stored event will give rise to a newpo<strong>in</strong>ter, and a sequence of new events will generate a sequence of dist<strong>in</strong>ct po<strong>in</strong>ters that mustthemselves be stored. Groups of event po<strong>in</strong>ters are stored <strong>in</strong> an event list, which has its ownstructure:typedef struct {CSHDR h;<strong>in</strong>t nslots; /* max events <strong>in</strong> this event list */<strong>in</strong>t nevents; /* number of events present */EVENT *e[1]; /* array of event po<strong>in</strong>ters e0, e1, e2.. */} EVLIST;Any function that creates or modifies a list will return a po<strong>in</strong>ter to the new list. The list po<strong>in</strong>tercan be used to access any of its component event po<strong>in</strong>ters, <strong>in</strong> the form of a-e[n]. Event po<strong>in</strong>tersand list po<strong>in</strong>ters are thus primary tools for manipulat<strong>in</strong>g the data of a score file. Po<strong>in</strong>ters andlists of po<strong>in</strong>ters can be copied and reordered without modify<strong>in</strong>g the data values they refer to.This means that notes and phrases can be copied and manipulated from a high level of control.Alternatively, the data with<strong>in</strong> an event or group of events can be modified without chang<strong>in</strong>g theevent or list po<strong>in</strong>ters. The Cscore function subprograms enable scores to be created andmanipulated <strong>in</strong> this way.In the follow<strong>in</strong>g summary of Cscore function calls, some simple nam<strong>in</strong>g conventions are used:The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.2


the symbols e, f are po<strong>in</strong>ters to events (notes);the symbols a, b are po<strong>in</strong>ters to lists (arrays) of such events;the letters ev at the end of a function name signify operation on an event;the letter l at the start of a function name signifies operation on a list.the symbol fp is a score <strong>in</strong>put stream file po<strong>in</strong>ter (FILE *);call<strong>in</strong>g syntaxdescriptione = createv(n);create a blank event with n pfields<strong>in</strong>t n;e = defev(“...”); def<strong>in</strong>es an event as per the character str<strong>in</strong>g ...e = copyev(f);make a new copy of event fe = getev();read the next event <strong>in</strong> the score <strong>in</strong>put fileputev(e);write event e to the score output fileputstr(“...”);write the str<strong>in</strong>g-def<strong>in</strong>ed event to score outputa = lcreat(n);create an empty event list with n slots<strong>in</strong>t n;a = lappev(a,e);append event e to list aa = lappstrev(a,”...”); append a str<strong>in</strong>g-def<strong>in</strong>ed event to list a;a = lcopy(b);copy the list b (but not the events)a = lcopyev(b);copy the events of b, mak<strong>in</strong>g a new lista = lget();read all events from score <strong>in</strong>put, up to next s or ea = lgetnext(nbeats); read next nbeats beats from score <strong>in</strong>putfloat nbeats;a = lgetuntil(beatno); read all events from score <strong>in</strong>put up to beat beatnofloat beatno;a = lsepf(b);separate the f statements from list b <strong>in</strong>to list aa = lseptwf(b);separate the t,w & f statements from list b <strong>in</strong>tolist aa = lcat(a,b);concatenate (append) the list b onto the list alsort(a);sort the list a <strong>in</strong>to chronological order by p[2]a = lx<strong>in</strong>s(b,”...”); extract notes of <strong>in</strong>struments ... (no new events)a = lxtimev(b,from,to); extract notes of time-span, creat<strong>in</strong>g new eventsfloat from, to;lput(a);lplay(a);write the events of list a to the score output filesend events of list a to the <strong>Csound</strong> orchestra forimmediate performance (or pr<strong>in</strong>t events if noorchestra)relev(e);release the space of event elrel(a);release the space of list a (but not the events)lrelev(a);release the events of list a, and the list spacefp = getcurfp();get the currently active <strong>in</strong>put scorefile po<strong>in</strong>ter(<strong>in</strong>itially f<strong>in</strong>ds the command-l<strong>in</strong>e <strong>in</strong>put scorefilepo<strong>in</strong>ter)fp = filopen(“filename”); open another <strong>in</strong>put scorefile (maximum of 5)setcurfp(fp);filclose(fp);make fp the currently active scorefile po<strong>in</strong>terclose the scorefile relat<strong>in</strong>g to FILE *fpThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.3


75.2 Writ<strong>in</strong>g a Ma<strong>in</strong> ProgramThe general format for a control program is:#<strong>in</strong>clude “cscore.h”cscore(){/* VARIABLE DECLARATIONS *//* PROGRAM BODY */} The <strong>in</strong>clude statement will def<strong>in</strong>e the event and list structures for the program. The follow<strong>in</strong>gC program will read from a standard numeric score, up to (but not <strong>in</strong>clud<strong>in</strong>g) the first s or estatement, then write that data (unaltered) as output.#<strong>in</strong>clude “cscore.h”cscore(){EVLIST *a; /* a is allowed to po<strong>in</strong>t to an event list */a = lget(); /* read events <strong>in</strong>, return the list po<strong>in</strong>ter */lput(a); /* write these events out (unchanged) */putstr(“e”); /* write the str<strong>in</strong>g e to output */}After execution of lget(), the variable a po<strong>in</strong>ts to a list of event addresses, each of which po<strong>in</strong>ts toa stored event. We have used that same po<strong>in</strong>ter to enable another list function (lput) to accessand write out all of the events that were read. If we now def<strong>in</strong>e another symbol e to be an eventpo<strong>in</strong>ter, then the statemente = a-e[4];will set it to the contents of the 4th slot <strong>in</strong> the evlist structure. The contents is a po<strong>in</strong>ter to anevent, which is itself comprised of an array of parameter field values. Thus the term e-p[5] willmean the value of parameter field 5 of the 4th event <strong>in</strong> the evlist denoted by a. The programbelow will multiply the value of that pfield by 2 before writ<strong>in</strong>g it out.#<strong>in</strong>clude “cscore.h”cscore(){EVENT *e; /* a po<strong>in</strong>ter to an event */EVLIST *a;a = lget(); /* read a score as a list of events */e = a-e[4]; /* po<strong>in</strong>t to event 4 <strong>in</strong> event list a */e-p[5] *= 2; /* f<strong>in</strong>d pfield 5, multiply its value by 2 */lput(a); /* write out the list of events */putstr(“e”); /* add a “score end” statement */}Now consider the follow<strong>in</strong>g score, <strong>in</strong> which p[5] conta<strong>in</strong>s frequency <strong>in</strong> Hz.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.4


f 1 0 257 10 1f 2 0 257 7 0 300 1 212 .8i 1 1 3 0 440 10000i 1 4 3 0 256 10000i 1 7 3 0 880 10000eIf this score were given to the preced<strong>in</strong>g ma<strong>in</strong> program, the result<strong>in</strong>g output would look like this:f 1 0 257 10 1f 2 0 257 7 0 300 1 212 .8i 1 1 3 0 440 10000i 1 4 3 0 512 10000 ; p[5] has become 512 <strong>in</strong>stead of 256.i 1 7 3 0 880 10000eNote that the 4th event is <strong>in</strong> fact the second note of the score. So far we have not dist<strong>in</strong>guishedbetween notes and function table setup <strong>in</strong> a numeric score. Both can be classed as events. Alsonote that our 4th event has been stored <strong>in</strong> e[4] of the structure. For compatibility with <strong>Csound</strong>pfield notation, we will ignore p[0] and e[0] of the event and list structures, stor<strong>in</strong>g p1 <strong>in</strong> p[1],event 1 <strong>in</strong> e[1], etc. The Cscore functions all adopt this convention.As an extension to the above, we could decide to use a and e to exam<strong>in</strong>e each of the events <strong>in</strong> thelist. Note that e has not preserved the numeral 4, but the contents of that slot. To <strong>in</strong>spect p5 ofthe previous listed event we need only redef<strong>in</strong>e e with the assignmente = a-e[3];More generally, if we declare a new variable f to be a po<strong>in</strong>ter to a po<strong>in</strong>ter to an event, thestatementf = &a-e[4];will set f to the address of the fourth event <strong>in</strong> the event list a, and *f will signify the contents ofthe slot, namely the event po<strong>in</strong>ter itself. The expression(*f)-p[5],like e-p[5], signifies the fifth pfield of the selected event. However, we can advance to the nextslot <strong>in</strong> the evlist by advanc<strong>in</strong>g the po<strong>in</strong>ter f. In C this is denoted by f++.In the follow<strong>in</strong>g program we will use the same <strong>in</strong>put score. This time we will separate the ftablestatements from the note statements. We will next write the three note-events stored <strong>in</strong> the list a,then create a second score section consist<strong>in</strong>g of the orig<strong>in</strong>al pitch set and a transposed version ofitself. This will br<strong>in</strong>g about an octave doubl<strong>in</strong>g.By po<strong>in</strong>t<strong>in</strong>g the variable f to the first note-event and <strong>in</strong>crement<strong>in</strong>g f <strong>in</strong>side a while block whichiterates n times (the number of events <strong>in</strong> the list), one statement can be made to act upon thesame pfield of each successive event.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.5


#<strong>in</strong>clude “cscore.h”cscore(){EVENT *e,**f; /* declarations. see pp.8-9 <strong>in</strong> the */EVLIST *a,*b; /* C language programm<strong>in</strong>g manual */<strong>in</strong>t n;a = lget(); /* read score <strong>in</strong>to event list “a” */b = lsepf(a); /* separate f statements */lput(b); /* write f statements out to score */lrelev(b); /* and release the spaces used */e = defev(“t 0 120”); /* def<strong>in</strong>e event for tempo statement */putev(e); /* write tempo statement to score */lput(a); /* write the notes */putstr(“s”); /* section end */putev(e); /* write tempo statement aga<strong>in</strong> */b = lcopyev(a); /* make a copy of the notes <strong>in</strong> “a” */n = b-nevents; /* and get the number present */f = &a-e[1];while (n--) /* iterate the follow<strong>in</strong>g l<strong>in</strong>e n times: */(*f++)-p[5] *= .5; /* transpose pitch down one octave */a = lcat(b,a); /* now add these notes to orig<strong>in</strong>al pitches */lput(a);putstr(“e”);}The output of this program is:f 1 0 257 10 1f 2 0 257 7 0 300 1 212 .8t 0 120i 1 1 3 0 440 10000i 1 4 3 0 256 10000i 1 7 3 0 880 10000st 0 120i 1 1 3 0 440 10000i 1 4 3 0 256 10000i 1 7 3 0 880 10000i 1 1 3 0 220 10000i 1 4 3 0 128 10000i 1 7 3 0 440 10000eThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.6


Next we extend the above program by us<strong>in</strong>g the while statement to look at p[5] and p[6]. In theorig<strong>in</strong>al score p[6] denotes amplitude. To create a dim<strong>in</strong>uendo <strong>in</strong> the added lower octave, whichis <strong>in</strong>dependent from the orig<strong>in</strong>al set of notes, a variable called dim will be used.#<strong>in</strong>clude “cscore.h”cscore(){EVENT *e,**f;EVLIST *a,*b;<strong>in</strong>t n, dim; /* declare two <strong>in</strong>teger variables */a = lget();b = lsepf(a);lput(b);lrelev(b);e = defev(“t 0 120”);putev(e);lput(a);putstr(“s”);putev(e); /* write out another tempo statement */b = lcopyev(a);n = b-nevents;dim = 0; /* <strong>in</strong>itialize dim to 0 */f = &a-e[1];while (n--){(*f)-p[6] -= dim; /* subtract current value of dim */(*f++)-p[5] *= .5; /* transpose, move f to next event */dim += 2000; /* <strong>in</strong>crease dim for each note */}a = lcat(b,a);lput(a);putstr(“e”);}The <strong>in</strong>crement of f <strong>in</strong> the above programs has depended on certa<strong>in</strong> precedence rules of C.Although this keeps the code tight, the practice can be dangerous for beg<strong>in</strong>ners. Increment<strong>in</strong>gmay alternately be written as a separate statement to make it more clear.while (n--){(*f)-p[6] -= dim;(*f)-p[5] *= .5;dim += 2000;f++;}The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.7


Us<strong>in</strong>g the same <strong>in</strong>put score aga<strong>in</strong>, the output from this program is:f 1 0 257 10 1f 2 0 257 7 0 300 1 212 .8t 0 120i 1 1 3 0 440 10000i 1 4 3 0 256 10000i 1 7 3 0 880 10000st 0 120i 1 1 3 0 440 10000 ; Three orig<strong>in</strong>al notes ati 1 4 3 0 256 10000 ; beats 1,4 and 7 with no dim.i 1 7 3 0 880 10000i 1 1 3 0 220 10000 ; three notes transposed down one octavei 1 4 3 0 128 8000 ; also at beats 1,4 and 7 with dim.i 1 7 3 0 440 6000eIn the follow<strong>in</strong>g program the same three-note sequence will be repeated at various time<strong>in</strong>tervals. The start<strong>in</strong>g time of each group is determ<strong>in</strong>ed by the values of the array cue. Thistime the dim will occur for each group of notes rather than each note. Note the position of thestatement which <strong>in</strong>crements the variable dim outside the <strong>in</strong>ner while block.#<strong>in</strong>clude “cscore.h”<strong>in</strong>t cue[3]={0,10,17}; /* declare an array of 3 <strong>in</strong>tegers */cscore(){EVENT *e, **f;EVLIST *a, *b;<strong>in</strong>t n, dim, cuecount, holdn; /* declare new variables */a = lget();b = lsepf(a);lput(b);lrelev(b);e = defev(“t 0 120”);putev(e);}n = a-nevents;holdn = n;/* hold the value of “n” to reset below*/cuecount = 0; /* <strong>in</strong>itialize cuecount to “0” */dim = 0;while (cuecount


Here the <strong>in</strong>ner while block looks at the events of list a (the notes) and the outer while block looksat each repetition of the events of list a (the pitch group repetitions). This program alsodemonstrates a useful trouble-shoot<strong>in</strong>g device with the pr<strong>in</strong>tf function. The semi-colon is first <strong>in</strong>the character str<strong>in</strong>g to produce a comment statement <strong>in</strong> the result<strong>in</strong>g score file. In this case thevalue of cue is be<strong>in</strong>g pr<strong>in</strong>ted <strong>in</strong> the output to <strong>in</strong>sure that the program is tak<strong>in</strong>g the proper arraymember at the proper time. When output data is wrong or error messages are encountered, thepr<strong>in</strong>tf function can help to p<strong>in</strong>po<strong>in</strong>t the problem.Us<strong>in</strong>g the identical <strong>in</strong>put file, the C program above will generate:f 1 0 257 10 1f 2 0 257 7 0 300 1 212 .8t 0 120; diagnostic: cue = 0i 1 1 3 0 440 10000i 1 4 3 0 256 10000i 1 7 3 0 880 10000; diagnostic: cue = 10i 1 11 3 0 440 8000i 1 14 3 0 256 8000i 1 17 3 0 880 8000; diagnostic: cue = 17i 1 28 3 0 440 4000i 1 31 3 0 256 4000i 1 34 3 0 880 4000e;The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.9


75.3 More Advanced ExamplesThe follow<strong>in</strong>g program demonstrates read<strong>in</strong>g from two different <strong>in</strong>put files. The idea is toswitch between two 2-section scores, and write out the <strong>in</strong>terleaved sections to a s<strong>in</strong>gle outputfile../.html<strong>in</strong>clude “cscore.h” /* CSCORE_SWITCH.C */cscore()/* callable from either <strong>Csound</strong> or standalonecscore */{EVLIST *a, *b;FILE *fp1, *fp2; /* declare two scorefile stream po<strong>in</strong>ters */fp1 = getcurfp(); /* this is the command-l<strong>in</strong>e score */fp2 = filopen(“score2.srt”); /* this is an additional score file */a = lget(); /* read section from score 1 */lput(a); /* write it out as is */putstr(“s”);setcurfp(fp2);b = lget(); /* read section from score 2 */lput(b); /* write it out as is */putstr(“s”);lrelev(a); /* optional to reclaim space */lrelev(b);setcurfp(fp1);a = lget(); /* read next section from score 1 */lput(a); /* write it out */putstr(“s”);setcurfp(fp2);b = lget(); /* read next sect from score 2 */lput(b); / * write it out */putstr(“e”);}F<strong>in</strong>ally, we show how to take a literal, un<strong>in</strong>terpreted score file and imbue it with some expressivetim<strong>in</strong>g changes. The theory of composer-related metric pulses has been <strong>in</strong>vestigated at length byManfred Cl<strong>in</strong>es, and the follow<strong>in</strong>g is <strong>in</strong> the spirit of his work. The strategy here is to first createan array of new onset times for every possible sixteenth-note onset, then to <strong>in</strong>dex <strong>in</strong>to it so as toadjust the start and duration of each note of the <strong>in</strong>put score to the <strong>in</strong>terpreted time-po<strong>in</strong>ts. Thisalso shows how a <strong>Csound</strong> orchestra can be <strong>in</strong>voked repeatedly from a run-time score generator.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.10


./.html<strong>in</strong>clude “cscore.h” /* CSCORE_PULSE.C *//* program to apply <strong>in</strong>terpretive durational pulse to *//* an exist<strong>in</strong>g score <strong>in</strong> 3/4 time, first beats on 0, 3, 6 ... */static float four[4] = { 1.05, 0.97, 1.03, 0.95 };4’s*/static float three[3] = { 1.03, 1.05, .92 };3’s*//* pulse width for/* pulse width forcscore() /* callable from either <strong>Csound</strong> or standalone cscore */{EVLIST *a, *b;register EVENT *e, **ep;float pulse16[4*4*4*4*3*4]; /* 16th-note array, 3/4 time, 256 measures */float acc16, acc1,<strong>in</strong>c1, acc3,<strong>in</strong>c3, acc12,<strong>in</strong>c12, acc48,<strong>in</strong>c48, acc192,<strong>in</strong>c192;register float *p = pulse16;register <strong>in</strong>t n16, n1, n3, n12, n48, n192;/* fill the array with <strong>in</strong>terpreted ontimes */for (acc192=0.,n192=0; n192


As stated above, the <strong>in</strong>put files to Cscore may be <strong>in</strong> orig<strong>in</strong>al or time-warped and pre-sortedform; this modality will be preserved (section by section) <strong>in</strong> read<strong>in</strong>g, process<strong>in</strong>g and writ<strong>in</strong>gscores. Standalone process<strong>in</strong>g will most often use unwarped sources and create unwarped newfiles. When runn<strong>in</strong>g from with<strong>in</strong> <strong>Csound</strong> the <strong>in</strong>put score will arrive already warped and sorted,and can thus be sent directly (normally section by section) to the orchestra.A list of events can be conveyed to a <strong>Csound</strong> orchestra us<strong>in</strong>g lplay. There may be any number oflplay calls <strong>in</strong> a Cscore program. Each list so conveyed can be either time-warped or not, buteach list must be <strong>in</strong> strict p2-chronological order (either from presort<strong>in</strong>g or us<strong>in</strong>g lsort). If thereis no lplay <strong>in</strong> a cscore module run from with<strong>in</strong> <strong>Csound</strong>, all events written out (via putev, putstror lput) constitute a new score, which will be sent <strong>in</strong>itially to scsort then to the <strong>Csound</strong> orchestrafor performance. These can be exam<strong>in</strong>ed <strong>in</strong> the files ‘cscore.out’ and ‘cscore.srt’.A standalone Cscore program will normally use the put commands to write <strong>in</strong>to its output file.If a standalone Cscore program conta<strong>in</strong>s lplay, the events thus <strong>in</strong>tended for performance will<strong>in</strong>stead be pr<strong>in</strong>ted on the console.A note list sent by lplay for performance should be temporally dist<strong>in</strong>ct from subsequent notelists. No note-end should extend past the next list’s start time, s<strong>in</strong>ce lplay will complete each listbefore start<strong>in</strong>g the next (i.e. like a Section marker that doesn’t reset local time to zero). This isimportant when us<strong>in</strong>g lgetnext() or lgetuntil() to fetch and process score segments prior toperformance.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.12


75.4 Compil<strong>in</strong>g a Cscore ProgramA Cscore program can be <strong>in</strong>voked either as a Standalone program or as part of <strong>Csound</strong>:orcscore –U pvanal scorename outfilenamecsound –C [otherflags] orchname scorenameTo create a standalone program, write a cscore.c program as shown above and test compile itwith ‘cc cscore.c’. If the compiler cannot f<strong>in</strong>d “cscore.h”, try us<strong>in</strong>g -I/usr/local/<strong>in</strong>clude, or justcopy the cscore.h module from the <strong>Csound</strong> source directory <strong>in</strong>to your own. There will still beunresolved references, so you must now l<strong>in</strong>k your program with certa<strong>in</strong> <strong>Csound</strong> I/O modules. Ifyour <strong>Csound</strong> <strong>in</strong>stallation has created a libcscore.a, you can typecc –o cscore.c -lcscoreElse set an environment variable to a <strong>Csound</strong> directory conta<strong>in</strong><strong>in</strong>g the already compiled modules,and <strong>in</strong>voke them explicitly:setenv CSOUND /ti/u/bv/<strong>Csound</strong>cc –o cscore cscore.c $CSOUND/cscorema<strong>in</strong>.o $CSOUND/cscorefns.o \$CSOUND/rdscore.o $CSOUND/memalloc.oThe result<strong>in</strong>g executable can be applied to an <strong>in</strong>put scorefile<strong>in</strong> by typ<strong>in</strong>g:cscore scorefile<strong>in</strong> scorefileoutTo operate from <strong>Csound</strong>, first proceed as above then l<strong>in</strong>k your program to a complete set of<strong>Csound</strong> modules. If your <strong>Csound</strong> <strong>in</strong>stallation has created a libcsound.a, you can do this bytyp<strong>in</strong>gcc –o mycsound cscore.o –lcsounc –lX11 –lm (X11 if your <strong>in</strong>stallation<strong>in</strong>cluded it)Else copy *.c, *.h and Makefile from the <strong>Csound</strong> source directory, replace cscore.c by your own,then run ‘make <strong>Csound</strong>’. The result<strong>in</strong>g executable is your own special <strong>Csound</strong>, usable as above.The -C flag will <strong>in</strong>voke your Cscore program after the <strong>in</strong>put score is sorted <strong>in</strong>to ‘score.srt’.With no lplay, the subsequent stages of process<strong>in</strong>g can be seen <strong>in</strong> the files ‘cscore.out’ and‘cscore.srt’.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.13


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Cscore Page 75.14


76 ADDING YOUR OWN CMODULES TO CSOUNDIf the exist<strong>in</strong>g <strong>Csound</strong> generators do not suit your needs, you can write your own modules <strong>in</strong> Cand add them to the run-time system. When you <strong>in</strong>voke <strong>Csound</strong> on an orchestra and score file,the orchestra is first read by a table-driven translator ‘otran’ and the <strong>in</strong>strument blocks convertedto coded templates ready for load<strong>in</strong>g <strong>in</strong>to memory by ‘oload’ on request by the score reader. Touse your own C-modules with<strong>in</strong> a standard orchestra you need only add an entry <strong>in</strong> otran’s tableand rel<strong>in</strong>k <strong>Csound</strong> with your own code.The translator, loader, and run-time monitor will treat your module just like any other providedyou follow some conventions. You need a structure def<strong>in</strong><strong>in</strong>g the <strong>in</strong>puts, outputs and workspace,plus some <strong>in</strong>itialization code and some perf-time code. Let’s put an example of these <strong>in</strong> two newfiles, newgen.h and newgen.c:typedef struct { /* newgen.h - def<strong>in</strong>e a structure */OPDSh; /* required header */float *result, *istrt, *<strong>in</strong>cr, *itime, *icont<strong>in</strong>; /* addr outarg,<strong>in</strong>args */float curval, v<strong>in</strong>cr; /* private dataspace */long countdown; /* ditto */} RMP;#<strong>in</strong>clude “cs.h” /* newgen.c - <strong>in</strong>it and perf code */#<strong>in</strong>clude “newgen.h”void rampset(RMP *p) /* at note <strong>in</strong>itialization: */{if (*p-icont<strong>in</strong> == 0.)p-curval = *p-istrt; /* optionally get new start value */p-v<strong>in</strong>cr = *p-<strong>in</strong>cr / esr; /* set s-rate <strong>in</strong>crement per sec. */p-countdown = *p-itime * esr; /* counter for itime seconds */}void ramp(RMP *p) /* dur<strong>in</strong>g note performance: */{float *rsltp = p-result; /* <strong>in</strong>it an output array po<strong>in</strong>ter */<strong>in</strong>t nn = ksmps; /* array size from orchestra */do {*rsltp++ = p-curval; /* copy current value to output */if (--p-countdown = 0) /* for the first itime seconds, */p-curval += p-v<strong>in</strong>cr; /* ramp the value */} while (--nn);}Now we add this module to the translator table entry.c, under the opcode name rampt:#<strong>in</strong>clude “newgen.h”void rampset(), ramp();/* opcode dspace thread outarg <strong>in</strong>args isub ksubasub */{ “rampt”, S(RMP), 5, “a”, “iiio”, rampset, NULL,ramp },The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Add<strong>in</strong>g your own Cmodules to <strong>Csound</strong> Page 76-1


F<strong>in</strong>ally we rel<strong>in</strong>k <strong>Csound</strong> to <strong>in</strong>clude the new module. If your <strong>Csound</strong> <strong>in</strong>stallation has created alibcsound.a, you can do this by typ<strong>in</strong>gcc -o mycsound newgen.c entry.c -lcsound -lX11 -lm (X11 if <strong>in</strong>cluded at<strong>in</strong>stallation)Else copy *.c, *.h and Makefile from the <strong>Csound</strong> sources, add newgen.o to the Makefile listOBJS, add newgen.h as a dependency for entry.o, and a new dependency ‘newgen.o:newgen.h’, then run ‘make <strong>Csound</strong>’. If your host is a Mac<strong>in</strong>tosh, simply add newgen.h andnewgen.c to one of the segments <strong>in</strong> the <strong>Csound</strong> Project, and <strong>in</strong>voke the C compiler.The above actions have added a new generator to the <strong>Csound</strong> language. It is an audio-rate l<strong>in</strong>earramp function which modifies an <strong>in</strong>put value at a user-def<strong>in</strong>ed slope for some period. A rampcan optionally cont<strong>in</strong>ue from the previous note’s last value. The <strong>Csound</strong> manual entry wouldlook like:ar rampt istart, islope, itime [, icont<strong>in</strong>]istart – beg<strong>in</strong>n<strong>in</strong>g value of an audio-rate l<strong>in</strong>ear ramp. Optionally overridden by a cont<strong>in</strong>ue flag.islope – slope of ramp, expressed as the y-<strong>in</strong>terval change per second.itime – ramp time <strong>in</strong> seconds, after which the value is held for the rema<strong>in</strong>der of the note.icont<strong>in</strong> (optional) – cont<strong>in</strong>ue flag. If zero, ramp<strong>in</strong>g will proceed from <strong>in</strong>put istart . If non-zero,ramp<strong>in</strong>g will proceed from the last value of the previous note. The default value is zero.The file newgen.h <strong>in</strong>cludes a one-l<strong>in</strong>e list of output and <strong>in</strong>put parameters. These are the portsthrough which the new generator will communicate with the other generators <strong>in</strong> an <strong>in</strong>strument.Communication is by address, not value, and this is a list of po<strong>in</strong>ters to floats. There are norestrictions on names, but the <strong>in</strong>put-output argument types are further def<strong>in</strong>ed by characterstr<strong>in</strong>gs <strong>in</strong> entry.c (<strong>in</strong>args, outargs). Inarg types are commonly x, a, k, and i, <strong>in</strong> the normal <strong>Csound</strong>manual conventions; also available are o (optional, default<strong>in</strong>g to 0), p (optional, default<strong>in</strong>g to 1).Outarg types <strong>in</strong>clude a, k, i and s (asig or ksig). It is important that all listed argument names beassigned a correspond<strong>in</strong>g argument type <strong>in</strong> entry.c. Also, i-type args are valid only at<strong>in</strong>itialization time, and other-type args are available only at perf time. Subsequent l<strong>in</strong>es <strong>in</strong> theRMP structure declare the work space needed to keep the code re-entrant. These enable themodule to be used multiple times <strong>in</strong> multiple <strong>in</strong>strument copies while preserv<strong>in</strong>g all data.The file newgen.c conta<strong>in</strong>s two subrout<strong>in</strong>es, each called with a po<strong>in</strong>ter to the uniquely allocatedRMP structure and its data. The subrout<strong>in</strong>es can be of three types: note <strong>in</strong>itialization, k-ratesignal generation, a-rate signal generation. A module normally requires two of these<strong>in</strong>itialization, and either k-rate or a-rate subrout<strong>in</strong>es which become <strong>in</strong>serted <strong>in</strong> various threadedlists of runnable tasks when an <strong>in</strong>strument is activated. The thread-types appear <strong>in</strong> entry.c <strong>in</strong> twoforms: isub, ksub and asub names; and a thread<strong>in</strong>g <strong>in</strong>dex which is the sum of isub=1, ksub=2,asub=4. The code itself may reference global variables def<strong>in</strong>ed <strong>in</strong> cs.h and oload.c, the mostuseful of which are:The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Add<strong>in</strong>g your own Cmodules to <strong>Csound</strong> Page 76-2


extern OPARMS O ; float esruser-def<strong>in</strong>ed sampl<strong>in</strong>g rate float ekruser-def<strong>in</strong>ed control rate float ensmpsuser-def<strong>in</strong>ed ksmps <strong>in</strong>t ksmpsuser-def<strong>in</strong>ed ksmps <strong>in</strong>t nchnlsuser-def<strong>in</strong>ed nchnls <strong>in</strong>t O.odebugcommand-l<strong>in</strong>e -v flag <strong>in</strong>t O.msglevelcommand-l<strong>in</strong>e -m level float pi, twopi obviousconstants float tpidsr twopi / esr floatsstrcodspecial code for str<strong>in</strong>g arguments76.1.1 FUNCTION TABLESTo access stored function tables, special help is available. The newly def<strong>in</strong>ed structure should<strong>in</strong>clude a po<strong>in</strong>ter<strong>in</strong>itialized by the statementFUNC*ftp;ftp = ftpf<strong>in</strong>d(p-ifuncno);where float *ifuncno is an i-type <strong>in</strong>put argument conta<strong>in</strong><strong>in</strong>g the ftable number. The stored table isthen at ftp-ftable, and other data such as length, phase masks, cps-to-<strong>in</strong>cr converters, are alsoaccessed from this po<strong>in</strong>ter. See the FUNC structure <strong>in</strong> cs.h, the ftf<strong>in</strong>d() code <strong>in</strong> fgens.c, and thecode for oscset() and koscil() <strong>in</strong> opcodes2.c.76.1.2 ADDITIONAL SPACESometimes the space requirement of a module is too large to be part of a structure (upper limit65535 bytes), or it is dependent on an i-arg value which is not known until <strong>in</strong>itialization.Additional space can be dynamically allocated and properly managed by <strong>in</strong>clud<strong>in</strong>g the l<strong>in</strong>eAUXCHauxch;<strong>in</strong> the def<strong>in</strong>ed structure (*p), then us<strong>in</strong>g the follow<strong>in</strong>g style of code <strong>in</strong> the <strong>in</strong>it module:if (p-auxch.auxp == NULL)auxalloc(npo<strong>in</strong>ts * sizeof(float), &p-auxch);The address of this auxiliary space is kept <strong>in</strong> a cha<strong>in</strong> of such spaces belong<strong>in</strong>g to this <strong>in</strong>strument,and is automatically managed while the <strong>in</strong>strument is be<strong>in</strong>g duplicated or garbage-collecteddur<strong>in</strong>g performance. The assignmentchar *auxp = p-auxch.auxp;will f<strong>in</strong>d the allocated space for <strong>in</strong>it-time and perf-time use. See the LINSEG structure <strong>in</strong>opcodes1.h and the code for lsgset() and klnseg() <strong>in</strong> opcodes1.c.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Add<strong>in</strong>g your own Cmodules to <strong>Csound</strong> Page 76-3


76.1.3 FILE SHARINGWhen access<strong>in</strong>g an external file often, or do<strong>in</strong>g it from multiple places, it is often efficient toread the entire file <strong>in</strong>to memory. This is accomplished by <strong>in</strong>clud<strong>in</strong>g the l<strong>in</strong>eMEMFIL*mfp;<strong>in</strong> the def<strong>in</strong>ed structure (*p), then us<strong>in</strong>g the follow<strong>in</strong>g style of code <strong>in</strong> the <strong>in</strong>it module:if (p-mfp == NULL)p-mfp = ldmemfile(filname);where char *filname is a str<strong>in</strong>g name of the file requested. The data read will be found between(char *) p-mfp-beg<strong>in</strong>p; and (char *) p-mfp-endp;Loaded files do not belong to a particular <strong>in</strong>strument, but are automatically shared for multipleaccess. See the ADSYN structure <strong>in</strong> opcodes3.h and the code for adset() and adsyn() <strong>in</strong>opcodes3.c.76.1.4 STRING ARGUMENTSTo permit a quoted str<strong>in</strong>g <strong>in</strong>put argument (float *ifilnam, say) <strong>in</strong> our def<strong>in</strong>ed structure (*p),assign it the argtype S <strong>in</strong> entry.c, <strong>in</strong>clude another member char *strarg <strong>in</strong> the structure, <strong>in</strong>sert al<strong>in</strong>eTSTRARG( “rampt”, RMP) \<strong>in</strong> the file oload.h, and <strong>in</strong>clude the follow<strong>in</strong>g code <strong>in</strong> the <strong>in</strong>it module:if (*p-ifilnam == sstrcod)strcpy(filename, unquote(p-strarg));See the code for adset() <strong>in</strong> opcodes3.c, lprdset() <strong>in</strong> opcodes5.c, and pvset() <strong>in</strong> opcodes8.c.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Add<strong>in</strong>g your own Cmodules to <strong>Csound</strong> Page 76-4


77 APPENDIX A: MISCELLANEOUSINFORMATION77.1 Pitch ConversionNote Hz cpspch MIDI Note Hz cpspch MIDIC-1 8.176 3.00 0 E4 329.628 8.04 64C#-1 8.662 3.01 1 F4 349.228 8.05 65D-1 9.177 3.02 2 F#4 369.994 8.06 66D#-1 9.723 3.03 3 G4 391.995 8.07 67E-1 10.301 3.04 4 G#4 415.305 8.08 68F-1 10.913 3.05 5 A4 440.000 8.09 69F#-1 11.562 3.06 6 A#4 466.164 8.10 70G-1 12.250 3.07 7 B4 493.883 8.11 71G#-1 12.978 3.08 8 C5 523.251 9.00 72A-1 13.750 3.09 9 C#5 554.365 9.01 73A#-1 14.568 3.10 10 D5 587.330 9.02 74B-1 15.434 3.11 11 D#5 622.254 9.03 75C0 16.352 4.00 12 E5 659.255 9.04 76C#0 17.324 4.01 13 F5 698.456 9.05 77D0 18.354 4.02 14 F#5 739.989 9.06 78D#0 19.445 4.03 15 G5 783.991 9.07 79E0 20.602 4.04 16 G#5 830.609 9.08 80F0 21.827 4.05 17 A5 880.000 9.09 81F#0 23.125 4.06 18 A#5 932.328 9.10 82G0 24.500 4.07 19 B5 987.767 9.11 83G#0 25.957 4.08 20 C6 1046.502 10.00 84A0 27.500 4.09 21 C#6 1108.731 10.01 85A#0 29.135 4.10 22 D6 1174.659 10.02 86B0 30.868 4.11 23 D#6 1244.508 10.03 87C1 32.703 5.00 24 E6 1318.510 10.04 88C#1 34.648 5.01 25 F6 1396.913 10.05 89D1 36.708 5.02 26 F#6 1479.978 10.06 90D#1 38.891 5.03 27 G6 1567.982 10.07 91E1 41.203 5.04 28 G#6 1661.219 10.08 92F1 43.654 5.05 29 A6 1760.000 10.09 93F#1 46.249 5.06 30 A#6 1864.655 10.10 94G1 48.999 5.07 31 B6 1975.533 10.11 95G#1 51.913 5.08 32 C7 2093.005 11.00 96A1 55.000 5.09 33 C#7 2217.461 11.01 97A#1 58.270 5.10 34 D7 2349.318 11.02 98B1 61.735 5.11 35 D#7 2489.016 11.03 99C2 65.406 6.00 36 E7 2637.020 11.04 100C#2 69.296 6.01 37 F7 2793.826 11.05 101D2 73.416 6.02 38 F#7 2959.955 11.06 102D#2 77.782 6.03 39 G7 3135.963 11.07 103E2 82.407 6.04 40 G#7 3322.438 11.08 104F2 87.307 6.05 41 A7 3520.000 11.09 105F#2 92.499 6.06 42 A#7 3729.310 11.10 106G2 97.999 6.07 43 B7 3951.066 11.11 107G#2 103.826 6.08 44 C8 4186.009 12.00 108A2 110.000 6.09 45 C#8 4434.922 12.01 109A#2 116.541 6.10 46 D8 4698.636 12.02 110B2 123.471 6.11 47 D#8 4978.032 12.03 111C3 130.813 7.00 48 E8 5274.041 12.04 112C#3 138.591 7.01 49 F8 5587.652 12.05 113D3 146.832 7.02 50 F#8 5919.911 12.06 114D#3 155.563 7.03 51 G8 6271.927 12.07 115E3 164.814 7.04 52 G#8 6644.875 12.08 116F3 174.614 7.05 53 A8 7040.000 12.09 117F#3 184.997 7.06 54 A#8 7458.620 12.10 118G3 195.998 7.07 55 B8 7902.133 12.11 119G#3 207.652 7.08 56 C9 8372.018 13.00 120A3 220.000 7.09 57 C#9 8869.844 13.01 121A#3 233.082 7.10 58 D9 9397.273 13.02 122B3 246.942 7.11 59 D#9 9956.063 13.03 123C4 261.626 8.00 60 E9 10548.08 13.04 124C#4 277.183 8.01 61 F9 11175.30 13.05 125D4 293.665 8.02 62 F#9 11839.82 13.06 126D#4 311.127 8.03 63 G9 12543.85 13.07 127The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-1


77.2 Sound Intensity Values (for a 1000 Hz tone)Dynamics Intensity (W/m^2) Level (dB)pa<strong>in</strong> 1 120fff 10^-2 100f 10^-4 80p 10^-6 60ppp 10^-8 40threshold 10^-12 0The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-2


77.3 Formant Valuesf1 f2 f3 f4 f5 f1 f2 f3 f4 f5soprano “a”tenor “a”freq (Hz) 800 1150 2900 3900 4950 freq (Hz) 650 1080 2650 2900 3250amp (dB) 0 -6 -32 -20 -50 amp (dB) 0 -6 -7 -8 -22bw (Hz) 80 90 120 130 140 bw (Hz) 80 90 120 130 140soprano “e”tenor “e”freq (Hz) 350 2000 2800 3600 4950 freq (Hz) 400 1700 2600 3200 3580amp (dB) 0 -20 -15 -40 -56 amp (dB) 0 -14 -12 -14 -20bw (Hz) 60 100 120 150 200 bw (Hz) 70 80 100 120 120soprano “i”tenor “i”freq (Hz) 270 2140 2950 3900 4950 freq (Hz) 290 1870 2800 3250 3540amp (dB) 0 -12 -26 -26 -44 amp (dB) 0 -15 -18 -20 -30bw (Hz) 60 90 100 120 120 bw (Hz) 40 90 100 120 120soprano “o”tenor “o”freq (Hz) 450 800 2830 3800 4950 freq (Hz) 400 800 2600 2800 3000amp (dB) 0 -11 -22 -22 -50 amp (dB) 0 -10 -12 -12 -26bw (Hz) 70 80 100 130 135 bw (Hz) 40 80 100 120 120soprano “u”tenor “u”freq (Hz) 325 700 2700 3800 4950 freq (Hz) 350 600 2700 2900 3300amp (dB) 0 -16 -35 -40 -60 amp (dB) 0 -20 -17 -14 -26bw (Hz) 50 60 170 180 200 bw (Hz) 40 60 100 120 120alto “a”bass “a”freq (Hz) 800 1150 2800 3500 4950 freq (Hz) 600 1040 2250 2450 2750amp (dB) 0 -4 -20 -36 -60 amp (dB) 0 -7 -9 -9 -20bw (Hz) 80 90 120 130 140 bw (Hz) 60 70 110 120 130The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-3


f1 f2 f3 f4 f5 f1 f2 f3 f4 f5alto “e”bass “e”freq (Hz) 400 1600 2700 3300 4950 freq (Hz) 400 1620 2400 2800 3100amp (dB) 0 -24 -30 -35 -60 amp (dB) 0 -12 -9 -12 -18bw (Hz) 60 80 120 150 200 bw (Hz) 40 80 100 120 120alto “i”bass “i”freq (Hz) 350 1700 2700 3700 4950 freq (Hz) 250 1750 2600 3050 3340amp (dB) 0 -20 -30 -36 -60 amp (dB) 0 -30 -16 -22 -28bw (Hz) 50 100 120 150 200 bw (Hz) 60 90 100 120 120alto “o”bass “o”freq (Hz) 450 800 2830 3500 4950 freq (Hz) 400 750 2400 2600 2900amp (dB) 0 -9 -16 -28 -55 amp (dB) 0 -11 -21 -20 -40bw (Hz) 70 80 100 130 135 bw (Hz) 40 80 100 120 120alto “u”bass “u”freq (Hz) 325 700 2530 3500 4950 freq (Hz) 350 600 2400 2675 2950amp (dB) 0 -12 -30 -40 -64 amp (dB) 0 -20 -32 -28 -36bw (Hz) 50 60 170 180 200 bw (Hz) 40 80 100 120 120The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-4


f1 f2 f3 f4 f5countertenor “a”freq (Hz) 660 1120 2750 3000 3350amp (dB) 0 -6 -23 -24 -38bw (Hz) 80 90 120 130 140countertenor “e”freq (Hz) 440 1800 2700 3000 3300amp (dB) 0 -14 -18 -20 -20bw (Hz) 70 80 100 120 120countertenor “i”freq (Hz) 270 1850 2900 3350 3590amp (dB) 0 -24 -24 -36 -36bw (Hz) 40 90 100 120 120countertenor “o”freq (Hz) 430 820 2700 3000 3300amp (dB) 0 -10 -26 -22 -34bw (Hz) 40 80 100 120 120countertenor “u”freq (Hz) 370 630 2750 3000 3400amp (dB) 0 -20 -23 -30 -34bw (Hz) 40 60 100 120 120The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-5


77.4 W<strong>in</strong>dow FunctionsW<strong>in</strong>dow<strong>in</strong>g functions are used for analysis, and as waveform envelopes, particularly <strong>in</strong> granularsynthesis. W<strong>in</strong>dow functions are built <strong>in</strong> to some opcodes, but others require a function table togenerate the w<strong>in</strong>dow. GEN20 is used for this purpose. The diagram of each w<strong>in</strong>dow below, isaccompanied by the f statement used to generate the it.77.4.1 HAMMINGf81 0 8192 20 1 177.4.2 HANNINGf82 0 8192 20 2 1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-6


77.4.3 BARTLETTf83 0 8192 20 3 177.4.4 BLACKMANf84 0 8192 20 4 1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-7


77.4.5 BLACKMAN-HARRISf85 0 8192 20 5 177.4.6 GAUSSIANf86 0 8192 20 6 1The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-8


77.4.7 RECTANGLEf88 0 8192 -20 8 .1Note: Vertical scale is exaggerated <strong>in</strong> this diagram.77.4.8 SYNCf89 0 4096 -20 9 .75The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-9


77.5 SoundFont2 File <strong>Format</strong>Beg<strong>in</strong>n<strong>in</strong>g with <strong>Csound</strong> Version 4.06, <strong>Csound</strong> supports SoundFont2 sample file format.SoundFont2 (or SF2) is a widespread standard which allows encod<strong>in</strong>g banks of wavetable-basedsounds <strong>in</strong>to a b<strong>in</strong>ary file. In order to understand the usage of these opcodes, the user must havesome knowledge of the SF2 format, so a brief description of this format follows.The SF2 format is made by generator and modulator objects. All current <strong>Csound</strong> opcodesregard<strong>in</strong>g SF2 support the generator function only.There are several levels of generators hav<strong>in</strong>g a hierarchical structure. The most basic k<strong>in</strong>d ofgenerator object is a sample. Samples may or may not be be looped, and are associated with aMIDI note number, called the base-key. When a sample is associated with a range of MIDI notenumbers, a range of velocities, a transposition (coarse and f<strong>in</strong>e tun<strong>in</strong>g), a scale tun<strong>in</strong>g, and a levelscal<strong>in</strong>g factor, the sample and its associations make up a “split.” A set of splits, together with aname, make up an “<strong>in</strong>strument.” When an <strong>in</strong>strument is associated with a key range, a velocityrange, a level scal<strong>in</strong>g factor, and a transposition, the <strong>in</strong>strument and its associations make up a“layer.” A set of layers, together with a name, makes up a “preset.” Presets are normally the f<strong>in</strong>alsound-generat<strong>in</strong>g structures ready for the user. They generate sound accord<strong>in</strong>g to the sett<strong>in</strong>gs oftheir lower-level components.Both sample data and structure data is embedded <strong>in</strong> the same SF2 b<strong>in</strong>ary file. A s<strong>in</strong>gle SF2 filecan conta<strong>in</strong> up to a maximum of 128 banks of 128 preset programs, for a total of 16384 presets<strong>in</strong> one SF2 file. The maximum number of layers, <strong>in</strong>struments, splits, and samples is not def<strong>in</strong>ed,and probably is only limited by the computer's memory.LayerInstrumentSplitSamplePresetLayerInstrumentSplitSampleLayerInstrumentSplitSampleSoundFont2 File StructureThe Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-10


77.6 Pr<strong>in</strong>t Edition Update ProcedureUpdated pages only, are available, <strong>in</strong> Adobe Acrobat ® (.pdf) format, separately from thecomplete manual. There are separate sets of files for s<strong>in</strong>gle- and double-sided pr<strong>in</strong>t<strong>in</strong>g. The nameof the update file for s<strong>in</strong>gle-sided pr<strong>in</strong>t<strong>in</strong>g, will be with the <strong>Csound</strong> version number to which theycorrespond, end<strong>in</strong>g with up.pdf. For example, the update file for version 3.52 will be called3_52up.pdf.The files conta<strong>in</strong><strong>in</strong>g the update pages only, for double-sided pr<strong>in</strong>t<strong>in</strong>g, will follow the sameconvention as for s<strong>in</strong>gle-sided pr<strong>in</strong>t<strong>in</strong>g, except that a 1 will be appended for the odd numberedpages and a 2 for even numbered pages. Example: 3_52up1.pdf and 3_52up2.pdf for <strong>Csound</strong>version 3.52.There will be as many sets of updates on the server as space permits, <strong>in</strong> the event the user missesan update before the next one is released. The version of the manual is stated on the title page, <strong>in</strong>the footer of each page, and <strong>in</strong> Section 22.6 (<strong>Manual</strong> Update History).To update an exist<strong>in</strong>g manual, pr<strong>in</strong>t the update file(s) for either s<strong>in</strong>gle- or double-sided pr<strong>in</strong>t<strong>in</strong>g,as required. Insert the new pages, and replace the changed pages, as needed, discard<strong>in</strong>g the oldpages that have been replaced.77.6.1 WHERE TO GET THE MANUALThe manual files are available from browser download from the editor’s website:http://www.lakewoodsound.com/csoundor via anonymous ftp:ftp://ftp.csounds.com/manualAll the files are zipped for easy download<strong>in</strong>g, but the Acrobat files are not compressed. Alsoavailable at this site are an HTML Edition, and ASCII text edition, and a Spanish Edition, also <strong>in</strong>Acrobat format, translated by Servando Valero.77.6.2 BUG REPORTSWe have worked to make these manuals as accurate as possible. Errors, however, will happen. Ifyou f<strong>in</strong>d a bug, an error, or omission, please report it to the editor (dmboothe@yahoo.com).The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-11


77.7 <strong>Manual</strong> Update HistoryNote: Beg<strong>in</strong>n<strong>in</strong>g with Version 3.55, page numbers <strong>in</strong> bold <strong>in</strong>dicate new or added pages. Otherpage numbers are revised, exist<strong>in</strong>g pages.DATE VERSION NEW OR CHANGED PAGESSeptember, 1998Version 3.48All3 November, 19988 November, 1998Included <strong>in</strong> 3.493release24 November, 19985 January, 199921 January, 199927 January, 199924 February, 199923 March, 199920 May, 199921 June, 199922 July, 19999 August, 1999Version 3.49 iii, v-xiv, 1:3, 2:1-2:2, 2:13, 5:4, 7:12-7:14, 8:4, 8:16-8:65,9:3-9:4, 9:31-9:40, 11:5-11:6, 13:1-13:2, 13:9, 14:4-14:18,15:18-15:20, 16:4-16:8, 22:6Version 3.491 i, iii, v-xiv, 2:2, 2:16, 8:66, 12:5-12:6, 14:7, 22:6Version 3.492 7:3, 7:14 – 7:18, 8:59 – 8:60, 8:66, 9:8 – 9:9, 9:35, 13:5 –13:6Version 3.493 iii, vi – xiv, 2:5, 5:3 8:18, 8:20, 22:6Version 3.494 iii, vii-xi, xiii-xiv, 3:1, 4:1, 8:14, 8:15, 8:35, 8:59, 9:32, 9:41,9:42, 22:6Version 3.50 iii-xvi, 2:9, 5:3, 7:3, 7:19-22, 8:4-6, 8:18, 8:61 8:67-70, 9:8-9,9:21, 9:23 9:36-37, 9:42-44 13:1-2, 13:5-6, 17:1-2, 18:1-2,22:6Version 3.51 iii, v, vii, xiv, xv, 8:65, 9:14, 17:1, 17:2, 22:6Version 3.52 iii; v-xi; xiii-xv; 5:4; 7:4-7; 7:11; 7:19-22; 8:8-12; 8:49; 8:54;8:71-72; 9:28; 9:38; 9:42; 12:5; 13:5; 13:6; 13:7; 14:4; 22:6Version 3.53 AllVersion 3.54 i; iii; v-xv; xix; xxiii-xxv; xxviii; xxx; xxxii-xxxiii; 2:2; 5:4-6;7:6-7; 7:9; 7:12; 7:20; 8:4-5; 8:8; 8:10-11; 8:16; 8:18, 8:28;8:30; 8:34; 8:34; 8:44-46; 8:65; 8:67-68; 9:1-2; 9:6; 9:10;9:12; 9:39-40; 9:46; 9:49-50; Sec13; 19:1-2; 19:9Version 3.55 i; iii; v-xvi; xix; xxxi; xxxv-xxxvi; 1:5; 2:1-3; 2:10-11; 4:1;5:4-6; 5:7-8; 7:18; 7:20; 8:5-15; 8:20; 8:24; 8:32; 8:34; 8:37;8:39; 8:42; 8:60; 8:64; 8:68; 8:70; 8:72; 9:13; 9:23; 9:26;9:32; 9:34; 9:36-38; 9:39; 9:41; 9:44; 9:48-49; 9:50-58; 10:6; 13:2; 13:6; 13:8; 13:11-12; 13:14-19; 14:1-2;14:4-6; 14:9-10; 14:14-17; 14:19-21; 15:1-7; 15:10-14; 15:16-20; 15:21-22; 16:2-8; 17:2; 18:2; 19:4-6; 19:10; 20:1; 20:5-7;20:10-13; 21:2; 22:6; 22:10-11Version 3.56 i-xxxviii; xxxix-xl; 7:6-9; 7:11-12; 7:14-16; 7:18-21; 8:1; 8:4-5; 8:8-9; 8:11; 8:13-15; 8:22-23; 8:63-74; 8:75-76; 9:59-62;12:7-8; 13:20; 13:21-22; 14:8; 14:11; 22:11-12; 23:1-24Version 3.57 i; v-xl; xli-xlvi; 2:9; 2:16; 5:2; 5:9-10; 6:1; 7:2; 7:18; 7:20;8:1-3; 8:6-7; 8:18; 8:20; 8:22-23; 8:25; 8:32; 8:40; 8:60; 8:63;9:1-62; 9:63-64; 12:1; 12:7-8; 12:9-10; 13:20; 13:22; 14:7;15:16-22; 19:4-10; 19:11-16; 20:04; 22:11; 23:1-22; (delete23:23-24)The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-12


<strong>Manual</strong> Update History (Cont<strong>in</strong>ued)18 August, 1999Version 3.58 i; v-xv; iii; xxxi; xxxii; xxxiii; xxxiv; 1:3; 5:4; 7:1; 9:3; 9:13;9:16; 9:20; 9:25-26; 9:36; 9:38; 9:40; 9:46-64; 14:11-22;14:23-24; 15:19; 19:11; 22:10; 22:1216 November, 1999Version 4.0 All23 November, 1999Version 4.01 i; ix-xvii; 42-3; 49-7 – 49-22; 49-23 – 49-24; 70-5; 76-12;QR10; QR1325 February, 2000Version 4.03 i – xvii; 2-3 – 2-5; 3-1; 3-3; 11-11; 11-12; 42-7; 45-1; 50-3;50-4; 50-5; 50-6; 52-1; 52-2; 68-15; 76-12; QR2; QR11;QR131 August, 2000Version 4.06 All15 September, 2000Version 4.07 i–xviii; 29-2; 34-1; 35-3; 39-3; 40-11; 42-11–42-12; 43-3; 43-12; 43-13–43-16; 56-1; 56-3; 58-3; 58-4; 60-6; 60-11–60-13;70-2–70-24; 77-13; QR10; QR14; QR16The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-13


This page <strong>in</strong>tentionally left blank.The Public <strong>Csound</strong> <strong>Reference</strong> <strong>Manual</strong> Version 4.07 Appendix A: Miscellaneous Information Page 77-14


<strong>Csound</strong> Quick <strong>Reference</strong>Orchestra Syntax: Orchestra Header Statementssr = iargkr = iargksmps = iargnchnls = iargstrset iarg, “str<strong>in</strong>gtext”pset con1, con2, ...seedivalgir ftgen ifn, itime, isize, igen, iarga[, iargb, …iargz]massign ichnl, <strong>in</strong>snumctrl<strong>in</strong>it ichnkm, ictlno1, ival1[, ictlno2, ival2[, ictlno3,ival3[, …ival32]]Orchestra Syntax: Variable Data Types<strong>in</strong>ameknameanameg<strong>in</strong>amegknameganamewname(<strong>in</strong>it variable - <strong>in</strong>itialization only)(control signal - performance time, control rate)(audio signal - performance time, audio rate)(global <strong>in</strong>it variable - <strong>in</strong>itialization only)(global control signal - performance time, controlrate)(global audio signal - performance time, audio rate)(spectral data – performance time, control rate)Orchestra Syntax: Instrument Block Statements<strong>in</strong>strend<strong>in</strong>NNOrchestra Syntax: Variable Initializationi/k/ar = iargi/k/ar <strong>in</strong>it iargir tivali/k/ar divz ia, ib, isubstInstrument Control: Instrument Invocationscheduleschedwhenschedkwhenturnon<strong>in</strong>snum, iwhen, idur[, p4, p5, …]ktrigger, k<strong>in</strong>snum, kwhen, kdur[, p4, p5, …]ktrigger, km<strong>in</strong>tim, kmaxnum, k<strong>in</strong>snum, kwhen, kdur[,kp4, kp5, …]<strong>in</strong>snum[, itime]Instrument Control: Duration Controliholdturnoff1


<strong>Csound</strong> Quick <strong>Reference</strong>Instrument Control: Real-time Performance Controlir active <strong>in</strong>snumcpuprc <strong>in</strong>snum, ipercentmaxalloc <strong>in</strong>snum, icountprealloc <strong>in</strong>snum, icountInstrument Control: Time Read<strong>in</strong>gi/kri/krkrkrtimektimestime<strong>in</strong>stktime<strong>in</strong>stsInstrument Control: Clock Controlclockon <strong>in</strong>umclockoff <strong>in</strong>umir readclock <strong>in</strong>umInstrument Control: Sens<strong>in</strong>g and Controlkpitch,kamppitch asig, iupdte, ilo, ihi, idbthresh[, ifrqs, iconf,istrt, iocts, iq, <strong>in</strong>ptls, irolloff, iskip]kcps,krmspitchamdf asig, im<strong>in</strong>cps, imaxcps[, icps[, imedi[, idowns[, iexcps]]]]ktemp tempest k<strong>in</strong>, iprd, im<strong>in</strong>dur, imemdur, ihp, ithresh, ihtim,ixfdbak, istartempo, ifn[, idisprd, itweek]kr follow asig, idtkout trigger ksig, kthreshold, kmodek/ar peak k/asigtempo ktempo, istartempokx, ky xy<strong>in</strong> iprd, ixm<strong>in</strong>, ixmax, iym<strong>in</strong>, iymax[, ix<strong>in</strong>it, iy<strong>in</strong>it]ar follow2 asig, katt, krelInstrument Control: Conditional Values(a > b ? v1 : v2)(a < b ? v1 : v2)(a >= b ? v1 : v2)(a


<strong>Csound</strong> Quick <strong>Reference</strong>Instrument Control: Macros#def<strong>in</strong>e NAME # replacement text ##def<strong>in</strong>e NAME(a’b’c) # replacement text #$NAME.#undef NAME#<strong>in</strong>clude “filename”Instrument Control: Program Flow Controligoto labeltigoto labelkgoto labelgotolabelif ia R ib igoto labelif ka R kb kgoto labelif ia R ib goto labeltimout istrt idur labellabel :Instrument Control: Re<strong>in</strong>itializationre<strong>in</strong>itrigotorireturnlabellabelMathematical Operations: Arithmetic and Logic Operations- a (no rate restriction)+ a (no rate restriction)a && b (logical AND; not audio-rate)a || b (logical OR; not audio-rate)a + b (no rate restriction)a - b (no rate restriction)a * b (no rate restriction)a / b (no rate restriction)a ^ b (b not audio-rate)a % b (no rate restriction)3


<strong>Csound</strong> Quick <strong>Reference</strong>Mathematical Operations: Mathematical Functions<strong>in</strong>t(x)frac(x)i(x)abs(x)exp(x)log(x)log10(x)sqrt(x)powoftwo(x)logbtwo(x)(<strong>in</strong>it-rate or control-rate args only)(<strong>in</strong>it-rate or control-rate args only)(control-rate args only)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(<strong>in</strong>it-rate or control-rate args only)(<strong>in</strong>it-rate or control-rate args only)Mathematical Operations: Trigonometric Functionss<strong>in</strong>(x)cos(x)tan(x)s<strong>in</strong><strong>in</strong>v(x)cos<strong>in</strong>v(x)tan<strong>in</strong>v(x)s<strong>in</strong>h(x)cosh(x)tanh(x)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)(no rate restriction)Mathematical Operations: Amplitude Functionsdbamp(x)ampdb(x)(<strong>in</strong>it-rate or control-rate args only)(no rate restriction)Mathematical Operations: Random Functionsrnd(x)birnd(x)(<strong>in</strong>it- or control-rate only)(<strong>in</strong>it- or control-rate only)Mathematical Operations: Opcode Equivalents of Functionsar sum asig1, asig2[,asig3…asigN]ar product asig1, asig2[,asig3…asigN]i/k/ar pow i/k/aarg, i/k/powi/k/ar tan<strong>in</strong>v2 i/k/ax, i/k/ayar mac asig1, ksig1, asig2, ksig2, asig3, …ar maca asig1, ksig1, asig2, ksig2, asig3, …4


<strong>Csound</strong> Quick <strong>Reference</strong>Pitch Converters: Functionsoctpch(pch) (<strong>in</strong>it- or control-rate args only)pchoct(oct) (<strong>in</strong>it- or control-rate args only)cpspch(pch) (<strong>in</strong>it- or control-rate args only)octcps(cps) (<strong>in</strong>it- or control-rate args only)cpsoct(oct) (no rate restriction)Pitch Convertors: Tun<strong>in</strong>g Opcodesicps cps2pch ipch, iequalicps cpsxpch ipch, iequal, irepeat, ibaseMIDI Support: Convertersival notnumival veloc [ilow, ihigh]icps cpsmidii/kcps cpsmidib [irange]icps cpstmid ifnioct octmidii/koct octmidib [irange]ipch pchmidii/kpch pchmidib [irange]iamp ampmidi iscal[, ifn]kaft aftouch [im<strong>in</strong>[, imax]]i/kbend pchbend [im<strong>in</strong>[, imax]]i/kval midictrl <strong>in</strong>um[, im<strong>in</strong>[, imax]]MIDI Support: Controller Input<strong>in</strong>itc7 ichan, ictlno, ivalue<strong>in</strong>itc14 ichan, ictlno1, ictlno2, ivalue<strong>in</strong>itc21 ichan, ictlno1, ictlno2, ictlno3, ivaluei/kdest midic7 ictlno, i/km<strong>in</strong>, i/kmax[, ifn]i/kdest midic14 ictlno1, ictlno2, i/km<strong>in</strong>, i/kmax[, ifn]i/kdest midic21 ictlno1, ictlno2, ictlno3, i/km<strong>in</strong>, i/kmax[, ifn]i/kdest ctrl7 ichan, ictlno, i/km<strong>in</strong>, i/kmax[, ifn]i/kdest ctrl14 ichan, ictlno1, ictlno2, i/km<strong>in</strong>, i/kmax[, ifn]i/kdest ctrl21 ichan, ictlno1, ictlno2, ictlno3, i/km<strong>in</strong>, i/kmax[, ifn]i/kval chanctrl ichnl, ictlno[, ilow, ihigh]5


<strong>Csound</strong> Quick <strong>Reference</strong>MIDI Support: Slider Banksi/k1, …,i/k8i/k1, …,i/k16i/k1, …,i/k32i/k1, …,i/k64k1, …,k8k1, …,k16k1, …,k32k1, …,k64i/k1, …,i/k16i/k1, …,i/k32slider8slider16slider32slider64slider8fslider16fslider32fslider64fs16b14s32b14MIDI Support: Generic I/Okstatus,kchan,kdata1,kdata2midi<strong>in</strong>midioutichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1, …,ictlnum8, im<strong>in</strong>8, imax8, <strong>in</strong>it8, ifn8ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1, …,ictlnum16, im<strong>in</strong>16, imax16, <strong>in</strong>it16, ifn16ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1, …,ictlnum32, im<strong>in</strong>32, imax32, <strong>in</strong>it32, ifn32ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1, …,ictlnum64, im<strong>in</strong>64, imax64, <strong>in</strong>it64, ifn64ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1, icutoff1,…, ictlnum8, im<strong>in</strong>8, imax8, <strong>in</strong>it8, ifn8, icutoff8ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1, icutoff1,…, ictlnum16, im<strong>in</strong>16, imax16, <strong>in</strong>it16, ifn16, icutoff16ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1, icutoff1,…, ictlnum32, im<strong>in</strong>32, imax32, <strong>in</strong>it32, ifn32, icutoff32ichan, ictlnum1, im<strong>in</strong>1, imax1, <strong>in</strong>it1, ifn1, icutoff1,…, ictlnum64, im<strong>in</strong>64, imax64, <strong>in</strong>it64, ifn64, icutoff64ichan, ictlno_msb1, ictlno_lsb1, im<strong>in</strong>1, imax1,<strong>in</strong>itvalue1, ifn1, …, ictlno_msb16, ictlno_lsb16,im<strong>in</strong>16, imax16, <strong>in</strong>itvalue16, ifn16ichan, ictlno_msb1, ictlno_lsb1, im<strong>in</strong>1, imax1,<strong>in</strong>itvalue1, ifn1, …, ictlno_msb32, ictlno_lsb32,im<strong>in</strong>32, imax32, <strong>in</strong>itvalue32, ifn32kstatus, kchan, kdata1, kdata2MIDI Support: Note-on/Note-offnoteonnoteoffnoteondurnoteondur2moscilmidionmidion2ichn, <strong>in</strong>um, ivelichn, <strong>in</strong>um, ivelichn, <strong>in</strong>um, ivel, idurichn, <strong>in</strong>um, ivel, idurkchn, knum, kvel, kdur, kpausekchn, knum, kvelkchn, knum, kvel, ktrig6


<strong>Csound</strong> Quick <strong>Reference</strong>MIDI Support: MIDI Message Outputouticoutkcoutic14outkc14outipboutkpboutiatoutkatoutipcoutkpcoutipatoutkpatnrpnmdelayichn, <strong>in</strong>um, ivalue, im<strong>in</strong>, imaxkchn, knum, kvalue, km<strong>in</strong>, kmaxichn, imsb, ilsb, ivalue, im<strong>in</strong>, imaxkchn, kmsb, klsb, kvalue, km<strong>in</strong>, kmaxichn, ivalue, im<strong>in</strong>, imaxkchn, kvalue, km<strong>in</strong>, kmaxichn, ivalue, im<strong>in</strong>, imaxkchn, kvalue, km<strong>in</strong>, kmaxichn, iprog, im<strong>in</strong>, imaxkchn, kprog, km<strong>in</strong>, kmaxichn, <strong>in</strong>otenum, ivalue, im<strong>in</strong>, imaxkchn, knotenum, kvalue, km<strong>in</strong>, kmaxkchan, kparmnum, kparmvaluekstatus, kchan, kd1, kd2, kdelayMIDI Support: Real-time MessagesmclockmrtmsgifreqimsgtypeMIDI Support: MIDI Event ExtenderskflagxtratimreleaseiextradurSignal Generators: L<strong>in</strong>ear and Exponential Generatorsk/ar l<strong>in</strong>e ia, idur1, ibk/ar expon ia, idur1, ibk/ar l<strong>in</strong>seg ia, idur1, ib[, idur2, ic[…]]k/ar l<strong>in</strong>segr ia, idur1, ib[, idur2, ic[…]], irel, izk/ar expseg ia, idur1, ib[, idur2, ic[…]]k/ar expsegr ia, idur1, ib[, idur2, ic[…]], irel, izar expsega ia, idur1, ib[, idur2, ic[…]]k/ar adsr iatt, idec, islev, irel[, idel]k/ar madsr iatt, idec, islev, irel[, idel]k/ar xadsr iatt, idec, islev, irel[, idel]k/ar mxadsr iatt, idec, islev, irel[, idel]7


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Generators: Table Accessi/k/ar table i/k/andx, ifn[, ixmode[, ixoff[, iwrap]]]i/k/ar tablei i/k/andx, ifn[, ixmode[, ixoff[, iwrap]]]i/k/ar table3 i/k/andx, ifn[, ixmode[, ixoff[, iwrap]]]kr oscil1 idel, kamp, idur, ifnkr oscil1i idel, kamp, idur, ifnar osciln kamp, ifrq, ifn, itimesSignal Generators: Phasorsk/ar phasor k/xcps[, iphs]k/ar phasorbnk k/xcps, kndx, icnt [, iphs]Signal Generators: Basic Oscillatorsk/ar oscil k/xamp, k/xcps, ifn[, iphs]k/ar oscili k/xamp, k/xcps, ifn[, iphs]k/ar oscil3 k/xamp, k/xcps, ifn[, iphs]k/ar poscil kamp, kcps, ifn[, iphs]k/ar poscil3 kamp, kcps, ifn[, iphs]k/ar lfo kamp, kcps[, itype]Signal Generators: Dynamic Spectrum Oscillatorsar buzz xamp, xcps, knh, ifn[, iphs]ar gbuzz xamp, xcps, knh, klh, kr, ifn[, iphs]ar vco kamp, kfqc, iwave, kpw, ifn, imaxdSignal Generators: Additive Synthesis/Resynthesisar adsyn kamod, kfmod, ksmod, ifilcodar adsynt kamp, kcps, iwfn, ifreqfn, iampfn, icnt[, iphs]ar hsboscil kamp, ktone, kbrite, ibasfreq, iwfn, ioctfn[, ioctcnt[, iphs]]8


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Generators: FM Synthesisar foscil xamp, kcps, kcar, kmod, kndx, ifn[, iphs]ar foscili xamp, kcps, kcar, kmod, kndx, ifn[, iphs]ar fmvoice kamp, kfreq, kvowel, ktilt, kvibamt, kvibrate, ifn1,ifn2, ifn3, ifn4, ivibfnar fmbell kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,ifn3, ifn4, ivfnar fmrhode kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,ifn3, ifn4, ivfnar fmwurlie kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,ifn3, ifn4, ivfnar fmmetal kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,ifn3, ifn4, ivfnar fmb3 kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,ifn3, ifn4, ivfnar fmpercfl kamp, kfreq, kc1, kc2, kvdepth, kvrate, ifn1, ifn2,ifn3, ifn4, ivfnSignal Generators: Sample Playbackar[,ar2]loscil xamp, kcps, ifn[, ibas[, imod1, ibeg1, iend1[, imod2,ibeg2, iend2]]]ar[,ar2]loscil3 xamp, kcps, ifn[, ibas[, imod1, ibeg1, iend1[, imod2,ibeg2, iend2]]]ar lposcil kamp, kfreqratio, kloop, kend, ifn[, iphs]ar lposcil3 kamp, kfreqratio, kloop, kend, ifn[, iphs]ir sfload “filename”sfpassign istartndx, ifilhandleir sfpreset iprog, ibank, ifilhandle, iprendxsfplist ifilhandlesfilist ifilhandlear1, ar2 sfplay ivel, <strong>in</strong>otnum, xamp, xfreq, iprendx [, iflag]ar sfplaym ivel, <strong>in</strong>otnum, xamp, xfreq, iprendx [, iflag]ar1, ar2 sf<strong>in</strong>tr ivel, <strong>in</strong>otnum, xamp, xfreq, <strong>in</strong>strnum, ifilhandle[, iflag]ar sf<strong>in</strong>strm ivel, <strong>in</strong>otnum, xamp, xfreq, <strong>in</strong>strnum, ifilhandle[, iflag]9


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Generators: Granular Synthesisar fof xamp, xfund, xform, koct, kband, kris, kdur, kdec,iolaps, ifna, ifnb, itotdur[, iphs[, ifmode]]ar fof2 xamp, xfund, xform, koct, kband, kris, kdur, kdec,iolaps, ifna, ifnb, itotdur, kphs, kglissar fog xamp, xdens, xtrans, xspd, koct, kband, kris, kdur,kdec, iolaps, ifna, ifnb, itotdur[, iphs[, itmode]]ar gra<strong>in</strong> xamp, xpitch, xdens, kampoff, kpitchoff, kgdur, igfn,iwfn, imgdur[, igrnd]ar granule xamp, ivoice, iratio, imode, ithd, ifn, ipshift,igskip, igskip_os, ilength, kgap, igap_os, kgsize,igsize_os, iatt, idec[, iseed[, ipitch1[, ipitch2[,ipitch3[, ipitch4[, ifnenv]]]]]]]]ar[, ac] sndwarp xamp, xtimewarp, xresample, ifn1, ibeg, iwsize, irandw,ioverlap, ifn2, itimemodear1, ar2[,ac1,ac2]sndwarpstxamp, xtimewarp, xresample, ifn1, ibeg, iwsize, irandw,ioverlap, ifn2, itimemodeSignal Generators: Scanned Synthesisscanu <strong>in</strong>it, irate, ifnvel, ifnmass, ifnstif, ifncentr,ifndamp, kmass, kstif, kcentr, kdamp, ileft, iright,kpos, kstrngth, a<strong>in</strong>, idisp, idar scans kamp, kfreq, ifn, id[, iorder]Signal Generators: Waveguide Physical Model<strong>in</strong>gar pluck kamp, kcps, icps, ifn, imeth[, iparm1, iparm2]ar wgpluck icps, iamp, kpick, iplk, idamp, ifilt, axcitear repluck iplk, xam, icps, kpick, krefl, axcitear wgpluck2 iplk, xam, icps, kpick, kreflar wgbow kamp, kfreq, kpres, krat, kvibf, kvamp, ifn[, im<strong>in</strong>freq]ar wgflute kamp, kfreq, kjet, iatt, idetk, knga<strong>in</strong>, kvibf, kvamp,ifn[, im<strong>in</strong>freq[, kjetrf[, kendrf]]]ar wgbrass kamp, kfreq, iatt, kvibf, kvamp, ifn[, im<strong>in</strong>freq]ar wgclar kamp, kfreq, kstiff, iatt, idetk, knga<strong>in</strong>, kvibf, kvamp,ifn[, im<strong>in</strong>freq]ar wgbowedbar kamp, kfreq, kpos, kbowpres, kga<strong>in</strong>[, kconst, ktvel,kbowpos, ilow]10


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Generators: Models and Emulationsar moog kamp, kfreq, kfiltq, kfiltrate, kvibf, kvamp, iafn,iwfn, ivfnar shaker kamp, kfreq, kbeans, kdamp, ktimes[, idecay]ar marimba kamp, kfreq, ihrd, ipos, imp, kvibf, kvamp, ivibfn,idec[, idoubles[, itriples]]ar vibes kamp, kfreq, ihrd, ipos, imp, kvibf, kvamp, ivibfn,idecar mandol kamp, kfreq, kpluck, kdetune, kga<strong>in</strong>, ksize, ifn[,im<strong>in</strong>freq]ar gogobel kamp, kfreq, ihrd, ipos, imp, kvibf, kvamp, ivibfnar voice kamp, kfreq, kphoneme, kform, kvibf, kvamp, ifn, ivfnax, ay,azlorenz ks, kr, kb, kh, ix, iy, iz, iskipax, ay,azplanetkmass1, kmass2, ksep, ix, iy, iz, ivx, ivy, ivz,idelta, ifrictionSignal Generators: STFT Resynthesis (Vocod<strong>in</strong>g)ar pvoc ktimpnt, kfmod, ifilcod, ifn, ib<strong>in</strong>s[, ib<strong>in</strong>offset,ib<strong>in</strong><strong>in</strong>cr, iextractmode, ifreqlim, igatefn]ar vpvoc ktimpnt, kfmod, ifile[, ispecwp[ ifn]]kfr, kap pvread ktimpnt, ifile, ib<strong>in</strong>pvbufread ktimpnt, ifilear pv<strong>in</strong>terp ktimpnt, kfmod, ifile, kfreqscale1, kfreqscale2,kampscale1, kampscale2, kfreq<strong>in</strong>terp, kamp<strong>in</strong>terpar pvcross ktimpnt, kfmod, ifile, kamp1, kamp2[, ispecwp]tableseg ifn1, idur1, ifn2[, idur2, ifn3[…]]tablexseg ifn1, idur1, ifn2[, idur2, ifn3[…]]ar pvadd ktimpnt, kfmod, ifilcod, ifn, ib<strong>in</strong>s[, ib<strong>in</strong>offset,ib<strong>in</strong><strong>in</strong>cr, iextractmode, ifreqlim, igatefn]Signal Generators: LPC Resynthesiskrmsr, lpread ktimpnt, ifilcod[, <strong>in</strong>poles[, ifrmrate]]krmso,kerr,kcpsar lpreson asigar lpfreson asig, kfrqratiolpslot islotlp<strong>in</strong>terp islot1, islot2, kmix11


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Generators: Random (Noise) Generatorsk/ar rand k/xamp[, iseed[, isize[, koffset]]]k/ar randh k/xamp, k/xcps[, iseed[, isize[, koffset]]]k/ar randi k/xamp, k/xcps[, iseed[, isize[, koffset]]]i/k/ar l<strong>in</strong>rand krangei/k/ar trirand krangei/k/ar exprand krangei/k/ar bexprnd krangei/k/ar cauchy kalphai/k/ar pcauchy kalphai/k/ar poisson klambdai/k/ar gauss krangei/k/ar weibull ksigma, ktaui/k/ar betarand krange, kalpha, kbetai/k/ar unirand krangear p<strong>in</strong>kish x<strong>in</strong>[, imethod, <strong>in</strong>umbands, iseed, iskip]Function Table Control: Table Queriesnsamp(x) (<strong>in</strong>it-rate args only)ftlen(x) (<strong>in</strong>it-rate args only)ftlptim(x) (<strong>in</strong>it-rate args only)ftsr(x) (<strong>in</strong>it-rate args only)i/kr tableng i/kfnFunction Table Control: Table Selectionk/ar tablekt k/xndx, i/kfn[, ixmode[, ixoff[, iwrap]]]k/ar tableikt k/xndx, kfn[, ixmode[, ixoff[, iwrap]]]Function Table Control: Read/Write Operationstablewtablewkttableiwtableigpwtablegpwtableimixtablemixtableicopytablecopyar tablera kfn, kstart, koffkstart tablewa kfn, asig, koffi/k/asig, i/k/andx, ifn[, ixmode[, ixoff[, iwgmode]]]k/asig, k/andx, kfn[, ixmode[, ixoff[, iwgmode]]]isig, <strong>in</strong>dx, ifn[, ixmode[, ixoff[, iwrap]]]ifnkfnidft, idoff, ilen, is1ft, is1off, is1g, is2ft, is2off,is2gkdft, kdoff, klen, ks1ft, ks1off, ks1g, ks2ft, ks2off,ks2gidft, isftkdft, ksft12


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Modifiers: Standard Filterskr portk ksig, khtim[, isig]kr port ksig, ihtim[, isig]kr tonek ksig, khp[, iskip]ar tone asig, khp[, iskip]kr atonek ksig, khp[, iskip]ar atone asig, khp[, iskip]kr resonk ksig, kcf, kbw[, iscl, iskip]ar reson asig, kcf, kbw[, iscl, iskip]kr aresonk ksig, kcf, kbw[, iscl, iskip]ar areson asig, kcf, kbw[, iscl, iskip]ar tonex asig, khp[, <strong>in</strong>umlayer, iskip]ar atonex asig, khp[, <strong>in</strong>umlayer, iskip]ar resonx asig, kcf, kbw[, <strong>in</strong>umlayer, iscl, iskip]ar resonr asig, kcf, kbw[,iscl, iskip]ar resonz asig, kcf, kbw[,iscl, iskip]ar resony asig, kbf, kbw, <strong>in</strong>um, ksep[, isepmode, iscl, iskip]ar lowres asig, kcutoff, kresonance[, iskip]ar lowresx asig, kcutoff, kresonance[, <strong>in</strong>umlayer, iskip]ar vlowres asig, kfco, kres, iord, ksepar lowpass2 asig, kcf, kq[, iskip]ar biquad asig, kb0, kb1, kb2, ka0, ka1, ka2[, iskip]ar rezzy asig, xfco, xres[, imode]ar moogvcf asig, xfco, xres[, iscale]alow, svfilt asig, kcf, kq[, iscl]ahigh,abandar1, ar2 hilbert asigar butterhp asig, kfreq[, iskip]ar butterlp asig, kfreq[, iskip]ar butterbp asig, kfreq, kband[, iskip]ar butterbr asig, kfreq, kband[, iskip]k/ar filter2 k/asig, iM, iN, ib0, ib1, …, ibM, ia1, ia2, …, iaNar zfilter2 asig, kdamp, kfreq, iM, iN, ib0, ib1, …, ibM, ia1, ia2,…, iaNSignal Modifiers: Specialized Filtersar nlfilt a<strong>in</strong>, ka, kb, kd, kL, kCar pareq asig, kc, iv, iq, imodear dcblock asig[, ig]13


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Modifiers: Envelope Modifiersk/ar l<strong>in</strong>en k/xamp, irise, idur, ideck/ar l<strong>in</strong>enr k/xamp, irise, idec, iatdeck/ar envlpx k/xamp, irise, idur, idec, ifn, iatss, iatdec[, ixmod]k/ar envlpxr k/xamp, irise, idur, idec, ifn, iatss, iatdec[, ixmod[,ir<strong>in</strong>d]]Signal Modifiers: Amplitude Modifierskr rms asig[, ihp, iskip]ar ga<strong>in</strong> asig, krms[, ihp, iskip]ar balance asig, acomp[, ihp, iskip]ar dam asig, kthreshold, icomp1, icomp2, irtime, iftimear clip asig, imeth, ilimit[, iarg]Signal Modifiers: Signal Limitersi/k/ar wrap i/k/asig, i/k/klow, i/k/khighi/k/ar mirror i/k/asig, i/k/klow, i/k/khighi/k/ar limit i/k/asig, i/k/klow, i/k/khighSignal Modifiers: Delayar delayr idlt[, iskip]delayw asigar delay asig, idlt[, iskip]ar delay1 asig[, iskip]ar deltap kdltar deltapi xdltar deltapn xnumsampsar deltap3 xdltar multitap asig, itime1, iga<strong>in</strong>1, itime2, iga<strong>in</strong>2…ar vdelay asig, adel, imaxdel[, iskip]ar vdelay3 asig, adel, imaxdel[, iskip]Signal Modifiers: Reverberationar reverb asig, krvt[, iskip]ar reverb2 asig, ktime, khdif[, iskip]ar nreverb asig, ktime, khdif[, iskip]ar comb asig, krvt, ilpt[, iskip]ar alpass asig, krvt, ilpt[, iskip]ar nestedap asig, imode, imaxdel, idel1, iga<strong>in</strong>1[, idel2, iga<strong>in</strong>2[,idel3, iga<strong>in</strong>3]]14


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Modifiers: Waveguidesar wguide1 asig, xfreq, xcutoff, kfeedbackar wguide2 asig, xfreq1, xfreq2, kcutoff1, kcutoff2, kfeedback1,kfeedback2ar streson asig, kfr, ifdbga<strong>in</strong>Signal Modfiers: Special Effectsar harmon asig, kestfrq, kmaxvar, kgenfreq1, kgenfreq2, imode,im<strong>in</strong>frq, iprdar flanger asig, adel, kfeedback[, imaxd]ar distort1 asig[, kprega<strong>in</strong>[, kpostga<strong>in</strong>[, kshape1[, kshape2]]]]ar phaser1 asig, kfreq, iord, kfeedback[, iskip]ar phaser2 asig, kfreq, kq, iord, imode, ksep, kfeedbackSignal Modifiers: Convolution and Morph<strong>in</strong>gar1[, convolve a<strong>in</strong>, ifilcod, ichannelar2[,ar3[,ar4]]]ar cross2 a<strong>in</strong>1, a<strong>in</strong>2, isize, ioverlap, iw<strong>in</strong>, kbiasSignal Modifiers: Pann<strong>in</strong>g and Spatializationa1, a2, a3, panasig, kx, ky, ifn[, imode[, ioffset]]a4a1, a2 locsig asig, kdegree, kdistance, kreverbsenda1, a2, a3, locsig asig, kdegree, kdistance, kreverbsenda4a1, a2 locsenda1, a2, a3, locsenda4a1, a2, a3, space asig, ifn, ktime, kreverbsend[, kx, ky]a4a1, a2, a3,a4spsendk1 spdist ifn, ktime[, kx, ky]aleft, hrtfer asig, kaz, kelev, “HRTFcompact”arightvbapls<strong>in</strong>it idim, ilsnum, idir1, idir2,...ar1, ar2, vbap4ar3, ar4asig, iazim, ielev, ispreadar1, ar2, vbap8ar3, ar4,asig, iazim, ielev, ispreadar5, ar6,ar7, ar8,15


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Modifiers: Pann<strong>in</strong>g and Spatialization (Cont’d)ar1, ar2,ar3, ar4,ar5, ar6,ar7, ar8,ar9, ar10,ar11, ar12,ar13, ar14,ar15, ar16ar1, ar2,ar3, ar4ar1, ar2,ar3, ar4,ar5, ar6,ar7, ar8,ar1, ar2,ar3, ar4,ar5, ar6,ar7, ar8,ar9, ar10,ar11, ar12,ar13, ar14,ar15, ar16vbap16asig, iazim, ielev, ispreadvbap4move asig, ispread, ifldnum, ifld1, ifld2, ...vbap8move asig, ispread, ifldnum, ifld1, ifld2, ...vbap16move asig, ispread, ifldnum, ifld1, ifld2, ...vbapzvbapzmove<strong>in</strong>umchnls, istartndx, asig, iazim, ielev, ispread<strong>in</strong>umchnls, istartndx, ispread, ifldnum, ifld1,ifld2,...16


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Modifiers: Sample Level Operatorskr downsamp asig[, iwlen]ar upsamp ksigar <strong>in</strong>terp ksig[, iskip]k/ar <strong>in</strong>teg k/asig[, iskip]k/ar diff k/asig[, iskip]k/ar samphold x/asig, k/xgate[, ival, ivstor]i/k/ar ntrpol i/k/asig1, i/k/asig2, i/k/kpo<strong>in</strong>t[, im<strong>in</strong>, imax]ar fold asig, k<strong>in</strong>crZak Patch Systemzak<strong>in</strong>it isizea, isizekziwisig, <strong>in</strong>dxzkwksig, kndxzawasig, kndxziwmisig, <strong>in</strong>dx[, imix]zkwmksig, kndx[, kmix]zawmasig, kndx[, kmix]ir zir <strong>in</strong>dxkr zkr kndxar zar kndxar zarg kndx, kga<strong>in</strong>kr zkmod ksig, kzkmodar zamod asig, kzamodzkclkfirst, klastzaclkfirst, klastOperations Us<strong>in</strong>g Spectral Data-Typeswsig specaddm wsig1, wsig2[, imul2]wsig specdiff wsig<strong>in</strong>wsig specscal wsig<strong>in</strong>, ifscale, ifthreshwsig spechist wsig<strong>in</strong>wsig specfilt wsig<strong>in</strong>, ifhtimkoct,kampspecptrk wsig, kvar, ilo, ihi, istrt, idbthresh, <strong>in</strong>ptls,irolloff[, iodd, iconfs, <strong>in</strong>terp, ifprd, iwtflg]ksum specsum wsig[, <strong>in</strong>terp]specdisp wsig, iprd[, iwtflg]wsig spectrum xsig, iprd, iocts, ifrqa, iq[, ihann, idbout, idsprd,ids<strong>in</strong>rs]17


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Input and Output: Inputar1ar1, ar2ar1, ar2,ar3, ar4ar1, ar2,ar3, ar4,ar5, ar6ar1, ar2,ar3, ar4,ar5, ar6,ar7, ar8ar1ar1, ar2ar1, ar2,ar3, ar4ar1[,ar2[,ar3,ar4]]ar1, ar2,ar3, ar4,ar5, ar6,ar7, ar8,ar9, ar10,ar11, ar12,ar13, ar14,ar15, ar16ar1, ar2,ar3, ar4,ar5, ar6,ar7, ar8,ar9, ar10,ar11, ar12,ar13, ar14,ar15, ar16ar17, ar18,ar19, ar20,ar21, ar22,ar23, ar24,ar25, ar26,ar27, ar28,ar29, ar30,ar31, ar32<strong>in</strong><strong>in</strong>s<strong>in</strong>q<strong>in</strong>h<strong>in</strong>osound<strong>in</strong> ifilcod[, iskptim[, iformat]]sound<strong>in</strong> ifilcod[, iskptim[, iformat]]sound<strong>in</strong> ifilcod[, iskptim[, iformat]]disk<strong>in</strong><strong>in</strong>x<strong>in</strong>32ar <strong>in</strong>ch ksig1<strong>in</strong>zifilcod, kpitch[, iskiptim[, iwraparound[, iformat]]]ksig118


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Input and Output: Outputoutouts1outs2outsoutq1outq2outq3outq4outqouthoutosoundoutsoundoutsoutxout32outcasigasigasigasig1, asig2asigasigasigasigasig1, asig2, asig3, asig4asig1, asig2, asig3, asig4, asig5, asig6asig1, asig2, asig3, asig4, asig5, asig6, asig7, asig8asig1, ifilcod[, iformat]asig1, asig2, ifilcod[, iformat] (**Not implemented***)asig1, asig2, asig3, asig4, asig5, asig6, asig7, asig8,asig10, asig11, asig12, asig13, asig14, asig15, asig16asig1, asig2, asig3, asig4, asig5, asig6, asig7, asig8,asig10, asig11, asig12, asig13, asig14, asig15, asig16,asig17, asig18, asig19, asig20, asig21, asig22, asig23,asig24, asig25, asig26, asig27, asig28, asig29, asig30,asig31, asig32asig1[, asig2,...]outch ksig1, asig1, ksig2, asig2, ...outzkisig119


<strong>Csound</strong> Quick <strong>Reference</strong>Signal Input and Output: File I/Odumpk ksig, ifilname, iformat, iprddumpk2 ksig1, ksig2, ifilname, iformat, iprddumpk3 ksig1, ksig2, ksig3, ifilname, iformat, iprddumpk4 ksig1, ksig2, ksig3, ksig4, ifilname, iformat, iprdksig readk ifilname, iformat[, ipol]kr1, kr2 readk2 ifilname, iformat[, ipol]kr1,kr2, readk3 ifilname, iformat[, ipol]kr3kr1,kr2, readk4 ifilname, iformat[, ipol]kr3,kr4fout“ifilename”, iformat, aout1[, aout2, aout3,...,aoutN]foutk “ifilename”, iformat, aout1[, aout2, aout3,...,aoutN]fouti ihandle, iformat, iflag, iout1[, iout2,iout3,....,ioutN]foutir ihandle, iformat, iflag, iout1[, iout2,out3,....,ioutN]ihandle fiopen “ifilename”,imodef<strong>in</strong>“ifilename”, iskipframes, iformat, a<strong>in</strong>1[, a<strong>in</strong>2,a<strong>in</strong>3,...,a<strong>in</strong>N]f<strong>in</strong>k“ifilename”, iskipframes, iformat, k<strong>in</strong>1[, k<strong>in</strong>2,k<strong>in</strong>3,...,k<strong>in</strong>N]f<strong>in</strong>i“ifilename”, iskipframes, iformat, <strong>in</strong>1[, <strong>in</strong>2,<strong>in</strong>3,...,<strong>in</strong>N]v<strong>in</strong>cr asig, a<strong>in</strong>crclear avar1[,avar2, avar3,…,avarN]Signal Input and Output: Sound File Queriesir filelen “ifilcod”ir filesr “ifilcod”ir filenchnls “ifilcod”ir filepeak “ifilcod”[, ichnl]Signal Input and Output: Pr<strong>in</strong>t<strong>in</strong>g and Displaypr<strong>in</strong>t iarg[, iarg, ...]display xsig, iprd[, <strong>in</strong>prds[, iwtflg]]dispfft xsig, iprd, iwsiz[, iwtyp[, idbouti[, iwtflg]]]pr<strong>in</strong>tk kval, ispace[, itime]pr<strong>in</strong>tks “txtstr<strong>in</strong>g”, itime, kval1, kval2, kval3, kval4pr<strong>in</strong>tk2 kvar[, numspaces]20


Score Syntax: Statements<strong>Csound</strong> Quick <strong>Reference</strong>f “table number” “action time” “size” “GEN rout<strong>in</strong>e” arg1[ arg2...arg...]f0 “action time” (Dummy f-table for padd<strong>in</strong>g score sections with silenceand report<strong>in</strong>g on progress of long runn<strong>in</strong>g jobs).b “base clock time” (Effective prior to score sort<strong>in</strong>g. This time base ispre-warped.)t 0 “<strong>in</strong>itial tempo” “time <strong>in</strong> beats” “tempo2”[“time <strong>in</strong> beats” “tempo3”“time <strong>in</strong>...]a 0 “beg<strong>in</strong> time advance <strong>in</strong> beats” “duration of time advance <strong>in</strong> beats”i “<strong>in</strong>strument number” “start” “duration” [p4 p5 p...]s (marks end of section and restarts score count<strong>in</strong>g from time 0)m “score location name” (marks a score section with a name)n “score location name” (named score section is re-read <strong>in</strong>to the scorefile at this location)r “<strong>in</strong>teger repeat count” “a macro name” (beg<strong>in</strong>s a new repeat<strong>in</strong>gsections)e (marks end of score - optional)Score Syntax: P-Field Substitution. (carries same p-field value from preced<strong>in</strong>g “i” statement with like<strong>in</strong>strument #)+ (determ<strong>in</strong>es current start from sum of preceed<strong>in</strong>g durations by add<strong>in</strong>gp2 + p3 from previous “i” statement. legal <strong>in</strong> p2 only.)^+x (determ<strong>in</strong>es current start of <strong>in</strong>strument from sum of preceed<strong>in</strong>g writtenevent by add<strong>in</strong>g last p2 to x. legal <strong>in</strong> p2 only.)^-x (determ<strong>in</strong>es current start of <strong>in</strong>strument from sum of preceed<strong>in</strong>g writtenevent by subtract<strong>in</strong>g x from last p2. legal <strong>in</strong> p2 only.)npx (replace with p-field(x) value from next note statement illegal <strong>in</strong> p1p2 p3.)ppx (replace with p-field(x) value from previous note statement illegal <strong>in</strong>p1 p2 p3.)< (p-field replaced by value derived from l<strong>in</strong>ear <strong>in</strong>terpolation betweenprevious and subsequent “anchor” values <strong>in</strong> same p-field. illegal <strong>in</strong> p1p2 p3)> (p-field replaced by value derived from l<strong>in</strong>ear <strong>in</strong>terpolation betweenprevious and subsequent “anchor” values <strong>in</strong> same p-field. illegal <strong>in</strong> p1p2 p3)) (p-field replaced by value derived from exponential <strong>in</strong>terpolationbetween previous and subsequent “anchor” values <strong>in</strong> same p-field.illegal <strong>in</strong> p1 p2 p3)( (p-field replaced by value derived from exponential <strong>in</strong>terpolationbetween previous and subsequent “anchor” values <strong>in</strong> same p-field.illegal <strong>in</strong> p1 p2 p3)~ (p-field replaced by value derived from random value <strong>in</strong> the rangebetween previous and subsequent “anchor” values <strong>in</strong> same p-field.illegal <strong>in</strong> p1 p2 p3)21


Score Syntax: Expressions[x+y][x-y][x*y][x/y][x%y][x^y][@x][@@x]<strong>Csound</strong> Quick <strong>Reference</strong>(add value x to value y with<strong>in</strong> a p-field. Note expressions must be <strong>in</strong>[brackets])(subtract value y from value x with<strong>in</strong> a p-field. Note expressions mustbe <strong>in</strong> [brackets])(multiply value x by value y with<strong>in</strong> a p-field. Note expressions mustbe <strong>in</strong> [brackets])(divide value x by value y with<strong>in</strong> a p-field. Note expressions must be<strong>in</strong> [brackets])(value x rema<strong>in</strong>der value y with<strong>in</strong> a p-field. Note expressions must be<strong>in</strong> [brackets])(power of value x to value y with<strong>in</strong> a p-field. Note expressions mustbe <strong>in</strong> [brackets])(next power-of-two greater than or equal to x. Note expressions mustbe <strong>in</strong> [brackets])(next power-of-two-plus-one greater than or equal to x. Noteexpressions must be <strong>in</strong> [brackets])Score Syntax: Macros#def<strong>in</strong>e NAME # replacement text ##def<strong>in</strong>e NAME(a’b’c) # replacement text #$NAME.#undef NAME#<strong>in</strong>clude “filename”22


<strong>Csound</strong> Quick <strong>Reference</strong>GEN Rout<strong>in</strong>es: S<strong>in</strong>e/Cos<strong>in</strong>e Generatorsf # time size 9 pna stra phsa pnb strb phsb …f # time size 10 str1 str2 str3 str4 …f # time size 19 pna stra phsa dcoa pnb strb phsb dcobf # time size 11 nh [lh [r]]GEN Rout<strong>in</strong>es: L<strong>in</strong>e/Exponential Segment Generatorsf # time size 5 a n1 b n2 c …f # time size 6 a n1 b n2 c n3 d …f # time size 7 a n1 b n2 c …f # time size 8 a n1 b n2 c n3 d …f # time size 25 x1 y1 x2 y2 x3 ...f # time size 27 x1 y1 x2 y2 x3 ...GEN Rout<strong>in</strong>es: File Accessf # time size 1 filcod skiptime format channelf # time size 23 “filename.txt”f # time 0 28 filcodGEN Rout<strong>in</strong>es: Numeric Value Accessf # time size 2 v1 v2 v3 …f # time size 17 x1 a x2 b x3 c …GEN Rout<strong>in</strong>es: W<strong>in</strong>dow Functionsf # time size 20 w<strong>in</strong>dow max [opt]GEN Rout<strong>in</strong>es: Random Functionsf # time size 21 type level [arg1 [arg2]]GEN Rout<strong>in</strong>es: Waveshap<strong>in</strong>gf # time size 3 xval1 xval2 c0 c1 c2 … cnf # time size 13 x<strong>in</strong>t xamp h0 h1 h2 … hnf # time size 14 x<strong>in</strong>t xamp h0 h1 h2 … hnf # time size 15 x<strong>in</strong>t xamp h0 phs0 h1 phs1 h2 phs2GEN Rout<strong>in</strong>es: Amplitude Scal<strong>in</strong>gf # time size 4 source# sourcemodef # time size 12 x<strong>in</strong>t23


<strong>Csound</strong> Quick <strong>Reference</strong>Command L<strong>in</strong>e Flags: Generic-I i-time only orch run-n no sound onto disk-i fnam sound <strong>in</strong>put filename fnam-o fnam sound output filename fnam-b N sample frames (or -kprds) per software sound I/O buffer-B N samples per hardware sound I/O buffer-A create an AIFF format output soundfile-W create a WAV format output soundfile-J create an IRCAM format output soundfile-h no header on output soundfile-c 8-bit signed_char sound samples-a alaw sound samples-8 8-bit unsigned_char sound samples-u ulaw sound samples-s short_<strong>in</strong>t sound samples-l long_<strong>in</strong>t sound samples-f float sound samples-r N orchestra srate override-k N orchestra krate override-v verbose orch translation-m N tty message level. N = Sum of: 1 = note amps, 2 = out-of-rangemsg, 4 = warn<strong>in</strong>gs-d suppress all displays-g suppress graphics, use ASCII displays-G create Postscript displays of any display-S score is <strong>in</strong> Scot format-x fnam extract from score.srt us<strong>in</strong>g extract file fnam-t N use un<strong>in</strong>terpreted beats of the score, <strong>in</strong>itially at tempo N-L dnam read L<strong>in</strong>e-oriented real-time score events from device dnam-M dnam read MIDI real-time events from device dnam-F fnam read MIDI file event stream from file fnam-P N MIDI susta<strong>in</strong> pedal threshold (N = 0 - 128)-R cont<strong>in</strong>ually rewrite header while writ<strong>in</strong>g soundfile (WAV/AIFF)-H/H1pr<strong>in</strong>t a heartbeat character at each soundfile write-H2 generates a “.” every time a buffer is written.-H3 reports the size <strong>in</strong> seconds of the output. In W<strong>in</strong>dows, writesthe <strong>in</strong>formation to the w<strong>in</strong>dow title bar.-H4 sounds a bell for every buffer of the output written.-N notify (r<strong>in</strong>g the bell) when score or MIDI file is done-T term<strong>in</strong>ate the performance when MIDI file is done-D defer GEN01 soundfile loads until performance time-z List opcodes <strong>in</strong> this version-z1 List opcodes and arguments <strong>in</strong> this version-- lognam Log all text output to lognam-j fnam Derive console messages from database fnam24


<strong>Csound</strong> Quick <strong>Reference</strong>Command L<strong>in</strong>e Flags: Utility Invocation-U snd<strong>in</strong>fo run utility program snd<strong>in</strong>fo-U hetro run utility program hetro-U lpanal run utility program lpanal-U pvanal run utility program pvanal-U cvanal run utility program cvanal-U pvlook run utility program pvlook-C use Cscore process<strong>in</strong>g of scorefileCommand L<strong>in</strong>e Flags: PC and W<strong>in</strong>dows-Specific-j num set the number of console text rows (default 25)-J num set the number of console text columns (default 80)-K num enables MIDI IN. num (optional) = MIDI IN port device id number-q num WAVE OUT device id number (use only if more WAVE devices are<strong>in</strong>stalled)-p num number of WAVE OUT buffers (default 4; max. 40)-O suppresses all console text output for better real-timeperformance-e allows any sample rate (to use only with WAVE cards support<strong>in</strong>gthis feature)-y doesn’t wait for keypress on exit-E allows graphic display for WCSHELL by Riccardo Bianch<strong>in</strong>i-Q num enable MIDI OUT. num (optional) = MIDI OUT port device id number-Y suppresses real-time WAVE OUT for better MIDI OUT tim<strong>in</strong>gperformance-* yields control to the system until audio output buffer is fullCommand L<strong>in</strong>e Flags: Mac<strong>in</strong>tosh-Specific-q sampdir set the directory for f<strong>in</strong>d<strong>in</strong>g samples-Q analdir set the directory for f<strong>in</strong>d<strong>in</strong>g analyses-X snddir set the directory for sav<strong>in</strong>g sound files-V num set screen buffer size-E num set number of graphs saved-p play on f<strong>in</strong>ish<strong>in</strong>g-e num set rescal<strong>in</strong>g factor-w set record<strong>in</strong>g of MIDI data-y num set rate for progress display-Y num set rate for profile display25


<strong>Csound</strong> Quick <strong>Reference</strong>Utilities: Analysis File Generationhetro -sr n <strong>in</strong>filename outfilename Hetrodyne analysis sample rate-c n <strong>in</strong>filename outfilename Hetrodyne analysis channel number-b n <strong>in</strong>filename outfilename Hetrodyne analysis segment beg<strong>in</strong> time-d n <strong>in</strong>filename outfilename Hetrodyne analysis segment duration-f n <strong>in</strong>filename outfilename Hetrodyne analysis beg<strong>in</strong>n<strong>in</strong>gfrequency-h n <strong>in</strong>filename outfilename Hetrodyne analysis number of partials-M n <strong>in</strong>filename outfilename Hetrodyne analysis maximum amplitude-m n <strong>in</strong>filename outfilename Hetrodyne analysis m<strong>in</strong>imum amplitude-n n <strong>in</strong>filename outfilename Hetrodyne analysis number ofbreakpo<strong>in</strong>ts-l n <strong>in</strong>filename outfilename Hetrodyne analysis use third orderlow-pass filter with f c of nlpanal -a <strong>in</strong>filename outfilename LPC analysis write filter pole<strong>in</strong>stead of coeffecients-s n <strong>in</strong>filename outfilename LPC analysis sample rate-c n <strong>in</strong>filename outfilename LPC analysis channel number-b n <strong>in</strong>filename outfilename LPC analysis segment beg<strong>in</strong> time-d n <strong>in</strong>filename outfilename LPC analysis segment duration-p n <strong>in</strong>filename outfilename LPC analysis number of poles-h n <strong>in</strong>filename outfilename LPC analysis hop size <strong>in</strong> samples-C s <strong>in</strong>filename outfilename LPC analysis text str<strong>in</strong>g for comments-P n <strong>in</strong>filename outfilename LPC analysis lowest frequency-Q n <strong>in</strong>filename outfilename LPC analysis highest frequency-v n <strong>in</strong>filename outfilename LPC analysis verbosity level ofterm<strong>in</strong>al messagespvanal -s n <strong>in</strong>filename outfilename STFT analysis sample rate-c n <strong>in</strong>filename outfilename STFT analysis channel number-b n <strong>in</strong>filename outfilename STFT analysis segment beg<strong>in</strong> time-d n <strong>in</strong>filename outfilename STFT analysis segment duration-n n <strong>in</strong>filename outfilename STFT analysis frame size-w n <strong>in</strong>filename outfilename STFT analysis w<strong>in</strong>dow overlap factor-h n <strong>in</strong>filename outfilename STFT analysis hop size <strong>in</strong> samplescvanal -s n <strong>in</strong>filename outfilename FFT analysis sample rate-c n <strong>in</strong>filename outfilename FFT analysis channel number-b n <strong>in</strong>filename outfilename FFT analysis segment beg<strong>in</strong> time-d n <strong>in</strong>filename outfilename FFT analysis segment duration26


Utilities: File Queries<strong>Csound</strong> Quick <strong>Reference</strong>snd<strong>in</strong>fo soundfilename get <strong>in</strong>fo about one or more soundfiles soundfilenamepvlook -bb n <strong>in</strong>filename STFT analysis file formatted textoutput beg<strong>in</strong>n<strong>in</strong>g b<strong>in</strong> number-eb n <strong>in</strong>filename STFT analysis file formatted textoutput end<strong>in</strong>g b<strong>in</strong> number-bf n <strong>in</strong>filename STFT analysis file formatted textoutput beg<strong>in</strong>n<strong>in</strong>g frame number-ef n <strong>in</strong>filename STFT analysis file formatted textoutput end<strong>in</strong>g frame number-i <strong>in</strong>filename STFT analysis file formatted textoutput as <strong>in</strong>tegers27


<strong>Csound</strong> Quick <strong>Reference</strong>This page <strong>in</strong>tentionally left blank.28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!