Lines Matching defs:aecm
200 static void ComfortNoise(AecmCore_t* aecm,
205 static WebRtc_Word16 CalcSuppressionGain(AecmCore_t * const aecm);
238 // - self : Pointer to the AECM instance.
276 AecmCore_t *aecm = malloc(sizeof(AecmCore_t));
277 *aecmInst = aecm;
278 if (aecm == NULL)
283 if (WebRtc_CreateBuffer(&aecm->farFrameBuf, FRAME_LEN + PART_LEN,
286 WebRtcAecm_FreeCore(aecm);
287 aecm = NULL;
291 if (WebRtc_CreateBuffer(&aecm->nearNoisyFrameBuf, FRAME_LEN + PART_LEN,
294 WebRtcAecm_FreeCore(aecm);
295 aecm = NULL;
299 if (WebRtc_CreateBuffer(&aecm->nearCleanFrameBuf, FRAME_LEN + PART_LEN,
302 WebRtcAecm_FreeCore(aecm);
303 aecm = NULL;
307 if (WebRtc_CreateBuffer(&aecm->outFrameBuf, FRAME_LEN + PART_LEN,
310 WebRtcAecm_FreeCore(aecm);
311 aecm = NULL;
315 if (WebRtc_CreateDelayEstimator(&aecm->delay_estimator,
319 WebRtcAecm_FreeCore(aecm);
320 aecm = NULL;
324 // Init some aecm pointers. 16 and 32 byte alignment is only necessary
326 aecm->xBuf = (WebRtc_Word16*) (((uintptr_t)aecm->xBuf_buf + 31) & ~ 31);
327 aecm->dBufClean = (WebRtc_Word16*) (((uintptr_t)aecm->dBufClean_buf + 31) & ~ 31);
328 aecm->dBufNoisy = (WebRtc_Word16*) (((uintptr_t)aecm->dBufNoisy_buf + 31) & ~ 31);
329 aecm->outBuf = (WebRtc_Word16*) (((uintptr_t)aecm->outBuf_buf + 15) & ~ 15);
330 aecm->channelStored = (WebRtc_Word16*) (((uintptr_t)
331 aecm->channelStored_buf + 15) & ~ 15);
332 aecm->channelAdapt16 = (WebRtc_Word16*) (((uintptr_t)
333 aecm->channelAdapt16_buf + 15) & ~ 15);
334 aecm->channelAdapt32 = (WebRtc_Word32*) (((uintptr_t)
335 aecm->channelAdapt32_buf + 31) & ~ 31);
340 void WebRtcAecm_InitEchoPathCore(AecmCore_t* aecm, const WebRtc_Word16* echo_path)
345 memcpy(aecm->channelStored, echo_path, sizeof(WebRtc_Word16) * PART_LEN1);
347 memcpy(aecm->channelAdapt16, echo_path, sizeof(WebRtc_Word16) * PART_LEN1);
350 aecm->channelAdapt32[i] = WEBRTC_SPL_LSHIFT_W32(
351 (WebRtc_Word32)(aecm->channelAdapt16[i]), 16);
355 aecm->mseAdaptOld = 1000;
356 aecm->mseStoredOld = 1000;
357 aecm->mseThreshold = WEBRTC_SPL_WORD32_MAX;
358 aecm->mseChannelCount = 0;
399 static void InverseFFTAndWindowC(AecmCore_t* aecm,
445 outCFFT - aecm->dfaCleanQDomain);
447 tmp32no1 + aecm->outBuf[i],
456 outCFFT - aecm->dfaCleanQDomain);
457 aecm->outBuf[i] = (WebRtc_Word16)WEBRTC_SPL_SAT(
471 // Copy the current block to the old position (aecm->outBuf is shifted elsewhere)
472 memcpy(aecm->xBuf, aecm->xBuf + PART_LEN, sizeof(WebRtc_Word16) * PART_LEN);
473 memcpy(aecm->dBufNoisy, aecm->dBufNoisy + PART_LEN, sizeof(WebRtc_Word16) * PART_LEN);
476 memcpy(aecm->dBufClean, aecm->dBufClean + PART_LEN, sizeof(WebRtc_Word16) * PART_LEN);
480 static void CalcLinearEnergiesC(AecmCore_t* aecm,
493 echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i],
496 (*echo_energy_adapt) += WEBRTC_SPL_UMUL_16_16(aecm->channelAdapt16[i],
502 static void StoreAdaptiveChannelC(AecmCore_t* aecm,
509 memcpy(aecm->channelStored, aecm->channelAdapt16, sizeof(WebRtc_Word16) * PART_LEN1);
513 echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i],
515 echo_est[i + 1] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i + 1],
517 echo_est[i + 2] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i + 2],
519 echo_est[i + 3] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i + 3],
522 echo_est[i] = WEBRTC_SPL_MUL_16_U16(aecm->channelStored[i],
526 static void ResetAdaptiveChannelC(AecmCore_t* aecm)
532 memcpy(aecm->channelAdapt16, aecm->channelStored,
537 aecm->channelAdapt32[i] = WEBRTC_SPL_LSHIFT_W32(
538 (WebRtc_Word32)aecm->channelStored[i], 16);
539 aecm->channelAdapt32[i + 1] = WEBRTC_SPL_LSHIFT_W32(
540 (WebRtc_Word32)aecm->channelStored[i + 1], 16);
541 aecm->channelAdapt32[i + 2] = WEBRTC_SPL_LSHIFT_W32(
542 (WebRtc_Word32)aecm->channelStored[i + 2], 16);
543 aecm->channelAdapt32[i + 3] = WEBRTC_SPL_LSHIFT_W32(
544 (WebRtc_Word32)aecm->channelStored[i + 3], 16);
546 aecm->channelAdapt32[i] = WEBRTC_SPL_LSHIFT_W32((WebRtc_Word32)aecm->channelStored[i], 16);
551 // This function initializes the AECM instant created with WebRtcAecm_CreateCore(...)
553 // - aecm : Pointer to the Echo Suppression instance
557 // - aecm : Initialized instance
562 int WebRtcAecm_InitCore(AecmCore_t * const aecm, int samplingFreq)
574 aecm->mult = (WebRtc_Word16)samplingFreq / 8000;
576 aecm->farBufWritePos = 0;
577 aecm->farBufReadPos = 0;
578 aecm->knownDelay = 0;
579 aecm->lastKnownDelay = 0;
581 WebRtc_InitBuffer(aecm->farFrameBuf);
582 WebRtc_InitBuffer(aecm->nearNoisyFrameBuf);
583 WebRtc_InitBuffer(aecm->nearCleanFrameBuf);
584 WebRtc_InitBuffer(aecm->outFrameBuf);
586 memset(aecm->xBuf_buf, 0, sizeof(aecm->xBuf_buf));
587 memset(aecm->dBufClean_buf, 0, sizeof(aecm->dBufClean_buf));
588 memset(aecm->dBufNoisy_buf, 0, sizeof(aecm->dBufNoisy_buf));
589 memset(aecm->outBuf_buf, 0, sizeof(aecm->outBuf_buf));
591 aecm->seed = 666;
592 aecm->totCount = 0;
594 if (WebRtc_InitDelayEstimator(aecm->delay_estimator) != 0) {
598 memset(aecm->far_history, 0, sizeof(uint16_t) * PART_LEN1 * MAX_DELAY);
599 memset(aecm->far_q_domains, 0, sizeof(int) * MAX_DELAY);
600 aecm->far_history_pos = MAX_DELAY;
602 aecm->nlpFlag = 1;
603 aecm->fixedDelay = -1;
605 aecm->dfaCleanQDomain = 0;
606 aecm->dfaCleanQDomainOld = 0;
607 aecm->dfaNoisyQDomain = 0;
608 aecm->dfaNoisyQDomainOld = 0;
610 memset(aecm->nearLogEnergy, 0, sizeof(aecm->nearLogEnergy));
611 aecm->farLogEnergy = 0;
612 memset(aecm->echoAdaptLogEnergy, 0, sizeof(aecm->echoAdaptLogEnergy));
613 memset(aecm->echoStoredLogEnergy, 0, sizeof(aecm->echoStoredLogEnergy));
618 WebRtcAecm_InitEchoPathCore(aecm, kChannelStored8kHz);
622 WebRtcAecm_InitEchoPathCore(aecm, kChannelStored16kHz);
625 memset(aecm->echoFilt, 0, sizeof(aecm->echoFilt));
626 memset(aecm->nearFilt, 0, sizeof(aecm->nearFilt));
627 aecm->noiseEstCtr = 0;
629 aecm->cngMode = AecmTrue;
631 memset(aecm->noiseEstTooLowCtr, 0, sizeof(aecm->noiseEstTooLowCtr));
632 memset(aecm->noiseEstTooHighCtr, 0, sizeof(aecm->noiseEstTooHighCtr));
636 aecm->noiseEst[i] = (tmp32 << 8);
642 aecm->noiseEst[i] = (tmp32 << 8);
645 aecm->farEnergyMin = WEBRTC_SPL_WORD16_MAX;
646 aecm->farEnergyMax = WEBRTC_SPL_WORD16_MIN;
647 aecm->farEnergyMaxMin = 0;
648 aecm->farEnergyVAD = FAR_ENERGY_MIN; // This prevents false speech detection at the
650 aecm->farEnergyMSE = 0;
651 aecm->currentVADValue = 0;
652 aecm->vadUpdateCount = 0;
653 aecm->firstVAD = 1;
655 aecm->startupState = 0;
656 aecm->supGain = SUPGAIN_DEFAULT;
657 aecm->supGainOld = SUPGAIN_DEFAULT;
659 aecm->supGainErrParamA = SUPGAIN_ERROR_PARAM_A;
660 aecm->supGainErrParamD = SUPGAIN_ERROR_PARAM_D;
661 aecm->supGainErrParamDiffAB = SUPGAIN_ERROR_PARAM_A - SUPGAIN_ERROR_PARAM_B;
662 aecm->supGainErrParamDiffBD = SUPGAIN_ERROR_PARAM_B - SUPGAIN_ERROR_PARAM_D;
688 int WebRtcAecm_Control(AecmCore_t *aecm, int delay, int nlpFlag)
690 aecm->nlpFlag = nlpFlag;
691 aecm->fixedDelay = delay;
696 int WebRtcAecm_FreeCore(AecmCore_t *aecm)
698 if (aecm == NULL)
703 WebRtc_FreeBuffer(aecm->farFrameBuf);
704 WebRtc_FreeBuffer(aecm->nearNoisyFrameBuf);
705 WebRtc_FreeBuffer(aecm->nearCleanFrameBuf);
706 WebRtc_FreeBuffer(aecm->outFrameBuf);
708 WebRtc_FreeDelayEstimator(aecm->delay_estimator);
709 free(aecm);
714 int WebRtcAecm_ProcessFrame(AecmCore_t * aecm,
729 WebRtcAecm_BufferFarFrame(aecm, farend, FRAME_LEN);
730 WebRtcAecm_FetchFarFrame(aecm, farFrame, FRAME_LEN, aecm->knownDelay);
734 WebRtc_WriteBuffer(aecm->farFrameBuf, farFrame, FRAME_LEN);
735 WebRtc_WriteBuffer(aecm->nearNoisyFrameBuf, nearendNoisy, FRAME_LEN);
738 WebRtc_WriteBuffer(aecm->nearCleanFrameBuf, nearendClean, FRAME_LEN);
742 while (WebRtc_available_read(aecm->farFrameBuf) >= PART_LEN)
749 WebRtc_ReadBuffer(aecm->farFrameBuf, (void**) &far_block_ptr, far_block,
751 WebRtc_ReadBuffer(aecm->nearNoisyFrameBuf,
760 WebRtc_ReadBuffer(aecm->nearCleanFrameBuf,
764 if (WebRtcAecm_ProcessBlock(aecm,
774 if (WebRtcAecm_ProcessBlock(aecm,
784 WebRtc_WriteBuffer(aecm->outFrameBuf, outBlock, PART_LEN);
789 size = (int) WebRtc_available_read(aecm->outFrameBuf);
792 WebRtc_MoveReadPtr(aecm->outFrameBuf, size - FRAME_LEN);
796 WebRtc_ReadBuffer(aecm->outFrameBuf, (void**) &out_ptr, out, FRAME_LEN);
847 // @param aecm [i/o] Handle of the AECM instance.
851 // Q(aecm->dfaQDomain).
854 void WebRtcAecm_CalcEnergies(AecmCore_t * aecm,
878 memmove(aecm->nearLogEnergy + 1, aecm->nearLogEnergy,
891 tmp16 -= WEBRTC_SPL_LSHIFT_W16(aecm->dfaNoisyQDomain, 8);
893 aecm->nearLogEnergy[0] = tmp16;
896 WebRtcAecm_CalcLinearEnergies(aecm, far_spectrum, echoEst, &tmpFar, &tmpAdapt, &tmpStored);
899 memmove(aecm->echoAdaptLogEnergy + 1, aecm->echoAdaptLogEnergy,
901 memmove(aecm->echoStoredLogEnergy + 1, aecm->echoStoredLogEnergy,
915 aecm->farLogEnergy = tmp16;
928 aecm->echoAdaptLogEnergy[0] = tmp16;
941 aecm->echoStoredLogEnergy[0] = tmp16;
944 if (aecm->farLogEnergy > FAR_ENERGY_MIN)
946 if (aecm->startupState == 0)
953 aecm->farEnergyMin = WebRtcAecm_AsymFilt(aecm->farEnergyMin, aecm->farLogEnergy,
955 aecm->farEnergyMax = WebRtcAecm_AsymFilt(aecm->farEnergyMax, aecm->farLogEnergy,
957 aecm->farEnergyMaxMin = (aecm->farEnergyMax - aecm->farEnergyMin);
960 tmp16 = 2560 - aecm->farEnergyMin;
970 if ((aecm->startupState == 0) | (aecm->vadUpdateCount > 1024))
973 aecm->farEnergyVAD = aecm->farEnergyMin + tmp16;
976 if (aecm->farEnergyVAD > aecm->farLogEnergy)
978 aecm->farEnergyVAD += WEBRTC_SPL_RSHIFT_W16(aecm->farLogEnergy +
980 aecm->farEnergyVAD,
982 aecm->vadUpdateCount = 0;
985 aecm->vadUpdateCount++;
989 aecm->farEnergyMSE = aecm->farEnergyVAD + (1 << 8);
993 if (aecm->farLogEnergy > aecm->farEnergyVAD)
995 if ((aecm->startupState == 0) | (aecm->farEnergyMaxMin > FAR_ENERGY_DIFF))
998 aecm->currentVADValue = 1;
1002 aecm->currentVADValue = 0;
1004 if ((aecm->currentVADValue) && (aecm->firstVAD))
1006 aecm->firstVAD = 0;
1007 if (aecm->echoAdaptLogEnergy[0] > aecm->nearLogEnergy[0])
1014 aecm->channelAdapt16[i] >>= 3;
1017 aecm->echoAdaptLogEnergy[0] -= (3 << 8);
1018 aecm->firstVAD = 1;
1028 // @param aecm [in] Handle of the AECM instance.
1032 WebRtc_Word16 WebRtcAecm_CalcStepSize(AecmCore_t * const aecm)
1041 if (!aecm->currentVADValue)
1045 } else if (aecm->startupState > 0)
1047 if (aecm->farEnergyMin >= aecm->farEnergyMax)
1052 tmp16 = (aecm->farLogEnergy - aecm->farEnergyMin);
1054 tmp32 = WebRtcSpl_DivW32W16(tmp32, aecm->farEnergyMaxMin);
1073 // @param aecm [i/o] Handle of the AECM instance.
1076 // @param dfa [in] Absolute value of the nearend signal (Q[aecm->dfaQDomain])
1080 void WebRtcAecm_UpdateChannel(AecmCore_t * aecm,
1108 zerosCh = WebRtcSpl_NormU32(aecm->channelAdapt32[i]);
1113 tmpU32no1 = WEBRTC_SPL_UMUL_32_16(aecm->channelAdapt32[i],
1121 WEBRTC_SPL_RSHIFT_W32(aecm->channelAdapt32[i], shiftChFar),
1133 tmp16no1 = zerosDfa - 2 + aecm->dfaNoisyQDomain -
1142 dfaQ = RESOLUTION_CHANNEL32 + far_q - aecm->dfaNoisyQDomain -
1157 // tmp32no1 = dfa[i] - (aecm->channelAdapt[i] * far_spectrum[i])
1159 // aecm->channelAdapt[i] += (2^mu) * tmp32no1
1202 aecm->channelAdapt32[i] = WEBRTC_SPL_ADD_SAT_W32(aecm->channelAdapt32[i],
1204 if (aecm->channelAdapt32[i] < 0)
1207 aecm->channelAdapt32[i] = 0;
1209 aecm->channelAdapt16[i]
1210 = (WebRtc_Word16)WEBRTC_SPL_RSHIFT_W32(aecm->channelAdapt32[i], 16);
1217 if ((aecm->startupState == 0) & (aecm->currentVADValue))
1221 WebRtcAecm_StoreAdaptiveChannel(aecm, far_spectrum, echoEst);
1224 if (aecm->farLogEnergy < aecm->farEnergyMSE)
1226 aecm->mseChannelCount = 0;
1229 aecm->mseChannelCount++;
1232 if (aecm->mseChannelCount >= (MIN_MSE_COUNT + 10))
1241 tmp32no1 = ((WebRtc_Word32)aecm->echoStoredLogEnergy[i]
1242 - (WebRtc_Word32)aecm->nearLogEnergy[i]);
1246 tmp32no1 = ((WebRtc_Word32)aecm->echoAdaptLogEnergy[i]
1247 - (WebRtc_Word32)aecm->nearLogEnergy[i]);
1252 & ((aecm->mseStoredOld << MSE_RESOLUTION) < (MIN_MSE_DIFF
1253 * aecm->mseAdaptOld)))
1257 WebRtcAecm_ResetAdaptiveChannel(aecm);
1259 < aecm->mseThreshold) & (aecm->mseAdaptOld < aecm->mseThreshold))
1264 WebRtcAecm_StoreAdaptiveChannel(aecm, far_spectrum, echoEst);
1267 if (aecm->mseThreshold == WEBRTC_SPL_WORD32_MAX)
1269 aecm->mseThreshold = (mseAdapt + aecm->mseAdaptOld);
1272 aecm->mseThreshold += WEBRTC_SPL_MUL_16_16_RSFT(mseAdapt
1273 - WEBRTC_SPL_MUL_16_16_RSFT(aecm->mseThreshold, 5, 3), 205, 8);
1279 aecm->mseChannelCount = 0;
1282 aecm->mseStoredOld = mseStored;
1283 aecm->mseAdaptOld = mseAdapt;
1294 // @param aecm [i/n] Handle of the AECM instance.
1299 static WebRtc_Word16 CalcSuppressionGain(AecmCore_t * const aecm)
1311 if (!aecm->currentVADValue)
1318 tmp16no1 = (aecm->nearLogEnergy[0] - aecm->echoStoredLogEnergy[0] - ENERGY_DEV_OFFSET);
1327 tmp32no1 = WEBRTC_SPL_MUL_16_16(aecm->supGainErrParamDiffAB, dE);
1330 supGain = aecm->supGainErrParamA - tmp16no1;
1333 tmp32no1 = WEBRTC_SPL_MUL_16_16(aecm->supGainErrParamDiffBD,
1338 supGain = aecm->supGainErrParamD + tmp16no1;
1343 supGain = aecm->supGainErrParamD;
1347 if (supGain > aecm->supGainOld)
1352 tmp16no1 = aecm->supGainOld;
1354 aecm->supGainOld = supGain;
1355 if (tmp16no1 < aecm->supGain)
1357 aecm->supGain += (WebRtc_Word16)((tmp16no1 - aecm->supGain) >> 4);
1360 aecm->supGain += (WebRtc_Word16)((tmp16no1 - aecm->supGain) >> 4);
1365 return aecm->supGain;
1503 int WebRtcAecm_ProcessBlock(AecmCore_t * aecm,
1566 if (aecm->startupState < 2)
1568 aecm->startupState = (aecm->totCount >= CONV_LEN) + (aecm->totCount >= CONV_LEN2);
1573 memcpy(aecm->xBuf + PART_LEN, farend, sizeof(WebRtc_Word16) * PART_LEN);
1574 memcpy(aecm->dBufNoisy + PART_LEN, nearendNoisy, sizeof(WebRtc_Word16) * PART_LEN);
1577 memcpy(aecm->dBufClean + PART_LEN, nearendClean, sizeof(WebRtc_Word16) * PART_LEN);
1587 far_q = TimeToFrequencyDomain(aecm->xBuf,
1593 zerosDBufNoisy = TimeToFrequencyDomain(aecm->dBufNoisy,
1597 aecm->dfaNoisyQDomainOld = aecm->dfaNoisyQDomain;
1598 aecm->dfaNoisyQDomain = (WebRtc_Word16)zerosDBufNoisy;
1604 aecm->dfaCleanQDomainOld = aecm->dfaNoisyQDomainOld;
1605 aecm->dfaCleanQDomain = aecm->dfaNoisyQDomain;
1610 zerosDBufClean = TimeToFrequencyDomain(aecm->dBufClean,
1614 aecm->dfaCleanQDomainOld = aecm->dfaCleanQDomain;
1615 aecm->dfaCleanQDomain = (WebRtc_Word16)zerosDBufClean;
1630 UpdateFarHistory(aecm, xfa, far_q);
1631 delay = WebRtc_DelayEstimatorProcessFix(aecm->delay_estimator,
1648 if (aecm->fixedDelay >= 0)
1651 delay = aecm->fixedDelay;
1664 far_spectrum_ptr = AlignedFarend(aecm, &far_q, delay);
1672 WebRtcAecm_CalcEnergies(aecm,
1679 mu = WebRtcAecm_CalcStepSize(aecm);
1682 aecm->totCount++;
1686 WebRtcAecm_UpdateChannel(aecm, far_spectrum_ptr, zerosXBuf, dfaNoisy, mu, echoEst32);
1687 supGain = CalcSuppressionGain(aecm);
1704 tmp32no1 = echoEst32[i] - aecm->echoFilt[i];
1705 aecm->echoFilt[i] += WEBRTC_SPL_RSHIFT_W32(WEBRTC_SPL_MUL_32_16(tmp32no1, 50), 8);
1707 zeros32 = WebRtcSpl_NormW32(aecm->echoFilt[i]) + 1;
1712 // Result in Q(RESOLUTION_CHANNEL+RESOLUTION_SUPGAIN+aecm->xfaQDomainBuf[diff])
1713 echoEst32Gained = WEBRTC_SPL_UMUL_32_16((WebRtc_UWord32)aecm->echoFilt[i],
1716 resolutionDiff += (aecm->dfaCleanQDomain - zerosXBuf);
1721 resolutionDiff += (aecm->dfaCleanQDomain - zerosXBuf);
1724 echoEst32Gained = WEBRTC_SPL_UMUL_32_16((WebRtc_UWord32)aecm->echoFilt[i],
1731 (WebRtc_UWord32)WEBRTC_SPL_RSHIFT_W32(aecm->echoFilt[i], tmp16no1),
1736 zeros16 = WebRtcSpl_NormW16(aecm->nearFilt[i]);
1737 if ((zeros16 < (aecm->dfaCleanQDomain - aecm
1738 & (aecm->nearFilt[i]))
1740 tmp16no1 = WEBRTC_SPL_SHIFT_W16(aecm->nearFilt[i], zeros16);
1741 qDomainDiff = zeros16 - aecm->dfaCleanQDomain + aecm->dfaCleanQDomainOld;
1744 tmp16no1 = WEBRTC_SPL_SHIFT_W16(aecm->nearFilt[i],
1745 aecm->dfaCleanQDomain - aecm->dfaCleanQDomainOld);
1755 aecm->nearFilt[i] = WEBRTC_SPL_WORD16_MAX;
1758 aecm->nearFilt[i] = WEBRTC_SPL_SHIFT_W16(tmp16no2, -qDomainDiff);
1765 } else if (aecm->nearFilt[i] == 0)
1772 echoEst32Gained += (WebRtc_UWord32)(aecm->nearFilt[i] >> 1);
1773 tmpU32 = WebRtcSpl_DivU32U16(echoEst32Gained, (WebRtc_UWord16)aecm->nearFilt[i]);
1802 if (aecm->mult == 2)
1838 if (aecm->nlpFlag)
1888 if (aecm->cngMode == AecmTrue)
1890 ComfortNoise(aecm, ptrDfaClean, efw, hnl);
1903 WebRtcAecm_InverseFFTAndWindow(aecm, fft, efw, output, nearendClean);
1911 // \param[in] aecm Handle of the AECM instance.
1912 // \param[in] dfa Absolute value of the nearend signal (Q[aecm->dfaQDomain]).
1913 // \param[in,out] outReal Real part of the output signal (Q[aecm->dfaQDomain]).
1914 // \param[in,out] outImag Imaginary part of the output signal (Q[aecm->dfaQDomain]).
1917 static void ComfortNoise(AecmCore_t* aecm,
1932 WebRtc_Word16 shiftFromNearToNoise = kNoiseEstQDomain - aecm->dfaCleanQDomain;
1938 if (aecm->noiseEstCtr < 100)
1941 aecm->noiseEstCtr++;
1956 if (outLShift32 < aecm->noiseEst[i])
1959 aecm->noiseEstTooLowCtr[i] = 0;
1961 if (aecm->noiseEst[i] < (1 << minTrackShift))
1966 aecm->noiseEstTooHighCtr[i]++;
1967 if (aecm->noiseEstTooHighCtr[i] >= kNoiseEstIncCount)
1969 aecm->noiseEst[i]--;
1970 aecm->noiseEstTooHighCtr[i] = 0; // Reset the counter
1975 aecm->noiseEst[i] -= ((aecm->noiseEst[i] - outLShift32) >> minTrackShift);
1980 aecm->noiseEstTooHighCtr[i] = 0;
1982 if ((aecm->noiseEst[i] >> 19) > 0)
1987 aecm->noiseEst[i] >>= 11;
1988 aecm->noiseEst[i] *= 2049;
1990 else if ((aecm->noiseEst[i] >> 11) > 0)
1993 aecm->noiseEst[i] *= 2049;
1994 aecm->noiseEst[i] >>= 11;
2000 aecm->noiseEstTooLowCtr[i]++;
2001 if (aecm->noiseEstTooLowCtr[i] >= kNoiseEstIncCount)
2003 aecm->noiseEst[i] += (aecm->noiseEst[i] >> 9) + 1;
2004 aecm->noiseEstTooLowCtr[i] = 0; // Reset counter
2012 tmp32 = WEBRTC_SPL_RSHIFT_W32(aecm->noiseEst[i], shiftFromNearToNoise);
2016 aecm->noiseEst[i] = WEBRTC_SPL_LSHIFT_W32(tmp32, shiftFromNearToNoise);
2026 WebRtcSpl_RandUArray(randW16, PART_LEN, &aecm->seed);
2066 void WebRtcAecm_BufferFarFrame(AecmCore_t* const aecm,
2073 while (aecm->farBufWritePos + writeLen > FAR_BUF_LEN)
2076 writeLen = FAR_BUF_LEN - aecm->farBufWritePos;
2077 memcpy(aecm->farBuf + aecm->farBufWritePos, farend + writePos,
2079 aecm->farBufWritePos = 0;
2084 memcpy(aecm->farBuf + aecm->farBufWritePos, farend + writePos,
2086 aecm->farBufWritePos += writeLen;
2089 void WebRtcAecm_FetchFarFrame(AecmCore_t * const aecm, WebRtc_Word16 * const farend,
2094 int delayChange = knownDelay - aecm->lastKnownDelay;
2096 aecm->farBufReadPos -= delayChange;
2099 while (aecm->farBufReadPos < 0)
2101 aecm->farBufReadPos += FAR_BUF_LEN;
2103 while (aecm->farBufReadPos > FAR_BUF_LEN - 1)
2105 aecm->farBufReadPos -= FAR_BUF_LEN;
2108 aecm->lastKnownDelay = knownDelay;
2111 while (aecm->farBufReadPos + readLen > FAR_BUF_LEN)
2115 readLen = FAR_BUF_LEN - aecm->farBufReadPos;
2116 memcpy(farend + readPos, aecm->farBuf + aecm->farBufReadPos,
2118 aecm->farBufReadPos = 0;
2122 memcpy(farend + readPos, aecm->farBuf + aecm->farBufReadPos,
2124 aecm->farBufReadPos += readLen;