Skip to content

cps2deg

Returns the nearest scale index to the value given in cps pitch.

Syntax

i/kscaledegree, i/kerror cps2deg icps [,iscalefn]

Usage

When given a cps pitch value, cps2deg returns the nearest scale degree, and an 'error' value. The scale degree is suitable for use in the csound opcode cpstun, or the cslc UDO cpstun3. The error value measures the deviation between the returned scale degree, and the nearest neighbouring note in the scale. Can be positive or negative.


Outputs and Arguments

i/kscaledegree -- The scale degree index into the scale

i/kerror -- Deviation amount to the next nearest note in the scale.

icps -- cps pitch input

iscalefn (optional, default=gi_CurrentScale) -- the table number to retrieve the scale degree from.

Example

cps2deg.orc

nextrh
instr Sound101
  ;; Audio source
  kfreq linseg p5, p3*0.1, p5 + (p5*0.4),p3*0.9,p5
  asource = wgflute(p4, kfreq, 0.95, 0.1, 0.1, 0.1, -1, 0.05,-1,400)
 ;; a glissando-ing flute

  acps, alock plltrack asource, 0.9
 ;; track the pitch

  kcps = k(acps)
  kscalepit cps2deg kcps
 ;; convert that pitch to scale degree indices in gi_CurrentScale

  ktrig init 1
  asound1 vco2 p4, cpstun(ktrig, kscalepit, gi_CurrentScale),12; [, imode] [, kpw] [, kphs] [, inyx]
  asound2 vco2 p4, cpstun(ktrig, kscalepit+2, gi_CurrentScale),12; [, imode] [, kpw] [, kphs] [, inyx]
  asound3 vco2 p4, cpstun(ktrig, kscalepit+4, gi_CurrentScale),12; [, imode] [, kpw] [, kphs] [, inyx]
  asound = (asound1+asound2+asound3)*0.8
 ;;; give those scale degrees to a vco instrument, and add some fixed-pitch harmonies

 send asound, asource
 ;; split between left and right channels. 
endin

patchsig "Sound101", "outs"

schedule "Sound101",0,6,0.5,340