OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 class RealFFTTest : public ::testing::Test { | 36 class RealFFTTest : public ::testing::Test { |
37 protected: | 37 protected: |
38 RealFFTTest() { | 38 RealFFTTest() { |
39 WebRtcSpl_Init(); | 39 WebRtcSpl_Init(); |
40 } | 40 } |
41 }; | 41 }; |
42 | 42 |
43 TEST_F(RealFFTTest, CreateFailsOnBadInput) { | 43 TEST_F(RealFFTTest, CreateFailsOnBadInput) { |
44 RealFFT* fft = WebRtcSpl_CreateRealFFT(11); | 44 RealFFT* fft = WebRtcSpl_CreateRealFFT(11); |
45 EXPECT_TRUE(fft == NULL); | 45 EXPECT_TRUE(fft == nullptr); |
46 fft = WebRtcSpl_CreateRealFFT(-1); | 46 fft = WebRtcSpl_CreateRealFFT(-1); |
47 EXPECT_TRUE(fft == NULL); | 47 EXPECT_TRUE(fft == nullptr); |
48 } | 48 } |
49 | 49 |
50 TEST_F(RealFFTTest, RealAndComplexMatch) { | 50 TEST_F(RealFFTTest, RealAndComplexMatch) { |
51 int i = 0; | 51 int i = 0; |
52 int j = 0; | 52 int j = 0; |
53 int16_t real_fft_time[kTimeDataLength] = {0}; | 53 int16_t real_fft_time[kTimeDataLength] = {0}; |
54 int16_t real_fft_freq[kFreqDataLength] = {0}; | 54 int16_t real_fft_freq[kFreqDataLength] = {0}; |
55 // One common buffer for complex FFT's time and frequency data. | 55 // One common buffer for complex FFT's time and frequency data. |
56 int16_t complex_fft_buff[kComplexFftDataLength] = {0}; | 56 int16_t complex_fft_buff[kComplexFftDataLength] = {0}; |
57 | 57 |
58 // Prepare the inputs to forward FFT's. | 58 // Prepare the inputs to forward FFT's. |
59 memcpy(real_fft_time, kRefData, sizeof(kRefData)); | 59 memcpy(real_fft_time, kRefData, sizeof(kRefData)); |
60 for (i = 0, j = 0; i < kTimeDataLength; i += 1, j += 2) { | 60 for (i = 0, j = 0; i < kTimeDataLength; i += 1, j += 2) { |
61 complex_fft_buff[j] = kRefData[i]; | 61 complex_fft_buff[j] = kRefData[i]; |
62 complex_fft_buff[j + 1] = 0; // Insert zero's to imaginary parts. | 62 complex_fft_buff[j + 1] = 0; // Insert zero's to imaginary parts. |
63 }; | 63 }; |
64 | 64 |
65 // Create and run real forward FFT. | 65 // Create and run real forward FFT. |
66 RealFFT* fft = WebRtcSpl_CreateRealFFT(kOrder); | 66 RealFFT* fft = WebRtcSpl_CreateRealFFT(kOrder); |
67 EXPECT_TRUE(fft != NULL); | 67 EXPECT_TRUE(fft != nullptr); |
68 EXPECT_EQ(0, WebRtcSpl_RealForwardFFT(fft, real_fft_time, real_fft_freq)); | 68 EXPECT_EQ(0, WebRtcSpl_RealForwardFFT(fft, real_fft_time, real_fft_freq)); |
69 | 69 |
70 // Run complex forward FFT. | 70 // Run complex forward FFT. |
71 WebRtcSpl_ComplexBitReverse(complex_fft_buff, kOrder); | 71 WebRtcSpl_ComplexBitReverse(complex_fft_buff, kOrder); |
72 EXPECT_EQ(0, WebRtcSpl_ComplexFFT(complex_fft_buff, kOrder, 1)); | 72 EXPECT_EQ(0, WebRtcSpl_ComplexFFT(complex_fft_buff, kOrder, 1)); |
73 | 73 |
74 // Verify the results between complex and real forward FFT. | 74 // Verify the results between complex and real forward FFT. |
75 for (i = 0; i < kFreqDataLength; i++) { | 75 for (i = 0; i < kFreqDataLength; i++) { |
76 EXPECT_EQ(real_fft_freq[i], complex_fft_buff[i]); | 76 EXPECT_EQ(real_fft_freq[i], complex_fft_buff[i]); |
77 } | 77 } |
(...skipping 19 matching lines...) Expand all Loading... |
97 EXPECT_EQ(real_scale, complex_scale); | 97 EXPECT_EQ(real_scale, complex_scale); |
98 for (i = 0, j = 0; i < kTimeDataLength; i += 1, j += 2) { | 98 for (i = 0, j = 0; i < kTimeDataLength; i += 1, j += 2) { |
99 EXPECT_LE(abs(real_fft_time[i] - complex_fft_buff[j]), 1); | 99 EXPECT_LE(abs(real_fft_time[i] - complex_fft_buff[j]), 1); |
100 } | 100 } |
101 | 101 |
102 WebRtcSpl_FreeRealFFT(fft); | 102 WebRtcSpl_FreeRealFFT(fft); |
103 } | 103 } |
104 | 104 |
105 } // namespace | 105 } // namespace |
106 } // namespace webrtc | 106 } // namespace webrtc |
OLD | NEW |