The Csound programming language is virtually synonymous with "computer music." Musicians all over the world have used it for more than 20 years, and it has earned the reputation of being both incredibly powerful and incredibly difficult to learn and use. In recent years, an international group of dedicated hackers, composers, sound designers, and educators has brought new life to the language, transforming it into the most full-featured and high-powered synthesis and signal-processing software available. - Learning Csound has never been easier. The language is fully documented in a 500-page reference manual and supported by an active mailing list, dozens of online tutorials, a quarterly e-zine, several textbooks, and a growing number of graphical front ends and utilities. On top of that, Csound remains absolutely free of charge (see the sidebar "Online Resources"). All the innovation and online support are attracting a new generation of innovative desktop-based electronic musicians. - I'll review some of the basics of the Csound language, then move on to more-advanced elements. Granular synthesis, one of Csound's most robust synthesis methods, will get a special focus. I'll also look at scanned synthesis, one of the newest sound-creation techniques. When all is said and done, you'll have many new uses for this powerful language and a whole new outlook on this exciting form of music making.
WHAT EXACTLY IS CSOUND?Csound is a programming language designed and optimized for sound rendering and signal processing. Written in the late '70s by Barry Vercoe of the MIT Media Lab, Csound is a direct descendant of the classic Music V language written in the late '60s by Max Mathews of Bell Labs. Today, it's available for nearly every computing platform. The language consists of more than 450 opcodes (operational codes), which are the software routines, or modules, used to build patches. In Csound, the patches are called instruments. The opcodes range in power and complexity from basic elements such as a table-lookup oscillator, linear envelope generator, and bandpass filter to the full-blown waveguide physical-modeling family. Opcodes exist for analog modeling, reading and processing samples, phase-vocoder resynthesis, FFT-based crossings, and more.
Typically, you design and play Csound instruments by creating two text files in a word processor or text editor: the orchestra file contains a description of one or more instruments, and the score file contains the notes, wavetables, samples, and any other information the instruments need. You tell Csound which score and orchestra files to use, and it renders (compiles) the resulting sound file to your hard drive. The instruments' complexity is limited only by your knowledge, interest, and need - never by Csound itself.
READY FOR LAUNCHIn its early years, Csound had a command-line interface, in which you typed the required parameters on a Unix console or personal-computer keyboard. Now, many launcher utilities produce or process a sound file and play a Csound instrument in real time. The launchers let you select the orchestra and score files using a simple graphic interface, and they generally provide menus, checkboxes, and text fields for setting and storing all the command-line options. Clicking the Render button starts the compiling process (see Fig. 1).
With some launchers, you can specify the output file's name, location, and type (AIFF or WAV at 16-, 24-, or 32-bit resolution). Many of the programs also display a graph of your waveforms and enable MIDI control or real-time audio input. You can hear the audio Csound creates directly through the sound card or create an audio file on disk.
For example, Matt Ingalls's PPCsound launcher (see Fig. 1) offers all these options and a console window for playing, pausing, or terminating the rendering. The termination function lets you evaluate your music before it has finished rendering and decide whether you want to continue or stop the rendering and edit your files. A graphic window displays oscillator waveshapes and sampled waveforms, and a list window displays the rendering's progress. The list window indicates when new instruments are allocated by showing their start times. It also displays the score's current amplitude, reports out-of-range samples, and shows other score and orchestra syntax errors. (See the sidebar "Graphical Front Ends and Utilities" for additional Csound helper applications.)
A SIMPLE OSCILLATOR/ENVELOPE INSTRUMENTA block diagram helps users visualize Csound patches by charting signal flow, parameter settings, and interconnections between opcodes. Like Csound itself, these block diagrams read from top to bottom. In Fig. 2, you see an oscillator (oscil) whose amplitude is controlled by a linear envelope generator (linen). The oscillator's frequency and wavetable are supplied in the score and are indicated in the diagram as p5 and p6 (more on this in a moment). Here's the Csound code that creates this instrument (anything after a semicolon and before a carriage return is a comment, which Csound ignores):
Notice that the code comes in two main sections. The top four lines designate various global settings such as the sample and control rates (sr and kr) and the number of audio channels (nchnls). Generally slower than the sample rate, the control rate updates control parameters that don't need the high resolution of audio samples. The information in the top four lines is included only once in the orchestra file. The instrument itself is defined in the bottom section, starting with "instr 1." Because an orchestra can contain as many distinct instruments as you want, each must have its own number.
Each opcode has a unique set of arguments, parameters the opcode requires to perform its function. In general, the syntax of a statement defining an opcode is as follows:
For example, Csound's linear ASR envelope generator, the linen opcode, has this syntax:
K/ar indicates that you can have the opcode render its output at either the control (k) or audio (ar) rate. To the right of the opcode name are the four arguments that linen requires. The first, k/xamp, includes the k/x prefix, which tells you that the amplitude can be dynamically altered by another opcode at the control or audio rate or set to a constant value. The x represents any type of input: constant, control rate, or audio rate. Using a k as well as an x is redundant, but that's what the Csound reference manual does.
The i prefix on the next three arguments - rise time, duration, and decay time - means that they must be set to constant values in the instrument definition or from the score; you cannot alter them during the course of a note.
Now look at the arguments for Csound's table-lookup oscillator, the oscil opcode:
Like linen, oscil can render its output at either the control or audio rate. Both the amplitude (k/xamp) and frequency (k/xcps) can be constant or modified by other opcodes at the control or audio rate. The wavetable that the oscillator reads (ifn) is set at initialization time and cannot change during the course of a note. The term ifn refers to the number of a function table, which Csound creates according to instructions in the score when it computes the sound. Arguments in brackets are optional. You can offset the oscillator's phase (iphs) if desired.
An opcode's arguments, or input parameters, are to the right of the opcode's name, and the routine's output, or result, is on the left. This syntax makes it easy to "patch" the output of one opcode to the input of another. In addition, opcodes can render their outputs at either the lower-resolution control rate or the sampling (audio) rate.
Furthermore, you can set and reset an instrument's parameters directly in the score by using the p prefix in the instrument design (see the previous "Example Instrument Definition" code) to refer to a specific p-field in the score file. A p-field is a column in the score containing the different parameter values for each note in the music. For example, the first column (p1) is for the instrument number, p2 the note start time, p3 the duration, and so on. The first three p-fields are standardized, but the rest can be anything you want. Following is an example of a Csound score:
In the oscil line of the "Example Instrument Definition" code, I assigned the oscillator's frequency argument to p5. This lets me set the instrument's frequency (in hertz) on a note-by-note basis in the score by simply changing the value in the fifth column of the score's note list. Similarly, because the ifn argument is assigned to p6, the sixth column in the note list controls the oscillator's waveshape for every note. Notice that columns p7 and p8 set the linen opcode's attack and release times, which can also be changed for every note.
In addition, one opcode's output can dynamically alter another opcode's input arguments during the course of a note, and this modulation can occur at the specified audio or control rate. The control rate is typically chosen because it is generally slower than the audio rate, but in some cases (such as with certain filtering or physical-modeling parameters), the audio rate is preferable. In the "Example Instrument Definition" code, the linen opcode's output (k1) is used as the oscil opcode's amplitude value.
MORPHING GRANULARAdmittedly, applying an envelope to an oscillator is not that interesting, but using envelopes to dynamically alter the parameters of Csound's grain opcode during the course of a note can produce some unique textures. (For more on granular synthesis, see "Square One: A World in a Grain of Sound" in the November 1999 issue of EM.)
A granular-synthesis instrument is diagrammed in Fig. 3. Of course, one way to control the amplitude of the final output is to modulate the grain opcode's amplitude parameter (located at the far left of the grain block in Fig. 3) with an envelope generator. In Fig. 3, however, this parameter is set to a constant value as specified in the p4 column of the score, and the output of the grain opcode is sent through a linen opcode, where it is shaped by the attack and release settings in the score. (This block diagram doesn't show all of the opcodes' parameters, which is not uncommon. Have a reference manual on hand to review an opcode's arguments.) The linen opcode's audio-rate output is labeled "a2," and the grain opcode's audio output is labeled "a1."
In this granular patch, various grain-parameter values change as the note plays because they are under the control of the line and expon envelope opcodes (two types of envelope generators). Alternatively, you can assign p-fields in the score to various parameters; for example, by assigning two p-fields to the start and end grain-density arguments, the density could change from 12,000 grains per second to 4,000 grains per second during the first note. During the next note, density might increase from 5 to 2,000 grains per second. You can also modulate the grain duration by giving different start and end values to the grain-duration argument.
By overlapping these two notes in time, you can morph from one evolving grain "cloud" to another that is quite different in shape and composition. Even the basic waveform the grain opcode uses can change for each note - the possibilities are endless. (See the sidebar "Top Six Tips" for some general suggestions for composing with Csound.)
GRANULAR MIDIThe sonic landscape of granular synthesis is relatively new, so exploring it with a real-time Csound patch should be useful. To this end, I'll convert my granular synthesizer into a MIDI instrument and replace most of the envelope generators with scaled 7-bit controllers using the midic7 opcode. This opcode lets you map an arbitrary controller number to an arbitrary working range best suited for the instrument at hand. For example, consider the following line of code:
This code maps the value of Continuous Controller 60 to the variable called kfreq (audio frequency) and multiplies the CC value by 100. An incoming value of 0 would result in an output of 0, a value of 64 would result in an output of 6400, and a value of 127 would result in an output of 12700. (Don't insert a comma within any number you use as an argument.) The code maps the controller's value into a useful frequency range.
When you start playing the instrument, what will the initial values be? Using the ctrlinit opcode, you can set the starting values of all controllers on a certain MIDI channel. The following example sets the initial value of CC 60 to 64, CC 68 to 0, and CC 72 to 127, all on channel 1 (indicated by the 1 in the first argument). You decide what your instrument does with this CC data.
Once you start playing the instrument, you can give these controllers any other value, but the instrument always starts from a preset, repeatable, and predictable value.
Now it's time to construct the real-time granular synthesizer. Here's the code:
This orchestra file has two MIDI value converters: cpsmidi (labeled "icps") converts MIDI note numbers to their equivalent in hertz, and ampmidi (iamp) maps MIDI Velocity (0-127) to linear amplitude (0 to 10000), as the grain opcode requires. CC 80 (kcps) is mapped to a range of 0 to 10000 and added to the base frequency derived from the note played on the MIDI keyboard, which gives CC 80 a large pitch-bend range. This function shows up as "icps+kcps" in the grain opcode's arguments (in the line starting with "a1"). The other four controllers in this example (CC 16, 17, 18, and 19) are also mapped to specific ranges and assigned to grain density, grain amplitude, grain pitch offset, and grain duration. They appear in the lines labeled "kdens," "kampoff," "kptchoff," and "kgdur," respectively.
One of the important considerations in this and every MIDI instrument is the linenr opcode (a2). In the past, Csound instruments always "knew" the note's duration when the instrument was initialized because every note statement included a start time (p2) and duration (p3). All other parameters in the score were up to the sound designer. But in a MIDI instrument, the duration depends on how long the key is depressed. To address this issue, Csound creators added a new class of MIDI-based opcodes that go into a release phase when the program senses a Note Off. These opcodes end with the letter r (for example, linenr, linsegr, and exponr).
This MIDI instrument's score file is also unique in that it contains no notes. Instead, a "dummy" function table (f0) causes the instrument to actively sense real-time MIDI data for a user-specified amount of time; here, I've specified 30 seconds. The first two lines in the following score are for creating the grain's waveform and amplitude envelope, respectively.
GRANULAR PROCESSINGInstead of granular synthesis, you can use the sndwarp opcode to independently time-scale and pitch-shift a sample in real time. A granular-processing instrument of this type uses the GEN01 function (Csound's table-generating functions are called GENs) to store the samples from a preexisting sound file indicated in the score. In the following instrument, CC 16 (ktwarp) time-scales the sound from 0.25 to 25 times its original length. CC 17 (kresamp) resamples the file and transposes it from 0.25 to 4 times the original pitch.
The sndwarp opcode's time-based algorithm opens a moving window into your sample file and changes the sample rate of the contents according to the ktwarp and kresamp settings. This code transforms the source in a wide range of clean, grungy, and magical ways.
In the next score, I've placed a sample's file name in quotes ("hello.aif") to read it into the GEN01 routine. As before, I've also used the dummy function table and amplitude-envelope function.
ACOUSTIC MODELINGCsound includes a large family of analysis/resynthesis opcodes and utilities. The convolve opcode provides a world of filtering, reverberation, room-simulation, and sound-morphing effects. Convolution is a generalized filtering algorithm that performs a dynamic spectral intersection between two sound files: a source file (which contains the material you wish to alter) and a filter file (which contains the impulse response of the filter).
Convolution is unique because it doesn't restrict how you define the filter's impulse response. Thus, the frequency characteristics of any sound file can filter any other sound file. You accomplish this by converting both files into the frequency domain and multiplying them together. Any frequency components they have in common will be emphasized, and any that are different will be attenuated or zeroed. If the frequency characteristics of either file change over time, as most do, the result will be a time-varying filter, or a dynamic spectral intersection between the two files. Csound's cvanal utility turns any sound file into a filter.
As an example, I'll convolve a voice with the cvanal-converted recording of a door slamming in a room. The result sounds like the voice speaking in that room. The following code shows a generic convolution orchestra with a variety of audio sources and filters, including the door slam ("door1.con") and my voice ("hellorcb.aif"):
In this convolve instrument, the diskin opcode (on the line marked "a1") reads a sound file into the orchestra from disk. The diskin opcode is disk based rather than RAM based, and it lets you transpose and reverse the direction of the file or use another Csound instrument to process the file in various ways. The strset opcode at the top of the orchestra file contains the names of the source and filter files and their associated function-table numbers. Once a file has an associated number, you can refer to the file in p-fields in the score and change it on a note-by-note basis.
In the next example score, each of the first four notes uses a different filter file (indicated in p7); among the files is the door slam (12). The source file (p6) remains the same for the first four notes; the next four notes have a second source file. You can see in the convolve instrument that p6 is assigned to the isource variable.
The convolve and cvanal opcodes can create exotic reverbs, complex resonators, and some incredible new effects. Try them with your favorite audio material.
SCANNED SYNTHESISCsound brings together the old and the new. Not only has it preserved a historical approach to computer music and retained a universal library of instruments, but it also encourages exploration of new areas. One of these new directions is scanned synthesis.
Scanned synthesis combines the power and functionality of wavetable synthesis with the timbral richness of physical modeling and waveguides. It enables you to create constantly evolving timbres using tiny wavetables. (Scanned synthesis is similar to wave sequencing in the Korg Wavestation, but it goes much further.) Unlike a traditional wavetable synthesizer, in which waveshapes are processed through filters, effects, and so on, scanned synthesis uses a physical model to generate a slowly varying waveshape that is scanned at a desired amplitude and rate. The shape of the scanned wave determines the timbre you hear, and the rate at which the wave is scanned determines the signal's pitch.
The waveshape used in scanned synthesis resides in a wavetable only 128 samples long. The wavetable can be any set of 128 individual samples, but the set based on a physical model of a vibrating string is particularly interesting. The string is modeled as a series of interconnected masses and springs. This "mass-spring" model is a very common way of looking at the physics of a string; researchers have used it for many years.
Depending on how the model's components connect with each other, you can alter the wavetable so it represents the behavior of objects other than the string. For example, you can change the string into a cylinder, torus, or sphere, and you can also modify the scanning trajectory used to derive values from these models.
Csound implements scanned synthesis as a pair of opcodes: a dynamic wavetable generator called scanu and a wavetable scanner called scans. The dynamic wavetable that scanu generates evolves at a very slow rate, typically between 0 and 15 Hz. This rate lets you modify the waveshape as it evolves; in fact, you can control every component of the model individually - a very powerful capability indeed. By altering the effect of damping forces on the string, the manner in which it the string decays, the nature of the "pluck," and so on (all parameters of the scanu opcode), you can generate a vast range of waveshapes to scan. With a powerful computer, many of the opcode's parameters are controllable in real time, giving you a very powerful virtual instrument to perform.
The scans opcode can also be modified to take many different paths through the waveform. The basic trajectory is stored in a function table, which is simply a matrix that contains the locations of the points to be scanned and defines the order in which they are scanned.
Perhaps most important, because the opcode that scans the wavetable is separate from the one that computes and updates the wavetable, it's possible to apply the scanning system to other "classic" synthesis techniques and dynamically animate them. Many of Csound's signal generators use wavetables, so they can be scanned and animated in new, vivid, and controllable ways. Except for some highly specialized software, Csound is the only way to experiment with scanned synthesis. You can find a complete online tutorial on scanned synthesis with more than 20 model instruments at www.csounds.com/ scanned.
WHY CSOUND?Csound provides every computer musician with new forms of musical expression and brings together the worlds of the composer and the sound designer. For the audio artist, Csound illuminates the underlying structure of the algorithm, the inner life of the sound. In Csound, the instrument is the synthesizer and the sound is the composition. As with any MIDI synth in your studio, you can play notes with the Csound synthesizer. In Csound, however, the note itself can be more than you've ever imagined.
Learning and using Csound has never been easier (see the sidebar "Online Resources" for a summary of online learning aids). Finally, your computer has the power to fully explore this limitless synthesis and signal-processing tool. So let your computer do some composing and start changing the way you make music. Join the international Csound community and take your music beyond MIDI, over the edge, into the ever-expanding Csound universe.
For many musicians, harnessing the strength of Csound is difficult because of its cryptic and arcane terms and syntax. As a result, many enterprising Csound users have created graphical user interfaces (GUIs) that are more informative, intuitive, and quite frankly more appropriate than the plain-vanilla Csound commands. Here's a short overview of three such interfaces.
VISORCBy David Perryhttp://cornelius.dhs.org/visorc/home.htmThis Windows GUI combines a Cycling '74Max/MSP-like graphical representation of each Csound opcode with a piano-roll score-file representation. It's easy to experiment with patches by simply "connecting" opcodes, and the powerful score editor has numerous features for rapidly generating extensive note lists. VisOrc lets you quickly toggle between text and icon views, so you can work with your files in the way most comfortable for you. It's a robust and powerful program for diving into Csound composing.
CECILIABy Alexandre Burton and Jean Pichewww.musique.umontreal.ca/Org/CompoElectro/CECCecilia is a complete Csound production environment for Linux and Power Macintosh. With the program's Grapher window, you can take full advantage of the synthesis and signal-processing power of Csound without even being aware of its existence (see Fig. A). In Cecilia, you'll find a large menu of modules, which are graphical interfaces to a huge library of incredible-sounding and extremely powerful Csound instruments.
VMCIBy Gabriel Maldonadohttp://web.tiscalinet.it/G-Maldonado/vmciplus.htmlThis virtual MIDI-controller interface is oriented toward the real-time manipulation and performance of MIDI instruments. By moving onscreen sliders, you can adjust many Csound instrument parameters in real time, and it's easy to save parameter settings, which you can recall at any time. VMCI is best used as a front end to Maldonado's fast DirectX Csound port, DirectCsound. The combination makes a powerful performance duo.
As you have probably surmised by now, you can use the Csound language in many different ways to make music. Remember this short list of ideas for various applications.
1. Synthesize textures, pads, drones, and loops and use them as audio tracks in your digital audio sequencing or mixing software.
2. Create samples, then download them to your favorite MIDI sampler. You'll amass a huge store of new source material in no time.
3. Process existing samples or audio tracks at virtually every stage of the pre- and post-production process. Use Csound on your final mix for equalization, compression, reverberation, acoustic modeling, or auditory localization.
4. Design a family of efficient MIDI instruments in Csound and play them in real time in your sessions or concerts.
5. Design MIDI instruments whose parameters are assigned to MIDI controllers and render the instruments using a Standard MIDI File containing both notes and controller data.
6. Use a Csound score file to compose an entire piece using the traditional text-based note list.
Here's a rundown of some sites that offer support for Csound activities. This list will continue to grow, so check back at the two first sites.
cSounds.com and Csound.org.The two main online Csound hubs are the commercial www.cSounds.com and the academic www.Csound.org. At cSounds.com, you'll find The Csound eZine, The Csound Online Reference Manual, The Csound Catalog with Audio, The Csound Masters (a series of Csound-based music CDs), The Elements (a series of Csound-based sampling CDs), and The Csound Sound Design & Composition contests.
At Csound.org, you'll be forwarded to The Csound FrontPage @ MIT Press, which has links to all Csound applications, sources, utilities, instruments, compositions, samples, tutorials, and people.
The mailing list and FAQ.One of the main reasons that Csound's popularity continues to grow is the wealth of information, suggestions, and solutions shared online via the Csound mailing list. I encourage you to join, introduce yourself, ask questions, make suggestions, and share your ideas. To subscribe, send an e-mail to firstname.lastname@example.org. However, before posting your first questions, check out The Csound FAQ at www.csounds.com/faq, where you might just find the answer you're looking for.
The reference manual.Csound is the ultimate educational environment for the computer musician. In the past, however, getting lost in Csound was usually par for the course. Today's Public Csound Reference Manual (www.lakewoodsound.com/csound) is a wonderfully readable and useful document, thanks to years of dedicated work by an international team led by David Boothe.
The magazine.Offering something for users at every level, the Csound Magazine (www.csounds.com/ezine) is by far the best online Csound material. It is edited and written primarily by Hans Mikelson, one of Csound's most prolific and brilliant sound designers and teachers. During the past few years, Mikelson published five issues, each containing the following tutorial columns: "Beginners," "Synthesis," "Processing," "Real-time," and "Internals." Each issue includes a feature; topics have ranged from score generation, composition, and psychoacoustics to cellular automata and ecological modeling.
Tutorials.Educators and sound designers have posted excellent tutorials online. A good place to start is my original 1989 TOOTorials (www.csounds.com/tutorials). Also, MIT Press has uploaded the first chapter of The Csound Book, (http://mitpress.mit.edu/e-books/csound/fpage/pub/csbook/Boulanger1/Boulang.html). The tutorial takes you from the basics to advanced concepts and designs. It includes more than 40 instruments and fully integrates and links with the HTML version of The Public Csound Reference Manual.
The book.MIT Press recently published The Csound Book (1996), the definitive Csound textbook, and posted several of the chapters online (www.csounds.com/book). The book is devoted exclusively to the study of computer music through Csound. More than 20 years in the making, this exhaustive guide contains 32 tutorial chapters in the printed text and 45 additional HTML chapters on the first of two CD-ROMs. All the chapters were written by the world's leading sound designers and teachers, and all contain complete working Csound instruments to illustrate the topics covered. Virtually everything is covered here: programming-language and software-synthesis basics, classic synthesis techniques, waveguides, chaos, studio effects, analog modeling, acoustical modeling, signal processing, reverberation, 3-D audio, C programming, and much more.
Instruments.Many instrument collections are posted for you to explore and modify. Among the finest online Csound libraries is a commercial set by Steven Cook (www.babcom.u-net.com/csound.html), a modeling set by Josep Comajuncosas (http://members.tripod.com/csound), and an incredible analog-emulation and studio-effects set by Hans Mikelson (www.werewolf.net/~hljmm/csound).
The Catalog with Audio. All the online collections, and hundreds more, are in The Csound Instrument Catalog with Audio (www.csounds.com/catalog). The advantage of this comprehensive collection is that all of the 2,000-plus instruments have been tested, edited, aligned, and prerendered. MP3 files of every orchestra are located alongside the text versions in this organized database. You can point and click to instantly hear a musical demo of any instrument. If something turns you on, simply click on the corresponding orchestra to launch Csound right from your browser and render an uncompressed version. The Csound Catalog with Audio is the best way to hear virtually everything that Csound is capable of doing. It also contains the most current version of the language, the first chapter of The Csound Book, The Public Csound Reference Manual, and step-by-step instructions on how to set up your computer and browser to run the program.