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