Update audio_processing module

Corresponds to upstream commit 524e9b043e7e86fd72353b987c9d5f6a1ebf83e1

Update notes:

 * Pull in third party license file

 * Replace .gypi files with BUILD.gn to keep track of what changes
   upstream

 * Bunch of new filse pulled in as dependencies

 * Won't build yet due to changes needed on top of these
This commit is contained in:
Arun Raghavan
2015-10-13 17:25:22 +05:30
parent 5ae7a5d6cd
commit 753eada3aa
324 changed files with 52533 additions and 16117 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
* Copyright (c) 2012 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
@ -8,147 +8,244 @@
* be found in the AUTHORS file in the root of the source tree.
*/
// Performs delay estimation on a block by block basis
// Performs delay estimation on binary converted spectra.
// 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_
#include "typedefs.h"
#include "webrtc/typedefs.h"
// Releases the memory allocated by WebRtc_CreateDelayEstimator(...)
static const int32_t kMaxBitCountsQ9 = (32 << 9); // 32 matching bits in Q9.
typedef struct {
// Pointer to bit counts.
int* far_bit_counts;
// Binary history variables.
uint32_t* binary_far_history;
int history_size;
} BinaryDelayEstimatorFarend;
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;
// Binary history variables.
uint32_t* binary_near_history;
int near_history_size;
int history_size;
// Delay estimation variables.
int32_t minimum_probability;
int last_delay_probability;
// Delay memory.
int last_delay;
// Robust validation
int robust_validation_enabled;
int allowed_offset;
int last_candidate_delay;
int compare_delay;
int candidate_hits;
float* histogram;
float last_delay_histogram;
// For dynamically changing the lookahead when using SoftReset...().
int lookahead;
// Far-end binary spectrum history buffer etc.
BinaryDelayEstimatorFarend* farend;
} BinaryDelayEstimator;
// Releases the memory allocated by
// WebRtc_CreateBinaryDelayEstimatorFarend(...).
// Input:
// - handle : Pointer to the delay estimation instance
// - self : Pointer to the binary delay estimation far-end
// instance which is the return value of
// WebRtc_CreateBinaryDelayEstimatorFarend().
//
int WebRtc_FreeDelayEstimator(void* handle);
void WebRtc_FreeBinaryDelayEstimatorFarend(BinaryDelayEstimatorFarend* self);
// Allocates the memory needed by the delay estimation. The memory needs to be
// initialized separately using the WebRtc_InitDelayEstimator(...)
// function.
// Allocates the memory needed by the far-end part of the binary delay
// estimation. The memory needs to be initialized separately through
// WebRtc_InitBinaryDelayEstimatorFarend(...).
//
// Inputs:
// - handle : Instance that should be created
// - spectrum_size : Size of the spectrum used both in far end and
// near end. Used to allocate memory for spectrum
// specific buffers.
// - history_size : Size of the far end history used to estimate the
// delay from. Used to allocate memory for history
// specific buffers.
// - enable_alignment : With this mode set to 1, a far end history is
// created, so that the user can retrieve aligned
// far end spectra using
// WebRtc_AlignedFarend(...). Otherwise, only delay
// values are calculated.
// - history_size : Size of the far-end binary spectrum history.
//
// Return value:
// - BinaryDelayEstimatorFarend*
// : Created |handle|. If the memory can't be allocated
// or if any of the input parameters are invalid NULL
// is returned.
//
BinaryDelayEstimatorFarend* WebRtc_CreateBinaryDelayEstimatorFarend(
int history_size);
// Re-allocates the buffers.
//
// Inputs:
// - self : Pointer to the binary estimation far-end instance
// which is the return value of
// WebRtc_CreateBinaryDelayEstimatorFarend().
// - history_size : Size of the far-end binary spectrum history.
//
// Return value:
// - history_size : The history size allocated.
int WebRtc_AllocateFarendBufferMemory(BinaryDelayEstimatorFarend* self,
int history_size);
// Initializes the delay estimation far-end instance created with
// WebRtc_CreateBinaryDelayEstimatorFarend(...).
//
// Input:
// - self : Pointer to the delay estimation far-end instance.
//
// Output:
// - handle : Created instance
// - self : Initialized far-end instance.
//
int WebRtc_CreateDelayEstimator(void** handle,
int spectrum_size,
int history_size,
int enable_alignment);
void WebRtc_InitBinaryDelayEstimatorFarend(BinaryDelayEstimatorFarend* self);
// Soft resets the delay estimation far-end instance created with
// WebRtc_CreateBinaryDelayEstimatorFarend(...).
//
// Input:
// - delay_shift : The amount of blocks to shift history buffers.
//
void WebRtc_SoftResetBinaryDelayEstimatorFarend(
BinaryDelayEstimatorFarend* self, int delay_shift);
// Adds the binary far-end spectrum to the internal far-end history buffer. This
// spectrum is used as reference when calculating the delay using
// WebRtc_ProcessBinarySpectrum().
//
// Inputs:
// - self : Pointer to the delay estimation far-end
// instance.
// - binary_far_spectrum : Far-end binary spectrum.
//
// Output:
// - self : Updated far-end instance.
//
void WebRtc_AddBinaryFarSpectrum(BinaryDelayEstimatorFarend* self,
uint32_t binary_far_spectrum);
// Releases the memory allocated by WebRtc_CreateBinaryDelayEstimator(...).
//
// Note that BinaryDelayEstimator utilizes BinaryDelayEstimatorFarend, but does
// not take ownership of it, hence the BinaryDelayEstimator has to be torn down
// before the far-end.
//
// Input:
// - self : Pointer to the binary delay estimation instance
// which is the return value of
// WebRtc_CreateBinaryDelayEstimator().
//
void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* self);
// Allocates the memory needed by the binary delay estimation. The memory needs
// to be initialized separately through WebRtc_InitBinaryDelayEstimator(...).
//
// See WebRtc_CreateDelayEstimator(..) in delay_estimator_wrapper.c for detailed
// description.
BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(
BinaryDelayEstimatorFarend* farend, int max_lookahead);
// Re-allocates |history_size| dependent buffers. The far-end buffers will be
// updated at the same time if needed.
//
// Input:
// - self : Pointer to the binary estimation instance which is
// the return value of
// WebRtc_CreateBinaryDelayEstimator().
// - history_size : Size of the history buffers.
//
// Return value:
// - history_size : The history size allocated.
int WebRtc_AllocateHistoryBufferMemory(BinaryDelayEstimator* self,
int history_size);
// Initializes the delay estimation instance created with
// WebRtc_CreateDelayEstimator(...)
// WebRtc_CreateBinaryDelayEstimator(...).
//
// Input:
// - handle : Pointer to the delay estimation instance
// - self : Pointer to the delay estimation instance.
//
// Output:
// - handle : Initialized instance
// - self : Initialized instance.
//
int WebRtc_InitDelayEstimator(void* handle);
void WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator* self);
// Estimates and returns the delay between the far end and near end blocks.
// Inputs:
// - handle : Pointer to the delay estimation instance
// - far_spectrum : Pointer to the far end spectrum data
// - near_spectrum : Pointer to the near end spectrum data of the current
// block
// - spectrum_size : The size of the data arrays (same for both far and
// near end)
// - far_q : The Q-domain of the far end data
// - vad_value : The VAD decision of the current block
// Soft resets the delay estimation instance created with
// WebRtc_CreateBinaryDelayEstimator(...).
//
// Output:
// - handle : Updated instance
// Input:
// - delay_shift : The amount of blocks to shift history buffers.
//
// Return value:
// - delay : >= 0 - Calculated delay value
// -1 - Error
// - actual_shifts : The actual number of shifts performed.
//
int WebRtc_DelayEstimatorProcess(void* handle,
uint16_t* far_spectrum,
uint16_t* near_spectrum,
int spectrum_size,
int far_q,
int vad_value);
int WebRtc_SoftResetBinaryDelayEstimator(BinaryDelayEstimator* self,
int delay_shift);
// Returns a pointer to the far end spectrum aligned to current near end
// spectrum. The function WebRtc_DelayEstimatorProcess(...) should have been
// called before WebRtc_AlignedFarend(...). Otherwise, you get the pointer to
// the previous frame. The memory is only valid until the next call of
// WebRtc_DelayEstimatorProcess(...).
// 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
// - far_spectrum_size : Size of far_spectrum allocated by the caller
// - self : Pointer to the delay estimation instance.
// - binary_near_spectrum : Near-end binary spectrum of the current block.
//
// Output:
// - far_q : The Q-domain of the aligned far end spectrum
// - self : Updated instance.
//
// Return value:
// - far_spectrum : Pointer to the aligned far end spectrum
// NULL - Error
// - delay : >= 0 - Calculated delay value.
// -2 - Insufficient data for estimation.
//
const uint16_t* WebRtc_AlignedFarend(void* handle,
int far_spectrum_size,
int* far_q);
int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator* self,
uint32_t binary_near_spectrum);
// Returns the last calculated delay updated by the function
// WebRtc_DelayEstimatorProcess(...)
// WebRtc_ProcessBinarySpectrum(...).
//
// Input:
// - handle : Pointer to the delay estimation instance
// - self : Pointer to the delay estimation instance.
//
// Return value:
// - delay : >= 0 - Last calculated delay value
// -1 - Error
// - delay : >= 0 - Last calculated delay value
// -2 - Insufficient data for estimation.
//
int WebRtc_last_delay(void* handle);
int WebRtc_binary_last_delay(BinaryDelayEstimator* self);
// Returns the history size used in the far end buffers to calculate the delay
// over.
//
// Input:
// - handle : Pointer to the delay estimation instance
// Returns the estimation quality of the last calculated delay updated by the
// function WebRtc_ProcessBinarySpectrum(...). The estimation quality is a value
// in the interval [0, 1]. The higher the value, the better the quality.
//
// Return value:
// - history_size : > 0 - Far end history size
// -1 - Error
//
int WebRtc_history_size(void* handle);
// - delay_quality : >= 0 - Estimation quality of last calculated
// delay value.
float WebRtc_binary_last_delay_quality(BinaryDelayEstimator* self);
// Returns the fixed spectrum size used in the algorithm.
// 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.
//
// Input:
// - handle : Pointer to the delay estimation instance
// Inputs:
// - new_value : The new value the mean should be updated with.
// - factor : The step size, in number of right shifts.
//
// Return value:
// - spectrum_size : > 0 - Spectrum size
// -1 - Error
// Input/Output:
// - mean_value : Pointer to the mean value.
//
int WebRtc_spectrum_size(void* handle);
// Returns 1 if the far end alignment is enabled and 0 otherwise.
//
// Input:
// - handle : Pointer to the delay estimation instance
//
// Return value:
// - alignment_enabled : 1 - Enabled
// 0 - Disabled
// -1 - Error
//
int WebRtc_is_alignment_enabled(void* handle);
void WebRtc_MeanEstimatorFix(int32_t new_value,
int factor,
int32_t* mean_value);
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_H_