This is part two of our CSound conversations. Here we talk to the csoundtekno
list to try and explore the basics of getting something happening in CSound.
Some parts of responses have been edited out where they didn't 
lead anywhere.

Part 1 is here.

What do we need to get together to start, in software and equipment 
(a basic setup)?

Kevin Conder:

I'd say the bare minimum would be a PC with a soundcard. You can 
either send audio output to a file or directly to your soundcard. If you
let Csound render its output to an audio-file, you can use a low-end PC.

I remember using a Pentium 75 to render a instrument that used 
granular synthesis. It would take hours (comparable to compiling the Linux 
kernel at the time.) I also remember how excited the Csound community 
became when PCs were fast enough to render moderately complex compositions 
in real-time! The real-time performances that Iain Duncan does is a 
relatively recent phenomenon.

That reminds me of my seven hour povray experience on a similar sort 
of machine.

Let's say what we want to do is a simple groove with some variations.
Do we need MIDI for this? Let's assume we don't need realtime.

Kevin Conder:
How simple are we talking here? A click track and bass-line?

That's a good enough to get most people started.
Kevin Conder:
AFAIK, Csound only supports MIDI file format 0 (or 1, if you only
use one track). I find a Linux program called Rosegarden helpful in this
regard. It has a quirky interface but it can convert a MIDI (format 0, 
IIRC) file to a Csound score. You can also input musical notation and
render it as MIDI or a Csound score.

I'm referring to Rosegarden version 4, you can download it here:

OK, then let's assume we're not going to use MIDI. I'm
assuming we're going to learn more without it but maybe MIDI
is a crucial tool in this style of thing. Is it?

Iain Duncan:
Well, not really. I mean you could make techno any number of ways with
csound. However, most people coming to csound from a more mainstream
background of using a midi sequencer and midi synthesizers aren't likely to
want to write a piece in score notatation. On the other hand, they might
well want to make a small part of a piece in score notation, render it, and
then dump it a regular multitrack project as a wave file. So it all depends
on how you plan on working. Do you want to be able to preview it in real
time or will you be happy rendering off line? Is your machine too slow, ( or
your idea too complex ) to render in real time anyway?

One big advantage of csound over PD/Max ( I believe, correct me if I'm wrong
please ) is that we can use a real time midi controlled instrument to write,
then export the midi info to a format 0 file, and then render it off line
using the midi file as a score and no real time output. That way we can
render at a stupidly high sample, control, and bit depth, and then filter
and downsample the wave file before putting it in our multitracker. This
allows far far higher precision than with real time midi, and can be used
as Istvan suggested to avoid aliasing by using say 192000 sr and
filtering it at 22K.

Right. If you have music keyboard skills then that must be the nicest way
to get note sequences recorded and there's the nice by product of what you
say above.

Maybe we can explore both MIDI and non-MIDI. What's been said implies that with
csound you can make your voices and also manufacture beats. Can we have a very
simple example of what that might look like?

Kevin Conder:
If you want *very simple* examples, then the working examples
in the Alternative Csound Reference Manual (ACRM) might be just the thing. 
You can look at the ACRM on-line here:

	You can download a copy for off-line reading here:

	I'm the maintainer of the ACRM, by the way... The ACRM covers
Csound 4.21, the latest version of Csound is 4.22. I'm working on updating
it right now.

	I'm assuming you're using Linux because that's one focus of You can get a Linux binary copy of Csound 4.21 here:

and here are a couple of Mac OS X links:
CSound  OS X GUI This appears to have CSound built in.
 CSound OSX (and the others as well) 

Kevin Conder:
	After you install Csound, here's an example command-line you can 
use to create a WAV file:
	csound -W -o mysound.wav my.orc my.sco

	This will create a WAV file called "mysound.wav" by rendering the
orchestra file "my.orc" and the score file "my.sco".

	Copy the orc+sco here for an example of a basic sine-wave oscillator:

	Here are examples of other sounds that Csound can create:
	fm bell
	fm rhodes

	Csound also has a good selection of filters:

	Is that enough to get you started?


Thanks. I'll put those examples in here later. (oscils.orc, oscils.sco)
That makes it quite plain where MIDI might or might not come into it
at a basic level.

Mstation later on:
Here are basic examples of an orchestra file and a score file. The orchestra
file describes the instruments and the score describes what they play.

/* oscils.orc */
/* Written by Kevin Conder */
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1 - a fast sine oscillator.
instr 1
  iamp = 10000
  icps = 440
  iphs = 0

  a1 oscils iamp, icps, iphs
  out a1
/* oscils.orc */

/* oscils.sco */
/* Written by Kevin Conder */
; Play Instrument #1 for 2 seconds.
i 1 0 2
/* oscils.sco */

