Convert some more things to size_t.

These changes stem from requests by Andrew on https://codereview.webrtc.org/1228823002/ to eliminate some "return -1"s and change to using asserts plus returning size_ts.  I then also converted the relevant connected bits.

This also cleans up a bunch of style issues, e.g. no spaces around operators.

BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, henrik.lundin@webrtc.org, niklas.enbom@webrtc.org

Review URL: https://codereview.webrtc.org/1305983003 .

Cr-Commit-Position: refs/heads/master@{#9813}
This commit is contained in:
Peter Kasting
2015-08-28 17:31:03 -07:00
parent e8386d2199
commit 1380e266ff
29 changed files with 267 additions and 390 deletions

View File

@ -10,7 +10,9 @@
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
#include <assert.h>
size_t WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
size_t in_vector_length,
size_t order,
int32_t* result,
@ -20,10 +22,7 @@ int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
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;
}

View File

@ -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,10 +424,8 @@ 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,
// 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,

View File

@ -24,10 +24,11 @@
*
*/
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
#include <assert.h>
#include <stdlib.h>
#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;
}

View File

@ -16,6 +16,8 @@
*
*/
#include <assert.h>
#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"

View File

@ -9,6 +9,7 @@
*/
#include <arm_neon.h>
#include <assert.h>
#include <stdlib.h>
#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);

View File

@ -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<int>(kVectorSize - 1),
WebRtcSpl_MinIndexW16(vector16, kVectorSize));
EXPECT_EQ(static_cast<int>(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<int>(kVectorSize - 1),
WebRtcSpl_MaxAbsIndexW16(vector16, kVectorSize));
EXPECT_EQ(static_cast<int>(kVectorSize - 1),
WebRtcSpl_MaxIndexW16(vector16, kVectorSize));
EXPECT_EQ(static_cast<int>(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<int>(kVector16Size),
EXPECT_EQ(kVector16Size,
WebRtcSpl_AutoCorrelation(vector16, kVector16Size,
kVector16Size - 1, vector32, &scale));
EXPECT_EQ(3, scale);

View File

@ -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 */

View File

@ -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) */
};

View File

@ -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 */

View File

@ -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;

View File

@ -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);
}

View File

@ -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 */
);

View File

@ -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(&regressor[-lagmax[i]],
&regressor[-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);

View File

@ -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);
}

View File

