~ubuntu-branches/ubuntu/saucy/speex/saucy-proposed

« back to all changes in this revision

Viewing changes to libspeex/fftwrap.c

  • Committer: Bazaar Package Importer
  • Author(s): Ron Lee
  • Date: 2008-06-04 03:48:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080604034819-jc7eevhn9behha7w
Tags: 1.2~beta4-2
Move the extra sse libs to /usr/lib/sse2.  That is a bit more elitist than
we need to be, but the linker already looks there without adding yet another
path permutation, and in practice most people who really care about how long
this is going to take won't find that sets the bar too high for them at all.

Actually, it's apparently ldconfig rather than the linker that is missing
this path, but this will still do for now while people figure out if or when
that should be fixed too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include "config.h"
37
37
#endif
38
38
 
39
 
/*#define USE_SMALLFT*/
40
 
#define USE_KISS_FFT
41
 
 
42
 
 
43
39
#include "arch.h"
44
40
#include "os_support.h"
45
41
 
130
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
242
#elif defined(USE_KISS_FFT)
134
243
 
135
244
#include "kiss_fftr.h"