User-Defined Opcode Database

# SinesToSSTI

returns a function table with one of the four standard waveforms, produced by the addition of harmonics

### Description

produces the waveforms saw (iwf=1, which is also the default), square (iwf=2), triangle (3), impulse (4) by the addition of inparts sinusoides (default = 10) and returns the result in a function table of itabsiz length (must be a power-of-2 or a power-of-2 plus 1, the default is 1024 points) with number ifno (default = 0 which means the number is given automatically)

### Syntax

iftout SinesToSSTI iwf [, inparts [, itabsiz [, ifno]]]

### Initialization

iwf - 1 = saw (default), 2 = square, 3 = triangle, 4 = impulse
inparts - number of sinusoides (default = 10)
itabsiz - length of the resulting function table (must be a power-of-2 or a power-of-2 plus 1, the default is 1024 points)
ifno - number of the function table (default = 0 which means the number is given automatically)

### Code

```  opcode SinesToSSTI, i, pooo
iwf, inparts, itabsiz, ifno xin
inparts	=		(inparts == 0 ? 10 : inparts)
itabsiz	=		(itabsiz == 0 ? 1024 : itabsiz)
iftemp		ftgen		0, 0, -(inparts * 3), -2, 0;temp ftab for writing the str-pna-phas vals
indx		=		1
loop:
if iwf == 1 then ; saw = 1, -1/2, 1/3, -1/4, ... as strength of partials
tabw_i		1/(indx % 2 == 0 ? -indx : indx), (indx-1)*3, iftemp; writes strength of partial
tabw_i		indx, (indx-1)*3+1, iftemp; writes partial number
elseif iwf == 2 then ; square = 1, 1/3, 1/5, ... for odd partials
tabw_i		1/(indx*2-1), (indx-1)*3, iftemp; writes strength of partial
tabw_i		indx*2-1, (indx-1)*3+1, iftemp; writes partial number
elseif iwf == 3 then ; triangle = 1, -1/9, 1/25, -1/49, 1/81, ... for odd partials
ieven		=		indx % 2; 0 = even index, 1 = odd index
istr		=		(ieven == 0 ? -1/(indx*2-1)^2 : 1/(indx*2-1)^2); results in 1, -1/9, 1/25, ...
tabw_i		istr, (indx-1)*3, iftemp; writes strength of partial
tabw_i		indx*2-1, (indx-1)*3+1, iftemp; writes partial number
elseif iwf == 4 then ; impulse = 1, 1, 1, ... for all partials
tabw_i		1, (indx-1)*3, iftemp; writes strength of partial (always 1)
tabw_i		indx, (indx-1)*3+1, iftemp; writes partial number
endif

loop_le	indx, 1, inparts, loop

iftout	ftgen		ifno, 0, itabsiz, 34, iftemp, inparts, 1; write table with GEN34
ftfree		iftemp, 0; remove iftemp
xout		iftout
endop```

### Examples

```<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>

opcode SinesToSSTI, i, pooo
;produces the waveforms saw (iwf=1, which is also the default), square (iwf=2), triangle (3), impulse (4) by the addition of inparts sinusoides (default = 10) and returns the result in a function table of itabsiz length (must be a power-of-2 or a power-of-2 plus 1, the default is 1024 points) with number ifno (default = 0 which means the number is given automatically)
iwf, inparts, itabsiz, ifno xin
inparts	=		(inparts == 0 ? 10 : inparts)
itabsiz	=		(itabsiz == 0 ? 1024 : itabsiz)
iftemp		ftgen		0, 0, -(inparts * 3), -2, 0;temp ftab for writing the str-pna-phas vals
indx		=		1
loop:
if iwf == 1 then ; saw = 1, -1/2, 1/3, -1/4, ... as strength of partials
tabw_i		1/(indx % 2 == 0 ? -indx : indx), (indx-1)*3, iftemp; writes strength of partial
tabw_i		indx, (indx-1)*3+1, iftemp; writes partial number
elseif iwf == 2 then ; square = 1, 1/3, 1/5, ... for odd partials
tabw_i		1/(indx*2-1), (indx-1)*3, iftemp; writes strength of partial
tabw_i		indx*2-1, (indx-1)*3+1, iftemp; writes partial number
elseif iwf == 3 then ; triangle = 1, -1/9, 1/25, -1/49, 1/81, ... for odd partials
ieven		=		indx % 2; 0 = even index, 1 = odd index
istr		=		(ieven == 0 ? -1/(indx*2-1)^2 : 1/(indx*2-1)^2); results in 1, -1/9, 1/25, ...
tabw_i		istr, (indx-1)*3, iftemp; writes strength of partial
tabw_i		indx*2-1, (indx-1)*3+1, iftemp; writes partial number
elseif iwf == 4 then ; impulse = 1, 1, 1, ... for all partials
tabw_i		1, (indx-1)*3, iftemp; writes strength of partial (always 1)
tabw_i		indx, (indx-1)*3+1, iftemp; writes partial number
endif

loop_le	indx, 1, inparts, loop

iftout	ftgen		ifno, 0, itabsiz, 34, iftemp, inparts, 1; write table with GEN34
ftfree		iftemp, 0; remove iftemp
xout		iftout
endop

instr 1
iftsw1		SinesToSSTI	1, 2, 512;saw with 2 partials and a 512 table
iftsw2		SinesToSSTI	;default = saw with 10 partials and a 1024 table
iftsw3		SinesToSSTI	1, 20, 16384;saw with 20 partials and a 16384 table
iftsq1		SinesToSSTI	2, 2, 512;square with 2 partials and a 512 table
iftsq2		SinesToSSTI	2; square with 10 partials and a 1024 table
iftsq3		SinesToSSTI	2, 20, 16384;square with 20 partials and a 16384 table
ifttr1		SinesToSSTI	3, 2, 512;triangle with 2 partials and a 512 table
ifttr2		SinesToSSTI	3; triangle with 10 partials and a 1024 table
ifttr3		SinesToSSTI	3, 20, 16384;triangle with 20 partials and a 16384 table
iftim1		SinesToSSTI	4, 2, 512, 1;impulse with 2 partials and a 512 table (no 1)
iftim2		SinesToSSTI	4; impulse with 10 partials and a 1024 table
iftim3		SinesToSSTI	4, 20, 16384, 2;impulse with 20 partials and a 16384 table (no 2)
endin

</CsInstruments>
<CsScore>
i 1 0 10
e
</CsScore>
</CsoundSynthesizer>```

### Credits

joachim heintz 2010

 Previous Home Next Baboon PartikkelSimpB