struct fft_context {
int nbits;
- int inverse;
uint16_t *revtab;
- struct fft_complex *exptab;
};
struct mdct_context {
- /** Size of MDCT (i.e. number of input data * 2). */
+ /** Size of MDCT (number of input data * 2). */
int n;
/** n = 2^n bits. */
int nbits;
- /** pre/post rotation tables */
+ /** Cosine table for pre/post rotation. */
fftsample_t *tcos;
+ /** Sine table for pre/post rotation. */
fftsample_t *tsin;
+ /** The context for the underlying fast Fourier transform. */
struct fft_context fft;
};
ff_cos_16384, ff_cos_32768, ff_cos_65536,
};
-static int split_radix_permutation(int i, int n, int inverse)
+static int split_radix_permutation(int i, int n)
{
int m;
if (n <= 2)
return i & 1;
m = n >> 1;
- if (!(i & m))
- return split_radix_permutation(i, m, inverse) * 2;
+ if ((i & m) == 0)
+ return split_radix_permutation(i, m) * 2;
m >>= 1;
- if (inverse == !(i & m))
- return split_radix_permutation(i, m, inverse) * 4 + 1;
+ if ((i & m) == 0)
+ return split_radix_permutation(i, m) * 4 + 1;
else
- return split_radix_permutation(i, m, inverse) * 4 - 1;
+ return split_radix_permutation(i, m) * 4 - 1;
}
-#define SQRTHALF (float)0.70710678118654752440 /* 1/sqrt(2) */
+/** 1 / sqrt(2). */
+#define SQRTHALF (float)0.70710678118654752440
#define BF(x,y,a,b) {\
x = a - b;\
}
/**
- * Compute the inverse MDCT of size N = 2^nbits.
+ * Compute the inverse MDCT.
*
+ * \param ctx The initialized context structure.
* \param output N samples.
* \param input N/2 samples.
+ *
+ * \sa \ref imdct_init().
*/
-void imdct(struct mdct_context *s, float *output, const float *input)
+void imdct(struct mdct_context *ctx, float *output, const float *input)
{
int k;
- int n = 1 << s->nbits;
+ int n = 1 << ctx->nbits;
int n2 = n >> 1;
int n4 = n >> 2;
- imdct_half(s, output + n4, input);
+ imdct_half(ctx, output + n4, input);
for (k = 0; k < n4; k++) {
output[k] = -output[n2 - k - 1];
}
}
-static int fft_init(struct fft_context *s, int nbits, int inverse)
+static int fft_init(struct fft_context *s, int nbits)
{
int i, j, n;
s->nbits = nbits;
n = 1 << nbits;
- s->exptab = para_malloc((n / 2) * sizeof(struct fft_complex));
s->revtab = para_malloc(n * sizeof(uint16_t));
- s->inverse = inverse;
for (j = 4; j <= nbits; j++) {
int k = 1 << j;
double freq = 2 * M_PI / k;
tab[k / 2 - i] = tab[i];
}
for (i = 0; i < n; i++)
- s->revtab[-split_radix_permutation(
- i, n, s->inverse) & (n - 1)] = i;
+ s->revtab[-split_radix_permutation(i, n) & (n - 1)] = i;
return 0;
}
-static void fft_end(struct fft_context *ctx)
-{
- freep(&ctx->revtab);
- freep(&ctx->exptab);
-}
-
/**
- * Init MDCT or IMDCT computation.
+ * Initialize the inverse modified cosine transform.
+ *
+ * \param nbits The number of bits to use (4 <= \a nbits <= 18).
+ *
+ * \param result Opaque structure that must be passed to \ref imdct().
+ *
+ * \return Standard.
*/
-int imdct_init(int nbits, int inverse, struct mdct_context **result)
+int imdct_init(int nbits, struct mdct_context **result)
{
int ret, n, n4, i;
double alpha;
s->tcos[i] = -cos(alpha);
s->tsin[i] = -sin(alpha);
}
- ret = fft_init(&s->fft, s->nbits - 2, inverse);
+ ret = fft_init(&s->fft, s->nbits - 2);
if (ret < 0)
goto fail;
*result = s;
return ret;
}
+/**
+ * Deallocate imdct resources.
+ *
+ * \param ctx The pointer obtained by imdct_init().
+ */
void imdct_end(struct mdct_context *ctx)
{
- freep(&ctx->tcos);
- freep(&ctx->tsin);
- fft_end(&ctx->fft);
+ free(ctx->tcos);
+ free(ctx->tsin);
+ free(ctx->fft.revtab);
free(ctx);
}