Skip to content

phasorbnk

Produce an arbitrary number of normalized moving phase values, accessible by an index.

Syntax

ares = phasorbnk(xcps, kndx, icnt [, iphs])
kres = phasorbnk(kcps, kndx, icnt [, iphs])
ares phasorbnk xcps, kndx, icnt [, iphs]
kres phasorbnk kcps, kndx, icnt [, iphs]

Initialization

icnt -- maximum number of phasors to be used.

iphs -- initial phase, expressed as a fraction of a cycle (0 to 1). A negative value skips initialization. If iphs>1, each phasor starts at a random phase.

When a negative initial phase skips initialization during a bank resize, retained phasors keep their phase. Newly added phasors start at zero. Reducing the bank count makes the removed indices unavailable, even if their storage remains allocated.

Performance

kndx -- index of the phasor to use, starting at zero.

For each independent phasor, an internal phase is successively accumulated in accordance with the kcps or xcps frequency to produce a moving phase value, normalized to lie in the range 0 <= phs < 1. Each individual phasor is accessed by index kndx.

This phasor bank can be used inside a k-rate loop to generate multiple independent voices, or together with the adsynt opcode to change parameters in the tables used by adsynt.

Each k-rate call outputs the selected phase, then advances it by kcps / kr. Calling the same index again in a loop advances that phase again. At audio rate, each sample outputs the selected phase, then advances it by xcps / sr. Other phasors keep their phase until selected.

Examples

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

Example of the phasorbnk opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac           -iadc     -d     ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o phasorbnk.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

; Initialize the global variables.
sr = 44100
ksmps = 10
nchnls = 1
0dbfs = 1

; Generate a sinewave table.
giwave ftgen 1, 0, 1024, 10, 1 

; Instrument #1
instr 1
  ; Generate 10 voices.
  icnt = 10 
  ; Empty the output buffer.
  asum = 0 
  ; Reset the loop index.
  kindex = 0 

; This loop is executed every k-cycle.
loop: 
  ; Generate non-harmonic partials.
  kcps = (kindex+1)*100+30 
  ; Get the phase for each voice.
  aphas phasorbnk kcps, kindex, icnt 
  ; Read the wave from the table.
  asig table aphas, giwave, 1 
  ; Accumulate the audio output.
  asum = asum + asig 

  ; Increment the index.
  kindex = kindex + 1

  ; Perform the loop until the index (kindex) reaches 
  ; the counter value (icnt).
  if (kindex < icnt) kgoto loop 

  out asum*0.092
endin


</CsInstruments>
<CsScore>

; Play Instrument #1 for two seconds.
i 1 0 2
e


</CsScore>
</CsoundSynthesizer>

Generate multiple voices with independent partials. This example is better with adsynt. See also the example under adsynt, for k-rate use of phasorbnk.

See also

Phasors

Credits

Author: Peter Neubäcker
Munich, Germany
August 1999

New in Csound version 3.58