diff options
Diffstat (limited to 'lib/rbcodec/codecs/libspeex/fftwrap.c')
-rw-r--r-- | lib/rbcodec/codecs/libspeex/fftwrap.c | 131 |
1 files changed, 120 insertions, 11 deletions
diff --git a/lib/rbcodec/codecs/libspeex/fftwrap.c b/lib/rbcodec/codecs/libspeex/fftwrap.c index 2312f755d6..b849e74f7c 100644 --- a/lib/rbcodec/codecs/libspeex/fftwrap.c +++ b/lib/rbcodec/codecs/libspeex/fftwrap.c | |||
@@ -1,23 +1,23 @@ | |||
1 | /* Copyright (C) 2005-2006 Jean-Marc Valin | 1 | /* Copyright (C) 2005-2006 Jean-Marc Valin |
2 | File: fftwrap.c | 2 | File: fftwrap.c |
3 | 3 | ||
4 | Wrapper for various FFTs | 4 | Wrapper for various FFTs |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions | 7 | modification, are permitted provided that the following conditions |
8 | are met: | 8 | are met: |
9 | 9 | ||
10 | - Redistributions of source code must retain the above copyright | 10 | - Redistributions of source code must retain the above copyright |
11 | notice, this list of conditions and the following disclaimer. | 11 | notice, this list of conditions and the following disclaimer. |
12 | 12 | ||
13 | - Redistributions in binary form must reproduce the above copyright | 13 | - Redistributions in binary form must reproduce the above copyright |
14 | notice, this list of conditions and the following disclaimer in the | 14 | notice, this list of conditions and the following disclaimer in the |
15 | documentation and/or other materials provided with the distribution. | 15 | documentation and/or other materials provided with the distribution. |
16 | 16 | ||
17 | - Neither the name of the Xiph.org Foundation nor the names of its | 17 | - Neither the name of the Xiph.org Foundation nor the names of its |
18 | contributors may be used to endorse or promote products derived from | 18 | contributors may be used to endorse or promote products derived from |
19 | this software without specific prior written permission. | 19 | this software without specific prior written permission. |
20 | 20 | ||
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
@@ -36,10 +36,6 @@ | |||
36 | #include "config-speex.h" | 36 | #include "config-speex.h" |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | /*#define USE_SMALLFT*/ | ||
40 | #define USE_KISS_FFT | ||
41 | |||
42 | |||
43 | #include "arch.h" | 39 | #include "arch.h" |
44 | #include "os_support.h" | 40 | #include "os_support.h" |
45 | 41 | ||
@@ -66,7 +62,7 @@ static int maximize_range(spx_word16_t *in, spx_word16_t *out, spx_word16_t boun | |||
66 | for (i=0;i<len;i++) | 62 | for (i=0;i<len;i++) |
67 | { | 63 | { |
68 | out[i] = SHL16(in[i], shift); | 64 | out[i] = SHL16(in[i], shift); |
69 | } | 65 | } |
70 | return shift; | 66 | return shift; |
71 | } | 67 | } |
72 | 68 | ||
@@ -130,6 +126,119 @@ void spx_ifft(void *table, float *in, float *out) | |||
130 | spx_drft_backward((struct drft_lookup *)table, out); | 126 | spx_drft_backward((struct drft_lookup *)table, out); |
131 | } | 127 | } |
132 | 128 | ||
129 | #elif defined(USE_INTEL_MKL) | ||
130 | #include <mkl.h> | ||
131 | |||
132 | struct mkl_config { | ||
133 | DFTI_DESCRIPTOR_HANDLE desc; | ||
134 | int N; | ||
135 | }; | ||
136 | |||
137 | void *spx_fft_init(int size) | ||
138 | { | ||
139 | struct mkl_config *table = (struct mkl_config *) speex_alloc(sizeof(struct mkl_config)); | ||
140 | table->N = size; | ||
141 | DftiCreateDescriptor(&table->desc, DFTI_SINGLE, DFTI_REAL, 1, size); | ||
142 | DftiSetValue(table->desc, DFTI_PACKED_FORMAT, DFTI_PACK_FORMAT); | ||
143 | DftiSetValue(table->desc, DFTI_PLACEMENT, DFTI_NOT_INPLACE); | ||
144 | DftiSetValue(table->desc, DFTI_FORWARD_SCALE, 1.0f / size); | ||
145 | DftiCommitDescriptor(table->desc); | ||
146 | return table; | ||
147 | } | ||
148 | |||
149 | void spx_fft_destroy(void *table) | ||
150 | { | ||
151 | struct mkl_config *t = (struct mkl_config *) table; | ||
152 | DftiFreeDescriptor(t->desc); | ||
153 | speex_free(table); | ||
154 | } | ||
155 | |||
156 | void spx_fft(void *table, spx_word16_t *in, spx_word16_t *out) | ||
157 | { | ||
158 | struct mkl_config *t = (struct mkl_config *) table; | ||
159 | DftiComputeForward(t->desc, in, out); | ||
160 | } | ||
161 | |||
162 | void spx_ifft(void *table, spx_word16_t *in, spx_word16_t *out) | ||
163 | { | ||
164 | struct mkl_config *t = (struct mkl_config *) table; | ||
165 | DftiComputeBackward(t->desc, in, out); | ||
166 | } | ||
167 | |||
168 | #elif defined(USE_GPL_FFTW3) | ||
169 | |||
170 | #include <fftw3.h> | ||
171 | |||
172 | struct fftw_config { | ||
173 | float *in; | ||
174 | float *out; | ||
175 | fftwf_plan fft; | ||
176 | fftwf_plan ifft; | ||
177 | int N; | ||
178 | }; | ||
179 | |||
180 | void *spx_fft_init(int size) | ||
181 | { | ||
182 | struct fftw_config *table = (struct fftw_config *) speex_alloc(sizeof(struct fftw_config)); | ||
183 | table->in = fftwf_malloc(sizeof(float) * (size+2)); | ||
184 | table->out = fftwf_malloc(sizeof(float) * (size+2)); | ||
185 | |||
186 | table->fft = fftwf_plan_dft_r2c_1d(size, table->in, (fftwf_complex *) table->out, FFTW_PATIENT); | ||
187 | table->ifft = fftwf_plan_dft_c2r_1d(size, (fftwf_complex *) table->in, table->out, FFTW_PATIENT); | ||
188 | |||
189 | table->N = size; | ||
190 | return table; | ||
191 | } | ||
192 | |||
193 | void spx_fft_destroy(void *table) | ||
194 | { | ||
195 | struct fftw_config *t = (struct fftw_config *) table; | ||
196 | fftwf_destroy_plan(t->fft); | ||
197 | fftwf_destroy_plan(t->ifft); | ||
198 | fftwf_free(t->in); | ||
199 | fftwf_free(t->out); | ||
200 | speex_free(table); | ||
201 | } | ||
202 | |||
203 | |||
204 | void spx_fft(void *table, spx_word16_t *in, spx_word16_t *out) | ||
205 | { | ||
206 | int i; | ||
207 | struct fftw_config *t = (struct fftw_config *) table; | ||
208 | const int N = t->N; | ||
209 | float *iptr = t->in; | ||
210 | float *optr = t->out; | ||
211 | const float m = 1.0 / N; | ||
212 | for(i=0;i<N;++i) | ||
213 | iptr[i]=in[i] * m; | ||
214 | |||
215 | fftwf_execute(t->fft); | ||
216 | |||
217 | out[0] = optr[0]; | ||
218 | for(i=1;i<N;++i) | ||
219 | out[i] = optr[i+1]; | ||
220 | } | ||
221 | |||
222 | void spx_ifft(void *table, spx_word16_t *in, spx_word16_t *out) | ||
223 | { | ||
224 | int i; | ||
225 | struct fftw_config *t = (struct fftw_config *) table; | ||
226 | const int N = t->N; | ||
227 | float *iptr = t->in; | ||
228 | float *optr = t->out; | ||
229 | |||
230 | iptr[0] = in[0]; | ||
231 | iptr[1] = 0.0f; | ||
232 | for(i=1;i<N;++i) | ||
233 | iptr[i+1] = in[i]; | ||
234 | iptr[N+1] = 0.0f; | ||
235 | |||
236 | fftwf_execute(t->ifft); | ||
237 | |||
238 | for(i=0;i<N;++i) | ||
239 | out[i] = optr[i]; | ||
240 | } | ||
241 | |||
133 | #elif defined(USE_KISS_FFT) | 242 | #elif defined(USE_KISS_FFT) |
134 | 243 | ||
135 | #include "kiss_fftr.h" | 244 | #include "kiss_fftr.h" |