Lines Matching defs:aecm
91 aecmob_t *aecm;
97 aecm = malloc(sizeof(aecmob_t));
98 *aecmInst = aecm;
99 if (aecm == NULL)
104 if (WebRtcAecm_CreateCore(&aecm->aecmCore) == -1)
106 WebRtcAecm_Free(aecm);
107 aecm = NULL;
111 if (WebRtc_CreateBuffer(&aecm->farendBuf, kBufSizeSamp,
114 WebRtcAecm_Free(aecm);
115 aecm = NULL;
119 aecm->initFlag = 0;
120 aecm->lastError = 0;
123 aecm->aecmCore->farFile = fopen("aecFar.pcm","wb");
124 aecm->aecmCore->nearFile = fopen("aecNear.pcm","wb");
125 aecm->aecmCore->outFile = fopen("aecOut.pcm","wb");
126 //aecm->aecmCore->outLpFile = fopen("aecOutLp.pcm","wb");
128 aecm->bufFile = fopen("aecBuf.dat", "wb");
129 aecm->delayFile = fopen("aecDelay.dat", "wb");
130 aecm->preCompFile = fopen("preComp.pcm", "wb");
131 aecm->postCompFile = fopen("postComp.pcm", "wb");
138 aecmob_t *aecm = aecmInst;
140 if (aecm == NULL)
146 fclose(aecm->aecmCore->farFile);
147 fclose(aecm->aecmCore->nearFile);
148 fclose(aecm->aecmCore->outFile);
149 //fclose(aecm->aecmCore->outLpFile);
151 fclose(aecm->bufFile);
152 fclose(aecm->delayFile);
153 fclose(aecm->preCompFile);
154 fclose(aecm->postCompFile);
156 WebRtcAecm_FreeCore(aecm->aecmCore);
157 WebRtc_FreeBuffer(aecm->farendBuf);
158 free(aecm);
165 aecmob_t *aecm = aecmInst;
168 if (aecm == NULL)
175 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
178 aecm->sampFreq = sampFreq;
180 // Initialize AECM core
181 if (WebRtcAecm_InitCore(aecm->aecmCore, aecm->sampFreq) == -1)
183 aecm->lastError = AECM_UNSPECIFIED_ERROR;
188 if (WebRtc_InitBuffer(aecm->farendBuf) == -1)
190 aecm->lastError = AECM_UNSPECIFIED_ERROR;
194 aecm->initFlag = kInitCheck; // indicates that initialization has been done
196 aecm->delayChange = 1;
198 aecm->sum = 0;
199 aecm->counter = 0;
200 aecm->checkBuffSize = 1;
201 aecm->firstVal = 0;
203 aecm->ECstartup = 1;
204 aecm->bufSizeStart = 0;
205 aecm->checkBufSizeCtr = 0;
206 aecm->filtDelay = 0;
207 aecm->timeForDelayChange = 0;
208 aecm->knownDelay = 0;
209 aecm->lastDelayDiff = 0;
211 memset(&aecm->farendOld[0][0], 0, 160);
217 if (WebRtcAecm_set_config(aecm, aecConfig) == -1)
219 aecm->lastError = AECM_UNSPECIFIED_ERROR;
229 aecmob_t *aecm = aecmInst;
232 if (aecm == NULL)
239 aecm->lastError = AECM_NULL_POINTER_ERROR;
243 if (aecm->initFlag != kInitCheck)
245 aecm->lastError = AECM_UNINITIALIZED_ERROR;
251 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
256 if (!aecm->ECstartup)
258 WebRtcAecm_DelayComp(aecm);
261 WebRtc_WriteBuffer(aecm->farendBuf, farend, (size_t) nrOfSamples);
270 aecmob_t *aecm = aecmInst;
292 if (aecm == NULL)
299 aecm->lastError = AECM_NULL_POINTER_ERROR;
305 aecm->lastError = AECM_NULL_POINTER_ERROR;
309 if (aecm->initFlag != kInitCheck)
311 aecm->lastError = AECM_UNINITIALIZED_ERROR;
317 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
324 aecm->lastError = AECM_BAD_PARAMETER_WARNING;
329 aecm->lastError = AECM_BAD_PARAMETER_WARNING;
333 aecm->msInSndCardBuf = msInSndCardBuf;
336 nBlocks10ms = nFrames / aecm->aecmCore->mult;
338 if (aecm->ECstartup)
349 (short) WebRtc_available_read(aecm->farendBuf) / FRAME_LEN;
350 // The AECM is in the start up mode
351 // AECM is disabled until the soundcard buffer and farend buffers are OK
354 if (aecm->checkBuffSize)
356 aecm->checkBufSizeCtr++;
362 if (aecm->counter == 0)
364 aecm->firstVal = aecm->msInSndCardBuf;
365 aecm->sum = 0;
368 if (abs(aecm->firstVal - aecm->msInSndCardBuf)
369 < WEBRTC_SPL_MAX(0.2 * aecm->msInSndCardBuf, kSampMsNb))
371 aecm->sum += aecm->msInSndCardBuf;
372 aecm->counter++;
375 aecm->counter = 0;
378 if (aecm->counter * nBlocks10ms >= 6)
382 aecm->bufSizeStart
383 = WEBRTC_SPL_MIN((3 * aecm->sum
384 * aecm->aecmCore->mult) / (aecm->counter * 40), BUF_SIZE_FRAMES);
386 aecm->checkBuffSize = 0;
389 if (aecm->checkBufSizeCtr * nBlocks10ms > 50)
392 aecm->bufSizeStart = WEBRTC_SPL_MIN((3 * aecm->msInSndCardBuf
393 * aecm->aecmCore->mult) / 40, BUF_SIZE_FRAMES);
394 aecm->checkBuffSize = 0;
399 if (!aecm->checkBuffSize)
406 if (nmbrOfFilledBuffers == aecm->bufSizeStart)
408 aecm->ECstartup = 0; // Enable the AECM
409 } else if (nmbrOfFilledBuffers > aecm->bufSizeStart)
411 WebRtc_MoveReadPtr(aecm->farendBuf,
412 (int) WebRtc_available_read(aecm->farendBuf)
413 - (int) aecm->bufSizeStart * FRAME_LEN);
414 aecm->ECstartup = 0;
420 // AECM is enabled
429 (short) WebRtc_available_read(aecm->farendBuf) / FRAME_LEN;
435 WebRtc_ReadBuffer(aecm->farendBuf, (void**) &farend_ptr, farend,
439 memcpy(&(aecm->farendOld[i][0]), farend_ptr,
444 memcpy(farend, &(aecm->farendOld[i][0]), FRAME_LEN * sizeof(short));
450 if ((i == 0 && aecm->sampFreq == 8000) || (i == 1 && aecm->sampFreq == 16000))
452 WebRtcAecm_EstBufDelay(aecm, aecm->msInSndCardBuf);
463 // Call the AECM
464 /*WebRtcAecm_ProcessFrame(aecm->aecmCore, farend, &nearend[FRAME_LEN * i],
465 &out[FRAME_LEN * i], aecm->knownDelay);*/
468 if (WebRtcAecm_ProcessFrame(aecm->aecmCore,
478 if (WebRtcAecm_ProcessFrame(aecm->aecmCore,
525 msInAECBuf = (short) WebRtc_available_read(aecm->farendBuf) /
526 (kSampMsNb * aecm->aecmCore->mult);
527 fwrite(&msInAECBuf, 2, 1, aecm->bufFile);
528 fwrite(&(aecm->knownDelay), sizeof(aecm->knownDelay), 1, aecm->delayFile);
536 aecmob_t *aecm = aecmInst;
538 if (aecm == NULL)
543 if (aecm->initFlag != kInitCheck)
545 aecm->lastError = AECM_UNINITIALIZED_ERROR;
551 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
554 aecm->aecmCore->cngMode = config.cngMode;
558 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
561 aecm->echoMode = config.echoMode;
563 if (aecm->echoMode == 0)
565 aecm->aecmCore->supGain = SUPGAIN_DEFAULT >> 3;
566 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT >> 3;
567 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A >> 3;
568 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D >> 3;
569 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A >> 3)
571 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B >> 3)
573 } else if (aecm->echoMode == 1)
575 aecm->aecmCore->supGain = SUPGAIN_DEFAULT >> 2;
576 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT >> 2;
577 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A >> 2;
578 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D >> 2;
579 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A >> 2)
581 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B >> 2)
583 } else if (aecm->echoMode == 2)
585 aecm->aecmCore->supGain = SUPGAIN_DEFAULT >> 1;
586 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT >> 1;
587 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A >> 1;
588 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D >> 1;
589 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A >> 1)
591 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B >> 1)
593 } else if (aecm->echoMode == 3)
595 aecm->aecmCore->supGain = SUPGAIN_DEFAULT;
596 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT;
597 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A;
598 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D;
599 aecm->aecmCore->supGainErrParamDiffAB = SUPGAIN_ERROR_PARAM_A - SUPGAIN_ERROR_PARAM_B;
600 aecm->aecmCore->supGainErrParamDiffBD = SUPGAIN_ERROR_PARAM_B - SUPGAIN_ERROR_PARAM_D;
601 } else if (aecm->echoMode == 4)
603 aecm->aecmCore->supGain = SUPGAIN_DEFAULT << 1;
604 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT << 1;
605 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A << 1;
606 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D << 1;
607 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A << 1)
609 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B << 1)
618 aecmob_t *aecm = aecmInst;
620 if (aecm == NULL)
627 aecm->lastError = AECM_NULL_POINTER_ERROR;
631 if (aecm->initFlag != kInitCheck)
633 aecm->lastError = AECM_UNINITIALIZED_ERROR;
637 config->cngMode = aecm->aecmCore->cngMode;
638 config->echoMode = aecm->echoMode;
647 aecmob_t *aecm = aecmInst;
650 if ((aecm == NULL) || (echo_path == NULL))
652 aecm->lastError = AECM_NULL_POINTER_ERROR;
657 // Input channel size does not match the size of AECM
658 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
661 if (aecm->initFlag != kInitCheck)
663 aecm->lastError = AECM_UNINITIALIZED_ERROR;
667 WebRtcAecm_InitEchoPathCore(aecm->aecmCore, echo_path_ptr);
676 aecmob_t *aecm = aecmInst;
679 if ((aecm == NULL) || (echo_path == NULL))
681 aecm->lastError = AECM_NULL_POINTER_ERROR;
686 // Input channel size does not match the size of AECM
687 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
690 if (aecm->initFlag != kInitCheck)
692 aecm->lastError = AECM_UNINITIALIZED_ERROR;
696 memcpy(echo_path_ptr, aecm->aecmCore->channelStored, size_bytes);
707 const char version[] = "AECM 1.2.0";
726 aecmob_t *aecm = aecmInst;
728 if (aecm == NULL)
733 return aecm->lastError;
736 static int WebRtcAecm_EstBufDelay(aecmob_t *aecm, short msInSndCardBuf)
739 short nSampFar = (short) WebRtc_available_read(aecm->farendBuf);
742 nSampSndCard = msInSndCardBuf * kSampMsNb * aecm->aecmCore->mult;
748 WebRtc_MoveReadPtr(aecm->farendBuf, FRAME_LEN);
752 aecm->filtDelay = WEBRTC_SPL_MAX(0, (8 * aecm->filtDelay + 2 * delayNew) / 10);
754 diff = aecm->filtDelay - aecm->knownDelay;
757 if (aecm->lastDelayDiff < 96)
759 aecm->timeForDelayChange = 0;
762 aecm->timeForDelayChange++;
764 } else if (diff < 96 && aecm->knownDelay > 0)
766 if (aecm->lastDelayDiff > 224)
768 aecm->timeForDelayChange = 0;
771 aecm->timeForDelayChange++;
775 aecm->timeForDelayChange = 0;
777 aecm->lastDelayDiff = diff;
779 if (aecm->timeForDelayChange > 25)
781 aecm->knownDelay = WEBRTC_SPL_MAX((int)aecm->filtDelay - 160, 0);
786 static int WebRtcAecm_DelayComp(aecmob_t *aecm)
788 int nSampFar = (int) WebRtc_available_read(aecm->farendBuf);
792 nSampSndCard = aecm->msInSndCardBuf * kSampMsNb * aecm->aecmCore->mult;
795 if (delayNew > FAR_BUF_LEN - FRAME_LEN * aecm->aecmCore->mult)
803 WebRtc_MoveReadPtr(aecm->farendBuf, -nSampAdd);
804 aecm->delayChange = 1; // the delay needs to be updated