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:
@ -1,9 +0,0 @@
|
||||
noinst_LTLIBRARIES = libaecm.la
|
||||
|
||||
libaecm_la_SOURCES = interface/echo_control_mobile.h \
|
||||
echo_control_mobile.c \
|
||||
aecm_core.c \
|
||||
aecm_core.h
|
||||
libaecm_la_CFLAGS = $(AM_CFLAGS) $(COMMON_CFLAGS) \
|
||||
-I$(top_srcdir)/src/common_audio/signal_processing_library/main/interface \
|
||||
-I$(top_srcdir)/src/modules/audio_processing/utility
|
@ -1,34 +0,0 @@
|
||||
# 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.
|
||||
|
||||
{
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'aecm',
|
||||
'type': '<(library)',
|
||||
'dependencies': [
|
||||
'<(webrtc_root)/common_audio/common_audio.gyp:spl',
|
||||
'apm_util'
|
||||
],
|
||||
'include_dirs': [
|
||||
'interface',
|
||||
],
|
||||
'direct_dependent_settings': {
|
||||
'include_dirs': [
|
||||
'interface',
|
||||
],
|
||||
},
|
||||
'sources': [
|
||||
'interface/echo_control_mobile.h',
|
||||
'echo_control_mobile.c',
|
||||
'aecm_core.c',
|
||||
'aecm_core.h',
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -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,217 +8,144 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
// Performs echo control (suppression) with fft routines in fixed-point
|
||||
// Performs echo control (suppression) with fft routines in fixed-point.
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AECM_MAIN_SOURCE_AECM_CORE_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_AECM_MAIN_SOURCE_AECM_CORE_H_
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AECM_AECM_CORE_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_AECM_AECM_CORE_H_
|
||||
|
||||
#define AECM_DYNAMIC_Q // turn on/off dynamic Q-domain
|
||||
//#define AECM_WITH_ABS_APPROX
|
||||
//#define AECM_SHORT // for 32 sample partition length (otherwise 64)
|
||||
|
||||
#include "typedefs.h"
|
||||
#include "signal_processing_library.h"
|
||||
|
||||
// Algorithm parameters
|
||||
|
||||
#define FRAME_LEN 80 // Total frame length, 10 ms
|
||||
#ifdef AECM_SHORT
|
||||
|
||||
#define PART_LEN 32 // Length of partition
|
||||
#define PART_LEN_SHIFT 6 // Length of (PART_LEN * 2) in base 2
|
||||
|
||||
#else
|
||||
|
||||
#define PART_LEN 64 // Length of partition
|
||||
#define PART_LEN_SHIFT 7 // Length of (PART_LEN * 2) in base 2
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
#include "webrtc/modules/audio_processing/aecm/aecm_defines.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
#ifdef _MSC_VER // visual c++
|
||||
#define ALIGN8_BEG __declspec(align(8))
|
||||
#define ALIGN8_END
|
||||
#else // gcc or icc
|
||||
#define ALIGN8_BEG
|
||||
#define ALIGN8_END __attribute__((aligned(8)))
|
||||
#endif
|
||||
|
||||
#define PART_LEN1 (PART_LEN + 1) // Unique fft coefficients
|
||||
#define PART_LEN2 (PART_LEN << 1) // Length of partition * 2
|
||||
#define PART_LEN4 (PART_LEN << 2) // Length of partition * 4
|
||||
#define FAR_BUF_LEN PART_LEN4 // Length of buffers
|
||||
#define MAX_DELAY 100
|
||||
|
||||
// Counter parameters
|
||||
#ifdef AECM_SHORT
|
||||
|
||||
#define CONV_LEN 1024 // Convergence length used at startup
|
||||
#else
|
||||
|
||||
#define CONV_LEN 512 // Convergence length used at startup
|
||||
#endif
|
||||
|
||||
#define CONV_LEN2 (CONV_LEN << 1) // Convergence length * 2 used at startup
|
||||
// Energy parameters
|
||||
#define MAX_BUF_LEN 64 // History length of energy signals
|
||||
|
||||
#define FAR_ENERGY_MIN 1025 // Lowest Far energy level: At least 2 in energy
|
||||
#define FAR_ENERGY_DIFF 929 // Allowed difference between max and min
|
||||
|
||||
#define ENERGY_DEV_OFFSET 0 // The energy error offset in Q8
|
||||
#define ENERGY_DEV_TOL 400 // The energy estimation tolerance in Q8
|
||||
#define FAR_ENERGY_VAD_REGION 230 // Far VAD tolerance region
|
||||
// Stepsize parameters
|
||||
#define MU_MIN 10 // Min stepsize 2^-MU_MIN (far end energy dependent)
|
||||
#define MU_MAX 1 // Max stepsize 2^-MU_MAX (far end energy dependent)
|
||||
#define MU_DIFF 9 // MU_MIN - MU_MAX
|
||||
// Channel parameters
|
||||
#define MIN_MSE_COUNT 20 // Min number of consecutive blocks with enough far end
|
||||
// energy to compare channel estimates
|
||||
#define MIN_MSE_DIFF 29 // The ratio between adapted and stored channel to
|
||||
// accept a new storage (0.8 in Q-MSE_RESOLUTION)
|
||||
#define MSE_RESOLUTION 5 // MSE parameter resolution
|
||||
#define RESOLUTION_CHANNEL16 12 // W16 Channel in Q-RESOLUTION_CHANNEL16
|
||||
#define RESOLUTION_CHANNEL32 28 // W32 Channel in Q-RESOLUTION_CHANNEL
|
||||
#define CHANNEL_VAD 16 // Minimum energy in frequency band to update channel
|
||||
// Suppression gain parameters: SUPGAIN_ parameters in Q-(RESOLUTION_SUPGAIN)
|
||||
#define RESOLUTION_SUPGAIN 8 // Channel in Q-(RESOLUTION_SUPGAIN)
|
||||
#define SUPGAIN_DEFAULT (1 << RESOLUTION_SUPGAIN) // Default suppression gain
|
||||
#define SUPGAIN_ERROR_PARAM_A 3072 // Estimation error parameter (Maximum gain) (8 in Q8)
|
||||
#define SUPGAIN_ERROR_PARAM_B 1536 // Estimation error parameter (Gain before going down)
|
||||
#define SUPGAIN_ERROR_PARAM_D SUPGAIN_DEFAULT // Estimation error parameter
|
||||
// (Should be the same as Default) (1 in Q8)
|
||||
#define SUPGAIN_EPC_DT 200 // = SUPGAIN_ERROR_PARAM_C * ENERGY_DEV_TOL
|
||||
// Defines for "check delay estimation"
|
||||
#define CORR_WIDTH 31 // Number of samples to correlate over.
|
||||
#define CORR_MAX 16 // Maximum correlation offset
|
||||
#define CORR_MAX_BUF 63
|
||||
#define CORR_DEV 4
|
||||
#define CORR_MAX_LEVEL 20
|
||||
#define CORR_MAX_LOW 4
|
||||
#define CORR_BUF_LEN (CORR_MAX << 1) + 1
|
||||
// Note that CORR_WIDTH + 2*CORR_MAX <= MAX_BUF_LEN
|
||||
|
||||
#define ONE_Q14 (1 << 14)
|
||||
|
||||
// NLP defines
|
||||
#define NLP_COMP_LOW 3277 // 0.2 in Q14
|
||||
#define NLP_COMP_HIGH ONE_Q14 // 1 in Q14
|
||||
|
||||
extern const WebRtc_Word16 WebRtcAecm_kSqrtHanning[];
|
||||
|
||||
typedef struct {
|
||||
WebRtc_Word16 real;
|
||||
WebRtc_Word16 imag;
|
||||
} complex16_t;
|
||||
int16_t real;
|
||||
int16_t imag;
|
||||
} ComplexInt16;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
int farBufWritePos;
|
||||
int farBufReadPos;
|
||||
int knownDelay;
|
||||
int lastKnownDelay;
|
||||
int firstVAD; // Parameter to control poorly initialized channels
|
||||
int firstVAD; // Parameter to control poorly initialized channels
|
||||
|
||||
void *farFrameBuf;
|
||||
void *nearNoisyFrameBuf;
|
||||
void *nearCleanFrameBuf;
|
||||
void *outFrameBuf;
|
||||
RingBuffer* farFrameBuf;
|
||||
RingBuffer* nearNoisyFrameBuf;
|
||||
RingBuffer* nearCleanFrameBuf;
|
||||
RingBuffer* outFrameBuf;
|
||||
|
||||
WebRtc_Word16 farBuf[FAR_BUF_LEN];
|
||||
int16_t farBuf[FAR_BUF_LEN];
|
||||
|
||||
WebRtc_Word16 mult;
|
||||
WebRtc_UWord32 seed;
|
||||
int16_t mult;
|
||||
uint32_t seed;
|
||||
|
||||
// Delay estimation variables
|
||||
void* delay_estimator_farend;
|
||||
void* delay_estimator;
|
||||
WebRtc_UWord16 currentDelay;
|
||||
uint16_t currentDelay;
|
||||
// Far end history variables
|
||||
// TODO(bjornv): Replace |far_history| with ring_buffer.
|
||||
uint16_t far_history[PART_LEN1 * MAX_DELAY];
|
||||
int far_history_pos;
|
||||
int far_q_domains[MAX_DELAY];
|
||||
|
||||
WebRtc_Word16 nlpFlag;
|
||||
WebRtc_Word16 fixedDelay;
|
||||
int16_t nlpFlag;
|
||||
int16_t fixedDelay;
|
||||
|
||||
WebRtc_UWord32 totCount;
|
||||
uint32_t totCount;
|
||||
|
||||
WebRtc_Word16 dfaCleanQDomain;
|
||||
WebRtc_Word16 dfaCleanQDomainOld;
|
||||
WebRtc_Word16 dfaNoisyQDomain;
|
||||
WebRtc_Word16 dfaNoisyQDomainOld;
|
||||
int16_t dfaCleanQDomain;
|
||||
int16_t dfaCleanQDomainOld;
|
||||
int16_t dfaNoisyQDomain;
|
||||
int16_t dfaNoisyQDomainOld;
|
||||
|
||||
WebRtc_Word16 nearLogEnergy[MAX_BUF_LEN];
|
||||
WebRtc_Word16 farLogEnergy;
|
||||
WebRtc_Word16 echoAdaptLogEnergy[MAX_BUF_LEN];
|
||||
WebRtc_Word16 echoStoredLogEnergy[MAX_BUF_LEN];
|
||||
int16_t nearLogEnergy[MAX_BUF_LEN];
|
||||
int16_t farLogEnergy;
|
||||
int16_t echoAdaptLogEnergy[MAX_BUF_LEN];
|
||||
int16_t echoStoredLogEnergy[MAX_BUF_LEN];
|
||||
|
||||
// The extra 16 or 32 bytes in the following buffers are for alignment based Neon code.
|
||||
// It's designed this way since the current GCC compiler can't align a buffer in 16 or 32
|
||||
// byte boundaries properly.
|
||||
WebRtc_Word16 channelStored_buf[PART_LEN1 + 8];
|
||||
WebRtc_Word16 channelAdapt16_buf[PART_LEN1 + 8];
|
||||
WebRtc_Word32 channelAdapt32_buf[PART_LEN1 + 8];
|
||||
WebRtc_Word16 xBuf_buf[PART_LEN2 + 16]; // farend
|
||||
WebRtc_Word16 dBufClean_buf[PART_LEN2 + 16]; // nearend
|
||||
WebRtc_Word16 dBufNoisy_buf[PART_LEN2 + 16]; // nearend
|
||||
WebRtc_Word16 outBuf_buf[PART_LEN + 8];
|
||||
// The extra 16 or 32 bytes in the following buffers are for alignment based
|
||||
// Neon code.
|
||||
// It's designed this way since the current GCC compiler can't align a
|
||||
// buffer in 16 or 32 byte boundaries properly.
|
||||
int16_t channelStored_buf[PART_LEN1 + 8];
|
||||
int16_t channelAdapt16_buf[PART_LEN1 + 8];
|
||||
int32_t channelAdapt32_buf[PART_LEN1 + 8];
|
||||
int16_t xBuf_buf[PART_LEN2 + 16]; // farend
|
||||
int16_t dBufClean_buf[PART_LEN2 + 16]; // nearend
|
||||
int16_t dBufNoisy_buf[PART_LEN2 + 16]; // nearend
|
||||
int16_t outBuf_buf[PART_LEN + 8];
|
||||
|
||||
// Pointers to the above buffers
|
||||
WebRtc_Word16 *channelStored;
|
||||
WebRtc_Word16 *channelAdapt16;
|
||||
WebRtc_Word32 *channelAdapt32;
|
||||
WebRtc_Word16 *xBuf;
|
||||
WebRtc_Word16 *dBufClean;
|
||||
WebRtc_Word16 *dBufNoisy;
|
||||
WebRtc_Word16 *outBuf;
|
||||
int16_t *channelStored;
|
||||
int16_t *channelAdapt16;
|
||||
int32_t *channelAdapt32;
|
||||
int16_t *xBuf;
|
||||
int16_t *dBufClean;
|
||||
int16_t *dBufNoisy;
|
||||
int16_t *outBuf;
|
||||
|
||||
WebRtc_Word32 echoFilt[PART_LEN1];
|
||||
WebRtc_Word16 nearFilt[PART_LEN1];
|
||||
WebRtc_Word32 noiseEst[PART_LEN1];
|
||||
int32_t echoFilt[PART_LEN1];
|
||||
int16_t nearFilt[PART_LEN1];
|
||||
int32_t noiseEst[PART_LEN1];
|
||||
int noiseEstTooLowCtr[PART_LEN1];
|
||||
int noiseEstTooHighCtr[PART_LEN1];
|
||||
WebRtc_Word16 noiseEstCtr;
|
||||
WebRtc_Word16 cngMode;
|
||||
int16_t noiseEstCtr;
|
||||
int16_t cngMode;
|
||||
|
||||
WebRtc_Word32 mseAdaptOld;
|
||||
WebRtc_Word32 mseStoredOld;
|
||||
WebRtc_Word32 mseThreshold;
|
||||
int32_t mseAdaptOld;
|
||||
int32_t mseStoredOld;
|
||||
int32_t mseThreshold;
|
||||
|
||||
WebRtc_Word16 farEnergyMin;
|
||||
WebRtc_Word16 farEnergyMax;
|
||||
WebRtc_Word16 farEnergyMaxMin;
|
||||
WebRtc_Word16 farEnergyVAD;
|
||||
WebRtc_Word16 farEnergyMSE;
|
||||
int16_t farEnergyMin;
|
||||
int16_t farEnergyMax;
|
||||
int16_t farEnergyMaxMin;
|
||||
int16_t farEnergyVAD;
|
||||
int16_t farEnergyMSE;
|
||||
int currentVADValue;
|
||||
WebRtc_Word16 vadUpdateCount;
|
||||
int16_t vadUpdateCount;
|
||||
|
||||
WebRtc_Word16 startupState;
|
||||
WebRtc_Word16 mseChannelCount;
|
||||
WebRtc_Word16 supGain;
|
||||
WebRtc_Word16 supGainOld;
|
||||
int16_t startupState;
|
||||
int16_t mseChannelCount;
|
||||
int16_t supGain;
|
||||
int16_t supGainOld;
|
||||
|
||||
WebRtc_Word16 supGainErrParamA;
|
||||
WebRtc_Word16 supGainErrParamD;
|
||||
WebRtc_Word16 supGainErrParamDiffAB;
|
||||
WebRtc_Word16 supGainErrParamDiffBD;
|
||||
int16_t supGainErrParamA;
|
||||
int16_t supGainErrParamD;
|
||||
int16_t supGainErrParamDiffAB;
|
||||
int16_t supGainErrParamDiffBD;
|
||||
|
||||
struct RealFFT* real_fft;
|
||||
|
||||
#ifdef AEC_DEBUG
|
||||
FILE *farFile;
|
||||
FILE *nearFile;
|
||||
FILE *outFile;
|
||||
#endif
|
||||
} AecmCore_t;
|
||||
} AecmCore;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_CreateCore(...)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_CreateCore()
|
||||
//
|
||||
// Allocates the memory needed by the AECM. The memory needs to be
|
||||
// initialized separately using the WebRtcAecm_InitCore() function.
|
||||
//
|
||||
// Input:
|
||||
// - aecm : Instance that should be created
|
||||
//
|
||||
// Output:
|
||||
// - aecm : Created instance
|
||||
//
|
||||
// Return value : 0 - Ok
|
||||
// -1 - Error
|
||||
//
|
||||
int WebRtcAecm_CreateCore(AecmCore_t **aecm);
|
||||
// Returns a pointer to the instance and a nullptr at failure.
|
||||
AecmCore* WebRtcAecm_CreateCore();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_InitCore(...)
|
||||
//
|
||||
// This function initializes the AECM instant created with WebRtcAecm_CreateCore(...)
|
||||
// This function initializes the AECM instant created with
|
||||
// WebRtcAecm_CreateCore()
|
||||
// Input:
|
||||
// - aecm : Pointer to the AECM instance
|
||||
// - samplingFreq : Sampling Frequency
|
||||
@ -229,57 +156,58 @@ int WebRtcAecm_CreateCore(AecmCore_t **aecm);
|
||||
// Return value : 0 - Ok
|
||||
// -1 - Error
|
||||
//
|
||||
int WebRtcAecm_InitCore(AecmCore_t * const aecm, int samplingFreq);
|
||||
int WebRtcAecm_InitCore(AecmCore* const aecm, int samplingFreq);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_FreeCore(...)
|
||||
//
|
||||
// This function releases the memory allocated by WebRtcAecm_CreateCore()
|
||||
// Input:
|
||||
// - aecm : Pointer to the AECM instance
|
||||
//
|
||||
// Return value : 0 - Ok
|
||||
// -1 - Error
|
||||
// 11001-11016: Error
|
||||
//
|
||||
int WebRtcAecm_FreeCore(AecmCore_t *aecm);
|
||||
void WebRtcAecm_FreeCore(AecmCore* aecm);
|
||||
|
||||
int WebRtcAecm_Control(AecmCore_t *aecm, int delay, int nlpFlag);
|
||||
int WebRtcAecm_Control(AecmCore* aecm, int delay, int nlpFlag);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_InitEchoPathCore(...)
|
||||
//
|
||||
// This function resets the echo channel adaptation with the specified channel.
|
||||
// Input:
|
||||
// - aecm : Pointer to the AECM instance
|
||||
// - echo_path : Pointer to the data that should initialize the echo path
|
||||
// - echo_path : Pointer to the data that should initialize the echo
|
||||
// path
|
||||
//
|
||||
// Output:
|
||||
// - aecm : Initialized instance
|
||||
//
|
||||
void WebRtcAecm_InitEchoPathCore(AecmCore_t* aecm, const WebRtc_Word16* echo_path);
|
||||
void WebRtcAecm_InitEchoPathCore(AecmCore* aecm, const int16_t* echo_path);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_ProcessFrame(...)
|
||||
//
|
||||
// This function processes frames and sends blocks to WebRtcAecm_ProcessBlock(...)
|
||||
// This function processes frames and sends blocks to
|
||||
// WebRtcAecm_ProcessBlock(...)
|
||||
//
|
||||
// Inputs:
|
||||
// - aecm : Pointer to the AECM instance
|
||||
// - farend : In buffer containing one frame of echo signal
|
||||
// - nearendNoisy : In buffer containing one frame of nearend+echo signal without NS
|
||||
// - nearendClean : In buffer containing one frame of nearend+echo signal with NS
|
||||
// - nearendNoisy : In buffer containing one frame of nearend+echo signal
|
||||
// without NS
|
||||
// - nearendClean : In buffer containing one frame of nearend+echo signal
|
||||
// with NS
|
||||
//
|
||||
// Output:
|
||||
// - out : Out buffer, one frame of nearend signal :
|
||||
//
|
||||
//
|
||||
int WebRtcAecm_ProcessFrame(AecmCore_t * aecm, const WebRtc_Word16 * farend,
|
||||
const WebRtc_Word16 * nearendNoisy,
|
||||
const WebRtc_Word16 * nearendClean,
|
||||
WebRtc_Word16 * out);
|
||||
int WebRtcAecm_ProcessFrame(AecmCore* aecm,
|
||||
const int16_t* farend,
|
||||
const int16_t* nearendNoisy,
|
||||
const int16_t* nearendClean,
|
||||
int16_t* out);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_ProcessBlock(...)
|
||||
//
|
||||
// This function is called for every block within one frame
|
||||
@ -288,19 +216,22 @@ int WebRtcAecm_ProcessFrame(AecmCore_t * aecm, const WebRtc_Word16 * farend,
|
||||
// Inputs:
|
||||
// - aecm : Pointer to the AECM instance
|
||||
// - farend : In buffer containing one block of echo signal
|
||||
// - nearendNoisy : In buffer containing one frame of nearend+echo signal without NS
|
||||
// - nearendClean : In buffer containing one frame of nearend+echo signal with NS
|
||||
// - nearendNoisy : In buffer containing one frame of nearend+echo signal
|
||||
// without NS
|
||||
// - nearendClean : In buffer containing one frame of nearend+echo signal
|
||||
// with NS
|
||||
//
|
||||
// Output:
|
||||
// - out : Out buffer, one block of nearend signal :
|
||||
//
|
||||
//
|
||||
int WebRtcAecm_ProcessBlock(AecmCore_t * aecm, const WebRtc_Word16 * farend,
|
||||
const WebRtc_Word16 * nearendNoisy,
|
||||
const WebRtc_Word16 * noisyClean,
|
||||
WebRtc_Word16 * out);
|
||||
int WebRtcAecm_ProcessBlock(AecmCore* aecm,
|
||||
const int16_t* farend,
|
||||
const int16_t* nearendNoisy,
|
||||
const int16_t* noisyClean,
|
||||
int16_t* out);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_BufferFarFrame()
|
||||
//
|
||||
// Inserts a frame of data into farend buffer.
|
||||
@ -310,10 +241,11 @@ int WebRtcAecm_ProcessBlock(AecmCore_t * aecm, const WebRtc_Word16 * farend,
|
||||
// - farend : In buffer containing one frame of farend signal
|
||||
// - farLen : Length of frame
|
||||
//
|
||||
void WebRtcAecm_BufferFarFrame(AecmCore_t * const aecm, const WebRtc_Word16 * const farend,
|
||||
void WebRtcAecm_BufferFarFrame(AecmCore* const aecm,
|
||||
const int16_t* const farend,
|
||||
const int farLen);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_FetchFarFrame()
|
||||
//
|
||||
// Read the farend buffer to account for known delay
|
||||
@ -324,35 +256,179 @@ void WebRtcAecm_BufferFarFrame(AecmCore_t * const aecm, const WebRtc_Word16 * co
|
||||
// - farLen : Length of frame
|
||||
// - knownDelay : known delay
|
||||
//
|
||||
void WebRtcAecm_FetchFarFrame(AecmCore_t * const aecm, WebRtc_Word16 * const farend,
|
||||
const int farLen, const int knownDelay);
|
||||
void WebRtcAecm_FetchFarFrame(AecmCore* const aecm,
|
||||
int16_t* const farend,
|
||||
const int farLen,
|
||||
const int knownDelay);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Some internal functions shared by ARM NEON and generic C code:
|
||||
// All the functions below are intended to be private
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_UpdateFarHistory()
|
||||
//
|
||||
// Moves the pointer to the next entry and inserts |far_spectrum| and
|
||||
// corresponding Q-domain in its buffer.
|
||||
//
|
||||
// Inputs:
|
||||
// - self : Pointer to the delay estimation instance
|
||||
// - far_spectrum : Pointer to the far end spectrum
|
||||
// - far_q : Q-domain of far end spectrum
|
||||
//
|
||||
void WebRtcAecm_UpdateFarHistory(AecmCore* self,
|
||||
uint16_t* far_spectrum,
|
||||
int far_q);
|
||||
|
||||
void WebRtcAecm_CalcLinearEnergies(AecmCore_t* aecm,
|
||||
const WebRtc_UWord16* far_spectrum,
|
||||
WebRtc_Word32* echoEst,
|
||||
WebRtc_UWord32* far_energy,
|
||||
WebRtc_UWord32* echo_energy_adapt,
|
||||
WebRtc_UWord32* echo_energy_stored);
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_AlignedFarend()
|
||||
//
|
||||
// Returns a pointer to the far end spectrum aligned to current near end
|
||||
// spectrum. The function WebRtc_DelayEstimatorProcessFix(...) should have been
|
||||
// called before AlignedFarend(...). Otherwise, you get the pointer to the
|
||||
// previous frame. The memory is only valid until the next call of
|
||||
// WebRtc_DelayEstimatorProcessFix(...).
|
||||
//
|
||||
// Inputs:
|
||||
// - self : Pointer to the AECM instance.
|
||||
// - delay : Current delay estimate.
|
||||
//
|
||||
// Output:
|
||||
// - far_q : The Q-domain of the aligned far end spectrum
|
||||
//
|
||||
// Return value:
|
||||
// - far_spectrum : Pointer to the aligned far end spectrum
|
||||
// NULL - Error
|
||||
//
|
||||
const uint16_t* WebRtcAecm_AlignedFarend(AecmCore* self, int* far_q, int delay);
|
||||
|
||||
void WebRtcAecm_StoreAdaptiveChannel(AecmCore_t* aecm,
|
||||
const WebRtc_UWord16* far_spectrum,
|
||||
WebRtc_Word32* echo_est);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_CalcSuppressionGain()
|
||||
//
|
||||
// This function calculates the suppression gain that is used in the
|
||||
// Wiener filter.
|
||||
//
|
||||
// Inputs:
|
||||
// - aecm : Pointer to the AECM instance.
|
||||
//
|
||||
// Return value:
|
||||
// - supGain : Suppression gain with which to scale the noise
|
||||
// level (Q14).
|
||||
//
|
||||
int16_t WebRtcAecm_CalcSuppressionGain(AecmCore* const aecm);
|
||||
|
||||
void WebRtcAecm_ResetAdaptiveChannel(AecmCore_t *aecm);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_CalcEnergies()
|
||||
//
|
||||
// This function calculates the log of energies for nearend, farend and
|
||||
// estimated echoes. There is also an update of energy decision levels,
|
||||
// i.e. internal VAD.
|
||||
//
|
||||
// Inputs:
|
||||
// - aecm : Pointer to the AECM instance.
|
||||
// - far_spectrum : Pointer to farend spectrum.
|
||||
// - far_q : Q-domain of farend spectrum.
|
||||
// - nearEner : Near end energy for current block in
|
||||
// Q(aecm->dfaQDomain).
|
||||
//
|
||||
// Output:
|
||||
// - echoEst : Estimated echo in Q(xfa_q+RESOLUTION_CHANNEL16).
|
||||
//
|
||||
void WebRtcAecm_CalcEnergies(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
const int16_t far_q,
|
||||
const uint32_t nearEner,
|
||||
int32_t* echoEst);
|
||||
|
||||
void WebRtcAecm_WindowAndFFT(WebRtc_Word16* fft,
|
||||
const WebRtc_Word16* time_signal,
|
||||
complex16_t* freq_signal,
|
||||
int time_signal_scaling);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_CalcStepSize()
|
||||
//
|
||||
// This function calculates the step size used in channel estimation
|
||||
//
|
||||
// Inputs:
|
||||
// - aecm : Pointer to the AECM instance.
|
||||
//
|
||||
// Return value:
|
||||
// - mu : Stepsize in log2(), i.e. number of shifts.
|
||||
//
|
||||
int16_t WebRtcAecm_CalcStepSize(AecmCore* const aecm);
|
||||
|
||||
void WebRtcAecm_InverseFFTAndWindow(AecmCore_t* aecm,
|
||||
WebRtc_Word16* fft,
|
||||
complex16_t* efw,
|
||||
WebRtc_Word16* output,
|
||||
const WebRtc_Word16* nearendClean);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// WebRtcAecm_UpdateChannel(...)
|
||||
//
|
||||
// This function performs channel estimation.
|
||||
// NLMS and decision on channel storage.
|
||||
//
|
||||
// Inputs:
|
||||
// - aecm : Pointer to the AECM instance.
|
||||
// - far_spectrum : Absolute value of the farend signal in Q(far_q)
|
||||
// - far_q : Q-domain of the farend signal
|
||||
// - dfa : Absolute value of the nearend signal
|
||||
// (Q[aecm->dfaQDomain])
|
||||
// - mu : NLMS step size.
|
||||
// Input/Output:
|
||||
// - echoEst : Estimated echo in Q(far_q+RESOLUTION_CHANNEL16).
|
||||
//
|
||||
void WebRtcAecm_UpdateChannel(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
const int16_t far_q,
|
||||
const uint16_t* const dfa,
|
||||
const int16_t mu,
|
||||
int32_t* echoEst);
|
||||
|
||||
extern const int16_t WebRtcAecm_kCosTable[];
|
||||
extern const int16_t WebRtcAecm_kSinTable[];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Some function pointers, for internal functions shared by ARM NEON and
|
||||
// generic C code.
|
||||
//
|
||||
typedef void (*CalcLinearEnergies)(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
int32_t* echoEst,
|
||||
uint32_t* far_energy,
|
||||
uint32_t* echo_energy_adapt,
|
||||
uint32_t* echo_energy_stored);
|
||||
extern CalcLinearEnergies WebRtcAecm_CalcLinearEnergies;
|
||||
|
||||
typedef void (*StoreAdaptiveChannel)(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
int32_t* echo_est);
|
||||
extern StoreAdaptiveChannel WebRtcAecm_StoreAdaptiveChannel;
|
||||
|
||||
typedef void (*ResetAdaptiveChannel)(AecmCore* aecm);
|
||||
extern ResetAdaptiveChannel WebRtcAecm_ResetAdaptiveChannel;
|
||||
|
||||
// For the above function pointers, functions for generic platforms are declared
|
||||
// and defined as static in file aecm_core.c, while those for ARM Neon platforms
|
||||
// are declared below and defined in file aecm_core_neon.c.
|
||||
#if defined(WEBRTC_DETECT_NEON) || defined(WEBRTC_HAS_NEON)
|
||||
void WebRtcAecm_CalcLinearEnergiesNeon(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
int32_t* echo_est,
|
||||
uint32_t* far_energy,
|
||||
uint32_t* echo_energy_adapt,
|
||||
uint32_t* echo_energy_stored);
|
||||
|
||||
void WebRtcAecm_StoreAdaptiveChannelNeon(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
int32_t* echo_est);
|
||||
|
||||
void WebRtcAecm_ResetAdaptiveChannelNeon(AecmCore* aecm);
|
||||
#endif
|
||||
|
||||
#if defined(MIPS32_LE)
|
||||
void WebRtcAecm_CalcLinearEnergies_mips(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
int32_t* echo_est,
|
||||
uint32_t* far_energy,
|
||||
uint32_t* echo_energy_adapt,
|
||||
uint32_t* echo_energy_stored);
|
||||
#if defined(MIPS_DSP_R1_LE)
|
||||
void WebRtcAecm_StoreAdaptiveChannel_mips(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
int32_t* echo_est);
|
||||
|
||||
void WebRtcAecm_ResetAdaptiveChannel_mips(AecmCore* aecm);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
771
webrtc/modules/audio_processing/aecm/aecm_core_c.c
Normal file
771
webrtc/modules/audio_processing/aecm/aecm_core_c.c
Normal file
@ -0,0 +1,771 @@
|
||||
/*
|
||||
* Copyright (c) 2013 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.
|
||||
*/
|
||||
|
||||
#include "webrtc/modules/audio_processing/aecm/aecm_core.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/real_fft.h"
|
||||
#include "webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h"
|
||||
#include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
|
||||
#include "webrtc/system_wrappers/interface/compile_assert_c.h"
|
||||
#include "webrtc/system_wrappers/interface/cpu_features_wrapper.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
// Square root of Hanning window in Q14.
|
||||
#if defined(WEBRTC_DETECT_NEON) || defined(WEBRTC_HAS_NEON)
|
||||
// Table is defined in an ARM assembly file.
|
||||
extern const ALIGN8_BEG int16_t WebRtcAecm_kSqrtHanning[] ALIGN8_END;
|
||||
#else
|
||||
static const ALIGN8_BEG int16_t WebRtcAecm_kSqrtHanning[] ALIGN8_END = {
|
||||
0, 399, 798, 1196, 1594, 1990, 2386, 2780, 3172,
|
||||
3562, 3951, 4337, 4720, 5101, 5478, 5853, 6224,
|
||||
6591, 6954, 7313, 7668, 8019, 8364, 8705, 9040,
|
||||
9370, 9695, 10013, 10326, 10633, 10933, 11227, 11514,
|
||||
11795, 12068, 12335, 12594, 12845, 13089, 13325, 13553,
|
||||
13773, 13985, 14189, 14384, 14571, 14749, 14918, 15079,
|
||||
15231, 15373, 15506, 15631, 15746, 15851, 15947, 16034,
|
||||
16111, 16179, 16237, 16286, 16325, 16354, 16373, 16384
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef AECM_WITH_ABS_APPROX
|
||||
//Q15 alpha = 0.99439986968132 const Factor for magnitude approximation
|
||||
static const uint16_t kAlpha1 = 32584;
|
||||
//Q15 beta = 0.12967166976970 const Factor for magnitude approximation
|
||||
static const uint16_t kBeta1 = 4249;
|
||||
//Q15 alpha = 0.94234827210087 const Factor for magnitude approximation
|
||||
static const uint16_t kAlpha2 = 30879;
|
||||
//Q15 beta = 0.33787806009150 const Factor for magnitude approximation
|
||||
static const uint16_t kBeta2 = 11072;
|
||||
//Q15 alpha = 0.82247698684306 const Factor for magnitude approximation
|
||||
static const uint16_t kAlpha3 = 26951;
|
||||
//Q15 beta = 0.57762063060713 const Factor for magnitude approximation
|
||||
static const uint16_t kBeta3 = 18927;
|
||||
#endif
|
||||
|
||||
static const int16_t kNoiseEstQDomain = 15;
|
||||
static const int16_t kNoiseEstIncCount = 5;
|
||||
|
||||
static void ComfortNoise(AecmCore* aecm,
|
||||
const uint16_t* dfa,
|
||||
ComplexInt16* out,
|
||||
const int16_t* lambda);
|
||||
|
||||
static void WindowAndFFT(AecmCore* aecm,
|
||||
int16_t* fft,
|
||||
const int16_t* time_signal,
|
||||
ComplexInt16* freq_signal,
|
||||
int time_signal_scaling) {
|
||||
int i = 0;
|
||||
|
||||
// FFT of signal
|
||||
for (i = 0; i < PART_LEN; i++) {
|
||||
// Window time domain signal and insert into real part of
|
||||
// transformation array |fft|
|
||||
int16_t scaled_time_signal = time_signal[i] << time_signal_scaling;
|
||||
fft[i] = (int16_t)((scaled_time_signal * WebRtcAecm_kSqrtHanning[i]) >> 14);
|
||||
scaled_time_signal = time_signal[i + PART_LEN] << time_signal_scaling;
|
||||
fft[PART_LEN + i] = (int16_t)((
|
||||
scaled_time_signal * WebRtcAecm_kSqrtHanning[PART_LEN - i]) >> 14);
|
||||
}
|
||||
|
||||
// Do forward FFT, then take only the first PART_LEN complex samples,
|
||||
// and change signs of the imaginary parts.
|
||||
WebRtcSpl_RealForwardFFT(aecm->real_fft, fft, (int16_t*)freq_signal);
|
||||
for (i = 0; i < PART_LEN; i++) {
|
||||
freq_signal[i].imag = -freq_signal[i].imag;
|
||||
}
|
||||
}
|
||||
|
||||
static void InverseFFTAndWindow(AecmCore* aecm,
|
||||
int16_t* fft,
|
||||
ComplexInt16* efw,
|
||||
int16_t* output,
|
||||
const int16_t* nearendClean) {
|
||||
int i, j, outCFFT;
|
||||
int32_t tmp32no1;
|
||||
// Reuse |efw| for the inverse FFT output after transferring
|
||||
// the contents to |fft|.
|
||||
int16_t* ifft_out = (int16_t*)efw;
|
||||
|
||||
// Synthesis
|
||||
for (i = 1, j = 2; i < PART_LEN; i += 1, j += 2) {
|
||||
fft[j] = efw[i].real;
|
||||
fft[j + 1] = -efw[i].imag;
|
||||
}
|
||||
fft[0] = efw[0].real;
|
||||
fft[1] = -efw[0].imag;
|
||||
|
||||
fft[PART_LEN2] = efw[PART_LEN].real;
|
||||
fft[PART_LEN2 + 1] = -efw[PART_LEN].imag;
|
||||
|
||||
// Inverse FFT. Keep outCFFT to scale the samples in the next block.
|
||||
outCFFT = WebRtcSpl_RealInverseFFT(aecm->real_fft, fft, ifft_out);
|
||||
for (i = 0; i < PART_LEN; i++) {
|
||||
ifft_out[i] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(
|
||||
ifft_out[i], WebRtcAecm_kSqrtHanning[i], 14);
|
||||
tmp32no1 = WEBRTC_SPL_SHIFT_W32((int32_t)ifft_out[i],
|
||||
outCFFT - aecm->dfaCleanQDomain);
|
||||
output[i] = (int16_t)WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX,
|
||||
tmp32no1 + aecm->outBuf[i],
|
||||
WEBRTC_SPL_WORD16_MIN);
|
||||
|
||||
tmp32no1 = (ifft_out[PART_LEN + i] *
|
||||
WebRtcAecm_kSqrtHanning[PART_LEN - i]) >> 14;
|
||||
tmp32no1 = WEBRTC_SPL_SHIFT_W32(tmp32no1,
|
||||
outCFFT - aecm->dfaCleanQDomain);
|
||||
aecm->outBuf[i] = (int16_t)WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX,
|
||||
tmp32no1,
|
||||
WEBRTC_SPL_WORD16_MIN);
|
||||
}
|
||||
|
||||
// Copy the current block to the old position
|
||||
// (aecm->outBuf is shifted elsewhere)
|
||||
memcpy(aecm->xBuf, aecm->xBuf + PART_LEN, sizeof(int16_t) * PART_LEN);
|
||||
memcpy(aecm->dBufNoisy,
|
||||
aecm->dBufNoisy + PART_LEN,
|
||||
sizeof(int16_t) * PART_LEN);
|
||||
if (nearendClean != NULL)
|
||||
{
|
||||
memcpy(aecm->dBufClean,
|
||||
aecm->dBufClean + PART_LEN,
|
||||
sizeof(int16_t) * PART_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
// Transforms a time domain signal into the frequency domain, outputting the
|
||||
// complex valued signal, absolute value and sum of absolute values.
|
||||
//
|
||||
// time_signal [in] Pointer to time domain signal
|
||||
// freq_signal_real [out] Pointer to real part of frequency domain array
|
||||
// freq_signal_imag [out] Pointer to imaginary part of frequency domain
|
||||
// array
|
||||
// freq_signal_abs [out] Pointer to absolute value of frequency domain
|
||||
// array
|
||||
// freq_signal_sum_abs [out] Pointer to the sum of all absolute values in
|
||||
// the frequency domain array
|
||||
// return value The Q-domain of current frequency values
|
||||
//
|
||||
static int TimeToFrequencyDomain(AecmCore* aecm,
|
||||
const int16_t* time_signal,
|
||||
ComplexInt16* freq_signal,
|
||||
uint16_t* freq_signal_abs,
|
||||
uint32_t* freq_signal_sum_abs) {
|
||||
int i = 0;
|
||||
int time_signal_scaling = 0;
|
||||
|
||||
int32_t tmp32no1 = 0;
|
||||
int32_t tmp32no2 = 0;
|
||||
|
||||
// In fft_buf, +16 for 32-byte alignment.
|
||||
int16_t fft_buf[PART_LEN4 + 16];
|
||||
int16_t *fft = (int16_t *) (((uintptr_t) fft_buf + 31) & ~31);
|
||||
|
||||
int16_t tmp16no1;
|
||||
#ifndef WEBRTC_ARCH_ARM_V7
|
||||
int16_t tmp16no2;
|
||||
#endif
|
||||
#ifdef AECM_WITH_ABS_APPROX
|
||||
int16_t max_value = 0;
|
||||
int16_t min_value = 0;
|
||||
uint16_t alpha = 0;
|
||||
uint16_t beta = 0;
|
||||
#endif
|
||||
|
||||
#ifdef AECM_DYNAMIC_Q
|
||||
tmp16no1 = WebRtcSpl_MaxAbsValueW16(time_signal, PART_LEN2);
|
||||
time_signal_scaling = WebRtcSpl_NormW16(tmp16no1);
|
||||
#endif
|
||||
|
||||
WindowAndFFT(aecm, fft, time_signal, freq_signal, time_signal_scaling);
|
||||
|
||||
// Extract imaginary and real part, calculate the magnitude for
|
||||
// all frequency bins
|
||||
freq_signal[0].imag = 0;
|
||||
freq_signal[PART_LEN].imag = 0;
|
||||
freq_signal_abs[0] = (uint16_t)WEBRTC_SPL_ABS_W16(freq_signal[0].real);
|
||||
freq_signal_abs[PART_LEN] = (uint16_t)WEBRTC_SPL_ABS_W16(
|
||||
freq_signal[PART_LEN].real);
|
||||
(*freq_signal_sum_abs) = (uint32_t)(freq_signal_abs[0]) +
|
||||
(uint32_t)(freq_signal_abs[PART_LEN]);
|
||||
|
||||
for (i = 1; i < PART_LEN; i++)
|
||||
{
|
||||
if (freq_signal[i].real == 0)
|
||||
{
|
||||
freq_signal_abs[i] = (uint16_t)WEBRTC_SPL_ABS_W16(freq_signal[i].imag);
|
||||
}
|
||||
else if (freq_signal[i].imag == 0)
|
||||
{
|
||||
freq_signal_abs[i] = (uint16_t)WEBRTC_SPL_ABS_W16(freq_signal[i].real);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Approximation for magnitude of complex fft output
|
||||
// magn = sqrt(real^2 + imag^2)
|
||||
// magn ~= alpha * max(|imag|,|real|) + beta * min(|imag|,|real|)
|
||||
//
|
||||
// The parameters alpha and beta are stored in Q15
|
||||
|
||||
#ifdef AECM_WITH_ABS_APPROX
|
||||
tmp16no1 = WEBRTC_SPL_ABS_W16(freq_signal[i].real);
|
||||
tmp16no2 = WEBRTC_SPL_ABS_W16(freq_signal[i].imag);
|
||||
|
||||
if(tmp16no1 > tmp16no2)
|
||||
{
|
||||
max_value = tmp16no1;
|
||||
min_value = tmp16no2;
|
||||
} else
|
||||
{
|
||||
max_value = tmp16no2;
|
||||
min_value = tmp16no1;
|
||||
}
|
||||
|
||||
// Magnitude in Q(-6)
|
||||
if ((max_value >> 2) > min_value)
|
||||
{
|
||||
alpha = kAlpha1;
|
||||
beta = kBeta1;
|
||||
} else if ((max_value >> 1) > min_value)
|
||||
{
|
||||
alpha = kAlpha2;
|
||||
beta = kBeta2;
|
||||
} else
|
||||
{
|
||||
alpha = kAlpha3;
|
||||
beta = kBeta3;
|
||||
}
|
||||
tmp16no1 = (int16_t)((max_value * alpha) >> 15);
|
||||
tmp16no2 = (int16_t)((min_value * beta) >> 15);
|
||||
freq_signal_abs[i] = (uint16_t)tmp16no1 + (uint16_t)tmp16no2;
|
||||
#else
|
||||
#ifdef WEBRTC_ARCH_ARM_V7
|
||||
__asm __volatile(
|
||||
"smulbb %[tmp32no1], %[real], %[real]\n\t"
|
||||
"smlabb %[tmp32no2], %[imag], %[imag], %[tmp32no1]\n\t"
|
||||
:[tmp32no1]"+&r"(tmp32no1),
|
||||
[tmp32no2]"=r"(tmp32no2)
|
||||
:[real]"r"(freq_signal[i].real),
|
||||
[imag]"r"(freq_signal[i].imag)
|
||||
);
|
||||
#else
|
||||
tmp16no1 = WEBRTC_SPL_ABS_W16(freq_signal[i].real);
|
||||
tmp16no2 = WEBRTC_SPL_ABS_W16(freq_signal[i].imag);
|
||||
tmp32no1 = tmp16no1 * tmp16no1;
|
||||
tmp32no2 = tmp16no2 * tmp16no2;
|
||||
tmp32no2 = WebRtcSpl_AddSatW32(tmp32no1, tmp32no2);
|
||||
#endif // WEBRTC_ARCH_ARM_V7
|
||||
tmp32no1 = WebRtcSpl_SqrtFloor(tmp32no2);
|
||||
|
||||
freq_signal_abs[i] = (uint16_t)tmp32no1;
|
||||
#endif // AECM_WITH_ABS_APPROX
|
||||
}
|
||||
(*freq_signal_sum_abs) += (uint32_t)freq_signal_abs[i];
|
||||
}
|
||||
|
||||
return time_signal_scaling;
|
||||
}
|
||||
|
||||
int WebRtcAecm_ProcessBlock(AecmCore* aecm,
|
||||
const int16_t* farend,
|
||||
const int16_t* nearendNoisy,
|
||||
const int16_t* nearendClean,
|
||||
int16_t* output) {
|
||||
int i;
|
||||
|
||||
uint32_t xfaSum;
|
||||
uint32_t dfaNoisySum;
|
||||
uint32_t dfaCleanSum;
|
||||
uint32_t echoEst32Gained;
|
||||
uint32_t tmpU32;
|
||||
|
||||
int32_t tmp32no1;
|
||||
|
||||
uint16_t xfa[PART_LEN1];
|
||||
uint16_t dfaNoisy[PART_LEN1];
|
||||
uint16_t dfaClean[PART_LEN1];
|
||||
uint16_t* ptrDfaClean = dfaClean;
|
||||
const uint16_t* far_spectrum_ptr = NULL;
|
||||
|
||||
// 32 byte aligned buffers (with +8 or +16).
|
||||
// TODO(kma): define fft with ComplexInt16.
|
||||
int16_t fft_buf[PART_LEN4 + 2 + 16]; // +2 to make a loop safe.
|
||||
int32_t echoEst32_buf[PART_LEN1 + 8];
|
||||
int32_t dfw_buf[PART_LEN2 + 8];
|
||||
int32_t efw_buf[PART_LEN2 + 8];
|
||||
|
||||
int16_t* fft = (int16_t*) (((uintptr_t) fft_buf + 31) & ~ 31);
|
||||
int32_t* echoEst32 = (int32_t*) (((uintptr_t) echoEst32_buf + 31) & ~ 31);
|
||||
ComplexInt16* dfw = (ComplexInt16*)(((uintptr_t)dfw_buf + 31) & ~31);
|
||||
ComplexInt16* efw = (ComplexInt16*)(((uintptr_t)efw_buf + 31) & ~31);
|
||||
|
||||
int16_t hnl[PART_LEN1];
|
||||
int16_t numPosCoef = 0;
|
||||
int16_t nlpGain = ONE_Q14;
|
||||
int delay;
|
||||
int16_t tmp16no1;
|
||||
int16_t tmp16no2;
|
||||
int16_t mu;
|
||||
int16_t supGain;
|
||||
int16_t zeros32, zeros16;
|
||||
int16_t zerosDBufNoisy, zerosDBufClean, zerosXBuf;
|
||||
int far_q;
|
||||
int16_t resolutionDiff, qDomainDiff, dfa_clean_q_domain_diff;
|
||||
|
||||
const int kMinPrefBand = 4;
|
||||
const int kMaxPrefBand = 24;
|
||||
int32_t avgHnl32 = 0;
|
||||
|
||||
// Determine startup state. There are three states:
|
||||
// (0) the first CONV_LEN blocks
|
||||
// (1) another CONV_LEN blocks
|
||||
// (2) the rest
|
||||
|
||||
if (aecm->startupState < 2)
|
||||
{
|
||||
aecm->startupState = (aecm->totCount >= CONV_LEN) +
|
||||
(aecm->totCount >= CONV_LEN2);
|
||||
}
|
||||
// END: Determine startup state
|
||||
|
||||
// Buffer near and far end signals
|
||||
memcpy(aecm->xBuf + PART_LEN, farend, sizeof(int16_t) * PART_LEN);
|
||||
memcpy(aecm->dBufNoisy + PART_LEN, nearendNoisy, sizeof(int16_t) * PART_LEN);
|
||||
if (nearendClean != NULL)
|
||||
{
|
||||
memcpy(aecm->dBufClean + PART_LEN,
|
||||
nearendClean,
|
||||
sizeof(int16_t) * PART_LEN);
|
||||
}
|
||||
|
||||
// Transform far end signal from time domain to frequency domain.
|
||||
far_q = TimeToFrequencyDomain(aecm,
|
||||
aecm->xBuf,
|
||||
dfw,
|
||||
xfa,
|
||||
&xfaSum);
|
||||
|
||||
// Transform noisy near end signal from time domain to frequency domain.
|
||||
zerosDBufNoisy = TimeToFrequencyDomain(aecm,
|
||||
aecm->dBufNoisy,
|
||||
dfw,
|
||||
dfaNoisy,
|
||||
&dfaNoisySum);
|
||||
aecm->dfaNoisyQDomainOld = aecm->dfaNoisyQDomain;
|
||||
aecm->dfaNoisyQDomain = (int16_t)zerosDBufNoisy;
|
||||
|
||||
|
||||
if (nearendClean == NULL)
|
||||
{
|
||||
ptrDfaClean = dfaNoisy;
|
||||
aecm->dfaCleanQDomainOld = aecm->dfaNoisyQDomainOld;
|
||||
aecm->dfaCleanQDomain = aecm->dfaNoisyQDomain;
|
||||
dfaCleanSum = dfaNoisySum;
|
||||
} else
|
||||
{
|
||||
// Transform clean near end signal from time domain to frequency domain.
|
||||
zerosDBufClean = TimeToFrequencyDomain(aecm,
|
||||
aecm->dBufClean,
|
||||
dfw,
|
||||
dfaClean,
|
||||
&dfaCleanSum);
|
||||
aecm->dfaCleanQDomainOld = aecm->dfaCleanQDomain;
|
||||
aecm->dfaCleanQDomain = (int16_t)zerosDBufClean;
|
||||
}
|
||||
|
||||
// Get the delay
|
||||
// Save far-end history and estimate delay
|
||||
WebRtcAecm_UpdateFarHistory(aecm, xfa, far_q);
|
||||
if (WebRtc_AddFarSpectrumFix(aecm->delay_estimator_farend,
|
||||
xfa,
|
||||
PART_LEN1,
|
||||
far_q) == -1) {
|
||||
return -1;
|
||||
}
|
||||
delay = WebRtc_DelayEstimatorProcessFix(aecm->delay_estimator,
|
||||
dfaNoisy,
|
||||
PART_LEN1,
|
||||
zerosDBufNoisy);
|
||||
if (delay == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (delay == -2)
|
||||
{
|
||||
// If the delay is unknown, we assume zero.
|
||||
// NOTE: this will have to be adjusted if we ever add lookahead.
|
||||
delay = 0;
|
||||
}
|
||||
|
||||
if (aecm->fixedDelay >= 0)
|
||||
{
|
||||
// Use fixed delay
|
||||
delay = aecm->fixedDelay;
|
||||
}
|
||||
|
||||
// Get aligned far end spectrum
|
||||
far_spectrum_ptr = WebRtcAecm_AlignedFarend(aecm, &far_q, delay);
|
||||
zerosXBuf = (int16_t) far_q;
|
||||
if (far_spectrum_ptr == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Calculate log(energy) and update energy threshold levels
|
||||
WebRtcAecm_CalcEnergies(aecm,
|
||||
far_spectrum_ptr,
|
||||
zerosXBuf,
|
||||
dfaNoisySum,
|
||||
echoEst32);
|
||||
|
||||
// Calculate stepsize
|
||||
mu = WebRtcAecm_CalcStepSize(aecm);
|
||||
|
||||
// Update counters
|
||||
aecm->totCount++;
|
||||
|
||||
// This is the channel estimation algorithm.
|
||||
// It is base on NLMS but has a variable step length,
|
||||
// which was calculated above.
|
||||
WebRtcAecm_UpdateChannel(aecm,
|
||||
far_spectrum_ptr,
|
||||
zerosXBuf,
|
||||
dfaNoisy,
|
||||
mu,
|
||||
echoEst32);
|
||||
supGain = WebRtcAecm_CalcSuppressionGain(aecm);
|
||||
|
||||
|
||||
// Calculate Wiener filter hnl[]
|
||||
for (i = 0; i < PART_LEN1; i++)
|
||||
{
|
||||
// Far end signal through channel estimate in Q8
|
||||
// How much can we shift right to preserve resolution
|
||||
tmp32no1 = echoEst32[i] - aecm->echoFilt[i];
|
||||
aecm->echoFilt[i] += (tmp32no1 * 50) >> 8;
|
||||
|
||||
zeros32 = WebRtcSpl_NormW32(aecm->echoFilt[i]) + 1;
|
||||
zeros16 = WebRtcSpl_NormW16(supGain) + 1;
|
||||
if (zeros32 + zeros16 > 16)
|
||||
{
|
||||
// Multiplication is safe
|
||||
// Result in
|
||||
// Q(RESOLUTION_CHANNEL+RESOLUTION_SUPGAIN+
|
||||
// aecm->xfaQDomainBuf[diff])
|
||||
echoEst32Gained = WEBRTC_SPL_UMUL_32_16((uint32_t)aecm->echoFilt[i],
|
||||
(uint16_t)supGain);
|
||||
resolutionDiff = 14 - RESOLUTION_CHANNEL16 - RESOLUTION_SUPGAIN;
|
||||
resolutionDiff += (aecm->dfaCleanQDomain - zerosXBuf);
|
||||
} else
|
||||
{
|
||||
tmp16no1 = 17 - zeros32 - zeros16;
|
||||
resolutionDiff = 14 + tmp16no1 - RESOLUTION_CHANNEL16 -
|
||||
RESOLUTION_SUPGAIN;
|
||||
resolutionDiff += (aecm->dfaCleanQDomain - zerosXBuf);
|
||||
if (zeros32 > tmp16no1)
|
||||
{
|
||||
echoEst32Gained = WEBRTC_SPL_UMUL_32_16((uint32_t)aecm->echoFilt[i],
|
||||
supGain >> tmp16no1);
|
||||
} else
|
||||
{
|
||||
// Result in Q-(RESOLUTION_CHANNEL+RESOLUTION_SUPGAIN-16)
|
||||
echoEst32Gained = (aecm->echoFilt[i] >> tmp16no1) * supGain;
|
||||
}
|
||||
}
|
||||
|
||||
zeros16 = WebRtcSpl_NormW16(aecm->nearFilt[i]);
|
||||
assert(zeros16 >= 0); // |zeros16| is a norm, hence non-negative.
|
||||
dfa_clean_q_domain_diff = aecm->dfaCleanQDomain - aecm->dfaCleanQDomainOld;
|
||||
if (zeros16 < dfa_clean_q_domain_diff && aecm->nearFilt[i]) {
|
||||
tmp16no1 = aecm->nearFilt[i] << zeros16;
|
||||
qDomainDiff = zeros16 - dfa_clean_q_domain_diff;
|
||||
tmp16no2 = ptrDfaClean[i] >> -qDomainDiff;
|
||||
} else {
|
||||
tmp16no1 = dfa_clean_q_domain_diff < 0
|
||||
? aecm->nearFilt[i] >> -dfa_clean_q_domain_diff
|
||||
: aecm->nearFilt[i] << dfa_clean_q_domain_diff;
|
||||
qDomainDiff = 0;
|
||||
tmp16no2 = ptrDfaClean[i];
|
||||
}
|
||||
tmp32no1 = (int32_t)(tmp16no2 - tmp16no1);
|
||||
tmp16no2 = (int16_t)(tmp32no1 >> 4);
|
||||
tmp16no2 += tmp16no1;
|
||||
zeros16 = WebRtcSpl_NormW16(tmp16no2);
|
||||
if ((tmp16no2) & (-qDomainDiff > zeros16)) {
|
||||
aecm->nearFilt[i] = WEBRTC_SPL_WORD16_MAX;
|
||||
} else {
|
||||
aecm->nearFilt[i] = qDomainDiff < 0 ? tmp16no2 << -qDomainDiff
|
||||
: tmp16no2 >> qDomainDiff;
|
||||
}
|
||||
|
||||
// Wiener filter coefficients, resulting hnl in Q14
|
||||
if (echoEst32Gained == 0)
|
||||
{
|
||||
hnl[i] = ONE_Q14;
|
||||
} else if (aecm->nearFilt[i] == 0)
|
||||
{
|
||||
hnl[i] = 0;
|
||||
} else
|
||||
{
|
||||
// Multiply the suppression gain
|
||||
// Rounding
|
||||
echoEst32Gained += (uint32_t)(aecm->nearFilt[i] >> 1);
|
||||
tmpU32 = WebRtcSpl_DivU32U16(echoEst32Gained,
|
||||
(uint16_t)aecm->nearFilt[i]);
|
||||
|
||||
// Current resolution is
|
||||
// Q-(RESOLUTION_CHANNEL+RESOLUTION_SUPGAIN- max(0,17-zeros16- zeros32))
|
||||
// Make sure we are in Q14
|
||||
tmp32no1 = (int32_t)WEBRTC_SPL_SHIFT_W32(tmpU32, resolutionDiff);
|
||||
if (tmp32no1 > ONE_Q14)
|
||||
{
|
||||
hnl[i] = 0;
|
||||
} else if (tmp32no1 < 0)
|
||||
{
|
||||
hnl[i] = ONE_Q14;
|
||||
} else
|
||||
{
|
||||
// 1-echoEst/dfa
|
||||
hnl[i] = ONE_Q14 - (int16_t)tmp32no1;
|
||||
if (hnl[i] < 0)
|
||||
{
|
||||
hnl[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hnl[i])
|
||||
{
|
||||
numPosCoef++;
|
||||
}
|
||||
}
|
||||
// Only in wideband. Prevent the gain in upper band from being larger than
|
||||
// in lower band.
|
||||
if (aecm->mult == 2)
|
||||
{
|
||||
// TODO(bjornv): Investigate if the scaling of hnl[i] below can cause
|
||||
// speech distortion in double-talk.
|
||||
for (i = 0; i < PART_LEN1; i++)
|
||||
{
|
||||
hnl[i] = (int16_t)((hnl[i] * hnl[i]) >> 14);
|
||||
}
|
||||
|
||||
for (i = kMinPrefBand; i <= kMaxPrefBand; i++)
|
||||
{
|
||||
avgHnl32 += (int32_t)hnl[i];
|
||||
}
|
||||
assert(kMaxPrefBand - kMinPrefBand + 1 > 0);
|
||||
avgHnl32 /= (kMaxPrefBand - kMinPrefBand + 1);
|
||||
|
||||
for (i = kMaxPrefBand; i < PART_LEN1; i++)
|
||||
{
|
||||
if (hnl[i] > (int16_t)avgHnl32)
|
||||
{
|
||||
hnl[i] = (int16_t)avgHnl32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate NLP gain, result is in Q14
|
||||
if (aecm->nlpFlag)
|
||||
{
|
||||
for (i = 0; i < PART_LEN1; i++)
|
||||
{
|
||||
// Truncate values close to zero and one.
|
||||
if (hnl[i] > NLP_COMP_HIGH)
|
||||
{
|
||||
hnl[i] = ONE_Q14;
|
||||
} else if (hnl[i] < NLP_COMP_LOW)
|
||||
{
|
||||
hnl[i] = 0;
|
||||
}
|
||||
|
||||
// Remove outliers
|
||||
if (numPosCoef < 3)
|
||||
{
|
||||
nlpGain = 0;
|
||||
} else
|
||||
{
|
||||
nlpGain = ONE_Q14;
|
||||
}
|
||||
|
||||
// NLP
|
||||
if ((hnl[i] == ONE_Q14) && (nlpGain == ONE_Q14))
|
||||
{
|
||||
hnl[i] = ONE_Q14;
|
||||
} else
|
||||
{
|
||||
hnl[i] = (int16_t)((hnl[i] * nlpGain) >> 14);
|
||||
}
|
||||
|
||||
// multiply with Wiener coefficients
|
||||
efw[i].real = (int16_t)(WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(dfw[i].real,
|
||||
hnl[i], 14));
|
||||
efw[i].imag = (int16_t)(WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(dfw[i].imag,
|
||||
hnl[i], 14));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// multiply with Wiener coefficients
|
||||
for (i = 0; i < PART_LEN1; i++)
|
||||
{
|
||||
efw[i].real = (int16_t)(WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(dfw[i].real,
|
||||
hnl[i], 14));
|
||||
efw[i].imag = (int16_t)(WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(dfw[i].imag,
|
||||
hnl[i], 14));
|
||||
}
|
||||
}
|
||||
|
||||
if (aecm->cngMode == AecmTrue)
|
||||
{
|
||||
ComfortNoise(aecm, ptrDfaClean, efw, hnl);
|
||||
}
|
||||
|
||||
InverseFFTAndWindow(aecm, fft, efw, output, nearendClean);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ComfortNoise(AecmCore* aecm,
|
||||
const uint16_t* dfa,
|
||||
ComplexInt16* out,
|
||||
const int16_t* lambda) {
|
||||
int16_t i;
|
||||
int16_t tmp16;
|
||||
int32_t tmp32;
|
||||
|
||||
int16_t randW16[PART_LEN];
|
||||
int16_t uReal[PART_LEN1];
|
||||
int16_t uImag[PART_LEN1];
|
||||
int32_t outLShift32;
|
||||
int16_t noiseRShift16[PART_LEN1];
|
||||
|
||||
int16_t shiftFromNearToNoise = kNoiseEstQDomain - aecm->dfaCleanQDomain;
|
||||
int16_t minTrackShift;
|
||||
|
||||
assert(shiftFromNearToNoise >= 0);
|
||||
assert(shiftFromNearToNoise < 16);
|
||||
|
||||
if (aecm->noiseEstCtr < 100)
|
||||
{
|
||||
// Track the minimum more quickly initially.
|
||||
aecm->noiseEstCtr++;
|
||||
minTrackShift = 6;
|
||||
} else
|
||||
{
|
||||
minTrackShift = 9;
|
||||
}
|
||||
|
||||
// Estimate noise power.
|
||||
for (i = 0; i < PART_LEN1; i++)
|
||||
{
|
||||
// Shift to the noise domain.
|
||||
tmp32 = (int32_t)dfa[i];
|
||||
outLShift32 = tmp32 << shiftFromNearToNoise;
|
||||
|
||||
if (outLShift32 < aecm->noiseEst[i])
|
||||
{
|
||||
// Reset "too low" counter
|
||||
aecm->noiseEstTooLowCtr[i] = 0;
|
||||
// Track the minimum.
|
||||
if (aecm->noiseEst[i] < (1 << minTrackShift))
|
||||
{
|
||||
// For small values, decrease noiseEst[i] every
|
||||
// |kNoiseEstIncCount| block. The regular approach below can not
|
||||
// go further down due to truncation.
|
||||
aecm->noiseEstTooHighCtr[i]++;
|
||||
if (aecm->noiseEstTooHighCtr[i] >= kNoiseEstIncCount)
|
||||
{
|
||||
aecm->noiseEst[i]--;
|
||||
aecm->noiseEstTooHighCtr[i] = 0; // Reset the counter
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aecm->noiseEst[i] -= ((aecm->noiseEst[i] - outLShift32)
|
||||
>> minTrackShift);
|
||||
}
|
||||
} else
|
||||
{
|
||||
// Reset "too high" counter
|
||||
aecm->noiseEstTooHighCtr[i] = 0;
|
||||
// Ramp slowly upwards until we hit the minimum again.
|
||||
if ((aecm->noiseEst[i] >> 19) > 0)
|
||||
{
|
||||
// Avoid overflow.
|
||||
// Multiplication with 2049 will cause wrap around. Scale
|
||||
// down first and then multiply
|
||||
aecm->noiseEst[i] >>= 11;
|
||||
aecm->noiseEst[i] *= 2049;
|
||||
}
|
||||
else if ((aecm->noiseEst[i] >> 11) > 0)
|
||||
{
|
||||
// Large enough for relative increase
|
||||
aecm->noiseEst[i] *= 2049;
|
||||
aecm->noiseEst[i] >>= 11;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make incremental increases based on size every
|
||||
// |kNoiseEstIncCount| block
|
||||
aecm->noiseEstTooLowCtr[i]++;
|
||||
if (aecm->noiseEstTooLowCtr[i] >= kNoiseEstIncCount)
|
||||
{
|
||||
aecm->noiseEst[i] += (aecm->noiseEst[i] >> 9) + 1;
|
||||
aecm->noiseEstTooLowCtr[i] = 0; // Reset counter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < PART_LEN1; i++)
|
||||
{
|
||||
tmp32 = aecm->noiseEst[i] >> shiftFromNearToNoise;
|
||||
if (tmp32 > 32767)
|
||||
{
|
||||
tmp32 = 32767;
|
||||
aecm->noiseEst[i] = tmp32 << shiftFromNearToNoise;
|
||||
}
|
||||
noiseRShift16[i] = (int16_t)tmp32;
|
||||
|
||||
tmp16 = ONE_Q14 - lambda[i];
|
||||
noiseRShift16[i] = (int16_t)((tmp16 * noiseRShift16[i]) >> 14);
|
||||
}
|
||||
|
||||
// Generate a uniform random array on [0 2^15-1].
|
||||
WebRtcSpl_RandUArray(randW16, PART_LEN, &aecm->seed);
|
||||
|
||||
// Generate noise according to estimated energy.
|
||||
uReal[0] = 0; // Reject LF noise.
|
||||
uImag[0] = 0;
|
||||
for (i = 1; i < PART_LEN1; i++)
|
||||
{
|
||||
// Get a random index for the cos and sin tables over [0 359].
|
||||
tmp16 = (int16_t)((359 * randW16[i - 1]) >> 15);
|
||||
|
||||
// Tables are in Q13.
|
||||
uReal[i] = (int16_t)((noiseRShift16[i] * WebRtcAecm_kCosTable[tmp16]) >>
|
||||
13);
|
||||
uImag[i] = (int16_t)((-noiseRShift16[i] * WebRtcAecm_kSinTable[tmp16]) >>
|
||||
13);
|
||||
}
|
||||
uImag[PART_LEN] = 0;
|
||||
|
||||
for (i = 0; i < PART_LEN1; i++)
|
||||
{
|
||||
out[i].real = WebRtcSpl_AddSatW16(out[i].real, uReal[i]);
|
||||
out[i].imag = WebRtcSpl_AddSatW16(out[i].imag, uImag[i]);
|
||||
}
|
||||
}
|
||||
|
1566
webrtc/modules/audio_processing/aecm/aecm_core_mips.c
Normal file
1566
webrtc/modules/audio_processing/aecm/aecm_core_mips.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
@ -7,308 +7,206 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#if defined(WEBRTC_ANDROID) && defined(WEBRTC_ARCH_ARM_NEON)
|
||||
|
||||
#include "aecm_core.h"
|
||||
#include "webrtc/modules/audio_processing/aecm/aecm_core.h"
|
||||
|
||||
#include <arm_neon.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "webrtc/common_audio/signal_processing/include/real_fft.h"
|
||||
|
||||
// TODO(kma): Re-write the corresponding assembly file, the offset
|
||||
// generating script and makefile, to replace these C functions.
|
||||
|
||||
// Square root of Hanning window in Q14.
|
||||
static const WebRtc_Word16 kSqrtHanningReversed[] __attribute__ ((aligned (8))) = {
|
||||
16384, 16373, 16354, 16325,
|
||||
16286, 16237, 16179, 16111,
|
||||
16034, 15947, 15851, 15746,
|
||||
15631, 15506, 15373, 15231,
|
||||
15079, 14918, 14749, 14571,
|
||||
14384, 14189, 13985, 13773,
|
||||
13553, 13325, 13089, 12845,
|
||||
12594, 12335, 12068, 11795,
|
||||
11514, 11227, 10933, 10633,
|
||||
10326, 10013, 9695, 9370,
|
||||
9040, 8705, 8364, 8019,
|
||||
7668, 7313, 6954, 6591,
|
||||
6224, 5853, 5478, 5101,
|
||||
4720, 4337, 3951, 3562,
|
||||
3172, 2780, 2386, 1990,
|
||||
1594, 1196, 798, 399
|
||||
const ALIGN8_BEG int16_t WebRtcAecm_kSqrtHanning[] ALIGN8_END = {
|
||||
0,
|
||||
399, 798, 1196, 1594, 1990, 2386, 2780, 3172,
|
||||
3562, 3951, 4337, 4720, 5101, 5478, 5853, 6224,
|
||||
6591, 6954, 7313, 7668, 8019, 8364, 8705, 9040,
|
||||
9370, 9695, 10013, 10326, 10633, 10933, 11227, 11514,
|
||||
11795, 12068, 12335, 12594, 12845, 13089, 13325, 13553,
|
||||
13773, 13985, 14189, 14384, 14571, 14749, 14918, 15079,
|
||||
15231, 15373, 15506, 15631, 15746, 15851, 15947, 16034,
|
||||
16111, 16179, 16237, 16286, 16325, 16354, 16373, 16384
|
||||
};
|
||||
|
||||
void WebRtcAecm_WindowAndFFT(WebRtc_Word16* fft,
|
||||
const WebRtc_Word16* time_signal,
|
||||
complex16_t* freq_signal,
|
||||
int time_signal_scaling)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
int16x4_t tmp16x4_scaling = vdup_n_s16(time_signal_scaling);
|
||||
__asm__("vmov.i16 d21, #0" ::: "d21");
|
||||
|
||||
for(i = 0, j = 0; i < PART_LEN; i += 4, j += 8)
|
||||
{
|
||||
int16x4_t tmp16x4_0;
|
||||
int16x4_t tmp16x4_1;
|
||||
int32x4_t tmp32x4_0;
|
||||
|
||||
/* Window near end */
|
||||
// fft[j] = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT((time_signal[i]
|
||||
// << time_signal_scaling), WebRtcAecm_kSqrtHanning[i], 14);
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_0) : "r"(&time_signal[i]));
|
||||
tmp16x4_0 = vshl_s16(tmp16x4_0, tmp16x4_scaling);
|
||||
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_1) : "r"(&WebRtcAecm_kSqrtHanning[i]));
|
||||
tmp32x4_0 = vmull_s16(tmp16x4_0, tmp16x4_1);
|
||||
|
||||
__asm__("vshrn.i32 d20, %q0, #14" : : "w"(tmp32x4_0) : "d20");
|
||||
__asm__("vst2.16 {d20, d21}, [%0, :128]" : : "r"(&fft[j]) : "q10");
|
||||
|
||||
// fft[PART_LEN2 + j] = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(
|
||||
// (time_signal[PART_LEN + i] << time_signal_scaling),
|
||||
// WebRtcAecm_kSqrtHanning[PART_LEN - i], 14);
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_0) : "r"(&time_signal[i + PART_LEN]));
|
||||
tmp16x4_0 = vshl_s16(tmp16x4_0, tmp16x4_scaling);
|
||||
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_1) : "r"(&kSqrtHanningReversed[i]));
|
||||
tmp32x4_0 = vmull_s16(tmp16x4_0, tmp16x4_1);
|
||||
|
||||
__asm__("vshrn.i32 d20, %q0, #14" : : "w"(tmp32x4_0) : "d20");
|
||||
__asm__("vst2.16 {d20, d21}, [%0, :128]" : : "r"(&fft[PART_LEN2 + j]) : "q10");
|
||||
}
|
||||
|
||||
WebRtcSpl_ComplexBitReverse(fft, PART_LEN_SHIFT);
|
||||
WebRtcSpl_ComplexFFT(fft, PART_LEN_SHIFT, 1);
|
||||
|
||||
// Take only the first PART_LEN2 samples, and switch the sign of the imaginary part.
|
||||
for(i = 0, j = 0; j < PART_LEN2; i += 8, j += 16)
|
||||
{
|
||||
__asm__("vld2.16 {d20, d21, d22, d23}, [%0, :256]" : : "r"(&fft[j]) : "q10", "q11");
|
||||
__asm__("vneg.s16 d22, d22" : : : "q10");
|
||||
__asm__("vneg.s16 d23, d23" : : : "q11");
|
||||
__asm__("vst2.16 {d20, d21, d22, d23}, [%0, :256]" : :
|
||||
"r"(&freq_signal[i].real): "q10", "q11");
|
||||
}
|
||||
static inline void AddLanes(uint32_t* ptr, uint32x4_t v) {
|
||||
#if defined(WEBRTC_ARCH_ARM64)
|
||||
*(ptr) = vaddvq_u32(v);
|
||||
#else
|
||||
uint32x2_t tmp_v;
|
||||
tmp_v = vadd_u32(vget_low_u32(v), vget_high_u32(v));
|
||||
tmp_v = vpadd_u32(tmp_v, tmp_v);
|
||||
*(ptr) = vget_lane_u32(tmp_v, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebRtcAecm_InverseFFTAndWindow(AecmCore_t* aecm,
|
||||
WebRtc_Word16* fft,
|
||||
complex16_t* efw,
|
||||
WebRtc_Word16* output,
|
||||
const WebRtc_Word16* nearendClean)
|
||||
{
|
||||
int i, j, outCFFT;
|
||||
WebRtc_Word32 tmp32no1;
|
||||
void WebRtcAecm_CalcLinearEnergiesNeon(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
int32_t* echo_est,
|
||||
uint32_t* far_energy,
|
||||
uint32_t* echo_energy_adapt,
|
||||
uint32_t* echo_energy_stored) {
|
||||
int16_t* start_stored_p = aecm->channelStored;
|
||||
int16_t* start_adapt_p = aecm->channelAdapt16;
|
||||
int32_t* echo_est_p = echo_est;
|
||||
const int16_t* end_stored_p = aecm->channelStored + PART_LEN;
|
||||
const uint16_t* far_spectrum_p = far_spectrum;
|
||||
int16x8_t store_v, adapt_v;
|
||||
uint16x8_t spectrum_v;
|
||||
uint32x4_t echo_est_v_low, echo_est_v_high;
|
||||
uint32x4_t far_energy_v, echo_stored_v, echo_adapt_v;
|
||||
|
||||
// Synthesis
|
||||
for(i = 0, j = 0; i < PART_LEN; i += 4, j += 8)
|
||||
{
|
||||
// We overwrite two more elements in fft[], but it's ok.
|
||||
__asm__("vld2.16 {d20, d21}, [%0, :128]" : : "r"(&(efw[i].real)) : "q10");
|
||||
__asm__("vmov q11, q10" : : : "q10", "q11");
|
||||
far_energy_v = vdupq_n_u32(0);
|
||||
echo_adapt_v = vdupq_n_u32(0);
|
||||
echo_stored_v = vdupq_n_u32(0);
|
||||
|
||||
__asm__("vneg.s16 d23, d23" : : : "q11");
|
||||
__asm__("vst2.16 {d22, d23}, [%0, :128]" : : "r"(&fft[j]): "q11");
|
||||
// Get energy for the delayed far end signal and estimated
|
||||
// echo using both stored and adapted channels.
|
||||
// The C code:
|
||||
// for (i = 0; i < PART_LEN1; i++) {
|
||||
// echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i],
|
||||
// far_spectrum[i]);
|
||||
// (*far_energy) += (uint32_t)(far_spectrum[i]);
|
||||
// *echo_energy_adapt += aecm->channelAdapt16[i] * far_spectrum[i];
|
||||
// (*echo_energy_stored) += (uint32_t)echo_est[i];
|
||||
// }
|
||||
while (start_stored_p < end_stored_p) {
|
||||
spectrum_v = vld1q_u16(far_spectrum_p);
|
||||
adapt_v = vld1q_s16(start_adapt_p);
|
||||
store_v = vld1q_s16(start_stored_p);
|
||||
|
||||
__asm__("vrev64.16 q10, q10" : : : "q10");
|
||||
__asm__("vst2.16 {d20, d21}, [%0]" : : "r"(&fft[PART_LEN4 - j - 6]): "q10");
|
||||
}
|
||||
far_energy_v = vaddw_u16(far_energy_v, vget_low_u16(spectrum_v));
|
||||
far_energy_v = vaddw_u16(far_energy_v, vget_high_u16(spectrum_v));
|
||||
|
||||
fft[PART_LEN2] = efw[PART_LEN].real;
|
||||
fft[PART_LEN2 + 1] = -efw[PART_LEN].imag;
|
||||
echo_est_v_low = vmull_u16(vreinterpret_u16_s16(vget_low_s16(store_v)),
|
||||
vget_low_u16(spectrum_v));
|
||||
echo_est_v_high = vmull_u16(vreinterpret_u16_s16(vget_high_s16(store_v)),
|
||||
vget_high_u16(spectrum_v));
|
||||
vst1q_s32(echo_est_p, vreinterpretq_s32_u32(echo_est_v_low));
|
||||
vst1q_s32(echo_est_p + 4, vreinterpretq_s32_u32(echo_est_v_high));
|
||||
|
||||
// Inverse FFT, result should be scaled with outCFFT.
|
||||
WebRtcSpl_ComplexBitReverse(fft, PART_LEN_SHIFT);
|
||||
outCFFT = WebRtcSpl_ComplexIFFT(fft, PART_LEN_SHIFT, 1);
|
||||
echo_stored_v = vaddq_u32(echo_est_v_low, echo_stored_v);
|
||||
echo_stored_v = vaddq_u32(echo_est_v_high, echo_stored_v);
|
||||
|
||||
// Take only the real values and scale with outCFFT.
|
||||
for (i = 0, j = 0; i < PART_LEN2; i += 8, j+= 16)
|
||||
{
|
||||
__asm__("vld2.16 {d20, d21, d22, d23}, [%0, :256]" : : "r"(&fft[j]) : "q10", "q11");
|
||||
__asm__("vst1.16 {d20, d21}, [%0, :128]" : : "r"(&fft[i]): "q10");
|
||||
}
|
||||
echo_adapt_v = vmlal_u16(echo_adapt_v,
|
||||
vreinterpret_u16_s16(vget_low_s16(adapt_v)),
|
||||
vget_low_u16(spectrum_v));
|
||||
echo_adapt_v = vmlal_u16(echo_adapt_v,
|
||||
vreinterpret_u16_s16(vget_high_s16(adapt_v)),
|
||||
vget_high_u16(spectrum_v));
|
||||
|
||||
int32x4_t tmp32x4_2;
|
||||
__asm__("vdup.32 %q0, %1" : "=w"(tmp32x4_2) : "r"((WebRtc_Word32)
|
||||
(outCFFT - aecm->dfaCleanQDomain)));
|
||||
for (i = 0; i < PART_LEN; i += 4)
|
||||
{
|
||||
int16x4_t tmp16x4_0;
|
||||
int16x4_t tmp16x4_1;
|
||||
int32x4_t tmp32x4_0;
|
||||
int32x4_t tmp32x4_1;
|
||||
start_stored_p += 8;
|
||||
start_adapt_p += 8;
|
||||
far_spectrum_p += 8;
|
||||
echo_est_p += 8;
|
||||
}
|
||||
|
||||
// fft[i] = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(
|
||||
// fft[i], WebRtcAecm_kSqrtHanning[i], 14);
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_0) : "r"(&fft[i]));
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_1) : "r"(&WebRtcAecm_kSqrtHanning[i]));
|
||||
__asm__("vmull.s16 %q0, %P1, %P2" : "=w"(tmp32x4_0) : "w"(tmp16x4_0), "w"(tmp16x4_1));
|
||||
__asm__("vrshr.s32 %q0, %q1, #14" : "=w"(tmp32x4_0) : "0"(tmp32x4_0));
|
||||
AddLanes(far_energy, far_energy_v);
|
||||
AddLanes(echo_energy_stored, echo_stored_v);
|
||||
AddLanes(echo_energy_adapt, echo_adapt_v);
|
||||
|
||||
// tmp32no1 = WEBRTC_SPL_SHIFT_W32((WebRtc_Word32)fft[i],
|
||||
// outCFFT - aecm->dfaCleanQDomain);
|
||||
__asm__("vshl.s32 %q0, %q1, %q2" : "=w"(tmp32x4_0) : "0"(tmp32x4_0), "w"(tmp32x4_2));
|
||||
|
||||
// fft[i] = (WebRtc_Word16)WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX,
|
||||
// tmp32no1 + outBuf[i], WEBRTC_SPL_WORD16_MIN);
|
||||
// output[i] = fft[i];
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_0) : "r"(&aecm->outBuf[i]));
|
||||
__asm__("vmovl.s16 %q0, %P1" : "=w"(tmp32x4_1) : "w"(tmp16x4_0));
|
||||
__asm__("vadd.i32 %q0, %q1" : : "w"(tmp32x4_0), "w"(tmp32x4_1));
|
||||
__asm__("vqshrn.s32 %P0, %q1, #0" : "=w"(tmp16x4_0) : "w"(tmp32x4_0));
|
||||
__asm__("vst1.16 %P0, [%1, :64]" : : "w"(tmp16x4_0), "r"(&fft[i]));
|
||||
__asm__("vst1.16 %P0, [%1, :64]" : : "w"(tmp16x4_0), "r"(&output[i]));
|
||||
|
||||
// tmp32no1 = WEBRTC_SPL_MUL_16_16_RSFT(
|
||||
// fft[PART_LEN + i], WebRtcAecm_kSqrtHanning[PART_LEN - i], 14);
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_0) : "r"(&fft[PART_LEN + i]));
|
||||
__asm__("vld1.16 %P0, [%1, :64]" : "=w"(tmp16x4_1) : "r"(&kSqrtHanningReversed[i]));
|
||||
__asm__("vmull.s16 %q0, %P1, %P2" : "=w"(tmp32x4_0) : "w"(tmp16x4_0), "w"(tmp16x4_1));
|
||||
__asm__("vshr.s32 %q0, %q1, #14" : "=w"(tmp32x4_0) : "0"(tmp32x4_0));
|
||||
|
||||
// tmp32no1 = WEBRTC_SPL_SHIFT_W32(tmp32no1, outCFFT - aecm->dfaCleanQDomain);
|
||||
__asm__("vshl.s32 %q0, %q1, %q2" : "=w"(tmp32x4_0) : "0"(tmp32x4_0), "w"(tmp32x4_2));
|
||||
// outBuf[i] = (WebRtc_Word16)WEBRTC_SPL_SAT(
|
||||
// WEBRTC_SPL_WORD16_MAX, tmp32no1, WEBRTC_SPL_WORD16_MIN);
|
||||
__asm__("vqshrn.s32 %P0, %q1, #0" : "=w"(tmp16x4_0) : "w"(tmp32x4_0));
|
||||
__asm__("vst1.16 %P0, [%1, :64]" : : "w"(tmp16x4_0), "r"(&aecm->outBuf[i]));
|
||||
}
|
||||
|
||||
// Copy the current block to the old position (outBuf is shifted elsewhere).
|
||||
for (i = 0; i < PART_LEN; i += 16)
|
||||
{
|
||||
__asm__("vld1.16 {d20, d21, d22, d23}, [%0, :256]" : :
|
||||
"r"(&aecm->xBuf[i + PART_LEN]) : "q10");
|
||||
__asm__("vst1.16 {d20, d21, d22, d23}, [%0, :256]" : : "r"(&aecm->xBuf[i]): "q10");
|
||||
}
|
||||
for (i = 0; i < PART_LEN; i += 16)
|
||||
{
|
||||
__asm__("vld1.16 {d20, d21, d22, d23}, [%0, :256]" : :
|
||||
"r"(&aecm->dBufNoisy[i + PART_LEN]) : "q10");
|
||||
__asm__("vst1.16 {d20, d21, d22, d23}, [%0, :256]" : :
|
||||
"r"(&aecm->dBufNoisy[i]): "q10");
|
||||
}
|
||||
if (nearendClean != NULL) {
|
||||
for (i = 0; i < PART_LEN; i += 16)
|
||||
{
|
||||
__asm__("vld1.16 {d20, d21, d22, d23}, [%0, :256]" : :
|
||||
"r"(&aecm->dBufClean[i + PART_LEN]) : "q10");
|
||||
__asm__("vst1.16 {d20, d21, d22, d23}, [%0, :256]" : :
|
||||
"r"(&aecm->dBufClean[i]): "q10");
|
||||
}
|
||||
}
|
||||
echo_est[PART_LEN] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[PART_LEN],
|
||||
far_spectrum[PART_LEN]);
|
||||
*echo_energy_stored += (uint32_t)echo_est[PART_LEN];
|
||||
*far_energy += (uint32_t)far_spectrum[PART_LEN];
|
||||
*echo_energy_adapt += aecm->channelAdapt16[PART_LEN] * far_spectrum[PART_LEN];
|
||||
}
|
||||
|
||||
void WebRtcAecm_CalcLinearEnergies(AecmCore_t* aecm,
|
||||
const WebRtc_UWord16* far_spectrum,
|
||||
WebRtc_Word32* echo_est,
|
||||
WebRtc_UWord32* far_energy,
|
||||
WebRtc_UWord32* echo_energy_adapt,
|
||||
WebRtc_UWord32* echo_energy_stored)
|
||||
{
|
||||
int i;
|
||||
void WebRtcAecm_StoreAdaptiveChannelNeon(AecmCore* aecm,
|
||||
const uint16_t* far_spectrum,
|
||||
int32_t* echo_est) {
|
||||
assert((uintptr_t)echo_est % 32 == 0);
|
||||
assert((uintptr_t)(aecm->channelStored) % 16 == 0);
|
||||
assert((uintptr_t)(aecm->channelAdapt16) % 16 == 0);
|
||||
|
||||
register WebRtc_UWord32 far_energy_r;
|
||||
register WebRtc_UWord32 echo_energy_stored_r;
|
||||
register WebRtc_UWord32 echo_energy_adapt_r;
|
||||
uint32x4_t tmp32x4_0;
|
||||
// This is C code of following optimized code.
|
||||
// During startup we store the channel every block.
|
||||
// memcpy(aecm->channelStored,
|
||||
// aecm->channelAdapt16,
|
||||
// sizeof(int16_t) * PART_LEN1);
|
||||
// Recalculate echo estimate
|
||||
// for (i = 0; i < PART_LEN; i += 4) {
|
||||
// echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i],
|
||||
// far_spectrum[i]);
|
||||
// echo_est[i + 1] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i + 1],
|
||||
// far_spectrum[i + 1]);
|
||||
// echo_est[i + 2] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i + 2],
|
||||
// far_spectrum[i + 2]);
|
||||
// echo_est[i + 3] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i + 3],
|
||||
// far_spectrum[i + 3]);
|
||||
// }
|
||||
// echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i],
|
||||
// far_spectrum[i]);
|
||||
const uint16_t* far_spectrum_p = far_spectrum;
|
||||
int16_t* start_adapt_p = aecm->channelAdapt16;
|
||||
int16_t* start_stored_p = aecm->channelStored;
|
||||
const int16_t* end_stored_p = aecm->channelStored + PART_LEN;
|
||||
int32_t* echo_est_p = echo_est;
|
||||
|
||||
__asm__("vmov.i32 q14, #0" : : : "q14"); // far_energy
|
||||
__asm__("vmov.i32 q8, #0" : : : "q8"); // echo_energy_stored
|
||||
__asm__("vmov.i32 q9, #0" : : : "q9"); // echo_energy_adapt
|
||||
uint16x8_t far_spectrum_v;
|
||||
int16x8_t adapt_v;
|
||||
uint32x4_t echo_est_v_low, echo_est_v_high;
|
||||
|
||||
for(i = 0; i < PART_LEN -7; i += 8)
|
||||
{
|
||||
// far_energy += (WebRtc_UWord32)(far_spectrum[i]);
|
||||
__asm__("vld1.16 {d26, d27}, [%0]" : : "r"(&far_spectrum[i]) : "q13");
|
||||
__asm__("vaddw.u16 q14, q14, d26" : : : "q14", "q13");
|
||||
__asm__("vaddw.u16 q14, q14, d27" : : : "q14", "q13");
|
||||
while (start_stored_p < end_stored_p) {
|
||||
far_spectrum_v = vld1q_u16(far_spectrum_p);
|
||||
adapt_v = vld1q_s16(start_adapt_p);
|
||||
|
||||
// Get estimated echo energies for adaptive channel and stored channel.
|
||||
// echoEst[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i], far_spectrum[i]);
|
||||
__asm__("vld1.16 {d24, d25}, [%0, :128]" : : "r"(&aecm->channelStored[i]) : "q12");
|
||||
__asm__("vmull.u16 q10, d26, d24" : : : "q12", "q13", "q10");
|
||||
__asm__("vmull.u16 q11, d27, d25" : : : "q12", "q13", "q11");
|
||||
__asm__("vst1.32 {d20, d21, d22, d23}, [%0, :256]" : : "r"(&echo_est[i]):
|
||||
"q10", "q11");
|
||||
vst1q_s16(start_stored_p, adapt_v);
|
||||
|
||||
// echo_energy_stored += (WebRtc_UWord32)echoEst[i];
|
||||
__asm__("vadd.u32 q8, q10" : : : "q10", "q8");
|
||||
__asm__("vadd.u32 q8, q11" : : : "q11", "q8");
|
||||
echo_est_v_low = vmull_u16(vget_low_u16(far_spectrum_v),
|
||||
vget_low_u16(vreinterpretq_u16_s16(adapt_v)));
|
||||
echo_est_v_high = vmull_u16(vget_high_u16(far_spectrum_v),
|
||||
vget_high_u16(vreinterpretq_u16_s16(adapt_v)));
|
||||
|
||||
// echo_energy_adapt += WEBRTC_SPL_UMUL_16_16(
|
||||
// aecm->channelAdapt16[i], far_spectrum[i]);
|
||||
__asm__("vld1.16 {d24, d25}, [%0, :128]" : : "r"(&aecm->channelAdapt16[i]) : "q12");
|
||||
__asm__("vmull.u16 q10, d26, d24" : : : "q12", "q13", "q10");
|
||||
__asm__("vmull.u16 q11, d27, d25" : : : "q12", "q13", "q11");
|
||||
__asm__("vadd.u32 q9, q10" : : : "q9", "q15");
|
||||
__asm__("vadd.u32 q9, q11" : : : "q9", "q11");
|
||||
}
|
||||
vst1q_s32(echo_est_p, vreinterpretq_s32_u32(echo_est_v_low));
|
||||
vst1q_s32(echo_est_p + 4, vreinterpretq_s32_u32(echo_est_v_high));
|
||||
|
||||
__asm__("vadd.u32 d28, d29" : : : "q14");
|
||||
__asm__("vpadd.u32 d28, d28" : : : "q14");
|
||||
__asm__("vmov.32 %0, d28[0]" : "=r"(far_energy_r): : "q14");
|
||||
|
||||
__asm__("vadd.u32 d18, d19" : : : "q9");
|
||||
__asm__("vpadd.u32 d18, d18" : : : "q9");
|
||||
__asm__("vmov.32 %0, d18[0]" : "=r"(echo_energy_adapt_r): : "q9");
|
||||
|
||||
__asm__("vadd.u32 d16, d17" : : : "q8");
|
||||
__asm__("vpadd.u32 d16, d16" : : : "q8");
|
||||
__asm__("vmov.32 %0, d16[0]" : "=r"(echo_energy_stored_r): : "q8");
|
||||
|
||||
// Get estimated echo energies for adaptive channel and stored channel.
|
||||
echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i], far_spectrum[i]);
|
||||
*echo_energy_stored = echo_energy_stored_r + (WebRtc_UWord32)echo_est[i];
|
||||
*far_energy = far_energy_r + (WebRtc_UWord32)(far_spectrum[i]);
|
||||
*echo_energy_adapt = echo_energy_adapt_r + WEBRTC_SPL_UMUL_16_16(
|
||||
aecm->channelAdapt16[i], far_spectrum[i]);
|
||||
far_spectrum_p += 8;
|
||||
start_adapt_p += 8;
|
||||
start_stored_p += 8;
|
||||
echo_est_p += 8;
|
||||
}
|
||||
aecm->channelStored[PART_LEN] = aecm->channelAdapt16[PART_LEN];
|
||||
echo_est[PART_LEN] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[PART_LEN],
|
||||
far_spectrum[PART_LEN]);
|
||||
}
|
||||
|
||||
void WebRtcAecm_StoreAdaptiveChannel(AecmCore_t* aecm,
|
||||
const WebRtc_UWord16* far_spectrum,
|
||||
WebRtc_Word32* echo_est)
|
||||
{
|
||||
int i;
|
||||
void WebRtcAecm_ResetAdaptiveChannelNeon(AecmCore* aecm) {
|
||||
assert((uintptr_t)(aecm->channelStored) % 16 == 0);
|
||||
assert((uintptr_t)(aecm->channelAdapt16) % 16 == 0);
|
||||
assert((uintptr_t)(aecm->channelAdapt32) % 32 == 0);
|
||||
|
||||
// During startup we store the channel every block.
|
||||
// Recalculate echo estimate.
|
||||
for(i = 0; i < PART_LEN -7; i += 8)
|
||||
{
|
||||
// aecm->channelStored[i] = acem->channelAdapt16[i];
|
||||
// echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i], far_spectrum[i]);
|
||||
__asm__("vld1.16 {d26, d27}, [%0]" : : "r"(&far_spectrum[i]) : "q13");
|
||||
__asm__("vld1.16 {d24, d25}, [%0, :128]" : : "r"(&aecm->channelAdapt16[i]) : "q12");
|
||||
__asm__("vst1.16 {d24, d25}, [%0, :128]" : : "r"(&aecm->channelStored[i]) : "q12");
|
||||
__asm__("vmull.u16 q10, d26, d24" : : : "q12", "q13", "q10");
|
||||
__asm__("vmull.u16 q11, d27, d25" : : : "q12", "q13", "q11");
|
||||
__asm__("vst1.16 {d20, d21, d22, d23}, [%0, :256]" : :
|
||||
"r"(&echo_est[i]) : "q10", "q11");
|
||||
}
|
||||
aecm->channelStored[i] = aecm->channelAdapt16[i];
|
||||
echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i], far_spectrum[i]);
|
||||
// The C code of following optimized code.
|
||||
// for (i = 0; i < PART_LEN1; i++) {
|
||||
// aecm->channelAdapt16[i] = aecm->channelStored[i];
|
||||
// aecm->channelAdapt32[i] = WEBRTC_SPL_LSHIFT_W32(
|
||||
// (int32_t)aecm->channelStored[i], 16);
|
||||
// }
|
||||
|
||||
int16_t* start_stored_p = aecm->channelStored;
|
||||
int16_t* start_adapt16_p = aecm->channelAdapt16;
|
||||
int32_t* start_adapt32_p = aecm->channelAdapt32;
|
||||
const int16_t* end_stored_p = start_stored_p + PART_LEN;
|
||||
|
||||
int16x8_t stored_v;
|
||||
int32x4_t adapt32_v_low, adapt32_v_high;
|
||||
|
||||
while (start_stored_p < end_stored_p) {
|
||||
stored_v = vld1q_s16(start_stored_p);
|
||||
vst1q_s16(start_adapt16_p, stored_v);
|
||||
|
||||
adapt32_v_low = vshll_n_s16(vget_low_s16(stored_v), 16);
|
||||
adapt32_v_high = vshll_n_s16(vget_high_s16(stored_v), 16);
|
||||
|
||||
vst1q_s32(start_adapt32_p, adapt32_v_low);
|
||||
vst1q_s32(start_adapt32_p + 4, adapt32_v_high);
|
||||
|
||||
start_stored_p += 8;
|
||||
start_adapt16_p += 8;
|
||||
start_adapt32_p += 8;
|
||||
}
|
||||
aecm->channelAdapt16[PART_LEN] = aecm->channelStored[PART_LEN];
|
||||
aecm->channelAdapt32[PART_LEN] = (int32_t)aecm->channelStored[PART_LEN] << 16;
|
||||
}
|
||||
|
||||
void WebRtcAecm_ResetAdaptiveChannel(AecmCore_t* aecm)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < PART_LEN -7; i += 8)
|
||||
{
|
||||
// aecm->channelAdapt16[i] = aecm->channelStored[i];
|
||||
// aecm->channelAdapt32[i] = WEBRTC_SPL_LSHIFT_W32((WebRtc_Word32)
|
||||
// aecm->channelStored[i], 16);
|
||||
__asm__("vld1.16 {d24, d25}, [%0, :128]" : :
|
||||
"r"(&aecm->channelStored[i]) : "q12");
|
||||
__asm__("vst1.16 {d24, d25}, [%0, :128]" : :
|
||||
"r"(&aecm->channelAdapt16[i]) : "q12");
|
||||
__asm__("vshll.s16 q10, d24, #16" : : : "q12", "q13", "q10");
|
||||
__asm__("vshll.s16 q11, d25, #16" : : : "q12", "q13", "q11");
|
||||
__asm__("vst1.16 {d20, d21, d22, d23}, [%0, :256]" : :
|
||||
"r"(&aecm->channelAdapt32[i]): "q10", "q11");
|
||||
}
|
||||
aecm->channelAdapt16[i] = aecm->channelStored[i];
|
||||
aecm->channelAdapt32[i] = WEBRTC_SPL_LSHIFT_W32(
|
||||
(WebRtc_Word32)aecm->channelStored[i], 16);
|
||||
}
|
||||
|
||||
#endif // #if defined(WEBRTC_ANDROID) && defined(WEBRTC_ARCH_ARM_NEON)
|
||||
|
87
webrtc/modules/audio_processing/aecm/aecm_defines.h
Normal file
87
webrtc/modules/audio_processing/aecm/aecm_defines.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AECM_AECM_DEFINES_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_AECM_AECM_DEFINES_H_
|
||||
|
||||
#define AECM_DYNAMIC_Q /* Turn on/off dynamic Q-domain. */
|
||||
|
||||
/* Algorithm parameters */
|
||||
#define FRAME_LEN 80 /* Total frame length, 10 ms. */
|
||||
|
||||
#define PART_LEN 64 /* Length of partition. */
|
||||
#define PART_LEN_SHIFT 7 /* Length of (PART_LEN * 2) in base 2. */
|
||||
|
||||
#define PART_LEN1 (PART_LEN + 1) /* Unique fft coefficients. */
|
||||
#define PART_LEN2 (PART_LEN << 1) /* Length of partition * 2. */
|
||||
#define PART_LEN4 (PART_LEN << 2) /* Length of partition * 4. */
|
||||
#define FAR_BUF_LEN PART_LEN4 /* Length of buffers. */
|
||||
#define MAX_DELAY 100
|
||||
|
||||
/* Counter parameters */
|
||||
#define CONV_LEN 512 /* Convergence length used at startup. */
|
||||
#define CONV_LEN2 (CONV_LEN << 1) /* Used at startup. */
|
||||
|
||||
/* Energy parameters */
|
||||
#define MAX_BUF_LEN 64 /* History length of energy signals. */
|
||||
#define FAR_ENERGY_MIN 1025 /* Lowest Far energy level: At least 2 */
|
||||
/* in energy. */
|
||||
#define FAR_ENERGY_DIFF 929 /* Allowed difference between max */
|
||||
/* and min. */
|
||||
#define ENERGY_DEV_OFFSET 0 /* The energy error offset in Q8. */
|
||||
#define ENERGY_DEV_TOL 400 /* The energy estimation tolerance (Q8). */
|
||||
#define FAR_ENERGY_VAD_REGION 230 /* Far VAD tolerance region. */
|
||||
|
||||
/* Stepsize parameters */
|
||||
#define MU_MIN 10 /* Min stepsize 2^-MU_MIN (far end energy */
|
||||
/* dependent). */
|
||||
#define MU_MAX 1 /* Max stepsize 2^-MU_MAX (far end energy */
|
||||
/* dependent). */
|
||||
#define MU_DIFF 9 /* MU_MIN - MU_MAX */
|
||||
|
||||
/* Channel parameters */
|
||||
#define MIN_MSE_COUNT 20 /* Min number of consecutive blocks with enough */
|
||||
/* far end energy to compare channel estimates. */
|
||||
#define MIN_MSE_DIFF 29 /* The ratio between adapted and stored channel to */
|
||||
/* accept a new storage (0.8 in Q-MSE_RESOLUTION). */
|
||||
#define MSE_RESOLUTION 5 /* MSE parameter resolution. */
|
||||
#define RESOLUTION_CHANNEL16 12 /* W16 Channel in Q-RESOLUTION_CHANNEL16. */
|
||||
#define RESOLUTION_CHANNEL32 28 /* W32 Channel in Q-RESOLUTION_CHANNEL. */
|
||||
#define CHANNEL_VAD 16 /* Minimum energy in frequency band */
|
||||
/* to update channel. */
|
||||
|
||||
/* Suppression gain parameters: SUPGAIN parameters in Q-(RESOLUTION_SUPGAIN). */
|
||||
#define RESOLUTION_SUPGAIN 8 /* Channel in Q-(RESOLUTION_SUPGAIN). */
|
||||
#define SUPGAIN_DEFAULT (1 << RESOLUTION_SUPGAIN) /* Default. */
|
||||
#define SUPGAIN_ERROR_PARAM_A 3072 /* Estimation error parameter */
|
||||
/* (Maximum gain) (8 in Q8). */
|
||||
#define SUPGAIN_ERROR_PARAM_B 1536 /* Estimation error parameter */
|
||||
/* (Gain before going down). */
|
||||
#define SUPGAIN_ERROR_PARAM_D SUPGAIN_DEFAULT /* Estimation error parameter */
|
||||
/* (Should be the same as Default) (1 in Q8). */
|
||||
#define SUPGAIN_EPC_DT 200 /* SUPGAIN_ERROR_PARAM_C * ENERGY_DEV_TOL */
|
||||
|
||||
/* Defines for "check delay estimation" */
|
||||
#define CORR_WIDTH 31 /* Number of samples to correlate over. */
|
||||
#define CORR_MAX 16 /* Maximum correlation offset. */
|
||||
#define CORR_MAX_BUF 63
|
||||
#define CORR_DEV 4
|
||||
#define CORR_MAX_LEVEL 20
|
||||
#define CORR_MAX_LOW 4
|
||||
#define CORR_BUF_LEN (CORR_MAX << 1) + 1
|
||||
/* Note that CORR_WIDTH + 2*CORR_MAX <= MAX_BUF_LEN. */
|
||||
|
||||
#define ONE_Q14 (1 << 14)
|
||||
|
||||
/* NLP defines */
|
||||
#define NLP_COMP_LOW 3277 /* 0.2 in Q14 */
|
||||
#define NLP_COMP_HIGH ONE_Q14 /* 1 in Q14 */
|
||||
|
||||
#endif
|
@ -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,22 +8,16 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
#include "webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h"
|
||||
|
||||
#include "echo_control_mobile.h"
|
||||
#include "aecm_core.h"
|
||||
#include "ring_buffer.h"
|
||||
#ifdef AEC_DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifdef MAC_IPHONE_PRINT
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#elif defined ARM_WINM_LOG
|
||||
#include "windows.h"
|
||||
extern HANDLE logFile;
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
#include "webrtc/modules/audio_processing/aecm/aecm_core.h"
|
||||
|
||||
#define BUF_SIZE_FRAMES 50 // buffer size (frames)
|
||||
// Maximum length of resampled signal. Must be an integer multiple of frames
|
||||
@ -31,7 +25,7 @@ extern HANDLE logFile;
|
||||
// The factor of 2 handles wb, and the + 1 is as a safety margin
|
||||
#define MAX_RESAMP_LEN (5 * FRAME_LEN)
|
||||
|
||||
static const int kBufSizeSamp = BUF_SIZE_FRAMES * FRAME_LEN; // buffer size (samples)
|
||||
static const size_t kBufSizeSamp = BUF_SIZE_FRAMES * FRAME_LEN; // buffer size (samples)
|
||||
static const int kSampMsNb = 8; // samples per ms in nb
|
||||
// Target suppression levels for nlp modes
|
||||
// log{0.001, 0.00001, 0.00000001}
|
||||
@ -63,7 +57,7 @@ typedef struct
|
||||
int delayChange;
|
||||
short lastDelayDiff;
|
||||
|
||||
WebRtc_Word16 echoMode;
|
||||
int16_t echoMode;
|
||||
|
||||
#ifdef AEC_DEBUG
|
||||
FILE *bufFile;
|
||||
@ -72,47 +66,37 @@ typedef struct
|
||||
FILE *postCompFile;
|
||||
#endif // AEC_DEBUG
|
||||
// Structures
|
||||
void *farendBuf;
|
||||
RingBuffer *farendBuf;
|
||||
|
||||
int lastError;
|
||||
|
||||
AecmCore_t *aecmCore;
|
||||
} aecmob_t;
|
||||
AecmCore* aecmCore;
|
||||
} AecMobile;
|
||||
|
||||
// Estimates delay to set the position of the farend buffer read pointer
|
||||
// (controlled by knownDelay)
|
||||
static int WebRtcAecm_EstBufDelay(aecmob_t *aecmInst, short msInSndCardBuf);
|
||||
static int WebRtcAecm_EstBufDelay(AecMobile* aecmInst, short msInSndCardBuf);
|
||||
|
||||
// Stuffs the farend buffer if the estimated delay is too large
|
||||
static int WebRtcAecm_DelayComp(aecmob_t *aecmInst);
|
||||
static int WebRtcAecm_DelayComp(AecMobile* aecmInst);
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_Create(void **aecmInst)
|
||||
{
|
||||
aecmob_t *aecm;
|
||||
if (aecmInst == NULL)
|
||||
{
|
||||
return -1;
|
||||
void* WebRtcAecm_Create() {
|
||||
AecMobile* aecm = malloc(sizeof(AecMobile));
|
||||
|
||||
WebRtcSpl_Init();
|
||||
|
||||
aecm->aecmCore = WebRtcAecm_CreateCore();
|
||||
if (!aecm->aecmCore) {
|
||||
WebRtcAecm_Free(aecm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
aecm = malloc(sizeof(aecmob_t));
|
||||
*aecmInst = aecm;
|
||||
if (aecm == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (WebRtcAecm_CreateCore(&aecm->aecmCore) == -1)
|
||||
aecm->farendBuf = WebRtc_CreateBuffer(kBufSizeSamp,
|
||||
sizeof(int16_t));
|
||||
if (!aecm->farendBuf)
|
||||
{
|
||||
WebRtcAecm_Free(aecm);
|
||||
aecm = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (WebRtcApm_CreateBuffer(&aecm->farendBuf, kBufSizeSamp) == -1)
|
||||
{
|
||||
WebRtcAecm_Free(aecm);
|
||||
aecm = NULL;
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
aecm->initFlag = 0;
|
||||
@ -129,16 +113,14 @@ WebRtc_Word32 WebRtcAecm_Create(void **aecmInst)
|
||||
aecm->preCompFile = fopen("preComp.pcm", "wb");
|
||||
aecm->postCompFile = fopen("postComp.pcm", "wb");
|
||||
#endif // AEC_DEBUG
|
||||
return 0;
|
||||
return aecm;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_Free(void *aecmInst)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
void WebRtcAecm_Free(void* aecmInst) {
|
||||
AecMobile* aecm = aecmInst;
|
||||
|
||||
if (aecm == NULL)
|
||||
{
|
||||
return -1;
|
||||
if (aecm == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef AEC_DEBUG
|
||||
@ -153,15 +135,13 @@ WebRtc_Word32 WebRtcAecm_Free(void *aecmInst)
|
||||
fclose(aecm->postCompFile);
|
||||
#endif // AEC_DEBUG
|
||||
WebRtcAecm_FreeCore(aecm->aecmCore);
|
||||
WebRtcApm_FreeBuffer(aecm->farendBuf);
|
||||
WebRtc_FreeBuffer(aecm->farendBuf);
|
||||
free(aecm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_Init(void *aecmInst, WebRtc_Word32 sampFreq)
|
||||
int32_t WebRtcAecm_Init(void *aecmInst, int32_t sampFreq)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
AecMobile* aecm = aecmInst;
|
||||
AecmConfig aecConfig;
|
||||
|
||||
if (aecm == NULL)
|
||||
@ -184,11 +164,7 @@ WebRtc_Word32 WebRtcAecm_Init(void *aecmInst, WebRtc_Word32 sampFreq)
|
||||
}
|
||||
|
||||
// Initialize farend buffer
|
||||
if (WebRtcApm_InitBuffer(aecm->farendBuf) == -1)
|
||||
{
|
||||
aecm->lastError = AECM_UNSPECIFIED_ERROR;
|
||||
return -1;
|
||||
}
|
||||
WebRtc_InitBuffer(aecm->farendBuf);
|
||||
|
||||
aecm->initFlag = kInitCheck; // indicates that initialization has been done
|
||||
|
||||
@ -222,11 +198,11 @@ WebRtc_Word32 WebRtcAecm_Init(void *aecmInst, WebRtc_Word32 sampFreq)
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_BufferFarend(void *aecmInst, const WebRtc_Word16 *farend,
|
||||
WebRtc_Word16 nrOfSamples)
|
||||
int32_t WebRtcAecm_BufferFarend(void *aecmInst, const int16_t *farend,
|
||||
size_t nrOfSamples)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
WebRtc_Word32 retVal = 0;
|
||||
AecMobile* aecm = aecmInst;
|
||||
int32_t retVal = 0;
|
||||
|
||||
if (aecm == NULL)
|
||||
{
|
||||
@ -257,38 +233,25 @@ WebRtc_Word32 WebRtcAecm_BufferFarend(void *aecmInst, const WebRtc_Word16 *faren
|
||||
WebRtcAecm_DelayComp(aecm);
|
||||
}
|
||||
|
||||
WebRtcApm_WriteBuffer(aecm->farendBuf, farend, nrOfSamples);
|
||||
WebRtc_WriteBuffer(aecm->farendBuf, farend, nrOfSamples);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_Process(void *aecmInst, const WebRtc_Word16 *nearendNoisy,
|
||||
const WebRtc_Word16 *nearendClean, WebRtc_Word16 *out,
|
||||
WebRtc_Word16 nrOfSamples, WebRtc_Word16 msInSndCardBuf)
|
||||
int32_t WebRtcAecm_Process(void *aecmInst, const int16_t *nearendNoisy,
|
||||
const int16_t *nearendClean, int16_t *out,
|
||||
size_t nrOfSamples, int16_t msInSndCardBuf)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
WebRtc_Word32 retVal = 0;
|
||||
short i;
|
||||
short farend[FRAME_LEN];
|
||||
AecMobile* aecm = aecmInst;
|
||||
int32_t retVal = 0;
|
||||
size_t i;
|
||||
short nmbrOfFilledBuffers;
|
||||
short nBlocks10ms;
|
||||
short nFrames;
|
||||
size_t nBlocks10ms;
|
||||
size_t nFrames;
|
||||
#ifdef AEC_DEBUG
|
||||
short msInAECBuf;
|
||||
#endif
|
||||
|
||||
#ifdef ARM_WINM_LOG
|
||||
__int64 freq, start, end, diff;
|
||||
unsigned int milliseconds;
|
||||
DWORD temp;
|
||||
#elif defined MAC_IPHONE_PRINT
|
||||
// double endtime = 0, starttime = 0;
|
||||
struct timeval starttime;
|
||||
struct timeval endtime;
|
||||
static long int timeused = 0;
|
||||
static int timecount = 0;
|
||||
#endif
|
||||
|
||||
if (aecm == NULL)
|
||||
{
|
||||
return -1;
|
||||
@ -339,13 +302,17 @@ WebRtc_Word32 WebRtcAecm_Process(void *aecmInst, const WebRtc_Word16 *nearendNoi
|
||||
{
|
||||
if (nearendClean == NULL)
|
||||
{
|
||||
memcpy(out, nearendNoisy, sizeof(short) * nrOfSamples);
|
||||
} else
|
||||
if (out != nearendNoisy)
|
||||
{
|
||||
memcpy(out, nearendNoisy, sizeof(short) * nrOfSamples);
|
||||
}
|
||||
} else if (out != nearendClean)
|
||||
{
|
||||
memcpy(out, nearendClean, sizeof(short) * nrOfSamples);
|
||||
}
|
||||
|
||||
nmbrOfFilledBuffers = WebRtcApm_get_buffer_size(aecm->farendBuf) / FRAME_LEN;
|
||||
nmbrOfFilledBuffers =
|
||||
(short) WebRtc_available_read(aecm->farendBuf) / FRAME_LEN;
|
||||
// The AECM is in the start up mode
|
||||
// AECM is disabled until the soundcard buffer and farend buffers are OK
|
||||
|
||||
@ -407,10 +374,9 @@ WebRtc_Word32 WebRtcAecm_Process(void *aecmInst, const WebRtc_Word16 *nearendNoi
|
||||
aecm->ECstartup = 0; // Enable the AECM
|
||||
} else if (nmbrOfFilledBuffers > aecm->bufSizeStart)
|
||||
{
|
||||
WebRtcApm_FlushBuffer(
|
||||
aecm->farendBuf,
|
||||
WebRtcApm_get_buffer_size(aecm->farendBuf)
|
||||
- aecm->bufSizeStart * FRAME_LEN);
|
||||
WebRtc_MoveReadPtr(aecm->farendBuf,
|
||||
(int) WebRtc_available_read(aecm->farendBuf)
|
||||
- (int) aecm->bufSizeStart * FRAME_LEN);
|
||||
aecm->ECstartup = 0;
|
||||
}
|
||||
}
|
||||
@ -422,20 +388,27 @@ WebRtc_Word32 WebRtcAecm_Process(void *aecmInst, const WebRtc_Word16 *nearendNoi
|
||||
// Note only 1 block supported for nb and 2 blocks for wb
|
||||
for (i = 0; i < nFrames; i++)
|
||||
{
|
||||
nmbrOfFilledBuffers = WebRtcApm_get_buffer_size(aecm->farendBuf) / FRAME_LEN;
|
||||
int16_t farend[FRAME_LEN];
|
||||
const int16_t* farend_ptr = NULL;
|
||||
|
||||
nmbrOfFilledBuffers =
|
||||
(short) WebRtc_available_read(aecm->farendBuf) / FRAME_LEN;
|
||||
|
||||
// Check that there is data in the far end buffer
|
||||
if (nmbrOfFilledBuffers > 0)
|
||||
{
|
||||
// Get the next 80 samples from the farend buffer
|
||||
WebRtcApm_ReadBuffer(aecm->farendBuf, farend, FRAME_LEN);
|
||||
WebRtc_ReadBuffer(aecm->farendBuf, (void**) &farend_ptr, farend,
|
||||
FRAME_LEN);
|
||||
|
||||
// Always store the last frame for use when we run out of data
|
||||
memcpy(&(aecm->farendOld[i][0]), farend, FRAME_LEN * sizeof(short));
|
||||
memcpy(&(aecm->farendOld[i][0]), farend_ptr,
|
||||
FRAME_LEN * sizeof(short));
|
||||
} else
|
||||
{
|
||||
// We have no data so we use the last played frame
|
||||
memcpy(farend, &(aecm->farendOld[i][0]), FRAME_LEN * sizeof(short));
|
||||
farend_ptr = farend;
|
||||
}
|
||||
|
||||
// Call buffer delay estimator when all data is extracted,
|
||||
@ -445,77 +418,23 @@ WebRtc_Word32 WebRtcAecm_Process(void *aecmInst, const WebRtc_Word16 *nearendNoi
|
||||
WebRtcAecm_EstBufDelay(aecm, aecm->msInSndCardBuf);
|
||||
}
|
||||
|
||||
#ifdef ARM_WINM_LOG
|
||||
// measure tick start
|
||||
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&start);
|
||||
#elif defined MAC_IPHONE_PRINT
|
||||
// starttime = clock()/(double)CLOCKS_PER_SEC;
|
||||
gettimeofday(&starttime, NULL);
|
||||
#endif
|
||||
// Call the AECM
|
||||
/*WebRtcAecm_ProcessFrame(aecm->aecmCore, farend, &nearend[FRAME_LEN * i],
|
||||
&out[FRAME_LEN * i], aecm->knownDelay);*/
|
||||
if (nearendClean == NULL)
|
||||
{
|
||||
if (WebRtcAecm_ProcessFrame(aecm->aecmCore,
|
||||
farend,
|
||||
&nearendNoisy[FRAME_LEN * i],
|
||||
NULL,
|
||||
&out[FRAME_LEN * i]) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (WebRtcAecm_ProcessFrame(aecm->aecmCore,
|
||||
farend,
|
||||
&nearendNoisy[FRAME_LEN * i],
|
||||
&nearendClean[FRAME_LEN * i],
|
||||
&out[FRAME_LEN * i]) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ARM_WINM_LOG
|
||||
|
||||
// measure tick end
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&end);
|
||||
|
||||
if(end > start)
|
||||
{
|
||||
diff = ((end - start) * 1000) / (freq/1000);
|
||||
milliseconds = (unsigned int)(diff & 0xffffffff);
|
||||
WriteFile (logFile, &milliseconds, sizeof(unsigned int), &temp, NULL);
|
||||
}
|
||||
#elif defined MAC_IPHONE_PRINT
|
||||
// endtime = clock()/(double)CLOCKS_PER_SEC;
|
||||
// printf("%f\n", endtime - starttime);
|
||||
|
||||
gettimeofday(&endtime, NULL);
|
||||
|
||||
if( endtime.tv_usec > starttime.tv_usec)
|
||||
{
|
||||
timeused += endtime.tv_usec - starttime.tv_usec;
|
||||
} else
|
||||
{
|
||||
timeused += endtime.tv_usec + 1000000 - starttime.tv_usec;
|
||||
}
|
||||
|
||||
if(++timecount == 1000)
|
||||
{
|
||||
timecount = 0;
|
||||
printf("AEC: %ld\n", timeused);
|
||||
timeused = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (WebRtcAecm_ProcessFrame(aecm->aecmCore,
|
||||
farend_ptr,
|
||||
&nearendNoisy[FRAME_LEN * i],
|
||||
(nearendClean
|
||||
? &nearendClean[FRAME_LEN * i]
|
||||
: NULL),
|
||||
&out[FRAME_LEN * i]) == -1)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef AEC_DEBUG
|
||||
msInAECBuf = WebRtcApm_get_buffer_size(aecm->farendBuf) / (kSampMsNb*aecm->aecmCore->mult);
|
||||
msInAECBuf = (short) WebRtc_available_read(aecm->farendBuf) /
|
||||
(kSampMsNb * aecm->aecmCore->mult);
|
||||
fwrite(&msInAECBuf, 2, 1, aecm->bufFile);
|
||||
fwrite(&(aecm->knownDelay), sizeof(aecm->knownDelay), 1, aecm->delayFile);
|
||||
#endif
|
||||
@ -523,9 +442,9 @@ WebRtc_Word32 WebRtcAecm_Process(void *aecmInst, const WebRtc_Word16 *nearendNoi
|
||||
return retVal;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_set_config(void *aecmInst, AecmConfig config)
|
||||
int32_t WebRtcAecm_set_config(void *aecmInst, AecmConfig config)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
AecMobile* aecm = aecmInst;
|
||||
|
||||
if (aecm == NULL)
|
||||
{
|
||||
@ -605,9 +524,9 @@ WebRtc_Word32 WebRtcAecm_set_config(void *aecmInst, AecmConfig config)
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_get_config(void *aecmInst, AecmConfig *config)
|
||||
int32_t WebRtcAecm_get_config(void *aecmInst, AecmConfig *config)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
AecMobile* aecm = aecmInst;
|
||||
|
||||
if (aecm == NULL)
|
||||
{
|
||||
@ -632,17 +551,19 @@ WebRtc_Word32 WebRtcAecm_get_config(void *aecmInst, AecmConfig *config)
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
|
||||
const void* echo_path,
|
||||
size_t size_bytes)
|
||||
int32_t WebRtcAecm_InitEchoPath(void* aecmInst,
|
||||
const void* echo_path,
|
||||
size_t size_bytes)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
const WebRtc_Word16* echo_path_ptr = echo_path;
|
||||
AecMobile* aecm = aecmInst;
|
||||
const int16_t* echo_path_ptr = echo_path;
|
||||
|
||||
if ((aecm == NULL) || (echo_path == NULL))
|
||||
{
|
||||
aecm->lastError = AECM_NULL_POINTER_ERROR;
|
||||
return -1;
|
||||
if (aecmInst == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (echo_path == NULL) {
|
||||
aecm->lastError = AECM_NULL_POINTER_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if (size_bytes != WebRtcAecm_echo_path_size_bytes())
|
||||
{
|
||||
@ -661,17 +582,19 @@ WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst,
|
||||
void* echo_path,
|
||||
size_t size_bytes)
|
||||
int32_t WebRtcAecm_GetEchoPath(void* aecmInst,
|
||||
void* echo_path,
|
||||
size_t size_bytes)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
WebRtc_Word16* echo_path_ptr = echo_path;
|
||||
AecMobile* aecm = aecmInst;
|
||||
int16_t* echo_path_ptr = echo_path;
|
||||
|
||||
if ((aecm == NULL) || (echo_path == NULL))
|
||||
{
|
||||
aecm->lastError = AECM_NULL_POINTER_ERROR;
|
||||
return -1;
|
||||
if (aecmInst == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (echo_path == NULL) {
|
||||
aecm->lastError = AECM_NULL_POINTER_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if (size_bytes != WebRtcAecm_echo_path_size_bytes())
|
||||
{
|
||||
@ -691,31 +614,12 @@ WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst,
|
||||
|
||||
size_t WebRtcAecm_echo_path_size_bytes()
|
||||
{
|
||||
return (PART_LEN1 * sizeof(WebRtc_Word16));
|
||||
return (PART_LEN1 * sizeof(int16_t));
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_get_version(WebRtc_Word8 *versionStr, WebRtc_Word16 len)
|
||||
int32_t WebRtcAecm_get_error_code(void *aecmInst)
|
||||
{
|
||||
const char version[] = "AECM 1.2.0";
|
||||
const short versionLen = (short)strlen(version) + 1; // +1 for null-termination
|
||||
|
||||
if (versionStr == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (versionLen > len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(versionStr, version, versionLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebRtc_Word32 WebRtcAecm_get_error_code(void *aecmInst)
|
||||
{
|
||||
aecmob_t *aecm = aecmInst;
|
||||
AecMobile* aecm = aecmInst;
|
||||
|
||||
if (aecm == NULL)
|
||||
{
|
||||
@ -725,19 +629,18 @@ WebRtc_Word32 WebRtcAecm_get_error_code(void *aecmInst)
|
||||
return aecm->lastError;
|
||||
}
|
||||
|
||||
static int WebRtcAecm_EstBufDelay(aecmob_t *aecm, short msInSndCardBuf)
|
||||
{
|
||||
short delayNew, nSampFar, nSampSndCard;
|
||||
static int WebRtcAecm_EstBufDelay(AecMobile* aecm, short msInSndCardBuf) {
|
||||
short delayNew, nSampSndCard;
|
||||
short nSampFar = (short) WebRtc_available_read(aecm->farendBuf);
|
||||
short diff;
|
||||
|
||||
nSampFar = WebRtcApm_get_buffer_size(aecm->farendBuf);
|
||||
nSampSndCard = msInSndCardBuf * kSampMsNb * aecm->aecmCore->mult;
|
||||
|
||||
delayNew = nSampSndCard - nSampFar;
|
||||
|
||||
if (delayNew < FRAME_LEN)
|
||||
{
|
||||
WebRtcApm_FlushBuffer(aecm->farendBuf, FRAME_LEN);
|
||||
WebRtc_MoveReadPtr(aecm->farendBuf, FRAME_LEN);
|
||||
delayNew += FRAME_LEN;
|
||||
}
|
||||
|
||||
@ -775,12 +678,11 @@ static int WebRtcAecm_EstBufDelay(aecmob_t *aecm, short msInSndCardBuf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int WebRtcAecm_DelayComp(aecmob_t *aecm)
|
||||
{
|
||||
int nSampFar, nSampSndCard, delayNew, nSampAdd;
|
||||
static int WebRtcAecm_DelayComp(AecMobile* aecm) {
|
||||
int nSampFar = (int) WebRtc_available_read(aecm->farendBuf);
|
||||
int nSampSndCard, delayNew, nSampAdd;
|
||||
const int maxStuffSamp = 10 * FRAME_LEN;
|
||||
|
||||
nSampFar = WebRtcApm_get_buffer_size(aecm->farendBuf);
|
||||
nSampSndCard = aecm->msInSndCardBuf * kSampMsNb * aecm->aecmCore->mult;
|
||||
delayNew = nSampSndCard - nSampFar;
|
||||
|
||||
@ -792,7 +694,7 @@ static int WebRtcAecm_DelayComp(aecmob_t *aecm)
|
||||
FRAME_LEN));
|
||||
nSampAdd = WEBRTC_SPL_MIN(nSampAdd, maxStuffSamp);
|
||||
|
||||
WebRtcApm_StuffBuffer(aecm->farendBuf, nSampAdd);
|
||||
WebRtc_MoveReadPtr(aecm->farendBuf, -nSampAdd);
|
||||
aecm->delayChange = 1; // the delay needs to be updated
|
||||
}
|
||||
|
||||
|
@ -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,10 +8,12 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AECM_MAIN_INTERFACE_ECHO_CONTROL_MOBILE_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_AECM_MAIN_INTERFACE_ECHO_CONTROL_MOBILE_H_
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AECM_INCLUDE_ECHO_CONTROL_MOBILE_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_AECM_INCLUDE_ECHO_CONTROL_MOBILE_H_
|
||||
|
||||
#include "typedefs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
enum {
|
||||
AecmFalse = 0,
|
||||
@ -29,8 +31,8 @@ enum {
|
||||
#define AECM_BAD_PARAMETER_WARNING 12100
|
||||
|
||||
typedef struct {
|
||||
WebRtc_Word16 cngMode; // AECM_FALSE, AECM_TRUE (default)
|
||||
WebRtc_Word16 echoMode; // 0, 1, 2, 3 (default), 4
|
||||
int16_t cngMode; // AECM_FALSE, AECM_TRUE (default)
|
||||
int16_t echoMode; // 0, 1, 2, 3 (default), 4
|
||||
} AecmConfig;
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -40,133 +42,116 @@ extern "C" {
|
||||
/*
|
||||
* Allocates the memory needed by the AECM. The memory needs to be
|
||||
* initialized separately using the WebRtcAecm_Init() function.
|
||||
*
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* void **aecmInst Pointer to the AECM instance to be
|
||||
* created and initialized
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* -1: error
|
||||
* Returns a pointer to the instance and a nullptr at failure.
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_Create(void **aecmInst);
|
||||
void* WebRtcAecm_Create();
|
||||
|
||||
/*
|
||||
* This function releases the memory allocated by WebRtcAecm_Create()
|
||||
*
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* void *aecmInst Pointer to the AECM instance
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* -1: error
|
||||
* void* aecmInst Pointer to the AECM instance
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_Free(void *aecmInst);
|
||||
void WebRtcAecm_Free(void* aecmInst);
|
||||
|
||||
/*
|
||||
* Initializes an AECM instance.
|
||||
*
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* void *aecmInst Pointer to the AECM instance
|
||||
* WebRtc_Word32 sampFreq Sampling frequency of data
|
||||
* void* aecmInst Pointer to the AECM instance
|
||||
* int32_t sampFreq Sampling frequency of data
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* int32_t return 0: OK
|
||||
* -1: error
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_Init(void* aecmInst,
|
||||
WebRtc_Word32 sampFreq);
|
||||
int32_t WebRtcAecm_Init(void* aecmInst, int32_t sampFreq);
|
||||
|
||||
/*
|
||||
* Inserts an 80 or 160 sample block of data into the farend buffer.
|
||||
*
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* void *aecmInst Pointer to the AECM instance
|
||||
* WebRtc_Word16 *farend In buffer containing one frame of
|
||||
* void* aecmInst Pointer to the AECM instance
|
||||
* int16_t* farend In buffer containing one frame of
|
||||
* farend signal
|
||||
* WebRtc_Word16 nrOfSamples Number of samples in farend buffer
|
||||
* int16_t nrOfSamples Number of samples in farend buffer
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* int32_t return 0: OK
|
||||
* -1: error
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_BufferFarend(void* aecmInst,
|
||||
const WebRtc_Word16* farend,
|
||||
WebRtc_Word16 nrOfSamples);
|
||||
int32_t WebRtcAecm_BufferFarend(void* aecmInst,
|
||||
const int16_t* farend,
|
||||
size_t nrOfSamples);
|
||||
|
||||
/*
|
||||
* Runs the AECM on an 80 or 160 sample blocks of data.
|
||||
*
|
||||
* Inputs Description
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* void *aecmInst Pointer to the AECM instance
|
||||
* WebRtc_Word16 *nearendNoisy In buffer containing one frame of
|
||||
* void* aecmInst Pointer to the AECM instance
|
||||
* int16_t* nearendNoisy In buffer containing one frame of
|
||||
* reference nearend+echo signal. If
|
||||
* noise reduction is active, provide
|
||||
* the noisy signal here.
|
||||
* WebRtc_Word16 *nearendClean In buffer containing one frame of
|
||||
* int16_t* nearendClean In buffer containing one frame of
|
||||
* nearend+echo signal. If noise
|
||||
* reduction is active, provide the
|
||||
* clean signal here. Otherwise pass a
|
||||
* NULL pointer.
|
||||
* WebRtc_Word16 nrOfSamples Number of samples in nearend buffer
|
||||
* WebRtc_Word16 msInSndCardBuf Delay estimate for sound card and
|
||||
* int16_t nrOfSamples Number of samples in nearend buffer
|
||||
* int16_t msInSndCardBuf Delay estimate for sound card and
|
||||
* system buffers
|
||||
*
|
||||
* Outputs Description
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word16 *out Out buffer, one frame of processed nearend
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* -1: error
|
||||
* int16_t* out Out buffer, one frame of processed nearend
|
||||
* int32_t return 0: OK
|
||||
* -1: error
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_Process(void* aecmInst,
|
||||
const WebRtc_Word16* nearendNoisy,
|
||||
const WebRtc_Word16* nearendClean,
|
||||
WebRtc_Word16* out,
|
||||
WebRtc_Word16 nrOfSamples,
|
||||
WebRtc_Word16 msInSndCardBuf);
|
||||
int32_t WebRtcAecm_Process(void* aecmInst,
|
||||
const int16_t* nearendNoisy,
|
||||
const int16_t* nearendClean,
|
||||
int16_t* out,
|
||||
size_t nrOfSamples,
|
||||
int16_t msInSndCardBuf);
|
||||
|
||||
/*
|
||||
* This function enables the user to set certain parameters on-the-fly
|
||||
*
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* void *aecmInst Pointer to the AECM instance
|
||||
* AecmConfig config Config instance that contains all
|
||||
* void* aecmInst Pointer to the AECM instance
|
||||
* AecmConfig config Config instance that contains all
|
||||
* properties to be set
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* int32_t return 0: OK
|
||||
* -1: error
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_set_config(void* aecmInst,
|
||||
AecmConfig config);
|
||||
int32_t WebRtcAecm_set_config(void* aecmInst, AecmConfig config);
|
||||
|
||||
/*
|
||||
* This function enables the user to set certain parameters on-the-fly
|
||||
*
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* void *aecmInst Pointer to the AECM instance
|
||||
* void* aecmInst Pointer to the AECM instance
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* AecmConfig *config Pointer to the config instance that
|
||||
* AecmConfig* config Pointer to the config instance that
|
||||
* all properties will be written to
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* int32_t return 0: OK
|
||||
* -1: error
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_get_config(void *aecmInst,
|
||||
AecmConfig *config);
|
||||
int32_t WebRtcAecm_get_config(void *aecmInst, AecmConfig *config);
|
||||
|
||||
/*
|
||||
* This function enables the user to set the echo path on-the-fly.
|
||||
@ -179,12 +164,12 @@ WebRtc_Word32 WebRtcAecm_get_config(void *aecmInst,
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* int32_t return 0: OK
|
||||
* -1: error
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
|
||||
const void* echo_path,
|
||||
size_t size_bytes);
|
||||
int32_t WebRtcAecm_InitEchoPath(void* aecmInst,
|
||||
const void* echo_path,
|
||||
size_t size_bytes);
|
||||
|
||||
/*
|
||||
* This function enables the user to get the currently used echo path
|
||||
@ -198,19 +183,19 @@ WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* int32_t return 0: OK
|
||||
* -1: error
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst,
|
||||
void* echo_path,
|
||||
size_t size_bytes);
|
||||
int32_t WebRtcAecm_GetEchoPath(void* aecmInst,
|
||||
void* echo_path,
|
||||
size_t size_bytes);
|
||||
|
||||
/*
|
||||
* This function enables the user to get the echo path size in bytes
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* size_t return : size in bytes
|
||||
* size_t return Size in bytes
|
||||
*/
|
||||
size_t WebRtcAecm_echo_path_size_bytes();
|
||||
|
||||
@ -219,32 +204,15 @@ size_t WebRtcAecm_echo_path_size_bytes();
|
||||
*
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* void *aecmInst Pointer to the AECM instance
|
||||
* void* aecmInst Pointer to the AECM instance
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word32 return 11000-11100: error code
|
||||
* int32_t return 11000-11100: error code
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_get_error_code(void *aecmInst);
|
||||
|
||||
/*
|
||||
* Gets a version string
|
||||
*
|
||||
* Inputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* char *versionStr Pointer to a string array
|
||||
* WebRtc_Word16 len The maximum length of the string
|
||||
*
|
||||
* Outputs Description
|
||||
* -------------------------------------------------------------------
|
||||
* WebRtc_Word8 *versionStr Pointer to a string array
|
||||
* WebRtc_Word32 return 0: OK
|
||||
* -1: error
|
||||
*/
|
||||
WebRtc_Word32 WebRtcAecm_get_version(WebRtc_Word8 *versionStr,
|
||||
WebRtc_Word16 len);
|
||||
int32_t WebRtcAecm_get_error_code(void *aecmInst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* WEBRTC_MODULES_AUDIO_PROCESSING_AECM_MAIN_INTERFACE_ECHO_CONTROL_MOBILE_H_ */
|
||||
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AECM_INCLUDE_ECHO_CONTROL_MOBILE_H_
|
Reference in New Issue
Block a user