1 /*
2  *  Copyright (c) 2012 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 "modules/audio_coding/codecs/isac/fix/source/codec.h"
12 #include "system_wrappers/include/cpu_features_wrapper.h"
13 #include "test/gtest.h"
14 #include "typedefs.h"  // NOLINT(build/include)
15 
16 class FiltersTest : public testing::Test {
17  protected:
18   // Pass a function pointer to the Tester function.
FiltersTester(AutocorrFix WebRtcIsacfix_AutocorrFixFunction)19   void FiltersTester(AutocorrFix WebRtcIsacfix_AutocorrFixFunction) {
20     const int kOrder = 12;
21     const int kBuffer = 40;
22     int16_t scale = 0;
23     int32_t r_buffer[kOrder + 2] = {0};
24 
25     // Test an overflow case.
26     const int16_t x_buffer_0[kBuffer] = {0, 0, 3010, 22351, 21106, 16969, -2095,
27         -664, 3513, -30980, 32767, -23839, 13335, 20289, -6831, 339, -17207,
28         32767, 4959, 6177, 32767, 16599, -4747, 20504, 3513, -30980, 32767,
29         -23839, 13335, 20289, 0, -16969, -2095, -664, 3513, 31981, 32767,
30         -13839, 23336, 30281};
31     const int32_t r_expected_0[kOrder + 2] = {1872498461, -224288754, 203789985,
32         483400487, -208272635, 2436500, 137785322, 266600814, -208486262,
33         329510080, 137949184, -161738972, -26894267, 237630192};
34 
35     WebRtcIsacfix_AutocorrFixFunction(r_buffer, x_buffer_0,
36                                       kBuffer, kOrder + 1, &scale);
37     for (int i = 0; i < kOrder + 2; i++) {
38       EXPECT_EQ(r_expected_0[i], r_buffer[i]);
39     }
40     EXPECT_EQ(3, scale);
41 
42     // Test a no-overflow case.
43     const int16_t x_buffer_1[kBuffer] = {0, 0, 300, 21, 206, 169, -295,
44         -664, 3513, -300, 327, -29, 15, 289, -6831, 339, -107,
45         37, 59, 6177, 327, 169, -4747, 204, 313, -980, 767,
46         -9, 135, 289, 0, -6969, -2095, -664, 0, 1, 7,
47         -39, 236, 281};
48     const int32_t r_expected_1[kOrder + 2] = {176253864, 8126617, 1983287,
49         -26196788, -3487363, -42839676, -24644043, 3469813, 30559879, 31905045,
50         5101567, 29328896, -55787438, -13163978};
51 
52     WebRtcIsacfix_AutocorrFixFunction(r_buffer, x_buffer_1,
53                                       kBuffer, kOrder + 1, &scale);
54     for (int i = 0; i < kOrder + 2; i++) {
55       EXPECT_EQ(r_expected_1[i], r_buffer[i]);
56     }
57     EXPECT_EQ(0, scale);
58   }
59 };
60 
TEST_F(FiltersTest,AutocorrFixTest)61 TEST_F(FiltersTest, AutocorrFixTest) {
62   FiltersTester(WebRtcIsacfix_AutocorrC);
63 #if defined(WEBRTC_HAS_NEON)
64   FiltersTester(WebRtcIsacfix_AutocorrNeon);
65 #endif
66 }
67