for (i = 0; i < samples; i++)
{
// For lower band
- tmp32 = WEBRTC_SPL_MUL_16_U16(in_mic[i], gain);
- sample = WEBRTC_SPL_RSHIFT_W32(tmp32, 12);
+ sample = (in_mic[i] * gain) >> 12;
if (sample > 32767)
{
in_mic[i] = 32767;
// For higher band
if (stt->fs == 32000)
{
- tmp32 = WEBRTC_SPL_MUL_16_U16(in_mic_H[i], gain);
- sample = WEBRTC_SPL_RSHIFT_W32(tmp32, 12);
+ sample = (in_mic_H[i] * gain) >> 12;
if (sample > 32767)
{
in_mic_H[i] = 32767;
ptr = stt->Rxx16w32_array[0];
}
- for (i = 0; i < WEBRTC_SPL_RSHIFT_W16(M, 1); i++)
+ for (i = 0; i < M / 2; i++)
{
if (stt->fs == 16000)
{
stt->lowLevelSignal = 0;
}
- micLevelTmp = WEBRTC_SPL_LSHIFT_W32(micLevelIn, stt->scale);
+ micLevelTmp = micLevelIn << stt->scale;
/* Set desired level */
gainIdx = stt->micVol;
if (stt->micVol > stt->maxAnalog)
}
for (ii = 0; ii < samples; ii++)
{
- tmpFlt = WEBRTC_SPL_RSHIFT_W32(WEBRTC_SPL_MUL_16_U16(in_near[ii], gain), 10);
+ tmpFlt = (in_near[ii] * gain) >> 10;
if (tmpFlt > 32767)
{
tmpFlt = 32767;
in_near[ii] = (int16_t)tmpFlt;
if (stt->fs == 32000)
{
- tmpFlt = WEBRTC_SPL_MUL_16_U16(in_near_H[ii], gain);
- tmpFlt = WEBRTC_SPL_RSHIFT_W32(tmpFlt, 10);
+ tmpFlt = (in_near_H[ii] * gain) >> 10;
if (tmpFlt > 32767)
{
tmpFlt = 32767;
/* Set the level we (finally) used */
stt->micGainIdx = gainIdx;
// *micLevelOut = stt->micGainIdx;
- *micLevelOut = WEBRTC_SPL_RSHIFT_W32(stt->micGainIdx, stt->scale);
+ *micLevelOut = stt->micGainIdx >> stt->scale;
/* Add to Mic as if it was the output from a true microphone */
if (WebRtcAgc_AddMic(agcInst, in_near, in_near_H, samples) != 0)
{
{
/* Lower the analog target level since we have reached its maximum */
zeros = WebRtcSpl_NormW32(stt->Rxx160_LPw32);
- stt->targetIdxOffset = WEBRTC_SPL_RSHIFT_W16((3 * zeros) - stt->targetIdx - 2, 2);
+ stt->targetIdxOffset = (3 * zeros - stt->targetIdx - 2) / 4;
}
#endif
/* Check if the signal is saturated */
for (i = 0; i < 10; i++)
{
- tmpW16 = (int16_t)WEBRTC_SPL_RSHIFT_W32(env[i], 20);
+ tmpW16 = (int16_t)(env[i] >> 20);
if (tmpW16 > 875)
{
stt->envSum += tmpW16;
stt->msZero = 0;
/* Increase microphone level only if it's less than 50% */
- midVal = WEBRTC_SPL_RSHIFT_W32(stt->maxAnalog + stt->minLevel + 1, 1);
+ midVal = (stt->maxAnalog + stt->minLevel + 1) / 2;
if (*inMicLevel < midVal)
{
/* *inMicLevel *= 1.1; */
- tmp32 = WEBRTC_SPL_MUL(1126, *inMicLevel);
- *inMicLevel = WEBRTC_SPL_RSHIFT_W32(tmp32, 10);
+ *inMicLevel = (1126 * *inMicLevel) >> 10;
/* Reduces risk of a muted mic repeatedly triggering excessive levels due
* to zero signal detection. */
*inMicLevel = WEBRTC_SPL_MIN(*inMicLevel, stt->zeroCtrlMax);
if (stt->vadMic.stdLongTerm < 4500)
{
/* Scale between min and max threshold */
- vadThresh += WEBRTC_SPL_RSHIFT_W16(4500 - stt->vadMic.stdLongTerm, 1);
+ vadThresh += (4500 - stt->vadMic.stdLongTerm) / 2;
}
/* stt->vadThreshold = (31 * stt->vadThreshold + vadThresh) / 32; */
tmp32 = (int32_t)vadThresh;
tmp32 += WEBRTC_SPL_MUL_16_16((int16_t)31, stt->vadThreshold);
- stt->vadThreshold = (int16_t)WEBRTC_SPL_RSHIFT_W32(tmp32, 5);
+ stt->vadThreshold = (int16_t)(tmp32 >> 5);
}
}
Agc_t *stt;
stt = (Agc_t *)state;
- inMicLevelTmp = WEBRTC_SPL_LSHIFT_W32(inMicLevel, stt->scale);
+ inMicLevelTmp = inMicLevel << stt->scale;
if (inMicLevelTmp > stt->maxAnalog)
{
{
int32_t tmpVol;
stt->firstCall = 1;
- tmp32 = WEBRTC_SPL_RSHIFT_W32((stt->maxLevel - stt->minLevel) * (int32_t)51, 9);
+ tmp32 = ((stt->maxLevel - stt->minLevel) * 51) >> 9;
tmpVol = (stt->minLevel + tmp32);
/* If the mic level is very low at start, increase it! */
/* If the mic level was manually changed to a very low value raise it! */
if ((inMicLevelTmp != stt->micVol) && (inMicLevelTmp < stt->minOutput))
{
- tmp32 = WEBRTC_SPL_RSHIFT_W32((stt->maxLevel - stt->minLevel) * (int32_t)51, 9);
+ tmp32 = ((stt->maxLevel - stt->minLevel) * 51) >> 9;
inMicLevelTmp = (stt->minLevel + tmp32);
stt->micVol = inMicLevelTmp;
#ifdef MIC_LEVEL_FEEDBACK
* Rxx160_LP is adjusted down because it is so slow it could
* cause the AGC to make wrong decisions. */
/* stt->Rxx160_LPw32 *= 0.875; */
- stt->Rxx160_LPw32 = WEBRTC_SPL_MUL(WEBRTC_SPL_RSHIFT_W32(stt->Rxx160_LPw32, 3), 7);
+ stt->Rxx160_LPw32 = (stt->Rxx160_LPw32 / 8) * 7;
stt->zeroCtrlMax = stt->micVol;
/* stt->micVol *= 0.903; */
tmp32 = inMicLevelTmp - stt->minLevel;
tmpU32 = WEBRTC_SPL_UMUL(29591, (uint32_t)(tmp32));
- stt->micVol = (int32_t)WEBRTC_SPL_RSHIFT_U32(tmpU32, 15) + stt->minLevel;
+ stt->micVol = (tmpU32 >> 15) + stt->minLevel;
if (stt->micVol > lastMicVol - 2)
{
stt->micVol = lastMicVol - 2;
Rxx16w32 = stt->Rxx16w32_array[0][i];
/* Rxx160w32 in Q(-7) */
- tmp32 = WEBRTC_SPL_RSHIFT_W32(Rxx16w32 - stt->Rxx16_vectorw32[stt->Rxx16pos], 3);
+ tmp32 = (Rxx16w32 - stt->Rxx16_vectorw32[stt->Rxx16pos]) >> 3;
stt->Rxx160w32 = stt->Rxx160w32 + tmp32;
stt->Rxx16_vectorw32[stt->Rxx16pos] = Rxx16w32;
}
/* Rxx16_LPw32 in Q(-4) */
- tmp32 = WEBRTC_SPL_RSHIFT_W32(Rxx16w32 - stt->Rxx16_LPw32, kAlphaShortTerm);
+ tmp32 = (Rxx16w32 - stt->Rxx16_LPw32) >> kAlphaShortTerm;
stt->Rxx16_LPw32 = (stt->Rxx16_LPw32) + tmp32;
if (vadLogRatio > stt->vadThreshold)
} else if (stt->activeSpeech == 250)
{
stt->activeSpeech += 2;
- tmp32 = WEBRTC_SPL_RSHIFT_W32(stt->Rxx16_LPw32Max, 3);
- stt->Rxx160_LPw32 = WEBRTC_SPL_MUL(tmp32, RXX_BUFFER_LEN);
+ tmp32 = stt->Rxx16_LPw32Max >> 3;
+ stt->Rxx160_LPw32 = tmp32 * RXX_BUFFER_LEN;
}
- tmp32 = WEBRTC_SPL_RSHIFT_W32(stt->Rxx160w32 - stt->Rxx160_LPw32, kAlphaLongTerm);
+ tmp32 = (stt->Rxx160w32 - stt->Rxx160_LPw32) >> kAlphaLongTerm;
stt->Rxx160_LPw32 = stt->Rxx160_LPw32 + tmp32;
if (stt->Rxx160_LPw32 > stt->upperSecondaryLimit)
/* Lower the recording level */
/* Multiply by 0.828125 which corresponds to decreasing ~0.8dB */
- tmp32 = WEBRTC_SPL_RSHIFT_W32(stt->Rxx160_LPw32, 6);
- stt->Rxx160_LPw32 = WEBRTC_SPL_MUL(tmp32, 53);
+ tmp32 = stt->Rxx160_LPw32 >> 6;
+ stt->Rxx160_LPw32 = tmp32 * 53;
/* Reduce the max gain to avoid excessive oscillation
* (but never drop below the maximum analog level).
- * stt->maxLevel = (15 * stt->maxLevel + stt->micVol) / 16;
*/
- tmp32 = (15 * stt->maxLevel) + stt->micVol;
- stt->maxLevel = WEBRTC_SPL_RSHIFT_W32(tmp32, 4);
+ stt->maxLevel = (15 * stt->maxLevel + stt->micVol) / 16;
stt->maxLevel = WEBRTC_SPL_MAX(stt->maxLevel, stt->maxAnalog);
stt->zeroCtrlMax = stt->micVol;
/* 0.95 in Q15 */
tmp32 = inMicLevelTmp - stt->minLevel;
tmpU32 = WEBRTC_SPL_UMUL(31130, (uint32_t)(tmp32));
- stt->micVol = (int32_t)WEBRTC_SPL_RSHIFT_U32(tmpU32, 15) + stt->minLevel;
+ stt->micVol = (tmpU32 >> 15) + stt->minLevel;
if (stt->micVol > lastMicVol - 1)
{
stt->micVol = lastMicVol - 1;
/* Lower the recording level */
stt->msTooHigh = 0;
/* Multiply by 0.828125 which corresponds to decreasing ~0.8dB */
- tmp32 = WEBRTC_SPL_RSHIFT_W32(stt->Rxx160_LPw32, 6);
- stt->Rxx160_LPw32 = WEBRTC_SPL_MUL(tmp32, 53);
+ stt->Rxx160_LPw32 = (stt->Rxx160_LPw32 / 64) * 53;
/* Reduce the max gain to avoid excessive oscillation
* (but never drop below the maximum analog level).
- * stt->maxLevel = (15 * stt->maxLevel + stt->micVol) / 16;
*/
- tmp32 = (15 * stt->maxLevel) + stt->micVol;
- stt->maxLevel = WEBRTC_SPL_RSHIFT_W32(tmp32, 4);
+ stt->maxLevel = (15 * stt->maxLevel + stt->micVol) / 16;
stt->maxLevel = WEBRTC_SPL_MAX(stt->maxLevel, stt->maxAnalog);
stt->zeroCtrlMax = stt->micVol;
/* 0.965 in Q15 */
tmp32 = inMicLevelTmp - stt->minLevel;
tmpU32 = WEBRTC_SPL_UMUL(31621, (uint32_t)(inMicLevelTmp - stt->minLevel));
- stt->micVol = (int32_t)WEBRTC_SPL_RSHIFT_U32(tmpU32, 15) + stt->minLevel;
+ stt->micVol = (tmpU32 >> 15) + stt->minLevel;
if (stt->micVol > lastMicVol - 1)
{
stt->micVol = lastMicVol - 1;
stt->msTooLow = 0;
/* Normalize the volume level */
- tmp32 = WEBRTC_SPL_LSHIFT_W32(inMicLevelTmp - stt->minLevel, 14);
+ tmp32 = (inMicLevelTmp - stt->minLevel) << 14;
if (stt->maxInit != stt->minLevel)
{
volNormFIX = tmp32 / (stt->maxInit - stt->minLevel);
volNormFIX, 13);
/* stt->Rxx160_LPw32 *= 1.047 [~0.2 dB]; */
- tmp32 = WEBRTC_SPL_RSHIFT_W32(stt->Rxx160_LPw32, 6);
- stt->Rxx160_LPw32 = WEBRTC_SPL_MUL(tmp32, 67);
+ stt->Rxx160_LPw32 = (stt->Rxx160_LPw32 / 64) * 67;
tmp32 = inMicLevelTmp - stt->minLevel;
tmpU32 = ((uint32_t)weightFIX * (uint32_t)(inMicLevelTmp - stt->minLevel));
- stt->micVol = (int32_t)WEBRTC_SPL_RSHIFT_U32(tmpU32, 14) + stt->minLevel;
+ stt->micVol = (tmpU32 >> 14) + stt->minLevel;
if (stt->micVol < lastMicVol + 2)
{
stt->micVol = lastMicVol + 2;
stt->msTooLow = 0;
/* Normalize the volume level */
- tmp32 = WEBRTC_SPL_LSHIFT_W32(inMicLevelTmp - stt->minLevel, 14);
+ tmp32 = (inMicLevelTmp - stt->minLevel) << 14;
if (stt->maxInit != stt->minLevel)
{
volNormFIX = tmp32 / (stt->maxInit - stt->minLevel);
volNormFIX, 13);
/* stt->Rxx160_LPw32 *= 1.047 [~0.2 dB]; */
- tmp32 = WEBRTC_SPL_RSHIFT_W32(stt->Rxx160_LPw32, 6);
- stt->Rxx160_LPw32 = WEBRTC_SPL_MUL(tmp32, 67);
+ stt->Rxx160_LPw32 = (stt->Rxx160_LPw32 / 64) * 67;
tmp32 = inMicLevelTmp - stt->minLevel;
tmpU32 = ((uint32_t)weightFIX * (uint32_t)(inMicLevelTmp - stt->minLevel));
- stt->micVol = (int32_t)WEBRTC_SPL_RSHIFT_U32(tmpU32, 14) + stt->minLevel;
+ stt->micVol = (tmpU32 >> 14) + stt->minLevel;
if (stt->micVol < lastMicVol + 1)
{
stt->micVol = lastMicVol + 1;
stt->micVol = stt->minOutput;
}
- *outMicLevel = WEBRTC_SPL_RSHIFT_W32(stt->micVol, stt->scale);
- if (*outMicLevel > WEBRTC_SPL_RSHIFT_W32(stt->maxAnalog, stt->scale))
- {
- *outMicLevel = WEBRTC_SPL_RSHIFT_W32(stt->maxAnalog, stt->scale);
- }
+ *outMicLevel = WEBRTC_SPL_MIN(stt->micVol, stt->maxAnalog) >> stt->scale;
return 0;
}
// TODO(bjornv): Investigate if we really need to scale up a small range now when we have
// a guard against zero-increments. For now, we do not support scale up (scale = 0).
stt->scale = 0;
- maxLevel = WEBRTC_SPL_LSHIFT_W32(maxLevel, stt->scale);
- minLevel = WEBRTC_SPL_LSHIFT_W32(minLevel, stt->scale);
+ maxLevel <<= stt->scale;
+ minLevel <<= stt->scale;
/* Make minLevel and maxLevel static in AdaptiveDigital */
if (stt->agcMode == kAgcModeAdaptiveDigital)
}
/* The maximum supplemental volume range is based on a vague idea
* of how much lower the gain will be than the real analog gain. */
- max_add = WEBRTC_SPL_RSHIFT_W32(maxLevel - minLevel, 2);
+ max_add = (maxLevel - minLevel) / 4;
/* Minimum/maximum volume level that can be set */
stt->minLevel = minLevel;
#endif
/* Minimum output volume is 4% higher than the available lowest volume level */
- tmp32 = WEBRTC_SPL_RSHIFT_W32((stt->maxLevel - stt->minLevel) * (int32_t)10, 8);
+ tmp32 = ((stt->maxLevel - stt->minLevel) * 10) >> 8;
stt->minOutput = (stt->minLevel + tmp32);
stt->msTooLow = 0;