The Guts of Mushroom

The Guts of Mushroom

Professor Lyon wrote Mushroom in Perl, a language developed in the late 1980s by Larry Wall, and a common choice for programmers who want to coordinate many different systems at the same time. When Lyon first became “seriously involved” with computer music in 1985, he wrote in C, but he started looking at Perl in… Read more »

Written By

NewMusicBox Staff

Professor Lyon wrote Mushroom in Perl, a language developed in the late 1980s by Larry Wall, and a common choice for programmers who want to coordinate many different systems at the same time.

When Lyon first became “seriously involved” with computer music in 1985, he wrote in C, but he started looking at Perl in 1993. “It was immediately evident that Perl could really help me do some things I was already doing with much less restraint.” Perl is an excellent language for the creation of “shell scripts,” which Lyon uses to automate his work. A shell script is a file containing a list of commands to be executed.

Back in 1985, Lyon explained, “computers were so slow that you really had to send batch jobs if you had some moderately complex idea that you wanted to hear.” A batch job is a collection of scripts sent to the CPU of the computer “to do whenever it can get around to them.” “In the past, I would often have to wait a day or two for a batch job to finish, but with today’s faster computers, the most computation-intensive jobs I run rarely require more than twenty minutes.” A key advantage to shell scripts is that they execute in the background, allowing you, the user, to do other work at the same time.

In conceptualizing how Mushroom works as a computer program, it is helpful to think of it as an overseer of many smaller programs of different “nationalities.” Mushroom itself, on the highest level, is not that hard to understand. Central to the program is the idea that all sound processes are “created equal.” In other words, on the highest level, sound processes are reduced to their most basic components: input and output sounds. This kind of “generic” implementation ensures that all sound processes are interchangeable, regardless of the input device or its encoding language.

Mushroom scripts, written in Perl, are designed to operate on any input sound in a directory. The program starts by “taking stock” of how many and what kind of processors to run on the sound. The program first looks in the current directory for preference and processor files, and creates them if they are not found. If the user has specified the number of processors to run, that number will be contained in the preference file; the default is three. The processor file contains a list of available processes.

Once the preference and processor information has been loaded, Mushroom begins to create derived sounds. First an input sound is selected. If the run is at level 0 (i.e. the sound has not yet been processed) this will always be the user-specified original sound. At any higher level, an input sound is randomly selected from available sounds at the previous level. Next, a series of processes is selected from the processor list. Finally, the processors are called using Perl functions named after the processes.

As an example, Lyon gives a process called “rev1” that adds reverberation to an input sound. The Mushroom function (in Perl) that calls “rev1” is surprisingly short:

sub rev1_mproc {
local ($insnd,$outsnd) = @_;
`rev1.pl $insnd $outsnd`;
}

Mushroom knows nothing about the Perl script “rev1.pl” except that its two parameters are “name of input sound” ($insnd) and “name of output sound” ($outsnd). The script “rev1.pl” must exist in some directory where Perl can find it. The script for “rev1,” also in Perl, is somewhat more complicated:

#!/usr/local/bin/perl
$HOME = $ENV{“HOME”};
require “$HOME/PERL/libperl.pl”;
($insnd,$outsnd,$dry,$tail,$gain) = @ARGV;
defined $outsnd || die “insnd outsnd [dry tail gain\n”;
#SET DEFAULTS IF UNDEFINED
$dry = $dry || .3;
$tail = $tail || 1.5;
$gain = $gain || 1.0;
# PATH OF THE Csound ORC
$proc = “$CSDIR/REVERB/rev1”;
$nchans = &getchans( $insnd );
if($nchans == 2 ){
$instr = “i1”;
} else {
$instr = “i2”;
}
$snddur = &getdur( $insnd );
$dur = $snddur + $tail ;
$score = $proc . “.sco”;
# CREATE Csound SCO
open( SCORE, ” target=”_blank”>$score”);
printf SCORE “$instr 0 %.5f 1 0 %.5f %.5f %.5f .01\n”,$dur, $gain, $dry, $snddur;
close( SCORE );
#RUN Csound TO GENERATE PROCESSED SOUND
`csio.pl $proc $insnd $outsnd`;

Comments in Perl (notes by the programmer that explain the program) are preceded by the “#” sign. If you look at the comments, you will notice that the script relies on other scripts and processes implemented in Csound, which is written in C, not Perl. This is nothing unusual, however. Sound processes in Mushroom can be implemented in any acoustic compiling program, driven by any language, provided that it does not require interactivity or communication through a graphic user interface. Multiple programs may even be used within a single process. “Perl brings them together,” Lyon has written, “and Mushroom harvests the results.”

The addition of sound processors to Mushroom is a relatively easy task. Most difficult is the creation of the new processing script, which requires knowledge of the acoustic compiler you are calling. (An example of this kind of script is the longer “rev1” script above). The processing script can only have two parameters: input and output sound file names. Once you have written the processing script, you add the name of that process to the processor list. Last, you add a “calling” function to Mushroom (an example of this would be the shorter “rev1” script above). The new processor would then be available to Mushroom for random insertion into a sound processing sequence.