From 86dd98409ff689597ef9859eb0919828136dce33 Mon Sep 17 00:00:00 2001
From: Gregory Maxwell <greg@xiph.org>
Date: Fri, 12 Aug 2011 19:03:29 -0400
Subject: [PATCH] Rearrange mode structure to avoid wasting memory from
 padding.

---
 libcelt/celt.c               |  6 +++---
 libcelt/dump_modes.c         | 12 +++++++-----
 libcelt/modes.h              | 12 ++++--------
 libcelt/static_modes_fixed.h |  8 ++++----
 libcelt/static_modes_float.h |  8 ++++----
 5 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/libcelt/celt.c b/libcelt/celt.c
index f06a20692..8de9ddeb8 100644
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -162,15 +162,15 @@ struct CELTEncoder {
 #endif
    int consec_transient;
 
+   opus_val32 preemph_memE[2];
+   opus_val32 preemph_memD[2];
+
    /* VBR-related parameters */
    opus_int32 vbr_reservoir;
    opus_int32 vbr_drift;
    opus_int32 vbr_offset;
    opus_int32 vbr_count;
 
-   opus_val32 preemph_memE[2];
-   opus_val32 preemph_memD[2];
-
 #ifdef RESYNTH
    celt_sig syn_mem[2][2*MAX_PERIOD];
 #endif
diff --git a/libcelt/dump_modes.c b/libcelt/dump_modes.c
index d963ff10f..96f6f9cdc 100644
--- a/libcelt/dump_modes.c
+++ b/libcelt/dump_modes.c
@@ -211,22 +211,24 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
          fprintf(file, "eband5ms,\t/* eBands */\n");
       else
          fprintf(file, "eBands%d_%d,\t/* eBands */\n", mode->Fs, mdctSize);
+
+      fprintf(file, "%d,\t/* maxLM */\n", mode->maxLM);
+      fprintf(file, "%d,\t/* nbShortMdcts */\n", mode->nbShortMdcts);
+      fprintf(file, "%d,\t/* shortMdctSize */\n", mode->shortMdctSize);
+
       fprintf(file, "%d,\t/* nbAllocVectors */\n", mode->nbAllocVectors);
       if (standard)
          fprintf(file, "band_allocation,\t/* allocVectors */\n");
       else
          fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", mode->Fs, mdctSize);
 
+      fprintf(file, "logN%d,\t/* logN */\n", framerate);
+      fprintf(file, "window%d,\t/* window */\n", mode->overlap);
       fprintf(file, "{%d, %d, {", mode->mdct.n, mode->mdct.maxshift);
       for (k=0;k<=mode->mdct.maxshift;k++)
          fprintf(file, "&fft_state%d_%d_%d, ", mode->Fs, mdctSize, k);
       fprintf (file, "}, mdct_twiddles%d},\t/* mdct */\n", mdctSize);
 
-      fprintf(file, "window%d,\t/* window */\n", mode->overlap);
-      fprintf(file, "%d,\t/* maxLM */\n", mode->maxLM);
-      fprintf(file, "%d,\t/* nbShortMdcts */\n", mode->nbShortMdcts);
-      fprintf(file, "%d,\t/* shortMdctSize */\n", mode->shortMdctSize);
-      fprintf(file, "logN%d,\t/* logN */\n", framerate);
       fprintf(file, "{%d, cache_index%d, cache_bits%d, cache_caps%d},\t/* cache */\n",
             mode->cache.size, mode->Fs/mdctSize, mode->Fs/mdctSize, mode->Fs/mdctSize);
       fprintf(file, "};\n");
diff --git a/libcelt/modes.h b/libcelt/modes.h
index 8ad6a4f6b..33cd03850 100644
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -74,20 +74,16 @@ struct CELTMode {
    opus_val16    preemph[4];
    const opus_int16   *eBands;   /**< Definition for each "pseudo-critical band" */
 
-   int          nbAllocVectors; /**< Number of lines in the matrix below */
-   const unsigned char   *allocVectors;   /**< Number of bits in each band for several rates */
-
-   /* Stuff that could go in the {en,de}coder, but we save space this way */
-   mdct_lookup mdct;
-
-   const opus_val16 *window;
-
    int         maxLM;
    int         nbShortMdcts;
    int         shortMdctSize;
 
+   int          nbAllocVectors; /**< Number of lines in the matrix below */
+   const unsigned char   *allocVectors;   /**< Number of bits in each band for several rates */
    const opus_int16 *logN;
 
+   const opus_val16 *window;
+   mdct_lookup mdct;
    PulseCache cache;
 };
 
diff --git a/libcelt/static_modes_fixed.h b/libcelt/static_modes_fixed.h
index 1c984a2c9..b377ef697 100644
--- a/libcelt/static_modes_fixed.h
+++ b/libcelt/static_modes_fixed.h
@@ -112,14 +112,14 @@ static const CELTMode mode48000_960_120 = {
 21,	/* effEBands */
 {27853, 0, 4096, 8192, },	/* preemph */
 eband5ms,	/* eBands */
-11,	/* nbAllocVectors */
-band_allocation,	/* allocVectors */
-{1920, 3, {&fft_state48000_960_0, &fft_state48000_960_1, &fft_state48000_960_2, &fft_state48000_960_3, }, mdct_twiddles960},	/* mdct */
-window120,	/* window */
 3,	/* maxLM */
 8,	/* nbShortMdcts */
 120,	/* shortMdctSize */
+11,	/* nbAllocVectors */
+band_allocation,	/* allocVectors */
 logN400,	/* logN */
+window120,	/* window */
+{1920, 3, {&fft_state48000_960_0, &fft_state48000_960_1, &fft_state48000_960_2, &fft_state48000_960_3, }, mdct_twiddles960},	/* mdct */
 {392, cache_index50, cache_bits50, cache_caps50},	/* cache */
 };
 
diff --git a/libcelt/static_modes_float.h b/libcelt/static_modes_float.h
index bed9ccde1..0f78132be 100644
--- a/libcelt/static_modes_float.h
+++ b/libcelt/static_modes_float.h
@@ -116,14 +116,14 @@ static const CELTMode mode48000_960_120 = {
 21,	/* effEBands */
 {0.85000610f, 0.0000000f, 1.0000000f, 1.0000000f, },	/* preemph */
 eband5ms,	/* eBands */
-11,	/* nbAllocVectors */
-band_allocation,	/* allocVectors */
-{1920, 3, {&fft_state48000_960_0, &fft_state48000_960_1, &fft_state48000_960_2, &fft_state48000_960_3, }, mdct_twiddles960},	/* mdct */
-window120,	/* window */
 3,	/* maxLM */
 8,	/* nbShortMdcts */
 120,	/* shortMdctSize */
+11,	/* nbAllocVectors */
+band_allocation,	/* allocVectors */
 logN400,	/* logN */
+window120,	/* window */
+{1920, 3, {&fft_state48000_960_0, &fft_state48000_960_1, &fft_state48000_960_2, &fft_state48000_960_3, }, mdct_twiddles960},	/* mdct */
 {392, cache_index50, cache_bits50, cache_caps50},	/* cache */
 };
 
-- 
GitLab