This CL includes part of changes in a larger one. The final goal is to allow multiple delay estimators using the same reference (far-end) to save computational complexity.

BUG=None

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3391 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
bjornv@webrtc.org 2013-01-18 23:16:46 +00:00
parent a2d8b75f29
commit bb599b7089
4 changed files with 37 additions and 19 deletions

View File

@ -151,15 +151,8 @@ void WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator* handle) {
handle->last_delay = -2;
}
int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator* handle,
uint32_t binary_far_spectrum,
uint32_t binary_near_spectrum) {
int i = 0;
int candidate_delay = -1;
int32_t value_best_candidate = 32 << 9; // 32 in Q9, (max |mean_bit_counts|).
int32_t value_worst_candidate = 0;
void WebRtc_AddBinaryFarSpectrum(BinaryDelayEstimator* handle,
uint32_t binary_far_spectrum) {
assert(handle != NULL);
// Shift binary spectrum history and insert current |binary_far_spectrum|.
memmove(&(handle->binary_far_history[1]), &(handle->binary_far_history[0]),
@ -171,7 +164,17 @@ int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator* handle,
memmove(&(handle->far_bit_counts[1]), &(handle->far_bit_counts[0]),
(handle->history_size - 1) * sizeof(int));
handle->far_bit_counts[0] = BitCount(binary_far_spectrum);
}
int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator* handle,
uint32_t binary_near_spectrum) {
int i = 0;
int candidate_delay = -1;
int32_t value_best_candidate = 32 << 9; // 32 in Q9, (max |mean_bit_counts|).
int32_t value_worst_candidate = 0;
assert(handle != NULL);
if (handle->near_history_size > 1) {
// If we apply lookahead, shift near-end binary spectrum history. Insert
// current |binary_near_spectrum| and pull out the delayed one.

View File

@ -65,12 +65,26 @@ BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(int max_delay,
//
void WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator* handle);
// Estimates and returns the delay between the binary far-end and binary near-
// end spectra. The value will be offset by the lookahead (i.e. the lookahead
// should be subtracted from the returned value).
// Adds the binary far-end spectrum to the internal buffer. This spectrum is
// used as reference when calculating the delay using
// WebRtc_ProcessBinarySpectrum().
// Inputs:
// - handle : Pointer to the delay estimation instance.
// - binary_far_spectrum : Far-end binary spectrum.
//
// Output:
// - handle : Updated instance.
//
void WebRtc_AddBinaryFarSpectrum(BinaryDelayEstimator* handle,
uint32_t binary_far_spectrum);
// Estimates and returns the delay between the binary far-end and binary near-
// end spectra. It is assumed the binary far-end spectrum has been added using
// WebRtc_AddBinaryFarSpectrum() prior to this call. The value will be offset by
// the lookahead (i.e. the lookahead should be subtracted from the returned
// value).
// Inputs:
// - handle : Pointer to the delay estimation instance.
// - binary_near_spectrum : Near-end binary spectrum of the current block.
//
// Output:
@ -82,7 +96,6 @@ void WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator* handle);
// -2 - Insufficient data for estimation.
//
int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator* handle,
uint32_t binary_far_spectrum,
uint32_t binary_near_spectrum);
// Returns the last calculated delay updated by the function

View File

@ -291,8 +291,8 @@ TEST_F(DelayEstimatorTest, ExactDelayEstimate) {
for (int offset = -kLookahead; offset < kMaxDelay; offset++) {
InitBinary();
for (int i = kLookahead; i < (sequence_length + kLookahead); i++) {
WebRtc_AddBinaryFarSpectrum(binary_handle_, binary_spectrum[i + offset]);
int delay = WebRtc_ProcessBinarySpectrum(binary_handle_,
binary_spectrum[i + offset],
binary_spectrum[i]);
// Verify that we WebRtc_binary_last_delay() returns correct delay.

View File

@ -248,8 +248,9 @@ int WebRtc_DelayEstimatorProcessFix(void* handle,
near_q,
&(self->near_spectrum_initialized));
WebRtc_AddBinaryFarSpectrum(self->binary_handle, binary_far_spectrum);
return WebRtc_ProcessBinarySpectrum(self->binary_handle,
binary_far_spectrum,
binary_near_spectrum);
}
@ -281,12 +282,13 @@ int WebRtc_DelayEstimatorProcessFloat(void* handle,
binary_far_spectrum = BinarySpectrumFloat(far_spectrum,
self->mean_far_spectrum,
&(self->far_spectrum_initialized));
binary_near_spectrum = BinarySpectrumFloat(near_spectrum,
self->mean_near_spectrum,
&(self->near_spectrum_initialized));
binary_near_spectrum =
BinarySpectrumFloat(near_spectrum, self->mean_near_spectrum,
&(self->near_spectrum_initialized));
WebRtc_AddBinaryFarSpectrum(self->binary_handle, binary_far_spectrum);
return WebRtc_ProcessBinarySpectrum(self->binary_handle,
binary_far_spectrum,
binary_near_spectrum);
}