Lines Matching defs:aecm
11 #include "webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h"
19 #include "webrtc/modules/audio_processing/aecm/aecm_core.h"
85 aecmob_t *aecm;
91 aecm = malloc(sizeof(aecmob_t));
92 *aecmInst = aecm;
93 if (aecm == NULL)
100 if (WebRtcAecm_CreateCore(&aecm->aecmCore) == -1)
102 WebRtcAecm_Free(aecm);
103 aecm = NULL;
107 aecm->farendBuf = WebRtc_CreateBuffer(kBufSizeSamp,
109 if (!aecm->farendBuf)
111 WebRtcAecm_Free(aecm);
112 aecm = NULL;
116 aecm->initFlag = 0;
117 aecm->lastError = 0;
120 aecm->aecmCore->farFile = fopen("aecFar.pcm","wb");
121 aecm->aecmCore->nearFile = fopen("aecNear.pcm","wb");
122 aecm->aecmCore->outFile = fopen("aecOut.pcm","wb");
123 //aecm->aecmCore->outLpFile = fopen("aecOutLp.pcm","wb");
125 aecm->bufFile = fopen("aecBuf.dat", "wb");
126 aecm->delayFile = fopen("aecDelay.dat", "wb");
127 aecm->preCompFile = fopen("preComp.pcm", "wb");
128 aecm->postCompFile = fopen("postComp.pcm", "wb");
135 aecmob_t *aecm = aecmInst;
137 if (aecm == NULL)
143 fclose(aecm->aecmCore->farFile);
144 fclose(aecm->aecmCore->nearFile);
145 fclose(aecm->aecmCore->outFile);
146 //fclose(aecm->aecmCore->outLpFile);
148 fclose(aecm->bufFile);
149 fclose(aecm->delayFile);
150 fclose(aecm->preCompFile);
151 fclose(aecm->postCompFile);
153 WebRtcAecm_FreeCore(aecm->aecmCore);
154 WebRtc_FreeBuffer(aecm->farendBuf);
155 free(aecm);
162 aecmob_t *aecm = aecmInst;
165 if (aecm == NULL)
172 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
175 aecm->sampFreq = sampFreq;
177 // Initialize AECM core
178 if (WebRtcAecm_InitCore(aecm->aecmCore, aecm->sampFreq) == -1)
180 aecm->lastError = AECM_UNSPECIFIED_ERROR;
185 if (WebRtc_InitBuffer(aecm->farendBuf) == -1)
187 aecm->lastError = AECM_UNSPECIFIED_ERROR;
191 aecm->initFlag = kInitCheck; // indicates that initialization has been done
193 aecm->delayChange = 1;
195 aecm->sum = 0;
196 aecm->counter = 0;
197 aecm->checkBuffSize = 1;
198 aecm->firstVal = 0;
200 aecm->ECstartup = 1;
201 aecm->bufSizeStart = 0;
202 aecm->checkBufSizeCtr = 0;
203 aecm->filtDelay = 0;
204 aecm->timeForDelayChange = 0;
205 aecm->knownDelay = 0;
206 aecm->lastDelayDiff = 0;
208 memset(&aecm->farendOld[0][0], 0, 160);
214 if (WebRtcAecm_set_config(aecm, aecConfig) == -1)
216 aecm->lastError = AECM_UNSPECIFIED_ERROR;
226 aecmob_t *aecm = aecmInst;
229 if (aecm == NULL)
236 aecm->lastError = AECM_NULL_POINTER_ERROR;
240 if (aecm->initFlag != kInitCheck)
242 aecm->lastError = AECM_UNINITIALIZED_ERROR;
248 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
253 if (!aecm->ECstartup)
255 WebRtcAecm_DelayComp(aecm);
258 WebRtc_WriteBuffer(aecm->farendBuf, farend, (size_t) nrOfSamples);
267 aecmob_t *aecm = aecmInst;
277 if (aecm == NULL)
284 aecm->lastError = AECM_NULL_POINTER_ERROR;
290 aecm->lastError = AECM_NULL_POINTER_ERROR;
294 if (aecm->initFlag != kInitCheck)
296 aecm->lastError = AECM_UNINITIALIZED_ERROR;
302 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
309 aecm->lastError = AECM_BAD_PARAMETER_WARNING;
314 aecm->lastError = AECM_BAD_PARAMETER_WARNING;
318 aecm->msInSndCardBuf = msInSndCardBuf;
321 nBlocks10ms = nFrames / aecm->aecmCore->mult;
323 if (aecm->ECstartup)
337 (short) WebRtc_available_read(aecm->farendBuf) / FRAME_LEN;
338 // The AECM is in the start up mode
339 // AECM is disabled until the soundcard buffer and farend buffers are OK
342 if (aecm->checkBuffSize)
344 aecm->checkBufSizeCtr++;
350 if (aecm->counter == 0)
352 aecm->firstVal = aecm->msInSndCardBuf;
353 aecm->sum = 0;
356 if (abs(aecm->firstVal - aecm->msInSndCardBuf)
357 < WEBRTC_SPL_MAX(0.2 * aecm->msInSndCardBuf, kSampMsNb))
359 aecm->sum += aecm->msInSndCardBuf;
360 aecm->counter++;
363 aecm->counter = 0;
366 if (aecm->counter * nBlocks10ms >= 6)
370 aecm->bufSizeStart
371 = WEBRTC_SPL_MIN((3 * aecm->sum
372 * aecm->aecmCore->mult) / (aecm->counter * 40), BUF_SIZE_FRAMES);
374 aecm->checkBuffSize = 0;
377 if (aecm->checkBufSizeCtr * nBlocks10ms > 50)
380 aecm->bufSizeStart = WEBRTC_SPL_MIN((3 * aecm->msInSndCardBuf
381 * aecm->aecmCore->mult) / 40, BUF_SIZE_FRAMES);
382 aecm->checkBuffSize = 0;
387 if (!aecm->checkBuffSize)
394 if (nmbrOfFilledBuffers == aecm->bufSizeStart)
396 aecm->ECstartup = 0; // Enable the AECM
397 } else if (nmbrOfFilledBuffers > aecm->bufSizeStart)
399 WebRtc_MoveReadPtr(aecm->farendBuf,
400 (int) WebRtc_available_read(aecm->farendBuf)
401 - (int) aecm->bufSizeStart * FRAME_LEN);
402 aecm->ECstartup = 0;
408 // AECM is enabled
417 (short) WebRtc_available_read(aecm->farendBuf) / FRAME_LEN;
423 WebRtc_ReadBuffer(aecm->farendBuf, (void**) &farend_ptr, farend,
427 memcpy(&(aecm->farendOld[i][0]), farend_ptr,
432 memcpy(farend, &(aecm->farendOld[i][0]), FRAME_LEN * sizeof(short));
438 if ((i == 0 && aecm->sampFreq == 8000) || (i == 1 && aecm->sampFreq == 16000))
440 WebRtcAecm_EstBufDelay(aecm, aecm->msInSndCardBuf);
443 // Call the AECM
444 /*WebRtcAecm_ProcessFrame(aecm->aecmCore, farend, &nearend[FRAME_LEN * i],
445 &out[FRAME_LEN * i], aecm->knownDelay);*/
446 if (WebRtcAecm_ProcessFrame(aecm->aecmCore,
458 msInAECBuf = (short) WebRtc_available_read(aecm->farendBuf) /
459 (kSampMsNb * aecm->aecmCore->mult);
460 fwrite(&msInAECBuf, 2, 1, aecm->bufFile);
461 fwrite(&(aecm->knownDelay), sizeof(aecm->knownDelay), 1, aecm->delayFile);
469 aecmob_t *aecm = aecmInst;
471 if (aecm == NULL)
476 if (aecm->initFlag != kInitCheck)
478 aecm->lastError = AECM_UNINITIALIZED_ERROR;
484 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
487 aecm->aecmCore->cngMode = config.cngMode;
491 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
494 aecm->echoMode = config.echoMode;
496 if (aecm->echoMode == 0)
498 aecm->aecmCore->supGain = SUPGAIN_DEFAULT >> 3;
499 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT >> 3;
500 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A >> 3;
501 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D >> 3;
502 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A >> 3)
504 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B >> 3)
506 } else if (aecm->echoMode == 1)
508 aecm->aecmCore->supGain = SUPGAIN_DEFAULT >> 2;
509 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT >> 2;
510 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A >> 2;
511 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D >> 2;
512 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A >> 2)
514 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B >> 2)
516 } else if (aecm->echoMode == 2)
518 aecm->aecmCore->supGain = SUPGAIN_DEFAULT >> 1;
519 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT >> 1;
520 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A >> 1;
521 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D >> 1;
522 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A >> 1)
524 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B >> 1)
526 } else if (aecm->echoMode == 3)
528 aecm->aecmCore->supGain = SUPGAIN_DEFAULT;
529 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT;
530 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A;
531 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D;
532 aecm->aecmCore->supGainErrParamDiffAB = SUPGAIN_ERROR_PARAM_A - SUPGAIN_ERROR_PARAM_B;
533 aecm->aecmCore->supGainErrParamDiffBD = SUPGAIN_ERROR_PARAM_B - SUPGAIN_ERROR_PARAM_D;
534 } else if (aecm->echoMode == 4)
536 aecm->aecmCore->supGain = SUPGAIN_DEFAULT << 1;
537 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT << 1;
538 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A << 1;
539 aecm
540 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A << 1)
542 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B << 1)
551 aecmob_t *aecm = aecmInst;
553 if (aecm == NULL)
560 aecm->lastError = AECM_NULL_POINTER_ERROR;
564 if (aecm->initFlag != kInitCheck)
566 aecm->lastError = AECM_UNINITIALIZED_ERROR;
570 config->cngMode = aecm->aecmCore->cngMode;
571 config->echoMode = aecm->echoMode;
580 aecmob_t *aecm = aecmInst;
587 aecm->lastError = AECM_NULL_POINTER_ERROR;
592 // Input channel size does not match the size of AECM
593 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
596 if (aecm->initFlag != kInitCheck)
598 aecm->lastError = AECM_UNINITIALIZED_ERROR;
602 WebRtcAecm_InitEchoPathCore(aecm->aecmCore, echo_path_ptr);
611 aecmob_t *aecm = aecmInst;
618 aecm->lastError = AECM_NULL_POINTER_ERROR;
623 // Input channel size does not match the size of AECM
624 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
627 if (aecm->initFlag != kInitCheck)
629 aecm->lastError = AECM_UNINITIALIZED_ERROR;
633 memcpy(echo_path_ptr, aecm->aecmCore->channelStored, size_bytes);
644 aecmob_t *aecm = aecmInst;
646 if (aecm == NULL)
651 return aecm->lastError;
654 static int WebRtcAecm_EstBufDelay(aecmob_t *aecm, short msInSndCardBuf)
657 short nSampFar = (short) WebRtc_available_read(aecm->farendBuf);
660 nSampSndCard = msInSndCardBuf * kSampMsNb * aecm->aecmCore->mult;
666 WebRtc_MoveReadPtr(aecm->farendBuf, FRAME_LEN);
670 aecm->filtDelay = WEBRTC_SPL_MAX(0, (8 * aecm->filtDelay + 2 * delayNew) / 10);
672 diff = aecm->filtDelay - aecm->knownDelay;
675 if (aecm->lastDelayDiff < 96)
677 aecm->timeForDelayChange = 0;
680 aecm->timeForDelayChange++;
682 } else if (diff < 96 && aecm->knownDelay > 0)
684 if (aecm->lastDelayDiff > 224)
686 aecm->timeForDelayChange = 0;
689 aecm->timeForDelayChange++;
693 aecm->timeForDelayChange = 0;
695 aecm->lastDelayDiff = diff;
697 if (aecm->timeForDelayChange > 25)
699 aecm->knownDelay = WEBRTC_SPL_MAX((int)aecm->filtDelay - 160, 0);
704 static int WebRtcAecm_DelayComp(aecmob_t *aecm)
706 int nSampFar = (int) WebRtc_available_read(aecm->farendBuf);
710 nSampSndCard = aecm->msInSndCardBuf * kSampMsNb * aecm->aecmCore->mult;
713 if (delayNew > FAR_BUF_LEN - FRAME_LEN * aecm->aecmCore->mult)
721 WebRtc_MoveReadPtr(aecm->farendBuf, -nSampAdd);
722 aecm->delayChange = 1; // the delay needs to be updated