View Full Version : Convoluting sounds with memory restrictions
WatsonLadd
06-28-2006, 05:56 AM
I have a sound that I want to convolute with the transfer function of the area without having to put the whole sound in memory. Is there a way to do this, or will I just have to make a Fourier Transform of the sound, and the room, multiply, and compute an inverse fourier transform, then play the sound?
monjardin
06-28-2006, 07:33 AM
I like the term convolve much better. To convolute implies obfuscation. Now on to your question!
Here is the convolution integral:
http://img521.imageshack.us/img521/3875/conv1fx.gif
However, you are working a discrete environment, so you get this:
http://img358.imageshack.us/img358/4816/img14vk.gif
So, for each n step you calculate for y, you need to sum the right term over the range of your whole signal. With that said, you could read each mth value from the transform and signal functions one at a time without placing the whole signal in memory, but you will need to do this for all of n.
float readX(int sample);
float readH(int sample);
void writeY(int sample, float value);
void convolveSignals()
{
for (int n = 0; n < NUM_SAMPLES; ++n)
{
float y = 0;
for (int m = 0; m < NUM_SAMPLES; ++n)
y += readX(m) * readH(n - m);
writeY(n, y);
}
}
Needless to say, you could get much better performance with the whole thing in memory.
Of course, I haven't done this before and I could be way off! :p
donBerto
06-28-2006, 08:20 AM
having the entire sound data in memory gives you absolute fidelity. alternatively, let's say you have n sound data for every second. you could skip every m sound data such that now you're only loading (n-m) sound data per second. that leaves your entire sound data smaller. optionally, you could then interpolate the "points" between the smaller data set to "regain" the sacrificed data.
all of this, of course, would cost you processing time. pick your trade-off.
just my 2cents.
:regards:
vBulletin, Copyright ©2000-2009, Jelsoft Enterprises Ltd.