From 4ab23d0e8f468d9f1e3ce4ffb50df070d8d06c6d Mon Sep 17 00:00:00 2001 From: "bjornv@webrtc.org" Date: Fri, 20 Mar 2015 06:01:06 +0000 Subject: [PATCH] Refactor audio_coding/ilbc: removes usage of macro WEBRTC_SPL_LSHIFT_W32 The macro is defined as #define WEBRTC_SPL_LSHIFT_W32(a, b) ((a) << (b)) It is a trivial operation that need no macro. In fact it may be confusing for to the user, since it can be interpreted as having an implicit cast to int32_t. Also removes unnecessary casts to int32_t from int16_t. BUG=3348,3353 TESTED=locally on linux and trybots R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/48519004 Cr-Commit-Position: refs/heads/master@{#8800} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8800 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/ilbc/cb_mem_energy.c | 4 ++-- .../codecs/ilbc/cb_mem_energy_augmentation.c | 2 +- .../audio_coding/codecs/ilbc/cb_mem_energy_calc.c | 2 +- .../audio_coding/codecs/ilbc/cb_search_core.c | 2 +- .../modules/audio_coding/codecs/ilbc/chebyshev.c | 15 ++++----------- .../audio_coding/codecs/ilbc/enhancer_interface.c | 5 ++--- .../modules/audio_coding/codecs/ilbc/gain_quant.c | 2 +- .../audio_coding/codecs/ilbc/get_lsp_poly.c | 5 ++--- .../modules/audio_coding/codecs/ilbc/hp_input.c | 4 ++-- .../modules/audio_coding/codecs/ilbc/hp_output.c | 4 ++-- webrtc/modules/audio_coding/codecs/ilbc/smooth.c | 7 +++---- .../audio_coding/codecs/ilbc/window32_w32.c | 6 ++---- 12 files changed, 23 insertions(+), 35 deletions(-) diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy.c b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy.c index 50ad0ad385..f8a09334f2 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy.c @@ -53,7 +53,7 @@ void WebRtcIlbcfix_CbMemEnergy( /* Normalize the energy and store the number of shifts */ energyShifts[0] = (int16_t)WebRtcSpl_NormW32(energy); - tmp32 = WEBRTC_SPL_LSHIFT_W32(energy, energyShifts[0]); + tmp32 = energy << energyShifts[0]; energyW16[0] = (int16_t)(tmp32 >> 16); /* Compute the energy of the rest of the cb memory @@ -69,7 +69,7 @@ void WebRtcIlbcfix_CbMemEnergy( /* Normalize the energy and store the number of shifts */ energyShifts[base_size] = (int16_t)WebRtcSpl_NormW32(energy); - tmp32 = WEBRTC_SPL_LSHIFT_W32(energy, energyShifts[base_size]); + tmp32 = energy << energyShifts[base_size]; energyW16[base_size] = (int16_t)(tmp32 >> 16); ppi = filteredCB + lMem - 1 - lTarget; diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_augmentation.c b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_augmentation.c index 6161f203f2..7e6daf921c 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_augmentation.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_augmentation.c @@ -58,7 +58,7 @@ void WebRtcIlbcfix_CbMemEnergyAugmentation( /* Normalize the energy and store the number of shifts */ (*enShPtr) = (int16_t)WebRtcSpl_NormW32(energy); - tmp32 = WEBRTC_SPL_LSHIFT_W32(energy, (*enShPtr)); + tmp32 = energy << *enShPtr; *enPtr = (int16_t)(tmp32 >> 16); enShPtr++; enPtr++; diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.c b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.c index 87a510da67..e5d14246f2 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.c @@ -58,7 +58,7 @@ void WebRtcIlbcfix_CbMemEnergyCalc( shft = (int16_t)WebRtcSpl_NormW32(energy); *eSh_ptr++ = shft; - tmp = WEBRTC_SPL_LSHIFT_W32(energy, shft); + tmp = energy << shft; *eW16_ptr++ = (int16_t)(tmp >> 16); } } diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c b/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c index 559d998178..3deb08a75c 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.c @@ -65,7 +65,7 @@ void WebRtcIlbcfix_CbSearchCore( for (i=0;i> 16); cDotSqW16 = (int16_t)(((int32_t)(tmp16)*(tmp16))>>16); diff --git a/webrtc/modules/audio_coding/codecs/ilbc/chebyshev.c b/webrtc/modules/audio_coding/codecs/ilbc/chebyshev.c index 96c1aed942..21a8f40df6 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/chebyshev.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/chebyshev.c @@ -39,8 +39,7 @@ int16_t WebRtcIlbcfix_Chebyshev( b2 = (int32_t)0x1000000; /* b2 = 1.0 (Q23) */ /* Calculate b1 = 2*x + f[1] */ - tmp1W32 = WEBRTC_SPL_LSHIFT_W32((int32_t)x, 10); - tmp1W32 += WEBRTC_SPL_LSHIFT_W32((int32_t)f[1], 14); + tmp1W32 = (x << 10) + (f[1] << 14); for (i = 2; i < 5; i++) { tmp2W32 = tmp1W32; @@ -50,10 +49,7 @@ int16_t WebRtcIlbcfix_Chebyshev( b1_low = (int16_t)((tmp1W32 - ((int32_t)b1_high << 16)) >> 1); /* Calculate 2*x*b1-b2+f[i] */ - tmp1W32 = WEBRTC_SPL_LSHIFT_W32(b1_high * x + ((b1_low * x) >> 15), 2); - - tmp1W32 -= b2; - tmp1W32 += WEBRTC_SPL_LSHIFT_W32((int32_t)f[i], 14); + tmp1W32 = ((b1_high * x + ((b1_low * x) >> 15)) << 2) - b2 + (f[i] << 14); /* Update b2 for next round */ b2 = tmp2W32; @@ -64,11 +60,8 @@ int16_t WebRtcIlbcfix_Chebyshev( b1_low = (int16_t)((tmp1W32 - ((int32_t)b1_high << 16)) >> 1); /* tmp1W32 = x*b1 - b2 + f[i]/2 */ - tmp1W32 = WEBRTC_SPL_LSHIFT_W32(b1_high * x, 1) + - WEBRTC_SPL_LSHIFT_W32((b1_low * x) >> 15, 1); - - tmp1W32 -= b2; - tmp1W32 += WEBRTC_SPL_LSHIFT_W32((int32_t)f[i], 13); + tmp1W32 = ((b1_high * x) << 1) + (((b1_low * x) >> 15) << 1) - + b2 + (f[i] << 13); /* Handle overflows and set to maximum or minimum int16_t instead */ if (tmp1W32>((int32_t)33553408)) { diff --git a/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c b/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c index d31af1bb7c..fde541455c 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c @@ -151,7 +151,7 @@ int WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ corr16[i] = (int16_t)WEBRTC_SPL_SHIFT_W32(corrmax[i], corrSh); 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); + totsh[i] = enerSh - (corrSh << 1); } /* Compare lagmax[0..3] for the (corr^2)/ener criteria */ @@ -278,8 +278,7 @@ int WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ (int16_t)tmp1); /* Calculate the Sqrt of the energy in Q15 ((14+16)/2) */ - SqrtEnChange = (int16_t)WebRtcSpl_SqrtFloor( - WEBRTC_SPL_LSHIFT_W32((int32_t)EnChange, 14)); + SqrtEnChange = (int16_t)WebRtcSpl_SqrtFloor(EnChange << 14); /* Multiply first part of vector with 2*SqrtEnChange */ diff --git a/webrtc/modules/audio_coding/codecs/ilbc/gain_quant.c b/webrtc/modules/audio_coding/codecs/ilbc/gain_quant.c index 983c6db3ce..90b4114d3b 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/gain_quant.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/gain_quant.c @@ -48,7 +48,7 @@ int16_t WebRtcIlbcfix_GainQuant( /* (o) quantized gain value */ /* Multiply the gain with 2^14 to make the comparison easier and with higher precision */ - gainW32 = WEBRTC_SPL_LSHIFT_W32((int32_t)gain, 14); + gainW32 = gain << 14; /* Do a binary search, starting in the middle of the CB loc - defines the current position in the table diff --git a/webrtc/modules/audio_coding/codecs/ilbc/get_lsp_poly.c b/webrtc/modules/audio_coding/codecs/ilbc/get_lsp_poly.c index 5cb1ab2656..62a686495b 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/get_lsp_poly.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/get_lsp_poly.c @@ -67,14 +67,13 @@ void WebRtcIlbcfix_GetLspPoly( high = (int16_t)(fPtr[-1] >> 16); low = (int16_t)((fPtr[-1] - ((int32_t)high << 16)) >> 1); - tmpW32 = WEBRTC_SPL_LSHIFT_W32(high * *lspPtr, 2) + - WEBRTC_SPL_LSHIFT_W32((low * *lspPtr) >> 15, 2); + tmpW32 = ((high * *lspPtr) << 2) + (((low * *lspPtr) >> 15) << 2); (*fPtr) += fPtr[-2]; (*fPtr) -= tmpW32; fPtr--; } - (*fPtr) -= (int32_t)WEBRTC_SPL_LSHIFT_W32((int32_t)(*lspPtr), 10); + *fPtr -= *lspPtr << 10; fPtr+=i; lspPtr+=2; diff --git a/webrtc/modules/audio_coding/codecs/ilbc/hp_input.c b/webrtc/modules/audio_coding/codecs/ilbc/hp_input.c index a36ea3944b..260591ede2 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/hp_input.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/hp_input.c @@ -77,11 +77,11 @@ void WebRtcIlbcfix_HpInput( } else if (tmpW32<-268435456) { tmpW32 = WEBRTC_SPL_WORD32_MIN; } else { - tmpW32 = WEBRTC_SPL_LSHIFT_W32(tmpW32, 3); + tmpW32 <<= 3; } y[0] = (int16_t)(tmpW32 >> 16); - y[1] = (int16_t)((tmpW32 - WEBRTC_SPL_LSHIFT_W32((int32_t)y[0], 16))>>1); + y[1] = (int16_t)((tmpW32 - (y[0] << 16)) >> 1); } return; diff --git a/webrtc/modules/audio_coding/codecs/ilbc/hp_output.c b/webrtc/modules/audio_coding/codecs/ilbc/hp_output.c index 970ae1179d..3abb427b9a 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/hp_output.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/hp_output.c @@ -77,11 +77,11 @@ void WebRtcIlbcfix_HpOutput( } else if (tmpW32<-268435456) { tmpW32 = WEBRTC_SPL_WORD32_MIN; } else { - tmpW32 = WEBRTC_SPL_LSHIFT_W32(tmpW32, 3); + tmpW32 <<= 3; } y[0] = (int16_t)(tmpW32 >> 16); - y[1] = (int16_t)((tmpW32 - WEBRTC_SPL_LSHIFT_W32((int32_t)y[0], 16))>>1); + y[1] = (int16_t)((tmpW32 - (y[0] << 16)) >> 1); } diff --git a/webrtc/modules/audio_coding/codecs/ilbc/smooth.c b/webrtc/modules/audio_coding/codecs/ilbc/smooth.c index 57bd4aeda1..f58e72c178 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/smooth.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/smooth.c @@ -76,13 +76,12 @@ void WebRtcIlbcfix_Smooth( scale1 = scale2 + 16; } - w00prim = WEBRTC_SPL_LSHIFT_W32(w00, scale1); + w00prim = w00 << scale1; w11prim = (int16_t) WEBRTC_SPL_SHIFT_W32(w11, scale2); /* Perform C = sqrt(w11/w00) (C is in Q11 since (16+6)/2=11) */ if (w11prim>64) { - endiff = WEBRTC_SPL_LSHIFT_W32( - (int32_t)WebRtcSpl_DivW32W16(w00prim, w11prim), 6); + endiff = WebRtcSpl_DivW32W16(w00prim, w11prim) << 6; C = (int16_t)WebRtcSpl_SqrtFloor(endiff); /* C is in Q11 */ } else { C = 1; @@ -166,7 +165,7 @@ void WebRtcIlbcfix_Smooth( /* B_W32 is in Q30 ( B = 1 - ENH_A0/2 - A * w10/w00 ) */ scale1 = 31-bitsw10; scale2 = 21-scale1; - w10prim = WEBRTC_SPL_LSHIFT_W32(w10, scale1); + w10prim = w10 << scale1; w00prim = WEBRTC_SPL_SHIFT_W32(w00, -scale2); scale = bitsw00-scale2-15; diff --git a/webrtc/modules/audio_coding/codecs/ilbc/window32_w32.c b/webrtc/modules/audio_coding/codecs/ilbc/window32_w32.c index a0278bbe7b..dbecc33abe 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/window32_w32.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/window32_w32.c @@ -46,11 +46,9 @@ void WebRtcIlbcfix_Window32W32( y_hi = (int16_t)(y[i] >> 16); /* Extract lower bytes, defined as (w32 - hi<<16)>>1 */ - temp = WEBRTC_SPL_LSHIFT_W32((int32_t)x_hi, 16); - x_low = (int16_t)((x[i] - temp) >> 1); + x_low = (int16_t)((x[i] - (x_hi << 16)) >> 1); - temp = WEBRTC_SPL_LSHIFT_W32((int32_t)y_hi, 16); - y_low = (int16_t)((y[i] - temp) >> 1); + y_low = (int16_t)((y[i] - (y_hi << 16)) >> 1); /* Calculate z by a 32 bit multiplication using both low and high from x and y */ temp = ((x_hi * y_hi) << 1) + ((x_hi * y_low) >> 14);