User-Defined Opcode Database

pvshift

Pitch shifting and spectral stretching with pvs streams

Download UDO File

Syntax

pvshift kpitch, kstretch, inumbins, iampin, iampout, ifreqin, ifreqout

Code

	opcode pvshift, 0, kkiiiii

; our input values are:
; kpitch - pitch shift amount [.5=down octave,
; 1=noshift, 2=up octave, etc]
; kstretch - spectral shift amount [ususal range is
; .99-1.01, where 1=nostretch]
; inumbins - number of fft bins [size of tables]
; iampin - table containing amp data
; iampout - table to write modified amp data
; ifreqin - table containing freq data
; ifreqout - table to write modified freq data

kpitch, kstretch, inumbins, iampin, iampout, ifreqin, ifreqout xin

; make sure we 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 tables and shifting pitch
kcount = 0
loop:
kindex 	= kcount/kpitch

if (kindex < inumbins) then
kval 	table kindex, iampin
kamp 	table kcount, iampout
	tablew kval+kamp, kcount, iampout

kval 	table kindex, ifreqin
	tablew kval*kpitch, kcount, ifreqout
endif

kcount = kcount + 1
kpitch = kpitch * kstretch

if (kcount < inumbins) kgoto loop

endop

Examples

instr 2 ; to test the pvshift opcode

; get input and do pvanal
ifftsize = 1024
iNumBins = ifftsize/2 + 1

ainl, ainr ins
fsigl pvsanal ainl, ifftsize, ifftsize/4, ifftsize*2, 0
; [ or alternatively use pvsfread with a pvoc-ex file here ]

; make ftables
iampin ftgen 0,0,iNumBins,2,0
iampout ftgen 0,0,iNumBins,2,0
ifreqin ftgen 0,0,iNumBins,2,0
ifreqout ftgen 0,0,iNumBins,2,0

; our gui controls
kfiltl invalue "filtl"
kfilth invalue "filth"
kpitch invalue "pitch"
kstretch invalue "stretch"

; export fsig to tables
kflag pvsftw fsigl, iampin, ifreqin
if (kflag > 0) then ; only proc when frame is ready

; pitch shift/stretch
pvshift kpitch, kstretch, iNumBins, iampin, iampout, ifreqin, ifreqout

; read modified data back to fsrc
pvsftr fsigl, iampout, ifreqout

endif


; resynthesize and output - compare with untouched right channel
aoutl pvsynth fsigl

outs aoutl, ainr

endin

Credits

Author: Matt Ingalls


Previous Home Next
declick   findPowerOfTwo