0

I need to apply an impulse response of an audio file that is 48kHz to an audio file that is 44.1kHz. It could be someone speaking for example. If I'm using the correct term, I need to convolve two audio file together so it would sound like someone is speaking inside of a cathedral.

What I don't know is how I go about doing this. I looked at minim library since it's the only audio library that I remember using and I found an example that applies an impulse response of a low pass filter to an audio file. Is there a way to convolve two audio files together to output a new sound? Audio processing isn't my forte so please don't mind my ignorance. Thanks, I'm trying to figure this out along the way.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • might be random, but sounds like something [Cristophe](http://doc.gold.ac.uk/~mas01cr/) would ask for :) – George Profenza Aug 20 '12 at 20:12
  • Yes, I couldn't do this last year and I still couldn't do it this year and it turn out to be the first question of the retake coursework. Regret not trying to figure this out then. For some reason, I couldn't send out any email through the webmail for some strange reason last week so I decided to ask here instead for answers. – Stock98 Aug 21 '12 at 01:11
  • Do you have to use Processing? Sounds like a job better suited to something like Max/MSP. More here: http://www.cycling74.com/forums/topic.php?id=20998 – ericsoco Aug 21 '12 at 01:19
  • Well according to the question I can use either processing or a vector programming environment which I haven't used before so processing is the closest thing to something I know. – Stock98 Aug 21 '12 at 01:28
  • @Stock98 Actually the task isn't that bad and it's kind of cool when you realize how simple it is. If you want to do the convolution operation on the two signals, you first need to make sure you're working with the same sample rate, so first step is to resample your impulse to the rate of the audio file you want to convolve to, the second is the actual convolution operation and finally you write the file to disk. Minim offers an option for [convolution](http://code.compartmental.net/minim/javadoc/ddf/minim/effects/Convolver.html), but I didn't see anything about resampling. Think about it... – George Profenza Aug 21 '12 at 02:27
  • ...if Minim doesn't offer resampling, it might actually be faster to use a package like Octave and 4 lines of code for 4 operations: [read from disk](http://octave.sourceforge.net/octave/function/wavread.html), [resample](http://octave.sourceforge.net/signal/function/resample.html), [convolve](http://octave.sourceforge.net/communications/function/conv.html), [save to disk](http://octave.sourceforge.net/octave/function/wavwrite.html). Pay attention to details though ! Goodluck! – George Profenza Aug 21 '12 at 02:32
  • @George Thanks, I will think about it in the morning since it's pretty late here as you probably already know. – Stock98 Aug 21 '12 at 02:32
  • I tried using octave last year but everyone was having trouble running it on the school computer so we ending up doing it on processing though that didn't go to well for most of the student haha. Though I'm willing to learn it because it looks well interesting from what I seen. The first thing is trying to get it working on this computer. It shouldn't take long if I actually do read the instruction from the site rather than a set of instruction by someone else. – Stock98 Aug 21 '12 at 02:34
  • I got octave working and manage to convolve the two wav file but now I'm trying to do the same on processing but with no success. Since minim doesn't say anything on resampling I decided just to resample in octave and save it via writewav so both wav should be the same. Since octave pretty much does it for you when you type in the function, it doesn't really help me much to understand the process though I did try accessing the .m file for those function but again it's confusing me. – Stock98 Aug 21 '12 at 10:43
  • You will not likely be able to understand the octave implementation without understanding the theory. The direct implementation, which I give in my answer, is okay for demonstration purposes, but it is WAY slower than what octave probably uses, which involves Fourier Transforms. – Bjorn Roche Aug 22 '12 at 19:00

1 Answers1

0

Yes, convolution is what you want, but first your source needs to be the same sample rate. Once your sources are the same sample rate, you have have two options for performing the S/R conversion: 1. you can do it "directly", which is the most straightforward way, but takes M*N time, or 2. you can do it using the Fourier transform, which is much more complex, but faster. You will need to implement the overlap add algorithm as well. Looking at the docs of Minim, it looks to me like they use a standard IIR filter, not convolution by an impulse response, so I don't think that will help. You will have to do a lot of work to do convolution on top of what Minim gives you using the FFT. If you want to go the "direct" route, it will look something like this:

for( i in 0...input.length )
    for( j in 0...conv.length )
        output[i] += i-j < 0 ? 0 : input[i-j] * conv[j] ;

more details here: http://www-rohan.sdsu.edu/~jiracek/DAGSAW/4.3.html or google "discrete convolution"

Update: Minim does give you convolution: http://code.compartmental.net/minim/javadoc/ddf/minim/effects/Convolver.html

Bjorn Roche
  • 11,279
  • 6
  • 36
  • 58