audio_coding/codec/ilbc: Removed usage of WEBRTC_SPL_MUL_16_16_RSFT

The macro is defined as
#define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
    (WEBRTC_SPL_MUL_16_16(a, b) >> (c))

where the latter macro is in C defined as
(For definitions on ARMv7 and MIPS, see common_audio/signal_processing/include/spl_inl_{armv7,mips}.h)

The replacement consists of
- avoiding casts to int16_t if inputs already are int16_t
- adding explicit cast to <type> if result is assigned to <type> (other than int or int32_t)
- minor cleanups like remove of unnecessary parantheses and style changes

BUG=3348, 3353
TESTED=locally on Mac and trybots
R=kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/39139004

Cr-Commit-Position: refs/heads/master@{#8544}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8544 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
bjornv@webrtc.org 2015-03-01 19:50:41 +00:00
parent e1b84a0b2b
commit 2f6ae0de5b
13 changed files with 39 additions and 46 deletions

View File

@ -44,8 +44,7 @@ void WebRtcIlbcfix_CbMemEnergyAugmentation(
for (lagcount=20; lagcount<=39; lagcount++) {
/* Update the energy recursively to save complexity */
nrjRecursive = nrjRecursive +
WEBRTC_SPL_MUL_16_16_RSFT(*ppe, *ppe, scale);
nrjRecursive += (*ppe * *ppe) >> scale;
ppe--;
energy = nrjRecursive;

View File

@ -359,7 +359,7 @@ void WebRtcIlbcfix_CbSearch(
bits = 16 - temp2;
}
tmp = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(gains[1],gains[1], 14);
tmp = (int16_t)((gains[1] * gains[1]) >> 14);
targetEner = (int16_t)WEBRTC_SPL_SHIFT_W32(targetEner, -bits) * tmp;

View File

@ -64,8 +64,8 @@ void WebRtcIlbcfix_CbUpdateBestIndex(
scaleTmp = -energyShiftNew-tmp16+31;
scaleTmp = WEBRTC_SPL_MIN(31, scaleTmp);
gainW32 = WEBRTC_SPL_MUL_16_16_RSFT(
((int16_t)WEBRTC_SPL_SHIFT_W32(cDotNew, -tmp16)), invEnergyNew, scaleTmp);
gainW32 = ((int16_t)WEBRTC_SPL_SHIFT_W32(cDotNew, -tmp16) * invEnergyNew) >>
scaleTmp;
/* Check if criteria satisfies Gain criteria (max 1.3)
if it is larger set the gain to 1.3

View File

@ -65,7 +65,7 @@ int16_t WebRtcIlbcfix_Chebyshev(
/* tmp1W32 = x*b1 - b2 + f[i]/2 */
tmp1W32 = WEBRTC_SPL_LSHIFT_W32(b1_high * x, 1) +
WEBRTC_SPL_LSHIFT_W32(WEBRTC_SPL_MUL_16_16_RSFT(b1_low, x, 15), 1);
WEBRTC_SPL_LSHIFT_W32((b1_low * x) >> 15, 1);
tmp1W32 -= b2;
tmp1W32 += WEBRTC_SPL_LSHIFT_W32((int32_t)f[i], 13);

View File

@ -92,8 +92,9 @@ void WebRtcIlbcfix_DoThePlc(
/* Normalize and store cross^2 and the number of shifts */
shiftMax = WebRtcSpl_GetSizeInBits(WEBRTC_SPL_ABS_W32(cross))-15;
crossSquareMax = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(WEBRTC_SPL_SHIFT_W32(cross, -shiftMax),
WEBRTC_SPL_SHIFT_W32(cross, -shiftMax), 15);
crossSquareMax = (int16_t)((
(int16_t)WEBRTC_SPL_SHIFT_W32(cross, -shiftMax) *
(int16_t)WEBRTC_SPL_SHIFT_W32(cross, -shiftMax)) >> 15);
for (j=inlag-2;j<=inlag+3;j++) {
WebRtcIlbcfix_CompCorr( &cross_comp, &ener_comp,
@ -103,8 +104,9 @@ void WebRtcIlbcfix_DoThePlc(
this lag is better or not. To avoid the division,
do a cross multiplication */
shift1 = WebRtcSpl_GetSizeInBits(WEBRTC_SPL_ABS_W32(cross_comp))-15;
crossSquare = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(WEBRTC_SPL_SHIFT_W32(cross_comp, -shift1),
WEBRTC_SPL_SHIFT_W32(cross_comp, -shift1), 15);
crossSquare = (int16_t)((
(int16_t)WEBRTC_SPL_SHIFT_W32(cross_comp, -shift1) *
(int16_t)WEBRTC_SPL_SHIFT_W32(cross_comp, -shift1)) >> 15);
shift2 = WebRtcSpl_GetSizeInBits(ener)-15;
measure = (int16_t)WEBRTC_SPL_SHIFT_W32(ener, -shift2) * crossSquare;
@ -154,7 +156,7 @@ void WebRtcIlbcfix_DoThePlc(
scale2=(int16_t)WebRtcSpl_NormW32(ener)-16;
tmp2=(int16_t)WEBRTC_SPL_SHIFT_W32(ener, scale2);
denom=(int16_t)WEBRTC_SPL_MUL_16_16_RSFT(tmp1, tmp2, 16); /* denom in Q(scale1+scale2-16) */
denom = (int16_t)((tmp1 * tmp2) >> 16); /* in Q(scale1+scale2-16) */
/* Square the cross correlation and norm it such that max_perSquare
will be in Q15 after the division */
@ -209,7 +211,8 @@ void WebRtcIlbcfix_DoThePlc(
}
/* pitch fact is approximated by first order */
tmpW32 = (int32_t)WebRtcIlbcfix_kPlcPitchFact[ind] +
WEBRTC_SPL_MUL_16_16_RSFT(WebRtcIlbcfix_kPlcPfSlope[ind], (max_perSquare-WebRtcIlbcfix_kPlcPerSqr[ind]), 11);
((WebRtcIlbcfix_kPlcPfSlope[ind] *
(max_perSquare - WebRtcIlbcfix_kPlcPerSqr[ind])) >> 11);
pitchfact = (int16_t)WEBRTC_SPL_MIN(tmpW32, 32767); /* guard against overflow */
@ -253,25 +256,21 @@ void WebRtcIlbcfix_DoThePlc(
if (i<80) {
tot_gain=use_gain;
} else if (i<160) {
tot_gain=(int16_t)WEBRTC_SPL_MUL_16_16_RSFT(31130, use_gain, 15); /* 0.95*use_gain */
tot_gain = (int16_t)((31130 * use_gain) >> 15); /* 0.95*use_gain */
} else {
tot_gain=(int16_t)WEBRTC_SPL_MUL_16_16_RSFT(29491, use_gain, 15); /* 0.9*use_gain */
tot_gain = (int16_t)((29491 * use_gain) >> 15); /* 0.9*use_gain */
}
/* mix noise and pitch repeatition */
PLCresidual[i] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(
tot_gain,
(pitchfact * PLCresidual[i] + (32767 - pitchfact) * randvec[i] +
16384) >> 15,
15);
PLCresidual[i] = (int16_t)((tot_gain *
((pitchfact * PLCresidual[i] + (32767 - pitchfact) * randvec[i] +
16384) >> 15)) >> 15);
/* Shifting down the result one step extra to ensure that no overflow
will occur */
energy += WEBRTC_SPL_MUL_16_16_RSFT(PLCresidual[i],
PLCresidual[i], (iLBCdec_inst->prevScale+1));
energy += (PLCresidual[i] * PLCresidual[i]) >>
(iLBCdec_inst->prevScale + 1);
}
/* less than 30 dB, use only noise */

View File

@ -149,8 +149,7 @@ int WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
ENH_BLOCKL_HALF, shifts);
enerSh = 15-WebRtcSpl_GetSizeInBits(ener);
corr16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(corrmax[i], corrSh);
corr16[i] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(corr16[i],
corr16[i], 16);
corr16[i] = (int16_t)((corr16[i] * corr16[i]) >> 16);
en16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(ener, enerSh);
totsh[i] = enerSh - WEBRTC_SPL_LSHIFT_W32(corrSh, 1);
}
@ -160,14 +159,12 @@ int WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
for (i=1; i<3; i++) {
if (totsh[ind] > totsh[i]) {
sh = WEBRTC_SPL_MIN(31, totsh[ind]-totsh[i]);
if (corr16[ind] * en16[i] <
WEBRTC_SPL_MUL_16_16_RSFT(corr16[i], en16[ind], sh)) {
if (corr16[ind] * en16[i] < (corr16[i] * en16[ind]) >> sh) {
ind = i;
}
} else {
sh = WEBRTC_SPL_MIN(31, totsh[i]-totsh[ind]);
if (WEBRTC_SPL_MUL_16_16_RSFT(corr16[ind], en16[i], sh) <
corr16[i] * en16[ind]) {
if ((corr16[ind] * en16[i]) >> sh < corr16[i] * en16[ind]) {
ind = i;
}
}
@ -297,8 +294,8 @@ int WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
tmpW16ptr=&plc_pred[plc_blockl-16];
for (i=16;i>0;i--) {
(*tmpW16ptr)=(int16_t)WEBRTC_SPL_MUL_16_16_RSFT(
(*tmpW16ptr), (SqrtEnChange+(win>>1)), 14);
*tmpW16ptr = (int16_t)(
(*tmpW16ptr * (SqrtEnChange + (win >> 1))) >> 14);
/* multiply by (2.0*SqrtEnChange+win) */
win += inc;
@ -319,10 +316,9 @@ int WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */
enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
for (i=0; i<plc_blockl; i++) {
win+=inc;
*enh_bufPtr1 =
(int16_t)WEBRTC_SPL_MUL_16_16_RSFT((*enh_bufPtr1), win, 14);
*enh_bufPtr1 += (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(
(16384-win), plc_pred[plc_blockl-1-i], 14);
*enh_bufPtr1 = (int16_t)((*enh_bufPtr1 * win) >> 14);
*enh_bufPtr1 += (int16_t)(
((16384 - win) * plc_pred[plc_blockl - 1 - i]) >> 14);
enh_bufPtr1--;
}
} else {

View File

@ -68,7 +68,7 @@ void WebRtcIlbcfix_GetLspPoly(
low = (int16_t)((fPtr[-1] - ((int32_t)high << 16)) >> 1);
tmpW32 = WEBRTC_SPL_LSHIFT_W32(high * *lspPtr, 2) +
WEBRTC_SPL_LSHIFT_W32(WEBRTC_SPL_MUL_16_16_RSFT(low, (*lspPtr), 15), 2);
WEBRTC_SPL_LSHIFT_W32((low * *lspPtr) >> 15, 2);
(*fPtr) += fPtr[-2];
(*fPtr) -= tmpW32;

View File

@ -37,8 +37,8 @@ void WebRtcIlbcfix_InterpolateSamples(
ppi = CBmem+lMem-j-24;
for (i=0; i<4; i++) {
*tmpPtr++ = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(WebRtcIlbcfix_kAlpha[temp2],*ppo, 15) +
(int16_t)WEBRTC_SPL_MUL_16_16_RSFT(WebRtcIlbcfix_kAlpha[temp1], *ppi, 15);
*tmpPtr++ = (int16_t)((WebRtcIlbcfix_kAlpha[temp2] * *ppo) >> 15) +
(int16_t)((WebRtcIlbcfix_kAlpha[temp1] * *ppi) >> 15);
ppo++;
ppi++;

View File

@ -36,7 +36,7 @@ void WebRtcIlbcfix_Lsf2Lsp(
for(i=0; i<m; i++)
{
freq = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(lsf[i], 20861, 15);
freq = (int16_t)((lsf[i] * 20861) >> 15);
/* 20861: 1.0/(2.0*PI) in Q17 */
/*
Upper 8 bits give the index k and

View File

@ -68,7 +68,7 @@ void WebRtcIlbcfix_Lsp2Lsf(
*/
/* tmp (linear offset) in Q16 */
tmp = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(WebRtcIlbcfix_kAcosDerivative[k],diff, 11);
tmp = (int16_t)((WebRtcIlbcfix_kAcosDerivative[k] * diff) >> 11);
/* freq in Q16 */
freq = (k << 9) + tmp;

View File

@ -122,7 +122,7 @@ void WebRtcIlbcfix_Poly2Lsp(
y <<= shifts;
y = (int16_t)WebRtcSpl_DivW32W16(536838144, y); /* 1/(yhigh-ylow) */
tmpW32 = WEBRTC_SPL_MUL_16_16_RSFT(x, y, (19-shifts));
tmpW32 = (x * y) >> (19 - shifts);
/* y=(xhigh-xlow)/(yhigh-ylow) */
y = (int16_t)(tmpW32&0xFFFF);
@ -131,7 +131,7 @@ void WebRtcIlbcfix_Poly2Lsp(
y = -y;
}
/* tmpW32 = ylow*(xhigh-xlow)/(yhigh-ylow) */
tmpW32 = WEBRTC_SPL_MUL_16_16_RSFT(ylow, y, 10);
tmpW32 = (ylow * y) >> 10;
xint = xlow-(int16_t)(tmpW32&0xFFFF);
}

View File

@ -53,10 +53,9 @@ void WebRtcIlbcfix_Window32W32(
y_low = (int16_t)((y[i] - temp) >> 1);
/* Calculate z by a 32 bit multiplication using both low and high from x and y */
temp = (x_hi * y_hi) << 1;
temp = (temp + (WEBRTC_SPL_MUL_16_16_RSFT(x_hi, y_low, 14)));
temp = ((x_hi * y_hi) << 1) + ((x_hi * y_low) >> 14);
z[i] = (temp + (WEBRTC_SPL_MUL_16_16_RSFT(x_low, y_hi, 14)));
z[i] = temp + ((x_low * y_hi) >> 14);
}
WebRtcSpl_VectorBitShiftW32(z, N, z, left_shifts);

View File

@ -92,7 +92,7 @@ int WebRtcIlbcfix_XcorrCoef(
EnergyMod=(int16_t)WEBRTC_SPL_SHIFT_W32(Energy, Energyscale);
/* Square cross correlation and store upper int16_t */
crossCorrSqMod=(int16_t)WEBRTC_SPL_MUL_16_16_RSFT(crossCorrmod, crossCorrmod, 16);
crossCorrSqMod = (int16_t)((crossCorrmod * crossCorrmod) >> 16);
/* Calculate the total number of (dynamic) right shifts that have
been performed on (crossCorr*crossCorr)/energy