Software stuff you only need to learn once

1) Getting set up:

Create a directory in your main unix directory called cos325. (To help you out with debugging etc. you may want to change permissions there so that others can read its contents. This is up to you. Some folks like their privacy... 'chmod 755 cs325' will do the trick. You will also have to 'chmod 755 ~ ' in this case.)

To access all of the course tools you will need to add the following line to your .cshrc file

source /u/paul/m325/setup.cos325

You will also need to add /usr/sbin and /usr/bin/X11 to the searchpath in your .cshrc file. It will look something like

setenv PATH ${PATH}:/usr/bin:/usr/sbin:/usr/bsd:/sbin:/usr/bin/X11 etc.

To activate these features after having edited your .cshrc just say 'source .cshrc'

Next, say
source /u/paul/m325/setup.icons

You only need to do this once. It makes the icons from some applications available.

Finally, do the following

cd ~/cos325
tar xvf /u/paul/m325/einwrap.tar

This will get you a new directory and tools for the ein->cmix conversion program.

You're all set.


2) Learning how to use the tools.

Ein

Ein is the primary tool for the course. Carefully read the article we wrote about it several years ago, the article is in pdf format. (Here is a postscript version, if you prefer.) The SGI version is quite similar to the NeXT version. After you've set your paths properly, you'll only need to say 'ein' in a shell to start it up. We recommend running it from a shell window since there is frequently useful information printed there. It's probably also worth consulting the Ein help page

Cmix

Cmix is a general purpose signal processing language. It is primarily useful for making music rather than doing research. For the purpose of detailed study, Ein is more useful, but to create wads of sound, Cmix is much easier to use. In fact, Ein is really only useful to create short sounds of generally less than 10 seconds. To facilitate a connection between these two programs, however, we have written an 'Ein to Cmix wrapper'. That is, you can create an Ein program, and simply plug it into Cmix in a few steps, so that you can make music with it rather than just a few short notes.

Here is how it works.

1) create and run an Ein script in Ein.

2) cd ~/cos325/einwrap

3) say 'getnexty' This simply copies the C code generated by Ein from /tmp to this directory, renames the file nexty.c and makes a minor adjustment.

4) say 'makeit somenameyouchoose' This compiles and links the Ein script with Cmix.

5) You now have a Cmix binary called 'somenameyouchoose' which will execute this Ein script in Cmix. To run Cmix, however, you need a set of Cmix commands to direct to 'somenameyouchoose'. You'll see a sample in 'einwrap.minc'. These commands are written in a language called Minc, which has C-like syntax (most of the time, it doesn't allow ++ or -- operators). Here is a quick help page on Minc.

======================einwrap.minc,sample=============================

/* make sure variables in nexty.c are static 
   make sure to use einwrap() for synthesis and 

commands are: 
einwrap(start,dur,null,gain,PP[0]-->) 
*/ 

system("F1 a.snd")          /* create a 2 channel, 44k, mono header for a soundfile 
                               of floating point samples*/ 

system("clean a.snd")       /* In case you had a previous file there, clean it out */ 

output("a.snd")             /* open the output file you just created */ 

einwrap(start=0,dur=12,0,gain=4000) /* do the synthesis starting at time 0, 
                                       for 12 seconds with a gain factor of 4000 */ 

=================================================================

(Note we're not yet dealing with programs which process an input file.)

Now just say

somenameyouchoose < einwrap.minc

Then, after that is done you can say

play a.snd

to listen to it.

Please read these few words on soundfile formats, ways to listen, and change format.

The problem now, however is that all it will play is the same thing that Ein played. We have to have some way
of resetting parameters. Given an Einscript:

y = sin(1000. * two_PI * t/sr);

for example, all we will hear is a 1000 hz sine wave. To get around this simply edit nexty.c to say

y = sin(PP[0] * two_PI * t/sr);

and rebuild the instrument with the makeit command.

You can specify up to 256 PP arguments, and they are passed, starting with the 4th argument for the einwrap();

Thus

einwrap(0,4,0,1000,440)

will create a 4 second sine of A 440.

The following Minc script, for example, will give you an outer-space wads of sound


system("F1 a.snd")  

system("clean a.snd")  

output("a.snd")  

start = 0
while(start < 10)  
     einwrap(start=start+.1,3,0,4000,random()*600+300)

the random() command returns random values between 0 and 1.


Using input soundfiles

If you are using an input soundfile in your Ein program there are only two different things you have to do.

1) In the minc script open the input soundfile with the input("soundfilename") command. Open this before you open the output soundfile.

2) use the Cmix command einwrap_in(start, dur, inskip, gain, PP[0], PP[1]...)

