User-Defined Opcode Database

FreqByRatioTab

frequency calculation of a step of a scale which is defined by a list of proportions

Download UDO File

Description

frequency calculation of a step of a scale which is defined by a list of proportions

Syntax

ifreq FreqByRatioTab iftratio, iref_freq, iumult, istep

Initialization

iftprops: function table with the number of proportions per unit multiplier (usually 2 = octave). the first value must be 1 and matches iref_freq, if istep == 0. the size of the table must be equal to the number of proportions 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 FreqByRatioTab, i, iiii
;;
iftprops, iref_freq, iumult, istep xin
itablen	=		ftlen(iftprops)
ipos 		=		floor(istep/itablen); "octave" position
ibasfreq	=		(iumult ^ ipos) * iref_freq; base freq of istep
ipropindx	=		istep % itablen; position of the appropriate proportion ...
ipropindx	=		(ipropindx < 0 ? (itablen + ipropindx) : ipropindx); ... in the table
iprop		tab_i		ipropindx, iftprops; get proportion
ifreq		=		ibasfreq * iprop; 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. 41)
giPytha	ftgen		0, 0, -12, -2, 1, 2187/2048, 9/8, 32/27, 81/64, 4/3, 729/512, 3/2, 6561/4096, 27/16, 16/9, 243/128
  opcode FreqByRatioTab, i, iiii
iftprops, iref_freq, iumult, istep xin
itablen	=		ftlen(iftprops)
ipos 		=		floor(istep/itablen); "octave" position
ibasfreq	=		(iumult ^ ipos) * iref_freq; base freq of istep
ipropindx	=		istep % itablen; position of the appropriate proportion ...
ipropindx	=		(ipropindx < 0 ? (itablen + ipropindx) : ipropindx); ... in the table
iprop		tab_i		ipropindx, iftprops; get proportion
ifreq		=		ibasfreq * iprop; get frequency
		xout		ifreq
  endop
instr 1
ifreq FreqByRatioTab giPytha, 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
PanPotStereo   Baboon