delay_estimator: Increases test coverage and makes input spectrum const

Noticed lack in tests verifying initial state is not left if we have zero input spectra. This CL adds such a test and change input spectra to const at affected places.

BUG=N/A
TESTED=trybots and manually
R=kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/15969004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6631 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
bjornv@webrtc.org 2014-07-09 06:40:09 +00:00
parent 12b4efefdd
commit b753762ce6
3 changed files with 38 additions and 13 deletions

View File

@ -383,14 +383,23 @@ TEST_F(DelayEstimatorTest, VerifyEnableRobustValidation) {
TEST_F(DelayEstimatorTest, InitializedSpectrumAfterProcess) {
// In this test we verify that the mean spectra are initialized after first
// time we call WebRtc_AddFarSpectrum() and Process() respectively.
// time we call WebRtc_AddFarSpectrum() and Process() respectively. The test
// also verifies the state is not left for zero spectra.
const float kZerosFloat[kSpectrumSize] = { 0.0 };
const uint16_t kZerosU16[kSpectrumSize] = { 0 };
// For floating point operations, process one frame and verify initialization
// flag.
Init();
EXPECT_EQ(0, WebRtc_AddFarSpectrumFloat(farend_handle_, kZerosFloat,
spectrum_size_));
EXPECT_EQ(0, farend_self_->far_spectrum_initialized);
EXPECT_EQ(0, WebRtc_AddFarSpectrumFloat(farend_handle_, far_f_,
spectrum_size_));
EXPECT_EQ(1, farend_self_->far_spectrum_initialized);
EXPECT_EQ(-2, WebRtc_DelayEstimatorProcessFloat(handle_, kZerosFloat,
spectrum_size_));
EXPECT_EQ(0, self_->near_spectrum_initialized);
EXPECT_EQ(-2, WebRtc_DelayEstimatorProcessFloat(handle_, near_f_,
spectrum_size_));
EXPECT_EQ(1, self_->near_spectrum_initialized);
@ -398,9 +407,15 @@ TEST_F(DelayEstimatorTest, InitializedSpectrumAfterProcess) {
// For fixed point operations, process one frame and verify initialization
// flag.
Init();
EXPECT_EQ(0, WebRtc_AddFarSpectrumFix(farend_handle_, kZerosU16,
spectrum_size_, 0));
EXPECT_EQ(0, farend_self_->far_spectrum_initialized);
EXPECT_EQ(0, WebRtc_AddFarSpectrumFix(farend_handle_, far_u16_,
spectrum_size_, 0));
EXPECT_EQ(1, farend_self_->far_spectrum_initialized);
EXPECT_EQ(-2, WebRtc_DelayEstimatorProcessFix(handle_, kZerosU16,
spectrum_size_, 0));
EXPECT_EQ(0, self_->near_spectrum_initialized);
EXPECT_EQ(-2, WebRtc_DelayEstimatorProcessFix(handle_, near_u16_,
spectrum_size_, 0));
EXPECT_EQ(1, self_->near_spectrum_initialized);

View File

@ -58,7 +58,7 @@ static void MeanEstimatorFloat(float new_value,
// Return:
// - out : Binary spectrum.
//
static uint32_t BinarySpectrumFix(uint16_t* spectrum,
static uint32_t BinarySpectrumFix(const uint16_t* spectrum,
SpectrumType* threshold_spectrum,
int q_domain,
int* threshold_initialized) {
@ -93,7 +93,7 @@ static uint32_t BinarySpectrumFix(uint16_t* spectrum,
return out;
}
static uint32_t BinarySpectrumFloat(float* spectrum,
static uint32_t BinarySpectrumFloat(const float* spectrum,
SpectrumType* threshold_spectrum,
int* threshold_initialized) {
int i = kBandFirst;
@ -197,8 +197,10 @@ void WebRtc_SoftResetDelayEstimatorFarend(void* handle, int delay_shift) {
WebRtc_SoftResetBinaryDelayEstimatorFarend(self->binary_farend, delay_shift);
}
int WebRtc_AddFarSpectrumFix(void* handle, uint16_t* far_spectrum,
int spectrum_size, int far_q) {
int WebRtc_AddFarSpectrumFix(void* handle,
const uint16_t* far_spectrum,
int spectrum_size,
int far_q) {
DelayEstimatorFarend* self = (DelayEstimatorFarend*) handle;
uint32_t binary_spectrum = 0;
@ -226,7 +228,8 @@ int WebRtc_AddFarSpectrumFix(void* handle, uint16_t* far_spectrum,
return 0;
}
int WebRtc_AddFarSpectrumFloat(void* handle, float* far_spectrum,
int WebRtc_AddFarSpectrumFloat(void* handle,
const float* far_spectrum,
int spectrum_size) {
DelayEstimatorFarend* self = (DelayEstimatorFarend*) handle;
uint32_t binary_spectrum = 0;
@ -409,7 +412,7 @@ int WebRtc_is_robust_validation_enabled(const void* handle) {
}
int WebRtc_DelayEstimatorProcessFix(void* handle,
uint16_t* near_spectrum,
const uint16_t* near_spectrum,
int spectrum_size,
int near_q) {
DelayEstimator* self = (DelayEstimator*) handle;
@ -441,7 +444,7 @@ int WebRtc_DelayEstimatorProcessFix(void* handle,
}
int WebRtc_DelayEstimatorProcessFloat(void* handle,
float* near_spectrum,
const float* near_spectrum,
int spectrum_size) {
DelayEstimator* self = (DelayEstimator*) handle;
uint32_t binary_spectrum = 0;

View File

@ -57,11 +57,18 @@ void WebRtc_SoftResetDelayEstimatorFarend(void* handle, int delay_shift);
// - spectrum_size : The size of the data arrays (same for both far- and
// near-end).
// - far_q : The Q-domain of the far-end data.
int WebRtc_AddFarSpectrumFix(void* handle, uint16_t* far_spectrum,
int spectrum_size, int far_q);
//
// Output:
// - handle : Updated far-end instance.
//
int WebRtc_AddFarSpectrumFix(void* handle,
const uint16_t* far_spectrum,
int spectrum_size,
int far_q);
// See WebRtc_AddFarSpectrumFix() for description.
int WebRtc_AddFarSpectrumFloat(void* handle, float* far_spectrum,
int WebRtc_AddFarSpectrumFloat(void* handle,
const float* far_spectrum,
int spectrum_size);
// Releases the memory allocated by WebRtc_CreateDelayEstimator(...)
@ -204,13 +211,13 @@ int WebRtc_is_robust_validation_enabled(const void* handle);
// -1 - Error.
// -2 - Insufficient data for estimation.
int WebRtc_DelayEstimatorProcessFix(void* handle,
uint16_t* near_spectrum,
const uint16_t* near_spectrum,
int spectrum_size,
int near_q);
// See WebRtc_DelayEstimatorProcessFix() for description.
int WebRtc_DelayEstimatorProcessFloat(void* handle,
float* near_spectrum,
const float* near_spectrum,
int spectrum_size);
// Returns the last calculated delay updated by the function