Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: third_party/openmax_dl/dl/sp/src/test/test_float_fft.c

Issue 12317152: Add openmax dl routines for review. MUST NOT BE LANDED (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <math.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <time.h>
15 #include <unistd.h>
16
17 #include "dl/sp/api/armSP.h"
18 #include "dl/sp/api/omxSP.h"
19 #include "dl/sp/src/test/aligned_ptr.h"
20 #include "dl/sp/src/test/compare.h"
21 #include "dl/sp/src/test/gensig.h"
22 #include "dl/sp/src/test/test_util.h"
23
24 #define MAX_FFT_ORDER TWIDDLE_TABLE_ORDER
25
26 int verbose;
27
28 void TestFloatFFT(int fft_log_size, int sigtype, float signal_value);
29
30 void main(int argc, char* argv[]) {
31 struct Options options;
32
33 SetDefaultOptions(&options, 0, MAX_FFT_ORDER);
34
35 ProcessCommandLine(&options, argc, argv,
36 "Test forward and inverse floating-point FFT\n");
37
38 verbose = options.verbose_;
39
40 if (verbose > 255)
41 DumpOptions(stderr, &options);
42
43 if (options.test_mode_) {
44 struct TestInfo info;
45
46 info.real_only_ = options.real_only_;
47 info.max_fft_order_ = options.max_fft_order_;
48 info.min_fft_order_ = options.min_fft_order_;
49 info.do_forward_tests_ = options.do_forward_tests_;
50 info.do_inverse_tests_ = options.do_inverse_tests_;
51 /* No known failures */
52 info.known_failures_ = 0;
53
54 info.forward_threshold_ = 138.81;
55 info.inverse_threshold_ = 138.81;
56 RunAllTests(&info);
57 } else {
58 TestFloatFFT(options.fft_log_size_,
59 options.signal_type_,
60 options.signal_value_);
61 }
62 }
63
64 void DumpFFTSpec(OMXFFTSpec_C_FC32* pSpec) {
65 ARMsFFTSpec_FC32* p = (ARMsFFTSpec_FC32*) pSpec;
66 printf(" N = %d\n", p->N);
67 printf(" pBitRev = %p\n", p->pBitRev);
68 printf(" pTwiddle = %p\n", p->pTwiddle);
69 printf(" pBuf = %p\n", p->pBuf);
70 }
71
72 void GenerateSignal(OMX_FC32* x, OMX_FC32* fft, int size, int signal_type,
73 float signal_value) {
74 GenerateTestSignalAndFFT((struct ComplexFloat *) x,
75 (struct ComplexFloat *) fft,
76 size,
77 signal_type,
78 signal_value,
79 0);
80 }
81
82 void TestFloatFFT(int fft_log_size, int signal_type, float signal_value) {
83 struct SnrResult snr;
84
85 RunOneForwardTest(fft_log_size, signal_type, signal_value, &snr);
86 printf("Forward float FFT\n");
87 printf("SNR: real part %f dB\n", snr.real_snr_);
88 printf(" imag part %f dB\n", snr.imag_snr_);
89 printf(" complex part %f dB\n", snr.complex_snr_);
90
91 RunOneInverseTest(fft_log_size, signal_type, signal_value, &snr);
92 printf("Inverse float FFT\n");
93 printf("SNR: real part %f dB\n", snr.real_snr_);
94 printf(" imag part %f dB\n", snr.imag_snr_);
95 printf(" complex part %f dB\n", snr.complex_snr_);
96 }
97
98 float RunOneForwardTest(int fft_log_size, int signal_type, float signal_value,
99 struct SnrResult* snr) {
100 OMX_FC32* x;
101 OMX_FC32* y;
102 struct AlignedPtr* x_aligned;
103 struct AlignedPtr* y_aligned;
104
105 OMX_FC32* y_true;
106
107 OMX_INT n, fft_spec_buffer_size;
108 OMXResult status;
109 OMXFFTSpec_C_FC32 * fft_fwd_spec = NULL;
110 int fft_size;
111
112 fft_size = 1 << fft_log_size;
113
114 status = omxSP_FFTGetBufSize_C_FC32(fft_log_size, &fft_spec_buffer_size);
115 if (verbose > 63) {
116 printf("fft_spec_buffer_size = %d\n", fft_spec_buffer_size);
117 }
118
119 fft_fwd_spec = (OMXFFTSpec_C_FC32*) malloc(fft_spec_buffer_size);
120 status = omxSP_FFTInit_C_FC32(fft_fwd_spec, fft_log_size);
121 if (status) {
122 fprintf(stderr,
123 "Failed to init forward FFT: status = %d, order %d \n",
124 status, fft_log_size);
125 exit(1);
126 }
127
128 x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
129 y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
130 y_true = (OMX_FC32*) malloc(sizeof(*y_true) * fft_size);
131
132 x = x_aligned->aligned_pointer_;
133 y = y_aligned->aligned_pointer_;
134
135 GenerateSignal(x, y_true, fft_size, signal_type, signal_value);
136
137 if (verbose > 63) {
138 printf("Signal\n");
139 DumpArrayComplexFloat("x", fft_size, x);
140
141 printf("Expected FFT output\n");
142 DumpArrayComplexFloat("y", fft_size, y_true);
143 }
144
145 status = omxSP_FFTFwd_CToC_FC32_Sfs(x, y, fft_fwd_spec);
146 if (status) {
147 fprintf(stderr, "Forward FFT failed: status = %d\n", status);
148 exit(1);
149 }
150
151 if (verbose > 63) {
152 printf("FFT Output\n");
153 DumpArrayComplexFloat("y", fft_size, y);
154 }
155
156 CompareComplexFloat(snr, y, y_true, fft_size);
157
158 FreeAlignedPointer(x_aligned);
159 FreeAlignedPointer(y_aligned);
160 free(fft_fwd_spec);
161
162 return snr->complex_snr_;
163 }
164
165 float RunOneInverseTest(int fft_log_size, int signal_type, float signal_value,
166 struct SnrResult* snr) {
167 OMX_FC32* x;
168 OMX_FC32* y;
169 OMX_FC32* z;
170
171 struct AlignedPtr* x_aligned;
172 struct AlignedPtr* y_aligned;
173 struct AlignedPtr* z_aligned;
174
175 OMX_INT n, fft_spec_buffer_size;
176 OMXResult status;
177 OMXFFTSpec_C_FC32 * fft_fwd_spec = NULL;
178 OMXFFTSpec_C_FC32 * fft_inv_spec = NULL;
179 int fft_size;
180
181 fft_size = 1 << fft_log_size;
182
183 status = omxSP_FFTGetBufSize_C_FC32(fft_log_size, &fft_spec_buffer_size);
184 if (verbose > 3) {
185 printf("fft_spec_buffer_size = %d\n", fft_spec_buffer_size);
186 }
187
188 fft_inv_spec = (OMXFFTSpec_C_FC32*)malloc(fft_spec_buffer_size);
189 status = omxSP_FFTInit_C_FC32(fft_inv_spec, fft_log_size);
190 if (status) {
191 fprintf(stderr, "Failed to init backward FFT: status = %d, order %d\n",
192 status, fft_log_size);
193 exit(1);
194 }
195
196 x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
197 y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
198 z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);
199 x = x_aligned->aligned_pointer_;
200 y = y_aligned->aligned_pointer_;
201 z = z_aligned->aligned_pointer_;
202
203 GenerateSignal(x, y, fft_size, signal_type, signal_value);
204
205 if (verbose > 63) {
206 printf("Inverse FFT Input Signal\n");
207 DumpArrayComplexFloat("x", fft_size, y);
208
209 printf("Expected Inverse FFT output\n");
210 DumpArrayComplexFloat("x", fft_size, x);
211 }
212
213 status = omxSP_FFTInv_CToC_FC32_Sfs(y, z, fft_inv_spec);
214 if (status) {
215 fprintf(stderr, "Inverse FFT failed: status = %d\n", status);
216 exit(1);
217 }
218
219 if (verbose > 63) {
220 printf("Actual Inverse FFT Output\n");
221 DumpArrayComplexFloat("z", fft_size, z);
222 }
223
224 CompareComplexFloat(snr, z, x, fft_size);
225
226 FreeAlignedPointer(x_aligned);
227 FreeAlignedPointer(y_aligned);
228 FreeAlignedPointer(z_aligned);
229 free(fft_inv_spec);
230
231 return snr->complex_snr_;
232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698