[LAD] Help with frequency domain filtering basics

fons at kokkinizita.net fons at kokkinizita.net
Wed Nov 25 20:32:27 UTC 2009


On Wed, Nov 25, 2009 at 06:52:00PM +0100, Olivier Guilyardi wrote:

> I managed to do this in Octave. Now, I'm trying to do it in C with fftw and the
> sound I obtain is like "shivering". It's recognizable but severely altered. I've
> spent hours on this, it just won't work.

Clearly there's something wrong with the input/output/overlap
logic. It's difficult to say exactly what, because you are
making this much more complicated than it should be. 
You are using at least 4 variables to control this: begun,
rindex, windex, rlen. They will be either redundant or in
conflict.

Hint: since the basic processing proceeds in blocks of 
fftsize/2, both input and output should use that step
as well. Doing the input at twice that size will just
complicate things, and is probably the deeper cause of
whatever error you made.

It should be easy to modify your code into the form
suggested below. 

All these buffers are of size fftsize/2:

IP          input save buffer
W1, W2      the first and second half of the window
R1, R2      the first and second half of the real
            buffer used for the FFT/IFFT
OP          output save buffer

IP and OP are per channel, the others can be shared.


init()
{
  IP <= 0
  OP <= 0
}

process (input, output)
{
// both input, output are of size fftsize/2

1.   R1 <= IP * W1
2.   R2 <= input * W2
3.   IP <= input
4.   FFT, callback, IFFT
5.   output <= (R1 + OP) * scale
6.   OP <= R2
}
   
No state variables are required at all.
There are some tricks to avoid the copies at
steps 3 and 6, but in general it's not worth
the trouble.

Ciao,

-- 
FA

Io lo dico sempre: l'Italia è troppo stretta e lunga.




More information about the Linux-audio-dev mailing list