cpuprc
Prev | Orchestra Opcodes and Operators | Next

## cpuprc

cpuprc — Control allocation of cpu resources on a per-instrument basis, to optimize realtime output.

## Description

Control allocation of cpu resources on a per-instrument basis, to optimize realtime output.

## Syntax

    cpuprc insnum, ipercent

    cpuprc Sinsname, ipercent

## Initialization

insnum -- instrument number or string

Sinsname -- instrument number or string

ipercent -- percent of cpu processing-time to assign. Can also be expressed as a fractional value.

## Performance

cpuprc sets the cpu processing-time percent usage of an instrument, in order to avoid buffer underrun in realtime performances, enabling a sort of polyphony theshold. The user must set ipercent value for each instrument to be activated in realtime. Assuming that the total theoretical processing time of the cpu of the computer is 100%, this percent value can only be defined empirically, because there are too many factors that contribute to limiting realtime polyphony in different computers.

For example, if ipercent is set to 5% for instrument 1, the maximum number of voices that can be allocated in realtime, is 20 (5% * 20 = 100%). If the user attempts to play a further note while the 20 previous notes are still playing, Csound inhibits the allocation of that note and will display the following warning message:

can't allocate last note because it exceeds 100% of cpu time

In order to avoid audio buffer underruns, it is suggested to set the maximum number of voices slightly lower than the real processing power of the computer. Sometimes an instrument can require more processing time than normal. If, for example, the instrument contains an oscillator which reads a table that doesn't fit in cache memory, it will be slower than normal. In addition, any program running concurrently in multitasking, can subtract processing power to varying degrees.

At the start, all instruments are set to a default value of ipercent = 0.0% (i.e. zero processing time or rather infinite cpu processing-speed). This setting is OK for deferred-time sessions.

All instances of cpuprc must be defined in the header section, not in the instrument body.

## Examples

Here is an example of the cpuprc opcode. It uses the file cpuprc.csd.

Example 137. Example of the cpuprc opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <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 cpuprc.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

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

    cpuprc 1, 2
    cpuprc 2, 30

    instr 1 ;cpu processing-time percent usage is set to 2% for each note

    asig oscil 0.2, 440, 1
         outs asig, asig

    endin

    instr 2	;cpu processing-time percent usage is set to 30% for each note
    	;so the 4 notes of the score exceeds 100% by far
    asig oscil 0.2, 440, 1
         outs asig, asig

    endin
    </CsInstruments>
    <CsScore>
    f 1 0 32768 10 1	; sine wave

    i 1 0 1
    i 1 0 1
    i 1 0 1
    i 1 0 1

    ;too many notes to process,
    ;check Csound output!
    i 2 3 1
    i 2 3 1
    i 2 3 1
    i 2 3 1
    e
    </CsScore>
    </CsoundSynthesizer>

## See Also

maxalloc, prealloc

## Credits

Author: Gabriel Maldonado
Italy
July, 1999

New in Csound version 3.57; named instruments added version 5.13

Prev | Up | Next
cpumeter | Home | cross2