From 2e8f9921c933c933e40d890da7594c1bdc434dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 22 Jan 2009 10:14:28 +0100 Subject: [PATCH] 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. --- gst-libs/gst/fft/gstfftf32.c | 11 ++++++++--- gst-libs/gst/fft/gstfftf64.c | 11 ++++++++--- gst-libs/gst/fft/gstffts16.c | 11 ++++++++--- gst-libs/gst/fft/gstffts32.c | 11 ++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/gst-libs/gst/fft/gstfftf32.c b/gst-libs/gst/fft/gstfftf32.c index b704b5ff2b..4facb353cd 100644 --- a/gst-libs/gst/fft/gstfftf32.c +++ b/gst-libs/gst/fft/gstfftf32.c @@ -20,6 +20,7 @@ #include #include +#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); } diff --git a/gst-libs/gst/fft/gstfftf64.c b/gst-libs/gst/fft/gstfftf64.c index cd6db088b1..5291f6289d 100644 --- a/gst-libs/gst/fft/gstfftf64.c +++ b/gst-libs/gst/fft/gstfftf64.c @@ -20,6 +20,7 @@ #include #include +#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); } diff --git a/gst-libs/gst/fft/gstffts16.c b/gst-libs/gst/fft/gstffts16.c index 8af64e3842..53135d8b98 100644 --- a/gst-libs/gst/fft/gstffts16.c +++ b/gst-libs/gst/fft/gstffts16.c @@ -20,6 +20,7 @@ #include #include +#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); } diff --git a/gst-libs/gst/fft/gstffts32.c b/gst-libs/gst/fft/gstffts32.c index 574f8250a7..2581318f5b 100644 --- a/gst-libs/gst/fft/gstffts32.c +++ b/gst-libs/gst/fft/gstffts32.c @@ -20,6 +20,7 @@ #include #include +#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); }