~vericalcroft/ubuntu/quantal/celt/added-misc-depends

« back to all changes in this revision

Viewing changes to libcelt/dump_modes.c

  • Committer: Bazaar Package Importer
  • Author(s): Ron Lee
  • Date: 2008-04-05 03:07:18 UTC
  • Revision ID: james.westby@ubuntu.com-20080405030718-qayahnc495gy25ng
Tags: upstream-0.3.0
ImportĀ upstreamĀ versionĀ 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* (C) 2008 Jean-Marc Valin, CSIRO
 
2
*/
 
3
/*
 
4
   Redistribution and use in source and binary forms, with or without
 
5
   modification, are permitted provided that the following conditions
 
6
   are met:
 
7
   
 
8
   - Redistributions of source code must retain the above copyright
 
9
   notice, this list of conditions and the following disclaimer.
 
10
   
 
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.
 
14
   
 
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.
 
18
   
 
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.
 
30
*/
 
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
#include "config.h"
 
34
#endif
 
35
 
 
36
#include <stdio.h>
 
37
#include "modes.h"
 
38
#include "celt.h"
 
39
#include "rate.h"
 
40
 
 
41
#define INT16 "%d"
 
42
#define INT32 "%d"
 
43
#define FLOAT "%f"
 
44
 
 
45
#ifdef FIXED_POINT
 
46
#define WORD16 INT16
 
47
#define WORD32 INT32
 
48
#else
 
49
#define WORD16 FLOAT
 
50
#define WORD32 FLOAT
 
51
#endif
 
52
 
 
53
 
 
54
void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
 
