Cabbage Logo
Back to Cabbage Site

Smooth Crossfade between two convolution files

Hi!

I have a combobox where I can select Reverb files (IRs).

When switching through them I am getting short delays and interreuption of the material that is played until it gets back to normal. Maybe it has to do with the re-calculation of the new (switched) IR file (?).

Is there a way to avoid this or to make a smooth transition from one file to the other?

Thank you very much!
//rootnote

Would it be simpler create two convolution reverbs and simply fade between the two rather than trying to switch IRs. Or you could use start a second instance of your convolution reverb instrument using the new IR?

If you are switching IR a lot, and also between several different IRs, it might make sense to use liveconv as the convolution opcode. Here you can update the IR by rewriting the contents sequentially.

1 Like

Hi @Oeyvind!
How can I access liveconv in cabbage? I have version 2.5.0 installed and cant seem to initialize it.

Thank you!

Seems to be recognised here without any problem. What error are you getting?

No error, doesnt seems to get loaded (it doesnt get red)

image

That doesn’t mean it’s not there. It just means Cabbage doesn’t highlight the opcode because it’s not part of its opcode list. It is now however as I just added it :wink:

@rorywalsh great! Thank you!

“Would it be simpler create two convolution reverbs and simply fade between the two rather than trying to switch IRs. Or you could use start a second instance of your convolution reverb instrument using the new IR?”

could I maybe ask for an example ? Thanks!

I’ve never used liveconv (sorry @Oeyvind , it’s high on my list of things to do in 2021!). But there is a Csound manual example that you should be able to quickly use in Cabbage :thinking:

I don’t have an example of this, I was just thinking aloud. But feel free to post your original code in order to start the ball rolling :+1:

1 Like

Yes, as Rory mentions, the example from the manual should get you started.
https://csound.com/docs/manual/liveconv.html
To reload the IR, you would start a new instance of instr 13 and give it the name of the new IR as a pfield.
If you constantly reload the same set of IRs back and forth a lot, then you might optimize the example by e.g. preloading the all IRs into tables. We have also sketched some ideas for reloading the spectral data directly without reanalysis, which might be useful if you reload very often, e.g. several times a second. Do tell if you need that and it might kick us into gear for implementing it :slight_smile:
Using liveconv and building your imeplementation from the manual example should be a very CPU effective way of accomplishing IR switching without clicks, as there is always just one convolution process running, even when you switch IR.

1 Like

ok, I have a simple version of it already running

giImpulse1L    ftgen   1, 0, 44100, 1, "1.WAV" , 0, 0, 1	;stereo file
giImpulse1R    ftgen   2, 0, 44100, 1, "1.WAV" , 0, 0, 1	;stereo file
giImpulse2L    ftgen   3, 0, 44100, 1, "2.wav"         , 0, 0, 1	;stereo file
giImpulse2R    ftgen   4, 0, 44100, 1, "2.wav"         , 0, 0, 1	;stereo file
    
ainL,ainR	ins	;READ STEREO AUDIO INPUT
    
instr	1	;CONVOLUTION INSTRUMENT

ainL,ainR	ins	;READ STEREO AUDIO INPUT


;---------------------------

    iplen		=	1024				;Buffer
itab1		=	giImpulse1L			
itab2		=	giImpulse1R
itab3		=	giImpulse2L
    itab4             =  	      giImpulse2R

;----------------------------

iirlen1L		=	nsamp(itab1)			
iskipsamples1L	=	nsamp(itab1)/2.3
iirlen1R		=	nsamp(itab2)			
iskipsamples1R	=	nsamp(itab2)/2.3
iirlen2L		=	nsamp(itab3)			
iskipsamples2L	=   nsamp(itab3)/2.3
iirlen2R		=	nsamp(itab4)			
iskipsamples2R	=   nsamp(itab4)/2.3
kupdate = 1
kclear = 0

;start-up impulse

aL 	liveconv ainL, itab1, 8192, kupdate, kclear
aR 	liveconv ainR, itab2, 8192, kupdate, kclear

Is it possible to skip samples in the IR like the iskipsamples in the fconv opcode or any other workaround?
Since the delay in the IR will be create delay when bypassing and switching it back on as VST version in a DAW.
http://www.csounds.com/manual/html/ftconv.html

Thanks

Ok. Good. Almost there. What is missing is the activity that happens in instr 13 in the manual example.

The way you have set it up now, you refer liveconv directly to the table where the ausdio is stored. This will not help you in replacing the IR, since the contents of the table is now static.
What you need to do:
Instead of changing the table reference in order to replace the IR, you should rewrite the contents of the table holding the IR (all the time referring liveconv to the same table).
This is what happens in instr 13. You can also use “skiptime” type tricks to jumpo ahead in the IR: you would do this as the skiptime for diskin (again, as in instr 13).

all best
Øyvind

1 Like

Thank you for the response!

So in my understanding I would add new IRs by something like this (by filling giIR_record table):

andx_IR1 line 0, 1, 1/(ftlen(giIR_record)/sr)
tablew a1amp, andx_IR1, giIR_record, 1
outch 1, a1
amp ; output the IR1

andx_IR2 line 0, 1, 1/(ftlen(giIR_record)/sr)
tablew a2amp, andx_IR2, giIR_record, 1
outch 1, a2
amp ; output the IR2

is that correct?
thanks

@Oeyvind am I on the correct path here? Thanks! :slight_smile: