1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef __SPEECH_SSAT_H__
5 #define __SPEECH_SSAT_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #if defined(__GNUC__) && defined(__arm__)
12 #include "cmsis.h"
speech_ssat_int16(int in)13 static inline short speech_ssat_int16(int in)
14 {
15     short out;
16 
17     out = __SSAT(in,16);
18 
19     return out;
20 }
21 
speech_ssat_int24(int in)22 static inline int speech_ssat_int24(int in)
23 {
24     short out;
25 
26     out = __SSAT(in, 24);
27 
28     return out;
29 }
30 #else
31 static inline short speech_ssat_int16(int in)
32 {
33     short out;
34 
35     if (in>32767)
36     {
37         in = 32767;
38     }
39     else if (in<-32768)
40     {
41         in = -32768;
42     }
43     out = (int)in;
44     return out;
45 }
46 
47 static inline int speech_ssat_int24(int in)
48 {
49     short out;
50 
51     if (in > 0x7fffff) {
52         in = 0x7fffff;
53     } else if (in < 0x800000) {
54         in = 0x800000;
55     }
56     out = (int)in;
57     return out;
58 }
59 #endif
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif