common_audio/signal_processing: Removed macro WEBRTC_SPL_MAX_SEED_USED
* Moved the macro to randomization_functions and made it static const.
* Made WebRtc_IncreaseSeed() static, since it is not used outside this function.
* Style guide changes.
BUG=3348,3353
TESTED=trybots, common_audio_unittests, modules_unittests, modules_tests
R=tina.legrand@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/21459004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@6179 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/common_audio/signal_processing/include/signal_processing_library.h b/webrtc/common_audio/signal_processing/include/signal_processing_library.h
index 3fb64a9..05c2ef9 100644
--- a/webrtc/common_audio/signal_processing/include/signal_processing_library.h
+++ b/webrtc/common_audio/signal_processing/include/signal_processing_library.h
@@ -27,7 +27,6 @@
#define WEBRTC_SPL_WORD32_MAX (int32_t)0x7fffffff
#define WEBRTC_SPL_WORD32_MIN (int32_t)0x80000000
#define WEBRTC_SPL_MAX_LPC_ORDER 14
-#define WEBRTC_SPL_MAX_SEED_USED 0x80000000L
#define WEBRTC_SPL_MIN(A, B) (A < B ? A : B) // Get min value
#define WEBRTC_SPL_MAX(A, B) (A > B ? A : B) // Get max value
// TODO(kma/bjorn): For the next two macros, investigate how to correct the code
@@ -665,7 +664,6 @@
// Randomization functions. Implementations collected in
// randomization_functions.c and descriptions at bottom of this file.
-uint32_t WebRtcSpl_IncreaseSeed(uint32_t* seed);
int16_t WebRtcSpl_RandU(uint32_t* seed);
int16_t WebRtcSpl_RandN(uint32_t* seed);
int16_t WebRtcSpl_RandUArray(int16_t* vector,
diff --git a/webrtc/common_audio/signal_processing/randomization_functions.c b/webrtc/common_audio/signal_processing/randomization_functions.c
index e2711fd..73f2409 100644
--- a/webrtc/common_audio/signal_processing/randomization_functions.c
+++ b/webrtc/common_audio/signal_processing/randomization_functions.c
@@ -11,7 +11,6 @@
/*
* This file contains implementations of the randomization functions
- * WebRtcSpl_IncreaseSeed()
* WebRtcSpl_RandU()
* WebRtcSpl_RandN()
* WebRtcSpl_RandUArray()
@@ -22,6 +21,8 @@
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
+static const uint32_t kMaxSeedUsed = 0x80000000;
+
static const int16_t kRandNTable[] = {
9178, -7260, 40, 10189, 4894, -3531, -13779, 14764,
-4008, -8884, -8990, 1008, 7368, 5184, 3251, -5817,
@@ -89,31 +90,26 @@
2374, -5797, 11839, 8940, -11874, 18213, 2855, 10492
};
-uint32_t WebRtcSpl_IncreaseSeed(uint32_t *seed)
-{
- seed[0] = (seed[0] * ((int32_t)69069) + 1) & (WEBRTC_SPL_MAX_SEED_USED - 1);
- return seed[0];
+static uint32_t IncreaseSeed(uint32_t* seed) {
+ seed[0] = (seed[0] * ((int32_t)69069) + 1) & (kMaxSeedUsed - 1);
+ return seed[0];
}
-int16_t WebRtcSpl_RandU(uint32_t *seed)
-{
- return (int16_t)(WebRtcSpl_IncreaseSeed(seed) >> 16);
+int16_t WebRtcSpl_RandU(uint32_t* seed) {
+ return (int16_t)(IncreaseSeed(seed) >> 16);
}
-int16_t WebRtcSpl_RandN(uint32_t *seed)
-{
- return kRandNTable[WebRtcSpl_IncreaseSeed(seed) >> 23];
+int16_t WebRtcSpl_RandN(uint32_t* seed) {
+ return kRandNTable[IncreaseSeed(seed) >> 23];
}
-// Creates an array of uniformly distributed variables
+// Creates an array of uniformly distributed variables.
int16_t WebRtcSpl_RandUArray(int16_t* vector,
int16_t vector_length,
- uint32_t* seed)
-{
- int i;
- for (i = 0; i < vector_length; i++)
- {
- vector[i] = WebRtcSpl_RandU(seed);
- }
- return vector_length;
+ uint32_t* seed) {
+ int i;
+ for (i = 0; i < vector_length; i++) {
+ vector[i] = WebRtcSpl_RandU(seed);
+ }
+ return vector_length;
}
diff --git a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
index c02e106..137f138 100644
--- a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
+++ b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
@@ -489,7 +489,7 @@
int16_t b16[kVectorSize];
uint32_t bSeed = 100000;
- EXPECT_EQ(464449057u, WebRtcSpl_IncreaseSeed(&bSeed));
+ EXPECT_EQ(7086, WebRtcSpl_RandU(&bSeed));
EXPECT_EQ(31565, WebRtcSpl_RandU(&bSeed));
EXPECT_EQ(-9786, WebRtcSpl_RandN(&bSeed));
EXPECT_EQ(kVectorSize, WebRtcSpl_RandUArray(b16, kVectorSize, &bSeed));