New _CreateBinaryDelayEstimator() and removed _history_size()

Changed create function to match malloc() in functionality.
Removed unused function.

Tested with audioproc_unittest

BUG=
TEST=

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2048 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
bjornv@webrtc.org 2012-04-18 08:30:29 +00:00
parent 180f83f8e2
commit 2e729762c7
3 changed files with 48 additions and 86 deletions

View File

@ -83,73 +83,52 @@ void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* handle) {
free(handle);
}
int WebRtc_CreateBinaryDelayEstimator(BinaryDelayEstimator** handle,
int max_delay,
int lookahead) {
BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(int max_delay,
int lookahead) {
BinaryDelayEstimator* self = NULL;
int history_size = max_delay + lookahead;
int return_value = 0;
int history_size = max_delay + lookahead; // Must be > 1 for buffer shifting.
if (handle == NULL) {
return -1;
}
*handle = NULL;
if (max_delay < 0) {
return -1;
}
if (lookahead < 0) {
return -1;
}
if (history_size < 2) {
// Must be this large for buffer shifting.
return -1;
if ((max_delay >= 0) && (lookahead >= 0) && (history_size > 1)) {
// Sanity conditions fulfilled.
self = malloc(sizeof(BinaryDelayEstimator));
}
self = malloc(sizeof(BinaryDelayEstimator));
*handle = self;
if (self == NULL) {
return -1;
if (self != NULL) {
int malloc_fail = 0;
self->mean_bit_counts = NULL;
self->bit_counts = NULL;
self->binary_far_history = NULL;
self->far_bit_counts = NULL;
self->binary_near_history = NULL;
self->history_size = history_size;
self->near_history_size = lookahead + 1;
// Allocate memory for spectrum buffers.
self->mean_bit_counts = malloc(history_size * sizeof(int32_t));
malloc_fail |= (self->mean_bit_counts == NULL);
self->bit_counts = malloc(history_size * sizeof(int32_t));
malloc_fail |= (self->bit_counts == NULL);
// Allocate memory for history buffers.
self->binary_far_history = malloc(history_size * sizeof(uint32_t));
malloc_fail |= (self->binary_far_history == NULL);
self->binary_near_history = malloc((lookahead + 1) * sizeof(uint32_t));
malloc_fail |= (self->binary_near_history == NULL);
self->far_bit_counts = malloc(history_size * sizeof(int));
malloc_fail |= (self->far_bit_counts == NULL);
if (malloc_fail) {
WebRtc_FreeBinaryDelayEstimator(self);
self = NULL;
}
}
self->mean_bit_counts = NULL;
self->bit_counts = NULL;
self->binary_far_history = NULL;
self->far_bit_counts = NULL;
self->binary_near_history = NULL;
self->history_size = history_size;
self->near_history_size = lookahead + 1;
// Allocate memory for spectrum buffers.
self->mean_bit_counts = malloc(history_size * sizeof(int32_t));
if (self->mean_bit_counts == NULL) {
return_value = -1;
}
self->bit_counts = malloc(history_size * sizeof(int32_t));
if (self->bit_counts == NULL) {
return_value = -1;
}
// Allocate memory for history buffers.
self->binary_far_history = malloc(history_size * sizeof(uint32_t));
if (self->binary_far_history == NULL) {
return_value = -1;
}
self->binary_near_history = malloc(self->near_history_size *
sizeof(uint32_t));
if (self->binary_near_history == NULL) {
return_value = -1;
}
self->far_bit_counts = malloc(history_size * sizeof(int));
if (self->far_bit_counts == NULL) {
return_value = -1;
}
if (return_value == -1) {
WebRtc_FreeBinaryDelayEstimator(self);
*handle = NULL;
}
return return_value;
return self;
}
int WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator* handle) {
@ -292,11 +271,6 @@ int WebRtc_binary_last_delay(BinaryDelayEstimator* handle) {
return handle->last_delay;
}
int WebRtc_history_size(BinaryDelayEstimator* handle) {
assert(handle != NULL);
return handle->history_size;
}
void WebRtc_MeanEstimatorFix(int32_t new_value,
int factor,
int32_t* mean_value) {

View File

@ -45,14 +45,15 @@ typedef struct {
// Releases the memory allocated by WebRtc_CreateBinaryDelayEstimator(...).
// Input:
// - handle : Pointer to the delay estimation instance.
// - handle : Pointer to the binary delay estimation instance
// which is the return value of
// WebRtc_CreateBinaryDelayEstimator().
//
void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* handle);
// Refer to WebRtc_CreateDelayEstimator() in delay_estimator_wrapper.h.
int WebRtc_CreateBinaryDelayEstimator(BinaryDelayEstimator** handle,
int max_delay,
int lookahead);
BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(int max_delay,
int lookahead);
// Initializes the delay estimation instance created with
// WebRtc_CreateBinaryDelayEstimator(...).
@ -97,18 +98,6 @@ int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator* handle,
//
int WebRtc_binary_last_delay(BinaryDelayEstimator* handle);
// Returns the history size used in the far-end buffers to calculate the delay
// over.
//
// Input:
// - handle : Pointer to the delay estimation instance.
//
// Return value:
// - history_size : > 0 - Far-end history size.
// -1 - Error.
//
int WebRtc_history_size(BinaryDelayEstimator* handle);
// Updates the |mean_value| recursively with a step size of 2^-|factor|. This
// function is used internally in the Binary Delay Estimator as well as the
// Fixed point wrapper.

View File

@ -188,12 +188,11 @@ int WebRtc_CreateDelayEstimator(void** handle,
self->mean_far_spectrum = NULL;
self->mean_near_spectrum = NULL;
// Create binary delay estimator.
if (WebRtc_CreateBinaryDelayEstimator(&self->binary_handle,
max_delay,
lookahead) != 0) {
self->binary_handle = WebRtc_CreateBinaryDelayEstimator(max_delay, lookahead);
if (self->binary_handle == NULL) {
return_value = -1;
}
// Allocate memory for spectrum buffers.
self->mean_far_spectrum = malloc(spectrum_size * sizeof(SpectrumType));
if (self->mean_far_spectrum == NULL) {