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,...] perf 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 forms execute one performance pass of an instrument instance or opcode object.

For an Instr made with create, call init before perf so its initialization takes place at a known point. If the instance has not been initialized, perf attempts to initialize it on its first call using the same p-field arguments.

Do not call perf on an instance that Csound already performs through play, schedule or splice. That would perform it twice. A paused instance skips its performance code. Keep the instance in a compatible performance context, with the same sample rate as its caller.

Initialize an opcode object before calling perf if that opcode has an initialization routine. Use run to combine initialization and performance in one call, including for an Opcode[].

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.

Examples

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

create, init, pause, delete, Instrument definitions, instances and opcode objects