@ -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);
if (blockStartPos[q] - 4 * ENH_OVERHANG >= 0) {
size_t value = blockStartPos[qq] + 4 * ENH_BLOCKL_HALF;
value = (value > period_q) ? (value - period_q) : 0;
WebRtcIlbcfix_NearestNeighbor(lagBlock + qq, plocs, value, periodl);
/* 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 */
}
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<periodl;i++) {
plocs2[i]=(plocs[i]-period[i]);
for (i = 0; i < periodl; i++) {
plocs2[i] = plocs[i] - period[i];
}
for (q = hl + 1; q <= (int16_t)(2 * hl); q++) {
for (q = hl + 1; q <= (2 * hl); q++) {
WebRtcIlbcfix_NearestNeighbor(
lagBlock + q,
plocs2,
(int16_t)(blockStartPos[q - 1] + 4 * ENH_BLOCKL_HALF),
blockStartPos[q - 1] + 4 * ENH_BLOCKL_HALF,
periodl);
blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];
@ -101,11 +97,11 @@ void WebRtcIlbcfix_GetSyncSeq(
/* 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[2*hl-q]);
WebRtcIlbcfix_Refiner(blockStartPos + q, idata, idatal, centerStartPos,
blockStartPos[q], surround,
WebRtcIlbcfix_kEnhWt[2 * hl - q]);
}
else {
} else {
/* Don't add anything since this sequence would
be outside the buffer */
}

View File

@ -27,12 +27,12 @@
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 */
);

View File

@ -18,29 +18,18 @@
#include "defines.h"
/*----------------------------------------------------------------*
* Find index in array such that the array element with said
* index is the element of said array closest to "value"
* according to the squared-error criterion
*---------------------------------------------------------------*/
void WebRtcIlbcfix_NearestNeighbor(
int16_t *index, /* (o) index of array element closest to value */
int16_t *array, /* (i) data array (Q2) */
int16_t value, /* (i) value (Q2) */
size_t arlength /* (i) dimension of data array (==8) */
){
void WebRtcIlbcfix_NearestNeighbor(size_t* index,
const size_t* array,
size_t value,
size_t arlength) {
size_t i;
int16_t diff;
/* Stack based */
int32_t crit[8];
/* Calculate square distance */
for(i=0;i<arlength;i++){
diff=array[i]-value;
crit[i] = diff * diff;
size_t min_diff = (size_t)-1;
for (i = 0; i < arlength; i++) {
const size_t diff =
(array[i] < value) ? (value - array[i]) : (array[i] - value);
if (diff < min_diff) {
*index = i;
min_diff = diff;
}
}
/* Find the minimum square distance */
*index=WebRtcSpl_MinIndexW32(crit, arlength);
}

View File

@ -24,14 +24,13 @@
/*----------------------------------------------------------------*
* Find index in array such that the array element with said
* index is the element of said array closest to "value"
* according to the squared-error criterion
*---------------------------------------------------------------*/
void WebRtcIlbcfix_NearestNeighbor(
int16_t *index, /* (o) index of array element closest to value */
int16_t *array, /* (i) data array (Q2) */
int16_t value, /* (i) value (Q2) */
size_t arlength /* (i) dimension of data array (==8) */
size_t* index, /* (o) index of array element closest to value */
const size_t* array, /* (i) data array (Q2) */
size_t value, /* (i) value (Q2) */
size_t arlength /* (i) dimension of data array (==ENH_NBLOCKS_TOT) */
);
#endif

View File

@ -30,18 +30,17 @@
*---------------------------------------------------------------*/
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 */
){
int16_t estSegPosRounded,searchSegStartPos,searchSegEndPos;
size_t corrdim,i;
int16_t tloc,tloc2,st,en,fraction;
size_t estSegPosRounded, searchSegStartPos, searchSegEndPos, corrdim;
size_t tloc, tloc2, i;
int32_t maxtemp, scalefact;
int16_t *filtStatePtr, *polyPtr;
@ -56,96 +55,86 @@ void WebRtcIlbcfix_Refiner(
estSegPosRounded = (estSegPos - 2) >> 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<corrdim;i++) {
if (scalefact > 0) {
for (i = 0; i < corrdim; i++) {
corrVec[i] = (int16_t)(corrVecTemp[i] >> scalefact);
}
} else {
for (i=0;i<corrdim;i++) {
corrVec[i]=(int16_t)corrVecTemp[i];
for (i = 0; i < corrdim; i++) {
corrVec[i] = (int16_t)corrVecTemp[i];
}
}
/* In order to guarantee that all values are initialized */
for (i=corrdim;i<ENH_CORRDIM;i++) {
corrVec[i]=0;
for (i = corrdim; i < ENH_CORRDIM; i++) {
corrVec[i] = 0;
}
/* Upsample the correlation */
WebRtcIlbcfix_EnhUpsample(corrVecUps,corrVec);
WebRtcIlbcfix_EnhUpsample(corrVecUps, corrVec);
/* Find maximum */
tloc=WebRtcSpl_MaxIndexW32(corrVecUps, ENH_UPS0 * corrdim);
tloc = WebRtcSpl_MaxIndexW32(corrVecUps, ENH_UPS0 * corrdim);
/* make vector can be upsampled without ever running outside
bounds */
*updStartPos = (int16_t)(searchSegStartPos * 4) + tloc + 4;
*updStartPos = searchSegStartPos * 4 + tloc + 4;
tloc2 = (tloc + 3) >> 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;
}

View File

@ -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 */

View File

@ -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<size_t>(
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;

View File

@ -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<size_t>(output_buffer_size));
record_parameters_.reset(sample_rate, channels,
static_cast<size_t>(input_buffer_size));
}
const AudioParameters& AudioManager::GetPlayoutAudioParameters() {

View File

@ -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());

View File

@ -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<size_t>(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<int>(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<size_t>(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<size_t>(-bytes_left), cached_bytes_);
cached_buffer_start_ = 0;
memcpy(cache_buffer_.get(), cache_ptr, cached_bytes_);
}

View File

@ -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<int8_t[]> 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

View File

@ -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,
SLDataFormat_PCM OpenSLESPlayer::CreatePCMConfiguration(
int channels,
int sample_rate,
int bits_per_sample) {
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]);
}

View File

@ -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

View File

@ -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<size_t>(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<size_t>(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_;
};

View File

@ -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<int>(sample_rate * io_buffer_duration + 0.5);
size_t frames_per_buffer =
static_cast<size_t>(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);