Csound for Linux
Csound is a music composition and sound programming language originally written by Barry Vercoe at MIT. As Nick Bailey pointed out in his October 1998 LJ article “Sculptor: A Real Time Phase Vocoder”, Barry's original MUSIC11 program was eventually ported from PDP-11 assembler to UNIX C, where it became Csound. MUSIC11 was derived from the pioneering MusicV program by Max Mathews, perhaps the most revered “Founding Father” of computer music technology.
One of MusicV's major innovations was the implementation of the unit generator, a “black box” concept that allowed great extensibility to the language. A unit generator can be a signal generator or modifier, a patching opcode, a sensor, or it can provide sound file I/O and signal display types. Csound has evolved into a notable successor to Music V, quickly accommodating new synthesis methods and DSP algorithms. It is now at the cutting edge of modern computer music software. Linux Csound has done more than simply kept pace with that evolution—it offers capabilities not found with versions available on other platforms.
In 1996, I wanted to try out the Linux OS. I knew certain software synthesis languages would run under it, and those languages were not available for DOS/Windows machines. Although Csound does indeed run under Microsoft operating systems (and many others), I was interested in seeing how well it would run under Linux. Jonathan Mohr had already added the real-time audio support for Linux, but I immediately discovered I had stumbled upon another big “DIY” (do it yourself) project. The source code available from the Bath, UK FTP site (the primary repository for the “canonical” packages) was a general UNIX package, without Linux-specific Makefiles or any other compilation amenities. Although I was a novice at both Linux and the C programming language, I jumped in and started thrashing. With good assistance from John Fitch (maintainer of the Bath site and the canonical sources) and the helpful members of the Csound mail list, I finally produced a working set of Makefiles for the entire source tree. I soon had a fast Linux Csound with full support for X displays, real-time audio output and all the current opcodes. Professor Burton Beerman kindly provided an FTP site for my Linux Csound packages on his MusTec server at Bowling Green State University, and for two years I maintained the public version on that site and at Bath.
Early in 1998, I received a message from Professor Nicola Bernardini at AIMI (Associazione di Informatica Musicale Italiana). He had thoroughly rewritten the Linux Csound Makefiles and wondered if I might be interested in adding them to the source package. His offer came at a good time, as I knew the code maintenance needed a more solid structure. Nicola's expertise was just the right factor appearing at just the right moment. His Makefiles enabled me to quickly prepare a variety of distribution packages (with or without X support, static build or shared lib, real-time audio enabled/disabled, etc.) and compile a more complete build of the source tree. Most importantly, the Makefiles created libcsound.so, a shared library which drastically reduced the binary's memory footprint (from about 450KB to less than 20KB).
Around the same time, developer Gabriel Maldonado wrote a set of MIDI output opcodes, allowing Csound to be used as a MIDI composition/control instrument. Csound already accommodated MIDI input, directly from /dev/midi or from a Type 0 Standard MIDI File (see Real-time Midi Input). Gabriel's opcodes are different: they permit exploration into MIDI composition algorithms simultaneously with the rest of Csound's real-time I/O. Hypothetically, it would be possible to have a MIDI device controlling one Csound instrument while another instrument sends its output to devaudio. Given support for a full-duplex sound card, it should even be possible to have asynchronous I/O for both the MIDI and the audio ports.
Alas, no routines had been written for Linux Csound that would accept the data from Gabriel's opcodes and send it out to the MIDI port. After studying John Fitch's code for the Windows Csound MIDI output handler, I decided to try writing the appropriate calls for Linux. I fumbled around with the OSS/Free API and eventually wrote the code needed to activate the requested MIDI interface and accept the control data sent to it from the Maldonado opcodes. Linux Csound was as up-to-date as any other version, and the necessary code for MIDI output had been trivial to write, consisting primarily of a few calls to the sound card API macros.
The next major step taken for Linux Csound was the establishment of a CVS repository. I had been complaining to Nicola that I found myself constantly checking everything coming to me in the canonical UNIX package, when he suggested the need for a revision control system. He volunteered to set it up at AIMI and after some trial-and-error hacking, he established the system we work with today. The CVS repository maintains separate directories for the canonical sources and the Linux-specific code. In this way, we can avoid rewriting sources just for Linux and we are always able to refer back to the “untouched” originals. Anonymous access to the CVS is permitted, but submissions for changes are carefully screened by the maintainer.
Of course, a CVS development repository isn't of much use unless it has developers contributing, so a logical next step was the formation of the Csound UNIX Development group. Programmers Robin Whittle and Damien Miller joined in immediately, and Damien kindly provided a web page with all pertinent information for anyone interested in joining the group. It is worth noting that the group is for development, not just developers. We welcome anyone interested in seeing Linux Csound grow into the finest language of its kind. Programmers are certainly welcome, but so are musicians, audiophiles, DSP engineers and anyone else with an interest in Csound and its possibilities.
In October 1998, two new members made significant contributions to the group's activities. Gabriel Maldonado donated his entire source tree to the CVS repository, which enables Linux Csound to keep up with the developments for his Windows versions. (This generosity is quite typical of the Csound community. Much code sharing occurs on the Csound mail list, with new instrument designs freely offered, along with much healthy debate over various computer music issues.) The other signal addition has been Fred Floberg, whose contributions require special description.
Csound's internal support for real-time audio has been dependent on calls to the API for the OSS sound-card drivers. While certainly sufficient for casual use, many sonic notions such as full-duplex and multiplexed real-time audio I/O are not realizable by the OSS/Free driver. However, the ALSA driver does indeed support those uses; thanks to code from Fred Floberg, Linux Csound now explicitly supports the ALSA interface. (The ALSA project, led by Jaroslav Kycela, is forming a new extended sound system API compatible with OSS/Free, but permitting much more advanced uses for sound-card features not supported by OSS/Free.) Fred is currently working on expanding MIDI file support. Csound now supports only Type 0 MIDI files, but Linux Csound should soon support the Type 1 and perhaps even the Type 2 Standard MIDI File formats.
Also, thanks to Robin and Damien, the Linux Csound distribution now supports the popular RPM packaging and can be built for glibc (libc6) systems. Debian users will be pleased to note that developer G<\#252>nter Geiger has prepared a package in the DEB format. Finally, Nicola Bernardini has written a Csound orchestra (instrument design) parser, which we hope will eventually be absorbed into the package. Such a utility is most helpful to a GUI designer, which brings me to my next topic: the power of Linux Csound and X.
My Linux soundapps web page shows more than twenty entries in the “Csound Helpers” section. The brief descriptions which follow are just that—brief descriptions which in no way indicate the full power of these applications. The examples shown here are for Linux systems running X; some excellent command-line utilities exist too and are included on the Linux soundapps page for those tools. All of these utilities work with the current versions of Linux Csound (3.47 or higher).
Note that each of these applications was built using freely available tools. The GNU C and C++ compilers, Tcl/Tk, Java, LessTif and WINE are powerful allies in the advancement of Linux sound and MIDI software. Their developers are to be commended for the wonderful work they have done for the good of the Linux community.
Cecilia (by Jean Piche and Alexandre Burton at the University of Montréal) is a fully-developed Csound composition and sound-processing environment. Written entirely in Tcl/Tk, Cecilia utilizes the entire range of possibilities afforded by Linux Csound, presenting a beautiful graphic interface (customizable, of course) and a powerful composition language (Cybil). Numerous real-time controls are supported, nearly all aspects of the program are user-definable, excellent on-line help is available and the GUI fully exploits Tk in the X environment. Cecilia won first place in the awards for computer-aided composition and realization software at the 1997 Second International Music Software Competition in Bourges. (See Figure 1.)
At the other end of the scale is developer Matti Koskinen's rain, a GIF-to-Csound score converter. A Csound score is the control file for a Csound instrument, providing it with such values as event start times, durations, amplitudes and frequencies, waveform selection and so forth. Matti's utility simply takes a GIF image, applies some user-defined values and magically translates it into a Csound score. The score can then be synthesized and played from within the application, or it can be saved to disk for later processing (perhaps in Cecilia). (See Figure 2.)
Adsyn is a graphic editor for Csound “hetro” analysis data files. hetro is one of the Csound sound file utility programs and its operation is quite simple. Using a heterodyne filter bank, it analyzes a sound file and creates a data file of separated frequency and amplitude values. That data file can be read and graphically represented by Adsyn and the frequency and amplitude components can be freely altered using the mouse. Csound's resynthesis opcode (adsyn) can be called; the edited file can then be synthesized and played from within Adsyn. Professor Oyvind Hammer originally wrote Adsyn for SGI machines at NoTAM, a Norwegian center for music and acoustics research. With his good graces, I began the port to Linux. It was finished with much assistance from Nicola Bernardini. (See Figure 3.)
Ceres2 is Johnathan Lee's enhanced version of Oyvind Hammer's Ceres, described in my September 1998 LJ article “Porting SGI Audio Applications to Linux”. Johnathan greatly extended the editing capabilities of the original software engine, which essentially performs a Fast Fourier Transform (FFT) on a sound file and renders a graphic representation of its frequency content and activity. The graphic display can be edited in various ways, a large number of transforms (spectral mutations) are available, up to three graphic linear control functions may be specified and a variety of output formats are supported, including two types of Csound scores. Ceres2 also extends some of the command-line analysis variables such as FFT size, analysis window size and window overlap. The Linux port was done by me, but it was dependent on work already done on the original Ceres with great help from Richard Kent, who also supplied the invaluable tichstuff libraries which replace the SGI libs. (See Figure 4.)
The Rosegarden suite includes a MIDI sequencer, a common-practice music notation display and the very nice feature of being able to save your work as a Csound score file. Such a tool is especially helpful for users most comfortable with standard notation conventions, allowing them to compose with their familiar symbols and then easily convert their creations for use with Csound instruments. (See Figure 5.)
The Java programming language lends itself to the easy creation of platform-neutral user interfaces. Jean-Pierre Lemoine's HPKComposer is an excellent example of a “pure Java” application, running under Windows, Mac OS and UNIX variants. Preparation for Linux is straightforward, depending upon successful installation of the Java development environment (JDK) in version 1.1.6 or higher, the Swing class libraries (version 1.1 beta3) from Sun Microsystems and Csound. HPKComposer blends aspects of the CMask program with the synthesis and DSP methods of Csound: tendency masks are used to create composition algorithms, which are realized by the synthesis engines (opcodes) of Csound. VRML displays are supported, the program is user-extensible, and although Java's current sound support is limited to 8-bit 8 kHz audio, when JDK 1.2 arrives it will support 16-bit 44.1 kHz CD-quality sound. (See Figure 6.)
Russell Pinkston's PatchWork for Win95 is a graphic “patcher” for the design of Csound instruments. Although a UNIX/Linux version of this program exists (XPatchWork), it has not been maintained and is in need of some serious debugging. However, the Linux WINE Windows emulator can run the Win95 version, proving once again that Linux always finds a way. (See Figure 7.)
Developer Richard Karpen has generously shared many of his opcodes with the general Csound community, one of which is called “space”. In the Csound manual entry for space is a mention of a GUI for creating the values needed by the GEN28 stored-function table, and SoundSpace is that GUI. Written in core Java, this unique utility provides a visual interface for determining the placement and sonic trajectories of up to 8 sound files in the auditory space, with support for stereo and 4-channel output. (See Figure 8.)
What is still to come? By the time this article is published, I hope to have some more Csound/Java applications running. Developer Michael Gogins has expressed great interest in seeing his “Silence” Csound environment running under Linux Java, and the prestigious IRCAM Music and Sound Research Center announced that a Linux version of their MAX for Java will be available at the end of 1998. Who knows; maybe someday I'll get around to completing my Tcl/Tk clone of Csounder, the popular Csound “launcher” for Windows (or at least get it working better under WINE).
The most recent versions of Linux Csound (3.49.xx and up) can be built for use on the 64-bit DEC Alpha. Thanks to developer Ed Hall, Linux Csound can claim to be the first 64-bit music and sound composition language widely and freely available to the public.
Nicola Bernardini continues to improve the distribution packaging: building Linux Csound is easier than ever, thanks to his incorporation of the configure utility. Work proceeds on accommodating autoconf and automake, since it is a primary objective to use the best tools available for creating the best possible distribution.
One of the intriguing problems facing the development group is how to make Csound re-entrant, enabling a plug-in architecture for Csound. To many of us, such an undertaking would mean a complete rewrite of Csound, and who knows where that might lead—“Son of Linux Csound”, perhaps? If you would like to join a very interesting distributed development project, take a look at the links listed in Resources and feel free to join the development group mail lists.
Richard Boulanger is a professor at the Music Synthesis Department of the Berklee College of Music. In the spring of 1999, his Csound book will at last be published by MIT Press. On one of the included CDs, you will find an article (which will, of course, be out of date by then) about running Csound under Linux. Yes, it was written by me, but I don't mention it to blow my own horn. This book is a massive tome and it includes contributions from all the major (and some not-so-major) members of the international Csound community. It should inspire many new users, several of whom will discover for the first time that Csound is available on the Linux platform.
Linux Csound offers terrific possibilities for real-time computer music performance. Along with advances in real-time support, Linux Csound can be expected to stay at the cutting edge of synthesis methodologies, interface design, DSP algorithms and composition strategies. It is an ideal tool for contemporary sonic exploration and it demonstrates once again the flexibility and power of Linux, the cutting edge OS for the modern musician.
David Phillips (firstname.lastname@example.org) is a composer/performer living in Ohio. Recent computer-music activities include an ambient composition for the artist Phil Sugden, lecturing on computer-music programming languages at Bowling Green State University, and maintaining the “official” version of Csound for Linux. Dave also enjoys reading Latin poetry, practicing t'ai-chi-ch'uan, and any time spent with his lovely partner Ivy Maria.