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