37 #include "opus_types.h"
38 #include "opus_defines.h"
39 #include "app_error.h"
41 # if !defined(__GNUC_PREREQ)
42 # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
43 # define __GNUC_PREREQ(_maj,_min) \
44 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
46 # define __GNUC_PREREQ(_maj,_min) 0
50 #if OPUS_GNUC_PREREQ(3, 0)
51 #define opus_likely(x) (__builtin_expect(!!(x), 1))
52 #define opus_unlikely(x) (__builtin_expect(!!(x), 0))
54 #define opus_likely(x) (!!(x))
55 #define opus_unlikely(x) (!!(x))
58 #define CELT_SIG_SCALE 32768.f
60 #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
61 #ifdef ENABLE_ASSERTIONS
64 static OPUS_INLINE
void _celt_fatal(
const char *str,
const char *file,
int line)
68 #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}}
69 #define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}}
71 #define celt_assert(cond)
72 #define celt_assert2(cond, message)
75 #define IMUL32(a,b) ((a)*(b))
77 #define MIN16(a,b) ((a) < (b) ? (a) : (b))
78 #define MAX16(a,b) ((a) > (b) ? (a) : (b))
79 #define MIN32(a,b) ((a) < (b) ? (a) : (b))
80 #define MAX32(a,b) ((a) > (b) ? (a) : (b))
81 #define IMIN(a,b) ((a) < (b) ? (a) : (b))
82 #define IMAX(a,b) ((a) > (b) ? (a) : (b))
83 #define UADD32(a,b) ((a)+(b))
84 #define USUB32(a,b) ((a)-(b))
89 #if defined(__x86_64__) || defined(__LP64__) || defined(_WIN64)
90 #define OPUS_FAST_INT64 1
92 #define OPUS_FAST_INT64 0
95 #define PRINT_MIPS(file)
99 typedef opus_int16 opus_val16;
100 typedef opus_int32 opus_val32;
101 typedef opus_int64 opus_val64;
103 typedef opus_val32 celt_sig;
104 typedef opus_val16 celt_norm;
105 typedef opus_val32 celt_ener;
112 #define SIG_SAT (300000000)
114 #define NORM_SCALING 16384
120 #define VERY_LARGE16 ((opus_val16)32767)
121 #define Q15_ONE ((opus_val16)32767)
123 #define SCALEIN(a) (a)
124 #define SCALEOUT(a) (a)
126 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))
127 #define ABS32(x) ((x) < 0 ? (-(x)) : (x))
129 static OPUS_INLINE opus_int16 SAT16(opus_int32 x) {
130 return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
134 #include "fixed_debug.h"
137 #include "fixed_generic.h"
139 #ifdef OPUS_ARM_PRESUME_AARCH64_NEON_INTR
140 #include "arm/fixed_arm64.h"
141 #elif OPUS_ARM_INLINE_EDSP
142 #include "arm/fixed_armv5e.h"
143 #elif defined (OPUS_ARM_INLINE_ASM)
144 #include "arm/fixed_armv4.h"
145 #elif defined (BFIN_ASM)
146 #include "fixed_bfin.h"
147 #elif defined (TI_C5X_ASM)
148 #include "fixed_c5x.h"
149 #elif defined (TI_C6X_ASM)
150 #include "fixed_c6x.h"
157 typedef float opus_val16;
158 typedef float opus_val32;
159 typedef float opus_val64;
161 typedef float celt_sig;
162 typedef float celt_norm;
163 typedef float celt_ener;
168 static OPUS_INLINE
int celt_isnan(
float x)
170 union {
float f; opus_uint32 i;} in;
172 return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0;
176 #error Cannot build libopus with -ffast-math unless FLOAT_APPROX is defined. This could result in crashes on extreme (e.g. NaN) input
178 #define celt_isnan(x) ((x)!=(x))
183 #define NORM_SCALING 1.f
185 #define EPSILON 1e-15f
186 #define VERY_SMALL 1e-30f
187 #define VERY_LARGE16 1e15f
188 #define Q15_ONE ((opus_val16)1.f)
191 #define ABS16(x) ((float)fabs(x))
192 #define ABS32(x) ((float)fabs(x))
194 #define QCONST16(x,bits) (x)
195 #define QCONST32(x,bits) (x)
197 #define NEG16(x) (-(x))
198 #define NEG32(x) (-(x))
199 #define NEG32_ovflw(x) (-(x))
200 #define EXTRACT16(x) (x)
201 #define EXTEND32(x) (x)
202 #define SHR16(a,shift) (a)
203 #define SHL16(a,shift) (a)
204 #define SHR32(a,shift) (a)
205 #define SHL32(a,shift) (a)
206 #define PSHR32(a,shift) (a)
207 #define VSHR32(a,shift) (a)
209 #define PSHR(a,shift) (a)
210 #define SHR(a,shift) (a)
211 #define SHL(a,shift) (a)
212 #define SATURATE(x,a) (x)
213 #define SATURATE16(x) (x)
215 #define ROUND16(a,shift) (a)
216 #define SROUND16(a,shift) (a)
217 #define HALF16(x) (.5f*(x))
218 #define HALF32(x) (.5f*(x))
220 #define ADD16(a,b) ((a)+(b))
221 #define SUB16(a,b) ((a)-(b))
222 #define ADD32(a,b) ((a)+(b))
223 #define SUB32(a,b) ((a)-(b))
224 #define ADD32_ovflw(a,b) ((a)+(b))
225 #define SUB32_ovflw(a,b) ((a)-(b))
226 #define MULT16_16_16(a,b) ((a)*(b))
227 #define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b))
228 #define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b))
230 #define MULT16_32_Q15(a,b) ((a)*(b))
231 #define MULT16_32_Q16(a,b) ((a)*(b))
233 #define MULT32_32_Q31(a,b) ((a)*(b))
235 #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
236 #define MAC16_32_Q16(c,a,b) ((c)+(a)*(b))
238 #define MULT16_16_Q11_32(a,b) ((a)*(b))
239 #define MULT16_16_Q11(a,b) ((a)*(b))
240 #define MULT16_16_Q13(a,b) ((a)*(b))
241 #define MULT16_16_Q14(a,b) ((a)*(b))
242 #define MULT16_16_Q15(a,b) ((a)*(b))
243 #define MULT16_16_P15(a,b) ((a)*(b))
244 #define MULT16_16_P13(a,b) ((a)*(b))
245 #define MULT16_16_P14(a,b) ((a)*(b))
246 #define MULT16_32_P16(a,b) ((a)*(b))
248 #define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b))
249 #define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b))
251 #define SCALEIN(a) ((a)*CELT_SIG_SCALE)
252 #define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE))
254 #define SIG2WORD16(x) (x)
258 #ifndef GLOBAL_STACK_SIZE
260 #define GLOBAL_STACK_SIZE 120000
262 #define GLOBAL_STACK_SIZE 120000