CsoundMax

Designing A Real-Time Csound Interface in Max/MSP

Joo Won Park
Printer friendly

Introduction

In November of 2001, Matt Ingalls released the csound~ "external" for Max/MSP. Hearing my first Csound piece rendered from within Max program was a dream come true. After some preliminary experiments, it seemed to me that the next logical step was to try and exploit the strength, power, and uniqueness of both Csound and Max by building a bridge between them.

CsoundMax started as a stand-alone Graphical User Interface which featured real-time versions of the Chapter 1 instruments from The Csound Book. As the system expanded, and more features and instruments were added, the program grew into a general graphical front-end for virtually any Csound orchestra. My goal was to make a reliable stand-alone system that could be used for education, performance, and sound design. It was also my hope that CsoundMax would attract new Csounders who were more comfortable with commercial software synthesizers and commercial music software.

In this article, I will share some of my experience with real-time Csound; show how Max can boost Csound's potentials; speak about interface design; and most importantly, show you how to adapt your existing .orc/.sco files into real-time .csd files for CsoundMax. As a Mac user, CsoundMax really changed the way I work with Csound. I hope to show you the new way to using Csound, now that it has become a part of Max/MSP.


CsoundMax is a free stand-alone program that will run on any OS 9 Macintosh. You do not need a copy of Max/MSP to use the program. The application and its source are downloadable at http://csounds.com/csoundmax

 


Fig. 1: The CsoundMax GUI


I. Goal


CsoundMax is an intuitive real-time performance and learning/teaching environment. To my surprise, improvising with even the simplest instruments can result in complex textures and sounds (simpleinst.mp3). To fine-tune timbres, one does not need to spend hours rendering the same orchestra again and again. In real-time, one can find "sweet spots" by "tweaking the knobs" (sweetspot.mp3). Thus, interactive sound design with Csound can literally take center stage. At last, with CsoundMax, I can "perform" my Csound instruments from my laptop.


From an educational standpoint, it was important to me that the system be backward compatible: CsoundMax had to render any existing non real-time instrument, but with added features and benefits. Visualization of the output and capturing the performance and audio were also considered. By implementing these Max/MSP features, one could now overdub (I mean "render-dub"), or play-along with pre-recorded samples (renderdub.mp3).

II. csound~ in Max


Max/MSP, developed by Miller Puckett and David Zicarelli, is a program optimized for realtime MIDI, synthesis, processing, and multimedia. In Max/MSP, the user creates "patches" which are similar to a Csound orchestra. These consist of a network of "objects", which correspond to our Csound opcodes. Depending on how the objects are interconnected, Max patches become algorithmic music generators or audio and video processors. And like Csound, the international users community have greatly expanded the capabilities of the program by adding their own "externals" (i.e. opcodes). In fact, Matt Ingalls' csound~ is just one such "external"- an incredibly powerful one I think, given that it brings all of Csound into any Max patch.

 


Fig. 2: Simple Csound .orc/.sco playback in a Max patch


To me, the strengths of Max/MSP are in MIDI, real-time control, and multimedia, and the strengths of Csound are in synthesis and sound processing. Thus, it was logical to use Max/MSP as the vehicle, while csound~ serves as the synthesis and processing engine (and I like to think of all the wonderful instruments in the Csound Book and Csound Catalog as the "fuel").


Furthermore, since a Max patch can be converted into a stand-alone application in just few clicks, Max is a way for non programmers to "write" software. This is just what I have done. In my case, I used Max to "compile" a user-friendly stand-alone version of Csound in which the Csound language itself is almost invisible to the user.

III. Design Features


At the outset, I asked myself "how could I exploit all the feature of the csound~ object and at the same time use terms and concepts that were familiar to Csounders?". I decided that the modular approach made the most sense. So, I divided the program into four main parts according to the function. The four main parts are Csound Performance, P-Field Control, Keyboard Control, and Audio Control.

1. Csound Performance


This section is modeled on the "classic" Mills Csound launcher for the Mac (also written by Matt Ingalls). In this section, you can choose/view/render/edit any Csound orchestra formats (i.e: .orc, .sco, and .csd), and message on/off features and real-time "clock" are added. For The Csound Book's Chapter 1 instruments, flowcharts are included in a pop-up window.


