Page  00000001 Using Csound as a Sound Engine for Interactive WWW Content Kenji Yasaka Keio University Computer Music Lab 5322 Endo, Fujisawa, Kanagawa, 252-0816, JAPAN 0. Abstract This paper is an overview of using Csound with the Common Gateway Interface(CGI) and Perl to build an interactive audio and sound service on the World Wide Web. CGI is used in most of the browsers, so by using Csound with CGI, it will allow most of the Internet users to be able to use interactive content built with Csound/CGI combination. 1. Introduction The WorldWide-Web has grown rapidly since the introduction of NCSA Mosaic. It has become a default interface for information on the Internet. Making interactive content on the WWW can be accomplished in many ways. Java and Shockwave are common environments for constructing Web content with sound capabilities. However, CGI is the most commonly implemented method enabling interaction between web server and client. This paper discusses using Csound as a sound engine for building interactive WWW content combined with CGI. 2. CGI and Csound Combining Csound and CGI is straight forward, due to their common way of handling data. Csound uses ASCII coded files to generate sound and CGI also uses ASCII code to move data between the client and a server based script. 2.1 CGI CGI is a method to interface external programs with HTTP or Web servers. Standard HTML files which are usually static, yet CGI provides the ability to provide dynamic information. It acts as a link between programs that reside on the server and information that a client requests. CGI passes text information that is selected or generated from HTML forms: <FORM METHOD="POST" ACTION="myname.cgi"> <INPUT TYPE="text" NAME="myname"><BR> <INPUT TYPE="submit" VALUE="Submit My Name"><BR> </FORM> This submits what the user entered in the field to CGI as an environment variable named "myname" to the server. This can be passed to a local variable and made available for processing. To implement a CGI application, any programming language that can compile a binary or execute on the Web server can be used: C, Pascal, Lisp, Shell Script, Basic, Perl, etc. But the Perl scripting language is commonly used due to its power in text processing, its ability to use system commands outside Perl, and its ease of programming. 2.2 Csound Csound handles instrument design and performance information with two formatted text files: a separate orchestra and score file.