The commands to build and run the binary are the same.

Example:

Ein script says:

y = y + .99 * S1;
tap 1 100

after you do getnexty and makeit the following minc script will do the job (you may want to add the header creation and cleaning).

input("someinputsoundfile")

output("someoutputsoundfile")

einwrap_in(0, dur(0), 0, 1)

to read the entire input soundfile through that filter. dur(0) is a minc function which returns the duration of the input soundfile.

You can process any number of input soundfiles. Simply opening another one close close the previous one. For example:

input("someinputsoundfile")

output("someoutputsoundfile")

einwrap_in(0, dur(0), 0, 1)

input("yetanothersoundfile")

einwrap_in(2, dur(0), 0, 1)


Will add a mix of the second soundfile to the disk starting at time 2.


Pitch notation

The following information is more useful for Cmix based instruments than Ein code:

The standard pitch notation in Cmix is called 8ve.pc form. In this format the integer part denotes the octave and the fractional part the number of semitones above the octave, with .01 representing 1 semitone and .11, eleven semitones.

There is another format called 'linear octaves', which is similar, but where the fractional part represents the percentage of an octave above the pitch denoted by the integer. Thus 8.5 represents f# above middle C.

You can also specify pitch in hz.

Minc has builtin functions to convert from one of these to another

cpspch(pch) returns the hz equivalent of the 8ve.pc value, pch
cpsoct(oct) returns the hz equivalent of the linear octaves value oct
midipch(pch) and pchmidi(midi) both convert from MIDI notenumbers (with 64 as middle C) to 8ve.pch form.
You can figure out what pchcps(), pchoct(), octpch(), will do.

Some good new.
The einwrap instrument has a feature which allows it to recognize strings representing pitches of the format

<notename><accidental><octave>

Thus f#8, denotes the f# above middle C. Notenames can be in upper or lower case, the accidental can be called #,s or S for sharp, f,F or b for flat, and if the octave is omitted 8 will be assumed. With the einwrap instrument these strings will be converted to hz.

For example,

for the nexty.c program

y = sin(PP[0] * two_PI * t/sr);

The following commands will give you a D major scale

einwrap(start=0,1,0,10000,"d8")
einwrap(start = start+1,1,0,10000,"e8")
einwrap(start = start+1,1,0,10000,"F#8")
einwrap(start = start+1,1,0,10000,"g8")
einwrap(start = start+1,1,0,10000,"a8")
einwrap(start = start+1,1,0,10000,"B8")
einwrap(start = start+1,1,0,10000,"c#9")
einwrap(start = start+1,1,0,10000,"d9")s

Realtime in Cmix

to play sounds as they are being produced you utter the following minc command before any instruments which you want to hear as they are being computed.

play_on(fno,mode,floatflag) where fno is the cmix number of the output file if mode = 0, play the output of the mix to disk (instrument output after mixed to disk) if mode = 1, play the instrument output plus disk, but don't mix instrument output to disk if mode = 2, just play the instrument output, don't mix to disk. Even though you are not writing anything to disk you need to have opened at least an empty soundfile.

floatflag is needed if the output soundfile is in floating point format to figure out how to rescale the floating point output. if floatflag < 0, consider the peak amplitude to be the current output (note the mode as well) if floatflag = 0, consider the peak amplitude to be the amplitude stored in the files header, assuming that it has been written there already. (don't use floatflag = 0 for a new file, obviously) if floatflag > 0, consider the peak amplitude to be that value.

The success of the playing depends, obviously, on the speed of the instrument. If the instrument cannot compute in realtime, it will not be able to play in real time and will stutter. If it computes in realtime or better the actual compute time will be real time, since the player will force the instrument to to wait until it requests more data. It works quite well on a Pentium machine, modulo the crummy soundcards, and pretty well on an 040, depending on the instrument.

To turn sound off simply say play_off(fno)

This is only needed for subsequent instrument calls which you don't want to hear. The Minc default is play_off() .

Please note that this is 'real-time' only in that it plays as it computes. Cmix lacks a scheduler so the only way to ever hear the total output is to play it after it is done. e.g. the following script

play_on(1,0)
someinstrument(start=0, dur=1,pitch=8.00)
someinstrument(start=0, dur=1,pitch=8.04)
someinstrument(start=0, dur=1,pitch=8.07)

will cause a c to be played for one second, then a c and and e, for one second, and then a c,e, and g for one second. (You could have placed the play_on() command in front of the third note to avoid tedium.)


Other pieces of software you should learn to use

rt: a realtime mixer. Self-documented

Mix: another realtime mixer (note the capital M). Also self-documented.

soundeditor: a basic soundeditor.