[Csnd] phase vocoder with array opcodes.
Date | 2014-05-24 10:40 |
From | Victor Lazzarini |
Subject | [Csnd] phase vocoder with array opcodes. |
To give you a taster of what is possible with the new array operations, I’ve prepared an example implementing a simple phase vocoder pitch shifter/harmoniser from basic principles (this is now one of the examples in the manual). =========================== ksmps = 64 instr 1 ihopsize = 256 ; hopsize ifftsize = 2048 ; FFT size iolaps = ifftsize/ihopsize ; overlaps ibw = sr/ifftsize ; bin bandwidth kcnt init 0 ; counting vars krow init 0 kOla[] init ifftsize ; overlap-add buffer kIn[] init ifftsize ; input buffer kOlph[] init ifftsize/2+1 ; old phases kPhs[] init ifftsize/2+1 ; synthesis phases kDeltaOut[] init ifftsize/2+1 ; synthesis freqs kMagsOut[] init ifftsize/2+1 ; synthesis mags kOut[][] init iolaps, ifftsize ; output buffers a1 diskin2 "fox.wav",1,0,1 ; audio input /* every hopsize samples */ if kcnt == ihopsize then /* window and take FFT */ kWin[] window kIn,krow*ihopsize kSpec[] rfft kWin /* mags & phases */ kMags[] mags kSpec kPha[] phs kSpec /* phase diffs */ kDelta[] = kPha - kOlph kOlph = kPha /* pitch shift */ ki = 0 iscal = 1.25 until ki == ifftsize/2 do if ki*iscal < ifftsize/2 then kDeltaOut[ki*iscal] = kDelta[ki]*iscal kMagsOut[ki*iscal] = kMags[ki] endif ki += 1 od /* accum phases */ kPhs = kDeltaOut + kPhs kPhs unwrap kPhs kSpec pol2rect kMagsOut,kPhs /* IFFT + window */ kRow[] irfft kSpec kWin window kRow, krow*ihopsize /* place it on out buffer */ kOut setrow kWin, krow /* zero the ola buffer */ kOla = 0 /* overlap-add */ ki = 0 until ki == iolaps do kRow getrow kOut, ki kOla = kOla + kRow ki += 1 od /* update counters */ krow = (krow+1)%iolaps kcnt = 0 endif /* shift audio in/out of buffers */ kIn shiftin a1 a2 shiftout kOla a1 delay a1, (ifftsize+ihopsize)/sr out a1*0.3+a2/iolaps /* increment counter */ kcnt += ksmps endin ======================== Dr Victor Lazzarini Senior Lecturer NUI Maynooth, Ireland victor dot lazzarini at nuim dot ie |
Date | 2014-05-24 17:18 |
From | peiman khosravi |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
Wow this looks great. I'm going to study it! Thanks for posting it here.
Best, Peiman On 24 May 2014 10:40, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: To give you a taster of what is possible with the new array operations, I’ve prepared an |
Date | 2014-05-24 17:42 |
From | Matti Koskinen |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
On 05/24/2014 12:40 PM, Victor Lazzarini wrote: > To give you a taster of what is possible with the new array operations, I’ve prepared an > example implementing a simple phase vocoder pitch shifter/harmoniser from basic principles > (this is now one of the examples in the manual). > hi, looks interesting, is the same principle available for the stretching? I'm writing a small (getting now also pthreads involved, as I'm trying real-time) program, that records video, freezes the frame for a predefined time. I've got OSC-message sent to csound, when the freeze starts, and the basic logic in csound seems to work, sound output is just from diskin2 at the moment. It would be nice to freeze sound from live input, in a way pvoc-stretch does. I've read Iain McCurdy's examples using granular synthesis, may work fine, but actually I really don't know, what would be the best method. Any hints? tnx -m |
Date | 2014-05-24 18:01 |
From | Victor Lazzarini |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
To freeze the input (I think, but have not tested it), it should be the case of just bypassing the shiftin line. ======================== Dr Victor Lazzarini Senior Lecturer NUI Maynooth, Ireland victor dot lazzarini at nuim dot ie On 24 May 2014, at 17:42, Matti Koskinen |
Date | 2014-05-24 18:12 |
From | Victor Lazzarini |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
Not quite so. We need to stop the new PV frames. Here’s an example |
Date | 2014-05-24 18:25 |
From | Victor Lazzarini |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
and here’s a modification for timescaling (compressing or scaling). Probably not as good quality as mincer/temposcal and other fsig methods; but usable I think, within limits ksmps = 64 nchnls = 2 instr 1 ihopsize = 256 ; hopsize ifftsize = 2048 ; FFT size iolaps = ifftsize/ihopsize ; overlaps ibw = sr/ifftsize ; bin bandwidth kcnt init 0 ; counting vars krow init 0 kOla[] init ifftsize ; overlap-add buffer kIn[] init ifftsize ; input buffer kOlph[] init ifftsize/2+1 ; old phases kPhs[] init ifftsize/2+1 ; synthesis phases kDeltaOut[] init ifftsize/2+1 ; synthesis freqs kMagsOut[] init ifftsize/2+1 ; synthesis mags kOut[][] init iolaps, ifftsize ; output buffers ktscal = 1.25 ;timescale (slower < 1 < faster) a1 diskin2 "fox.wav",1/ktscal,0,1 ; audio input kfreez = 0 ; no freezing /* every hopsize samples */ if kcnt == ihopsize then /* window and take FFT */ if kfreez == 0 then kWin[] window kIn,krow*ihopsize kSpec[] rfft kWin /* mags & phases */ kMags[] mags kSpec kPha[] phs kSpec /* phase diffs */ kDelta[] = kPha - kOlph kOlph = kPha endif /* pitch shift */ ki = 0 until ki == ifftsize/2 do if ki*ktscal < ifftsize/2 then kDeltaOut[ki*ktscal] = kDelta[ki]*ktscal kMagsOut[ki*ktscal] = kMags[ki] endif ki += 1 od /* accum phases */ kPhs = kDeltaOut + kPhs kPhs unwrap kPhs kSpec pol2rect kMagsOut,kPhs /* IFFT + window */ kRow[] irfft kSpec kWin window kRow, krow*ihopsize /* place it on out buffer */ kOut setrow kWin, krow /* zero the ola buffer */ kOla = 0 /* overlap-add */ ki = 0 until ki == iolaps do kRow getrow kOut, ki kOla = kOla + kRow ki += 1 od /* update counters */ krow = (krow+1)%iolaps kcnt = 0 endif /* shift audio in/out of buffers */ kIn shiftin a1 a2 shiftout kOla a1 delay a1, (ifftsize+ihopsize)/sr out a2/iolaps, a2/iolaps /* increment counter */ kcnt += ksmps endin ======================== Dr Victor Lazzarini Senior Lecturer NUI Maynooth, Ireland victor dot lazzarini at nuim dot ie On 24 May 2014, at 18:01, Victor Lazzarini |
Date | 2014-05-24 21:03 |
From | Victor Lazzarini |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
and finally, a more usual timescaling example, taking audio from a function table |
Date | 2014-05-24 21:34 |
From | Matti Koskinen |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
Thank you very much! I don't get any sound though tnx -m On 05/24/2014 08:25 PM, Victor Lazzarini wrote: > and here’s a modification for timescaling (compressing or scaling). Probably not as good quality > as mincer/temposcal and other fsig methods; but usable I think, within limits > > ksmps = 64 > nchnls = 2 > > instr 1 > > ihopsize = 256 ; hopsize > ifftsize = 2048 ; FFT size > iolaps = ifftsize/ihopsize ; overlaps > ibw = sr/ifftsize ; bin bandwidth > kcnt init 0 ; counting vars > krow init 0 > > kOla[] init ifftsize ; overlap-add buffer > kIn[] init ifftsize ; input buffer > kOlph[] init ifftsize/2+1 ; old phases > kPhs[] init ifftsize/2+1 ; synthesis phases > kDeltaOut[] init ifftsize/2+1 ; synthesis freqs > kMagsOut[] init ifftsize/2+1 ; synthesis mags > kOut[][] init iolaps, ifftsize ; output buffers > > ktscal = 1.25 ;timescale (slower < 1 < faster) > a1 diskin2 "fox.wav",1/ktscal,0,1 ; audio input > > kfreez = 0 ; no freezing > /* every hopsize samples */ > if kcnt == ihopsize then > /* window and take FFT */ > if kfreez == 0 then > kWin[] window kIn,krow*ihopsize this part is bit unclear. Does the kIn shiftin a1 in the end of the instr fill the buffer after enough loops? > kSpec[] rfft kWin > /* mags & phases */ > kMags[] mags kSpec > kPha[] phs kSpec > > /* phase diffs */ > kDelta[] = kPha - kOlph > kOlph = kPha > endif > > /* pitch shift */ > ki = 0 > until ki == ifftsize/2 do > if ki*ktscal < ifftsize/2 then > kDeltaOut[ki*ktscal] = kDelta[ki]*ktscal > kMagsOut[ki*ktscal] = kMags[ki] > endif > ki += 1 > od > > /* accum phases */ > kPhs = kDeltaOut + kPhs > kPhs unwrap kPhs > kSpec pol2rect kMagsOut,kPhs > > /* IFFT + window */ > kRow[] irfft kSpec > kWin window kRow, krow*ihopsize > /* place it on out buffer */ > kOut setrow kWin, krow > > /* zero the ola buffer */ > kOla = 0 > /* overlap-add */ > ki = 0 > until ki == iolaps do > kRow getrow kOut, ki > kOla = kOla + kRow > ki += 1 > od > > /* update counters */ > krow = (krow+1)%iolaps > kcnt = 0 > endif > > > /* shift audio in/out of buffers */ > kIn shiftin a1 > > a2 shiftout kOla > a1 delay a1, (ifftsize+ihopsize)/sr > out a2/iolaps, a2/iolaps > > /* increment counter */ > kcnt += ksmps > > endin > > > ======================== > Dr Victor Lazzarini > Senior Lecturer > NUI Maynooth, Ireland > victor dot lazzarini at nuim dot ie > > > > > On 24 May 2014, at 18:01, Victor Lazzarini |
Date | 2014-05-24 21:42 |
From | Victor Lazzarini |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
What do you mean you don’t get any sound? It works here. Did you modify the example? shiftin fills the buffer continuously, and every ihopsize samples we do a spectral analysis. ======================== Dr Victor Lazzarini Senior Lecturer NUI Maynooth, Ireland victor dot lazzarini at nuim dot ie On 24 May 2014, at 21:34, Matti Koskinen |
Date | 2014-05-24 21:51 |
From | Matti Koskinen |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
On 05/24/2014 11:42 PM, Victor Lazzarini wrote: > What do you mean you don’t get any sound? It works here. Did you modify the example? > shiftin fills the buffer continuously, and every ihopsize samples we do a spectral analysis. > > in the end csound gives overall amps 0.00000 0.000000 I changed only my own mono wav-file to diskin2, nothing else Tried both on osx 10.9 after brew install csound --HEAD and ubuntu 13.04 after git clone csound. ksmps is 64 *OR* I had ksmp=64, just checked, after fix, yes! sound. sorry -m |
Date | 2014-05-24 21:56 |
From | Victor Lazzarini |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
Good to know. Yes, ksmps=64 is required. ======================== Dr Victor Lazzarini Senior Lecturer NUI Maynooth, Ireland victor dot lazzarini at nuim dot ie On 24 May 2014, at 21:51, Matti Koskinen |
Date | 2014-05-24 22:10 |
From | Matti Koskinen |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
osx fine, but on linux: Score finished in csoundPerform(). inactive allocs returned to freespace end of score. overall amps: 0.05776 0.05776 overall samples out of range: 0 0 0 errors in performance Elapsed time at end of performance: real: 9.909s, CPU: 3.770s 324 2730 sample blks of 64-bit floats written to dac *** Error in `csound': free(): invalid size: 0x00000000016d94b0 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x80996)[0x7f2abb95a996] /usr/local/lib/libcsound64.so.6.0(+0x5b638)[0x7f2abbf1a638] /usr/local/lib/libcsound64.so.6.0(+0x1b41a6)[0x7f2abc0731a6] /usr/local/lib/libcsound64.so.6.0(csoundDestroy+0xb1)[0x7f2abc06f0d9] csound[0x4015c3] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f2abb8fbde5] csound[0x40118c] -m |
Date | 2014-05-24 23:55 |
From | Victor Lazzarini |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
fixed now in git ======================== Dr Victor Lazzarini Senior Lecturer NUI Maynooth, Ireland victor dot lazzarini at nuim dot ie On 24 May 2014, at 22:10, Matti Koskinen |
Date | 2014-05-25 21:06 |
From | Andres Cabrera |
Subject | Re: [Csnd] phase vocoder with array opcodes. |
Hi, When trying to run:<CsoundSynthesizer> <CsOptions> </CsOptions> <CsInstruments> sr = 44100 ksmps = 128 nchnls = 2 0dbfs = 1.0 instr 1 karr[] init 9,8,7,6,5,4,3,2 kout[] rfft karr
kcount init 0 until kcount == 8 do printf "%f", 1, kout[kcount] kcount += 1 od turnoff endin </CsInstruments> <CsScore> i 1 0 1 </CsScore> </CsoundSynthesizer> 0 __GI_raise 56 0x7ffff4bef037 1 __GI_abort 90 0x7ffff4bf2698 2 __libc_message 199 0x7ffff4c2c5ab 3 malloc_printerr 4923 0x7ffff4c38a46 4 _int_free 3779 0x7ffff4c38a46 5 memRESET memalloc.c 230 0x7ffff7904d42 6 reset csound.c 2912 0x7ffff7a5fa2c 7 csoundDestroy csound.c 1223 0x7ffff7a5b920 8 CsoundEngine::cleanupCsound csoundengine.cpp 976 0x457e8f 9 CsoundEngine::stopCsound csoundengine.cpp 931 0x457cf6 10 CsoundEngine::stop csoundengine.cpp 698 0x456ae6 11 CsoundEngine::messageListDispatcher csoundengine.cpp 1086 0x459063 12 QtConcurrent::StoredFunctorCall1<void, void (*)(void*), void*>::runFunctor qtconcurrentstoredfunctioncall.h 275 0x462e13 13 QtConcurrent::RunFunctionTask<void>::run qtconcurrentrunbase.h 132 0x45aa0c 14 ?? /home/andres/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5 0x7ffff5a530fb 15 ?? /home/andres/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5 0x7ffff5a56088 16 start_thread 311 0x7ffff57a6f8e 17 clone 113 0x7ffff4cb2a0d The error seems to be: WARNING: csoundRealFFTnp2(): invalid FFT size *** Error in `/home/andres/Documents/src/csound-csound6-git-build/csound': malloc(): memory corruption: 0x0000000001e06e30 *** Andrés On Sat, May 24, 2014 at 3:55 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: fixed now in git |