Fig. 3: Csound Performance section with flowchart and .orc/.csd window


2. P-Field Control


Six knobs and four number boxes are hard-wired to control i-values and k-values of the instruments. The k-values are also controlled by a 2D "K-Control Pad". With it, user can simultaneously modify two k-values with mouse movement (similar to the xyin opcode). Movements of the GUI controllers can be recorded and played back in the "Automation" section. Also, one can create and save their own knob setting and label as a custom presets by editing a single line in a text file (a Max coll) in my "Preset Database".


Fig. 4: P-Field Control with 2D K-Control Pad

3. Keyboard Control


Three methods of controlling frequency are grouped in this section. You can click on the notes in a graphical keyboard, play notes from the ASCII keyboard, or play from an external MIDI keyboards. MIDI controllers can be assigned to the knobs in this section too. For orchestras with more than two instruments, the graphical keyboard can be layered. I like triggering notes with my MIDI keyboard and control the timbre with "K-Control Pad" (kpad.mp3).


Fig. 5: Keyboard Control and MIDI Controller Assignment window


4. Audio Performance


This section groups together all the audio features of the program. To capture the real-time performance, an audio recorder is added. The recorded audio (or any sound files for that matter) can be played back and endlessly looped. While the audio file is playing, I can play along with another rendering instrument and, if I wish, record that, too (withsample.mp3). Viewing the audio in time domain and frequency domain can be done by selecting the Waveform window and the Spectrum window. And you can even overide the instrument's envelope by graphically designing your global envelope, which can be stored with a preset.


Fig. 6: Audio Performance, Spectrum and Wavefom window



IV. Example of writing .csd File for CsoundBook~/csound~


For users who want to convert their instruments into realtime instrument for use with CsoundMax system, here is a step-by-step example of how I converted a Chapter 1 instrument from The Csound Book into a realtime instrument. I will compare and analyze 113~.csd with the original 113.orc/sco instrument. Although there are new opcodes to learn and few rules to follow, I am confident that any Csounder can convert their own instruments without too much trouble.

Here's the original 113.orc

instr 113
k1 linen p4, p7, p3, p8
a1 oscil k1, p5, p6
out a1
endin


and the original
113.sco

;Function 1 uses the GEN10 subroutine to compute a sine wave
;Function 2 uses the GEN10 subroutine to compute the first sixteen partials of a sawtooth wave
f1 0 4096 10 1
f2 0 4096 10 1 .5 .333 .25 .2 .166 .142 .125 .111 .1 .09 .083 .076 .071 .066 .062

;ins strt dur amp frq fn atk rel
i113 0 2 10000 440 1 1 1
i113 2 .5 10000 220 1 .01 1.99
i113 5 4 10000 110 2 3.9 .1
i113 10 10 10000 138. 6 2 9 1
i113 10 10 10000 329 .6 1 5 5

Here is 113~.csd, my real-time version of 113.orc and 113.sco. The .csd format is more efficient, and was chosen over the traditional .orc/.sco approach because it meant less files and less clicking.

;Chapter 1: Instrument 113 - Oscillator With Linen Envelope
<CsoundSynthesizer>
<CsInstruments>
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2

instr 99; Timer
ktime times
outvalue 1, ktime
endin

instr 113
kvol invalue 1
idur = p3; duration
ipitch = p4; frequency
irise = p5; envelope attack value
idecay = p6; envelope release value
k1 linen 1,irise,idur,idecay
a1 oscil kvol*100*k1, ipitch, 1
outvalue 2, kvol*100
outs a1,a1
endin
</CsInstruments>
<CsScore>
f1 0 4096 10 1
f2 0 4096 10 1 .5 .333 .25 .2 .166 .142 .125 .111 .1 .09 .083 .076 .071 .066 .062
i99 0 600
</CsScore>
</CsoundSynthesizer>

I will now analyze 113~.csd with comments (in
red) to show one way of modifying non realtime Csound files and converting them into real-time performers. To make your instrument appear in the CsoundMax pop-up menu, press the "Choose Folder" button and select the folder in which your file resides.

