1 /* (C) 2008 Jean-Marc Valin, CSIRO
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
15 - Neither the name of the Xiph.org Foundation nor the names of its
16 contributors may be used to endorse or promote products derived from
17 this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
57 fprintf(file, "/* The contents of this file is automatically generated and contains static\n");
58 fprintf(file, " definitions for some pre-defined modes */\n");
59 fprintf(file, "#include \"modes.h\"\n");
60 fprintf(file, "#include \"rate.h\"\n");
63 for (i=0;i<nb_modes;i++)
65 CELTMode *mode = modes[i];
66 fprintf(file, "#ifndef DEF_EBANDS%d_%d\n", mode->Fs, mode->mdctSize);
67 fprintf(file, "#define DEF_EBANDS%d_%d\n", mode->Fs, mode->mdctSize);
68 fprintf (file, "static const celt_int16_t eBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands+2);
69 for (j=0;j<mode->nbEBands+2;j++)
70 fprintf (file, "%d, ", mode->eBands[j]);
71 fprintf (file, "};\n");
72 fprintf(file, "#endif\n");
76 fprintf(file, "#ifndef DEF_PBANDS%d_%d\n", mode->Fs, mode->mdctSize);
77 fprintf(file, "#define DEF_PBANDS%d_%d\n", mode->Fs, mode->mdctSize);
78 fprintf (file, "static const celt_int16_t pBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbPBands+2);
79 for (j=0;j<mode->nbPBands+2;j++)
80 fprintf (file, "%d, ", mode->pBands[j]);
81 fprintf (file, "};\n");
82 fprintf(file, "#endif\n");
86 fprintf(file, "#ifndef DEF_WINDOW%d\n", mode->overlap);
87 fprintf(file, "#define DEF_WINDOW%d\n", mode->overlap);
88 fprintf (file, "static const celt_word16_t window%d[%d] = {\n", mode->overlap, mode->overlap);
89 for (j=0;j<mode->overlap;j++)
90 fprintf (file, WORD16 ", ", mode->window[j]);
91 fprintf (file, "};\n");
92 fprintf(file, "#endif\n");
95 fprintf(file, "#ifndef DEF_PSY%d\n", mode->Fs);
96 fprintf(file, "#define DEF_PSY%d\n", mode->Fs);
97 fprintf (file, "static const celt_word16_t psy_decayR_%d[%d] = {\n", mode->Fs, MAX_PERIOD/2);
98 for (j=0;j<MAX_PERIOD/2;j++)
99 fprintf (file, WORD16 ", ", mode->psy.decayR[j]);
100 fprintf (file, "};\n");
101 fprintf(file, "#endif\n");
105 fprintf(file, "#ifndef DEF_ALLOC_VECTORS%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
106 fprintf(file, "#define DEF_ALLOC_VECTORS%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
107 fprintf (file, "static const celt_int16_t allocVectors%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands*mode->nbAllocVectors);
108 for (j=0;j<mode->nbAllocVectors;j++)
111 for (k=0;k<mode->nbEBands;k++)
112 fprintf (file, "%2d, ", mode->allocVectors[j*mode->nbEBands+k]);
113 fprintf (file, "\n");
115 fprintf (file, "};\n");
116 fprintf(file, "#endif\n");
119 fprintf(file, "#ifndef DEF_ALLOC_ENERGY%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
120 fprintf(file, "#define DEF_ALLOC_ENERGY%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
121 fprintf (file, "static const celt_int16_t allocEnergy%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands*mode->nbAllocVectors);
122 for (j=0;j<mode->nbAllocVectors;j++)
125 for (k=0;k<mode->nbEBands;k++)
126 fprintf (file, "%2d, ", mode->energy_alloc[j*mode->nbEBands+k]);
127 fprintf (file, "\n");
129 fprintf (file, "};\n");
130 fprintf(file, "#endif\n");
133 fprintf(file, "#ifndef DEF_ALLOC_CACHE%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
134 fprintf(file, "#define DEF_ALLOC_CACHE%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
135 for (j=0;j<mode->nbEBands;j++)
138 if (j==0 || (mode->bits[j] != mode->bits[j-1]))
140 fprintf (file, "static const celt_int16_t allocCache_band%d_%d_%d_%d[MAX_PULSES] = {\n", j, mode->Fs, mode->mdctSize, mode->nbChannels);
141 for (k=0;k<MAX_PULSES;k++)
142 fprintf (file, "%2d, ", mode->bits[j][k]);
143 fprintf (file, "};\n");
145 fprintf (file, "#define allocCache_band%d_%d_%d_%d allocCache_band%d_%d_%d_%d\n", j, mode->Fs, mode->mdctSize, mode->nbChannels, j-1, mode->Fs, mode->mdctSize, mode->nbChannels);
148 fprintf (file, "static const celt_int16_t *allocCache%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands);
149 for (j=0;j<mode->nbEBands;j++)
151 fprintf (file, "allocCache_band%d_%d_%d_%d, ", j, mode->Fs, mode->mdctSize, mode->nbChannels);
153 fprintf (file, "};\n");
154 fprintf(file, "#endif\n");
158 if (mode->bits_stereo)
160 fprintf(file, "#ifndef DEF_ALLOC_STEREO_CACHE%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
161 fprintf(file, "#define DEF_ALLOC_STEREO_CACHE%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
162 for (j=0;j<mode->nbEBands;j++)
165 if (j==0 || (mode->bits[j] != mode->bits_stereo[j-1]))
167 fprintf (file, "static const celt_int16_t allocStereoCache_band%d_%d_%d_%d[MAX_PULSES] = {\n", j, mode->Fs, mode->mdctSize, mode->nbChannels);
168 for (k=0;k<MAX_PULSES;k++)
169 fprintf (file, "%2d, ", mode->bits_stereo[j][k]);
170 fprintf (file, "};\n");
172 fprintf (file, "#define allocStereoCache_band%d_%d_%d_%d allocStereoCache_band%d_%d_%d_%d\n", j, mode->Fs, mode->mdctSize, mode->nbChannels, j-1, mode->Fs, mode->mdctSize, mode->nbChannels);
175 fprintf (file, "static const celt_int16_t *allocStereoCache%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands);
176 for (j=0;j<mode->nbEBands;j++)
178 fprintf (file, "allocStereoCache_band%d_%d_%d_%d, ", j, mode->Fs, mode->mdctSize, mode->nbChannels);
180 fprintf (file, "};\n");
181 fprintf(file, "#endif\n");
186 fprintf(file, "static const CELTMode mode%d_%d_%d_%d = {\n", mode->Fs, mode->nbChannels, mode->mdctSize, mode->overlap);
187 fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
188 fprintf(file, INT32 ",\t/* Fs */\n", mode->Fs);
189 fprintf(file, "%d,\t/* overlap */\n", mode->overlap);
190 fprintf(file, "%d,\t/* mdctSize */\n", mode->mdctSize);
191 fprintf(file, "%d,\t/* nbChannels */\n", mode->nbChannels);
192 fprintf(file, "%d,\t/* nbEBands */\n", mode->nbEBands);
193 fprintf(file, "%d,\t/* nbPBands */\n", mode->nbPBands);
194 fprintf(file, "%d,\t/* pitchEnd */\n", mode->pitchEnd);
195 fprintf(file, "eBands%d_%d,\t/* eBands */\n", mode->Fs, mode->mdctSize);
196 fprintf(file, "pBands%d_%d,\t/* pBands */\n", mode->Fs, mode->mdctSize);
197 fprintf(file, WORD16 ",\t/* ePredCoef */\n", mode->ePredCoef);
198 fprintf(file, "%d,\t/* nbAllocVectors */\n", mode->nbAllocVectors);
199 fprintf(file, "allocVectors%d_%d_%d,\t/* allocVectors */\n", mode->Fs, mode->mdctSize, mode->nbChannels);
200 fprintf(file, "allocCache%d_%d_%d,\t/* bits */\n", mode->Fs, mode->mdctSize, mode->nbChannels);
201 if (mode->bits_stereo)
202 fprintf(file, "allocStereoCache%d_%d_%d,\t/* bits_stereo */\n", mode->Fs, mode->mdctSize, mode->nbChannels);
204 fprintf(file, "0,\t/* bits_stereo */\n");
205 fprintf(file, "{%d, 0, 0},\t/* mdct */\n", 2*mode->mdctSize);
206 fprintf(file, "0,\t/* fft */\n");
207 fprintf(file, "window%d,\t/* window */\n", mode->overlap);
208 fprintf(file, "%d,\t/* nbShortMdcts */\n", mode->nbShortMdcts);
209 fprintf(file, "%d,\t/* shortMdctSize */\n", mode->shortMdctSize);
210 fprintf(file, "{%d, 0, 0},\t/* shortMdct */\n", 2*mode->mdctSize);
211 fprintf(file, "window%d,\t/* shortWindow */\n", mode->overlap);
212 fprintf(file, "{psy_decayR_%d},\t/* psy */\n", mode->Fs);
213 fprintf(file, "0,\t/* prob */\n");
214 fprintf(file, "allocEnergy%d_%d_%d,\t/* energy_alloc */\n", mode->Fs, mode->mdctSize, mode->nbChannels);
215 fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
216 fprintf(file, "};\n");
219 fprintf(file, "/* List of all the available modes */\n");
220 fprintf(file, "#define TOTAL_MODES %d\n", nb_modes);
221 fprintf(file, "static const CELTMode * const static_mode_list[TOTAL_MODES] = {\n");
222 for (i=0;i<nb_modes;i++)
224 CELTMode *mode = modes[i];
225 fprintf(file, "&mode%d_%d_%d_%d,\n", mode->Fs, mode->nbChannels, mode->mdctSize, mode->overlap);
227 fprintf(file, "};\n");
230 void dump_header(FILE *file, CELTMode **modes, int nb_modes)
236 fprintf (file, "/* This header file is generated automatically*/\n");
237 for (i=0;i<nb_modes;i++)
239 CELTMode *mode = modes[i];
241 channels = mode->nbChannels;
242 else if (channels != mode->nbChannels)
245 frame_size = mode->mdctSize;
246 else if (frame_size != mode->mdctSize)
249 overlap = mode->overlap;
250 else if (overlap != mode->overlap)
255 fprintf (file, "#define CHANNELS(mode) %d\n", channels);
257 fprintf (file, "#define DISABLE_STEREO\n");
261 fprintf (file, "#define FRAMESIZE(mode) %d\n", frame_size);
265 fprintf (file, "#define OVERLAP(mode) %d\n", overlap);
269 int main(int argc, char **argv)
276 fprintf (stderr, "must have a multiple of 4 arguments\n");
280 m = malloc(nb*sizeof(CELTMode*));
284 Fs = atoi(argv[3*i+1]);
285 ch = atoi(argv[3*i+2]);
286 frame = atoi(argv[3*i+3]);
287 m[i] = celt051_mode_create(Fs, ch, frame, NULL);
289 file = fopen("static_modes.c", "w");
290 dump_modes(file, m, nb);
292 file = fopen("static_modes.h", "w");
293 dump_header(file, m, nb);
296 celt051_mode_destroy(m[i]);