2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
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"
27 #define MAX_FFT_ORDER 12
29 int main(int argc, char* argv[]) {
30 struct Options options;
33 SetDefaultOptions(&options, 1, MAX_FFT_ORDER);
35 ProcessCommandLine(&options, argc, argv, "Test forward and inverse real 16 \
36 -bit fixed-point FFT, with 32-bit complex FFT routines\n");
38 verbose = options.verbose_;
39 signal_value = options.signal_value_;
42 DumpOptions(stderr, &options);
45 info.real_only_ = options.real_only_;
46 info.max_fft_order_ = options.max_fft_order_;
47 info.min_fft_order_ = options.min_fft_order_;
48 info.do_forward_tests_ = options.do_forward_tests_;
49 info.do_inverse_tests_ = options.do_inverse_tests_;
50 /* No known failures */
51 info.known_failures_ = 0;
52 info.forward_threshold_ = 90.12;
53 info.inverse_threshold_ = 89.28;
55 if (options.test_mode_) {
58 TestOneFFT(options.fft_log_size_,
60 options.signal_value_,
62 "16-bit Real FFT using 32-bit complex FFT");
68 void GenerateSignal(OMX_S16* x, OMX_SC32* fft, int size, int signal_type) {
70 struct ComplexFloat *test_signal;
71 struct ComplexFloat *true_fft;
73 test_signal = (struct ComplexFloat*) malloc(sizeof(*test_signal) * size);
74 true_fft = (struct ComplexFloat*) malloc(sizeof(*true_fft) * size);
75 GenerateTestSignalAndFFT(test_signal, true_fft, size, signal_type,
79 * Convert the complex result to what we want
82 for (k = 0; k < size; ++k) {
83 x[k] = test_signal[k].Re;
86 for (k = 0; k < size / 2 + 1; ++k) {
87 fft[k].Re = true_fft[k].Re + 0.5;
88 fft[k].Im = true_fft[k].Im + 0.5;
95 float RunOneForwardTest(int fft_log_size, int signal_type, float signal_value,
96 struct SnrResult* snr) {
100 struct AlignedPtr* x_aligned;
101 struct AlignedPtr* y_aligned;
105 OMX_INT n, fft_spec_buffer_size;
107 OMXFFTSpec_R_S16S32 * fft_fwd_spec = NULL;
110 fft_size = 1 << fft_log_size;
112 status = omxSP_FFTGetBufSize_R_S16S32(fft_log_size, &fft_spec_buffer_size);
114 printf("fft_spec_buffer_size = %d\n", fft_spec_buffer_size);
117 fft_fwd_spec = (OMXFFTSpec_R_S16S32*) malloc(fft_spec_buffer_size);
118 status = omxSP_FFTInit_R_S16S32(fft_fwd_spec, fft_log_size);
120 fprintf(stderr, "Failed to init forward FFT: status = %d\n", status);
124 x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
125 y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
126 y_true = (OMX_SC32*) malloc(sizeof(*y_true) * (fft_size / 2 + 1));
128 x = x_aligned->aligned_pointer_;
129 y = y_aligned->aligned_pointer_;
131 GenerateSignal(x, y_true, fft_size, signal_type);
135 DumpArrayReal16("x", fft_size, x);
137 printf("Expected FFT output\n");
138 DumpArrayComplex32("y", fft_size / 2, y_true);
141 status = omxSP_FFTFwd_RToCCS_S16S32_Sfs(x, (OMX_S32*) y, fft_fwd_spec, 0);
143 fprintf(stderr, "Forward FFT failed: status = %d\n", status);
148 printf("FFT Output\n");
149 DumpArrayComplex32("y", fft_size / 2, y);
152 CompareComplex32(snr, y, y_true, fft_size / 2 + 1);
154 FreeAlignedPointer(x_aligned);
155 FreeAlignedPointer(y_aligned);
158 return snr->complex_snr_;
161 float RunOneInverseTest(int fft_log_size, int signal_type, float signal_value,
162 struct SnrResult* snr) {
168 struct AlignedPtr* x_aligned;
169 struct AlignedPtr* y_aligned;
170 struct AlignedPtr* z_aligned;
171 struct AlignedPtr* y_true_aligned;
174 OMX_INT fft_spec_buffer_size;
176 OMXFFTSpec_R_S16S32 * fft_inv_spec = NULL;
179 fft_size = 1 << fft_log_size;
181 status = omxSP_FFTGetBufSize_R_S16S32(fft_log_size, &fft_spec_buffer_size);
183 printf("fft_spec_buffer_size = %d\n", fft_spec_buffer_size);
186 fft_inv_spec = (OMXFFTSpec_R_S16S32*)malloc(fft_spec_buffer_size);
187 status = omxSP_FFTInit_R_S16S32(fft_inv_spec, fft_log_size);
189 fprintf(stderr, "Failed to init backward FFT: status = %d\n", status);
193 x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
194 y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size / 2 + 1));
195 z_aligned = AllocAlignedPointer(32, sizeof(*z) * fft_size);
196 y_true_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size / 2 + 1));
198 x = x_aligned->aligned_pointer_;
199 y = y_aligned->aligned_pointer_;
200 z = z_aligned->aligned_pointer_;
201 y_true = y_true_aligned->aligned_pointer_;
203 GenerateSignal(x, y_true, fft_size, signal_type);
206 printf("Inverse FFT Input Signal\n");
207 DumpArrayComplex32("y", fft_size / 2, y_true);
209 printf("Expected Inverse FFT output\n");
210 DumpArrayReal16("x", fft_size, x);
213 status = omxSP_FFTInv_CCSToR_S32S16_Sfs((OMX_S32*) y_true, z,
216 fprintf(stderr, "Inverse FFT failed: status = %d\n", status);
221 printf("Actual Inverse FFT Output\n");
222 DumpArrayReal16("x", fft_size, z);
225 CompareReal16(snr, z, x, fft_size);
227 FreeAlignedPointer(x_aligned);
228 FreeAlignedPointer(y_aligned);
229 FreeAlignedPointer(z_aligned);
230 FreeAlignedPointer(y_true_aligned);
233 return snr->real_snr_;