summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libopus/celt/arch.h
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2014-01-19 16:31:59 +0100
committerNils Wallménius <nils@rockbox.org>2014-07-13 11:12:40 +0200
commit9b7ec42403073ee887efc531c153e6b1b6c15bab (patch)
tree07e72fe9d817c65a6fede22955344a870842d5e6 /lib/rbcodec/codecs/libopus/celt/arch.h
parente557951c94c1efa769900257e466900f0ffeb53b (diff)
downloadrockbox-9b7ec42403073ee887efc531c153e6b1b6c15bab.tar.gz
rockbox-9b7ec42403073ee887efc531c153e6b1b6c15bab.zip
Sync to upstream libopus
Sync to commit bb4b6885a139644cf3ac14e7deda9f633ec2d93c This brings in a bunch of optimizations to decode speed and memory usage. Allocations are switched from using the pseudostack to using the real stack. Enabled hacks to reduce stack usage. This should fix crashes on sansa clip, although some files will not play due to failing allocations in the codec buffer. Speeds up decoding of the following test files: H300 (cf) C200 (arm7tdmi) ipod classic (arm9e) 16 kbps (silk) 14.28 MHz 4.00 MHz 2.61 MHz 64 kbps (celt) 4.09 MHz 8.08 MHz 6.24 MHz 128 kbps (celt) 1.93 MHz 8.83 MHz 6.53 MHz Change-Id: I851733a8a5824b61feb363a173091bc7e6629b58
Diffstat (limited to 'lib/rbcodec/codecs/libopus/celt/arch.h')
-rw-r--r--lib/rbcodec/codecs/libopus/celt/arch.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/lib/rbcodec/codecs/libopus/celt/arch.h b/lib/rbcodec/codecs/libopus/celt/arch.h
index b2d26c4ee4..035b92ff29 100644
--- a/lib/rbcodec/codecs/libopus/celt/arch.h
+++ b/lib/rbcodec/codecs/libopus/celt/arch.h
@@ -69,11 +69,9 @@ static OPUS_INLINE void _celt_fatal(const char *str, const char *file, int line)
69 69
70#define IMUL32(a,b) ((a)*(b)) 70#define IMUL32(a,b) ((a)*(b))
71 71
72#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ 72#define ABS(x) ((x) < 0 ? (-(x)) : (x))
73#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
74#define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */ 73#define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */
75#define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ 74#define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
76#define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
77#define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */ 75#define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */
78#define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */ 76#define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
79#define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */ 77#define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */
@@ -108,6 +106,13 @@ typedef opus_val32 celt_ener;
108#define SCALEIN(a) (a) 106#define SCALEIN(a) (a)
109#define SCALEOUT(a) (a) 107#define SCALEOUT(a) (a)
110 108
109#define ABS16(x) ((x) < 0 ? (-(x)) : (x))
110#define ABS32(x) ((x) < 0 ? (-(x)) : (x))
111
112static OPUS_INLINE opus_int16 SAT16(opus_int32 x) {
113 return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
114}
115
111#ifdef FIXED_DEBUG 116#ifdef FIXED_DEBUG
112#include "fixed_debug.h" 117#include "fixed_debug.h"
113#else 118#else
@@ -139,6 +144,22 @@ typedef float celt_sig;
139typedef float celt_norm; 144typedef float celt_norm;
140typedef float celt_ener; 145typedef float celt_ener;
141 146
147#ifdef FLOAT_APPROX
148/* This code should reliably detect NaN/inf even when -ffast-math is used.
149 Assumes IEEE 754 format. */
150static OPUS_INLINE int celt_isnan(float x)
151{
152 union {float f; opus_uint32 i;} in;
153 in.f = x;
154 return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0;
155}
156#else
157#ifdef __FAST_MATH__
158#error Cannot build libopus with -ffast-math unless FLOAT_APPROX is defined. This could result in crashes on extreme (e.g. NaN) input
159#endif
160#define celt_isnan(x) ((x)!=(x))
161#endif
162
142#define Q15ONE 1.0f 163#define Q15ONE 1.0f
143 164
144#define NORM_SCALING 1.f 165#define NORM_SCALING 1.f
@@ -148,6 +169,10 @@ typedef float celt_ener;
148#define VERY_LARGE16 1e15f 169#define VERY_LARGE16 1e15f
149#define Q15_ONE ((opus_val16)1.f) 170#define Q15_ONE ((opus_val16)1.f)
150 171
172/* This appears to be the same speed as C99's fabsf() but it's more portable. */
173#define ABS16(x) ((float)fabs(x))
174#define ABS32(x) ((float)fabs(x))
175
151#define QCONST16(x,bits) (x) 176#define QCONST16(x,bits) (x)
152#define QCONST32(x,bits) (x) 177#define QCONST32(x,bits) (x)
153 178
@@ -186,6 +211,7 @@ typedef float celt_ener;
186#define MULT32_32_Q31(a,b) ((a)*(b)) 211#define MULT32_32_Q31(a,b) ((a)*(b))
187 212
188#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) 213#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
214#define MAC16_32_Q16(c,a,b) ((c)+(a)*(b))
189 215
190#define MULT16_16_Q11_32(a,b) ((a)*(b)) 216#define MULT16_16_Q11_32(a,b) ((a)*(b))
191#define MULT16_16_Q11(a,b) ((a)*(b)) 217#define MULT16_16_Q11(a,b) ((a)*(b))
@@ -203,6 +229,8 @@ typedef float celt_ener;
203#define SCALEIN(a) ((a)*CELT_SIG_SCALE) 229#define SCALEIN(a) ((a)*CELT_SIG_SCALE)
204#define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE)) 230#define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE))
205 231
232#define SIG2WORD16(x) (x)
233
206#endif /* !FIXED_POINT */ 234#endif /* !FIXED_POINT */
207 235
208#ifndef GLOBAL_STACK_SIZE 236#ifndef GLOBAL_STACK_SIZE