;Chapter 1: Instrument 113
The first line of the .csd will appear in the description window of the "Csound Performance" section. Write a description of your orchestra followed by semicolon ( ; )

<CsoundSynthesizer>
Every section begins with <_____> and ends with </____> in .csd format. This marks the beginning of the Csound file.

<CsInstruments>
Beginning of orchestra section

sr = 44100
kr = 4410
ksmps = 10
nchnls = 2
nchnls MUST be set to 2.

instr 99; Timer
ktime times
outvalue 1, ktime
endin
The instr 99 is included in every .csd file to calculate the runtime. Time (in seconds) goes out to outvalue 1. outvalue sends k-rate values from the Csound orchestra to outlet in the csound~ object. CsoundMax can have a total of 6 outvalues. In my system, outvalue 1 is reserved for runtime.

instr 113
kvol invalue 1
invalue receives k-rate value from inlet of the csound~. CsoundMax has total of 5 invalues. In my system, invalue 1 is reserved for the Volume knob.

idur = p3; duration
ipitch = p4; frequency
irise = p5; envelope attack value
idecay = p6; envelope release value
CsoundMax can receive a total of 8 i-values (p-fields in the score file). Be sure not to confuse invalue with i-value: invalue is for k-values. p3 is reserved for duration, and p4 is reserved for frequency. In this example, rise time and decay time are set for p5 and p6.

k1 linen 1,irise,idur,idecay
a1 oscil kvol*100*k1, ipitch, 1
Here, kvol is multiplied by 100, because initial range of kvol is from 0 to 127. You should multiply kvol to scale your instrument 's level.

outvalue 2, kvol*100
In my system, outvalue 2 is reserved for volume. Be sure to multiply kvol in the same way as above to adjust your outputs appropriately.


outs a1,a1
endin
</CsInstruments>
End of orchestra section

<CsScore
>
Beginning of score section

f1 0 4096 10 1
i99 0 600
The score (or patch) will run for 600 seconds because i99, the timer instrument, is running from 0 to 600. If you have a global effect instrument in your orchestra (such as a global reverb), add a line to the score for your global instrument and set its duration to the desired rendering time.

</CsScore>
</CsoundSynthesizer>
end of Csound file


Conclusion


With CsoundMax, I discovered how some input and output features can totally change the way people approach and perceive Csound. I hope that this kind of graphical representation of Csound will make the Csound program more attractive and intuitive for electronic musicians, and give them a great musical and educational expreience of Csound. My plan now, is to get feedback from users, add the features they suggest, and work on a few others that I need for my music, such as multi-channel I/O via Asio, real-teim audio input processing, and algorithmic performance control of my Csound instruments.

Acknowledgments


I'd like to thank Dr. Richard Boulanger for all his direction and advice. As always, he has provided me with an opportunity to learn and grow. I also like to thank Peter Elsea and Jer Welter for letting me use their Lmult and Frame~ Max objects. This project would have been nothing if Matt Ingalls has not released csound~ object and his CsoundLib. I thank him and David Zicarelli who supports him, for providing such a great object and giving me great advice and assistance. Of course, thanks to John ffitch, all the Csounders, and Max community for all their help, suggestions, and instructions.

Links


- almost everything csound: http://csounds.com/
- almost every csound instrument: http://csounds.com/catalog/
- almost everything you need to know about csound: http://csounds.com/book/
- the csound reference manual in html format: http://csounds.com/manual/html/manual.htm

- updates of CsoundMax: http://csounds.com/csoundmax/
- updates of the csound~ object: http://music.columbia.edu/~matt/
- csound~ and CsoundLib by Matt Ingalls <matt@sonomatics.com>: http://sonomatics.com

- Official Site for Max/MSP: http://www.cycling74.com

- Lmult by Peter Elsea <elsea@cats.ucsc.edu>: http://arts.ucsc.edu/EMS/
copyright © 1995 by The Regents of the University of California
Used by permission
- frame~ by Jer Welter <mrjester@fledge.watson.org>: http://www.watson.org/~mrjester/max/
copyright © 2001, Used by permission.

- CsoundMax is written by Joo Won Park <joowon@csounds.com>: http://www.joowonhome.com
- this project is directed by Dr. Richard Boulanger <csound@mediaone.net>: http://csounds.com