Skip to content

cpstun3, cpstun3_i

Return tuning values from scale table.

Syntax

kcps cpstun3 kindex, ktable [,kforcetrigger]
icps cpstun3_i iindex, itable
kcps = cpstun3(kindex, ktable [,kforcetrigger])
icps = cpstun3_i(iindex, itable)

Usage

cpstun3 works in similar fashion to the Csound cpstun opcode. Given an index (representing something like a pitch-class), and a function table formatted with pitch ratio's, cpstun returns the cps pitch.

cpstun3 enhances cpstun by working with fractional indices, negative indices, and non-octave scales. The fractional part is calculated as a value between neighbouring whole-integer indices.

cpstun3 evaluates every time kindex changes. The kforcetrigger argument is optional.

Note also that cpstun3 uses a different order of arguments from cpstun.


Outputs and Arguments

k/iindex -- An index of the scale. Think of this a bit like a pitch class. Can be fractional and negative.

k/itable -- Function table containing the parameters (numgrades, interval, basefreq, basekeymidi) and tuning ratios (beginning at 1, and extending to the period of the scale).

kforcetrigger (optional for cpstun3) -- when non zero triggers an evaluation.

See also cpstun and Iain McCurdy's cpstun2

Example

cpstun3.orc

cpstun3
gi_bohlenpierce ftgen 0,0,64,-2,13,3,gi_cslc_middle_c,1, 3^(1/13),3^(2/13),3^(3/13),3^(4/13),3^(5/13),3^(6/13),3^(7/13),3^(8/13),3^(9/13),3^(10/13),3^(11/13),3^(12/13),3
;; bohlen-pierce, 13ed3

scalemode gi_bohlenpierce, 0, fillarray(1,2,1,2,1,2,1,2,1) ;; let's pick 9 out of 13. 

instr Sound101

  kamp = p4
  ipitndx = p5 ;; p5 gets scale degrees.

  kpitch linseg ipitndx, p3*0.6, ipitndx, p3*0.1, floor:i(ipitndx)-2, p3*0.3, floor:i(ipitndx)-2
  ;; glissando the scale degrees

  kcps cpstun3 kpitch, gi_CurrentScale
  ;;; convert to cps pitch

  ares vco2 kamp, kcps,12
  ares declickr ares

  outs ares, ares
send ares
endin

patchsig "Sound101", "outs"

schedule "Sound101", 0, 7, 0.25, 0
schedule "Sound101", 0, 7, 0.25, 2.5
schedule "Sound101", 0, 7, 0.25, 4
;; play a chord.