Configuring Audio & Tuning Audio Performance
Selecting Audio Devices And Drivers
Csound relates to the various inputs and outputs of sound devices installed on your computer as a numbered list. If you are using a multichannel interface then each stereo pair will most likely be assigned a different number. If you wish to send or receive audio to or from a specific audio connection you will need to know the number by which Csound knows it. If you are not sure of what that is you can trick Csound into providing you with a list of available devices by trying to run Csound using an obviously out of range device number, like this:
<CsoundSynthesizer> <CsOptions> -iadc999 -odac999 </CsOptions> <CsInstruments> ;Example by Andrés Cabrera instr 1 endin </CsInstruments> <CsScore> e </CsScore> </CsoundSynthesizer>
The input and output devices will be listed seperately. Specify your input device with the -iadc flag and the number of your input device, and your output device with the -odac flag and the number of your output device. For instance, if you select the "XYZ" device from the list above both, for input and output, you include:
in the <CsOptions> section of you .csd file.
The RT output module can be set with the -+rtaudio flag. If you don't use this flag, the PortAudio driver will be used. Other possible drivers are jack and alsa (Linux), mme (Windows) or CoreAudio (Mac). So, this sets your audio driver to mme instead of Port Audio:
Tuning Performance and Latency
Live performance and latency depend mainly on the sizes of the software and the hardware buffers. They can be set in the <CsOptions> using the -B flag for the hardware buffer, and the -b flag for the software buffer. For instance, this statement sets the hardware buffer size to 512 samples and the software buffer size to 128 sample:
The other factor which affects Csound's live performance is the ksmps value which is set in the header of the <CsInstruments> section. By this value, you define how many samples are processed every Csound control cycle.
Try your realtime performance with -B512, -b128 and ksmps=32. With a software buffer of 128 samples, a hardware buffer of 512 and a sample rate of 44100 you will have around 12ms latency, which is usable for live keyboard playing. If you have problems with either the latency or the performance, tweak the values as described here.
To define the audio hardware used for realtime performance, open the configuration dialog. In the "Run" Tab, you can choose your audio interface, and the preferred driver. You can select input and output devices from a list if you press the buttons to the right of the text boxes for input and output names. Software and hardware buffer sizes can be set at the top of this dialogue box.
Csound Can Produce Extreme Dynamic Range!
Csound can Produce Extreme Dynamic Range, so keep an eye on the level you are sending to your output. The number which describes the level of 0 dB, can be set in Csound by the 0dbfs assignment in the <CsInstruments> header. There is no limitation, if you set 0dbfs = 1 and send a value of 32000, this can damage your ears and speakers!
Using Live Audio Input And Output
To process audio from an external source (for example a microphone), use the inch opcode to access any of the inputs of your audio input device. For the output, outch gives you all necessary flexibility. The following example takes a live audio input and transforms its sound using ring modulation. The Csound Console should output five times per second the input amplitude level.
<CsoundSynthesizer> <CsOptions> ;CHANGE YOUR INPUT AND OUTPUT DEVICE NUMBER HERE IF NECESSARY! -iadc0 -odac0 -B512 -b128 </CsOptions> <CsInstruments> ;Example by Joachim Heintz sr = 44100 ;set sample rate to 44100 Hz ksmps = 32 ;number of samples per control cycle nchnls = 2 ;use two audio channels 0dbfs = 1 ;set maximum level as 1 giSine ftgen 0, 0, 2^10, 10, 1 ;table with sine wave instr 1 aIn inch 1 ;take input from channel 1 kInLev downsamp aIn ;convert audio input to control signal printk .2, abs(kInLev) ;make modulator frequency oscillate 200 to 1000 Hz kModFreq poscil 400, 1/2, giSine kModFreq = kModFreq+600 aMod poscil 1, kModFreq, giSine ;modulator signal aRM = aIn * aMod ;ring modulation outch 1, aRM, 2, aRM ;output tochannel 1 and 2 endin </CsInstruments> <CsScore> i 1 0 3600 </CsScore> </CsoundSynthesizer>
Live Audio is frequently used with live devices like widgets or MIDI. In QuteCsound, you can find several examples in Examples -> Getting Started -> Realtime Interaction.