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:
parent
180f83f8e2
commit
2e729762c7
@ -83,35 +83,19 @@ void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* handle) {
|
||||
free(handle);
|
||||
}
|
||||
|
||||
int WebRtc_CreateBinaryDelayEstimator(BinaryDelayEstimator** handle,
|
||||
int max_delay,
|
||||
BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(int max_delay,
|
||||
int lookahead) {
|
||||
BinaryDelayEstimator* self = NULL;
|
||||
int history_size = max_delay + lookahead;
|
||||
int return_value = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
int history_size = max_delay + lookahead; // Must be > 1 for buffer shifting.
|
||||
|
||||
if ((max_delay >= 0) && (lookahead >= 0) && (history_size > 1)) {
|
||||
// Sanity conditions fulfilled.
|
||||
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;
|
||||
@ -123,33 +107,28 @@ int WebRtc_CreateBinaryDelayEstimator(BinaryDelayEstimator** handle,
|
||||
|
||||
// Allocate memory for spectrum buffers.
|
||||
self->mean_bit_counts = malloc(history_size * sizeof(int32_t));
|
||||
if (self->mean_bit_counts == NULL) {
|
||||
return_value = -1;
|
||||
}
|
||||
malloc_fail |= (self->mean_bit_counts == NULL);
|
||||
|
||||
self->bit_counts = malloc(history_size * sizeof(int32_t));
|
||||
if (self->bit_counts == NULL) {
|
||||
return_value = -1;
|
||||
}
|
||||
malloc_fail |= (self->bit_counts == NULL);
|
||||
|
||||
// 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;
|
||||
}
|
||||
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));
|
||||
if (self->far_bit_counts == NULL) {
|
||||
return_value = -1;
|
||||
malloc_fail |= (self->far_bit_counts == NULL);
|
||||
|
||||
if (malloc_fail) {
|
||||
WebRtc_FreeBinaryDelayEstimator(self);
|
||||
self = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -45,13 +45,14 @@ 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,
|
||||
BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(int max_delay,
|
||||
int lookahead);
|
||||
|
||||
// Initializes the delay estimation instance created with
|
||||
@ -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.
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user