2 * (c) 2011 Stefan Kost <ensonic@users.sf.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include <gst/fft/gstffts16.h>
22 #include <gst/fft/gstffts32.h>
23 #include <gst/fft/gstfftf32.h>
24 #include <gst/fft/gstfftf64.h>
26 /* effectively max range seems to be 1/4 of what it should be */
28 #define MAKE_I_TEST(_g_,_G_,_t_,_T_,_f_) \
30 test_##_t_ (const gchar *test_name, gint num_freq, gint window) \
33 GstFFT ##_T_ ##Complex *fdata; \
35 _g_ maxfr = 0, maxfi = 0; \
36 gint num_samples = num_freq * 2 - 2; \
39 ctx = gst_fft_ ##_t_ ##_new (num_samples, FALSE); \
40 fdata = g_new (GstFFT ##_T_ ##Complex, num_freq); \
41 adata = g_new (_g_, num_samples); \
43 for (s = 0; s < num_samples;) { \
44 adata[s++]=G_MIN##_G_; \
45 adata[s++]=G_MAX##_G_; \
48 gst_fft_ ##_t_ ##_window (ctx, adata, window); \
49 gst_fft_ ##_t_ ##_fft (ctx, adata, fdata); \
51 for (f = 0; f < num_freq; f++) { \
52 if (fdata[1+f].r > maxfr) \
53 maxfr = fdata[1+f].r; \
54 if (fdata[1+f].i > maxfi) \
55 maxfi = fdata[1+f].i; \
58 printf (#_t_" %-15s: maxfr: %"_f_" %10.5f maxfi: %"_f_" %10.5f\n",\
60 maxfr, (gfloat)G_MAX##_G_/maxfr, \
61 maxfi, (gfloat)G_MAX##_G_/maxfi); \
63 gst_fft_ ##_t_ ##_free (ctx); \
68 MAKE_I_TEST (gint16, INT16, s16, S16, "6d");
69 MAKE_I_TEST (gint32, INT32, s32, S32, "9d");
71 #define MAKE_F_TEST(_g_,_G_,_t_,_T_,_f_) \
73 test_##_t_ (const gchar *test_name, gint num_freq, gint window) \
76 GstFFT ##_T_ ##Complex *fdata; \
78 _g_ maxfr = 0, maxfi = 0; \
79 gint num_samples = num_freq * 2 - 2; \
82 ctx = gst_fft_ ##_t_ ##_new (num_samples, FALSE); \
83 fdata = g_new (GstFFT ##_T_ ##Complex, num_freq); \
84 adata = g_new (_g_, num_samples); \
86 for (s = 0; s < num_samples;) { \
91 gst_fft_ ##_t_ ##_window (ctx, adata, window); \
92 gst_fft_ ##_t_ ##_fft (ctx, adata, fdata); \
94 for (f = 0; f < num_freq; f++) { \
95 if (fdata[1+f].r > maxfr) \
96 maxfr = fdata[1+f].r; \
97 if (fdata[1+f].i > maxfi) \
98 maxfi = fdata[1+f].i; \
101 printf (#_t_" %-15s: maxfr: %"_f_" %10.5f maxfi: %"_f_" %10.5f\n",\
103 maxfr, (gfloat)1.0/maxfr, \
104 maxfi, (gfloat)1.0/maxfi); \
106 gst_fft_ ##_t_ ##_free (ctx); \
111 MAKE_F_TEST (gfloat, FLOAT, f32, F32, "10.5f");
112 MAKE_F_TEST (gdouble, DOUBLE, f64, F64, "10.5f");
115 main (gint argc, gchar * argv[])
119 gst_init (&argc, &argv);
122 test_s16 ("200, none", num_bands, GST_FFT_WINDOW_RECTANGULAR);
123 test_s16 ("200, hamming", num_bands, GST_FFT_WINDOW_HAMMING);
124 test_s16 ("200, hann", num_bands, GST_FFT_WINDOW_HANN);
125 test_s16 ("200, bartlett", num_bands, GST_FFT_WINDOW_BARTLETT);
126 test_s16 ("200, blackman", num_bands, GST_FFT_WINDOW_BLACKMAN);
130 test_s16 ("300, none", num_bands, GST_FFT_WINDOW_RECTANGULAR);
131 test_s16 ("300, hamming", num_bands, GST_FFT_WINDOW_HAMMING);
132 test_s16 ("300, hann", num_bands, GST_FFT_WINDOW_HANN);
133 test_s16 ("300, bartlett", num_bands, GST_FFT_WINDOW_BARTLETT);
134 test_s16 ("300, blackman", num_bands, GST_FFT_WINDOW_BLACKMAN);
138 test_s32 ("200, none", num_bands, GST_FFT_WINDOW_RECTANGULAR);
139 test_s32 ("200, hamming", num_bands, GST_FFT_WINDOW_HAMMING);
140 test_s32 ("200, hann", num_bands, GST_FFT_WINDOW_HANN);
141 test_s32 ("200, bartlett", num_bands, GST_FFT_WINDOW_BARTLETT);
142 test_s32 ("200, blackman", num_bands, GST_FFT_WINDOW_BLACKMAN);
146 test_s32 ("300, none", num_bands, GST_FFT_WINDOW_RECTANGULAR);
147 test_s32 ("300, hamming", num_bands, GST_FFT_WINDOW_HAMMING);
148 test_s32 ("300, hann", num_bands, GST_FFT_WINDOW_HANN);
149 test_s32 ("300, bartlett", num_bands, GST_FFT_WINDOW_BARTLETT);
150 test_s32 ("300, blackman", num_bands, GST_FFT_WINDOW_BLACKMAN);
154 test_f32 ("200, none", num_bands, GST_FFT_WINDOW_RECTANGULAR);
155 test_f32 ("200, hamming", num_bands, GST_FFT_WINDOW_HAMMING);
156 test_f32 ("200, hann", num_bands, GST_FFT_WINDOW_HANN);
157 test_f32 ("200, bartlett", num_bands, GST_FFT_WINDOW_BARTLETT);
158 test_f32 ("200, blackman", num_bands, GST_FFT_WINDOW_BLACKMAN);
162 test_f32 ("300, none", num_bands, GST_FFT_WINDOW_RECTANGULAR);
163 test_f32 ("300, hamming", num_bands, GST_FFT_WINDOW_HAMMING);
164 test_f32 ("300, hann", num_bands, GST_FFT_WINDOW_HANN);
165 test_f32 ("300, bartlett", num_bands, GST_FFT_WINDOW_BARTLETT);
166 test_f32 ("300, blackman", num_bands, GST_FFT_WINDOW_BLACKMAN);
170 test_f64 ("200, none", num_bands, GST_FFT_WINDOW_RECTANGULAR);
171 test_f64 ("200, hamming", num_bands, GST_FFT_WINDOW_HAMMING);
172 test_f64 ("200, hann", num_bands, GST_FFT_WINDOW_HANN);
173 test_f64 ("200, bartlett", num_bands, GST_FFT_WINDOW_BARTLETT);
174 test_f64 ("200, blackman", num_bands, GST_FFT_WINDOW_BLACKMAN);
178 test_f64 ("300, none", num_bands, GST_FFT_WINDOW_RECTANGULAR);
179 test_f64 ("300, hamming", num_bands, GST_FFT_WINDOW_HAMMING);
180 test_f64 ("300, hann", num_bands, GST_FFT_WINDOW_HANN);
181 test_f64 ("300, bartlett", num_bands, GST_FFT_WINDOW_BARTLETT);
182 test_f64 ("300, blackman", num_bands, GST_FFT_WINDOW_BLACKMAN);