From 7c15510f389b00fea03e8512cf1a09d0a344b8e9 Mon Sep 17 00:00:00 2001 From: "bjornv@webrtc.org" Date: Mon, 29 Sep 2014 09:40:38 +0000 Subject: [PATCH] common_audio refactoring: Removed macro WEBRTC_SPL_LSHIFT_U32 The macro is a trivial shift operator including a cast before shift. There is no guard against negative shifts. Replaced with << at place and added casts when necessary. Affects both fixed and float point versions of iSAC BUG=3348,3353 TESTED=locally on linux and trybots R=kwiberg@webrtc.org, tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/27369004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7320 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../include/signal_processing_library.h | 1 - .../signal_processing/signal_processing_unittest.cc | 1 - .../codecs/isac/fix/source/arith_routines_hist.c | 2 +- .../codecs/isac/fix/source/arith_routines_logist.c | 9 ++++----- .../codecs/isac/fix/source/bandwidth_estimator.c | 12 ++++++------ .../audio_coding/codecs/isac/main/source/crc.c | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/webrtc/common_audio/signal_processing/include/signal_processing_library.h b/webrtc/common_audio/signal_processing/include/signal_processing_library.h index 21c5663f80..ba306ed3b9 100644 --- a/webrtc/common_audio/signal_processing/include/signal_processing_library.h +++ b/webrtc/common_audio/signal_processing/include/signal_processing_library.h @@ -95,7 +95,6 @@ #define WEBRTC_SPL_LSHIFT_W32(x, c) ((x) << (c)) #define WEBRTC_SPL_RSHIFT_U32(x, c) ((uint32_t)(x) >> (c)) -#define WEBRTC_SPL_LSHIFT_U32(x, c) ((uint32_t)(x) << (c)) #define WEBRTC_SPL_RAND(a) \ ((int16_t)(WEBRTC_SPL_MUL_16_16_RSFT((a), 18816, 7) & 0x00007fff)) diff --git a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc index 3fa3d2ee51..d5cc5f0739 100644 --- a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc +++ b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc @@ -72,7 +72,6 @@ TEST_F(SplTest, MacroTest) { EXPECT_EQ(32766, WEBRTC_SPL_LSHIFT_W32(a, 1)); EXPECT_EQ(8191u, WEBRTC_SPL_RSHIFT_U32(a, 1)); - EXPECT_EQ(32766u, WEBRTC_SPL_LSHIFT_U32(a, 1)); EXPECT_EQ(1470, WEBRTC_SPL_RAND(A)); diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/arith_routines_hist.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/arith_routines_hist.c index 5311b3930e..2cc020d403 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/arith_routines_hist.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/arith_routines_hist.c @@ -310,7 +310,7 @@ int16_t WebRtcIsacfix_DecHistOneStepMulti(int16_t *data, if (streamData->stream_index == 0) { /* read first word from bytestream */ - streamval = WEBRTC_SPL_LSHIFT_U32(*streamPtr++, 16); + streamval = (uint32_t)(*streamPtr++) << 16; streamval |= *streamPtr++; } else { streamval = streamData->streamval; diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/arith_routines_logist.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/arith_routines_logist.c index 4efdecc9a6..5133128b8a 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/arith_routines_logist.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/arith_routines_logist.c @@ -184,21 +184,20 @@ int WebRtcIsacfix_EncLogisticMulti2(Bitstr_enc *streamData, * W_upper < 2^24 */ while ( !(W_upper & 0xFF000000) ) { - W_upper = WEBRTC_SPL_LSHIFT_U32(W_upper, 8); + W_upper <<= 8; if (streamData->full == 0) { *streamPtr++ += (uint16_t) WEBRTC_SPL_RSHIFT_U32( streamData->streamval, 24); streamData->full = 1; } else { - *streamPtr = (uint16_t) WEBRTC_SPL_LSHIFT_U32( - WEBRTC_SPL_RSHIFT_U32(streamData->streamval, 24), 8); + *streamPtr = (uint16_t)((streamData->streamval >> 24) << 8); streamData->full = 0; } if( streamPtr > maxStreamPtr ) return -ISAC_DISALLOWED_BITSTREAM_LENGTH; - streamData->streamval = WEBRTC_SPL_LSHIFT_U32(streamData->streamval, 8); + streamData->streamval <<= 8; } } @@ -257,7 +256,7 @@ int16_t WebRtcIsacfix_DecLogisticMulti2(int16_t *dataQ7, if (streamData->stream_index == 0) { /* read first word from bytestream */ - streamVal = WEBRTC_SPL_LSHIFT_U32(*streamPtr++, 16); + streamVal = (uint32_t)(*streamPtr++) << 16; streamVal |= *streamPtr++; } else { diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c index d28a6f705c..e69435f03b 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c @@ -523,9 +523,9 @@ int32_t WebRtcIsacfix_UpdateUplinkBwImpl(BwEstimatorstr *bweStr, bweStr->recBw = (int32_t) MIN_ISAC_BW; } - bweStr->recBwAvg = WEBRTC_SPL_LSHIFT_U32(bweStr->recBw + bweStr->recHeaderRate, 5); + bweStr->recBwAvg = (bweStr->recBw + bweStr->recHeaderRate) << 5; - bweStr->recBwAvgQ = WEBRTC_SPL_LSHIFT_U32(bweStr->recBw, 7); + bweStr->recBwAvgQ = bweStr->recBw << 7; bweStr->recJitterShortTerm = 0; @@ -573,8 +573,8 @@ int16_t WebRtcIsacfix_UpdateUplinkBwRec(BwEstimatorstr *bweStr, /* compute the BN estimate as decoded on the other side */ /* sendBwAvg = 0.9 * sendBwAvg + 0.1 * kQRateTable[RateInd]; */ - bweStr->sendBwAvg = WEBRTC_SPL_UMUL(461, bweStr->sendBwAvg) + - WEBRTC_SPL_UMUL(51, WEBRTC_SPL_LSHIFT_U32(kQRateTable[RateInd], 7)); + bweStr->sendBwAvg = 461 * bweStr->sendBwAvg + + 51 * ((uint32_t)kQRateTable[RateInd] << 7); bweStr->sendBwAvg = WEBRTC_SPL_RSHIFT_U32(bweStr->sendBwAvg, 9); @@ -625,8 +625,8 @@ uint16_t WebRtcIsacfix_GetDownlinkBwIndexImpl(BwEstimatorstr *bweStr) /* Compute the averaged BN estimate on this side */ /* recBwAvg = 0.9 * recBwAvg + 0.1 * (rate + bweStr->recHeaderRate), 0.9 and 0.1 in Q9 */ - bweStr->recBwAvg = WEBRTC_SPL_UMUL(922, bweStr->recBwAvg) + - WEBRTC_SPL_UMUL(102, WEBRTC_SPL_LSHIFT_U32((uint32_t)rate + bweStr->recHeaderRate, 5)); + bweStr->recBwAvg = 922 * bweStr->recBwAvg + + 102 * (((uint32_t)rate + bweStr->recHeaderRate) << 5); bweStr->recBwAvg = WEBRTC_SPL_RSHIFT_U32(bweStr->recBwAvg, 10); /* Find quantization index that gives the closest rate after averaging. diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/crc.c b/webrtc/modules/audio_coding/codecs/isac/main/source/crc.c index 1d36ff0915..06c15cb390 100644 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/crc.c +++ b/webrtc/modules/audio_coding/codecs/isac/main/source/crc.c @@ -102,7 +102,7 @@ int16_t WebRtcIsac_GetCrc(const int16_t* bitstream, for (byte_cntr = 0; byte_cntr < len_bitstream_in_bytes; byte_cntr++) { crc_tbl_indx = (WEBRTC_SPL_RSHIFT_U32(crc_state, 24) ^ bitstream_ptr_uw8[byte_cntr]) & 0xFF; - crc_state = WEBRTC_SPL_LSHIFT_U32(crc_state, 8) ^ kCrcTable[crc_tbl_indx]; + crc_state = (crc_state << 8) ^ kCrcTable[crc_tbl_indx]; } *crc = ~crc_state;