diff options
Diffstat (limited to 'apps/codecs/libspeex/misc.h')
-rw-r--r-- | apps/codecs/libspeex/misc.h | 148 |
1 files changed, 123 insertions, 25 deletions
diff --git a/apps/codecs/libspeex/misc.h b/apps/codecs/libspeex/misc.h index 1664aaed9d..8702919b7b 100644 --- a/apps/codecs/libspeex/misc.h +++ b/apps/codecs/libspeex/misc.h | |||
@@ -35,6 +35,8 @@ | |||
35 | #ifndef MISC_H | 35 | #ifndef MISC_H |
36 | #define MISC_H | 36 | #define MISC_H |
37 | 37 | ||
38 | #include "config-speex.h" | ||
39 | |||
38 | #ifndef SPEEX_VERSION | 40 | #ifndef SPEEX_VERSION |
39 | #define SPEEX_MAJOR_VERSION 1 /**< Major Speex version. */ | 41 | #define SPEEX_MAJOR_VERSION 1 /**< Major Speex version. */ |
40 | #define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */ | 42 | #define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */ |
@@ -69,16 +71,14 @@ | |||
69 | #endif | 71 | #endif |
70 | 72 | ||
71 | #include "arch.h" | 73 | #include "arch.h" |
72 | 74 | #include "rockbox.h" | |
73 | #ifndef RELEASE | ||
74 | /** Print a named vector to stdout */ | ||
75 | void print_vec(float *vec, int len, char *name); | ||
76 | #endif | ||
77 | 75 | ||
78 | /** Convert little endian */ | 76 | /** Convert little endian */ |
79 | static inline spx_int32_t le_int(spx_int32_t i) | 77 | static inline spx_int32_t le_int(spx_int32_t i) |
80 | { | 78 | { |
81 | #if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) ) | 79 | #if 1 |
80 | return letoh32(i); | ||
81 | #elif !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) ) | ||
82 | spx_uint32_t ui, ret; | 82 | spx_uint32_t ui, ret; |
83 | ui = i; | 83 | ui = i; |
84 | ret = ui>>24; | 84 | ret = ui>>24; |
@@ -91,40 +91,138 @@ static inline spx_int32_t le_int(spx_int32_t i) | |||
91 | #endif | 91 | #endif |
92 | } | 92 | } |
93 | 93 | ||
94 | #define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__); | ||
95 | #define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}} | ||
96 | |||
97 | #ifndef RELEASE | ||
98 | static void print_vec(float *vec, int len, char *name) | ||
99 | { | ||
100 | int i; | ||
101 | printf ("%s ", name); | ||
102 | for (i=0;i<len;i++) | ||
103 | printf (" %f", vec[i]); | ||
104 | printf ("\n"); | ||
105 | } | ||
106 | #endif | ||
107 | |||
108 | #ifdef FIXED_DEBUG | ||
109 | long long spx_mips=0; | ||
110 | #endif | ||
111 | |||
112 | |||
94 | /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free */ | 113 | /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free */ |
95 | void *speex_alloc (int size); | 114 | #ifndef OVERRIDE_SPEEX_ALLOC |
115 | static inline void *speex_alloc (int size) | ||
116 | { | ||
117 | return calloc(size,1); | ||
118 | } | ||
119 | #endif | ||
96 | 120 | ||
97 | /** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ | 121 | /** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ |
98 | void *speex_alloc_scratch (int size); | 122 | #ifndef OVERRIDE_SPEEX_ALLOC_SCRATCH |
123 | static inline void *speex_alloc_scratch (int size) | ||
124 | { | ||
125 | return calloc(size,1); | ||
126 | } | ||
127 | #endif | ||
99 | 128 | ||
100 | /** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */ | 129 | /** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */ |
101 | void *speex_realloc (void *ptr, int size); | 130 | #ifndef OVERRIDE_SPEEX_REALLOC |
131 | static inline void *speex_realloc (void *ptr, int size) | ||
132 | { | ||
133 | return realloc(ptr, size); | ||
134 | } | ||
135 | #endif | ||
102 | 136 | ||
103 | /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */ | 137 | /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */ |
104 | void speex_free (void *ptr); | 138 | #ifndef OVERRIDE_SPEEX_FREE |
139 | static inline void speex_free (void *ptr) | ||
140 | { | ||
141 | free(ptr); | ||
142 | } | ||
143 | #endif | ||
105 | 144 | ||
106 | /** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ | 145 | /** Same as speex_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ |
107 | void speex_free_scratch (void *ptr); | 146 | #ifndef OVERRIDE_SPEEX_FREE_SCRATCH |
147 | static inline void speex_free_scratch (void *ptr) | ||
148 | { | ||
149 | free(ptr); | ||
150 | } | ||
151 | #endif | ||
108 | 152 | ||
109 | /** Speex wrapper for mem_move */ | 153 | /** Print warning message with integer argument to stderr */ |
110 | void *speex_move (void *dest, void *src, int n); | 154 | #ifndef OVERRIDE_SPEEX_MOVE |
155 | static inline void *speex_move (void *dest, void *src, int n) | ||
156 | { | ||
157 | return memmove(dest,src,n); | ||
158 | } | ||
159 | #endif | ||
111 | 160 | ||
112 | /** Abort with an error message to stderr (internal Speex error) */ | 161 | #ifndef OVERRIDE_SPEEX_FATAL |
113 | void speex_error(const char *str); | 162 | static inline void _speex_fatal(const char *str, const char *file, int line) |
163 | { | ||
164 | fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); | ||
165 | exit(1); | ||
166 | } | ||
167 | #endif | ||
114 | 168 | ||
115 | /** Print warning message to stderr (programming error) */ | 169 | #ifndef OVERRIDE_SPEEX_WARNING |
116 | void speex_warning(const char *str); | 170 | static inline void speex_warning(const char *str) |
171 | { | ||
172 | #ifndef DISABLE_WARNINGS | ||
173 | fprintf (stderr, "warning: %s\n", str); | ||
174 | #endif | ||
175 | } | ||
176 | #endif | ||
117 | 177 | ||
118 | /** Print warning message with integer argument to stderr */ | 178 | #ifndef OVERRIDE_SPEEX_WARNING_INT |
119 | void speex_warning_int(const char *str, int val); | 179 | static inline void speex_warning_int(const char *str, int val) |
180 | { | ||
181 | #ifndef DISABLE_WARNINGS | ||
182 | fprintf (stderr, "warning: %s %d\n", str, val); | ||
183 | #endif | ||
184 | } | ||
185 | #endif | ||
120 | 186 | ||
121 | /** Print notification message to stderr */ | 187 | #ifndef OVERRIDE_SPEEX_NOTIFY |
122 | void speex_notify(const char *str); | 188 | static inline void speex_notify(const char *str) |
189 | { | ||
190 | #ifndef DISABLE_NOTIFICATIONS | ||
191 | fprintf (stderr, "notification: %s\n", str); | ||
192 | #endif | ||
193 | } | ||
194 | #endif | ||
123 | 195 | ||
124 | /** Generate a random number */ | 196 | #ifdef FIXED_POINT |
125 | spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed); | 197 | /** Generate a pseudo-random number */ |
198 | static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed) | ||
199 | { | ||
200 | spx_word32_t res; | ||
201 | *seed = 1664525 * *seed + 1013904223; | ||
202 | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); | ||
203 | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); | ||
204 | } | ||
205 | #else | ||
206 | /** Generate a pseudo-random number */ | ||
207 | static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed) | ||
208 | { | ||
209 | const unsigned int jflone = 0x3f800000; | ||
210 | const unsigned int jflmsk = 0x007fffff; | ||
211 | union {int i; float f;} ran; | ||
212 | *seed = 1664525 * *seed + 1013904223; | ||
213 | ran.i = jflone | (jflmsk & *seed); | ||
214 | ran.f -= 1.5; | ||
215 | return 3.4642*std*ran.f; | ||
216 | } | ||
217 | #endif | ||
126 | 218 | ||
219 | #ifndef OVERRIDE_SPEEX_PUTC | ||
127 | /** Speex wrapper for putc */ | 220 | /** Speex wrapper for putc */ |
128 | void _speex_putc(int ch, void *file); | 221 | static inline void _speex_putc(int ch, void *file) |
222 | { | ||
223 | FILE *f = (FILE *)file; | ||
224 | fprintf(f, "%c", ch); | ||
225 | } | ||
226 | #endif | ||
129 | 227 | ||
130 | #endif | 228 | #endif |