날짜: 2004.08.03, (화), 7:58:39 AM Asia/Seoul
받는 사람: csound@lists.bath.ac.uk
제목: [Csnd] pvs pitch shift
답장 받는 사람:: csound@lists.bath.ac.uk
finally figured out how to do pitch shifting and spectral stretching with pvs streams! [thanks to rwd for pointing me to Stephan Bernsee’s dspdimension.com]
made a user-opcode that does it – see below. on my machine i can only do one channel in real-time, but i bet its fine on newer ones. however still might be worth making a real opcode that does this anyway, so that you dont even have to convert fsig to ftables first.
-m
nchnls = 2
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
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
—
Send bugs reports to csound-bugs@cs.bath.ac.uk
(or to http://www.cs.bath.ac.uk/cgi-bin/csound )
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk