Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_coding / codecs / isac / fix / source / lpc_masking_model_unittest.cc
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 "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/modules/audio_coding/codecs/isac/fix/source/lpc_masking_model.h"
13 #include "webrtc/system_wrappers/interface/cpu_features_wrapper.h"
14 #include "webrtc/typedefs.h"
15
16 class LpcMaskingModelTest : public testing::Test {
17  protected:
18   // Pass a function pointer to the Tester function.
19   void CalculateResidualEnergyTester(CalculateResidualEnergy
20                                      CalculateResidualEnergyFunction) {
21     const int kIntOrder = 10;
22     const int32_t kInt32QDomain = 5;
23     const int kIntShift = 11;
24     int16_t a[kIntOrder + 1] = {32760, 122, 7, 0, -32760, -3958,
25         -48, 18745, 498, 9, 23456};
26     int32_t corr[kIntOrder + 1] = {11443647, -27495, 0,
27         98745, -11443600, 1, 1, 498, 9, 888, 23456};
28     int q_shift_residual = 0;
29     int32_t residual_energy = 0;
30
31     // Test the code path where (residual_energy >= 0x10000).
32     residual_energy = CalculateResidualEnergyFunction(kIntOrder,
33         kInt32QDomain, kIntShift, a, corr, &q_shift_residual);
34     EXPECT_EQ(1789023310, residual_energy);
35     EXPECT_EQ(2, q_shift_residual);
36
37     // Test the code path where (residual_energy < 0x10000)
38     // and ((energy & 0x8000) != 0).
39     for (int i = 0; i < kIntOrder + 1; i++) {
40       a[i] = 24575 >> i;
41       corr[i] = i;
42     }
43     residual_energy = CalculateResidualEnergyFunction(kIntOrder,
44         kInt32QDomain, kIntShift, a, corr, &q_shift_residual);
45     EXPECT_EQ(1595279092, residual_energy);
46     EXPECT_EQ(26, q_shift_residual);
47
48     // Test the code path where (residual_energy <= 0x7fff).
49     for (int i = 0; i < kIntOrder + 1; i++) {
50       a[i] = 2457 >> i;
51     }
52     residual_energy = CalculateResidualEnergyFunction(kIntOrder,
53         kInt32QDomain, kIntShift, a, corr, &q_shift_residual);
54     EXPECT_EQ(2029266944, residual_energy);
55     EXPECT_EQ(33, q_shift_residual);
56   }
57 };
58
59 TEST_F(LpcMaskingModelTest, CalculateResidualEnergyTest) {
60   CalculateResidualEnergyTester(WebRtcIsacfix_CalculateResidualEnergyC);
61 #ifdef WEBRTC_DETECT_ARM_NEON
62   if ((WebRtc_GetCPUFeaturesARM() & kCPUFeatureNEON) != 0) {
63     CalculateResidualEnergyTester(WebRtcIsacfix_CalculateResidualEnergyNeon);
64   }
65 #elif defined(WEBRTC_ARCH_ARM_NEON)
66   CalculateResidualEnergyTester(WebRtcIsacfix_CalculateResidualEnergyNeon);
67 #endif
68 }