xref: /aosp_15_r20/external/webrtc/modules/audio_coding/codecs/ilbc/smooth_out_data.c (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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/smooth_out_data.h"
20 
21 #include "modules/audio_coding/codecs/ilbc/constants.h"
22 #include "modules/audio_coding/codecs/ilbc/defines.h"
23 #include "rtc_base/sanitizer.h"
24 
25 // An s32 + s32 -> s32 addition that's allowed to overflow. (It's still
26 // undefined behavior, so not a good idea; this just makes UBSan ignore the
27 // violation, so that our old code can continue to do what it's always been
28 // doing.)
29 static inline int32_t RTC_NO_SANITIZE("signed-integer-overflow")
OverflowingAdd_S32_S32_To_S32(int32_t a,int32_t b)30     OverflowingAdd_S32_S32_To_S32(int32_t a, int32_t b) {
31   return a + b;
32 }
33 
WebRtcIlbcfix_Smooth_odata(int16_t * odata,int16_t * psseq,int16_t * surround,int16_t C)34 int32_t WebRtcIlbcfix_Smooth_odata(
35     int16_t *odata,
36     int16_t *psseq,
37     int16_t *surround,
38     int16_t C)
39 {
40   int i;
41 
42   int16_t err;
43   int32_t errs;
44 
45   for(i=0;i<80;i++) {
46     odata[i]= (int16_t)((C * surround[i] + 1024) >> 11);
47   }
48 
49   errs=0;
50   for(i=0;i<80;i++) {
51     err = (psseq[i] - odata[i]) >> 3;
52     errs = OverflowingAdd_S32_S32_To_S32(errs, err * err);  // errs in Q-6
53   }
54 
55   return errs;
56 }
57