paraslash 0.7.3
[paraslash.git] / imdct.c
diff --git a/imdct.c b/imdct.c
index 32928487b724653535d604adbf690e013a7eb516..2e1089f1f818be4bcdeb20be3d4d7a865943e00e 100644 (file)
--- a/imdct.c
+++ b/imdct.c
@@ -7,18 +7,14 @@
  * Copyright (c) 2002 Fabrice Bellard
  * Partly based on libdjbfft by D. J. Bernstein
  *
- * Licensed under the GNU Lesser General Public License.
- * For licencing details see COPYING.LIB.
+ * Licensed under the GNU Lesser General Public License, see file COPYING.LIB.
  */
 
 /**
  * \file imdct.c Inverse modified discrete cosine transform.
  */
 
-#include <inttypes.h>
 #include <math.h>
-#include <string.h>
-#include <stdlib.h>
 #include <regex.h>
 
 #include "para.h"
@@ -58,7 +54,9 @@ struct mdct_context {
        struct fft_context fft;
 };
 
-/** cos(2 * pi * x / n) for 0 <= x <= n / 4, followed by its reverse */
+/** \cond cosine_tabs */
+
+/* cos(2 * pi * x / n) for 0 <= x <= n / 4, followed by its reverse */
 #define COSINE_TAB(n) static fftsample_t cos_ ## n[n / 2] __a_aligned(16)
 
 COSINE_TAB(16);
@@ -79,6 +77,7 @@ static fftsample_t *cos_tabs[] = {
        cos_16, cos_32, cos_64, cos_128, cos_256, cos_512, cos_1024, cos_2048,
        cos_4096, cos_8192, cos_16384, cos_32768, cos_65536,
 };
+/** \endcond cosine_tabs */
 
 __a_const static int split_radix_permutation(int i, int n)
 {
@@ -141,28 +140,26 @@ __a_const static int split_radix_permutation(int i, int n)
 }
 
 /* z[0...8n - 1], w[1...2n - 1] */
-#define PASS(name)\
-static void name(struct fft_complex *z, const fftsample_t *wre, unsigned int n)\
-{\
-       fftsample_t t1, t2, t3, t4, t5, t6;\
-       int o1 = 2 * n;\
-       int o2 = 4 * n;\
-       int o3 = 6 * n;\
-       const fftsample_t *wim = wre + o1;\
-       n--;\
-\
-       TRANSFORM_ZERO(z[0], z[o1], z[o2], z[o3]);\
-       TRANSFORM(z[1], z[o1 + 1], z[o2 + 1], z[o3 + 1], wre[1], wim[-1]);\
-       do {\
-               z += 2;\
-               wre += 2;\
-               wim -= 2;\
-               TRANSFORM(z[0], z[o1], z[o2], z[o3], wre[0], wim[0]);\
-               TRANSFORM(z[1], z[o1 + 1], z[o2 + 1], z[o3 + 1], wre[1], wim[-1]);\
-       } while (--n);\
+static void pass(struct fft_complex *z, const fftsample_t *wre, unsigned int n)
+{
+       fftsample_t t1, t2, t3, t4, t5, t6;
+       int o1 = 2 * n;
+       int o2 = 4 * n;
+       int o3 = 6 * n;
+       const fftsample_t *wim = wre + o1;
+
+       n--;
+       TRANSFORM_ZERO(z[0], z[o1], z[o2], z[o3]);
+       TRANSFORM(z[1], z[o1 + 1], z[o2 + 1], z[o3 + 1], wre[1], wim[-1]);
+       do {
+               z += 2;
+               wre += 2;
+               wim -= 2;
+               TRANSFORM(z[0], z[o1], z[o2], z[o3], wre[0], wim[0]);
+               TRANSFORM(z[1], z[o1 + 1], z[o2 + 1], z[o3 + 1], wre[1], wim[-1]);
+       } while (--n);
 }
 
-PASS(pass)
 #undef BUTTERFLIES
 #define BUTTERFLIES BUTTERFLIES_BIG
 
@@ -293,7 +290,6 @@ static void imdct_half(struct mdct_context *s, fftsample_t *output,
        fft(&s->fft, z);
 
        /* post rotation + reordering */
-       output += n4;
        for (k = 0; k < n8; k++) {
                fftsample_t r0, i0, r1, i1;
                CMUL(r0, i1, z[n8 - k - 1].im, z[n8 - k - 1].re,
@@ -340,7 +336,7 @@ static int fft_init(struct fft_context *s, int nbits)
        s->nbits = nbits;
        n = 1 << nbits;
 
-       s->revtab = para_malloc(n * sizeof(uint16_t));
+       s->revtab = arr_alloc(n, sizeof(uint16_t));
        for (j = 4; j <= nbits; j++) {
                int k = 1 << j;
                double freq = 2 * M_PI / k;
@@ -370,13 +366,13 @@ int imdct_init(int nbits, struct mdct_context **result)
        double alpha;
        struct mdct_context *s;
 
-       s = para_calloc(sizeof(*s));
+       s = zalloc(sizeof(*s));
        n = 1 << nbits;
        s->nbits = nbits;
        s->n = n;
        n4 = n >> 2;
-       s->tcos = para_malloc(n4 * sizeof(fftsample_t));
-       s->tsin = para_malloc(n4 * sizeof(fftsample_t));
+       s->tcos = arr_alloc(n4, sizeof(fftsample_t));
+       s->tsin = arr_alloc(n4, sizeof(fftsample_t));
 
        for (i = 0; i < n4; i++) {
                alpha = 2 * M_PI * (i + 1.0 / 8.0) / n;