CSound Tutorial: Instruments and Score Code

by Jake Hills

Csound is one of the most powerful computer programming languages for generating and processing sound. There is almost nothing in the realm of digital audio that Csound can not do. It was developed by Barry Vercoe at MIT in the mid 1980s and was based on previous work by Max Mathews called Music-N.  Csound is free and open source, and is tended to by an experienced core of programmers and musicians and is supported by a large online community. Because of that community, help is readily available for anyone who wishes to get started with audio programming. This tutorial will teach how to make sound in Csound.

Csound does not have it’s own GUI (graphical user interface).  One can not simply double click and open Csound.  The easiest way to use Csound is through what is called a front end, or an integrated development environment or IDE for short. Most installations of Csound come with an IDE called CSoundqt.  Although there other IDEs available, this program is a fine tool for working with Csound.  Upon opening Csoundqt, the user is greeted with this:

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0

</CsInstruments>
<CsScore>

</CsScore>
</CsoundSynthesizer>

Like in other programming languages, we see a bunch of opening tags, and closing tags.  At first, it can be confusing to look at something like this. Below is the same code, except with added comments which make the layout easier to understand.

<CsoundSynthesizer> ; everything under this tag, is part of the 
Csound program

<CsOptions> ; Under the CsOptions tag, we put specific options 
that we want.  We don’t need any to make sound for now.

</CsOptions> ; this is the close of the options tag

<CsInstruments> ; under this tag, we put the definitions for the 
instruments that we will make.

sr = 44100 ;Here, we set the sample rate to 44.1khz
ksmps = 128 ;Think of this as a buffer.
nchnls = 2 ;This is how many channels we produce. Leave this set 
at 2 for now.
0dbfs = 1.0 ; This is 0dB Full Scale.  When set to one, that meansmaximum amplitude for your program is 1.

; Here is where create our instrument.

</CsInstruments> ; Here is the end of the instrument tag.

<CsScore>; Here is where we tell Csound what to do with the 
instruments.

; This section is broken up into columns.  The first is tells 
csound which of the instruments to play, the second is when to 
begin, and the third is how long it lasts.  Any subsequent columnsare assigned by the programmer.

</CsScore> ; This is the end of the score section
</CsoundSynthesizer> ; This tag closes the Csound file.  Any 
information after this tag will be ignored by the compiler.

Now that we have a basic understanding of the layout of a Csound file, it is time to make a little noise.  Inside the <CsInstruments> tag, below 0dbfs = 1.0 is where we make our first instrument.  It may look something like this:

instr 1 ; This is the name of the instrument.  We just called it 
1.

aSig poscil 0.5, 440 ; Here, we use the opcode ‘poscil’ which can take two arguments, in this case amplitude (0.5) and frequency 
(440) and generates a sine wave and puts it in something called 
aSig.

outs aSig, aSig ; Here, whatever was in aSig is sent to the 
speakers using ‘outs’.

endin ; This is the end of the instrument we have created.

With our first instrument created, we now need to tell Csound what to do with it. This is done in the <CsScore> section. The first three columns here will tell Csound what is playing, when it plays, and how long it lasts.  For example:

;what when length
 i1   0    2

This code says to play an instrument called 1, which we made in the (CsInstruments> tag, beginning at time 0 for 2 beats.  By default, Csound is set at 60 beats per minute, so 2 beats equals 2 seconds for now.  Here is the completed code without comments:

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0

instr 1
aSig posil 0.5, 440
outs aSig, aSig
endin

</CsInstruments>
<CsScore>

i1 0 2

</CsScore>
</CsoundSynthesizer>

We can now run the code by pressing command (or control) + enter.  We should then hear a sine wave with a frequency of 440 hz for 2 seconds.

Csound is extremely powerful, and once mastered, it can be used to do just about anything with audio imaginable.  This tutorial covered one of the most basic skills in Csound.  One of the best resources about learning how to use csound is found on the internet at http://en.flossmanuals.net/csound/ .  A complete list of opcodes with examples can be found here: http://www.csounds.com/manual/html/ .  With these resources, a little time and effort, Csound can be a powerful tool in audio production and processing.

Advertisements

Direct String Synthesis: Practical guide for basic use of the Ebow Plus

by Jake Hills.

Many guitar effects deal with signal manipulation; that is to say the guitar, through electromagnetic inductance, creates an electrical signal which is then manipulated by an effect circuit The effect in this tutorial does not work through signal manipulation, but rather, through direct string synthesis. Ebows are one of the most widely used guitar effects and have been used in recordings in almost every genre. The ebow expands on the idea that Jimmy Page demonstrated in the late 60s and early 70s when doing guitar solos on stage with his band Led Zeppelin. During some of these solos, he abandoned the plectrum (also known as a guitar pick) and exchanged it with a cello bow. The effect was haunting and very unnatural sounding, seeming to have no attack or origin and fading away with long decay. The ebow creates a similar effect, but with more control and works on a different principle. Using a cello bow on a guitar would physically vibrate the strings in the same way it would on a cello. An ebow on the other hand, vibrates the string by vibrating the string’s magnetic field. In this way we are able to have a note swell out of seemingly nowhere and sustain for as long as the performer desires. In addition to vibrating the string at it’s fundamental frequency, there is also an option to vibrate at the frequency of the first harmonic of any given pitch which is why during the first event where the ebow is used, we can hear both the fundamental and the first harmonic of the pitch. These options open up a great new way of play guitar.

One of the greatest things about the ebow is the ease at which it is operated. To begin, ensure that there is a nine volt battery in the ebow. This can be done by carefully removing the top compartment. Once there is a battery in place, you are ready to begin. The switch on the ebow has three distinct positions. When holding the ebow in the right hand with the grooves facing the guitar body, the downward position effects the fundamental frequency. Once switched downward, a blue LED light will shine out of the base of the ebow. Move the ebow toward the strings of the guitar so that the strings rest in the grooves of the ebow. The string between the grooves will be the one that is affected. In this way, infinite sustain can be achieved for any note within the natural range of the guitar. For every fundamental note that can be sustained using the ebow, several harmonics are also available. The technique is the same, the only difference is that the switch is moved into the upward position. Here the harmonic can be changed by which way the ebow is moved along whichever string currently affected. By using the harmonics option on the ebow, notes can be generated far outside the natural range of the guitar. This is how the ebow is used. The last thing that one must know in order the ebow to be useful is this: practice is necessary when using the ebow. It is an entirely new way to playa string on a guitar and requires practice. Do not be discouraged because things are different, but rather be encouraged by the variety of sounds made possible by this effect.