55
{
 
56
   int i, j;
 
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");
 
61
 
 
62
   fprintf(file, "\n");
 
63
   for (i=0;i<nb_modes;i++)
 
64
   {
 
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");
 
73
      fprintf(file, "\n");
 
74
      
 
75
      
 
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
      printf ("};\n");
 
82
      fprintf(file, "#endif\n");
 
83
      fprintf(file, "\n");
 
84
      
 
85
      
 
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
      printf ("};\n");
 
92
      fprintf(file, "#endif\n");
 
93
      fprintf(file, "\n");
 
94
      
 
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
      printf ("};\n");
 
101
      fprintf(file, "#endif\n");
 
102
      fprintf(file, "\n");
 
103
 
 
104
      
 
105
      fprintf(file, "#ifndef DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mode->mdctSize);
 
106
      fprintf(file, "#define DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mode->mdctSize);
 
107
      fprintf (file, "static const celt_int16_t allocVectors%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands*mode->nbAllocVectors);
 
108
      for (j=0;j<mode->nbAllocVectors;j++)
 
109
      {
 
110
         int k;
 
111
         for (k=0;k<mode->nbEBands;k++)
 
112
            fprintf (file, "%2d, ", mode->allocVectors[j*mode->nbEBands+k]);
 
113
         fprintf (file, "\n");
 
114
      }
 
115
      fprintf (file, "};\n");
 
116
      fprintf(file, "#endif\n");
 
117
      fprintf(file, "\n");
 
118
      
 
119
      fprintf(file, "#ifndef DEF_ALLOC_CACHE%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
 
120
      fprintf(file, "#define DEF_ALLOC_CACHE%d_%d_%d\n", mode->Fs, mode->mdctSize, mode->nbChannels);
 
121
      for (j=0;j<mode->nbEBands;j++)
 
122
      {
 
123
         int k;
 
124
         if (j==0 || (mode->bits[j] != mode->bits[j-1]))
 
125
         {
 
126
            fprintf (file, "static const celt_int16_t allocCache_band%d_%d_%d_%d[MAX_PULSES] = {\n", j, mode->Fs, mode->mdctSize, mode->nbChannels);
 
127
            for (k=0;k<MAX_PULSES;k++)
 
128
               fprintf (file, "%2d, ", mode->bits[j][k]);
 
129
            fprintf (file, "};\n");
 
130
         } else {
 
131
            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);
 
132
         }
 
133
      }
 
134
      fprintf (file, "static const celt_int16_t *allocCache%d_%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbChannels, mode->nbEBands);
 
135
      for (j=0;j<mode->nbEBands;j++)
 
136
      {
 
137
         fprintf (file, "allocCache_band%d_%d_%d_%d, ", j, mode->Fs, mode->mdctSize, mode->nbChannels);
 
138
      }
 
139
      fprintf (file, "};\n");
 
140
      fprintf(file, "#endif\n");
 
141
      fprintf(file, "\n");
 
142
 
 
143
      
 
144
      fprintf(file, "static const CELTMode mode%d_%d_%d_%d = {\n", mode->Fs, mode->nbChannels, mode->mdctSize, mode->overlap);
 
145
      fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
 
146
      fprintf(file, INT32 ",\t/* Fs */\n", mode->Fs);
 
147
      fprintf(file, "%d,\t/* overlap */\n", mode->overlap);
 
148
      fprintf(file, "%d,\t/* mdctSize */\n", mode->mdctSize);
 
149
      fprintf(file, "%d,\t/* nbMdctBlocks */\n", mode->nbMdctBlocks);
 
150
      fprintf(file, "%d,\t/* nbChannels */\n", mode->nbChannels);
 
151
      fprintf(file, "%d,\t/* nbEBands */\n", mode->nbEBands);
 
152
      fprintf(file, "%d,\t/* nbPBands */\n", mode->nbPBands);
 
153
      fprintf(file, "%d,\t/* pitchEnd */\n", mode->pitchEnd);
 
154
      fprintf(file, "eBands%d_%d,\t/* eBands */\n", mode->Fs, mode->mdctSize);
 
155
      fprintf(file, "pBands%d_%d,\t/* pBands */\n", mode->Fs, mode->mdctSize);
 
156
      fprintf(file, WORD16 ",\t/* ePredCoef */\n", mode->ePredCoef);
 
157
      fprintf(file, "%d,\t/* nbAllocVectors */\n", mode->nbAllocVectors);
 
158
      fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", mode->Fs, mode->mdctSize);
 
159
      fprintf(file, "allocCache%d_%d_%d,\t/* bits */\n", mode->Fs, mode->mdctSize, mode->nbChannels);
 
160
      fprintf(file, "{%d, 0, 0},\t/* mdct */\n", 2*mode->mdctSize);
 
161
      fprintf(file, "window%d,\t/* window */\n", mode->overlap);
 
162
      fprintf(file, "{psy_decayR_%d},\t/* psy */\n", mode->Fs);
 
163
      fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
 
164
      fprintf(file, "};\n");
 
165
   }
 
166
   fprintf(file, "\n");
 
167
   fprintf(file, "/* List of all the available modes */\n");
 
168
   fprintf(file, "#define TOTAL_MODES %d\n", nb_modes);
 
169
   fprintf(file, "static const CELTMode * const static_mode_list[TOTAL_MODES] = {\n");
 
170
   for (i=0;i<nb_modes;i++)
 
171
   {
 
172
      CELTMode *mode = modes[i];
 
173
      fprintf(file, "&mode%d_%d_%d_%d,\n", mode->Fs, mode->nbChannels, mode->mdctSize, mode->overlap);
 
174
   }
 
175
   fprintf(file, "};\n");
 
176
}
 
177
 
 
178
#if 0
 
179
int main()
 
180
{
 
181
   CELTMode *m[3];
 
182
   m[0] = celt_mode_create(44100, 1, 256, 128, NULL);
 
183
   m[1] = celt_mode_create(48000, 1, 256, 128, NULL);
 
184
   m[2] = celt_mode_create(51200, 1, 256, 128, NULL);
 
185
   dump_modes(stdout, m, 1);
 
186
   return 0;
 
187
}
 
188
#endif