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

Side by Side Diff: third_party/openmax_dl/dl/sp/src/test/test_rfft16.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 int verbose;
25 int signal_value;
26
27 #define MAX_FFT_ORDER 12
28
29 void TestFFT(int fft_log_size, int signal_type, int scale_factor);
30
31 void main(int argc, char* argv[]) {
32 struct Options options;
33
34 SetDefaultOptions(&options, 1, MAX_FFT_ORDER);
35
36 ProcessCommandLine(&options, argc, argv,
37 "Test forward and inverse real 16-bit fixed-point FFT\n");
38
39 verbose = options.verbose_;
40 signal_value = options.signal_value_;
41
42 if (verbose > 255)
43 DumpOptions(stderr, &options);
44
45 if (options.test_mode_) {
46 struct TestInfo info;
47
48 info.real_only_ = options.real_only_;
49 info.max_fft_order_ = options.max_fft_order_;
50 info.min_fft_order_ = options.min_fft_order_;
51 info.do_forward_tests_ = options.do_forward_tests_;
52 info.do_inverse_tests_ = options.do_inverse_tests_;
53 /* No known failures */
54 info.known_failures_ = 0;
55 info.forward_threshold_ = 90.12;
56 info.inverse_threshold_ = 89.28;
57 signal_value = 32767;
58 RunAllTests(&info);
59 } else {
60 TestFFT(options.fft_log_size_,
61 options.signal_type_,
62 options.scale_factor_);
63 }
64 }
65
66 void GenerateSignal(OMX_S16* x, OMX_SC32* fft, int size, int signal_type) {
67 int k;
68 struct ComplexFloat *test_signal;
69 struct ComplexFloat *true_fft;
70
71 test_signal = (struct ComplexFloat*) malloc(sizeof(*test_signal) * size);
72 true_fft = (struct ComplexFloat*) malloc(sizeof(*true_fft) * size);
73 GenerateTestSignalAndFFT(test_signal, true_fft, size, signal_type,
74 signal_value, 1);
75
76 /*
77 * Convert the complex result to what we want
78 */
79
80 for (k = 0; k < size; ++k) {
81 x[k] = test_signal[k].Re;
82 }
83
84 for (k = 0; k < size / 2 + 1; ++k) {
85 fft[k].Re = true_fft[k].Re;
86 fft[k].Im = true_fft[k].Im;
87 }
88
89 free(test_signal);
90 free(true_fft);
91 }
92
93 void TestFFT(int fft_log_size, int signal_type, int scale_factor) {
94 struct SnrResult snr;
95
96 RunOneForwardTest(fft_log_size, signal_type, signal_value, &snr);
97 printf("Forward float FFT\n");
98 printf("SNR: real part %f dB\n", snr.real_snr_);
99 printf(" imag part %f dB\n", snr.imag_snr_);
100 printf(" complex part %f dB\n", snr.complex_snr_);
101
102 RunOneInverseTest(fft_log_size, signal_type, signal_value, &snr);
103 printf("Inverse float FFT\n");
104 printf("SNR: %f dB\n", snr.real_snr_);
105 }
106
107 float RunOneForwardTest(int fft_log_size, int signal_type, float signal_value,
108 struct SnrResult* snr) {
109 OMX_S16* x;
110 OMX_SC32* y;
111
112 struct AlignedPtr* x_aligned;
113 struct AlignedPtr* y_aligned;
114
115 OMX_SC32* y_true;
116
117 OMX_INT n, fft_spec_buffer_size;
118 OMXResult status;
119 OMXFFTSpec_R_S16S32 * fft_fwd_spec = NULL;
120 int fft_size;
121
122 fft_size = 1 << fft_log_size;
123
124 status = omxSP_FFTGetBufSize_R_S16S32(fft_log_size, &fft_spec_buffer_size);
125 if (verbose > 63) {
126 printf("fft_spec_buffer_size = %d\n", fft_spec_buffer_size);
127 }
128
129 fft_fwd_spec = (OMXFFTSpec_R_S16S32*) malloc(fft_spec_buffer_size);
130 status = omxSP_FFTInit_R_S16S32(fft_fwd_spec, fft_log_size);
131 if (status) {
132 fprintf(stderr, "Failed to init forward FFT: status = %d\n", status);
133 exit(1);
134 }
135
136 x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
137 y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
138 y_true = (OMX_SC32*) malloc(sizeof(*y_true) * (fft_size / 2 + 1));
139
140 x = x_aligned->aligned_pointer_;
141 y = y_aligned->aligned_pointer_;
142
143 GenerateSignal(x, y_true, fft_size, signal_type);
144
145 if (verbose > 63) {
146 printf("Signal\n");
147 DumpArrayReal16("x", fft_size, x);
148
149 printf("Expected FFT output\n");
150 DumpArrayComplex32("y", fft_size / 2, y_true);
151 }
152
153 status = omxSP_FFTFwd_RToCCS_S16S32_Sfs(x, (OMX_S32*) y, fft_fwd_spec, 0);
154 if (status) {
155 fprintf(stderr, "Forward FFT failed: status = %d\n", status);
156 exit(1);
157 }
158
159 if (verbose > 63) {
160 printf("FFT Output\n");
161 DumpArrayComplex32("y", fft_size / 2, y);
162 }
163
164 CompareComplex32(snr, y, y_true, fft_size / 2 + 1);
165
166 FreeAlignedPointer(x_aligned);
167 FreeAlignedPointer(y_aligned);
168 free(fft_fwd_spec);
169
170 return snr->complex_snr_;
171 }
172
173 float RunOneInverseTest(int fft_log_size, int signal_type, float signal_value,
174 struct SnrResult* snr) {
175 OMX_S16* x;
176 OMX_SC32* y;
177 OMX_S16* z;
178 OMX_SC32* y_true;
179
180 struct AlignedPtr* x_aligned;
181 struct AlignedPtr* y_aligned;
182 struct AlignedPtr* z_aligned;
183 struct AlignedPtr* y_true_aligned;
184
185 OMX_INT n;
186 OMX_INT fft_spec_buffer_size;
187 OMXResult status;
188 OMXFFTSpec_R_S16S32 * fft_inv_spec = NULL;
189 int fft_size;
190
191 fft_size = 1 << fft_log_size;
192
193 status = omxSP_FFTGetBufSize_R_S16S32(fft_log_size, &fft_spec_buffer_size);
194 if (verbose > 3) {
195 printf("fft_spec_buffer_size = %d\n", fft_spec_buffer_size);
196 }
197
198 fft_inv_spec = (OMXFFTSpec_R_S16S32*)malloc(fft_spec_buffer_size);
199 status = omxSP_FFTInit_R_S16S32(fft_inv_spec, fft_log_size);
200 if (status) {
201 fprintf(stderr, "Failed to init backward FFT: status = %d\n", status);
202 exit(1);
203 }
204
205 x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
206 y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size / 2 + 1));
207 z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);
208 y_true_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size / 2 + 1));
209
210 x = x_aligned->aligned_pointer_;
211 y = y_aligned->aligned_pointer_;
212 z = z_aligned->aligned_pointer_;
213 y_true = y_true_aligned->aligned_pointer_;
214
215 GenerateSignal(x, y_true, fft_size, signal_type);
216
217 if (verbose > 63) {
218 printf("Inverse FFT Input Signal\n");
219 DumpArrayComplex32("y", fft_size / 2, y_true);
220
221 printf("Expected Inverse FFT output\n");
222 DumpArrayReal16("x", fft_size, x);
223 }
224
225 status = omxSP_FFTInv_CCSToR_S32S16_Sfs((OMX_S32*) y_true, z,
226 fft_inv_spec, 0);
227 if (status) {
228 fprintf(stderr, "Inverse FFT failed: status = %d\n", status);
229 exit(1);
230 }
231
232 if (verbose > 63) {
233 printf("Actual Inverse FFT Output\n");
234 DumpArrayReal16("x", fft_size, z);
235 }
236
237 CompareReal16(snr, z, x, fft_size);
238
239 FreeAlignedPointer(x_aligned);
240 FreeAlignedPointer(y_aligned);
241 FreeAlignedPointer(z_aligned);
242 FreeAlignedPointer(y_true_aligned);
243 free(fft_inv_spec);
244
245 return snr->real_snr_;
246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698