aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_processing/utility
diff options
context:
space:
mode:
authorbjornv@webrtc.org <bjornv@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-01-18 23:16:46 +0000
committerbjornv@webrtc.org <bjornv@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-01-18 23:16:46 +0000
commitbb599b7089e1927ae3bc0948a6205bb8130d325f (patch)
tree227f925726882668d94d593def51dc2871e28436 /webrtc/modules/audio_processing/utility
parenta2d8b75f291a3c33e337bbf7a527f8b4e9e32f19 (diff)
downloadwebrtc-bb599b7089e1927ae3bc0948a6205bb8130d325f.tar.gz
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
Diffstat (limited to 'webrtc/modules/audio_processing/utility')
-rw-r--r--webrtc/modules/audio_processing/utility/delay_estimator.c21
-rw-r--r--webrtc/modules/audio_processing/utility/delay_estimator.h21
-rw-r--r--webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc2
-rw-r--r--webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c12
4 files changed, 37 insertions, 19 deletions
diff --git a/webrtc/modules/audio_processing/utility/delay_estimator.c b/webrtc/modules/audio_processing/utility/delay_estimator.c
index 355a6b9447..59909c12b7 100644
--- a/webrtc/modules/audio_processing/utility/delay_estimator.c
+++ b/webrtc/modules/audio_processing/utility/delay_estimator.c
@@ -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.
diff --git a/webrtc/modules/audio_processing/utility/delay_estimator.h b/webrtc/modules/audio_processing/utility/delay_estimator.h
index 97456d195d..da46e72863 100644
--- a/webrtc/modules/audio_processing/utility/delay_estimator.h
+++ b/webrtc/modules/audio_processing/utility/delay_estimator.h
@@ -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
diff --git a/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc b/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc
index 58599a35ef..43504effbb 100644
--- a/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc
+++ b/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc
@@ -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.
diff --git a/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c b/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c
index 474cb69ba7..3a6f5b11e9 100644
--- a/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c
+++ b/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c
@@ -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);
}