User-Defined Opcode Database

FreqByCentTab

frequency calculation of a step of a scale which is defined by a list of cent values

Download UDO File

Description

frequency calculation of a step of a scale which is defined by a list of cent values

Syntax

ifreq FreqByCentTab iftcent, iref_freq, iumult, istep

Initialization

iftcent: function table with the number of cent values per unit multiplier (usually 2 = octave). the first value must be 0 and matches iref_freq, if istep == 0. the size of the table must be equal to the number of cent values in it (use -size and -2 as GEN)
iref_freq: reference frequency (= for istep == 0)
iumult: unit multiplier (2 = octave, 3 = duodecime or whatever)
istep: selected step (0 = reference frequency, 1 = one step higher, -1 = one step lower)

Code

  opcode FreqByCentTab, i, iiii
;iftcent:	function table with the number of cent values per unit multiplier (usually 2 = octave)
	;the first value must be 0 and matches iref_freq, if istep == 0
	;the size of the table must be equal to the number of cent values in it (use -size and -2 as GEN)
;iref_freq:	reference frequency (= for istep == 0)
;iumult:	unit multiplier (2 = octave, 3 = duodecime or whatever)
;istep:	selected step (0 = reference frequency, 1 = one step higher, -1 = one step lower)
iftcent, iref_freq, iumult, istep xin
itablen	=		ftlen(iftcent)
ipos 		=		floor(istep/itablen); "octave" position
ibasfreq	=		(iumult ^ ipos) * iref_freq; base freq of istep
icentindx	=		istep % itablen; position of the appropriate centvalue ...
icentindx	=		(icentindx < 0 ? (itablen + icentindx) : icentindx); ... in the table
icent		tab_i		icentindx, iftcent; get cent value
ifreq		=		ibasfreq * cent(icent); get frequency
		xout		ifreq
  endop

Examples

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
;centlist of the tuning "Werckmeister III" 1691 (after Klaus Lang, Auf Wohlklangswellen durch der Toene Meer, Graz 1999, BEM 10, p. 97)
giWerck	ftgen		0, 0, -12, -2, 0, 90, 192, 294, 390, 498, 588, 696, 792, 888, 996, 1092
  opcode FreqByCentTab, i, iiii
iftcent, iref_freq, iumult, istep xin
itablen	=		ftlen(iftcent)
ipos 		=		floor(istep/itablen); "octave" position
ibasfreq	=		(iumult ^ ipos) * iref_freq; base freq of istep
icentindx	=		istep % itablen; position of the appropriate centvalue ...
icentindx	=		(icentindx < 0 ? (itablen + icentindx) : icentindx); ... in the table
icent		tab_i		icentindx, iftcent; get cent value
ifreq		=		ibasfreq * cent(icent); get frequency
		xout		ifreq
  endop
instr 1
ifreq FreqByCentTab giWerck, 440, 2, p4
print ifreq
endin
</CsInstruments>
<CsScore>
i 1 0 0 0
i . . . 1
i . . . -1
e
</CsScore>
</CsoundSynthesizer>

Credits

joachim heintz 1/2010


Previous Home Next
PartikkelSimpA   FileToPvsBuf