|
1 arch.h |
|
2 fixed_arm4.h |
|
3 fixed_arm5e.h |
|
4 fixed_bfin.h |
|
5 fixed_debug.h |
|
6 fixed_generic.h |
|
7 resample.c |
|
8 speex_resampler.h |
|
9 |
|
10 are taken from http://git.xiph.org/speex.git/ as of 2008-10-28. |
|
11 |
|
12 The only changes are: |
|
13 |
|
14 --- arch.h 2008-11-28 09:57:15.000000000 +0100 |
|
15 +++ arch.h 2008-11-28 09:57:37.000000000 +0100 |
|
16 @@ -78,7 +78,10 @@ |
|
17 #include "../include/speex/speex_types.h" |
|
18 #endif |
|
19 |
|
20 +#ifndef ABS |
|
21 #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ |
|
22 +#endif |
|
23 + |
|
24 #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ |
|
25 #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */ |
|
26 #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ |
|
27 @@ -134,6 +137,28 @@ |
|
28 |
|
29 #else |
|
30 |
|
31 +#ifdef DOUBLE_PRECISION |
|
32 +typedef double spx_mem_t; |
|
33 +typedef double spx_coef_t; |
|
34 +typedef double spx_lsp_t; |
|
35 +typedef double spx_sig_t; |
|
36 +typedef double spx_word16_t; |
|
37 +typedef double spx_word32_t; |
|
38 + |
|
39 +#define Q15ONE 1.0 |
|
40 +#define LPC_SCALING 1. |
|
41 +#define SIG_SCALING 1. |
|
42 +#define LSP_SCALING 1. |
|
43 +#define GAMMA_SCALING 1. |
|
44 +#define GAIN_SCALING 1. |
|
45 +#define GAIN_SCALING_1 1. |
|
46 + |
|
47 + |
|
48 +#define VERY_SMALL 1e-20 |
|
49 +#define VERY_LARGE32 1e20 |
|
50 +#define VERY_LARGE16 1e20 |
|
51 +#define Q15_ONE ((spx_word16_t)1.) |
|
52 +#else /* !DOUBLE_PRECISION */ |
|
53 typedef float spx_mem_t; |
|
54 typedef float spx_coef_t; |
|
55 typedef float spx_lsp_t; |
|
56 @@ -154,6 +179,7 @@ |
|
57 #define VERY_LARGE32 1e15f |
|
58 #define VERY_LARGE16 1e15f |
|
59 #define Q15_ONE ((spx_word16_t)1.f) |
|
60 +#endif /* DOUBLE_PRECISION */ |
|
61 |
|
62 #define QCONST16(x,bits) (x) |
|
63 #define QCONST32(x,bits) (x) |
|
64 --- resample.c 2008-11-28 09:56:42.000000000 +0100 |
|
65 +++ resample.c 2008-11-01 20:38:35.000000000 +0100 |
|
66 @@ -63,22 +63,27 @@ |
|
67 |
|
68 #ifdef OUTSIDE_SPEEX |
|
69 #include <stdlib.h> |
|
70 -static void * |
|
71 + |
|
72 +#include <glib.h> |
|
73 + |
|
74 +#define EXPORT G_GNUC_INTERNAL |
|
75 + |
|
76 +static inline void * |
|
77 speex_alloc (int size) |
|
78 { |
|
79 - return calloc (size, 1); |
|
80 + return g_malloc0 (size); |
|
81 } |
|
82 |
|
83 -static void * |
|
84 +static inline void * |
|
85 speex_realloc (void *ptr, int size) |
|
86 { |
|
87 - return realloc (ptr, size); |
|
88 + return g_realloc (ptr, size); |
|
89 } |
|
90 |
|
91 -static void |
|
92 +static inline void |
|
93 speex_free (void *ptr) |
|
94 { |
|
95 - free (ptr); |
|
96 + g_free (ptr); |
|
97 } |
|
98 |
|
99 #include "speex_resampler.h" |
|
100 @@ -90,7 +95,6 @@ |
|
101 #include "os_support.h" |
|
102 #endif /* OUTSIDE_SPEEX */ |
|
103 |
|
104 -#include "stack_alloc.h" |
|
105 #include <math.h> |
|
106 |
|
107 #ifndef M_PI |
|
108 @@ -263,10 +267,17 @@ |
|
109 }; |
|
110 |
|
111 /*8,24,40,56,80,104,128,160,200,256,320*/ |
|
112 +#ifdef DOUBLE_PRECISION |
|
113 +static double |
|
114 +compute_func (double x, struct FuncDef *func) |
|
115 +{ |
|
116 + double y, frac; |
|
117 +#else |
|
118 static double |
|
119 compute_func (float x, struct FuncDef *func) |
|
120 { |
|
121 float y, frac; |
|
122 +#endif |
|
123 double interp[4]; |
|
124 int ind; |
|
125 y = x * func->oversample; |
|
126 @@ -317,11 +328,19 @@ |
|
127 } |
|
128 #else |
|
129 /* The slow way of computing a sinc for the table. Should improve that some day */ |
|
130 +#ifdef DOUBLE_PRECISION |
|
131 +static spx_word16_t |
|
132 +sinc (double cutoff, double x, int N, struct FuncDef *window_func) |
|
133 +{ |
|
134 + /*fprintf (stderr, "%f ", x); */ |
|
135 + double xx = x * cutoff; |
|
136 +#else |
|
137 static spx_word16_t |
|
138 sinc (float cutoff, float x, int N, struct FuncDef *window_func) |
|
139 { |
|
140 /*fprintf (stderr, "%f ", x); */ |
|
141 float xx = x * cutoff; |
|
142 +#endif |
|
143 if (fabs (x) < 1e-6) |
|
144 return cutoff; |
|
145 else if (fabs (x) > .5 * N) |
|
146 @@ -372,6 +391,7 @@ |
|
147 } |
|
148 #endif |
|
149 |
|
150 +#ifndef DOUBLE_PRECISION |
|
151 static int |
|
152 resampler_basic_direct_single (SpeexResamplerState * st, |
|
153 spx_uint32_t channel_index, const spx_word16_t * in, spx_uint32_t * in_len, |
|
154 @@ -421,6 +441,7 @@ |
|
155 st->samp_frac_num[channel_index] = samp_frac_num; |
|
156 return out_sample; |
|
157 } |
|
158 +#endif |
|
159 |
|
160 #ifdef FIXED_POINT |
|
161 #else |
|
162 @@ -476,6 +497,7 @@ |
|
163 } |
|
164 #endif |
|
165 |
|
166 +#ifndef DOUBLE_PRECISION |
|
167 static int |
|
168 resampler_basic_interpolate_single (SpeexResamplerState * st, |
|
169 spx_uint32_t channel_index, const spx_word16_t * in, spx_uint32_t * in_len, |
|
170 @@ -554,6 +576,7 @@ |
|
171 st->samp_frac_num[channel_index] = samp_frac_num; |
|
172 return out_sample; |
|
173 } |
|
174 +#endif |
|
175 |
|
176 #ifdef FIXED_POINT |
|
177 #else |
|
178 @@ -584,10 +607,16 @@ |
|
179 PDIV32 (SHL32 ((samp_frac_num * st->oversample) % st->den_rate, 15), |
|
180 st->den_rate); |
|
181 #else |
|
182 +#ifdef DOUBLE_PRECISION |
|
183 + const spx_word16_t frac = |
|
184 + ((double) ((samp_frac_num * st->oversample) % st->den_rate)) / |
|
185 + st->den_rate; |
|
186 +#else |
|
187 const spx_word16_t frac = |
|
188 ((float) ((samp_frac_num * st->oversample) % st->den_rate)) / |
|
189 st->den_rate; |
|
190 #endif |
|
191 +#endif |
|
192 spx_word16_t interp[4]; |
|
193 |
|
194 |
|
195 @@ -688,20 +717,27 @@ |
|
196 spx_int32_t j; |
|
197 for (j = 0; j < st->filt_len; j++) { |
|
198 st->sinc_table[i * st->filt_len + j] = |
|
199 - sinc (st->cutoff, |
|
200 - ((j - (spx_int32_t) st->filt_len / 2 + 1) - |
|
201 + sinc (st->cutoff, ((j - (spx_int32_t) st->filt_len / 2 + 1) - |
|
202 +#ifdef DOUBLE_PRECISION |
|
203 + ((double) i) / st->den_rate), st->filt_len, |
|
204 +#else |
|
205 ((float) i) / st->den_rate), st->filt_len, |
|
206 +#endif |
|
207 quality_map[st->quality].window_func); |
|
208 } |
|
209 } |
|
210 #ifdef FIXED_POINT |
|
211 st->resampler_ptr = resampler_basic_direct_single; |
|
212 #else |
|
213 +#ifdef DOUBLE_PRECISION |
|
214 + st->resampler_ptr = resampler_basic_direct_double; |
|
215 +#else |
|
216 if (st->quality > 8) |
|
217 st->resampler_ptr = resampler_basic_direct_double; |
|
218 else |
|
219 st->resampler_ptr = resampler_basic_direct_single; |
|
220 #endif |
|
221 +#endif |
|
222 /*fprintf (stderr, "resampler uses direct sinc table and normalised cutoff %f\n", cutoff); */ |
|
223 } else { |
|
224 spx_int32_t i; |
|
225 @@ -717,16 +753,24 @@ |
|
226 } |
|
227 for (i = -4; i < (spx_int32_t) (st->oversample * st->filt_len + 4); i++) |
|
228 st->sinc_table[i + 4] = |
|
229 +#ifdef DOUBLE_PRECISION |
|
230 + sinc (st->cutoff, (i / (double) st->oversample - st->filt_len / 2), |
|
231 +#else |
|
232 sinc (st->cutoff, (i / (float) st->oversample - st->filt_len / 2), |
|
233 +#endif |
|
234 st->filt_len, quality_map[st->quality].window_func); |
|
235 #ifdef FIXED_POINT |
|
236 st->resampler_ptr = resampler_basic_interpolate_single; |
|
237 #else |
|
238 +#ifdef DOUBLE_PRECISION |
|
239 + st->resampler_ptr = resampler_basic_interpolate_double; |
|
240 +#else |
|
241 if (st->quality > 8) |
|
242 st->resampler_ptr = resampler_basic_interpolate_double; |
|
243 else |
|
244 st->resampler_ptr = resampler_basic_interpolate_single; |
|
245 #endif |
|
246 +#endif |
|
247 /*fprintf (stderr, "resampler uses interpolated sinc table and normalised cutoff %f\n", cutoff); */ |
|
248 } |
|
249 st->int_advance = st->num_rate / st->den_rate; |
|
250 @@ -956,11 +1000,18 @@ |
|
251 spx_uint32_t channel_index, const spx_int16_t * in, spx_uint32_t * in_len, |
|
252 spx_int16_t * out, spx_uint32_t * out_len) |
|
253 #else |
|
254 +#ifdef DOUBLE_PRECISION |
|
255 +EXPORT int |
|
256 +speex_resampler_process_float (SpeexResamplerState * st, |
|
257 + spx_uint32_t channel_index, const double *in, spx_uint32_t * in_len, |
|
258 + double *out, spx_uint32_t * out_len) |
|
259 +#else |
|
260 EXPORT int |
|
261 speex_resampler_process_float (SpeexResamplerState * st, |
|
262 spx_uint32_t channel_index, const float *in, spx_uint32_t * in_len, |
|
263 float *out, spx_uint32_t * out_len) |
|
264 #endif |
|
265 +#endif |
|
266 { |
|
267 int j; |
|
268 spx_uint32_t ilen = *in_len; |
|
269 @@ -1078,9 +1129,16 @@ |
|
270 return RESAMPLER_ERR_SUCCESS; |
|
271 } |
|
272 |
|
273 +#ifdef DOUBLE_PRECISION |
|
274 +EXPORT int |
|
275 +speex_resampler_process_interleaved_float (SpeexResamplerState * st, |
|
276 + const double *in, spx_uint32_t * in_len, double *out, |
|
277 + spx_uint32_t * out_len) |
|
278 +#else |
|
279 EXPORT int |
|
280 speex_resampler_process_interleaved_float (SpeexResamplerState * st, |
|
281 const float *in, spx_uint32_t * in_len, float *out, spx_uint32_t * out_len) |
|
282 +#endif |
|
283 { |
|
284 spx_uint32_t i; |
|
285 int istride_save, ostride_save; |
|
286 --- speex_resampler.h 2008-11-28 09:57:15.000000000 +0100 |
|
287 +++ speex_resampler.h 2008-11-28 09:57:37.000000000 +0100 |
|
288 @@ -77,10 +77,10 @@ |
|
289 #define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem) |
|
290 #define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror) |
|
291 |
|
292 -#define spx_int16_t short |
|
293 -#define spx_int32_t int |
|
294 -#define spx_uint16_t unsigned short |
|
295 -#define spx_uint32_t unsigned int |
|
296 +#define spx_int16_t gint16 |
|
297 +#define spx_int32_t gint32 |
|
298 +#define spx_uint16_t guint16 |
|
299 +#define spx_uint32_t guint32 |
|
300 |
|
301 #else /* OUTSIDE_SPEEX */ |
|
302 |
|
303 @@ -162,10 +162,17 @@ |
|
304 * @param out Output buffer |
|
305 * @param out_len Size of the output buffer. Returns the number of samples written |
|
306 */ |
|
307 +#ifdef DOUBLE_PRECISION |
|
308 + int speex_resampler_process_float (SpeexResamplerState * st, |
|
309 + spx_uint32_t channel_index, |
|
310 + const double *in, |
|
311 + spx_uint32_t * in_len, double *out, spx_uint32_t * out_len); |
|
312 +#else |
|
313 int speex_resampler_process_float (SpeexResamplerState * st, |
|
314 spx_uint32_t channel_index, |
|
315 const float *in, |
|
316 spx_uint32_t * in_len, float *out, spx_uint32_t * out_len); |
|
317 +#endif |
|
318 |
|
319 /** Resample an int array. The input and output buffers must *not* overlap. |
|
320 * @param st Resampler state |
|
321 @@ -191,9 +198,15 @@ |
|
322 * @param out_len Size of the output buffer. Returns the number of samples written. |
|
323 * This is all per-channel. |
|
324 */ |
|
325 +#ifdef DOUBLE_PRECISION |
|
326 + int speex_resampler_process_interleaved_float (SpeexResamplerState * st, |
|
327 + const double *in, |
|
328 + spx_uint32_t * in_len, double *out, spx_uint32_t * out_len); |
|
329 +#else |
|
330 int speex_resampler_process_interleaved_float (SpeexResamplerState * st, |
|
331 const float *in, |
|
332 spx_uint32_t * in_len, float *out, spx_uint32_t * out_len); |
|
333 +#endif |
|
334 |
|
335 /** Resample an interleaved int array. The input and output buffers must *not* overlap. |
|
336 * @param st Resampler state |