aboutsummaryrefslogtreecommitdiff
path: root/src/common_audio/signal_processing/spl_sqrt_floor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common_audio/signal_processing/spl_sqrt_floor.c')
-rw-r--r--src/common_audio/signal_processing/spl_sqrt_floor.c67
1 files changed, 34 insertions, 33 deletions
diff --git a/src/common_audio/signal_processing/spl_sqrt_floor.c b/src/common_audio/signal_processing/spl_sqrt_floor.c
index aa36459ec4..62041b3dc8 100644
--- a/src/common_audio/signal_processing/spl_sqrt_floor.c
+++ b/src/common_audio/signal_processing/spl_sqrt_floor.c
@@ -1,21 +1,26 @@
/*
- * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
+ * Written by Wilco Dijkstra, 1996.
+ * Refer to NOTICE file at the root of git project.
*
- * 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.
+ * Minor modifications in code style for WebRTC, 2012.
*/
+#include "signal_processing_library.h"
+
/*
- * This file contains the function WebRtcSpl_SqrtFloor().
- * The description header can be found in signal_processing_library.h
+ * Algorithm:
+ * Successive approximation of the equation (root + delta) ^ 2 = N
+ * until delta < 1. If delta < 1 we have the integer part of SQRT (N).
+ * Use delta = 2^i for i = 15 .. 0.
+ *
+ * Output precision is 16 bits. Note for large input values (close to
+ * 0x7FFFFFFF), bit 15 (the highest bit of the low 16-bit half word)
+ * contains the MSB information (a non-sign value). Do with caution
+ * if you need to cast the output to int16_t type.
*
+ * If the input value is negative, it returns 0.
*/
-#include "signal_processing_library.h"
-
#define WEBRTC_SPL_SQRT_ITER(N) \
try1 = root + (1 << (N)); \
if (value >= try1 << (N)) \
@@ -24,30 +29,26 @@
root |= 2 << (N); \
}
-// (out) Square root of input parameter
-WebRtc_Word32 WebRtcSpl_SqrtFloor(WebRtc_Word32 value)
+int32_t WebRtcSpl_SqrtFloor(int32_t value)
{
- // new routine for performance, 4 cycles/bit in ARM
- // output precision is 16 bits
-
- WebRtc_Word32 root = 0, try1;
+ int32_t 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);
+ 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;
+ return root >> 1;
}