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
This commit is contained in:
bjornv@webrtc.org 2014-05-16 06:38:47 +00:00
parent 75718cf80a
commit d83d607271
3 changed files with 17 additions and 23 deletions

View File

@ -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 @@ void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector,
// 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,

View File

@ -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 @@ static const int16_t kRandNTable[] = {
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;
}

View File

@ -489,7 +489,7 @@ TEST_F(SplTest, RandTest) {
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));