DSPRelated.com
Forums

Problems using fftw, fftw_free

Started by Unknown November 9, 2005
Hello,
It's my first post and so I've searched some topics about fftw, trying not
to ask something alredy answered and I didn't find anything about it, so
I'd like to ask your help about using fftw...

I'm a borland c++ builder user (bc++ 5) and fftw runs smooth and fast
calculating the fft of my real data (audio data) ... but I get problems
when I try to deallocate the fft output buffer I created with fftw_malloc
...

Here is some of the code I'm using...

void TRANSCRICAO::AlimentarModulosFFT()
{
// Dados que ser�o utilizados pela FFTW
  double *BufferEntradaFFT;
  short *BufferDadosRetirados;
  fftw_complex *BufferResultadoFFT;
  fftw_plan planoExecFFT;
// ------------------------------------
  BufferEntradaFFT = (double *) calloc (TamanhoBufferFFT,
sizeof(double));
  BufferDadosRetirados = (short *) calloc (TamanhoBufferFFT)
  BufferResultadoFFT = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) *
(TamanhoBufferFFT*0.5));
  planoExecFFT = fftw_plan_dft_r2c_1d(TamanhoBufferFFT, BufferEntradaFFT,
BufferResultadoFFT, FFTW_ESTIMATE);
for (x=0; (x+(TamanhoBufferFFT*arquivoWAV.getNCanais())) <
arquivoWAV.getDataSize();
x+=(TamanhoBufferFFT*(arquivoWAV.getNCanais()*0.5))) //Window 50% overlap
  {
      //Here I feed BufferEntradaFFT with my audio data windowed with
hann
      fftw_execute(planoExecFFT); 
      // Here I call my stuff to use the fft data I got from fftw_execute
  }
  // ----------desalocar recursos!
  fftw_destroy_plan(planoExecFFT);
  free(BufferEntradaFFT);
  free(BufferDadosRetirados);
  fftw_free(BufferResultadoFFT); // Here I get the problem ...
}

The message I get from my executable file is : 
"Access violation at address 784AC8E1 in module "ntdll.dll". Write of
address 00000000".

But the funny part is, if I comment the line 

fftw_execute(planoExecFFT); 

I get no exception and the rotine works fine.

I do not know what I should do make this go away ... so I'm here asking
for your help...
And yes! I know it's not a programming forum, but many of you guys use
fftw without any trouble, so maybe you could point me into a direction.
Thanks
Gabriel




Finally I discovered the problem!
The FFT vector in a real to complex FFT should have n/2+1 bins, and I only
allocated n/2!
Thanks to the ones who at least took a look at that thread and sorry for
such a stupid doubt! hehehe
Gabriel
Gabriel Sim&#4294967295;es wrote:

> Finally I discovered the problem! > The FFT vector in a real to complex FFT should have n/2+1 bins, and I only > allocated n/2! > Thanks to the ones who at least took a look at that thread and sorry for > such a stupid doubt! hehehe > Gabriel
Just remember "The only *DUMB* question is the one you do not ask" :)