1 /**
2 * @file
3 * Common code for Vorbis I encoder and decoder
4 * @author Denes Balatoni ( dbalatoni programozo hu )
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * Common code for Vorbis I encoder and decoder
26 * @author Denes Balatoni ( dbalatoni programozo hu )
27 */
28
33
36
37
38 /* Helper functions */
39
40 // x^(1/n)
42 {
43 unsigned int ret = 0,
i, j;
44
45 do {
47 for (
i = 0, j =
ret;
i < n - 1;
i++)
49 } while (j <= x);
50
52 }
53
54 // Generate vlc codes from vorbis huffman code lengths
55
56 // the two bits[p] > 32 checks should be redundant, all calling code should
57 // already ensure that, but since it allows overwriting the stack it seems
58 // reasonable to check redundantly.
60 {
61 uint32_t exit_at_level[33] = { 404 };
62 unsigned i, j, p,
code;
63
64 for (p = 0; (p < num) && (
bits[p] == 0); ++p)
65 ;
66 if (p == num)
67 return 0;
68
69 codes[p] = 0;
73 exit_at_level[
i+1] = 1
u <<
i;
74
75 ++p;
76
77 for (
i = p; (
i < num) && (
bits[
i] == 0); ++
i)
78 ;
80 return 0;
81
82 for (; p < num; ++p) {
86 continue;
87 // find corresponding exit(node which the tree can grow further from)
90 break;
91 if (!
i)
// overspecified tree
93 code = exit_at_level[
i];
95 // construct code (append 0s to end) and introduce new exits
96 for (j =
i + 1 ;j <=
bits[p]; ++j)
97 exit_at_level[j] =
code + (1
u << (j - 1));
99 }
100
101 //no exits should be left (underspecified tree - ie. unused valid vlcs - not allowed by SPEC)
102 for (p = 1; p < 33; p++)
103 if (exit_at_level[p])
105
106 return 0;
107 }
108
111 {
116 int j;
120 for (j = 2; j <
i; j++) {
125 } else {
128 }
129 }
130 }
132 int j;
133 for (j =
i + 1; j <
values; j++) {
136 "Duplicate value found in floor 1 X coordinates\n");
138 }
143 }
144 }
145 }
146 return 0;
147 }
148
150 intptr_t sy, int ady, int adx,
151 float *buf)
152 {
153 int err = -adx;
154 x -= x1 - 1;
155 buf += x1 - 1;
156 while (++x < 0) {
157 err += ady;
158 if (err >= 0) {
159 err += ady - adx;
160 y += sy;
162 }
164 }
165 if (x <= 0) {
166 if (err + ady >= 0)
167 y += sy;
169 }
170 }
171
172 static void render_line(
int x0,
int y0,
int x1,
int y1,
float *buf)
173 {
174 int dy = y1 - y0;
175 int adx = x1 - x0;
177 int sy = dy < 0 ? -1 : 1;
179 if (ady*2 <= adx) { // optimized common case
181 } else {
183 int x = x0;
184 int y = y0;
185 int err = -adx;
187 while (++x < x1) {
189 err += ady;
190 if (err >= 0) {
191 err -= adx;
192 y += sy;
193 }
195 }
196 }
197 }
198
200 uint16_t *y_list,
int *
flag,
202 {
204 lx = 0;
205 ly = y_list[0] * multiplier;
210 int y1 = y_list[
pos] * multiplier;
213 lx = x1;
214 ly = y1;
215 }
217 break;
218 }
221 }