<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>

sr = 96000
ksmps = 10
nchnls = 1
0dbfs = 1

opcode warp,0,iiiiiii
	
inumbins, iampin, ifreqin, iampout,ifreqout,iwarpfunction, icount xin

; start with an empty table
iclear 	ftgen 0, 0, inumbins, -2, 0

	tablecopy iampout, iclear
	tablecopy ifreqout, iclear
;perform a do-while loop cycling through the table
;copying data from original index to new index

kindex = 0 
loop: 
;read the warp or remapping function
kwarp		table   kindex, iwarpfunction
;read original data from original index points
kAmp		table   kindex, iampin	
kFreq		table   kindex, ifreqin
;read the amplitude of the output table at destination index
kAmpTest	table   kwarp, iampout

;read from the count table to determine the number of repeats 
kcount	table   kwarp, icount 

	;Add one increment to the count table and divide 1 by this value 
	;to determine a value for averaging the amplitude sum later
	kaverage = 1/(kcount+1)	
	tablew  kaverage, kwarp, icount 

;If no repeated indexes are found then simply write the value 
if (kcount = 0) then
	tablew  kFreq, kwarp, ifreqout
	tablew  kAmp, kwarp, iampout

;else, if the new amplitude value is larger than the old one 
;use the freq value & add the new amp value to the old one 
elseif (kAmp>kAmpTest) then
	tablew  kFreq, kwarp, ifreqout
	tablew  kAmp+kAmpTest, kwarp, iampout
elseif (kAmp<kAmpTest) then
	tablew  kAmp+kAmpTest, kwarp, iampout
endif

kindex = kindex + 1

if (kindex < inumbins) kgoto loop

	;multiply icount with iampout to average the added amplitude values
	;this ensures that we do not get clips 

	vmultv  iampout, icount, inumbins 	
endop







instr 1

ifftsize = 2048 ;FFT size
iol = 4	    ;Overlap factor
ihop = ifftsize/iol	;hop size
iwindow = ifftsize*2	;window size (can be larger than FFT)
iwintype = 2

iNumBins = (ifftsize/2) + 1	; The number of used bins+1 for use by the table
ifreqin ftgen 0,0,iNumBins,2,0
iampin  ftgen 0,0,iNumBins,2,0
ifreqout ftgen 0,0,iNumBins,2,0
iampout  ftgen 0,0,iNumBins,2,0
icount  ftgen 0,0,iNumBins,2,0

;function table for remapping the data
iwarpfunction ftgen 0,0,iNumBins,-7,0 ,iNumBins, iNumBins ;Unaltered

;try these for more fun!
;iwarpfunction ftgen 0,0,iNumBins,-7,20 ,iNumBins, 20;Unaltered
;iwarpfunction ftgen 0,0,iNumBins,-7,0 ,iNumBins/2, iNumBins, 20, iNumBins/2
;iwarpfunction ftgen 0,0,iNumBins,-7,0 ,iNumBins/4, iNumBins, 0, iNumBins/2
;iwarpfunction ftgen 0,0,iNumBins,-7,iNumBins/20 ,iNumBins/4, 0, iNumBins/2,iNumBins

ain1, ain2 diskin "/Volumes/Sounds/vocal noises/mm-ah hrmonics.aiff", 1
;ain1	in
ain1	dcblock	ain1

fsig1	pvsanal 	ain1, ifftsize, ihop, iwindow, iwintype	

; export fsig amplitude and frequency data to table
kflag 	pvsftw fsig1, iampin, ifreqin
;not that iamp and ifreq have been replaced by iampin and ifreqin.
if (kflag > 0) then ; only proc when frame is ready

 ;the UDO reference is placed here to Frequency warp the PVS data
	warp	iNumBins, iampin, ifreqin, iampout, ifreqout, iwarpfunction, icount

; read data back to fsrc
	pvsftr fsig1, iampout, ifreqout 
;note that iamp and ifreq have been replaced by iampout and ifreqout

endif

aout1 pvsynth fsig1
outs	aout1

endin


</CsInstruments>
<CsScore>

i 1 0 20
e
</CsScore>
</CsoundSynthesizer>
<MacOptions>
Version: 3
Render: Real
Ask: Yes
Functions: ioObject
Listing: Window
WindowBounds: 0 62 801 140
CurrentView: io
IOViewEdit: On
Options: -b128 -A -s -m167 -R
</MacOptions>
<MacGUI>
ioView background {32125, 41634, 41120}
</MacGUI>

