Log in

View Full Version : AudioConvolution filter


mg262
26th August 2005, 00:23
I was in the mood to code something, but a bit too wiped out to try anything hard... so I built a very simple audio plug-in.
a convolver plugin would be very cool.

that would handle reverbs, frequency filters and phase filters all in 1 go.

just use an audio app to generate an impulse (make a 1-sample click and filter it), and point the avs plugin to that wave file.
AudioConvolution, 25Aug05 (http://people.pwf.cam.ac.uk/mg262/posts/AudioConvolution_25Aug05.dll)

AudioConvolution(clip input, clip kernel)

You must pass in clips with video; audio must be 16-bit; kernel must have mono audio. kernel should only have a single figure number of nonzero points. (Or else it becomes very slow) I've only tested it once, with a mono input.

Incidentally, this makes no attempt to be fast whatsoever. This is a throwaway thing and I don't plan to add features to it (though I will fix bugs!). I might speed it up a bit though...

Edit:

A slightly faster version...

AudioConvolution, 26Aug05 (http://people.pwf.cam.ac.uk/mg262/posts/AudioConvolution_26Aug05.dll)

So you should be able to feed it larger kernels. By the way, when I said very slow above, I meant slower than real-time :p ... if you don't mind waiting to encode the audio larger kernels should work fine... but try on kernels with < 30 nonzero values first, to check whether it's working.

I know whats slowing it down, and it can be fixed to allow yet larger kernels. I can deal with it if anyone actually has an interest in using this thing.

Mug Funky
26th August 2005, 11:19
haha! you rock!

it's not really usable yet (i was thinking kernels in the region of 512-1024 points), but it's definitely a start. a convolver in avisynth means all possible kinds of passive filters can be made in avisynth now (so long as you have another program capable of making the impulses...).

i gather it's faster to export audio through virtualdub, then use something like foobar's convolver to do the dirty work?

still, it's a very good start. i can see a lot of impulse files being posted here to get rid of certain problems (pilot tones! yaaaah!) with audio.

mg262
26th August 2005, 11:56
:)

i was thinking kernels in the region of 512-1024 pointsTell you what, send me one in a WAV file and I'll try to poke things until it works in real-time. It may even work now... the only kernels I understand are echoes and setting up a 512 point echo is just not a good idea...

I don't think it is intrinsically slow... AVISynth requests about 2000 samples at a time, but the filter needs to look back maybe on the order of 20,000 (depending on the kernel). So it requests 10 times as many source samples as needed. Can be fixed with a buffer of one kind or another.

Scratch the comment about the second clip requiring video... this works fine with the 26th August version:

AudioConvolution(wavsource("echo.wav"))

MfA
26th August 2005, 13:14
If you are feeling ambitiuous you could port the code from BruteFIR.

tsp
26th August 2005, 15:30
are you using fftw for this filter?

mg262
26th August 2005, 15:37
Guys, guys,
I was in the mood to code something, but a bit too wiped out to try anything hard... so I built a very simple audio plug-in.
Incidentally, this makes no attempt to be fast whatsoever.

I just felt like throwing something together last night. It's not sophisticated at all. It doesn't apply a DFT because it's set up to deal with sparse kernels (cf echoes)... I don't/didn't know enough about audio to know whether that was the right way to go, but it sounds like it isn't...

Edit: @tsp, if I do modify it to use fftw, is it as simple as calling one function on source chunk and kernel, multiplying, and calling that function again? (Probably with size rounded up to multiple of two.) Or does it take a lot more work to use the library? Thanks!

MfA
26th August 2005, 20:30
Essentially yes, but you also have to deal with overlap add/save technique ... and really large FFTs are inefficient. Brutefir (http://www.ludd.luth.se/~torger/brutefir.html) uses partitioned FFTs to sidestep that.

tsp
26th August 2005, 20:40
well as long as the partionsize is a power of 2 the slowdown shouldn't be that inefficient. I mean on a modern computer there should be more than enough proccesing power to do the fft in realtime. Have a look at my variableblur (http://www.avisynth.org/warpenterprises/files/variableblur_25_dll_20050506.zip) sourcecode (gaussian.cpp/.h) for how it is possible to use fftw to do a 2d convolution (of course with audio it is only 1d=faster)