User-Defined Opcode Database

PfieldsToTable

Transfers score parameter fields to a function table

Download UDO File

Description

writes score parameter fields to a function table

Syntax

PfieldsToTable ift, istart, iend

Initialization

ift: function table in which the values are to be written
istart: first p-field to write
iend: last p-field to write

Code

opcode PfieldsToTable, 0, iii
;;writes score parameter fields to a function table
;ift: function table in which the values are to be written
;istart: first p-field to write
;iend: last p-field to write
ift, istart, iend xin
index		init		0
loop:
ival		=		p(istart)
		tabw_i		ival, index, ift
istart		=		istart + 1
index		=		index + 1
if istart <= iend igoto loop
endop

Examples

<CsoundSynthesizer>
<CsOptions>
-n -d -m 0
</CsOptions>
<CsInstruments>


	seed	0


opcode TabPermRand_i, 0, iiii
;;permutes the values of iTabin randomly and writes the result (optionally with printing) to iTabout
;iTabin: function table to be permuted
;iTabout: function table in which the result is written
;iprint: 1=result is printed out
;iprecision: float precision
iTabin, iTabout, iprint, iprecision	xin
itablen	=		ftlen(iTabin)
icopy		ftgentmp	0, 0, -itablen, -2, 0 
		tableicopy	icopy, iTabin

ileng		init		itablen
irndlm		init		ileng
indxerg	init		0
Sformat	sprintf	"%%.%df\t", iprecision
loop:
irand		random	0, irndlm - .0001
index		=	int(irand)
ival		tab_i	index, icopy
		tabw_i	ival, indxerg, iTabout
	korrektur:
if (index + 1 == ileng) igoto korrigiert
indxneu	=	index
indxalt	=	indxneu+1
ivalalt	tab_i	indxalt, icopy
		tabw_i	ivalalt, indxneu, icopy
index	=	index + 1
	igoto	korrektur
	korrigiert:
ileng	=	ileng - 1
irndlm	=	irndlm - 1
indxerg	=	indxerg + 1
if iprint == 1 then
		prints		Sformat, ival
endif
if (irndlm > 0) igoto loop
		prints		"%n"
endop


opcode PfieldsToTable, 0, iii
;;writes score parameter fields to a function table
;ift: function table in which the values are to be written
;istart: first p-field to write
;iend: last p-field to write
ift, istart, iend xin
index		init		0
loop:
ival		=		p(istart)
		tabw_i		ival, index, ift
istart		=		istart + 1
index		=		index + 1
if istart <= iend igoto loop
endop



instr 1
icount		=		p4; how many random permutations to be done
iprc		=		p5; precision of printing
ilast		pcount			; last p-field in this score line
itablen	=		ilast - 5; length of ftable in which p6, ... pN are written
iTab		ftgen		0, 0, -itablen, -2, 0
iRes		ftgen		0, 0, -itablen, -2, 0
		PfieldsToTable 	iTab, 6, ilast
indx		init		0
loop:
		TabPermRand_i	iTab, iRes, 1, iprc
		loop_lt	indx, 1, icount, loop
endin


</CsInstruments>
<CsScore>
;			count	prec	values
i1	0	.1	24	0	1 2 3 4 5 6 7 8 9 10 11 12
</CsScore>
</CsoundSynthesizer>

Credits

joachim heintz 2009


Previous Home Next
TabPermRand_i   PanPotStereo