X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=imdct.c;h=f77da7bb7228c6a982dff314ba3fd459f3006d32;hb=6e3e6ad58782bbd5b6249700e6c52fc8e2a16809;hp=db68bc834764b125f1929785069de49131acfc7b;hpb=537de45f0091a6129bc26602496384b464117863;p=paraslash.git diff --git a/imdct.c b/imdct.c index db68bc83..f77da7bb 100644 --- a/imdct.c +++ b/imdct.c @@ -39,30 +39,34 @@ struct fft_context { }; 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; }; -/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */ -DECLARE_ALIGNED_16(fftsample_t, ff_cos_16[8]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_32[16]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_64[32]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_128[64]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_256[128]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_512[256]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_1024[512]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_2048[1024]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_4096[2048]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_8192[4096]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_16384[8192]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_32768[16384]); -DECLARE_ALIGNED_16(fftsample_t, ff_cos_65536[32768]); +/** cos(2 * pi * x / n) for 0 <= x <= n / 4, followed by its reverse */ +#define COSINE_TAB(n) fftsample_t ff_cos_ ## n[n / 2] __aligned(16) + +COSINE_TAB(16); +COSINE_TAB(32); +COSINE_TAB(64); +COSINE_TAB(128); +COSINE_TAB(256); +COSINE_TAB(512); +COSINE_TAB(1024); +COSINE_TAB(2048); +COSINE_TAB(4096); +COSINE_TAB(8192); +COSINE_TAB(16384); +COSINE_TAB(32768); +COSINE_TAB(65536); static fftsample_t *ff_cos_tabs[] = { ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, @@ -85,7 +89,8 @@ static int split_radix_permutation(int i, int n) 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;\ @@ -297,19 +302,22 @@ static void imdct_half(struct mdct_context *s, fftsample_t *output, } /** - * 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]; @@ -343,6 +351,12 @@ static int fft_init(struct fft_context *s, int nbits) /** * 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, struct mdct_context **result) { @@ -375,10 +389,15 @@ fail: 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); - freep(&ctx->fft.revtab); + free(ctx->tcos); + free(ctx->tsin); + free(ctx->fft.revtab); free(ctx); }