Page  00000002 2.3 HTML Form and Perl Script It is possible to create a CGI program that converts, processes and formats variables received from a client into a Csound orchestra and score file. In this way, such a CGI becomes middle-ware that permits Csound to become an engine for building interactive sound WWW content. The following is an example of using CGI to create the score file for a Csound instrument "Toot 2"[Boulanger,1994] using the WWW. The HTML form would look like: <FORM METHOD="POST" ACTION="toot2.cgi"> <INPUT TYPE="text" NAME="start"><BR> <INPUT TYPE="text" NAME="dur"><BR> <INPUT TYPE="text" NAME="amp"><BR> <INPUT TYPE="text" NAME="pitch"><BR> <INPUT TYPE="submit" VALUE="Run Csound!"><BR> </FORM> And the server side CGI called toot2.cgi would look like: use CGI; $query = new CGI; $start = $query->param ('start'); $dur = $query->param ('dur'); $amp = $query->param('amp'); $pitch = $query->param('pitch'); open(SCORE, ">toot2.sco"); print SCORE "fl 0 4096 10 lYn"; print SCORE "il $start $dur $amp $pitchYn"; print SCORE "eYn"; close (SCORE); system("/usr/local/bin/csound -d -A -o toot2.aiff toot2.orc toot2.sco"); print $query->header(); print "<HTML><HEAD><TITLE>Csound Toot2 CGI Result</TITLE></HEAD>Yn"; print "<BODY><H3>Sound file created. Click <A HREF="toot2.aiff">here </A>to list en.<BR></H3>Yn</BODY></HTML>Yn"; This example CGI script will take values submitted by the client to local variables and then will write to a score file. After that, it launches Csound with an existing orchestra file and the generated score file, and writes out a new sound file. Finally, it creates HTML output providing a link to the sound file to the client. This perl script uses the Perl 5 CGI module called[Stein, 1998]. 2.4 DOTCOM( A WWW site called "DOTCOM" was created in 1995 using this method. This site uses a Csound score generator for percussion called BashFest[Lyon, 1995]. With BashFest, DOTCOM uses an original score generator to create bass and piano parts. All together, DOTCOM allows a user to use up to 3 parts at once. First, the user will be prompted to select several parameters, such as which instruments to use, how many bars to generate, etc. The web browser displays several rows of check boxes. For the drum part, each check box represents instruments with 16th note resolution, an individual percussive attack. For the bass and piano part, each check box represents a pitch with 16th note resolution. For drum part, it will look like: <INPUT TYPE="checkbox" NAME="snl" VALUE="1"> The name "snl" means the check box is for the first beat of the snare drum. The value "1" is the actual value submitted with "snl" when it is checked, and the score generator interprets this as an attack. If user doesn't check on "snl", then the score generator will simply put "0" in the place of "snl". <INPUT TYPE="checkbox" NAME="ccsl4" VALUE="9.01""

Page  00000003 The above example is taken from the Piano part. The name "ccsl4" stands for 14th beat note of pitch C#, which is 1 octave lower than middle "C". Csound can utilize "octave point pitch-class" encoded pitches, where the value "9.01" indicates the 2nd semitone of the 9th octave. This value will be used directly in piano part score generator. Inside the CGI script, above two events will be processed as follows: for($i=1;$i<$beats;$i++) { $sn[$i] = $query->param("sn$i"); $ccs[$i] = $query->param("ccs$i"); $tempo = $query->param('tempo'); $step = ((60.00 / $tempo) / 4.00); open(SCORE, ">$workdir/dotcom.sco"); $event = 0.00; for($k=1;$k<$beats;$k++) { print SCORE "ilYt$eventYt$stepYn" if(defined($sn[$k]); print SCORE "i2Yt$eventYt$stepYt$ccs[$k]Yn" if(defined($ccs[$k])); $event = $event + $step; close(SCORE); All the processes are not depicted in the above script, but it serves as an example of the possibilities of utilizing the Common Gateway Interface to create and control a Csound orchestra. 3. Form-based File Upload and Csound In addition to synthesizing sounds, the CGI/Csound combination can also be used to process sound files that the client may have on their local machine. This is done by using what is called "Form-based File Upload" mentioned in RFC 1867. 3.1 Form-based File Upload(RFC1867)[Nebel, Masinter, 1995] Form-based file upload is done by using the HTML form "POST" method. The form method should also use "multipart/form-data" as a MIME(Multipurpose Internet Mail Extensions) encoding type to be sent to the WWW server. To use file uploading, we need to use "file" as an <INPUT> tag type. This <INPUT> tag will allow any WWW browser that supports file upload to display a text field with a button labeled "Browse..." for selecting file to upload. Here's an example: <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="upload.cgi"> <INPUT TYPE="file" NAME="sndfile"><BR> <INPUT TYPE="submit"> </FORM> Here is an example of utilizing the Perl CGI module,, to parse the above FORM example: $file = $query->param('sndfile'); $tmpfile = tmpFileName($file); $type = $query->uploadInfo($file)->{'Content-Type'}; "$file" will have the file name denoted by the form tag: <INPUT>. Care should be taken to avoid confusion between the client's and server's respective paths. "$type" will have a MIME type code reflecting the file submitted. For example, an AIFF file will have a MIME type of "audio/aiff" and a WAV file will have "audio/wav". This type information is useful for converting sound files from one format to another. "$tmpfile" will have a full path to the temporary saved data that creates. The client can copy this file somewhere for processing, or you can try something like: open(OUTPUT, ">sounddata");

Page  00000004 while(<$file>) { print OUTPUT "$_"; } close(OUTPUT); close $file; to get the data. 3.2 WebReverb( html) WebReverb is an example of a WWW based reverberator processor built using this technique. The Csound orchestra file generation done inside CGI script will look like: instr 1 al, al soundin "/tmp/webreverb/webrev3727110224494/test.aiff" arevl reverb2 al, 4, 1 arev2 reverb2 a2, 4, 1 outs ((arevl + al) *.1), ((arev2 + a2) *.1) endin It uses the "reverb2" unit generator for reverberating the input sound file. The HTML form for WebReverb shows fields for reverb time, high frequency diffusion amount, effect balance, and file format of the result. With these parameters, the sound file and the CGI script, a WWW based reverberator processor is made possible. 4. Conclusion Using the combination of Csound and CGI will let the user access many of Csound's functions even if they are not fluent with Csound or have little knowledge of sound synthesis. WWW is a simple interface to the Internet, thus making interactive content with Csound/CGI easy to use for the client and effective for the content provider. Furthermore, when combined with an online database and adding the function to modify existing orchestra and score files saved on the WWW server, Csound and CGI will allow multi-user collaboration on the Internet. One of the relevant benefits of using computer networking is to facilitate distributed collaborative works where the participants are separated by distance. But there has not yet been a salient example due to the high bandwidth required for high-definition audio. Today, even though the bandwidth of the wide area network (WAN) is growing rapidly, it is still not suitable for sounds to be transferred in real time, synchronously, between clients. Csound/CGI are not real time nor synchronous applications, but they can be used for collaborative sound productions that don't have these requirements, such as distributed collaborative studio works. Whereas a real time synchronous work would be a live stage performance. In the future, when the networking and computing power improves enough, it will be possible to do a smooth, low latency live performance on the network. But until then, we should also try to develop a public network space, which facilitates network studio collaboration, and Csound/CGI has the capability to accomplish this goal. 5. References [Boulanger, 1994] Richard Boulanger, An Instrument Design,, 1994 [Stein, 1998] Lincoln Stein, - a Perl5 CGI Library,, 1998 [Lyon, 1995] Eric Lyon, BashFest,, 1995 [Nebel, Masinter, 1995] Emrnesto Nebel, Larry Masinter, RFC 1867, 1867.txt, 1995