aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_processing/aec/echo_cancellation.c
diff options
context:
space:
mode:
authortina.legrand@webrtc.org <tina.legrand@webrtc.org>2015-01-20 10:22:49 +0000
committertina.legrand@webrtc.org <tina.legrand@webrtc.org>2015-01-20 10:22:49 +0000
commitee0c100d5495cd8c440b767a7852532afbbcefb2 (patch)
tree048de65c4ad07891a066effb08a9b59e45faf80e /webrtc/modules/audio_processing/aec/echo_cancellation.c
parentf88f88eddef7361e136dc7515508d4aca0dc0a0a (diff)
downloadwebrtc-ee0c100d5495cd8c440b767a7852532afbbcefb2.tar.gz
Revert 8080 "Support 48kHz in AEC"
> Support 48kHz in AEC > > Doing something similar for the band 16-24kHz to what is done for the band 8-16kHz. The only difference is that there is no comfort noise added in this band. Could not test how this sounds because there are no aecdumps with 48kHz sample rate as nfar as I know. > Tested for 32kHz sample rate and the output is bitexact with how it was before this CL. > > BUG=webrtc:3146 > R=andrew@webrtc.org > > Review URL: https://webrtc-codereview.appspot.com/28319004 TBR=aluebs@webrtc.org Review URL: https://webrtc-codereview.appspot.com/33949004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@8100 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.c125
1 files changed, 70 insertions, 55 deletions
diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation.c b/webrtc/modules/audio_processing/aec/echo_cancellation.c
index e40336b6d9..99883c4db9 100644
--- a/webrtc/modules/audio_processing/aec/echo_cancellation.c
+++ b/webrtc/modules/audio_processing/aec/echo_cancellation.c
@@ -104,16 +104,18 @@ int webrtc_aec_instance_count = 0;
static void EstBufDelayNormal(Aec* aecInst);
static void EstBufDelayExtended(Aec* aecInst);
static int ProcessNormal(Aec* self,
- const float* const* near,
- int num_bands,
- float* const* out,
+ const float* near,
+ const float* near_high,
+ float* out,
+ float* out_high,
int16_t num_samples,
int16_t reported_delay_ms,
int32_t skew);
static void ProcessExtended(Aec* self,
- const float* const* near,
- int num_bands,
- float* const* out,
+ const float* near,
+ const float* near_high,
+ float* out,
+ float* out_high,
int16_t num_samples,
int16_t reported_delay_ms,
int32_t skew);
@@ -197,10 +199,7 @@ int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) {
Aec* aecpc = aecInst;
AecConfig aecConfig;
- if (sampFreq != 8000 &&
- sampFreq != 16000 &&
- sampFreq != 32000 &&
- sampFreq != 48000) {
+ if (sampFreq != 8000 && sampFreq != 16000 && sampFreq != 32000) {
aecpc->lastError = AEC_BAD_PARAMETER_ERROR;
return -1;
}
@@ -228,7 +227,7 @@ int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) {
aecpc->initFlag = initCheck; // indicates that initialization has been done
- if (aecpc->sampFreq == 32000 || aecpc->sampFreq == 48000) {
+ if (aecpc->sampFreq == 32000) {
aecpc->splitSampFreq = 16000;
} else {
aecpc->splitSampFreq = sampFreq;
@@ -339,14 +338,19 @@ int32_t WebRtcAec_BufferFarend(void* aecInst,
}
int32_t WebRtcAec_Process(void* aecInst,
- const float* const* nearend,
- int num_bands,
- float* const* out,
+ const float* nearend,
+ const float* nearendH,
+ float* out,
+ float* outH,
int16_t nrOfSamples,
int16_t msInSndCardBuf,
int32_t skew) {
Aec* 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;
@@ -364,6 +368,12 @@ int32_t WebRtcAec_Process(void* aecInst,
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;
@@ -376,18 +386,14 @@ int32_t WebRtcAec_Process(void* aecInst,
// This returns the value of aec->extended_filter_enabled.
if (WebRtcAec_delay_correction_enabled(aecpc->aec)) {
- ProcessExtended(aecpc,
- nearend,
- num_bands,
- out,
- nrOfSamples,
- msInSndCardBuf,
- skew);
+ ProcessExtended(
+ aecpc, nearend, nearendH, out, outH, nrOfSamples, msInSndCardBuf, skew);
} else {
if (ProcessNormal(aecpc,
nearend,
- num_bands,
+ nearendH,
out,
+ outH,
nrOfSamples,
msInSndCardBuf,
skew) != 0) {
@@ -592,15 +598,17 @@ AecCore* WebRtcAec_aec_core(void* handle) {
}
static int ProcessNormal(Aec* aecpc,
- const float* const* nearend,
- int num_bands,
- float* const* out,
+ const float* nearend,
+ const float* nearendH,
+ float* out,
+ float* outH,
int16_t nrOfSamples,
int16_t msInSndCardBuf,
int32_t skew) {
int retVal = 0;
short i;
short nBlocks10ms;
+ short nFrames;
// Limit resampling to doubling/halving of signal
const float minSkewEst = -0.5f;
const float maxSkewEst = 1.0f;
@@ -641,14 +649,16 @@ static int ProcessNormal(Aec* aecpc,
}
}
- nBlocks10ms = nrOfSamples / (FRAME_LEN * aecpc->rate_factor);
+ nFrames = nrOfSamples / FRAME_LEN;
+ nBlocks10ms = nFrames / aecpc->rate_factor;
if (aecpc->startup_phase) {
- for (i = 0; i < num_bands; ++i) {
- // Only needed if they don't already point to the same place.
- if (nearend[i] != out[i]) {
- memcpy(out[i], nearend[i], sizeof(nearend[i][0]) * nrOfSamples);
- }
+ // Only needed if they don't already point to the same place.
+ if (nearend != out) {
+ memcpy(out, nearend, sizeof(*out) * nrOfSamples);
+ }
+ if (nearendH != outH) {
+ memcpy(outH, nearendH, sizeof(*outH) * nrOfSamples);
}
// The AEC is in the start up mode
@@ -726,25 +736,29 @@ static int ProcessNormal(Aec* aecpc,
EstBufDelayNormal(aecpc);
}
- // Call the AEC.
- // TODO(bjornv): Re-structure such that we don't have to pass
- // |aecpc->knownDelay| as input. Change name to something like
- // |system_buffer_diff|.
- WebRtcAec_ProcessFrames(aecpc->aec,
- nearend,
- num_bands,
- nrOfSamples,
- aecpc->knownDelay,
- out);
+ // Note that 1 frame is supported for NB and 2 frames for WB.
+ for (i = 0; i < nFrames; i++) {
+ // Call the AEC.
+ WebRtcAec_ProcessFrame(aecpc->aec,
+ &nearend[FRAME_LEN * i],
+ &nearendH[FRAME_LEN * i],
+ aecpc->knownDelay,
+ &out[FRAME_LEN * i],
+ &outH[FRAME_LEN * i]);
+ // TODO(bjornv): Re-structure such that we don't have to pass
+ // |aecpc->knownDelay| as input. Change name to something like
+ // |system_buffer_diff|.
+ }
}
return retVal;
}
static void ProcessExtended(Aec* self,
- const float* const* near,
- int num_bands,
- float* const* out,
+ const float* near,
+ const float* near_high,
+ float* out,
+ float* out_high,
int16_t num_samples,
int16_t reported_delay_ms,
int32_t skew) {
@@ -772,11 +786,12 @@ static void ProcessExtended(Aec* self,
self->msInSndCardBuf = reported_delay_ms;
if (!self->farend_started) {
- for (i = 0; i < num_bands; ++i) {
- // Only needed if they don't already point to the same place.
- if (near[i] != out[i]) {
- memcpy(out[i], near[i], sizeof(near[i][0]) * num_samples);
- }
+ // Only needed if they don't already point to the same place.
+ if (near != out) {
+ memcpy(out, near, sizeof(*out) * num_samples);
+ }
+ if (near_high != out_high) {
+ memcpy(out_high, near_high, sizeof(*out_high) * num_samples);
}
return;
}
@@ -806,12 +821,12 @@ static void ProcessExtended(Aec* self,
WEBRTC_SPL_MAX(0, self->knownDelay + delay_diff_offset);
for (i = 0; i < num_frames; ++i) {
- WebRtcAec_ProcessFrames(self->aec,
- near,
- num_bands,
- FRAME_LEN * i,
- adjusted_known_delay,
- out);
+ 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]);
}
}
}