Csound relates to the various inputs and outputs of sound devices installed on your computer as a numbered list. 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:
EXAMPLE 02D01_GetDeviceList.csd
<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.1 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 one of the devices from the list above both, for input and output, you may include something like
-iadc2 -odac3
in the <CsOptions> section of you .csd file.
The RT (= real-time) 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:
-+rtaudio=mme
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.2 For instance, this statement sets the hardware buffer size to 512 samples and the software buffer size to 128 sample:
-B512 -b128
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.3 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.
When you have instruments that have substantial sections that could block out execution, for instance with code that loads buffers from files or creates big tables, you can try the option --realtime.
This option will give your audio processing the priority over other tasks to be done. It places all initialisation code on a separate thread, and does not block the audio thread. Instruments start performing only after all the initialisation is done. That can have a side-effect on scheduling if your audio input and output buffers are not small enough, because the audio processing thread may “run ahead” of the initialisation one, taking advantage of any slack in the buffering.
Given that this option is intrinsically linked to low-latency, realtime audio performance, and also to reduce the effect on scheduling these other tasks, it is recommended that small ksmps and buffer sizes, for example ksmps=16, 32, or 64, -b32 or 64, and -B256 or 512.
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, 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!
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.
EXAMPLE 02D02_LiveInput.csd
<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 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 kModFreq = kModFreq+600 aMod poscil 1, kModFreq ;modulator signal aRM = aIn * aMod ;ring modulation outch 1, aRM, 2, aRM ;output to channel 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 CsoundQt, you can find several examples in Examples -> Getting Started -> Realtime Interaction.
There has been error in communication with Booktype server. Not sure right now where is the problem.
You should refresh this page.