Getting Started with Csound
Prev | Preface | Next

## Getting Started with Csound

### Downloading

In case you don't already have Csound (or have an older version) download the appropriate Csound version for your platform from the Github Csound Download Page. Installers for Windows have '.exe' extension and for Mac '.dmg'. If the installer's filename ends in '-d' it means the installer has been built with double precision (64-bit) which provides higher quality output than the ordinary float precision (32-bit). The float versions provide quicker output, which may be important if you're using Csound in a real-time setting. You can also download the sources and build them, but this requires more expertise (See the section Building Csound).

It may also be useful to download the most recent version of this manual, which you will also find there.

### Running

Csound can be run in different ways. Since Csound is a command line program (DOS in Windows terms), just clicking on the csound executable will have no effect. Csound must be called either from the computer's command line or from a front end. To use Csound from the command line, you must open a Terminal (Command Prompt or DOS Prompt on Windows, or Terminal on MacOS). Using Csound from the command line can be difficult if you've never used a terminal, so you may want to try to use one of the front ends, either QuteCsound, which is included with the latest distributions, or another front end. A front end is a window-based (not necessarily Windows-based) program that assists running Csound. Most front ends include text editors with which you can edit csound files, and many include other useful features.

Whether being run from a front end or being executed from the command line, Csound needs two things:

- A Csound file ('.csd' or possibly an '.orc' and a '.sco' file)
- A list of command line flags (or configuration options) that configure execution. They determine things like output filename and format, whether real-time audio and MIDI are enabled, which audio output to use for real-time audio, the buffer size, the types of messages printed, etc. These options can be included in the '.csd' file itself, so for the examples included in this manual you shouldn't need to worry about them. Front end programs often have dialog boxes in which the command line flags can be set. The complete and very long list of available command flags can be found here, but you might want to have a look there later...

See the section Configuring if Csound is giving you trouble.

This documentation includes many '.csd' files which you can try out, and which should work directly from the command line or from any front end. A simple example is oscil.csd, which can be found in the examples folder of this documentation. Your front end should allow you to load the file, and the front end should have a 'play' or 'render' button that will allow you to hear the file. If you want to experiment with the file, you're well advised to use the front end's 'Save As..." command to copy it to some other directory on your hard drive, such as a 'csound scores' directory that you create.

| Note for MacCsound users
You might need to remove all the lines from the command options slot in order for the manual examples to work.

You can also try the manual examples from the command line. To do this, navigate to the examples directory of the manual using something like this on Windows (assuming the manual is located at c:\Program Files\Csound\manual\):

    cd "c:\Program Files\Csound\doc\manual\examples"

or something like:

    cd /manualdirectory/manual/examples

for the Mac or linux Terminal. Then type:

    csound oscil.csd

The example files are configured to run in real time by default, so with this command you should hear a two-second sine wave.

### Writing your own .csd files

A .csd file looks like this (this file is oscils.csd):

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -odac    ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o oscils.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    instr 1

    iflg = p4
    asig oscils .7, 220, 0, iflg
         outs asig, asig

    endin
    </CsInstruments>
    <CsScore>

    i 1 0 2 0
    i 1 3 2 2	;double precision
    e
    </CsScore>
    </CsoundSynthesizer>

Csound's .csd files have three main sections between the <CsSynthesizer> and </CsSynthesizer> tags:

- CsOptions - Includes the Command Line flags specific to this particular file. These options can also be set using the .csound6rc file, which you can edit in a text editor, or directly in the command line. Some front ends also provide ways to specify global or local options.
- CsInstruments - Contains the instruments or processes available in the file. Instruments are defined using the instr and endin opcodes. The CsInstruments section also contains the Orchestra Header, which defines things like sample rate, the number of samples in a control period, and the number of output channels.
- CsScore - Contains the 'notes' to be played, and optionally the definition of f-tables. Notes are created using the i statement, and f-tables are created using the f statement. Several other score statements are available.

Anything after a semicolon (;) until the end of the line is a comment, and is ignored by Csound.

You can write .csd files in any plain text editor, such as Notepad or Textedit. If you use a word processor (not recommended), be sure to save the file as plain text (not rich text). Many front ends include advanced editing capabilities, such as syntax highlighting and auto-completion of code.

You can find an in-depth tutorial on getting started with Csound written by Michael Gogins here.

Prev | Up | Next
Copyright Notice | Home | What's new in Csound 6.15.0