Skip to content

perf

Execute a performance pass on an instrument or opcode.

Syntax

err:k = perf(ins:Instr[, p4:k, ...])
[var:*,... =] perf(opc:Opcode[,arg1:*,...])
kerr perf ins:Instr[, kp4, ...]
[xvar,...] init op:Opcode[,arg1:*,...]

Performance

p4, ... -- instrument parameters (k-rate, or a-rate, which is truncated to a scalar)

err -- error code (0 if successful)

arg1, ... -- opcode arguments

var,... -- opcode outputs

These three versions of perf execute a performance pass of a complete instrument or a single opcode. Some opcodes and all instruments are required to be initialised first (see init).

Optionally, parameters(pfields) are passed to an instrument perf() and are picked up at perf-time. They are normally k-sig variables but can also be a-sigs in which case the vector is truncated to the first element.

For the opcode perf(), inputs and outputs are checked and should match the opcode object signature.

The following example shows the perf opcode in the context of instrument and opcode objects,

Examples of instance and opcode perf.
<CsoundSynthesizer>
<CsOptions>
-o dac
</CsOptions>
<CsInstruments>
0dbfs = 1

opcode Osci(a:k,f:k):a
  xout oscili(a,f)
endop

instr One

 // run at i-time
  myInstr:InstrDef = create({{ out Osci(p4,p5) }})
  myInstance:Instr = create(myInstr)
  err1:i = init(myInstance)

  // env, gliss
  env:k = linen(0.5,0.1,p3,0.1)
  slid:k = expon(440, p3, 880)

  // set p5
  setp(myInstance, 5, slid)
  // run at perf-time, set p4
  err2:k = perf(myInstance,env)

  // run at deinit time
  delete(myInstance) 
  delete(myInstr)

  // schedule instr def
  schedule(Two,0,2,0.5,1000)

endin

instr Two
 obj:Opcode = create(oscili)
 sig:a = init(obj, p4, p5)
 sig:a = perf(obj, p4, p5)
   out(sig*adsr(0.1,0.1,0.5,0.1))
 event_i("e", 0, 3)
endin

schedule(One,0,1)

</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

See also

Initialization and Reinitialization