1 /*
2 * AAC definitions and structures
3 * Copyright (c) 2024 Lynne
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
24
26 {
27 float ratio;
28 if (reset) {
31 }
else if (
state->last_len !=
N) {
33 uint8_t last[512 /* 2048 / 4 */];
34 memcpy(last,
state->last,
sizeof(last));
35
37 for (
i = 0;
i <
N/2;
i++) {
38 int k = (int)(
i * ratio);
40 }
41
44
46 }
47
52
54 return state->last[0] << 12;
55 }
56
58 {
63
65
69
71 }
72
74 {
75 int i_min = -1;
78 while ((i_max - i_min) > 1) {
79 i = i_min + ((i_max - i_min) / 2);
83 else if (
c > (j >> 8))
85 else
86 return (j & 0xFF);
87 }
89 }
90
92 uint16_t
a, uint16_t
b)
93 {
98
100 }
101
102 /* Initialize AC */
104 {
106 ac->
high = UINT16_MAX;
108 }
109
111 const uint16_t *cdf, uint16_t cdf_len)
112 {
116
117 int sym;
118 int rng =
high - low + 1;
119 int c = ((((int)(
val - low + 1)) << 14) - ((int)1));
120
121 const uint16_t *
p = cdf - 1;
122
123 /* One for each possible CDF length in the spec */
124 switch (cdf_len) {
125 case 2:
126 if ((
p[1] * rng) >
c)
128 break;
129 case 4:
130 if ((
p[2] * rng) >
c)
132 if ((
p[1] * rng) >
c)
134 break;
135 case 17:
136 /* First check if the current probability is even met at all */
137 if ((
p[1] * rng) <=
c)
138 break;
140 for (
int i = 8;
i >= 1;
i >>= 1)
141 if ((
p[
i] * rng) >
c)
143 break;
144 case 27:
145 if ((
p[16] * rng) >
c)
147 if ((
p[8] * rng) >
c)
149 if (
p != (cdf - 1 + 24))
150 if ((
p[4] * rng) >
c)
152 if ((
p[2] * rng) >
c)
154
155 if (
p != (cdf - 1 + 24 + 2))
156 if ((
p[1] * rng) >
c)
158 break;
159 default:
160 /* This should never happen */
162 }
163
164 sym = (int)((ptrdiff_t)(
p - cdf)) + 1;
165 if (sym)
166 high = low + ((rng * cdf[sym - 1]) >> 14) - 1;
167 low += (rng * cdf[sym]) >> 14;
168
169 /* This loop could be done faster */
170 while (1) {
172 ;
173 } else if (low >= 32768) {
175 low -= 32768;
177 }
else if (low >= 16384 &&
high < 49152) {
179 low -= 16384;
181 } else {
182 break;
183 }
184 low += low;
187 };
188
192
193 return sym;
194 }
195
197 {
199
202
205 }