diff --git a/webrtc/common_audio/signal_processing/auto_correlation.c b/webrtc/common_audio/signal_processing/auto_correlation.c index 8d6c879ca7..fda4fffeed 100644 --- a/webrtc/common_audio/signal_processing/auto_correlation.c +++ b/webrtc/common_audio/signal_processing/auto_correlation.c @@ -10,20 +10,19 @@ #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" -int WebRtcSpl_AutoCorrelation(const int16_t* in_vector, - size_t in_vector_length, - size_t order, - int32_t* result, - int* scale) { +#include + +size_t WebRtcSpl_AutoCorrelation(const int16_t* in_vector, + size_t in_vector_length, + size_t order, + int32_t* result, + int* scale) { int32_t sum = 0; size_t i = 0, j = 0; int16_t smax = 0; int scaling = 0; - if (order > in_vector_length) { - /* Undefined */ - return -1; - } + assert(order <= in_vector_length); // Find the maximum absolute value of the samples. smax = WebRtcSpl_MaxAbsValueW16(in_vector, in_vector_length); @@ -62,5 +61,5 @@ int WebRtcSpl_AutoCorrelation(const int16_t* in_vector, } *scale = scaling; - return (int)(order + 1); + return order + 1; } 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 37c21e7577..2e96883e6d 100644 --- a/webrtc/common_audio/signal_processing/include/signal_processing_library.h +++ b/webrtc/common_audio/signal_processing/include/signal_processing_library.h @@ -149,8 +149,7 @@ void WebRtcSpl_ZerosArrayW32(int32_t* vector, // - vector : 16-bit input vector. // - length : Number of samples in vector. // -// Return value : Maximum absolute value in vector; -// or -1, if (vector == NULL || length == 0). +// Return value : Maximum absolute value in vector. typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, size_t length); extern MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16; int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length); @@ -167,8 +166,7 @@ int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length); // - vector : 32-bit input vector. // - length : Number of samples in vector. // -// Return value : Maximum absolute value in vector; -// or -1, if (vector == NULL || length == 0). +// Return value : Maximum absolute value in vector. typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, size_t length); extern MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32; int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length); @@ -186,9 +184,6 @@ int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length); // - length : Number of samples in vector. // // Return value : Maximum sample value in |vector|. -// If (vector == NULL || length == 0) WEBRTC_SPL_WORD16_MIN -// is returned. Note that WEBRTC_SPL_WORD16_MIN is a feasible -// value and we can't catch errors purely based on it. typedef int16_t (*MaxValueW16)(const int16_t* vector, size_t length); extern MaxValueW16 WebRtcSpl_MaxValueW16; int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length); @@ -206,9 +201,6 @@ int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length); // - length : Number of samples in vector. // // Return value : Maximum sample value in |vector|. -// If (vector == NULL || length == 0) WEBRTC_SPL_WORD32_MIN -// is returned. Note that WEBRTC_SPL_WORD32_MIN is a feasible -// value and we can't catch errors purely based on it. typedef int32_t (*MaxValueW32)(const int32_t* vector, size_t length); extern MaxValueW32 WebRtcSpl_MaxValueW32; int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length); @@ -226,9 +218,6 @@ int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length); // - length : Number of samples in vector. // // Return value : Minimum sample value in |vector|. -// If (vector == NULL || length == 0) WEBRTC_SPL_WORD16_MAX -// is returned. Note that WEBRTC_SPL_WORD16_MAX is a feasible -// value and we can't catch errors purely based on it. typedef int16_t (*MinValueW16)(const int16_t* vector, size_t length); extern MinValueW16 WebRtcSpl_MinValueW16; int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length); @@ -246,9 +235,6 @@ int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length); // - length : Number of samples in vector. // // Return value : Minimum sample value in |vector|. -// If (vector == NULL || length == 0) WEBRTC_SPL_WORD32_MAX -// is returned. Note that WEBRTC_SPL_WORD32_MAX is a feasible -// value and we can't catch errors purely based on it. typedef int32_t (*MinValueW32)(const int32_t* vector, size_t length); extern MinValueW32 WebRtcSpl_MinValueW32; int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length); @@ -265,12 +251,11 @@ int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length); // - vector : 16-bit input vector. // - length : Number of samples in vector. // -// Return value : Index to the maximum absolute value in vector, or -1, -// if (vector == NULL || length == 0). +// Return value : Index to the maximum absolute value in vector. // If there are multiple equal maxima, return the index of the // first. -32768 will always have precedence over 32767 (despite -// -32768 presenting an int16 absolute value of 32767); -int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length); +// -32768 presenting an int16 absolute value of 32767). +size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length); // Returns the vector index to the maximum sample value of a 16-bit vector. // @@ -279,9 +264,8 @@ int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length); // - length : Number of samples in vector. // // Return value : Index to the maximum value in vector (if multiple -// indexes have the maximum, return the first); -// or -1, if (vector == NULL || length == 0). -int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length); +// indexes have the maximum, return the first). +size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length); // Returns the vector index to the maximum sample value of a 32-bit vector. // @@ -290,9 +274,8 @@ int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length); // - length : Number of samples in vector. // // Return value : Index to the maximum value in vector (if multiple -// indexes have the maximum, return the first); -// or -1, if (vector == NULL || length == 0). -int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length); +// indexes have the maximum, return the first). +size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length); // Returns the vector index to the minimum sample value of a 16-bit vector. // @@ -301,9 +284,8 @@ int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length); // - length : Number of samples in vector. // // Return value : Index to the mimimum value in vector (if multiple -// indexes have the minimum, return the first); -// or -1, if (vector == NULL || length == 0). -int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length); +// indexes have the minimum, return the first). +size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length); // Returns the vector index to the minimum sample value of a 32-bit vector. // @@ -312,9 +294,8 @@ int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length); // - length : Number of samples in vector. // // Return value : Index to the mimimum value in vector (if multiple -// indexes have the minimum, return the first); -// or -1, if (vector == NULL || length == 0). -int WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length); +// indexes have the minimum, return the first). +size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length); // End: Minimum and maximum operations. @@ -443,14 +424,12 @@ void WebRtcSpl_AffineTransformVector(int16_t* out_vector, // - scale : The number of left shifts required to obtain the // auto-correlation in Q0 // -// Return value : -// - -1, if |order| > |in_vector_length|; -// - Number of samples in |result|, i.e. (order+1), otherwise. -int WebRtcSpl_AutoCorrelation(const int16_t* in_vector, - size_t in_vector_length, - size_t order, - int32_t* result, - int* scale); +// Return value : Number of samples in |result|, i.e. (order+1) +size_t WebRtcSpl_AutoCorrelation(const int16_t* in_vector, + size_t in_vector_length, + size_t order, + int32_t* result, + int* scale); // A 32-bit fix-point implementation of the Levinson-Durbin algorithm that // does NOT use the 64 bit class diff --git a/webrtc/common_audio/signal_processing/min_max_operations.c b/webrtc/common_audio/signal_processing/min_max_operations.c index 22ce765455..4a962f86a0 100644 --- a/webrtc/common_audio/signal_processing/min_max_operations.c +++ b/webrtc/common_audio/signal_processing/min_max_operations.c @@ -24,10 +24,11 @@ * */ -#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" - +#include #include +#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" + // TODO(bjorn/kma): Consolidate function pairs (e.g. combine // WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.) // TODO(kma): Move the next six functions into min_max_operations_c.c. @@ -37,9 +38,7 @@ int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) { size_t i = 0; int absolute = 0, maximum = 0; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); for (i = 0; i < length; i++) { absolute = abs((int)vector[i]); @@ -65,9 +64,7 @@ int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) { uint32_t absolute = 0, maximum = 0; size_t i = 0; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); for (i = 0; i < length; i++) { absolute = abs((int)vector[i]); @@ -86,9 +83,7 @@ int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) { int16_t maximum = WEBRTC_SPL_WORD16_MIN; size_t i = 0; - if (vector == NULL || length == 0) { - return maximum; - } + assert(length > 0); for (i = 0; i < length; i++) { if (vector[i] > maximum) @@ -102,9 +97,7 @@ int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) { int32_t maximum = WEBRTC_SPL_WORD32_MIN; size_t i = 0; - if (vector == NULL || length == 0) { - return maximum; - } + assert(length > 0); for (i = 0; i < length; i++) { if (vector[i] > maximum) @@ -118,9 +111,7 @@ int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) { int16_t minimum = WEBRTC_SPL_WORD16_MAX; size_t i = 0; - if (vector == NULL || length == 0) { - return minimum; - } + assert(length > 0); for (i = 0; i < length; i++) { if (vector[i] < minimum) @@ -134,9 +125,7 @@ int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) { int32_t minimum = WEBRTC_SPL_WORD32_MAX; size_t i = 0; - if (vector == NULL || length == 0) { - return minimum; - } + assert(length > 0); for (i = 0; i < length; i++) { if (vector[i] < minimum) @@ -146,15 +135,13 @@ int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) { } // Index of maximum absolute value in a word16 vector. -int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) { +size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) { // Use type int for local variables, to accomodate the value of abs(-32768). size_t i = 0, index = 0; int absolute = 0, maximum = 0; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); for (i = 0; i < length; i++) { absolute = abs((int)vector[i]); @@ -165,17 +152,15 @@ int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) { } } - return (int)index; + return index; } // Index of maximum value in a word16 vector. -int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) { +size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) { size_t i = 0, index = 0; int16_t maximum = WEBRTC_SPL_WORD16_MIN; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); for (i = 0; i < length; i++) { if (vector[i] > maximum) { @@ -184,17 +169,15 @@ int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) { } } - return (int)index; + return index; } // Index of maximum value in a word32 vector. -int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) { +size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) { size_t i = 0, index = 0; int32_t maximum = WEBRTC_SPL_WORD32_MIN; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); for (i = 0; i < length; i++) { if (vector[i] > maximum) { @@ -203,17 +186,15 @@ int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) { } } - return (int)index; + return index; } // Index of minimum value in a word16 vector. -int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) { +size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) { size_t i = 0, index = 0; int16_t minimum = WEBRTC_SPL_WORD16_MAX; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); for (i = 0; i < length; i++) { if (vector[i] < minimum) { @@ -222,17 +203,15 @@ int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) { } } - return (int)index; + return index; } // Index of minimum value in a word32 vector. -int WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) { +size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) { size_t i = 0, index = 0; int32_t minimum = WEBRTC_SPL_WORD32_MAX; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); for (i = 0; i < length; i++) { if (vector[i] < minimum) { @@ -241,5 +220,5 @@ int WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) { } } - return (int)index; + return index; } diff --git a/webrtc/common_audio/signal_processing/min_max_operations_mips.c b/webrtc/common_audio/signal_processing/min_max_operations_mips.c index a7d3251c6f..28de45b3a5 100644 --- a/webrtc/common_audio/signal_processing/min_max_operations_mips.c +++ b/webrtc/common_audio/signal_processing/min_max_operations_mips.c @@ -16,6 +16,8 @@ * */ +#include + #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" // Maximum absolute value of word16 vector. @@ -24,9 +26,8 @@ int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length) { int32_t tmp32_0, tmp32_1, tmp32_2, tmp32_3; size_t i, loop_size; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); + #if defined(MIPS_DSP_R1) const int32_t* tmpvec32 = (int32_t*)vector; loop_size = length >> 4; @@ -229,9 +230,7 @@ int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length) { uint32_t absolute = 0, maximum = 0; int tmp1 = 0, max_value = 0x7fffffff; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); __asm__ volatile ( ".set push \n\t" @@ -265,9 +264,7 @@ int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length) { int tmp1; int16_t value; - if (vector == NULL || length == 0) { - return maximum; - } + assert(length > 0); __asm__ volatile ( ".set push \n\t" @@ -295,9 +292,7 @@ int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length) { int32_t maximum = WEBRTC_SPL_WORD32_MIN; int tmp1, value; - if (vector == NULL || length == 0) { - return maximum; - } + assert(length > 0); __asm__ volatile ( ".set push \n\t" @@ -327,9 +322,7 @@ int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length) { int tmp1; int16_t value; - if (vector == NULL || length == 0) { - return minimum; - } + assert(length > 0); __asm__ volatile ( ".set push \n\t" @@ -358,9 +351,7 @@ int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length) { int32_t minimum = WEBRTC_SPL_WORD32_MAX; int tmp1, value; - if (vector == NULL || length == 0) { - return minimum; - } + assert(length > 0); __asm__ volatile ( ".set push \n\t" diff --git a/webrtc/common_audio/signal_processing/min_max_operations_neon.c b/webrtc/common_audio/signal_processing/min_max_operations_neon.c index ee8bef1a9c..6fbbf94ee0 100644 --- a/webrtc/common_audio/signal_processing/min_max_operations_neon.c +++ b/webrtc/common_audio/signal_processing/min_max_operations_neon.c @@ -9,6 +9,7 @@ */ #include +#include #include #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" @@ -17,9 +18,7 @@ int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length) { int absolute = 0, maximum = 0; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); const int16_t* p_start = vector; size_t rest = length & 7; @@ -77,9 +76,7 @@ int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, size_t length) { size_t i = 0; size_t residual = length & 0x7; - if (vector == NULL || length == 0) { - return -1; - } + assert(length > 0); const int32_t* p_start = vector; uint32x4_t max32x4_0 = vdupq_n_u32(0); @@ -131,9 +128,7 @@ int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, size_t length) { size_t i = 0; size_t residual = length & 0x7; - if (vector == NULL || length == 0) { - return maximum; - } + assert(length > 0); const int16_t* p_start = vector; int16x8_t max16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MIN); @@ -171,9 +166,7 @@ int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, size_t length) { size_t i = 0; size_t residual = length & 0x7; - if (vector == NULL || length == 0) { - return maximum; - } + assert(length > 0); const int32_t* p_start = vector; int32x4_t max32x4_0 = vdupq_n_s32(WEBRTC_SPL_WORD32_MIN); @@ -215,9 +208,7 @@ int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, size_t length) { size_t i = 0; size_t residual = length & 0x7; - if (vector == NULL || length == 0) { - return minimum; - } + assert(length > 0); const int16_t* p_start = vector; int16x8_t min16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MAX); @@ -255,9 +246,7 @@ int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, size_t length) { size_t i = 0; size_t residual = length & 0x7; - if (vector == NULL || length == 0) { - return minimum; - } + assert(length > 0); const int32_t* p_start = vector; int32x4_t min32x4_0 = vdupq_n_s32(WEBRTC_SPL_WORD32_MAX); diff --git a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc index a593c4d5bc..108f459c89 100644 --- a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc +++ b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc @@ -221,36 +221,6 @@ TEST_F(SplTest, BasicArrayOperationsTest) { } } -TEST_F(SplTest, ExeptionsHandlingMinMaxOperationsTest) { - // Test how the functions handle exceptional cases. - const size_t kVectorSize = 2; - int16_t vector16[kVectorSize] = {0}; - int32_t vector32[kVectorSize] = {0}; - - EXPECT_EQ(-1, WebRtcSpl_MaxAbsValueW16(vector16, 0)); - EXPECT_EQ(-1, WebRtcSpl_MaxAbsValueW16(NULL, kVectorSize)); - EXPECT_EQ(WEBRTC_SPL_WORD16_MIN, WebRtcSpl_MaxValueW16(vector16, 0)); - EXPECT_EQ(WEBRTC_SPL_WORD16_MIN, WebRtcSpl_MaxValueW16(NULL, kVectorSize)); - EXPECT_EQ(WEBRTC_SPL_WORD16_MAX, WebRtcSpl_MinValueW16(vector16, 0)); - EXPECT_EQ(WEBRTC_SPL_WORD16_MAX, WebRtcSpl_MinValueW16(NULL, kVectorSize)); - EXPECT_EQ(-1, WebRtcSpl_MaxAbsValueW32(vector32, 0)); - EXPECT_EQ(-1, WebRtcSpl_MaxAbsValueW32(NULL, kVectorSize)); - EXPECT_EQ(WEBRTC_SPL_WORD32_MIN, WebRtcSpl_MaxValueW32(vector32, 0)); - EXPECT_EQ(WEBRTC_SPL_WORD32_MIN, WebRtcSpl_MaxValueW32(NULL, kVectorSize)); - EXPECT_EQ(WEBRTC_SPL_WORD32_MAX, WebRtcSpl_MinValueW32(vector32, 0)); - EXPECT_EQ(WEBRTC_SPL_WORD32_MAX, WebRtcSpl_MinValueW32(NULL, kVectorSize)); - EXPECT_EQ(-1, WebRtcSpl_MaxAbsIndexW16(vector16, 0)); - EXPECT_EQ(-1, WebRtcSpl_MaxAbsIndexW16(NULL, kVectorSize)); - EXPECT_EQ(-1, WebRtcSpl_MaxIndexW16(vector16, 0)); - EXPECT_EQ(-1, WebRtcSpl_MaxIndexW16(NULL, kVectorSize)); - EXPECT_EQ(-1, WebRtcSpl_MaxIndexW32(vector32, 0)); - EXPECT_EQ(-1, WebRtcSpl_MaxIndexW32(NULL, kVectorSize)); - EXPECT_EQ(-1, WebRtcSpl_MinIndexW16(vector16, 0)); - EXPECT_EQ(-1, WebRtcSpl_MinIndexW16(NULL, kVectorSize)); - EXPECT_EQ(-1, WebRtcSpl_MinIndexW32(vector32, 0)); - EXPECT_EQ(-1, WebRtcSpl_MinIndexW32(NULL, kVectorSize)); -} - TEST_F(SplTest, MinMaxOperationsTest) { const size_t kVectorSize = 17; @@ -267,10 +237,8 @@ TEST_F(SplTest, MinMaxOperationsTest) { WebRtcSpl_MinValueW16(vector16, kVectorSize)); EXPECT_EQ(WEBRTC_SPL_WORD32_MIN, WebRtcSpl_MinValueW32(vector32, kVectorSize)); - EXPECT_EQ(static_cast(kVectorSize - 1), - WebRtcSpl_MinIndexW16(vector16, kVectorSize)); - EXPECT_EQ(static_cast(kVectorSize - 1), - WebRtcSpl_MinIndexW32(vector32, kVectorSize)); + EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MinIndexW16(vector16, kVectorSize)); + EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MinIndexW32(vector32, kVectorSize)); // Test the cases where maximum values have to be caught // outside of the unrolled loops in ARM-Neon. @@ -285,12 +253,9 @@ TEST_F(SplTest, MinMaxOperationsTest) { WebRtcSpl_MaxAbsValueW32(vector32, kVectorSize)); EXPECT_EQ(WEBRTC_SPL_WORD32_MAX, WebRtcSpl_MaxValueW32(vector32, kVectorSize)); - EXPECT_EQ(static_cast(kVectorSize - 1), - WebRtcSpl_MaxAbsIndexW16(vector16, kVectorSize)); - EXPECT_EQ(static_cast(kVectorSize - 1), - WebRtcSpl_MaxIndexW16(vector16, kVectorSize)); - EXPECT_EQ(static_cast(kVectorSize - 1), - WebRtcSpl_MaxIndexW32(vector32, kVectorSize)); + EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MaxAbsIndexW16(vector16, kVectorSize)); + EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MaxIndexW16(vector16, kVectorSize)); + EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MaxIndexW32(vector32, kVectorSize)); // Test the cases where multiple maximum and minimum values are present. vector16[1] = WEBRTC_SPL_WORD16_MAX; @@ -312,11 +277,11 @@ TEST_F(SplTest, MinMaxOperationsTest) { WebRtcSpl_MaxValueW32(vector32, kVectorSize)); EXPECT_EQ(WEBRTC_SPL_WORD32_MIN, WebRtcSpl_MinValueW32(vector32, kVectorSize)); - EXPECT_EQ(6, WebRtcSpl_MaxAbsIndexW16(vector16, kVectorSize)); - EXPECT_EQ(1, WebRtcSpl_MaxIndexW16(vector16, kVectorSize)); - EXPECT_EQ(1, WebRtcSpl_MaxIndexW32(vector32, kVectorSize)); - EXPECT_EQ(6, WebRtcSpl_MinIndexW16(vector16, kVectorSize)); - EXPECT_EQ(6, WebRtcSpl_MinIndexW32(vector32, kVectorSize)); + EXPECT_EQ(6u, WebRtcSpl_MaxAbsIndexW16(vector16, kVectorSize)); + EXPECT_EQ(1u, WebRtcSpl_MaxIndexW16(vector16, kVectorSize)); + EXPECT_EQ(1u, WebRtcSpl_MaxIndexW32(vector32, kVectorSize)); + EXPECT_EQ(6u, WebRtcSpl_MinIndexW16(vector16, kVectorSize)); + EXPECT_EQ(6u, WebRtcSpl_MinIndexW32(vector32, kVectorSize)); } TEST_F(SplTest, VectorOperationsTest) { @@ -500,9 +465,7 @@ TEST_F(SplTest, AutoCorrelationTest) { const int32_t expected[kVector16Size] = {302681398, 14223410, -121705063, -85221647, -17104971, 61806945, 6644603, -669329, 43}; - EXPECT_EQ(-1, WebRtcSpl_AutoCorrelation(vector16, kVector16Size, - kVector16Size + 1, vector32, &scale)); - EXPECT_EQ(static_cast(kVector16Size), + EXPECT_EQ(kVector16Size, WebRtcSpl_AutoCorrelation(vector16, kVector16Size, kVector16Size - 1, vector32, &scale)); EXPECT_EQ(3, scale); diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c b/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c index d297b1556c..fafa39f69b 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c @@ -103,7 +103,7 @@ void WebRtcIlbcfix_CbSearchCore( } /* Find the index of the best value */ - *bestIndex = (size_t)WebRtcSpl_MaxIndexW32(Crit, range); + *bestIndex = WebRtcSpl_MaxIndexW32(Crit, range); *bestCrit = Crit[*bestIndex]; /* Calculate total shifts of this criteria */ diff --git a/webrtc/modules/audio_coding/codecs/ilbc/constants.c b/webrtc/modules/audio_coding/codecs/ilbc/constants.c index f726ae2a6f..9e341942e6 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/constants.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/constants.c @@ -647,7 +647,7 @@ const int16_t WebRtcIlbcfix_kEnhWt[3] = { 4800, 16384, 27968 /* Q16 */ }; -const int16_t WebRtcIlbcfix_kEnhPlocs[ENH_NBLOCKS_TOT] = { +const size_t WebRtcIlbcfix_kEnhPlocs[ENH_NBLOCKS_TOT] = { 160, 480, 800, 1120, 1440, 1760, 2080, 2400 /* Q(-2) */ }; diff --git a/webrtc/modules/audio_coding/codecs/ilbc/constants.h b/webrtc/modules/audio_coding/codecs/ilbc/constants.h index 1f4de4d69f..7c4ad4d928 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/constants.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/constants.h @@ -81,7 +81,7 @@ extern const int16_t WebRtcIlbcfix_kAlpha[]; extern const int16_t WebRtcIlbcfix_kEnhPolyPhaser[ENH_UPS0][ENH_FLO_MULT2_PLUS1]; extern const int16_t WebRtcIlbcfix_kEnhWt[]; -extern const int16_t WebRtcIlbcfix_kEnhPlocs[]; +extern const size_t WebRtcIlbcfix_kEnhPlocs[]; /* PLC tables */ diff --git a/webrtc/modules/audio_coding/codecs/ilbc/defines.h b/webrtc/modules/audio_coding/codecs/ilbc/defines.h index 5fcd4a01e4..2faaea15fc 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/defines.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/defines.h @@ -213,7 +213,7 @@ typedef struct IlbcDecoder_ { /* enhancer state information */ int use_enhancer; int16_t enh_buf[ENH_BUFL+ENH_BUFL_FILTEROVERHEAD]; - int16_t enh_period[ENH_NBLOCKS_TOT]; + size_t enh_period[ENH_NBLOCKS_TOT]; } IlbcDecoder; diff --git a/webrtc/modules/audio_coding/codecs/ilbc/enhancer.c b/webrtc/modules/audio_coding/codecs/ilbc/enhancer.c index 5683597006..521d00441c 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/enhancer.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/enhancer.c @@ -29,10 +29,10 @@ void WebRtcIlbcfix_Enhancer( int16_t *odata, /* (o) smoothed block, dimension blockl */ int16_t *idata, /* (i) data buffer used for enhancing */ - int16_t idatal, /* (i) dimension idata */ - int16_t centerStartPos, /* (i) first sample current block within idata */ - int16_t *period, /* (i) pitch period array (pitch bward-in time) */ - int16_t *plocs, /* (i) locations where period array values valid */ + size_t idatal, /* (i) dimension idata */ + size_t centerStartPos, /* (i) first sample current block within idata */ + size_t *period, /* (i) pitch period array (pitch bward-in time) */ + const size_t *plocs, /* (i) locations where period array values valid */ size_t periodl /* (i) dimension of period and plocs */ ){ /* Stack based */ @@ -47,5 +47,5 @@ void WebRtcIlbcfix_Enhancer( /* compute the smoothed output from said second sequence */ - WebRtcIlbcfix_Smooth(odata, idata+centerStartPos, surround); + WebRtcIlbcfix_Smooth(odata, idata + centerStartPos, surround); } diff --git a/webrtc/modules/audio_coding/codecs/ilbc/enhancer.h b/webrtc/modules/audio_coding/codecs/ilbc/enhancer.h index 78a12d34cb..ed219fb1bb 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/enhancer.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/enhancer.h @@ -29,10 +29,10 @@ void WebRtcIlbcfix_Enhancer( int16_t *odata, /* (o) smoothed block, dimension blockl */ int16_t *idata, /* (i) data buffer used for enhancing */ - int16_t idatal, /* (i) dimension idata */ - int16_t centerStartPos, /* (i) first sample current block within idata */ - int16_t *period, /* (i) pitch period array (pitch bward-in time) */ - int16_t *plocs, /* (i) locations where period array values valid */ + size_t idatal, /* (i) dimension idata */ + size_t centerStartPos, /* (i) first sample current block within idata */ + size_t *period, /* (i) pitch period array (pitch bward-in time) */ + const size_t *plocs, /* (i) locations where period array values valid */ size_t periodl /* (i) dimension of period and plocs */ ); diff --git a/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c b/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c index f15aee6676..1c0fd42383 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c @@ -35,22 +35,24 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ int16_t *in, /* (i) unenhanced signal */ IlbcDecoder *iLBCdec_inst /* (i) buffers etc */ ){ - int iblock; + size_t iblock; size_t lag=20, tlag=20; size_t inLen=iLBCdec_inst->blockl+120; int16_t scale, scale1; size_t plc_blockl; - int16_t *enh_buf, *enh_period; - int32_t tmp1, tmp2, max, new_blocks; + int16_t *enh_buf; + size_t *enh_period; + int32_t tmp1, tmp2, max; + size_t new_blocks; int16_t *enh_bufPtr1; size_t i; - int k; + size_t k; int16_t EnChange; int16_t SqrtEnChange; int16_t inc; int16_t win; int16_t *tmpW16ptr; - int16_t startPos; + size_t startPos; int16_t *plc_pred; int16_t *target, *regressor; int16_t max16; @@ -60,7 +62,7 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ int16_t corrSh; size_t ind; int16_t sh; - int16_t start, stop; + size_t start, stop; /* Stack based */ int16_t totsh[3]; int16_t downsampled[(BLOCKL_MAX+120)>>1]; /* length 180 */ @@ -68,7 +70,7 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ int32_t corrmax[3]; int16_t corr16[3]; int16_t en16[3]; - int16_t lagmax[3]; + size_t lagmax[3]; plc_pred = downsampled; /* Reuse memory since plc_pred[ENH_BLOCKL] and downsampled are non overlapping */ @@ -99,7 +101,7 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ memmove(enh_period, &enh_period[new_blocks], (ENH_NBLOCKS_TOT - new_blocks) * sizeof(*enh_period)); - k = WebRtcSpl_DownsampleFast( + WebRtcSpl_DownsampleFast( enh_buf+ENH_BUFL-inLen, /* Input samples */ inLen + ENH_BUFL_FILTEROVERHEAD, downsampled, @@ -131,11 +133,9 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ for (i=0;i<2;i++) { lagmax[i] = WebRtcSpl_MaxIndexW32(corr32, 50); corrmax[i] = corr32[lagmax[i]]; - start = lagmax[i] - 2; - stop = lagmax[i] + 2; - start = WEBRTC_SPL_MAX(0, start); - stop = WEBRTC_SPL_MIN(49, stop); - for (k=start; k<=stop; k++) { + start = WEBRTC_SPL_MAX(2, lagmax[i]) - 2; + stop = WEBRTC_SPL_MIN(47, lagmax[i]) + 2; + for (k = start; k <= stop; k++) { corr32[k] = 0; } } @@ -145,8 +145,8 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ /* Calculate normalized corr^2 and ener */ for (i=0;i<3;i++) { corrSh = 15-WebRtcSpl_GetSizeInBits(corrmax[i]); - ener = WebRtcSpl_DotProductWithScale(®ressor[-lagmax[i]], - ®ressor[-lagmax[i]], + ener = WebRtcSpl_DotProductWithScale(regressor - lagmax[i], + regressor - lagmax[i], ENH_BLOCKL_HALF, shifts); enerSh = 15-WebRtcSpl_GetSizeInBits(ener); corr16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(corrmax[i], corrSh); @@ -171,10 +171,10 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ } } - lag = (size_t)(lagmax[ind] + 10); + lag = lagmax[ind] + 10; /* Store the estimated lag in the non-downsampled domain */ - enh_period[ENH_NBLOCKS_TOT - new_blocks + iblock] = (int16_t)(lag * 8); + enh_period[ENH_NBLOCKS_TOT - new_blocks + iblock] = lag * 8; /* Store the estimated lag for backward PLC */ if (iLBCdec_inst->prev_enh_pl==1) { @@ -368,9 +368,9 @@ size_t WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ WebRtcIlbcfix_Enhancer(out + iblock * ENH_BLOCKL, enh_buf, ENH_BUFL, - (int16_t)(iblock * ENH_BLOCKL + startPos), + iblock * ENH_BLOCKL + startPos, enh_period, - (int16_t*)WebRtcIlbcfix_kEnhPlocs, ENH_NBLOCKS_TOT); + WebRtcIlbcfix_kEnhPlocs, ENH_NBLOCKS_TOT); } return (lag); diff --git a/webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c b/webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c index f442f6a285..48332808e4 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/frame_classify.c @@ -82,7 +82,7 @@ size_t WebRtcIlbcfix_FrameClassify( } /* Extract the best choise of start state */ - pos = (size_t)WebRtcSpl_MaxIndexW32(ssqEn, iLBCenc_inst->nsub - 1) + 1; + pos = WebRtcSpl_MaxIndexW32(ssqEn, iLBCenc_inst->nsub - 1) + 1; return(pos); } diff --git a/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c b/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c index 66dfafbe7a..a98a96cdf1 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/get_sync_seq.c @@ -27,72 +27,68 @@ void WebRtcIlbcfix_GetSyncSeq( int16_t *idata, /* (i) original data */ - int16_t idatal, /* (i) dimension of data */ - int16_t centerStartPos, /* (i) where current block starts */ - int16_t *period, /* (i) rough-pitch-period array (Q-2) */ - int16_t *plocs, /* (i) where periods of period array are taken (Q-2) */ + size_t idatal, /* (i) dimension of data */ + size_t centerStartPos, /* (i) where current block starts */ + size_t *period, /* (i) rough-pitch-period array (Q-2) */ + const size_t *plocs, /* (i) where periods of period array are taken (Q-2) */ size_t periodl, /* (i) dimension period array */ - int16_t hl, /* (i) 2*hl+1 is the number of sequences */ + size_t hl, /* (i) 2*hl+1 is the number of sequences */ int16_t *surround /* (i/o) The contribution from this sequence summed with earlier contributions */ ){ - size_t i; - int16_t centerEndPos,q; + size_t i, centerEndPos, q; /* Stack based */ - int16_t lagBlock[2*ENH_HL+1]; - int16_t blockStartPos[2*ENH_HL+1]; /* Defines the position to search around (Q2) */ - int16_t plocs2[ENH_PLOCSL]; + size_t lagBlock[2 * ENH_HL + 1]; + size_t blockStartPos[2 * ENH_HL + 1]; /* The position to search around (Q2) */ + size_t plocs2[ENH_PLOCSL]; - centerEndPos=centerStartPos+ENH_BLOCKL-1; + centerEndPos = centerStartPos + ENH_BLOCKL - 1; /* present (find predicted lag from this position) */ WebRtcIlbcfix_NearestNeighbor(lagBlock + hl, plocs, - (int16_t)(2 * (centerStartPos + centerEndPos)), + 2 * (centerStartPos + centerEndPos), periodl); - blockStartPos[hl] = (int16_t)(4 * centerStartPos); + blockStartPos[hl] = 4 * centerStartPos; /* past (find predicted position and perform a refined search to find the best sequence) */ - for(q=hl-1;q>=0;q--) { - blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]]; + for (q = hl; q > 0; q--) { + size_t qq = q - 1; + size_t period_q = period[lagBlock[q]]; + /* Stop if this sequence would be outside the buffer; that means all + further-past sequences would also be outside the buffer. */ + if (blockStartPos[q] < period_q + (4 * ENH_OVERHANG)) + break; + blockStartPos[qq] = blockStartPos[q] - period_q; - WebRtcIlbcfix_NearestNeighbor( - lagBlock + q, - plocs, - (int16_t)(blockStartPos[q] + 4 * ENH_BLOCKL_HALF - - period[lagBlock[q + 1]]), - periodl); + size_t value = blockStartPos[qq] + 4 * ENH_BLOCKL_HALF; + value = (value > period_q) ? (value - period_q) : 0; + WebRtcIlbcfix_NearestNeighbor(lagBlock + qq, plocs, value, periodl); - if (blockStartPos[q] - 4 * ENH_OVERHANG >= 0) { - - /* Find the best possible sequence in the 4 times upsampled - domain around blockStartPos+q */ - WebRtcIlbcfix_Refiner(blockStartPos+q,idata,idatal, - centerStartPos,blockStartPos[q],surround,WebRtcIlbcfix_kEnhWt[q]); - - } else { - /* Don't add anything since this sequence would - be outside the buffer */ - } + /* Find the best possible sequence in the 4 times upsampled + domain around blockStartPos+q */ + WebRtcIlbcfix_Refiner(blockStartPos + qq, idata, idatal, centerStartPos, + blockStartPos[qq], surround, + WebRtcIlbcfix_kEnhWt[qq]); } /* future (find predicted position and perform a refined search to find the best sequence) */ - for(i=0;i> 2; - searchSegStartPos=estSegPosRounded-ENH_SLOP; + searchSegStartPos = + (estSegPosRounded < ENH_SLOP) ? 0 : (estSegPosRounded - ENH_SLOP); - if (searchSegStartPos<0) { - searchSegStartPos=0; + searchSegEndPos = estSegPosRounded + ENH_SLOP; + if ((searchSegEndPos + ENH_BLOCKL) >= idatal) { + searchSegEndPos = idatal - ENH_BLOCKL - 1; } - searchSegEndPos=estSegPosRounded+ENH_SLOP; - if(searchSegEndPos+ENH_BLOCKL >= idatal) { - searchSegEndPos=idatal-ENH_BLOCKL-1; - } - corrdim=(size_t)(searchSegEndPos-searchSegStartPos+1); + corrdim = searchSegEndPos + 1 - searchSegStartPos; /* compute upsampled correlation and find location of max */ - WebRtcIlbcfix_MyCorr(corrVecTemp,idata+searchSegStartPos, - corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL); + WebRtcIlbcfix_MyCorr(corrVecTemp, idata + searchSegStartPos, + corrdim + ENH_BLOCKL - 1, idata + centerStartPos, + ENH_BLOCKL); /* Calculate the rescaling factor for the correlation in order to put the correlation in a int16_t vector instead */ - maxtemp=WebRtcSpl_MaxAbsValueW32(corrVecTemp, corrdim); + maxtemp = WebRtcSpl_MaxAbsValueW32(corrVecTemp, corrdim); - scalefact=WebRtcSpl_GetSizeInBits(maxtemp)-15; + scalefact = WebRtcSpl_GetSizeInBits(maxtemp) - 15; - if (scalefact>0) { - for (i=0;i 0) { + for (i = 0; i < corrdim; i++) { corrVec[i] = (int16_t)(corrVecTemp[i] >> scalefact); } } else { - for (i=0;i> 2; - st=searchSegStartPos+tloc2-ENH_FL0; - /* initialize the vector to be filtered, stuff with zeros when data is outside idata buffer */ - if(st<0){ - WebRtcSpl_MemSetW16(vect, 0, (size_t)(-st)); - WEBRTC_SPL_MEMCPY_W16(&vect[-st], idata, (ENH_VECTL+st)); - } - else{ - en=st+ENH_VECTL; - - if(en>idatal){ - WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], - (ENH_VECTL-(en-idatal))); - WebRtcSpl_MemSetW16(&vect[ENH_VECTL-(en-idatal)], 0, - (size_t)(en-idatal)); - } - else { + if (ENH_FL0 > (searchSegStartPos + tloc2)) { + const size_t st = ENH_FL0 - searchSegStartPos - tloc2; + WebRtcSpl_MemSetW16(vect, 0, st); + WEBRTC_SPL_MEMCPY_W16(&vect[st], idata, ENH_VECTL - st); + } else { + const size_t st = searchSegStartPos + tloc2 - ENH_FL0; + if ((st + ENH_VECTL) > idatal) { + const size_t en = st + ENH_VECTL - idatal; + WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], ENH_VECTL - en); + WebRtcSpl_MemSetW16(&vect[ENH_VECTL - en], 0, en); + } else { WEBRTC_SPL_MEMCPY_W16(vect, &idata[st], ENH_VECTL); } } - /* Calculate which of the 4 fractions to use */ - fraction = (int16_t)(tloc2 * ENH_UPS0) - tloc; /* compute the segment (this is actually a convolution) */ - filtStatePtr = filt + 6; - polyPtr = (int16_t*)WebRtcIlbcfix_kEnhPolyPhaser[fraction]; - for (i=0;i<7;i++) { + polyPtr = (int16_t*)WebRtcIlbcfix_kEnhPolyPhaser[tloc2 * ENH_UPS0 - tloc]; + for (i = 0; i < 7; i++) { *filtStatePtr-- = *polyPtr++; } - WebRtcSpl_FilterMAFastQ12( - &vect[6], vect, filt, - ENH_FLO_MULT2_PLUS1, ENH_BLOCKL); + WebRtcSpl_FilterMAFastQ12(&vect[6], vect, filt, ENH_FLO_MULT2_PLUS1, + ENH_BLOCKL); - /* Add the contribution from this vector (scaled with gain) to the total surround vector */ - WebRtcSpl_AddAffineVectorToVector( - surround, vect, gain, - (int32_t)32768, 16, ENH_BLOCKL); + /* Add the contribution from this vector (scaled with gain) to the total + surround vector */ + WebRtcSpl_AddAffineVectorToVector(surround, vect, gain, 32768, 16, + ENH_BLOCKL); return; } diff --git a/webrtc/modules/audio_coding/codecs/ilbc/refiner.h b/webrtc/modules/audio_coding/codecs/ilbc/refiner.h index d13996152d..f8a2abc2d6 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/refiner.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/refiner.h @@ -30,11 +30,11 @@ *---------------------------------------------------------------*/ void WebRtcIlbcfix_Refiner( - int16_t *updStartPos, /* (o) updated start point (Q-2) */ + size_t *updStartPos, /* (o) updated start point (Q-2) */ int16_t *idata, /* (i) original data buffer */ - int16_t idatal, /* (i) dimension of idata */ - int16_t centerStartPos, /* (i) beginning center segment */ - int16_t estSegPos, /* (i) estimated beginning other segment (Q-2) */ + size_t idatal, /* (i) dimension of idata */ + size_t centerStartPos, /* (i) beginning center segment */ + size_t estSegPos, /* (i) estimated beginning other segment (Q-2) */ int16_t *surround, /* (i/o) The contribution from this sequence summed with earlier contributions */ int16_t gain /* (i) Gain to use for this sequence */ diff --git a/webrtc/modules/audio_coding/neteq/expand.cc b/webrtc/modules/audio_coding/neteq/expand.cc index c163feee6d..2aa9fb0a8d 100644 --- a/webrtc/modules/audio_coding/neteq/expand.cc +++ b/webrtc/modules/audio_coding/neteq/expand.cc @@ -467,8 +467,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) { correlation_length, correlation_lags, correlation_scale, -1); // Find maximizing index. - best_index = static_cast( - WebRtcSpl_MaxIndexW32(correlation_vector2, correlation_lags)); + best_index = WebRtcSpl_MaxIndexW32(correlation_vector2, correlation_lags); int32_t max_correlation = correlation_vector2[best_index]; // Compensate index with start offset. best_index = best_index + start_index; diff --git a/webrtc/modules/audio_device/android/audio_manager.cc b/webrtc/modules/audio_device/android/audio_manager.cc index 81fabdf9fe..77099ab10b 100644 --- a/webrtc/modules/audio_device/android/audio_manager.cc +++ b/webrtc/modules/audio_device/android/audio_manager.cc @@ -191,8 +191,10 @@ void AudioManager::OnCacheAudioParameters(JNIEnv* env, hardware_aec_ = hardware_aec; low_latency_playout_ = low_latency_output; // TODO(henrika): add support for stereo output. - playout_parameters_.reset(sample_rate, channels, output_buffer_size); - record_parameters_.reset(sample_rate, channels, input_buffer_size); + playout_parameters_.reset(sample_rate, channels, + static_cast(output_buffer_size)); + record_parameters_.reset(sample_rate, channels, + static_cast(input_buffer_size)); } const AudioParameters& AudioManager::GetPlayoutAudioParameters() { diff --git a/webrtc/modules/audio_device/android/audio_manager_unittest.cc b/webrtc/modules/audio_device/android/audio_manager_unittest.cc index a5af8b0683..0aff88c91e 100644 --- a/webrtc/modules/audio_device/android/audio_manager_unittest.cc +++ b/webrtc/modules/audio_device/android/audio_manager_unittest.cc @@ -9,6 +9,7 @@ */ #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/format_macros.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/modules/audio_device/android/build_info.h" #include "webrtc/modules/audio_device/android/audio_manager.h" @@ -72,14 +73,14 @@ TEST_F(AudioManagerTest, ShowAudioParameterInfo) { low_latency_out ? "Low latency OpenSL" : "Java/JNI based AudioTrack"); PRINT("%ssample rate: %d Hz\n", kTag, playout_parameters_.sample_rate()); PRINT("%schannels: %d\n", kTag, playout_parameters_.channels()); - PRINT("%sframes per buffer: %d <=> %.2f ms\n", kTag, + PRINT("%sframes per buffer: %" PRIuS " <=> %.2f ms\n", kTag, playout_parameters_.frames_per_buffer(), playout_parameters_.GetBufferSizeInMilliseconds()); PRINT("RECORD: \n"); PRINT("%saudio layer: %s\n", kTag, "Java/JNI based AudioRecord"); PRINT("%ssample rate: %d Hz\n", kTag, record_parameters_.sample_rate()); PRINT("%schannels: %d\n", kTag, record_parameters_.channels()); - PRINT("%sframes per buffer: %d <=> %.2f ms\n", kTag, + PRINT("%sframes per buffer: %" PRIuS " <=> %.2f ms\n", kTag, record_parameters_.frames_per_buffer(), record_parameters_.GetBufferSizeInMilliseconds()); } @@ -109,10 +110,10 @@ TEST_F(AudioManagerTest, AudioParametersWithDefaultConstruction) { EXPECT_FALSE(params.is_valid()); EXPECT_EQ(0, params.sample_rate()); EXPECT_EQ(0, params.channels()); - EXPECT_EQ(0, params.frames_per_buffer()); + EXPECT_EQ(0U, params.frames_per_buffer()); EXPECT_EQ(0U, params.frames_per_10ms_buffer()); - EXPECT_EQ(0, params.GetBytesPerFrame()); - EXPECT_EQ(0, params.GetBytesPerBuffer()); + EXPECT_EQ(0U, params.GetBytesPerFrame()); + EXPECT_EQ(0U, params.GetBytesPerBuffer()); EXPECT_EQ(0U, params.GetBytesPer10msBuffer()); EXPECT_EQ(0.0f, params.GetBufferSizeInMilliseconds()); } @@ -121,9 +122,9 @@ TEST_F(AudioManagerTest, AudioParametersWithDefaultConstruction) { TEST_F(AudioManagerTest, AudioParametersWithNonDefaultConstruction) { const int kSampleRate = 48000; const int kChannels = 1; - const int kFramesPerBuffer = 480; + const size_t kFramesPerBuffer = 480; const size_t kFramesPer10msBuffer = 480; - const int kBytesPerFrame = 2; + const size_t kBytesPerFrame = 2; const float kBufferSizeInMs = 10.0f; AudioParameters params(kSampleRate, kChannels, kFramesPerBuffer); EXPECT_TRUE(params.is_valid()); diff --git a/webrtc/modules/audio_device/android/fine_audio_buffer.cc b/webrtc/modules/audio_device/android/fine_audio_buffer.cc index 99f853a23e..37f994b800 100644 --- a/webrtc/modules/audio_device/android/fine_audio_buffer.cc +++ b/webrtc/modules/audio_device/android/fine_audio_buffer.cc @@ -20,12 +20,12 @@ namespace webrtc { FineAudioBuffer::FineAudioBuffer(AudioDeviceBuffer* device_buffer, - int desired_frame_size_bytes, + size_t desired_frame_size_bytes, int sample_rate) : device_buffer_(device_buffer), desired_frame_size_bytes_(desired_frame_size_bytes), sample_rate_(sample_rate), - samples_per_10_ms_(sample_rate_ * 10 / 1000), + samples_per_10_ms_(static_cast(sample_rate_ * 10 / 1000)), bytes_per_10_ms_(samples_per_10_ms_ * sizeof(int16_t)), cached_buffer_start_(0), cached_bytes_(0) { @@ -35,7 +35,7 @@ FineAudioBuffer::FineAudioBuffer(AudioDeviceBuffer* device_buffer, FineAudioBuffer::~FineAudioBuffer() { } -int FineAudioBuffer::RequiredBufferSizeBytes() { +size_t FineAudioBuffer::RequiredBufferSizeBytes() { // It is possible that we store the desired frame size - 1 samples. Since new // audio frames are pulled in chunks of 10ms we will need a buffer that can // hold desired_frame_size - 1 + 10ms of data. We omit the - 1. @@ -56,13 +56,13 @@ void FineAudioBuffer::GetBufferData(int8_t* buffer) { // |desired_frame_size_bytes_| is greater than 10ms of audio. Note that we // write the audio after the cached bytes copied earlier. int8_t* unwritten_buffer = &buffer[cached_bytes_]; - int bytes_left = desired_frame_size_bytes_ - cached_bytes_; + int bytes_left = static_cast(desired_frame_size_bytes_ - cached_bytes_); // Ceiling of integer division: 1 + ((x - 1) / y) - int number_of_requests = 1 + (bytes_left - 1) / (bytes_per_10_ms_); - for (int i = 0; i < number_of_requests; ++i) { + size_t number_of_requests = 1 + (bytes_left - 1) / (bytes_per_10_ms_); + for (size_t i = 0; i < number_of_requests; ++i) { device_buffer_->RequestPlayoutData(samples_per_10_ms_); int num_out = device_buffer_->GetPlayoutData(unwritten_buffer); - if (num_out != samples_per_10_ms_) { + if (static_cast(num_out) != samples_per_10_ms_) { CHECK_EQ(num_out, 0); cached_bytes_ = 0; return; @@ -74,14 +74,14 @@ void FineAudioBuffer::GetBufferData(int8_t* buffer) { CHECK_LE(bytes_left, 0); // Put the samples that were written to |buffer| but are not used in the // cache. - int cache_location = desired_frame_size_bytes_; + size_t cache_location = desired_frame_size_bytes_; int8_t* cache_ptr = &buffer[cache_location]; cached_bytes_ = number_of_requests * bytes_per_10_ms_ - (desired_frame_size_bytes_ - cached_bytes_); // If cached_bytes_ is larger than the cache buffer, uninitialized memory // will be read. CHECK_LE(cached_bytes_, bytes_per_10_ms_); - CHECK_EQ(-bytes_left, cached_bytes_); + CHECK_EQ(static_cast(-bytes_left), cached_bytes_); cached_buffer_start_ = 0; memcpy(cache_buffer_.get(), cache_ptr, cached_bytes_); } diff --git a/webrtc/modules/audio_device/android/fine_audio_buffer.h b/webrtc/modules/audio_device/android/fine_audio_buffer.h index dce40beb78..3534271ece 100644 --- a/webrtc/modules/audio_device/android/fine_audio_buffer.h +++ b/webrtc/modules/audio_device/android/fine_audio_buffer.h @@ -32,7 +32,7 @@ class FineAudioBuffer { // |device_buffer| delivers 10ms of data. Given the sample rate the number // of samples can be calculated. FineAudioBuffer(AudioDeviceBuffer* device_buffer, - int desired_frame_size_bytes, + size_t desired_frame_size_bytes, int sample_rate); ~FineAudioBuffer(); @@ -40,7 +40,7 @@ class FineAudioBuffer { // buffer is smaller memory trampling will happen. // |desired_frame_size_bytes| and |samples_rate| are as described in the // constructor. - int RequiredBufferSizeBytes(); + size_t RequiredBufferSizeBytes(); // |buffer| must be of equal or greater size than what is returned by // RequiredBufferSize. This is to avoid unnecessary memcpy. @@ -50,18 +50,18 @@ class FineAudioBuffer { // Device buffer that provides 10ms chunks of data. AudioDeviceBuffer* device_buffer_; // Number of bytes delivered per GetBufferData - int desired_frame_size_bytes_; + size_t desired_frame_size_bytes_; int sample_rate_; - int samples_per_10_ms_; + size_t samples_per_10_ms_; // Convenience parameter to avoid converting from samples - int bytes_per_10_ms_; + size_t bytes_per_10_ms_; // Storage for samples that are not yet asked for. rtc::scoped_ptr cache_buffer_; // Location of first unread sample. - int cached_buffer_start_; + size_t cached_buffer_start_; // Number of bytes stored in cache. - int cached_bytes_; + size_t cached_bytes_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_device/android/opensles_player.cc b/webrtc/modules/audio_device/android/opensles_player.cc index 0789ebf1ba..ceef9463b2 100644 --- a/webrtc/modules/audio_device/android/opensles_player.cc +++ b/webrtc/modules/audio_device/android/opensles_player.cc @@ -14,6 +14,7 @@ #include "webrtc/base/arraysize.h" #include "webrtc/base/checks.h" +#include "webrtc/base/format_macros.h" #include "webrtc/modules/audio_device/android/audio_manager.h" #include "webrtc/modules/audio_device/android/fine_audio_buffer.h" @@ -182,9 +183,10 @@ void OpenSLESPlayer::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { AllocateDataBuffers(); } -SLDataFormat_PCM OpenSLESPlayer::CreatePCMConfiguration(int channels, - int sample_rate, - int bits_per_sample) { +SLDataFormat_PCM OpenSLESPlayer::CreatePCMConfiguration( + int channels, + int sample_rate, + size_t bits_per_sample) { ALOGD("CreatePCMConfiguration"); CHECK_EQ(bits_per_sample, SL_PCMSAMPLEFORMAT_FIXED_16); SLDataFormat_PCM format; @@ -231,7 +233,7 @@ void OpenSLESPlayer::AllocateDataBuffers() { DCHECK(!simple_buffer_queue_); CHECK(audio_device_buffer_); bytes_per_buffer_ = audio_parameters_.GetBytesPerBuffer(); - ALOGD("native buffer size: %d", bytes_per_buffer_); + ALOGD("native buffer size: %" PRIuS, bytes_per_buffer_); // Create a modified audio buffer class which allows us to ask for any number // of samples (and not only multiple of 10ms) to match the native OpenSL ES // buffer size. @@ -240,8 +242,8 @@ void OpenSLESPlayer::AllocateDataBuffers() { audio_parameters_.sample_rate())); // Each buffer must be of this size to avoid unnecessary memcpy while caching // data between successive callbacks. - const int required_buffer_size = fine_buffer_->RequiredBufferSizeBytes(); - ALOGD("required buffer size: %d", required_buffer_size); + const size_t required_buffer_size = fine_buffer_->RequiredBufferSizeBytes(); + ALOGD("required buffer size: %" PRIuS, required_buffer_size); for (int i = 0; i < kNumOfOpenSLESBuffers; ++i) { audio_buffers_[i].reset(new SLint8[required_buffer_size]); } diff --git a/webrtc/modules/audio_device/android/opensles_player.h b/webrtc/modules/audio_device/android/opensles_player.h index 2217fa0993..79cc6f4df8 100644 --- a/webrtc/modules/audio_device/android/opensles_player.h +++ b/webrtc/modules/audio_device/android/opensles_player.h @@ -96,7 +96,7 @@ class OpenSLESPlayer { // Configures the SL_DATAFORMAT_PCM structure. SLDataFormat_PCM CreatePCMConfiguration(int channels, int sample_rate, - int bits_per_sample); + size_t bits_per_sample); // Allocate memory for audio buffers which will be used to render audio // via the SLAndroidSimpleBufferQueueItf interface. @@ -145,7 +145,7 @@ class OpenSLESPlayer { // Number of bytes per audio buffer in each |audio_buffers_[i]|. // Typical sizes are 480 or 512 bytes corresponding to native output buffer // sizes of 240 or 256 audio frames respectively. - int bytes_per_buffer_; + size_t bytes_per_buffer_; // Queue of audio buffers to be used by the player object for rendering // audio. They will be used in a Round-robin way and the size of each buffer diff --git a/webrtc/modules/audio_device/include/audio_device_defines.h b/webrtc/modules/audio_device/include/audio_device_defines.h index 32df9e9756..a14c77e4c6 100644 --- a/webrtc/modules/audio_device/include/audio_device_defines.h +++ b/webrtc/modules/audio_device/include/audio_device_defines.h @@ -143,33 +143,33 @@ class AudioTransport { class AudioParameters { public: // This implementation does only support 16-bit PCM samples. - enum { kBitsPerSample = 16 }; + static const size_t kBitsPerSample = 16; AudioParameters() : sample_rate_(0), channels_(0), frames_per_buffer_(0), frames_per_10ms_buffer_(0) {} - AudioParameters(int sample_rate, int channels, int frames_per_buffer) + AudioParameters(int sample_rate, int channels, size_t frames_per_buffer) : sample_rate_(sample_rate), channels_(channels), frames_per_buffer_(frames_per_buffer), frames_per_10ms_buffer_(static_cast(sample_rate / 100)) {} - void reset(int sample_rate, int channels, int frames_per_buffer) { + void reset(int sample_rate, int channels, size_t frames_per_buffer) { sample_rate_ = sample_rate; channels_ = channels; frames_per_buffer_ = frames_per_buffer; frames_per_10ms_buffer_ = static_cast(sample_rate / 100); } - int bits_per_sample() const { return kBitsPerSample; } + size_t bits_per_sample() const { return kBitsPerSample; } int sample_rate() const { return sample_rate_; } int channels() const { return channels_; } - int frames_per_buffer() const { return frames_per_buffer_; } + size_t frames_per_buffer() const { return frames_per_buffer_; } size_t frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; } bool is_valid() const { return ((sample_rate_ > 0) && (channels_ > 0) && (frames_per_buffer_ > 0)); } - int GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; } - int GetBytesPerBuffer() const { + size_t GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; } + size_t GetBytesPerBuffer() const { return frames_per_buffer_ * GetBytesPerFrame(); } size_t GetBytesPer10msBuffer() const { @@ -184,7 +184,7 @@ class AudioParameters { private: int sample_rate_; int channels_; - int frames_per_buffer_; + size_t frames_per_buffer_; size_t frames_per_10ms_buffer_; }; diff --git a/webrtc/modules/audio_device/ios/audio_device_ios.mm b/webrtc/modules/audio_device/ios/audio_device_ios.mm index 09419f2bda..6f610d7afc 100644 --- a/webrtc/modules/audio_device/ios/audio_device_ios.mm +++ b/webrtc/modules/audio_device/ios/audio_device_ios.mm @@ -86,8 +86,8 @@ static void GetHardwareAudioParameters(AudioParameters* playout_parameters, double io_buffer_duration = (double)session.IOBufferDuration; int output_channels = (int)session.outputNumberOfChannels; int input_channels = (int)session.inputNumberOfChannels; - int frames_per_buffer = - static_cast(sample_rate * io_buffer_duration + 0.5); + size_t frames_per_buffer = + static_cast(sample_rate * io_buffer_duration + 0.5); // Copy hardware parameters to output parameters. playout_parameters->reset(sample_rate, output_channels, frames_per_buffer); record_parameters->reset(sample_rate, input_channels, frames_per_buffer);