Iain Duncan:
John, you should maybe add my really simple example of how to get midi
real time going with csoundAV, though you might want to mention that
currently csoundAV is only happy on windows, and real time midi i/o is only
currently 100% functional on CsoundAV. During the code freeze I know Richard
Dobson and Istvan Varga want to get the real time midi working properly on
other builds of csound, and Gabriel Maldonado will soon be putting out his
latest CsoundAV that will include multi-channel audio i/o on win 2K and XP
with much better stability and latency.

Here again is my example code in case you missed it....

Thanks. Yes, I did miss it.


;*** A simple midi controlled instrument to demonstrate and test midi on csound.
;*** This should work either controlled by a midi file or midi real time input


;*** You can put your flags here, or put them in the csound call

;*** Example flags for CsoundAV and Win98 with MME audio drivers,
;*** Comment these out if not using them

;*** -F chooses a midi file for input.
;*** replace my sample path with the correct one

;*** -+K chooses midi out
;*** -+q chooses MME audio out,
;*** -+X chooses DirectX audio out
;*** no number following the flag will open a window to choose device

;*** -+p chooses number of buffers, -b chooses buffer size 
;*** when using -+X, -+p has no effect as there is only one buffer
;*** if Csound clicks, raise buffers. For lower latency, lower them.

;*** -+O suppresses all csound print messages for better real time 
;*** -+* sends windows to kindergarden and teaches it to share better

;*** Sample flag lines below. Uncomment the one you want to use.

;*** MME audio out from a midi file ( no real time midi input )
;-+q -+p16 -b32  -+O -+* -F c:\csound\scale.mid

;*** DirectX audio from a midi file ( no midi input )
;-+X -b256 -+O -+* -F c:\csound\scale.mid

;*** MME audio out, real time midi input ( no midi file )
;-+K -+q -+p16 -b32  -+* -+O 

;*** Direct X audio out, ( no midi file )
;-+K -+X -b256 -+O -+*

;*** MME audio with midi file and midi input
;-+K -+q -+p16 -b32  -+* -+O -F c:\csound\scale.mid

;*** DirectX audio with midi file and midi input
;-+K -+X -b256 -+O -+* -F c:\csound\scale.mid

;*** Sample code for midi output will be added later
;*** Iain Duncan, Nov. 13, 2002.



;************* Csound Header section

sr		=	44100
kr		=	882
ksmps	=	50
nchnls	=	1

;*** Macro for readability. 
#define WAVETABLE1 # 1 #	

;*** Assign midi channel 1 to instrument 1. ( Same as default really. )
massign		1,	1

;************* Instrument 1 section.
	instr	1	

;*** Variable definitions:

;*** midi ADSR envelope values
iampatt	init		0.01		;*** attack time in sec
iampdec	init		0.1		;*** decay time in sec
iampsus	init		0.7		;*** sus level in percent of full
iamprel	init		0.5		;*** release time in seconds

;*** Midi to Csound conversion:

;*** convert midi vel to amps. ( 127 will equal 20000 amps )
iamp		ampmidi	5000		

;*** convert midi note number to cps
ipitch	cpsmidi			

;*** Synthesizer architecture:

;*** oscillate through the wavetable
asig		oscil	iamp, ipitch, $WAVETABLE1

;*** make an a-rate midi ADSR envelope
;aampenv	madsr	iampatt, iampdec, iampsus, iamprel, 0, 2	

;*** make an a-rate midi envelope. Note: "madsr" and "mxadsr" do NOT work.
aampenv	expsegr	0.0001, iampatt, 1, iampdec, iampsus, iamprel, 0.0001 

;*** apply the envelope and the amplitude value	
asigout	=		asig * aampenv

;*** output the audio signal
		out		asigout		




;*** For a midi controlled instrument the score section just holds table data
;*** If it is a real time instrument, we need to turn on csound for a while.

;*** A dummy function call is used to turn on csound for one minute.
f0	1000

;*** Create an squarish additive synthesis wavetable using Gen 10
f1	0  8192  10	1	0	.3	0	.2	0	.1	0	.05  0   .02	




For more thoughts on making music, Brian Redfern (interviewed
here some two years ago) had these ideas and maybe part 3 might follow up
on this. Another interesting aspect is realtime performance.

Brian Redfern:
Well, one thing I can think of is doing a standard 909 style drum machine
sim in csound, another would be covering building a 303 like synth, and
then another would be covering a typical synthesis, like using a phys mod
of say a flute in the context of a csound techno track.

Thanks all.

Back to top


post to Delicious Digg Reddit Facebook StumbleUpon

Recent on Mstation: music: Vivian Girls, America's Cup, music: Too Young to Fall..., music: Pains of Being Pure At Heart, Berlin Lakes, music: Atarah Valentine, Travel - Copenhagen, House in the Desert

front page / music / software / games / hardware /wetware / guides / books / art / search / travel /rss / podcasts / contact us