diff --git a/src/common_audio/signal_processing_library/main/interface/signal_processing_library.h b/src/common_audio/signal_processing_library/main/interface/signal_processing_library.h index b59a236b42..414e0450c0 100644 --- a/src/common_audio/signal_processing_library/main/interface/signal_processing_library.h +++ b/src/common_audio/signal_processing_library/main/interface/signal_processing_library.h @@ -379,6 +379,7 @@ WebRtc_Word16 WebRtcSpl_RandUArray(WebRtc_Word16* vector, // Math functions WebRtc_Word32 WebRtcSpl_Sqrt(WebRtc_Word32 value); +WebRtc_Word32 WebRtcSpl_SqrtFloor(WebRtc_Word32 value); // Divisions. Implementations collected in division_operations.c and // descriptions at bottom of this file. @@ -1319,6 +1320,23 @@ void WebRtcSpl_SynthesisQMF(const WebRtc_Word16* low_band, // Return value : Result of the sqrt calculation // +// +// WebRtcSpl_SqrtFloor(...) +// +// Returns the square root of the input value |value|. The precision of this +// function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer. +// If |value| is a negative number then 0 is returned. +// +// Algorithm: +// +// An iterative 4 cylce/bit routine +// +// Input: +// - value : Value to calculate sqrt of +// +// Return value : Result of the sqrt calculation +// + // // WebRtcSpl_DivU32U16(...) // diff --git a/src/common_audio/signal_processing_library/main/source/spl.gyp b/src/common_audio/signal_processing_library/main/source/spl.gyp index 2dfa0fc9b9..9c052fc607 100644 --- a/src/common_audio/signal_processing_library/main/source/spl.gyp +++ b/src/common_audio/signal_processing_library/main/source/spl.gyp @@ -65,6 +65,7 @@ 'sin_table.c', 'sin_table_1024.c', 'spl_sqrt.c', + 'spl_sqrt_floor.c', 'spl_version.c', 'splitting_filter.c', 'sqrt_of_one_minus_x_squared.c', diff --git a/src/common_audio/signal_processing_library/main/source/spl_sqrt_floor.c b/src/common_audio/signal_processing_library/main/source/spl_sqrt_floor.c new file mode 100644 index 0000000000..aa36459ec4 --- /dev/null +++ b/src/common_audio/signal_processing_library/main/source/spl_sqrt_floor.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +/* + * This file contains the function WebRtcSpl_SqrtFloor(). + * The description header can be found in signal_processing_library.h + * + */ + +#include "signal_processing_library.h" + +#define WEBRTC_SPL_SQRT_ITER(N) \ + try1 = root + (1 << (N)); \ + if (value >= try1 << (N)) \ + { \ + value -= try1 << (N); \ + root |= 2 << (N); \ + } + +// (out) Square root of input parameter +WebRtc_Word32 WebRtcSpl_SqrtFloor(WebRtc_Word32 value) +{ + // new routine for performance, 4 cycles/bit in ARM + // output precision is 16 bits + + WebRtc_Word32 root = 0, try1; + + WEBRTC_SPL_SQRT_ITER (15); + WEBRTC_SPL_SQRT_ITER (14); + WEBRTC_SPL_SQRT_ITER (13); + WEBRTC_SPL_SQRT_ITER (12); + WEBRTC_SPL_SQRT_ITER (11); + WEBRTC_SPL_SQRT_ITER (10); + WEBRTC_SPL_SQRT_ITER ( 9); + WEBRTC_SPL_SQRT_ITER ( 8); + WEBRTC_SPL_SQRT_ITER ( 7); + WEBRTC_SPL_SQRT_ITER ( 6); + WEBRTC_SPL_SQRT_ITER ( 5); + WEBRTC_SPL_SQRT_ITER ( 4); + WEBRTC_SPL_SQRT_ITER ( 3); + WEBRTC_SPL_SQRT_ITER ( 2); + WEBRTC_SPL_SQRT_ITER ( 1); + WEBRTC_SPL_SQRT_ITER ( 0); + + return root >> 1; +} diff --git a/src/common_audio/signal_processing_library/main/test/unit_test/unit_test.cc b/src/common_audio/signal_processing_library/main/test/unit_test/unit_test.cc index 19cc553f65..5adc339130 100644 --- a/src/common_audio/signal_processing_library/main/test/unit_test/unit_test.cc +++ b/src/common_audio/signal_processing_library/main/test/unit_test/unit_test.cc @@ -147,6 +147,7 @@ TEST_F(SplTest, MathOperationsTest) { WebRtc_Word32 den = -5; WebRtc_UWord16 denU = 5; EXPECT_EQ(10, WebRtcSpl_Sqrt(A)); + EXPECT_EQ(10, WebRtcSpl_SqrtFloor(A)); EXPECT_EQ(-91772805, WebRtcSpl_DivResultInQ31(den, num));