2011-09-15 12:27:36 +00:00
|
|
|
/*
|
2012-04-16 07:28:29 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-09-15 12:27:36 +00:00
|
|
|
*
|
|
|
|
|
* 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_
|
|
|
|
|
|
Revert 3428
> Delay estimator wrapper API changes. This should finalize the changes to delay estimator making it work for multi-probe.
>
> The changes are summarized here:
>
> delay_estimator.*
> -----------------
> Replaced assert() with correct error check. This is consistent with previous versions of the delay_estimator, i.e., to check for valid parameters where they are actually used and not high up in a wrapper layer.
>
> delay_estimator_internal.h
> --------------------------
> Pulled out the far-end part of DelayEstimator struct and put it in DelayEstimatorFarend. The only common parameter is spectrum_size, which we store in both and thereby avoiding having a Farend pointer in DelayEstimator.
>
> delay_estimator_wrapper.*
> -------------------------
> Added and updated descriptions. From Free(), Create(), Init() the far-end parts have been put in separate Farend versions. Same goes for the Process() which now has an AddFarSpectrum() version.
> The flow of calls should be something like (in pseudo-code)
>
> far* = CreateFarend(history_size)
> near* = Create(far, lookahead)
> InitFarend(far)
> Init(near)
> while call ongoing
> AddFarSpectrum(far, far_spectrum)
> Process(near, near_spectrum)
> end while
> Free(near)
> FreeFarend(far)
>
> delay_estimator_unittest.cc
> ---------------------------
> Added farend support setting up calls as mentioned above.
>
> aecm_core.*
> -----------
> Cleaned up some lint warnings.
> Added delay_estimator_farend pointer. Called Create(), Init() and Free() in above mentioned order.
> If AddFarSpectrumFix() was not successfully done, we end and return -1. This is what we would have done for Process().
>
> aec_core.*
> ----------
> Cleaned up some lint warnings.
> Added delay_estimator_farend pointer. Calls in proper order. Since we only use the delay estimator for logging there is no error handling. We only call Process() if AddFarSpectrum() was successful though.
>
> TEST=audioproc_unittest, trybots
> BUG=None
>
> Review URL: https://webrtc-codereview.appspot.com/1076006
TBR=bjornv@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/1062008
git-svn-id: http://webrtc.googlecode.com/svn/trunk@3429 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-01-29 21:30:26 +00:00
|
|
|
#include "typedefs.h"
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2011-11-18 08:30:34 +00:00
|
|
|
typedef struct {
|
2011-12-29 14:51:21 +00:00
|
|
|
// Pointer to bit counts.
|
|
|
|
|
int* far_bit_counts;
|
2013-01-25 15:53:41 +00:00
|
|
|
// Binary history variables.
|
|
|
|
|
uint32_t* binary_far_history;
|
Revert 3428
> Delay estimator wrapper API changes. This should finalize the changes to delay estimator making it work for multi-probe.
>
> The changes are summarized here:
>
> delay_estimator.*
> -----------------
> Replaced assert() with correct error check. This is consistent with previous versions of the delay_estimator, i.e., to check for valid parameters where they are actually used and not high up in a wrapper layer.
>
> delay_estimator_internal.h
> --------------------------
> Pulled out the far-end part of DelayEstimator struct and put it in DelayEstimatorFarend. The only common parameter is spectrum_size, which we store in both and thereby avoiding having a Farend pointer in DelayEstimator.
>
> delay_estimator_wrapper.*
> -------------------------
> Added and updated descriptions. From Free(), Create(), Init() the far-end parts have been put in separate Farend versions. Same goes for the Process() which now has an AddFarSpectrum() version.
> The flow of calls should be something like (in pseudo-code)
>
> far* = CreateFarend(history_size)
> near* = Create(far, lookahead)
> InitFarend(far)
> Init(near)
> while call ongoing
> AddFarSpectrum(far, far_spectrum)
> Process(near, near_spectrum)
> end while
> Free(near)
> FreeFarend(far)
>
> delay_estimator_unittest.cc
> ---------------------------
> Added farend support setting up calls as mentioned above.
>
> aecm_core.*
> -----------
> Cleaned up some lint warnings.
> Added delay_estimator_farend pointer. Called Create(), Init() and Free() in above mentioned order.
> If AddFarSpectrumFix() was not successfully done, we end and return -1. This is what we would have done for Process().
>
> aec_core.*
> ----------
> Cleaned up some lint warnings.
> Added delay_estimator_farend pointer. Calls in proper order. Since we only use the delay estimator for logging there is no error handling. We only call Process() if AddFarSpectrum() was successful though.
>
> TEST=audioproc_unittest, trybots
> BUG=None
>
> Review URL: https://webrtc-codereview.appspot.com/1076006
TBR=bjornv@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/1062008
git-svn-id: http://webrtc.googlecode.com/svn/trunk@3429 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-01-29 21:30:26 +00:00
|
|
|
// Buffer size.
|
2013-01-25 15:53:41 +00:00
|
|
|
int history_size;
|
|
|
|
|
} BinaryDelayEstimatorFarend;
|
2011-11-18 08:30:34 +00:00
|
|
|
|
2013-01-25 15:53:41 +00:00
|
|
|
typedef struct {
|
|
|
|
|
// Pointer to bit counts.
|
|
|
|
|
int32_t* mean_bit_counts;
|
2011-11-18 08:30:34 +00:00
|
|
|
// 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.
|
|
|
|
|
uint32_t* binary_near_history;
|
2011-11-18 08:30:34 +00:00
|
|
|
|
2011-12-29 14:51:21 +00:00
|
|
|
// Delay estimation variables.
|
|
|
|
|
int32_t minimum_probability;
|
|
|
|
|
int last_delay_probability;
|
2011-11-18 08:30:34 +00:00
|
|
|
|
2011-11-22 22:40:27 +00:00
|
|
|
// Delay memory.
|
2011-11-18 08:30:34 +00:00
|
|
|
int last_delay;
|
|
|
|
|
|
Revert 3428
> Delay estimator wrapper API changes. This should finalize the changes to delay estimator making it work for multi-probe.
>
> The changes are summarized here:
>
> delay_estimator.*
> -----------------
> Replaced assert() with correct error check. This is consistent with previous versions of the delay_estimator, i.e., to check for valid parameters where they are actually used and not high up in a wrapper layer.
>
> delay_estimator_internal.h
> --------------------------
> Pulled out the far-end part of DelayEstimator struct and put it in DelayEstimatorFarend. The only common parameter is spectrum_size, which we store in both and thereby avoiding having a Farend pointer in DelayEstimator.
>
> delay_estimator_wrapper.*
> -------------------------
> Added and updated descriptions. From Free(), Create(), Init() the far-end parts have been put in separate Farend versions. Same goes for the Process() which now has an AddFarSpectrum() version.
> The flow of calls should be something like (in pseudo-code)
>
> far* = CreateFarend(history_size)
> near* = Create(far, lookahead)
> InitFarend(far)
> Init(near)
> while call ongoing
> AddFarSpectrum(far, far_spectrum)
> Process(near, near_spectrum)
> end while
> Free(near)
> FreeFarend(far)
>
> delay_estimator_unittest.cc
> ---------------------------
> Added farend support setting up calls as mentioned above.
>
> aecm_core.*
> -----------
> Cleaned up some lint warnings.
> Added delay_estimator_farend pointer. Called Create(), Init() and Free() in above mentioned order.
> If AddFarSpectrumFix() was not successfully done, we end and return -1. This is what we would have done for Process().
>
> aec_core.*
> ----------
> Cleaned up some lint warnings.
> Added delay_estimator_farend pointer. Calls in proper order. Since we only use the delay estimator for logging there is no error handling. We only call Process() if AddFarSpectrum() was successful though.
>
> TEST=audioproc_unittest, trybots
> BUG=None
>
> Review URL: https://webrtc-codereview.appspot.com/1076006
TBR=bjornv@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/1062008
git-svn-id: http://webrtc.googlecode.com/svn/trunk@3429 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-01-29 21:30:26 +00:00
|
|
|
// Near-end buffer size.
|
|
|
|
|
int near_history_size;
|
2013-01-25 15:53:41 +00:00
|
|
|
// Far-end binary spectrum history buffer etc.
|
|
|
|
|
BinaryDelayEstimatorFarend* farend;
|
2011-12-29 14:51:21 +00:00
|
|
|
} BinaryDelayEstimator;
|
2011-11-18 08:30:34 +00:00
|
|
|
|
2013-01-25 15:53:41 +00:00
|
|
|
// Releases the memory allocated by
|
|
|
|
|
// WebRtc_CreateBinaryDelayEstimatorFarend(...).
|
|
|
|
|
// Input:
|
|
|
|
|
// - self : Pointer to the binary delay estimation far-end
|
|
|
|
|
// instance which is the return value of
|
|
|
|
|
// WebRtc_CreateBinaryDelayEstimatorFarend().
|
|
|
|
|
//
|
|
|
|
|
void WebRtc_FreeBinaryDelayEstimatorFarend(BinaryDelayEstimatorFarend* self);
|
|
|
|
|
|
|
|
|
|
// 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:
|
|
|
|
|
// - 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);
|
|
|
|
|
|
|
|
|
|
// Initializes the delay estimation far-end instance created with
|
|
|
|
|
// WebRtc_CreateBinaryDelayEstimatorFarend(...).
|
|
|
|
|
//
|
|
|
|
|
// Input:
|
|
|
|
|
// - self : Pointer to the delay estimation far-end instance.
|
|
|
|
|
//
|
|
|
|
|
// Output:
|
|
|
|
|
// - self : Initialized far-end instance.
|
|
|
|
|
//
|
|
|
|
|
void WebRtc_InitBinaryDelayEstimatorFarend(BinaryDelayEstimatorFarend* self);
|
|
|
|
|
|
|
|
|
|
// 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:
|
2013-01-25 22:02:15 +00:00
|
|
|
// - self : Pointer to the delay estimation far-end
|
2013-01-25 15:53:41 +00:00
|
|
|
// instance.
|
|
|
|
|
// - binary_far_spectrum : Far-end binary spectrum.
|
|
|
|
|
//
|
|
|
|
|
// Output:
|
Revert 3428
> Delay estimator wrapper API changes. This should finalize the changes to delay estimator making it work for multi-probe.
>
> The changes are summarized here:
>
> delay_estimator.*
> -----------------
> Replaced assert() with correct error check. This is consistent with previous versions of the delay_estimator, i.e., to check for valid parameters where they are actually used and not high up in a wrapper layer.
>
> delay_estimator_internal.h
> --------------------------
> Pulled out the far-end part of DelayEstimator struct and put it in DelayEstimatorFarend. The only common parameter is spectrum_size, which we store in both and thereby avoiding having a Farend pointer in DelayEstimator.
>
> delay_estimator_wrapper.*
> -------------------------
> Added and updated descriptions. From Free(), Create(), Init() the far-end parts have been put in separate Farend versions. Same goes for the Process() which now has an AddFarSpectrum() version.
> The flow of calls should be something like (in pseudo-code)
>
> far* = CreateFarend(history_size)
> near* = Create(far, lookahead)
> InitFarend(far)
> Init(near)
> while call ongoing
> AddFarSpectrum(far, far_spectrum)
> Process(near, near_spectrum)
> end while
> Free(near)
> FreeFarend(far)
>
> delay_estimator_unittest.cc
> ---------------------------
> Added farend support setting up calls as mentioned above.
>
> aecm_core.*
> -----------
> Cleaned up some lint warnings.
> Added delay_estimator_farend pointer. Called Create(), Init() and Free() in above mentioned order.
> If AddFarSpectrumFix() was not successfully done, we end and return -1. This is what we would have done for Process().
>
> aec_core.*
> ----------
> Cleaned up some lint warnings.
> Added delay_estimator_farend pointer. Calls in proper order. Since we only use the delay estimator for logging there is no error handling. We only call Process() if AddFarSpectrum() was successful though.
>
> TEST=audioproc_unittest, trybots
> BUG=None
>
> Review URL: https://webrtc-codereview.appspot.com/1076006
TBR=bjornv@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/1062008
git-svn-id: http://webrtc.googlecode.com/svn/trunk@3429 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-01-29 21:30:26 +00:00
|
|
|
// - handle : Updated far-end instance.
|
2013-01-25 15:53:41 +00:00
|
|
|
//
|
2013-01-25 22:02:15 +00:00
|
|
|
void WebRtc_AddBinaryFarSpectrum(BinaryDelayEstimatorFarend* self,
|
2013-01-25 15:53:41 +00:00
|
|
|
uint32_t binary_far_spectrum);
|
|
|
|
|
|
2011-12-29 14:51:21 +00:00
|
|
|
// Releases the memory allocated by WebRtc_CreateBinaryDelayEstimator(...).
|
2013-01-25 15:53:41 +00:00
|
|
|
//
|
|
|
|
|
// Note that BinaryDelayEstimator utilizes BinaryDelayEstimatorFarend, but does
|
|
|
|
|
// not take ownership of it, hence the BinaryDelayEstimator has to be torn down
|
|
|
|
|
// before the far-end.
|
|
|
|
|
//
|
2011-09-15 12:27:36 +00:00
|
|
|
// Input:
|
2013-01-25 22:02:15 +00:00
|
|
|
// - self : Pointer to the binary delay estimation instance
|
2012-04-18 08:30:29 +00:00
|
|
|
// which is the return value of
|
|
|
|
|
// WebRtc_CreateBinaryDelayEstimator().
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2013-01-25 22:02:15 +00:00
|
|
|
void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* self);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2013-01-25 15:53:41 +00:00
|
|
|
// Allocates the memory needed by the binary delay estimation. The memory needs
|
|
|
|
|
// to be initialized separately through WebRtc_InitBinaryDelayEstimator(...).
|
|
|
|
|
//
|
|
|
|
|
// Inputs:
|
|
|
|
|
// - farend : Pointer to the far-end part of the Binary Delay
|
|
|
|
|
// Estimator. This memory has to be created separately
|
|
|
|
|
// prior to this call using
|
|
|
|
|
// WebRtc_CreateBinaryDelayEstimatorFarend().
|
|
|
|
|
//
|
|
|
|
|
// Note that BinaryDelayEstimator does not take
|
|
|
|
|
// ownership of |farend|.
|
|
|
|
|
//
|
|
|
|
|
// - lookahead : Amount of non-causal lookahead to use. This can
|
|
|
|
|
// detect cases in which a near-end signal occurs before
|
|
|
|
|
// the corresponding far-end signal. It will delay the
|
|
|
|
|
// estimate for the current block by an equal amount,
|
|
|
|
|
// and the returned values will be offset by it.
|
|
|
|
|
//
|
|
|
|
|
// A value of zero is the typical no-lookahead case.
|
|
|
|
|
// This also represents the minimum delay which can be
|
|
|
|
|
// estimated.
|
|
|
|
|
//
|
|
|
|
|
// Note that the effective range of delay estimates is
|
|
|
|
|
// [-|lookahead|,... ,|history_size|-|lookahead|)
|
|
|
|
|
// where |history_size| was set upon creating the far-end
|
|
|
|
|
// history buffer size.
|
|
|
|
|
//
|
|
|
|
|
// Return value:
|
|
|
|
|
// - BinaryDelayEstimator*
|
|
|
|
|
// : Created |handle|. If the memory can't be allocated
|
|
|
|
|
// or if any of the input parameters are invalid NULL
|
|
|
|
|
// is returned.
|
|
|
|
|
//
|
|
|
|
|
BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(
|
|
|
|
|
BinaryDelayEstimatorFarend* farend, int lookahead);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
|
|
|
|
// Initializes the delay estimation instance created with
|
2011-12-29 14:51:21 +00:00
|
|
|
// WebRtc_CreateBinaryDelayEstimator(...).
|
2013-01-25 15:53:41 +00:00
|
|
|
//
|
2011-09-15 12:27:36 +00:00
|
|
|
// Input:
|
2013-01-25 22:02:15 +00:00
|
|
|
// - self : Pointer to the delay estimation instance.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Output:
|
2013-01-25 22:02:15 +00:00
|
|
|
// - self : Initialized instance.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2013-01-25 22:02:15 +00:00
|
|
|
void WebRtc_InitBinaryDelayEstimator(BinaryDelayEstimator* self);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2013-01-18 23:16:46 +00:00
|
|
|
// 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).
|
2013-01-25 15:53:41 +00:00
|
|
|
//
|
2013-01-18 23:16:46 +00:00
|
|
|
// Inputs:
|
2013-01-25 22:02:15 +00:00
|
|
|
// - self : Pointer to the delay estimation instance.
|
2011-12-29 14:51:21 +00:00
|
|
|
// - binary_near_spectrum : Near-end binary spectrum of the current block.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Output:
|
2013-01-25 22:02:15 +00:00
|
|
|
// - self : Updated instance.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Return value:
|
2011-12-29 14:51:21 +00:00
|
|
|
// - delay : >= 0 - Calculated delay value.
|
2011-11-27 23:40:58 +00:00
|
|
|
// -2 - Insufficient data for estimation.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2013-01-25 22:02:15 +00:00
|
|
|
int WebRtc_ProcessBinarySpectrum(BinaryDelayEstimator* self,
|
2011-12-29 14:51:21 +00:00
|
|
|
uint32_t binary_near_spectrum);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
|
|
|
|
// Returns the last calculated delay updated by the function
|
2011-12-29 14:51:21 +00:00
|
|
|
// WebRtc_ProcessBinarySpectrum(...).
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
|
|
|
|
// Input:
|
2013-01-25 22:02:15 +00:00
|
|
|
// - self : 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
|
2011-11-27 23:40:58 +00:00
|
|
|
// -2 - Insufficient data for estimation.
|
2011-09-15 12:27:36 +00:00
|
|
|
//
|
2013-01-25 22:02:15 +00:00
|
|
|
int WebRtc_binary_last_delay(BinaryDelayEstimator* self);
|
2011-09-15 12:27:36 +00:00
|
|
|
|
2013-01-18 21:54:15 +00:00
|
|
|
// 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] in Q14. The higher the value, the better quality.
|
|
|
|
|
//
|
|
|
|
|
// Input:
|
2013-01-25 22:02:15 +00:00
|
|
|
// - self : Pointer to the delay estimation instance.
|
2013-01-18 21:54:15 +00:00
|
|
|
//
|
|
|
|
|
// Return value:
|
|
|
|
|
// - delay_quality : >= 0 - Estimation quality (in Q14) of last
|
|
|
|
|
// calculated delay value.
|
|
|
|
|
// -2 - Insufficient data for estimation.
|
|
|
|
|
//
|
2013-01-25 22:02:15 +00:00
|
|
|
int WebRtc_binary_last_delay_quality(BinaryDelayEstimator* self);
|
2013-01-18 21:54:15 +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_
|