Reduce the number of allocations for creating FFT contexts

Reduce the number of allocations from 2 to 1 for every FFT
context by allocating enough memory for the FFT context
and passing parts of it to the kissfft allocation functions.
This commit is contained in:
Sebastian Dröge 2009-01-22 10:14:28 +01:00
parent eaf525f7f2
commit 2e8f9921c9
4 changed files with 32 additions and 12 deletions

View file

@ -20,6 +20,7 @@
#include <glib.h>
#include <math.h>
#include "_kiss_fft_guts_f32.h"
#include "kiss_fftr_f32.h"
#include "gstfft.h"
#include "gstfftf32.h"
@ -74,13 +75,18 @@ GstFFTF32 *
gst_fft_f32_new (gint len, gboolean inverse)
{
GstFFTF32 *self;
gsize subsize = 0, memneeded;
g_return_val_if_fail (len > 0, NULL);
g_return_val_if_fail (len % 2 == 0, NULL);
self = g_new (GstFFTF32, 1);
kiss_fftr_f32_alloc (len, (inverse) ? 1 : 0, NULL, &subsize);
memneeded = ALIGN_STRUCT (sizeof (GstFFTF32)) + subsize;
self->cfg = kiss_fftr_f32_alloc (len, (inverse) ? 1 : 0, NULL, NULL);
self = (GstFFTF32 *) g_malloc0 (memneeded);
self->cfg = (((guint8 *) self) + ALIGN_STRUCT (sizeof (GstFFTF32)));
self->cfg = kiss_fftr_f32_alloc (len, (inverse) ? 1 : 0, self->cfg, &subsize);
g_assert (self->cfg);
self->inverse = inverse;
@ -152,7 +158,6 @@ gst_fft_f32_inverse_fft (GstFFTF32 * self, const GstFFTF32Complex * freqdata,
void
gst_fft_f32_free (GstFFTF32 * self)
{
kiss_fftr_f32_free (self->cfg);
g_free (self);
}

View file

@ -20,6 +20,7 @@
#include <glib.h>
#include <math.h>
#include "_kiss_fft_guts_f64.h"
#include "kiss_fftr_f64.h"
#include "gstfft.h"
#include "gstfftf64.h"
@ -74,13 +75,18 @@ GstFFTF64 *
gst_fft_f64_new (gint len, gboolean inverse)
{
GstFFTF64 *self;
gsize subsize = 0, memneeded;
g_return_val_if_fail (len > 0, NULL);
g_return_val_if_fail (len % 2 == 0, NULL);
self = g_new (GstFFTF64, 1);
kiss_fftr_f64_alloc (len, (inverse) ? 1 : 0, NULL, &subsize);
memneeded = ALIGN_STRUCT (sizeof (GstFFTF64)) + subsize;
self->cfg = kiss_fftr_f64_alloc (len, (inverse) ? 1 : 0, NULL, NULL);
self = (GstFFTF64 *) g_malloc0 (memneeded);
self->cfg = (((guint8 *) self) + ALIGN_STRUCT (sizeof (GstFFTF64)));
self->cfg = kiss_fftr_f64_alloc (len, (inverse) ? 1 : 0, self->cfg, &subsize);
g_assert (self->cfg);
self->inverse = inverse;
@ -152,7 +158,6 @@ gst_fft_f64_inverse_fft (GstFFTF64 * self, const GstFFTF64Complex * freqdata,
void
gst_fft_f64_free (GstFFTF64 * self)
{
kiss_fftr_f64_free (self->cfg);
g_free (self);
}

View file

@ -20,6 +20,7 @@
#include <glib.h>
#include <math.h>
#include "_kiss_fft_guts_s16.h"
#include "kiss_fftr_s16.h"
#include "gstfft.h"
#include "gstffts16.h"
@ -74,13 +75,18 @@ GstFFTS16 *
gst_fft_s16_new (gint len, gboolean inverse)
{
GstFFTS16 *self;
gsize subsize = 0, memneeded;
g_return_val_if_fail (len > 0, NULL);
g_return_val_if_fail (len % 2 == 0, NULL);
self = g_new (GstFFTS16, 1);
kiss_fftr_s16_alloc (len, (inverse) ? 1 : 0, NULL, &subsize);
memneeded = ALIGN_STRUCT (sizeof (GstFFTS16)) + subsize;
self->cfg = kiss_fftr_s16_alloc (len, (inverse) ? 1 : 0, NULL, NULL);
self = (GstFFTS16 *) g_malloc0 (memneeded);
self->cfg = (((guint8 *) self) + ALIGN_STRUCT (sizeof (GstFFTS16)));
self->cfg = kiss_fftr_s16_alloc (len, (inverse) ? 1 : 0, self->cfg, &subsize);
g_assert (self->cfg);
self->inverse = inverse;
@ -152,7 +158,6 @@ gst_fft_s16_inverse_fft (GstFFTS16 * self, const GstFFTS16Complex * freqdata,
void
gst_fft_s16_free (GstFFTS16 * self)
{
kiss_fftr_s16_free (self->cfg);
g_free (self);
}

View file

@ -20,6 +20,7 @@
#include <glib.h>
#include <math.h>
#include "_kiss_fft_guts_s32.h"
#include "kiss_fftr_s32.h"
#include "gstfft.h"
#include "gstffts32.h"
@ -73,13 +74,18 @@ GstFFTS32 *
gst_fft_s32_new (gint len, gboolean inverse)
{
GstFFTS32 *self;
gsize subsize = 0, memneeded;
g_return_val_if_fail (len > 0, NULL);
g_return_val_if_fail (len % 2 == 0, NULL);
self = g_new (GstFFTS32, 1);
kiss_fftr_s32_alloc (len, (inverse) ? 1 : 0, NULL, &subsize);
memneeded = ALIGN_STRUCT (sizeof (GstFFTS32)) + subsize;
self->cfg = kiss_fftr_s32_alloc (len, (inverse) ? 1 : 0, NULL, NULL);
self = (GstFFTS32 *) g_malloc0 (memneeded);
self->cfg = (((guint8 *) self) + ALIGN_STRUCT (sizeof (GstFFTS32)));
self->cfg = kiss_fftr_s32_alloc (len, (inverse) ? 1 : 0, self->cfg, &subsize);
g_assert (self->cfg);
self->inverse = inverse;
@ -151,7 +157,6 @@ gst_fft_s32_inverse_fft (GstFFTS32 * self, const GstFFTS32Complex * freqdata,
void
gst_fft_s32_free (GstFFTS32 * self)
{
kiss_fftr_s32_free (self->cfg);
g_free (self);
}