Steva
Steva

Reputation: 231

Real fft error - ffmpeg

I am trying to use ffmpegs fft utility for audio samples called real fft(rdft).

But I have SIGSEGV error. Code is very simple.

 static void fft(float* data){
    RDFTContext * ctx = av_rdft_init(Globals::WindowSizePower, DFT_R2C)
    av_rdft_calc(ctx, data);
    av_rdft_end(ctx);
    av_free(ctx);
  }

Defined constants are

static const int WindowSize = 1024;
static const int WindowSizePower = 10;

Can someone tell me what I am doing wrong? I tried to find example on internet where this ffmpeg utility is used but I didnt find any.

EDIT:

This is function which call this function

void fftInit(float* correction){
        m_fft_data = new float[Globals::WindowSize]();
        memcpy(m_fft_data, correction, sizeof(float)*Globals::WindowSize);
        for(int i = 0; i < Globals::WindowSize; ++i){
            m_fft_data[i] *= m_data[i];
        }

        FFMPEGFFT::fft(m_fft_data);
    }

Input data is properly allocated. I tested extracted data before coming to this part.

Upvotes: 0

Views: 357

Answers (1)

DaBler
DaBler

Reputation: 2852

Calling av_free after av_rdft_end is incorrect. av_rdft_end already frees the memory space pointed to by ctx.

(Moreover, a semicolon is missing after av_rdft_init.)

Edit:

The second problem is that the operator new[] returns improperly aligned pointer. Use e.g. av_malloc instead. av_malloc allocates a block with alignment suitable for all memory accesses (including SSE instructions).

Upvotes: 1

Related Questions