2011-09-15 12:27:36 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-11-18 08:30:34 +00:00
|
|
|
// Performs delay estimation on binary converted spectra.
|
2011-09-15 12:27:36 +00:00
|
|
|
// The return value is 0 - OK and -1 - Error, unless otherwise stated.
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_H_
|
|
|
|
|
|
2011-11-18 08:30:34 +00:00
|
|
|
#include "signal_processing_library.h"
|
2011-09-15 15:01:04 +00:00
|
|
|
#include "typedefs.h"
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2011-11-18 08:30:34 +00:00
|
|
|
typedef struct {
|
|
|
|
|
// Pointer to bit counts
|
|
|
|
|
int32_t* mean_bit_counts;
|
|
|
|
|
|
|
|
|
|
// Array only used locally in ProcessBinarySpectrum() but whose size is
|
|
|
|
|
// determined at run-time.
|
|
|
|
|
int32_t* bit_counts;
|
|
|
|
|
|
2011-11-22 22:40:27 +00:00
|
|
|
// Binary history variables.
|
2011-11-18 08:30:34 +00:00
|
|
|
uint32_t* binary_far_history;
|
2011-11-22 22:40:27 +00:00
|
|
|
uint32_t* binary_near_history;
|
2011-11-18 08:30:34 +00:00
|
|
|
|
2011-11-22 22:40:27 +00:00
|
|
|
// Delay histogram variables.
|
2011-11-18 08:30:34 +00:00
|
|
|
int* delay_histogram;
|
|
|
|
|
int vad_counter;
|
|
|
|
|
|
2011-11-22 22:40:27 +00:00
|
|
|
// Delay memory.
|
2011-11-18 08:30:34 +00:00
|
|
|
int last_delay;
|
|
|
|
|
|
2011-11-22 22:40:27 +00:00
|
|
|
// Buffer size.
|
2011-11-18 08:30:34 +00:00
|
|
|
int history_size;
|
2011-11-22 22:40:27 +00:00
|
|
|
|
|
|
|
|
// Near-end buffer size.
|
|
|
|
|
int near_history_size;
|
2011-11-18 08:30:34 +00:00
|
|
|
} BinaryDelayEstimator_t;
|
|
|
|
|
|
|
|
|
|
// Releases the memory allocated by WebRtc_CreateBinaryDelayEstimator(...)
|
2011-09-15 12:27:36 +00:00
|
|
|
// Input:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - handle : Pointer to the delay estimation instance
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2011-11-18 08:30:34 +00:00
|
|
|
int WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator_t* handle);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2011-11-22 22:40:27 +00:00
|
|
|
// Refer to WebRtc_CreateDelayEstimator() in delay_estimator_wrapper.h
|
2011-11-18 08:30:34 +00:00
|
|
|
int WebRtc_CreateBinaryDelayEstimator(BinaryDelayEstimator_t** handle,
|
2011-11-22 22:40:27 +00:00
|
|
|
int max_delay,
|
|
|
|
|
int lookahead);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
|
|
|
|
// Initializes the delay estimation instance created with
|
2011-11-18 08:30:34 +00:00
|
|
|
// WebRtc_CreateBinaryDelayEstimator(...)
|
2011-09-15 12:27:36 +00:00
|
|
|
// Input:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - handle : Pointer to the delay estimation instance
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Output:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - handle : Initialized instance
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2011-11-18 08:30:34 +00:00
|
|
|
int WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator_t* handle);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2011-11-22 22:40:27 +00:00
|
|
|
// 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).
|
2011-09-15 12:27:36 +00:00
|
|
|
// Inputs:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - handle : Pointer to the delay estimation instance
|
2011-11-22 22:40:27 +00:00
|
|
|
// - binary_far_spectrum : Far-end binary spectrum
|
|
|
|
|
// - binary_near_spectrum : Near-end binary spectrum of the current block
|
2011-11-18 08:30:34 +00:00
|
|
|
// - vad_value : The VAD decision of the current block
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Output:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - handle : Updated instance
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Return value:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - delay : >= 0 - Calculated delay value
|
|
|
|
|
// -1 - Error
|
2011-11-27 23:40:58 +00:00
|
|
|
// -2 - Insufficient data for estimation.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2011-11-18 08:30:34 +00:00
|
|
|
int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator_t* handle,
|
|
|
|
|
uint32_t binary_far_spectrum,
|
|
|
|
|
uint32_t binary_near_spectrum,
|
|
|
|
|
int vad_value);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
|
|
|
|
// Returns the last calculated delay updated by the function
|
2011-11-18 08:30:34 +00:00
|
|
|
// WebRtc_ProcessBinarySpectrum(...)
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Input:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - handle : Pointer to the delay estimation instance
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Return value:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - delay : >= 0 - Last calculated delay value
|
|
|
|
|
// -1 - Error
|
2011-11-27 23:40:58 +00:00
|
|
|
// -2 - Insufficient data for estimation.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2011-11-18 08:30:34 +00:00
|
|
|
int WebRtc_binary_last_delay(BinaryDelayEstimator_t* handle);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2011-11-22 22:40:27 +00:00
|
|
|
// Returns the history size used in the far-end buffers to calculate the delay
|
2011-09-15 12:27:36 +00:00
|
|
|
// over.
|
|
|
|
|
//
|
|
|
|
|
// Input:
|
2011-11-18 08:30:34 +00:00
|
|
|
// - handle : Pointer to the delay estimation instance
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Return value:
|
2011-11-22 22:40:27 +00:00
|
|
|
// - history_size : > 0 - Far-end history size
|
2011-11-18 08:30:34 +00:00
|
|
|
// -1 - Error
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2011-11-18 08:30:34 +00:00
|
|
|
int WebRtc_history_size(BinaryDelayEstimator_t* handle);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2011-11-18 08:30:34 +00:00
|
|
|
// 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.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2011-11-18 08:30:34 +00:00
|
|
|
// Inputs:
|
|
|
|
|
// - new_value : The new value the mean should be updated with.
|
|
|
|
|
// - factor : The step size, in number of right shifts.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2011-11-18 08:30:34 +00:00
|
|
|
// Input/Output:
|
|
|
|
|
// - mean_value : Pointer to the mean value.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2011-11-18 08:30:34 +00:00
|
|
|
void WebRtc_MeanEstimatorFix(int32_t new_value,
|
|
|
|
|
int factor,
|
|
|
|
|
int32_t* mean_value);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_H_
|