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,73 +83,52 @@ void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* handle) {
|
|||||||
free(handle);
|
free(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebRtc_CreateBinaryDelayEstimator(BinaryDelayEstimator** handle,
|
BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(int max_delay,
|
||||||
int max_delay,
|
int lookahead) {
|
||||||
int lookahead) {
|
|
||||||
BinaryDelayEstimator* self = NULL;
|
BinaryDelayEstimator* self = NULL;
|
||||||
int history_size = max_delay + lookahead;
|
int history_size = max_delay + lookahead; // Must be > 1 for buffer shifting.
|
||||||
int return_value = 0;
|
|
||||||
|
|
||||||
if (handle == NULL) {
|
if ((max_delay >= 0) && (lookahead >= 0) && (history_size > 1)) {
|
||||||
return -1;
|
// Sanity conditions fulfilled.
|
||||||
}
|
self = malloc(sizeof(BinaryDelayEstimator));
|
||||||
*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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self = malloc(sizeof(BinaryDelayEstimator));
|
if (self != NULL) {
|
||||||
*handle = self;
|
int malloc_fail = 0;
|
||||||
if (self == NULL) {
|
|
||||||
return -1;
|
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;
|
return self;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator* handle) {
|
int WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator* handle) {
|
||||||
@ -292,11 +271,6 @@ int WebRtc_binary_last_delay(BinaryDelayEstimator* handle) {
|
|||||||
return handle->last_delay;
|
return handle->last_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebRtc_history_size(BinaryDelayEstimator* handle) {
|
|
||||||
assert(handle != NULL);
|
|
||||||
return handle->history_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebRtc_MeanEstimatorFix(int32_t new_value,
|
void WebRtc_MeanEstimatorFix(int32_t new_value,
|
||||||
int factor,
|
int factor,
|
||||||
int32_t* mean_value) {
|
int32_t* mean_value) {
|
||||||
|
@ -45,14 +45,15 @@ typedef struct {
|
|||||||
|
|
||||||
// Releases the memory allocated by WebRtc_CreateBinaryDelayEstimator(...).
|
// Releases the memory allocated by WebRtc_CreateBinaryDelayEstimator(...).
|
||||||
// Input:
|
// 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);
|
void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* handle);
|
||||||
|
|
||||||
// Refer to WebRtc_CreateDelayEstimator() in delay_estimator_wrapper.h.
|
// Refer to WebRtc_CreateDelayEstimator() in delay_estimator_wrapper.h.
|
||||||
int WebRtc_CreateBinaryDelayEstimator(BinaryDelayEstimator** handle,
|
BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(int max_delay,
|
||||||
int max_delay,
|
int lookahead);
|
||||||
int lookahead);
|
|
||||||
|
|
||||||
// Initializes the delay estimation instance created with
|
// Initializes the delay estimation instance created with
|
||||||
// WebRtc_CreateBinaryDelayEstimator(...).
|
// WebRtc_CreateBinaryDelayEstimator(...).
|
||||||
@ -97,18 +98,6 @@ int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator* handle,
|
|||||||
//
|
//
|
||||||
int WebRtc_binary_last_delay(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
|
// 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
|
// function is used internally in the Binary Delay Estimator as well as the
|
||||||
// Fixed point wrapper.
|
// Fixed point wrapper.
|
||||||
|
@ -188,12 +188,11 @@ int WebRtc_CreateDelayEstimator(void** handle,
|
|||||||
self->mean_far_spectrum = NULL;
|
self->mean_far_spectrum = NULL;
|
||||||
self->mean_near_spectrum = NULL;
|
self->mean_near_spectrum = NULL;
|
||||||
|
|
||||||
// Create binary delay estimator.
|
self->binary_handle = WebRtc_CreateBinaryDelayEstimator(max_delay, lookahead);
|
||||||
if (WebRtc_CreateBinaryDelayEstimator(&self->binary_handle,
|
if (self->binary_handle == NULL) {
|
||||||
max_delay,
|
|
||||||
lookahead) != 0) {
|
|
||||||
return_value = -1;
|
return_value = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate memory for spectrum buffers.
|
// Allocate memory for spectrum buffers.
|
||||||
self->mean_far_spectrum = malloc(spectrum_size * sizeof(SpectrumType));
|
self->mean_far_spectrum = malloc(spectrum_size * sizeof(SpectrumType));
|
||||||
if (self->mean_far_spectrum == NULL) {
|
if (self->mean_far_spectrum == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user