shithub: opus

Download patch

ref: 3dbc1d0df9eb82b0d376d6db70d976e2c4b0c668
parent: 03f9ed300583c4eb8ebb81abf49c427d24893153
author: Jean-Marc Valin <[email protected]>
date: Sat Mar 8 10:21:24 EST 2008

cleaning up some of the mode stuff

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -160,7 +160,7 @@
 }
 
 /** Apply window and compute the MDCT for all sub-frames and all channels in a frame */
-static celt_word32_t compute_mdcts(const mdct_lookup *mdct_lookup, celt_word16_t *window, celt_sig_t *in, celt_sig_t *out, int N, int overlap, int B, int C)
+static celt_word32_t compute_mdcts(const mdct_lookup *mdct_lookup, const celt_word16_t *window, celt_sig_t *in, celt_sig_t *out, int N, int overlap, int B, int C)
 {
    int i, c, N4;
    celt_word32_t E = 0;
@@ -200,7 +200,7 @@
 }
 
 /** Compute the IMDCT and apply window for all sub-frames and all channels in a frame */
-static void compute_inv_mdcts(const mdct_lookup *mdct_lookup, celt_word16_t *window, celt_sig_t *X, celt_sig_t *out_mem, celt_sig_t *mdct_overlap, int N, int overlap, int B, int C)
+static void compute_inv_mdcts(const mdct_lookup *mdct_lookup, const celt_word16_t *window, celt_sig_t *X, celt_sig_t *out_mem, celt_sig_t *mdct_overlap, int N, int overlap, int B, int C)
 {
    int i, c, N4;
    VARDECL(celt_word32_t *x);
--- a/libcelt/dump_modes.c
+++ b/libcelt/dump_modes.c
@@ -37,12 +37,19 @@
 #include "modes.h"
 #include "celt.h"
 
+#define INT16 "%d"
+#define INT32 "%d"
+#define FLOAT "%f"
+
 #ifdef FIXED_POINT
-#define WORD "%d"
+#define WORD16 INT16
+#define WORD32 INT32
 #else
-#define WORD "%f"
+#define WORD16 FLOAT
+#define WORD32 FLOAT
 #endif
 
+
 void dump_modes(FILE *file, CELTMode *modes, int nb_modes)
 {
    int i, j;
@@ -63,7 +70,7 @@
       fprintf(file, "\n");
       fprintf (file, "const celt_word16_t window%d[%d] = {\n", modes->overlap, modes->overlap);
       for (j=0;j<modes->overlap;j++)
-         fprintf (file, WORD ", ", modes->window[j]);
+         fprintf (file, WORD16 ", ", modes->window[j]);
       printf ("};\n");
       fprintf(file, "\n");
       fprintf (file, "const int allocVectors%d_%d[%d] = {\n", modes->Fs, modes->mdctSize, modes->nbEBands*modes->nbAllocVectors);
@@ -78,7 +85,7 @@
       fprintf(file, "\n");
       fprintf(file, "CELTMode mode%d_%d_%d_%d = {\n", modes->Fs, modes->nbChannels, modes->mdctSize, modes->overlap);
       fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
-      fprintf(file, "%d,\t/* Fs */\n", modes->Fs);
+      fprintf(file, INT32 ",\t/* Fs */\n", modes->Fs);
       fprintf(file, "%d,\t/* overlap */\n", modes->overlap);
       fprintf(file, "%d,\t/* mdctSize */\n", modes->mdctSize);
       fprintf(file, "%d,\t/* nbMdctBlocks */\n", modes->nbMdctBlocks);
@@ -88,22 +95,23 @@
       fprintf(file, "%d,\t/* pitchEnd */\n", modes->pitchEnd);
       fprintf(file, "eBands%d_%d,\t/* eBands */\n", modes->Fs, modes->mdctSize);
       fprintf(file, "pBands%d_%d,\t/* pBands */\n", modes->Fs, modes->mdctSize);
-      fprintf(file, "%d,\t/* ePredCoef */\n", modes->ePredCoef);
+      fprintf(file, WORD16 ",\t/* ePredCoef */\n", modes->ePredCoef);
       fprintf(file, "%d,\t/* nbAllocVectors */\n", modes->nbAllocVectors);
       fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", modes->Fs, modes->mdctSize);
       fprintf(file, "0,\t/* bits */\n");
-      fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
-      fprintf(file, "{0, 0, 0},\t/* ,mdct */\n", modes->mdctSize);
+      fprintf(file, "{%d, 0, 0},\t/* mdct */\n", 2*modes->mdctSize);
       fprintf(file, "window%d,\t/* window */\n", modes->overlap);
+      fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
       fprintf(file, "};\n");
       modes++;
    }
 }
 
-#if 0
+#if 1
 int main()
 {
-   CELTMode *m = celt_mode_create(44100, 2, 256, 128, NULL);
+   CELTMode *m = celt_mode_create(44100, 1, 256, 128, NULL);
    dump_modes(stdout, m, 1);
+   return 0;
 }
 #endif
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -218,7 +218,8 @@
    int res;
    int N, i;
    CELTMode *mode;
-   
+   celt_word16_t *window;
+
    /* The good thing here is that permutation of the arguments will automatically be invalid */
    
    if (Fs < 32000 || Fs > 64000)
@@ -268,15 +269,16 @@
    N = mode->mdctSize;
    mdct_init(&mode->mdct, 2*N);
 
-   mode->window = (celt_word16_t*)celt_alloc(mode->overlap*sizeof(celt_word16_t));
+   window = (celt_word16_t*)celt_alloc(mode->overlap*sizeof(celt_word16_t));
 
 #ifndef FIXED_POINT
    for (i=0;i<mode->overlap;i++)
-      mode->window[i] = Q15ONE*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap));
+      window[i] = Q15ONE*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap));
 #else
    for (i=0;i<mode->overlap;i++)
-      mode->window[i] = MIN32(32767,32768.*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap)));
+      window[i] = MIN32(32767,32768.*sin(.5*M_PI* sin(.5*M_PI*(i+.5)/mode->overlap) * sin(.5*M_PI*(i+.5)/mode->overlap)));
 #endif
+   mode->window = window;
 
    mode->marker_start = MODEVALID;
    mode->marker_end = MODEVALID;
@@ -303,7 +305,7 @@
    }
    celt_free((int**)mode->bits);
    mdct_clear(&mode->mdct);
-   celt_free(mode->window);
+   celt_free((celt_word16_t*)mode->window);
 
    mode->marker_start = MODEFREED;
    mode->marker_end = MODEFREED;
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -61,13 +61,13 @@
    const int   *allocVectors;   /**< Number of bits in each band for several rates */
    
    const int * const *bits; /**< Cache for pulses->bits mapping in each band */
-   celt_uint32_t marker_end;
-   
+
    /* Stuff that could go in the {en,de}coder, but we save space this way */
    mdct_lookup mdct;
    
-   celt_word16_t *window;
+   const celt_word16_t *window;
 
+   celt_uint32_t marker_end;
 };
 
 int check_mode(const CELTMode *mode);
--- a/libcelt/quant_pitch.c
+++ b/libcelt/quant_pitch.c
@@ -99,7 +99,7 @@
 
 int unquant_pitch(celt_pgain_t *gains, int len, ec_dec *dec)
 {
-   int i, id;
+   int id;
    id = ec_dec_uint(dec, 128);
    id2gains(id, gains, len);
    return id!=0;