This source file includes following definitions.
- fftss_table_alloc
- fftss_table_add
- fftss_table_free
- fftss_fma_table
- fftss_normal_table
#include <stdio.h>
#include <stdlib.h>
#include "libfftss.h"
typedef struct _fftss_table {
struct _fftss_table *prev, *next;
long n;
long type;
double *w;
long count;
} fftss_table;
fftss_table tables = {&tables, &tables, -1, -1, NULL, -1};
double *fftss_table_alloc(long n, long type)
{
fftss_table *tbl;
tbl = tables.next;
while (tbl->count > 0) {
if (tbl->n == n && tbl->type == type) {
tbl->count++;
return tbl->w;
}
tbl = tbl->next;
}
return NULL;
}
void fftss_table_add(long n, long type, double *w)
{
fftss_table *tbl0, *tbl1;
tbl0 = malloc(sizeof(fftss_table));
tbl1 = tables.prev;
tables.prev = tbl0;
tbl1->next = tbl0;
tbl0->next = &tables;
tbl0->prev = tbl1;
tbl0->n = n;
tbl0->type = type;
tbl0->w = w;
tbl0->count = 1;
}
void fftss_table_free(long n, long type)
{
fftss_table *tbl;
tbl = tables.next;
while (tbl->count > 0) {
if (tbl->n == n && tbl->type == type) {
tbl->count--;
if (tbl->count == 0) {
fftss_free(tbl->w);
tbl->prev->next = tbl->next;
tbl->next->prev = tbl->prev;
free(tbl);
}
return;
}
tbl = tbl->next;
}
return;
}
void fftss_fma_table(fftss_plan_1d p)
{
long i, n;
n = p->n;
for (i = 1; i < n * 3 / 4; i++) {
double sin_i;
sin_i = sin(2.0 * M_PI * (double)i / (double)n);
p->w[2 * i] = cos(2.0 * M_PI * (double)i / (double)n) / sin_i;
p->w[2 * i + 1] = sin_i;
}
for (i = 1; i < n / 4; i++) {
p->w[2 * i + n * 3 / 2] = p->w[i * 6];
p->w[2 * i + n * 3 / 2 + 1] = p->w[i * 6 + 1] / p->w[i * 2 + 1];
}
{
double d0, d1;
d0 = 1.0 / 4.0;
d1 = (double)(1<<16);
d1 = d1 * d1;
d1 = d1 * d1;
d1 = d1 * d1;
d1 = d1 * d1;
#if 0 && defined(__ia64__)
d1 = d1 * d1;
d0 = d0 * d1;
#endif
#if 0
d1 = d1 * d0;
#endif
d0 = 1.0 / d1;
p->w[0] = d1; p->w[n] = -d1;
p->w[1] = p->w[n + 1] = d0;
p->w[n * 3 / 2] = d1;
p->w[n * 3 / 2 + 1] = 1.0;
}
}
void fftss_normal_table(fftss_plan_1d p)
{
long i, n;
n = p->n;
for (i = 0; i < n; i++) {
p->w[2 * i] = cos(2.0 * M_PI * (double)i / (double)n);
p->w[2 * i + 1] = sin(2.0 * M_PI * (double)i / (double)n);
}
}