aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_processing/aec/echo_cancellation.c
diff options
context:
space:
mode:
authorandrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-10-08 23:41:42 +0000
committerandrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-10-08 23:41:42 +0000
commit13b2d4659380675871e2a232bd3a0b8dbbc35a7a (patch)
tree41f0123299b6b51e2e01ee2a31a35acd17820e36 /webrtc/modules/audio_processing/aec/echo_cancellation.c
parentd241718e17d3c696d3d64b9c37b74e27a4ce0f21 (diff)
downloadwebrtc-13b2d4659380675871e2a232bd3a0b8dbbc35a7a.tar.gz
clang-format audio_processing/aec/*
TBR=bjornv TESTED=trybots Review URL: https://webrtc-codereview.appspot.com/2373004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4944 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'webrtc/modules/audio_processing/aec/echo_cancellation.c')
-rw-r--r--webrtc/modules/audio_processing/aec/echo_cancellation.c698
1 files changed, 364 insertions, 334 deletions
diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation.c b/webrtc/modules/audio_processing/aec/echo_cancellation.c
index 57208cd907..cf95e43b2f 100644
--- a/webrtc/modules/audio_processing/aec/echo_cancellation.c
+++ b/webrtc/modules/audio_processing/aec/echo_cancellation.c
@@ -90,7 +90,7 @@ static const int kMaxTrustedDelayMs = 500;
#define MAX_RESAMP_LEN (5 * FRAME_LEN)
static const int kMaxBufSizeStart = 62; // In partitions
-static const int sampMsNb = 8; // samples per ms in nb
+static const int sampMsNb = 8; // samples per ms in nb
static const int initCheck = 42;
#ifdef WEBRTC_AEC_DEBUG_DUMP
@@ -99,334 +99,351 @@ int webrtc_aec_instance_count = 0;
// Estimates delay to set the position of the far-end buffer read pointer
// (controlled by knownDelay)
-static void EstBufDelayNormal(aecpc_t *aecInst);
-static void EstBufDelayExtended(aecpc_t *aecInst);
-static int ProcessNormal(aecpc_t* self, const int16_t* near,
- const int16_t* near_high, int16_t* out, int16_t* out_high,
- int16_t num_samples, int16_t reported_delay_ms, int32_t skew);
-static void ProcessExtended(aecpc_t* self, const int16_t* near,
- const int16_t* near_high, int16_t* out, int16_t* out_high,
- int16_t num_samples, int16_t reported_delay_ms, int32_t skew);
-
-int32_t WebRtcAec_Create(void **aecInst)
-{
- aecpc_t *aecpc;
- if (aecInst == NULL) {
- return -1;
- }
+static void EstBufDelayNormal(aecpc_t* aecInst);
+static void EstBufDelayExtended(aecpc_t* aecInst);
+static int ProcessNormal(aecpc_t* self,
+ const int16_t* near,
+ const int16_t* near_high,
+ int16_t* out,
+ int16_t* out_high,
+ int16_t num_samples,
+ int16_t reported_delay_ms,
+ int32_t skew);
+static void ProcessExtended(aecpc_t* self,
+ const int16_t* near,
+ const int16_t* near_high,
+ int16_t* out,
+ int16_t* out_high,
+ int16_t num_samples,
+ int16_t reported_delay_ms,
+ int32_t skew);
+
+int32_t WebRtcAec_Create(void** aecInst) {
+ aecpc_t* aecpc;
+ if (aecInst == NULL) {
+ return -1;
+ }
- aecpc = malloc(sizeof(aecpc_t));
- *aecInst = aecpc;
- if (aecpc == NULL) {
- return -1;
- }
+ aecpc = malloc(sizeof(aecpc_t));
+ *aecInst = aecpc;
+ if (aecpc == NULL) {
+ return -1;
+ }
- if (WebRtcAec_CreateAec(&aecpc->aec) == -1) {
- WebRtcAec_Free(aecpc);
- aecpc = NULL;
- return -1;
- }
+ if (WebRtcAec_CreateAec(&aecpc->aec) == -1) {
+ WebRtcAec_Free(aecpc);
+ aecpc = NULL;
+ return -1;
+ }
- if (WebRtcAec_CreateResampler(&aecpc->resampler) == -1) {
- WebRtcAec_Free(aecpc);
- aecpc = NULL;
- return -1;
- }
- // Create far-end pre-buffer. The buffer size has to be large enough for
- // largest possible drift compensation (kResamplerBufferSize) + "almost" an
- // FFT buffer (PART_LEN2 - 1).
- aecpc->far_pre_buf = WebRtc_CreateBuffer(PART_LEN2 + kResamplerBufferSize,
- sizeof(float));
- if (!aecpc->far_pre_buf) {
- WebRtcAec_Free(aecpc);
- aecpc = NULL;
- return -1;
- }
+ if (WebRtcAec_CreateResampler(&aecpc->resampler) == -1) {
+ WebRtcAec_Free(aecpc);
+ aecpc = NULL;
+ return -1;
+ }
+ // Create far-end pre-buffer. The buffer size has to be large enough for
+ // largest possible drift compensation (kResamplerBufferSize) + "almost" an
+ // FFT buffer (PART_LEN2 - 1).
+ aecpc->far_pre_buf =
+ WebRtc_CreateBuffer(PART_LEN2 + kResamplerBufferSize, sizeof(float));
+ if (!aecpc->far_pre_buf) {
+ WebRtcAec_Free(aecpc);
+ aecpc = NULL;
+ return -1;
+ }
- aecpc->initFlag = 0;
- aecpc->lastError = 0;
+ aecpc->initFlag = 0;
+ aecpc->lastError = 0;
#ifdef WEBRTC_AEC_DEBUG_DUMP
- aecpc->far_pre_buf_s16 = WebRtc_CreateBuffer(
- PART_LEN2 + kResamplerBufferSize, sizeof(int16_t));
- if (!aecpc->far_pre_buf_s16) {
- WebRtcAec_Free(aecpc);
- aecpc = NULL;
- return -1;
- }
- {
- char filename[64];
- sprintf(filename, "aec_buf%d.dat", webrtc_aec_instance_count);
- aecpc->bufFile = fopen(filename, "wb");
- sprintf(filename, "aec_skew%d.dat", webrtc_aec_instance_count);
- aecpc->skewFile = fopen(filename, "wb");
- sprintf(filename, "aec_delay%d.dat", webrtc_aec_instance_count);
- aecpc->delayFile = fopen(filename, "wb");
- webrtc_aec_instance_count++;
- }
+ aecpc->far_pre_buf_s16 =
+ WebRtc_CreateBuffer(PART_LEN2 + kResamplerBufferSize, sizeof(int16_t));
+ if (!aecpc->far_pre_buf_s16) {
+ WebRtcAec_Free(aecpc);
+ aecpc = NULL;
+ return -1;
+ }
+ {
+ char filename[64];
+ sprintf(filename, "aec_buf%d.dat", webrtc_aec_instance_count);
+ aecpc->bufFile = fopen(filename, "wb");
+ sprintf(filename, "aec_skew%d.dat", webrtc_aec_instance_count);
+ aecpc->skewFile = fopen(filename, "wb");
+ sprintf(filename, "aec_delay%d.dat", webrtc_aec_instance_count);
+ aecpc->delayFile = fopen(filename, "wb");
+ webrtc_aec_instance_count++;
+ }
#endif
- return 0;
+ return 0;
}
-int32_t WebRtcAec_Free(void *aecInst)
-{
- aecpc_t *aecpc = aecInst;
+int32_t WebRtcAec_Free(void* aecInst) {
+ aecpc_t* aecpc = aecInst;
- if (aecpc == NULL) {
- return -1;
- }
+ if (aecpc == NULL) {
+ return -1;
+ }
- WebRtc_FreeBuffer(aecpc->far_pre_buf);
+ WebRtc_FreeBuffer(aecpc->far_pre_buf);
#ifdef WEBRTC_AEC_DEBUG_DUMP
- WebRtc_FreeBuffer(aecpc->far_pre_buf_s16);
- fclose(aecpc->bufFile);
- fclose(aecpc->skewFile);
- fclose(aecpc->delayFile);
+ WebRtc_FreeBuffer(aecpc->far_pre_buf_s16);
+ fclose(aecpc->bufFile);
+ fclose(aecpc->skewFile);
+ fclose(aecpc->delayFile);
#endif
- WebRtcAec_FreeAec(aecpc->aec);
- WebRtcAec_FreeResampler(aecpc->resampler);
- free(aecpc);
+ WebRtcAec_FreeAec(aecpc->aec);
+ WebRtcAec_FreeResampler(aecpc->resampler);
+ free(aecpc);
- return 0;
+ return 0;
}
-int32_t WebRtcAec_Init(void *aecInst, int32_t sampFreq, int32_t scSampFreq)
-{
- aecpc_t *aecpc = aecInst;
- AecConfig aecConfig;
-
- if (sampFreq != 8000 && sampFreq != 16000 && sampFreq != 32000) {
- aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
- return -1;
- }
- aecpc->sampFreq = sampFreq;
+int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) {
+ aecpc_t* aecpc = aecInst;
+ AecConfig aecConfig;
- if (scSampFreq < 1 || scSampFreq > 96000) {
- aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
- return -1;
- }
- aecpc->scSampFreq = scSampFreq;
-
- // Initialize echo canceller core
- if (WebRtcAec_InitAec(aecpc->aec, aecpc->sampFreq) == -1) {
- aecpc->lastError = AEC_UNSPECIFIED_ERROR;
- return -1;
- }
-
- if (WebRtcAec_InitResampler(aecpc->resampler, aecpc->scSampFreq) == -1) {
- aecpc->lastError = AEC_UNSPECIFIED_ERROR;
- return -1;
- }
-
- if (WebRtc_InitBuffer(aecpc->far_pre_buf) == -1) {
- aecpc->lastError = AEC_UNSPECIFIED_ERROR;
- return -1;
- }
- WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN); // Start overlap.
-
- aecpc->initFlag = initCheck; // indicates that initialization has been done
+ if (sampFreq != 8000 && sampFreq != 16000 && sampFreq != 32000) {
+ aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
+ return -1;
+ }
+ aecpc->sampFreq = sampFreq;
- if (aecpc->sampFreq == 32000) {
- aecpc->splitSampFreq = 16000;
- }
- else {
- aecpc->splitSampFreq = sampFreq;
- }
+ if (scSampFreq < 1 || scSampFreq > 96000) {
+ aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
+ return -1;
+ }
+ aecpc->scSampFreq = scSampFreq;
- aecpc->delayCtr = 0;
- aecpc->sampFactor = (aecpc->scSampFreq * 1.0f) / aecpc->splitSampFreq;
- // Sampling frequency multiplier (SWB is processed as 160 frame size).
- aecpc->rate_factor = aecpc->splitSampFreq / 8000;
-
- aecpc->sum = 0;
- aecpc->counter = 0;
- aecpc->checkBuffSize = 1;
- aecpc->firstVal = 0;
-
- aecpc->startup_phase = 1;
- aecpc->bufSizeStart = 0;
- aecpc->checkBufSizeCtr = 0;
- aecpc->msInSndCardBuf = 0;
- aecpc->filtDelay = -1; // -1 indicates an initialized state.
- aecpc->timeForDelayChange = 0;
- aecpc->knownDelay = 0;
- aecpc->lastDelayDiff = 0;
+ // Initialize echo canceller core
+ if (WebRtcAec_InitAec(aecpc->aec, aecpc->sampFreq) == -1) {
+ aecpc->lastError = AEC_UNSPECIFIED_ERROR;
+ return -1;
+ }
- aecpc->skewFrCtr = 0;
- aecpc->resample = kAecFalse;
- aecpc->highSkewCtr = 0;
- aecpc->skew = 0;
+ if (WebRtcAec_InitResampler(aecpc->resampler, aecpc->scSampFreq) == -1) {
+ aecpc->lastError = AEC_UNSPECIFIED_ERROR;
+ return -1;
+ }
- aecpc->farend_started = 0;
+ if (WebRtc_InitBuffer(aecpc->far_pre_buf) == -1) {
+ aecpc->lastError = AEC_UNSPECIFIED_ERROR;
+ return -1;
+ }
+ WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN); // Start overlap.
- // Default settings.
- aecConfig.nlpMode = kAecNlpModerate;
- aecConfig.skewMode = kAecFalse;
- aecConfig.metricsMode = kAecFalse;
- aecConfig.delay_logging = kAecFalse;
+ aecpc->initFlag = initCheck; // indicates that initialization has been done
- if (WebRtcAec_set_config(aecpc, aecConfig) == -1) {
- aecpc->lastError = AEC_UNSPECIFIED_ERROR;
- return -1;
- }
+ if (aecpc->sampFreq == 32000) {
+ aecpc->splitSampFreq = 16000;
+ } else {
+ aecpc->splitSampFreq = sampFreq;
+ }
+
+ aecpc->delayCtr = 0;
+ aecpc->sampFactor = (aecpc->scSampFreq * 1.0f) / aecpc->splitSampFreq;
+ // Sampling frequency multiplier (SWB is processed as 160 frame size).
+ aecpc->rate_factor = aecpc->splitSampFreq / 8000;
+
+ aecpc->sum = 0;
+ aecpc->counter = 0;
+ aecpc->checkBuffSize = 1;
+ aecpc->firstVal = 0;
+
+ aecpc->startup_phase = 1;
+ aecpc->bufSizeStart = 0;
+ aecpc->checkBufSizeCtr = 0;
+ aecpc->msInSndCardBuf = 0;
+ aecpc->filtDelay = -1; // -1 indicates an initialized state.
+ aecpc->timeForDelayChange = 0;
+ aecpc->knownDelay = 0;
+ aecpc->lastDelayDiff = 0;
+
+ aecpc->skewFrCtr = 0;
+ aecpc->resample = kAecFalse;
+ aecpc->highSkewCtr = 0;
+ aecpc->skew = 0;
+
+ aecpc->farend_started = 0;
+
+ // Default settings.
+ aecConfig.nlpMode = kAecNlpModerate;
+ aecConfig.skewMode = kAecFalse;
+ aecConfig.metricsMode = kAecFalse;
+ aecConfig.delay_logging = kAecFalse;
+
+ if (WebRtcAec_set_config(aecpc, aecConfig) == -1) {
+ aecpc->lastError = AEC_UNSPECIFIED_ERROR;
+ return -1;
+ }
#ifdef WEBRTC_AEC_DEBUG_DUMP
- if (WebRtc_InitBuffer(aecpc->far_pre_buf_s16) == -1) {
- aecpc->lastError = AEC_UNSPECIFIED_ERROR;
- return -1;
- }
- WebRtc_MoveReadPtr(aecpc->far_pre_buf_s16, -PART_LEN); // Start overlap.
+ if (WebRtc_InitBuffer(aecpc->far_pre_buf_s16) == -1) {
+ aecpc->lastError = AEC_UNSPECIFIED_ERROR;
+ return -1;
+ }
+ WebRtc_MoveReadPtr(aecpc->far_pre_buf_s16, -PART_LEN); // Start overlap.
#endif
- return 0;
+ return 0;
}
// only buffer L band for farend
-int32_t WebRtcAec_BufferFarend(void *aecInst, const int16_t *farend,
- int16_t nrOfSamples)
-{
- aecpc_t *aecpc = aecInst;
- int32_t retVal = 0;
- int newNrOfSamples = (int) nrOfSamples;
- short newFarend[MAX_RESAMP_LEN];
- const int16_t* farend_ptr = farend;
- float tmp_farend[MAX_RESAMP_LEN];
- const float* farend_float = tmp_farend;
- float skew;
- int i = 0;
-
- if (farend == NULL) {
- aecpc->lastError = AEC_NULL_POINTER_ERROR;
- return -1;
- }
+int32_t WebRtcAec_BufferFarend(void* aecInst,
+ const int16_t* farend,
+ int16_t nrOfSamples) {
+ aecpc_t* aecpc = aecInst;
+ int32_t retVal = 0;
+ int newNrOfSamples = (int)nrOfSamples;
+ short newFarend[MAX_RESAMP_LEN];
+ const int16_t* farend_ptr = farend;
+ float tmp_farend[MAX_RESAMP_LEN];
+ const float* farend_float = tmp_farend;
+ float skew;
+ int i = 0;
+
+ if (farend == NULL) {
+ aecpc->lastError = AEC_NULL_POINTER_ERROR;
+ return -1;
+ }
- if (aecpc->initFlag != initCheck) {
- aecpc->lastError = AEC_UNINITIALIZED_ERROR;
- return -1;
- }
+ if (aecpc->initFlag != initCheck) {
+ aecpc->lastError = AEC_UNINITIALIZED_ERROR;
+ return -1;
+ }
- // number of samples == 160 for SWB input
- if (nrOfSamples != 80 && nrOfSamples != 160) {
- aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
- return -1;
- }
+ // number of samples == 160 for SWB input
+ if (nrOfSamples != 80 && nrOfSamples != 160) {
+ aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
+ return -1;
+ }
- skew = aecpc->skew;
+ skew = aecpc->skew;
- if (aecpc->skewMode == kAecTrue && aecpc->resample == kAecTrue) {
- // Resample and get a new number of samples
- WebRtcAec_ResampleLinear(aecpc->resampler, farend, nrOfSamples, skew,
- newFarend, &newNrOfSamples);
- farend_ptr = (const int16_t*) newFarend;
- }
+ if (aecpc->skewMode == kAecTrue && aecpc->resample == kAecTrue) {
+ // Resample and get a new number of samples
+ WebRtcAec_ResampleLinear(aecpc->resampler,
+ farend,
+ nrOfSamples,
+ skew,
+ newFarend,
+ &newNrOfSamples);
+ farend_ptr = (const int16_t*)newFarend;
+ }
- aecpc->farend_started = 1;
- WebRtcAec_SetSystemDelay(aecpc->aec, WebRtcAec_system_delay(aecpc->aec) +
- newNrOfSamples);
+ aecpc->farend_started = 1;
+ WebRtcAec_SetSystemDelay(aecpc->aec,
+ WebRtcAec_system_delay(aecpc->aec) + newNrOfSamples);
#ifdef WEBRTC_AEC_DEBUG_DUMP
- WebRtc_WriteBuffer(aecpc->far_pre_buf_s16, farend_ptr,
- (size_t) newNrOfSamples);
+ WebRtc_WriteBuffer(
+ aecpc->far_pre_buf_s16, farend_ptr, (size_t)newNrOfSamples);
#endif
- // Cast to float and write the time-domain data to |far_pre_buf|.
- for (i = 0; i < newNrOfSamples; i++) {
- tmp_farend[i] = (float) farend_ptr[i];
- }
- WebRtc_WriteBuffer(aecpc->far_pre_buf, farend_float,
- (size_t) newNrOfSamples);
+ // Cast to float and write the time-domain data to |far_pre_buf|.
+ for (i = 0; i < newNrOfSamples; i++) {
+ tmp_farend[i] = (float)farend_ptr[i];
+ }
+ WebRtc_WriteBuffer(aecpc->far_pre_buf, farend_float, (size_t)newNrOfSamples);
- // Transform to frequency domain if we have enough data.
- while (WebRtc_available_read(aecpc->far_pre_buf) >= PART_LEN2) {
- // We have enough data to pass to the FFT, hence read PART_LEN2 samples.
- WebRtc_ReadBuffer(aecpc->far_pre_buf, (void**) &farend_float, tmp_farend,
- PART_LEN2);
+ // Transform to frequency domain if we have enough data.
+ while (WebRtc_available_read(aecpc->far_pre_buf) >= PART_LEN2) {
+ // We have enough data to pass to the FFT, hence read PART_LEN2 samples.
+ WebRtc_ReadBuffer(
+ aecpc->far_pre_buf, (void**)&farend_float, tmp_farend, PART_LEN2);
- WebRtcAec_BufferFarendPartition(aecpc->aec, farend_float);
+ WebRtcAec_BufferFarendPartition(aecpc->aec, farend_float);
- // Rewind |far_pre_buf| PART_LEN samples for overlap before continuing.
- WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN);
+ // Rewind |far_pre_buf| PART_LEN samples for overlap before continuing.
+ WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN);
#ifdef WEBRTC_AEC_DEBUG_DUMP
- WebRtc_ReadBuffer(aecpc->far_pre_buf_s16, (void**) &farend_ptr, newFarend,
- PART_LEN2);
- WebRtc_WriteBuffer(WebRtcAec_far_time_buf(aecpc->aec),
- &farend_ptr[PART_LEN], 1);
- WebRtc_MoveReadPtr(aecpc->far_pre_buf_s16, -PART_LEN);
+ WebRtc_ReadBuffer(
+ aecpc->far_pre_buf_s16, (void**)&farend_ptr, newFarend, PART_LEN2);
+ WebRtc_WriteBuffer(
+ WebRtcAec_far_time_buf(aecpc->aec), &farend_ptr[PART_LEN], 1);
+ WebRtc_MoveReadPtr(aecpc->far_pre_buf_s16, -PART_LEN);
#endif
- }
+ }
- return retVal;
+ return retVal;
}
-int32_t WebRtcAec_Process(void *aecInst, const int16_t *nearend,
- const int16_t *nearendH, int16_t *out, int16_t *outH,
- int16_t nrOfSamples, int16_t msInSndCardBuf,
- int32_t skew)
-{
- aecpc_t *aecpc = aecInst;
- int32_t retVal = 0;
- if (nearend == NULL) {
- aecpc->lastError = AEC_NULL_POINTER_ERROR;
- return -1;
- }
+int32_t WebRtcAec_Process(void* aecInst,
+ const int16_t* nearend,
+ const int16_t* nearendH,
+ int16_t* out,
+ int16_t* outH,
+ int16_t nrOfSamples,
+ int16_t msInSndCardBuf,
+ int32_t skew) {
+ aecpc_t* aecpc = aecInst;
+ int32_t retVal = 0;
+ if (nearend == NULL) {
+ aecpc->lastError = AEC_NULL_POINTER_ERROR;
+ return -1;
+ }
- if (out == NULL) {
- aecpc->lastError = AEC_NULL_POINTER_ERROR;
- return -1;
- }
+ if (out == NULL) {
+ aecpc->lastError = AEC_NULL_POINTER_ERROR;
+ return -1;
+ }
- if (aecpc->initFlag != initCheck) {
- aecpc->lastError = AEC_UNINITIALIZED_ERROR;
- return -1;
- }
+ if (aecpc->initFlag != initCheck) {
+ aecpc->lastError = AEC_UNINITIALIZED_ERROR;
+ return -1;
+ }
- // number of samples == 160 for SWB input
- if (nrOfSamples != 80 && nrOfSamples != 160) {
- aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
- return -1;
- }
+ // number of samples == 160 for SWB input
+ if (nrOfSamples != 80 && nrOfSamples != 160) {
+ aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
+ return -1;
+ }
- // Check for valid pointers based on sampling rate
- if (aecpc->sampFreq == 32000 && nearendH == NULL) {
- aecpc->lastError = AEC_NULL_POINTER_ERROR;
- return -1;
- }
+ // Check for valid pointers based on sampling rate
+ if (aecpc->sampFreq == 32000 && nearendH == NULL) {
+ aecpc->lastError = AEC_NULL_POINTER_ERROR;
+ return -1;
+ }
- if (msInSndCardBuf < 0) {
- msInSndCardBuf = 0;
- aecpc->lastError = AEC_BAD_PARAMETER_WARNING;
- retVal = -1;
- }
- else if (msInSndCardBuf > kMaxTrustedDelayMs) {
- // The clamping is now done in ProcessExtended/Normal().
- aecpc->lastError = AEC_BAD_PARAMETER_WARNING;
- retVal = -1;
- }
+ if (msInSndCardBuf < 0) {
+ msInSndCardBuf = 0;
+ aecpc->lastError = AEC_BAD_PARAMETER_WARNING;
+ retVal = -1;
+ } else if (msInSndCardBuf > kMaxTrustedDelayMs) {
+ // The clamping is now done in ProcessExtended/Normal().
+ aecpc->lastError = AEC_BAD_PARAMETER_WARNING;
+ retVal = -1;
+ }
- // This returns the value of aec->extended_filter_enabled.
- if (WebRtcAec_delay_correction_enabled(aecpc->aec)) {
- ProcessExtended(aecpc, nearend, nearendH, out, outH, nrOfSamples,
- msInSndCardBuf, skew);
- } else {
- if (ProcessNormal(aecpc, nearend, nearendH, out, outH, nrOfSamples,
- msInSndCardBuf, skew) != 0) {
- retVal = -1;
- }
+ // This returns the value of aec->extended_filter_enabled.
+ if (WebRtcAec_delay_correction_enabled(aecpc->aec)) {
+ ProcessExtended(
+ aecpc, nearend, nearendH, out, outH, nrOfSamples, msInSndCardBuf, skew);
+ } else {
+ if (ProcessNormal(aecpc,
+ nearend,
+ nearendH,
+ out,
+ outH,
+ nrOfSamples,
+ msInSndCardBuf,
+ skew) != 0) {
+ retVal = -1;
}
+ }
#ifdef WEBRTC_AEC_DEBUG_DUMP
- {
- int16_t far_buf_size_ms = (int16_t)(WebRtcAec_system_delay(aecpc->aec) /
- (sampMsNb * aecpc->rate_factor));
- (void)fwrite(&far_buf_size_ms, 2, 1, aecpc->bufFile);
- (void)fwrite(&aecpc->knownDelay, sizeof(aecpc->knownDelay), 1,
- aecpc->delayFile);
- }
+ {
+ int16_t far_buf_size_ms = (int16_t)(WebRtcAec_system_delay(aecpc->aec) /
+ (sampMsNb * aecpc->rate_factor));
+ (void)fwrite(&far_buf_size_ms, 2, 1, aecpc->bufFile);
+ (void)fwrite(
+ &aecpc->knownDelay, sizeof(aecpc->knownDelay), 1, aecpc->delayFile);
+ }
#endif
- return retVal;
+ return retVal;
}
int WebRtcAec_set_config(void* handle, AecConfig config) {
@@ -442,8 +459,9 @@ int WebRtcAec_set_config(void* handle, AecConfig config) {
}
self->skewMode = config.skewMode;
- if (config.nlpMode != kAecNlpConservative && config.nlpMode != kAecNlpModerate
- && config.nlpMode != kAecNlpAggressive) {
+ if (config.nlpMode != kAecNlpConservative &&
+ config.nlpMode != kAecNlpModerate &&
+ config.nlpMode != kAecNlpAggressive) {
self->lastError = AEC_BAD_PARAMETER_ERROR;
return -1;
}
@@ -458,14 +476,14 @@ int WebRtcAec_set_config(void* handle, AecConfig config) {
return -1;
}
- WebRtcAec_SetConfigCore(self->aec, config.nlpMode, config.metricsMode,
- config.delay_logging);
+ WebRtcAec_SetConfigCore(
+ self->aec, config.nlpMode, config.metricsMode, config.delay_logging);
return 0;
}
int WebRtcAec_get_echo_status(void* handle, int* status) {
aecpc_t* self = (aecpc_t*)handle;
- if (status == NULL ) {
+ if (status == NULL) {
self->lastError = AEC_NULL_POINTER_ERROR;
return -1;
}
@@ -488,10 +506,10 @@ int WebRtcAec_GetMetrics(void* handle, AecMetrics* metrics) {
Stats erle;
Stats a_nlp;
- if (handle == NULL ) {
+ if (handle == NULL) {
return -1;
}
- if (metrics == NULL ) {
+ if (metrics == NULL) {
self->lastError = AEC_NULL_POINTER_ERROR;
return -1;
}
@@ -503,46 +521,46 @@ int WebRtcAec_GetMetrics(void* handle, AecMetrics* metrics) {
WebRtcAec_GetEchoStats(self->aec, &erl, &erle, &a_nlp);
// ERL
- metrics->erl.instant = (int) erl.instant;
+ metrics->erl.instant = (int)erl.instant;
if ((erl.himean > kOffsetLevel) && (erl.average > kOffsetLevel)) {
// Use a mix between regular average and upper part average.
dtmp = kUpWeight * erl.himean + (1 - kUpWeight) * erl.average;
- metrics->erl.average = (int) dtmp;
+ metrics->erl.average = (int)dtmp;
} else {
metrics->erl.average = kOffsetLevel;
}
- metrics->erl.max = (int) erl.max;
+ metrics->erl.max = (int)erl.max;
if (erl.min < (kOffsetLevel * (-1))) {
- metrics->erl.min = (int) erl.min;
+ metrics->erl.min = (int)erl.min;
} else {
metrics->erl.min = kOffsetLevel;
}
// ERLE
- metrics->erle.instant = (int) erle.instant;
+ metrics->erle.instant = (int)erle.instant;
if ((erle.himean > kOffsetLevel) && (erle.average > kOffsetLevel)) {
// Use a mix between regular average and upper part average.
dtmp = kUpWeight * erle.himean + (1 - kUpWeight) * erle.average;
- metrics->erle.average = (int) dtmp;
+ metrics->erle.average = (int)dtmp;
} else {
metrics->erle.average = kOffsetLevel;
}
- metrics->erle.max = (int) erle.max;
+ metrics->erle.max = (int)erle.max;
if (erle.min < (kOffsetLevel * (-1))) {
- metrics->erle.min = (int) erle.min;
+ metrics->erle.min = (int)erle.min;
} else {
metrics->erle.min = kOffsetLevel;
}
// RERL
- if ((metrics->erl.average > kOffsetLevel)
- && (metrics->erle.average > kOffsetLevel)) {
+ if ((metrics->erl.average > kOffsetLevel) &&
+ (metrics->erle.average > kOffsetLevel)) {
stmp = metrics->erl.average + metrics->erle.average;
} else {
stmp = kOffsetLevel;
@@ -555,20 +573,20 @@ int WebRtcAec_GetMetrics(void* handle, AecMetrics* metrics) {
metrics->rerl.min = stmp;
// A_NLP
- metrics->aNlp.instant = (int) a_nlp.instant;
+ metrics->aNlp.instant = (int)a_nlp.instant;
if ((a_nlp.himean > kOffsetLevel) && (a_nlp.average > kOffsetLevel)) {
// Use a mix between regular average and upper part average.
dtmp = kUpWeight * a_nlp.himean + (1 - kUpWeight) * a_nlp.average;
- metrics->aNlp.average = (int) dtmp;
+ metrics->aNlp.average = (int)dtmp;
} else {
metrics->aNlp.average = kOffsetLevel;
}
- metrics->aNlp.max = (int) a_nlp.max;
+ metrics->aNlp.max = (int)a_nlp.max;
if (a_nlp.min < (kOffsetLevel * (-1))) {
- metrics->aNlp.min = (int) a_nlp.min;
+ metrics->aNlp.min = (int)a_nlp.min;
} else {
metrics->aNlp.min = kOffsetLevel;
}
@@ -599,22 +617,25 @@ int WebRtcAec_GetDelayMetrics(void* handle, int* median, int* std) {
return 0;
}
-int32_t WebRtcAec_get_error_code(void *aecInst)
-{
- aecpc_t *aecpc = aecInst;
- return aecpc->lastError;
+int32_t WebRtcAec_get_error_code(void* aecInst) {
+ aecpc_t* aecpc = aecInst;
+ return aecpc->lastError;
}
AecCore* WebRtcAec_aec_core(void* handle) {
if (!handle) {
return NULL;
}
- return ((aecpc_t*) handle)->aec;
+ return ((aecpc_t*)handle)->aec;
}
-static int ProcessNormal(aecpc_t *aecpc, const int16_t *nearend,
- const int16_t *nearendH, int16_t *out, int16_t *outH,
- int16_t nrOfSamples, int16_t msInSndCardBuf,
+static int ProcessNormal(aecpc_t* aecpc,
+ const int16_t* nearend,
+ const int16_t* nearendH,
+ int16_t* out,
+ int16_t* outH,
+ int16_t nrOfSamples,
+ int16_t msInSndCardBuf,
int32_t skew) {
int retVal = 0;
short i;
@@ -624,8 +645,8 @@ static int ProcessNormal(aecpc_t *aecpc, const int16_t *nearend,
const float minSkewEst = -0.5f;
const float maxSkewEst = 1.0f;
- msInSndCardBuf = msInSndCardBuf > kMaxTrustedDelayMs ?
- kMaxTrustedDelayMs : msInSndCardBuf;
+ msInSndCardBuf =
+ msInSndCardBuf > kMaxTrustedDelayMs ? kMaxTrustedDelayMs : msInSndCardBuf;
// TODO(andrew): we need to investigate if this +10 is really wanted.
msInSndCardBuf += 10;
aecpc->msInSndCardBuf = msInSndCardBuf;
@@ -633,27 +654,24 @@ static int ProcessNormal(aecpc_t *aecpc, const int16_t *nearend,
if (aecpc->skewMode == kAecTrue) {
if (aecpc->skewFrCtr < 25) {
aecpc->skewFrCtr++;
- }
- else {
+ } else {
retVal = WebRtcAec_GetSkew(aecpc->resampler, skew, &aecpc->skew);
if (retVal == -1) {
aecpc->skew = 0;
aecpc->lastError = AEC_BAD_PARAMETER_WARNING;
}
- aecpc->skew /= aecpc->sampFactor*nrOfSamples;
+ aecpc->skew /= aecpc->sampFactor * nrOfSamples;
if (aecpc->skew < 1.0e-3 && aecpc->skew > -1.0e-3) {
aecpc->resample = kAecFalse;
- }
- else {
+ } else {
aecpc->resample = kAecTrue;
}
if (aecpc->skew < minSkewEst) {
aecpc->skew = minSkewEst;
- }
- else if (aecpc->skew > maxSkewEst) {
+ } else if (aecpc->skew > maxSkewEst) {
aecpc->skew = maxSkewEst;
}
@@ -692,11 +710,10 @@ static int ProcessNormal(aecpc_t *aecpc, const int16_t *nearend,
}
if (abs(aecpc->firstVal - aecpc->msInSndCardBuf) <
- WEBRTC_SPL_MAX(0.2 * aecpc->msInSndCardBuf, sampMsNb)) {
+ WEBRTC_SPL_MAX(0.2 * aecpc->msInSndCardBuf, sampMsNb)) {
aecpc->sum += aecpc->msInSndCardBuf;
aecpc->counter++;
- }
- else {
+ } else {
aecpc->counter = 0;
}
@@ -704,9 +721,10 @@ static int ProcessNormal(aecpc_t *aecpc, const int16_t *nearend,
// The far-end buffer size is determined in partitions of
// PART_LEN samples. Use 75% of the average value of the system
// delay as buffer size to start with.
- aecpc->bufSizeStart = WEBRTC_SPL_MIN((3 * aecpc->sum *
- aecpc->rate_factor * 8) / (4 * aecpc->counter * PART_LEN),
- kMaxBufSizeStart);
+ aecpc->bufSizeStart =
+ WEBRTC_SPL_MIN((3 * aecpc->sum * aecpc->rate_factor * 8) /
+ (4 * aecpc->counter * PART_LEN),
+ kMaxBufSizeStart);
// Buffer size has now been determined.
aecpc->checkBuffSize = 0;
}
@@ -714,8 +732,9 @@ static int ProcessNormal(aecpc_t *aecpc, const int16_t *nearend,
if (aecpc->checkBufSizeCtr * nBlocks10ms > 50) {
// For really bad systems, don't disable the echo canceller for
// more than 0.5 sec.
- aecpc->bufSizeStart = WEBRTC_SPL_MIN((aecpc->msInSndCardBuf *
- aecpc->rate_factor * 3) / 40, kMaxBufSizeStart);
+ aecpc->bufSizeStart = WEBRTC_SPL_MIN(
+ (aecpc->msInSndCardBuf * aecpc->rate_factor * 3) / 40,
+ kMaxBufSizeStart);
aecpc->checkBuffSize = 0;
}
}
@@ -765,9 +784,14 @@ static int ProcessNormal(aecpc_t *aecpc, const int16_t *nearend,
return retVal;
}
-static void ProcessExtended(aecpc_t* self, const int16_t* near,
- const int16_t* near_high, int16_t* out, int16_t* out_high,
- int16_t num_samples, int16_t reported_delay_ms, int32_t skew) {
+static void ProcessExtended(aecpc_t* self,
+ const int16_t* near,
+ const int16_t* near_high,
+ int16_t* out,
+ int16_t* out_high,
+ int16_t num_samples,
+ int16_t reported_delay_ms,
+ int32_t skew) {
int i;
const int num_frames = num_samples / FRAME_LEN;
#if defined(WEBRTC_UNTRUSTED_DELAY)
@@ -779,14 +803,16 @@ static void ProcessExtended(aecpc_t* self, const int16_t* near,
// Due to the longer filter, we no longer add 10 ms to the reported delay
// to reduce chance of non-causality. Instead we apply a minimum here to avoid
// issues with the read pointer jumping around needlessly.
- reported_delay_ms = reported_delay_ms < kMinTrustedDelayMs ?
- kMinTrustedDelayMs : reported_delay_ms;
+ reported_delay_ms = reported_delay_ms < kMinTrustedDelayMs
+ ? kMinTrustedDelayMs
+ : reported_delay_ms;
// If the reported delay appears to be bogus, we attempt to recover by using
// the measured fixed delay values. We use >= here because higher layers
// may already clamp to this maximum value, and we would otherwise not
// detect it here.
- reported_delay_ms = reported_delay_ms >= kMaxTrustedDelayMs ?
- kFixedDelayMs : reported_delay_ms;
+ reported_delay_ms = reported_delay_ms >= kMaxTrustedDelayMs
+ ? kFixedDelayMs
+ : reported_delay_ms;
#endif
self->msInSndCardBuf = reported_delay_ms;
@@ -805,10 +831,11 @@ static void ProcessExtended(aecpc_t* self, const int16_t* near,
// action on the first frame. In the trusted delay case, we'll take the
// current reported delay, unless it's less then our conservative
// measurement.
- int startup_size_ms = reported_delay_ms < kFixedDelayMs ?
- kFixedDelayMs : reported_delay_ms;
+ int startup_size_ms =
+ reported_delay_ms < kFixedDelayMs ? kFixedDelayMs : reported_delay_ms;
int overhead_elements = (WebRtcAec_system_delay(self->aec) -
- startup_size_ms / 2 * self->rate_factor * 8) / PART_LEN;
+ startup_size_ms / 2 * self->rate_factor * 8) /
+ PART_LEN;
WebRtcAec_MoveFarReadPtr(self->aec, overhead_elements);
self->startup_phase = 0;
}
@@ -823,9 +850,12 @@ static void ProcessExtended(aecpc_t* self, const int16_t* near,
WEBRTC_SPL_MAX(0, self->knownDelay + delay_diff_offset);
for (i = 0; i < num_frames; ++i) {
- WebRtcAec_ProcessFrame(self->aec, &near[FRAME_LEN * i],
- &near_high[FRAME_LEN * i], adjusted_known_delay,
- &out[FRAME_LEN * i], &out_high[FRAME_LEN * i]);
+ WebRtcAec_ProcessFrame(self->aec,
+ &near[FRAME_LEN * i],
+ &near_high[FRAME_LEN * i],
+ adjusted_known_delay,
+ &out[FRAME_LEN * i],
+ &out_high[FRAME_LEN * i]);
}
}
}
@@ -857,8 +887,8 @@ static void EstBufDelayNormal(aecpc_t* aecpc) {
// We use -1 to signal an initialized state in the "extended" implementation;
// compensate for that.
aecpc->filtDelay = aecpc->filtDelay < 0 ? 0 : aecpc->filtDelay;
- aecpc->filtDelay = WEBRTC_SPL_MAX(0, (short) (0.8 * aecpc->filtDelay +
- 0.2 * current_delay));
+ aecpc->filtDelay =
+ WEBRTC_SPL_MAX(0, (short)(0.8 * aecpc->filtDelay + 0.2 * current_delay));
delay_difference = aecpc->filtDelay - aecpc->knownDelay;
if (delay_difference > 224) {
@@ -879,7 +909,7 @@ static void EstBufDelayNormal(aecpc_t* aecpc) {
aecpc->lastDelayDiff = delay_difference;
if (aecpc->timeForDelayChange > 25) {
- aecpc->knownDelay = WEBRTC_SPL_MAX((int) aecpc->filtDelay - 160, 0);
+ aecpc->knownDelay = WEBRTC_SPL_MAX((int)aecpc->filtDelay - 160, 0);
}
}
@@ -910,8 +940,8 @@ static void EstBufDelayExtended(aecpc_t* self) {
if (self->filtDelay == -1) {
self->filtDelay = WEBRTC_SPL_MAX(0, 0.5 * current_delay);
} else {
- self->filtDelay = WEBRTC_SPL_MAX(0, (short) (0.95 * self->filtDelay +
- 0.05 * current_delay));
+ self->filtDelay = WEBRTC_SPL_MAX(
+ 0, (short)(0.95 * self->filtDelay + 0.05 * current_delay));
}
delay_difference = self->filtDelay - self->knownDelay;
@@ -933,6 +963,6 @@ static void EstBufDelayExtended(aecpc_t* self) {
self->lastDelayDiff = delay_difference;
if (self->timeForDelayChange > 25) {
- self->knownDelay = WEBRTC_SPL_MAX((int) self->filtDelay - 256, 0);
+ self->knownDelay = WEBRTC_SPL_MAX((int)self->filtDelay - 256, 0);
}
}