1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 /******************************************************************
12
13 iLBC Speech Coder ANSI-C Source Code
14
15 WebRtcIlbcfix_Smooth_odata.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/defines.h"
20 #include "modules/audio_coding/codecs/ilbc/constants.h"
21 #include "rtc_base/sanitizer.h"
22
23 // An s32 + s32 -> s32 addition that's allowed to overflow. (It's still
24 // undefined behavior, so not a good idea; this just makes UBSan ignore the
25 // violation, so that our old code can continue to do what it's always been
26 // doing.)
27 static inline int32_t RTC_NO_SANITIZE("signed-integer-overflow")
OverflowingAdd_S32_S32_To_S32(int32_t a,int32_t b)28 OverflowingAdd_S32_S32_To_S32(int32_t a, int32_t b) {
29 return a + b;
30 }
31
WebRtcIlbcfix_Smooth_odata(int16_t * odata,int16_t * psseq,int16_t * surround,int16_t C)32 int32_t WebRtcIlbcfix_Smooth_odata(
33 int16_t *odata,
34 int16_t *psseq,
35 int16_t *surround,
36 int16_t C)
37 {
38 int i;
39
40 int16_t err;
41 int32_t errs;
42
43 for(i=0;i<80;i++) {
44 odata[i]= (int16_t)((C * surround[i] + 1024) >> 11);
45 }
46
47 errs=0;
48 for(i=0;i<80;i++) {
49 err = (psseq[i] - odata[i]) >> 3;
50 errs = OverflowingAdd_S32_S32_To_S32(errs, err * err); // errs in Q-6
51 }
52
53 return errs;
54 }
55