shithub: opus

Download patch

ref: 2a6039b3f48759981138f0e25655212b03e2c160
parent: c209c342bffc3a601adf09bf3092e47808dae646
author: Jean-Marc Valin <[email protected]>
date: Fri Mar 7 17:25:27 EST 2008

Adding code to dump the contents of a mode struct to a C file that can be
compiled without having to use the initialisation code.

--- a/libcelt/Makefile.am
+++ b/libcelt/Makefile.am
@@ -14,10 +14,10 @@
 lib_LTLIBRARIES = libcelt.la
 
 # Sources for compilation in the library
-libcelt_la_SOURCES = bands.c celt.c cwrs.c ecintrin.h \
-	entcode.c entdec.c entenc.c header.c kfft_single.c kiss_fft.c \
-	kiss_fftr.c laplace.c mdct.c modes.c pitch.c psy.c quant_bands.c \
-	quant_pitch.c rangedec.c rangeenc.c rate.c vq.c
+libcelt_la_SOURCES = bands.c celt.c cwrs.c dump_modes.c ecintrin.h entcode.c \
+	entdec.c entenc.c header.c kfft_single.c kiss_fft.c kiss_fftr.c laplace.c mdct.c \
+	modes.c pitch.c psy.c quant_bands.c quant_pitch.c rangedec.c rangeenc.c rate.c \
+	vq.c
 
 #noinst_HEADERS =
 
--- /dev/null
+++ b/libcelt/dump_modes.c
@@ -1,0 +1,109 @@
+/* (C) 2008 Jean-Marc Valin, CSIRO
+*/
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include "modes.h"
+#include "celt.h"
+
+#ifdef FIXED_POINT
+#define WORD "%d"
+#else
+#define WORD "%f"
+#endif
+
+void dump_modes(FILE *file, CELTMode *modes, int nb_modes)
+{
+   int i, j;
+   for (i=0;i<nb_modes;i++)
+   {
+      fprintf(file, "#include \"modes.h\"\n");
+
+      fprintf(file, "\n");
+      fprintf (file, "const int eBands%d_%d[%d] = {\n", modes->Fs, modes->mdctSize, modes->nbEBands+2);
+      for (j=0;j<modes->nbEBands+2;j++)
+         fprintf (file, "%d, ", modes->eBands[j]);
+      fprintf (file, "};\n");
+      fprintf(file, "\n");
+      fprintf (file, "const int pBands%d_%d[%d] = {\n", modes->Fs, modes->mdctSize, modes->nbPBands+2);
+      for (j=0;j<modes->nbPBands+2;j++)
+         fprintf (file, "%d, ", modes->pBands[j]);
+      printf ("};\n");
+      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]);
+      printf ("};\n");
+      fprintf(file, "\n");
+      fprintf (file, "const int allocVectors%d_%d[%d] = {\n", modes->Fs, modes->mdctSize, modes->nbEBands*modes->nbAllocVectors);
+      for (j=0;j<modes->nbAllocVectors;j++)
+      {
+         int k;
+         for (k=0;k<modes->nbEBands;k++)
+            fprintf (file, "%2d, ", modes->allocVectors[j*modes->nbEBands+k]);
+         fprintf (file, "\n");
+      }
+      fprintf (file, "};\n");
+      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, "%d,\t/* overlap */\n", modes->overlap);
+      fprintf(file, "%d,\t/* mdctSize */\n", modes->mdctSize);
+      fprintf(file, "%d,\t/* nbMdctBlocks */\n", modes->nbMdctBlocks);
+      fprintf(file, "%d,\t/* nbChannels */\n", modes->nbChannels);
+      fprintf(file, "%d,\t/* nbEBands */\n", modes->nbEBands);
+      fprintf(file, "%d,\t/* nbPBands */\n", modes->nbPBands);
+      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, "%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, "window%d,\t/* window */\n", modes->overlap);
+      fprintf(file, "};\n");
+      modes++;
+   }
+}
+
+#if 0
+int main()
+{
+   CELTMode *m = celt_mode_create(44100, 2, 256, 128, NULL);
+   dump_modes(stdout, m, 1);
+}
+#endif