~ubuntu-branches/ubuntu/precise/gst-plugins-base0.10/precise-updates

« back to all changes in this revision

Viewing changes to tests/examples/fft/fftrange.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2011-12-12 12:40:13 UTC
  • mfrom: (36.1.15 experimental)
  • Revision ID: package-import@ubuntu.com-20111212124013-onyadfb150d8c5dk
Tags: 0.10.35.2-2
* debian/libgstreamer-plugins-base.install:
  + Add license translations file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GStreamer
 
2
 * (c) 2011 Stefan Kost <ensonic@users.sf.net>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include <stdio.h>
 
21
#include <gst/fft/gstffts16.h>
 
22
#include <gst/fft/gstffts32.h>
 
23
#include <gst/fft/gstfftf32.h>
 
24
#include <gst/fft/gstfftf64.h>
 
25
 
 
26
/* effectively max range seems to be 1/4 of what it should be */
 
27
 
 
28
#define MAKE_I_TEST(_g_,_G_,_t_,_T_,_f_)                        \
 
29
static void                                                     \
 
30
test_##_t_ (const gchar *test_name, gint num_freq, gint window) \
 
31
{                                                               \
 
32
  GstFFT ##_T_ *ctx;                                            \
 
33
  GstFFT ##_T_ ##Complex *fdata;                                \
 
34
  _g_ *adata;                                                   \
 
35
  _g_ maxfr = 0, maxfi = 0;                                     \
 
36
  gint num_samples = num_freq * 2 - 2;                          \
 
37
  gint s, f;                                                    \
 
38
                                                                \
 
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);                             \
 
42
                                                                \
 
43
  for (s = 0; s < num_samples;) {                               \
 
44
    adata[s++]=G_MIN##_G_;                                      \
 
45
    adata[s++]=G_MAX##_G_;                                      \
 
46
  }                                                             \
 
47
                                                                \
 
48
  gst_fft_ ##_t_ ##_window (ctx, adata, window);                \
 
49
  gst_fft_ ##_t_ ##_fft (ctx, adata, fdata);                    \
 
50
                                                                \
 
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;                                     \
 
56
  }                                                             \
 
57
                                                                \
 
58
  printf (#_t_" %-15s: maxfr: %"_f_" %10.5f maxfi: %"_f_" %10.5f\n",\
 
59
    test_name,                                                  \
 
60
    maxfr, (gfloat)G_MAX##_G_/maxfr,                            \
 
61
    maxfi, (gfloat)G_MAX##_G_/maxfi);                           \
 
62
                                                                \
 
63
  gst_fft_ ##_t_ ##_free (ctx);                                 \
 
64
  g_free (fdata);                                               \
 
65
  g_free (adata);                                               \
 
66
}
 
67
 
 
68
MAKE_I_TEST (gint16, INT16, s16, S16, "6d");
 
69
MAKE_I_TEST (gint32, INT32, s32, S32, "9d");
 
70
 
 
71
#define MAKE_F_TEST(_g_,_G_,_t_,_T_,_f_)                        \
 
72
static void                                                     \
 
73
test_##_t_ (const gchar *test_name, gint num_freq, gint window) \
 
74
{                                                               \
 
75
  GstFFT ##_T_ *ctx;                                            \
 
76
  GstFFT ##_T_ ##Complex *fdata;                                \
 
77
  _g_ *adata;                                                   \
 
78
  _g_ maxfr = 0, maxfi = 0;                                     \
 
79
  gint num_samples = num_freq * 2 - 2;                          \
 
80
  gint s, f;                                                    \
 
81
                                                                \
 
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);                             \
 
85
                                                                \
 
86
  for (s = 0; s < num_samples;) {                               \
 
87
    adata[s++]=-1.0;                                            \
 
88
    adata[s++]=+1.0;                                            \
 
89
  }                                                             \
 
90
                                                                \
 
91
  gst_fft_ ##_t_ ##_window (ctx, adata, window);                \
 
92
  gst_fft_ ##_t_ ##_fft (ctx, adata, fdata);                    \
 
93
                                                                \
 
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;                                     \
 
99
  }                                                             \
 
100
                                                                \
 
101
  printf (#_t_" %-15s: maxfr: %"_f_" %10.5f maxfi: %"_f_" %10.5f\n",\
 
102
    test_name,                                                  \
 
103
    maxfr, (gfloat)1.0/maxfr,                                   \
 
104
    maxfi, (gfloat)1.0/maxfi);                                  \
 
105
                                                                \
 
106
  gst_fft_ ##_t_ ##_free (ctx);                                 \
 
107
  g_free (fdata);                                               \
 
108
  g_free (adata);                                               \
 
109
}
 
110
 
 
111
MAKE_F_TEST (gfloat, FLOAT, f32, F32, "10.5f");
 
112
MAKE_F_TEST (gdouble, DOUBLE, f64, F64, "10.5f");
 
113
 
 
114
gint
 
115
main (gint argc, gchar * argv[])
 
116
{
 
117
  gint num_bands;
 
118
 
 
119
  gst_init (&argc, &argv);
 
120
 
 
121
  num_bands = 200;
 
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);
 
127
  puts ("");
 
128
 
 
129
  num_bands = 300;
 
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);
 
135
  puts ("\n");
 
136
 
 
137
  num_bands = 200;
 
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);
 
143
  puts ("");
 
144
 
 
145
  num_bands = 300;
 
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);
 
151
  puts ("\n");
 
152
 
 
153
  num_bands = 200;
 
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);
 
159
  puts ("");
 
160
 
 
161
  num_bands = 300;
 
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);
 
167
  puts ("\n");
 
168
 
 
169
  num_bands = 200;
 
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);
 
175
  puts ("");
 
176
 
 
177
  num_bands = 300;
 
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);
 
183
  puts ("\n");
 
184
}