| 1 | /* |
| 2 | * ACM decoder. |
| 3 | * |
| 4 | * Copyright (c) 2004-2010, Marko Kreen |
| 5 | * |
| 6 | * Permission to use, copy, modify, and/or distribute this software for any |
| 7 | * purpose with or without fee is hereby granted, provided that the above |
| 8 | * copyright notice and this permission notice appear in all copies. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include "config.h" |
| 21 | #endif |
| 22 | |
| 23 | #include <stdint.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | #include "libacm.h"cxx . . $ `<file>/third_party/libacm/libacm.h`/ |
| 29 | |
| 30 | #define ACM_BUFLENcxx . . $ `third_party/libacm/decode.c:30:9`! (64*1024) |
| 31 | |
| 32 | #define ACM_EXPECTED_EOFcxx . . $ `third_party/libacm/decode.c:32:9`! -99 |
| 33 | |
| 34 | typedef int (*filler_tcxx . . $ filler_t#)(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col); |
| 35 | |
| 36 | /************************************** |
| 37 | * Stream processing |
| 38 | **************************************/ |
| 39 | |
| 40 | /* NB: bits <= 31! Thus less checks in code. */ |
| 41 | |
| 42 | static int load_bufcxx . . $ load_buf(ed2c4f9031459999).(ACMStreamcxx . . $ ACMStream# *acm) |
| 43 | { |
| 44 | int res = 0; |
| 45 | |
| 46 | if (acm->file_eofcxx . . $ ACMStream#file_eof.) |
| 47 | return 0; |
| 48 | |
| 49 | acm->buf_start_ofscxx . . $ ACMStream#buf_start_ofs. += acm->buf_sizecxx . . $ ACMStream#buf_size.; |
| 50 | |
| 51 | if (acm->iocxx . . $ ACMStream#io..read_funccxx . . $ acm_io_callbacks#read_func. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 52 | res = acm->iocxx . . $ ACMStream#io..read_funccxx . . $ acm_io_callbacks#read_func.(acm->bufcxx . . $ ACMStream#buf., 1, acm->buf_maxcxx . . $ ACMStream#buf_max., |
| 53 | acm->io_argcxx . . $ ACMStream#io_arg.); |
| 54 | |
| 55 | if (res < 0) |
| 56 | return ACM_ERR_READ_ERRcxx . . $ `third_party/libacm/libacm.h:35:9`!; |
| 57 | |
| 58 | if (res == 0) { |
| 59 | acm->file_eofcxx . . $ ACMStream#file_eof. = 1; |
| 60 | /* add single zero byte */ |
| 61 | acm->bufcxx . . $ ACMStream#buf.[0] = 0; |
| 62 | acm->buf_sizecxx . . $ ACMStream#buf_size. = 1; |
| 63 | } else { |
| 64 | acm->buf_sizecxx . . $ ACMStream#buf_size. = res; |
| 65 | } |
| 66 | acm->buf_poscxx . . $ ACMStream#buf_pos. = 0; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static int load_bitscxx . . $ load_bits(ed2c4f9031459999).(ACMStreamcxx . . $ ACMStream# *acm) |
| 71 | { |
| 72 | int err; |
| 73 | unsigned data, got; |
| 74 | uint8_tcxx . . $ uint8_t# *p = acm->bufcxx . . $ ACMStream#buf. + acm->buf_poscxx . . $ ACMStream#buf_pos.; |
| 75 | switch (acm->buf_sizecxx . . $ ACMStream#buf_size. - acm->buf_poscxx . . $ ACMStream#buf_pos.) { |
| 76 | default: |
| 77 | data = 0; |
| 78 | got = 0; |
| 79 | break; |
| 80 | case 1: |
| 81 | data = p[0]; |
| 82 | got = 8; |
| 83 | break; |
| 84 | case 2: |
| 85 | data = p[0] + (p[1] << 8); |
| 86 | got = 16; |
| 87 | break; |
| 88 | case 3: |
| 89 | data = p[0] + (p[1] << 8) + (p[2] << 16); |
| 90 | got = 24; |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | if ((err = load_bufcxx . . $ load_buf(ed2c4f9031459999).(acm)) < 0) |
| 95 | return err; |
| 96 | |
| 97 | while (got < 32) { |
| 98 | if (acm->buf_sizecxx . . $ ACMStream#buf_size. - acm->buf_poscxx . . $ ACMStream#buf_pos. == 0) |
| 99 | break; |
| 100 | data |= acm->bufcxx . . $ ACMStream#buf.[acm->buf_poscxx . . $ ACMStream#buf_pos.] << got; |
| 101 | got += 8; |
| 102 | acm->buf_poscxx . . $ ACMStream#buf_pos.++; |
| 103 | } |
| 104 | acm->bit_datacxx . . $ ACMStream#bit_data. = data; |
| 105 | acm->bit_availcxx . . $ ACMStream#bit_avail. = got; |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int get_bits_reloadcxx . . $ get_bits_reload(7be6002641480a7d).(ACMStreamcxx . . $ ACMStream# *acm, unsigned bits) |
| 110 | { |
| 111 | int got, err; |
| 112 | unsigned data, b_data, b_avail; |
| 113 | |
| 114 | data = acm->bit_datacxx . . $ ACMStream#bit_data.; |
| 115 | got = acm->bit_availcxx . . $ ACMStream#bit_avail.; |
| 116 | bits -= got; |
| 117 | |
| 118 | if (acm->buf_sizecxx . . $ ACMStream#buf_size. - acm->buf_poscxx . . $ ACMStream#buf_pos. >= 4) { |
| 119 | uint8_tcxx . . $ uint8_t# *p = acm->bufcxx . . $ ACMStream#buf. + acm->buf_poscxx . . $ ACMStream#buf_pos.; |
| 120 | acm->buf_poscxx . . $ ACMStream#buf_pos. += 4; |
| 121 | b_data = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24); |
| 122 | b_avail = 32; |
| 123 | } else { |
| 124 | if ((err = load_bitscxx . . $ load_bits(ed2c4f9031459999).(acm)) < 0) |
| 125 | return err; |
| 126 | if (acm->bit_availcxx . . $ ACMStream#bit_avail. < bits) |
| 127 | return ACM_ERR_UNEXPECTED_EOFcxx . . $ `third_party/libacm/libacm.h:38:9`!; |
| 128 | b_data = acm->bit_datacxx . . $ ACMStream#bit_data.; |
| 129 | b_avail = acm->bit_availcxx . . $ ACMStream#bit_avail.; |
| 130 | } |
| 131 | |
| 132 | data |= (b_data & ((1 << bits) - 1)) << got; |
| 133 | acm->bit_datacxx . . $ ACMStream#bit_data. = b_data >> bits; |
| 134 | acm->bit_availcxx . . $ ACMStream#bit_avail. = b_avail - bits; |
| 135 | return data; |
| 136 | } |
| 137 | |
| 138 | #define GET_BITS_NOERRcxx . . $ `third_party/libacm/decode.c:138:9`!(tmpval, acm, bits) do { \ |
| 139 | if (acm->bit_avail >= bits) { \ |
| 140 | tmpval = acm->bit_data & ((1 << bits) - 1); \ |
| 141 | acm->bit_data >>= bits; \ |
| 142 | acm->bit_avail -= bits; \ |
| 143 | } else \ |
| 144 | tmpval = get_bits_reload(acm, bits); \ |
| 145 | } while (0) |
| 146 | |
| 147 | #define GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(res, acm, bits) do { \ |
| 148 | int tmpval; \ |
| 149 | GET_BITS_NOERRcxx . . $ `third_party/libacm/decode.c:138:9`!(tmpval, acm, bits); \ |
| 150 | if (tmpval < 0) \ |
| 151 | return tmpval; \ |
| 152 | res = tmpval; \ |
| 153 | } while (0) |
| 154 | |
| 155 | #define GET_BITS_EXPECT_EOFcxx . . $ `third_party/libacm/decode.c:155:9`!(res, acm, bits) do { \ |
| 156 | int tmpval; \ |
| 157 | GET_BITS_NOERRcxx . . $ `third_party/libacm/decode.c:138:9`!(tmpval, acm, bits); \ |
| 158 | if (tmpval < 0) { \ |
| 159 | if (tmpval == ACM_ERR_UNEXPECTED_EOFcxx . . $ `third_party/libacm/libacm.h:38:9`!) \ |
| 160 | return ACM_EXPECTED_EOFcxx . . $ `third_party/libacm/decode.c:32:9`!; \ |
| 161 | return tmpval; \ |
| 162 | } \ |
| 163 | res = tmpval; \ |
| 164 | } while (0) |
| 165 | |
| 166 | /************************************************* |
| 167 | * Table filling |
| 168 | *************************************************/ |
| 169 | static const int map_1bitcxx . . $ map_1bit.[] = { -1, +1 }; |
| 170 | static const int map_2bit_nearcxx . . $ map_2bit_near.[] = { -2, -1, +1, +2 }; |
| 171 | static const int map_2bit_farcxx . . $ map_2bit_far.[] = { -3, -2, +2, +3 }; |
| 172 | static const int map_3bitcxx . . $ map_3bit.[] = { -4, -3, -2, -1, +1, +2, +3, +4 }; |
| 173 | |
| 174 | /* IOW: (r * acm->subblock_len) + c */ |
| 175 | #define set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, r, c, idx) do { \ |
| 176 | unsigned _pos = ((r) << acm->info.acm_level) + (c); \ |
| 177 | acm->block[_pos] = acm->midbuf[idx]; \ |
| 178 | } while (0) |
| 179 | |
| 180 | /************ Fillers **********/ |
| 181 | |
| 182 | static int f_zerocxx . . $ f_zero(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 183 | { |
| 184 | unsigned i; |
| 185 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) |
| 186 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 187 | |
| 188 | return 1; |
| 189 | } |
| 190 | |
| 191 | static int f_badcxx . . $ f_bad(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 192 | { |
| 193 | /* corrupt block? */ |
| 194 | return ACM_ERR_CORRUPTcxx . . $ `third_party/libacm/libacm.h:37:9`!; |
| 195 | } |
| 196 | |
| 197 | static int f_linearcxx . . $ f_linear(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 198 | { |
| 199 | uint32_tcxx . . $ uint32_t# i; |
| 200 | int b, middle = 1 << (ind - 1); |
| 201 | |
| 202 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 203 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, ind); |
| 204 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, b - middle); |
| 205 | } |
| 206 | return 1; |
| 207 | } |
| 208 | |
| 209 | static int f_k13cxx . . $ f_k13(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 210 | { |
| 211 | unsigned i, b; |
| 212 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 213 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 214 | if (b == 0) { |
| 215 | /* 0 */ |
| 216 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i++, col, 0); |
| 217 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 218 | break; |
| 219 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 220 | continue; |
| 221 | } |
| 222 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 223 | if (b == 0) { |
| 224 | /* 1, 0 */ |
| 225 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 226 | continue; |
| 227 | } |
| 228 | /* 1, 1, ? */ |
| 229 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 230 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_1bit[b]); |
| 231 | } |
| 232 | return 1; |
| 233 | } |
| 234 | |
| 235 | static int f_k12cxx . . $ f_k12(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 236 | { |
| 237 | unsigned i, b; |
| 238 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 239 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 240 | if (b == 0) { |
| 241 | /* 0 */ |
| 242 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 243 | continue; |
| 244 | } |
| 245 | |
| 246 | /* 1, ? */ |
| 247 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 248 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_1bit[b]); |
| 249 | } |
| 250 | return 1; |
| 251 | } |
| 252 | |
| 253 | static int f_k24cxx . . $ f_k24(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 254 | { |
| 255 | unsigned i, b; |
| 256 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 257 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 258 | if (b == 0) { |
| 259 | /* 0 */ |
| 260 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i++, col, 0); |
| 261 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) break; |
| 262 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 263 | continue; |
| 264 | } |
| 265 | |
| 266 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 267 | if (b == 0) { |
| 268 | /* 1, 0 */ |
| 269 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 270 | continue; |
| 271 | } |
| 272 | |
| 273 | /* 1, 1, ?, ? */ |
| 274 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 2); |
| 275 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_2bit_near[b]); |
| 276 | } |
| 277 | return 1; |
| 278 | } |
| 279 | |
| 280 | static int f_k23cxx . . $ f_k23(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 281 | { |
| 282 | unsigned i, b; |
| 283 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 284 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 285 | if (b == 0) { |
| 286 | /* 0 */ |
| 287 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 288 | continue; |
| 289 | } |
| 290 | |
| 291 | /* 1, ?, ? */ |
| 292 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 2); |
| 293 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_2bit_near[b]); |
| 294 | } |
| 295 | return 1; |
| 296 | } |
| 297 | |
| 298 | static int f_k35cxx . . $ f_k35(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 299 | { |
| 300 | unsigned i, b; |
| 301 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 302 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 303 | if (b == 0) { |
| 304 | /* 0 */ |
| 305 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i++, col, 0); |
| 306 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 307 | break; |
| 308 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 309 | continue; |
| 310 | } |
| 311 | |
| 312 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 313 | if (b == 0) { |
| 314 | /* 1, 0 */ |
| 315 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 316 | continue; |
| 317 | } |
| 318 | |
| 319 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 320 | if (b == 0) { |
| 321 | /* 1, 1, 0, ? */ |
| 322 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 323 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_1bit[b]); |
| 324 | continue; |
| 325 | } |
| 326 | |
| 327 | /* 1, 1, 1, ?, ? */ |
| 328 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 2); |
| 329 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_2bit_far[b]); |
| 330 | } |
| 331 | return 1; |
| 332 | } |
| 333 | |
| 334 | static int f_k34cxx . . $ f_k34(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 335 | { |
| 336 | unsigned i, b; |
| 337 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 338 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 339 | if (b == 0) { |
| 340 | /* 0 */ |
| 341 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 342 | continue; |
| 343 | } |
| 344 | |
| 345 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 346 | if (b == 0) { |
| 347 | /* 1, 0, ? */ |
| 348 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 349 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_1bit[b]); |
| 350 | continue; |
| 351 | } |
| 352 | |
| 353 | /* 1, 1, ?, ? */ |
| 354 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 2); |
| 355 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_2bit_far[b]); |
| 356 | } |
| 357 | return 1; |
| 358 | } |
| 359 | |
| 360 | static int f_k45cxx . . $ f_k45(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 361 | { |
| 362 | unsigned i, b; |
| 363 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 364 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 365 | if (b == 0) { |
| 366 | /* 0 */ |
| 367 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); i++; |
| 368 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 369 | break; |
| 370 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 371 | continue; |
| 372 | } |
| 373 | |
| 374 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 375 | if (b == 0) { |
| 376 | /* 1, 0 */ |
| 377 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 378 | continue; |
| 379 | } |
| 380 | |
| 381 | /* 1, 1, ?, ?, ? */ |
| 382 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 3); |
| 383 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_3bit[b]); |
| 384 | } |
| 385 | return 1; |
| 386 | } |
| 387 | |
| 388 | static int f_k44cxx . . $ f_k44(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 389 | { |
| 390 | unsigned i, b; |
| 391 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 392 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 1); |
| 393 | if (b == 0) { |
| 394 | /* 0 */ |
| 395 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, 0); |
| 396 | continue; |
| 397 | } |
| 398 | |
| 399 | /* 1, ?, ?, ? */ |
| 400 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 3); |
| 401 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, map_3bit[b]); |
| 402 | } |
| 403 | return 1; |
| 404 | } |
| 405 | |
| 406 | static int f_t15cxx . . $ f_t15(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 407 | { |
| 408 | unsigned i, b; |
| 409 | int n1, n2, n3, tmp; |
| 410 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 411 | /* b = (x1) + (x2 * 3) + (x3 * 9) */ |
| 412 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 5); |
| 413 | if (b >= 3 * 3 * 3) |
| 414 | return ACM_ERR_CORRUPTcxx . . $ `third_party/libacm/libacm.h:37:9`!; |
| 415 | |
| 416 | n1 = b % 3 - 1; |
| 417 | tmp = b / 3; |
| 418 | n2 = tmp % 3 - 1; |
| 419 | n3 = tmp / 3 - 1; |
| 420 | |
| 421 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i++, col, n1); |
| 422 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 423 | break; |
| 424 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i++, col, n2); |
| 425 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 426 | break; |
| 427 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, n3); |
| 428 | } |
| 429 | return 1; |
| 430 | } |
| 431 | |
| 432 | static int f_t27cxx . . $ f_t27(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 433 | { |
| 434 | unsigned i, b; |
| 435 | int n1, n2, n3, tmp; |
| 436 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 437 | /* b = (x1) + (x2 * 5) + (x3 * 25) */ |
| 438 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 7); |
| 439 | if (b >= 5 * 5 * 5) |
| 440 | return ACM_ERR_CORRUPTcxx . . $ `third_party/libacm/libacm.h:37:9`!; |
| 441 | |
| 442 | n1 = b % 5 - 2; |
| 443 | tmp = b / 5; |
| 444 | n2 = tmp % 5 - 2; |
| 445 | n3 = tmp / 5 - 2; |
| 446 | |
| 447 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i++, col, n1); |
| 448 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 449 | break; |
| 450 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i++, col, n2); |
| 451 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 452 | break; |
| 453 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, n3); |
| 454 | } |
| 455 | return 1; |
| 456 | } |
| 457 | |
| 458 | static int f_t37cxx . . $ f_t37(8873a5f53f0ef6fd).(ACMStreamcxx . . $ ACMStream# *acm, unsigned ind, unsigned col) |
| 459 | { |
| 460 | unsigned i, b; |
| 461 | int n1, n2; |
| 462 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; i++) { |
| 463 | /* b = (x1) + (x2 * 11) */ |
| 464 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(b, acm, 7); |
| 465 | if (b >= 11 * 11) |
| 466 | return ACM_ERR_CORRUPTcxx . . $ `third_party/libacm/libacm.h:37:9`!; |
| 467 | |
| 468 | n1 = b % 11 - 5; |
| 469 | n2 = b / 11 - 5; |
| 470 | |
| 471 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i++, col, n1); |
| 472 | if (i >= acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 473 | break; |
| 474 | set_poscxx . . $ `third_party/libacm/decode.c:175:9`!(acm, i, col, n2); |
| 475 | } |
| 476 | return 1; |
| 477 | } |
| 478 | |
| 479 | /****************/ |
| 480 | |
| 481 | static const filler_tcxx . . $ filler_t# filler_listcxx . . $ filler_list.[] = { |
| 482 | f_zerocxx . . $ f_zero(8873a5f53f0ef6fd)., f_badcxx . . $ f_bad(8873a5f53f0ef6fd)., f_badcxx . . $ f_bad(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., /* 0..3 */ |
| 483 | f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., /* 4..7 */ |
| 484 | f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., /* 8..11 */ |
| 485 | f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., /* 12..15 */ |
| 486 | f_linearcxx . . $ f_linear(8873a5f53f0ef6fd)., f_k13cxx . . $ f_k13(8873a5f53f0ef6fd)., f_k12cxx . . $ f_k12(8873a5f53f0ef6fd)., f_t15cxx . . $ f_t15(8873a5f53f0ef6fd)., /* 16..19 */ |
| 487 | f_k24cxx . . $ f_k24(8873a5f53f0ef6fd)., f_k23cxx . . $ f_k23(8873a5f53f0ef6fd)., f_t27cxx . . $ f_t27(8873a5f53f0ef6fd)., f_k35cxx . . $ f_k35(8873a5f53f0ef6fd)., /* 20..23 */ |
| 488 | f_k34cxx . . $ f_k34(8873a5f53f0ef6fd)., f_badcxx . . $ f_bad(8873a5f53f0ef6fd)., f_k45cxx . . $ f_k45(8873a5f53f0ef6fd)., f_k44cxx . . $ f_k44(8873a5f53f0ef6fd)., /* 24..27 */ |
| 489 | f_badcxx . . $ f_bad(8873a5f53f0ef6fd)., f_t37cxx . . $ f_t37(8873a5f53f0ef6fd)., f_badcxx . . $ f_bad(8873a5f53f0ef6fd)., f_badcxx . . $ f_bad(8873a5f53f0ef6fd). /* 28..31 */ |
| 490 | }; |
| 491 | |
| 492 | static int fill_blockcxx . . $ fill_block(ed2c4f9031459999).(ACMStreamcxx . . $ ACMStream# *acm) |
| 493 | { |
| 494 | unsigned i, ind; |
| 495 | int err; |
| 496 | for (i = 0; i < acm->infocxx . . $ ACMStream#info..acm_colscxx . . $ ACMInfo#acm_cols.; i++) { |
| 497 | GET_BITS_EXPECT_EOFcxx . . $ `third_party/libacm/decode.c:155:9`!(ind, acm, 5); |
| 498 | err = filler_listcxx . . $ filler_list.[ind](acm, ind, i); |
| 499 | if (err < 0) |
| 500 | return err; |
| 501 | } |
| 502 | return 1; |
| 503 | } |
| 504 | |
| 505 | /********************************************** |
| 506 | * Decompress code |
| 507 | **********************************************/ |
| 508 | |
| 509 | static void jugglecxx . . $ juggle(9b55cb156eacdfd4).(int *wrap_p, int *block_p, unsigned sub_len, unsigned sub_count) |
| 510 | { |
| 511 | uint32_tcxx . . $ uint32_t# i, j; |
| 512 | int *p; |
| 513 | uint32_tcxx . . $ uint32_t# r0, r1, r2, r3; |
| 514 | for (i = 0; i < sub_len; i++) { |
| 515 | p = block_p; |
| 516 | r0 = wrap_p[0]; |
| 517 | r1 = wrap_p[1]; |
| 518 | for (j = 0; j < sub_count/2; j++) { |
| 519 | r2 = *p; *p = r1*2 + (r0 + r2); p += sub_len; |
| 520 | r3 = *p; *p = r2*2 - (r1 + r3); p += sub_len; |
| 521 | r0 = r2; r1 = r3; |
| 522 | } |
| 523 | *wrap_p++ = r0; |
| 524 | *wrap_p++ = r1; |
| 525 | block_p++; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | static void juggle_blockcxx . . $ juggle_block(54ee7bf75f7d9c31).(ACMStreamcxx . . $ ACMStream# *acm) |
| 530 | { |
| 531 | unsigned sub_count, sub_len, todo_count, step_subcount, i; |
| 532 | int *wrap_p, *block_p, *p; |
| 533 | |
| 534 | /* juggle only if subblock_len > 1 */ |
| 535 | if (acm->infocxx . . $ ACMStream#info..acm_levelcxx . . $ ACMInfo#acm_level. == 0) |
| 536 | return; |
| 537 | |
| 538 | /* 2048 / subblock_len */ |
| 539 | if (acm->infocxx . . $ ACMStream#info..acm_levelcxx . . $ ACMInfo#acm_level. > 9) |
| 540 | step_subcount = 1; |
| 541 | else |
| 542 | step_subcount = (2048 >> acm->infocxx . . $ ACMStream#info..acm_levelcxx . . $ ACMInfo#acm_level.) - 2; |
| 543 | |
| 544 | /* Apply juggle() (rows)x(cols) |
| 545 | * from (step_subcount * 2) x (subblock_len/2) |
| 546 | * to (step_subcount * subblock_len) x (1) |
| 547 | */ |
| 548 | todo_count = acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.; |
| 549 | block_p = acm->blockcxx . . $ ACMStream#block.; |
| 550 | while (1) { |
| 551 | wrap_p = acm->wrapbufcxx . . $ ACMStream#wrapbuf.; |
| 552 | sub_count = step_subcount; |
| 553 | if (sub_count > todo_count) |
| 554 | sub_count = todo_count; |
| 555 | |
| 556 | sub_len = acm->infocxx . . $ ACMStream#info..acm_colscxx . . $ ACMInfo#acm_cols. / 2; |
| 557 | sub_count *= 2; |
| 558 | |
| 559 | jugglecxx . . $ juggle(9b55cb156eacdfd4).(wrap_p, block_p, sub_len, sub_count); |
| 560 | wrap_p += sub_len*2; |
| 561 | |
| 562 | for (i = 0, p = block_p; i < sub_count; i++) { |
| 563 | p[0]++; |
| 564 | p += sub_len; |
| 565 | } |
| 566 | |
| 567 | while (sub_len > 1) { |
| 568 | sub_len /= 2; |
| 569 | sub_count *= 2; |
| 570 | jugglecxx . . $ juggle(9b55cb156eacdfd4).(wrap_p, block_p, sub_len, sub_count); |
| 571 | wrap_p += sub_len*2; |
| 572 | } |
| 573 | if (todo_count <= step_subcount) |
| 574 | break; |
| 575 | todo_count -= step_subcount; |
| 576 | block_p += step_subcount << acm->infocxx . . $ ACMStream#info..acm_levelcxx . . $ ACMInfo#acm_level.; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | /***************************************************************/ |
| 581 | static int decode_blockcxx . . $ decode_block(ed2c4f9031459999).(ACMStreamcxx . . $ ACMStream# *acm) |
| 582 | { |
| 583 | int pwr, count, val, i, x, err; |
| 584 | |
| 585 | acm->block_readycxx . . $ ACMStream#block_ready. = 0; |
| 586 | acm->block_poscxx . . $ ACMStream#block_pos. = 0; |
| 587 | |
| 588 | /* read header */ |
| 589 | GET_BITS_EXPECT_EOFcxx . . $ `third_party/libacm/decode.c:155:9`!(pwr, acm, 4); |
| 590 | GET_BITS_EXPECT_EOFcxx . . $ `third_party/libacm/decode.c:155:9`!(val, acm, 16); |
| 591 | |
| 592 | /* generate tables */ |
| 593 | count = 1 << pwr; |
| 594 | for (i = 0, x = 0; i < count; i++) { |
| 595 | acm->midbufcxx . . $ ACMStream#midbuf.[i] = x; |
| 596 | x += val; |
| 597 | } |
| 598 | for (i = 1, x = -val; i <= count; i++) { |
| 599 | acm->midbufcxx . . $ ACMStream#midbuf.[-i] = (unsigned)x; |
| 600 | x -= val; |
| 601 | } |
| 602 | |
| 603 | /* to_check? */ |
| 604 | if ((err = fill_blockcxx . . $ fill_block(ed2c4f9031459999).(acm)) <= 0) |
| 605 | return err; |
| 606 | |
| 607 | juggle_blockcxx . . $ juggle_block(54ee7bf75f7d9c31).(acm); |
| 608 | |
| 609 | acm->block_readycxx . . $ ACMStream#block_ready. = 1; |
| 610 | |
| 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | /****************************** |
| 615 | * Output formats |
| 616 | ******************************/ |
| 617 | |
| 618 | static uint8_tcxx . . $ uint8_t# *out_s16lecxx . . $ out_s16le(247a3b6e8e06651a).(int *src, uint8_tcxx . . $ uint8_t# *dst, unsigned n, unsigned shift) |
| 619 | { |
| 620 | while (n--) { |
| 621 | int val = *src++ >> shift; |
| 622 | *dst++ = val & 0xFF; |
| 623 | *dst++ = (val >> 8) & 0xFF; |
| 624 | } |
| 625 | return dst; |
| 626 | } |
| 627 | |
| 628 | static uint8_tcxx . . $ uint8_t# *out_s16becxx . . $ out_s16be(247a3b6e8e06651a).(int *src, uint8_tcxx . . $ uint8_t# *dst, unsigned n, unsigned shift) |
| 629 | { |
| 630 | while (n--) { |
| 631 | int val = *src++ >> shift; |
| 632 | *dst++ = (val >> 8) & 0xFF; |
| 633 | *dst++ = val & 0xFF; |
| 634 | } |
| 635 | return dst; |
| 636 | } |
| 637 | |
| 638 | static uint8_tcxx . . $ uint8_t# *out_u16lecxx . . $ out_u16le(247a3b6e8e06651a).(int *src, uint8_tcxx . . $ uint8_t# *dst, unsigned n, unsigned shift) |
| 639 | { |
| 640 | while (n--) { |
| 641 | int val = (*src++ >> shift) + 0x8000; |
| 642 | *dst++ = val & 0xFF; |
| 643 | *dst++ = (val >> 8) & 0xFF; |
| 644 | } |
| 645 | return dst; |
| 646 | } |
| 647 | |
| 648 | static uint8_tcxx . . $ uint8_t# *out_u16becxx . . $ out_u16be(247a3b6e8e06651a).(int *src, uint8_tcxx . . $ uint8_t# *dst, unsigned n, unsigned shift) |
| 649 | { |
| 650 | while (n--) { |
| 651 | int val = (*src++ >> shift) + 0x8000; |
| 652 | *dst++ = (val >> 8) & 0xFF; |
| 653 | *dst++ = val & 0xFF; |
| 654 | } |
| 655 | return dst; |
| 656 | } |
| 657 | |
| 658 | static int output_valuescxx . . $ output_values(45be0bde0584cd8d).(int *src, uint8_tcxx . . $ uint8_t# *dst, int n, |
| 659 | int acm_level, int bigendianp, int wordlen, int sgned) |
| 660 | { |
| 661 | uint8_tcxx . . $ uint8_t# *res = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 662 | if (wordlen == 2) { |
| 663 | if (bigendianp == 0) { |
| 664 | if (sgned) |
| 665 | res = out_s16lecxx . . $ out_s16le(247a3b6e8e06651a).(src, dst, n, acm_level); |
| 666 | else |
| 667 | res = out_u16lecxx . . $ out_u16le(247a3b6e8e06651a).(src, dst, n, acm_level); |
| 668 | } else { |
| 669 | if (sgned) |
| 670 | res = out_s16becxx . . $ out_s16be(247a3b6e8e06651a).(src, dst, n, acm_level); |
| 671 | else |
| 672 | res = out_u16becxx . . $ out_u16be(247a3b6e8e06651a).(src, dst, n, acm_level); |
| 673 | } |
| 674 | } |
| 675 | if (res != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 676 | return res - dst; |
| 677 | return ACM_ERR_BADFMTcxx . . $ `third_party/libacm/libacm.h:36:9`!; |
| 678 | } |
| 679 | |
| 680 | /* |
| 681 | * WAVC (compressed WAV) files are ACM files with additional header. |
| 682 | * |
| 683 | * 'WAVC' + 'V1.00' + uncompr(4b) + compr(4b) + 12b |
| 684 | */ |
| 685 | |
| 686 | #define WAVC_IDcxx . . $ `third_party/libacm/decode.c:686:9`! 0x564157 /* 'WAV' */ |
| 687 | |
| 688 | static int read_wavc_headercxx . . $ read_wavc_header(ed2c4f9031459999).(ACMStreamcxx . . $ ACMStream# *acm) |
| 689 | { |
| 690 | static const uint16_tcxx . . $ uint16_t# expect[12] = { |
| 691 | /* 'V1.0', raw_size, acm_size */ |
| 692 | 0x3156, 0x302E, 0,0, 0,0, |
| 693 | /* hdrlen?, chans?, bits?, hz */ |
| 694 | 28,0, 1, 16, 22050, 0 |
| 695 | }; |
| 696 | uint16_tcxx . . $ uint16_t# i, buf[12]; |
| 697 | |
| 698 | for (i = 0; i < 12; i++) |
| 699 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(buf[i], acm, 16); |
| 700 | if (memcmpcxx . . $ memcmp(36f949851efa3055).(buf, expect, 4) != 0) |
| 701 | return -1; |
| 702 | /* full comparision is too strict */ |
| 703 | if (0 && memcmpcxx . . $ memcmp(36f949851efa3055).(buf + 6, expect + 6, 12) != 0) |
| 704 | return -1; |
| 705 | /* just make sure the magic 28 is there */ |
| 706 | if (expect[6] != buf[6]) |
| 707 | return -1; |
| 708 | |
| 709 | acm->wavc_filecxx . . $ ACMStream#wavc_file. = 1; |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static int read_headercxx . . $ read_header(ed2c4f9031459999).(ACMStreamcxx . . $ ACMStream# *acm) |
| 714 | { |
| 715 | uint32_tcxx . . $ uint32_t# tmp; |
| 716 | |
| 717 | /* read header */ |
| 718 | |
| 719 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(tmp, acm, 24); |
| 720 | if (tmp == WAVC_IDcxx . . $ `third_party/libacm/decode.c:686:9`!) { |
| 721 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(tmp, acm, 8); |
| 722 | if (tmp != 'C') |
| 723 | return ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 724 | if (read_wavc_headercxx . . $ read_wavc_header(ed2c4f9031459999).(acm) < 0) |
| 725 | return ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 726 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(tmp, acm, 24); |
| 727 | } |
| 728 | if (tmp != ACM_IDcxx . . $ `third_party/libacm/libacm.h:28:9`!) |
| 729 | return ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 730 | acm->infocxx . . $ ACMStream#info..acm_idcxx . . $ ACMInfo#acm_id. = tmp; |
| 731 | |
| 732 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(acm->info.acm_version, acm, 8); |
| 733 | if (acm->infocxx . . $ ACMStream#info..acm_versioncxx . . $ ACMInfo#acm_version. != 1) |
| 734 | return ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 735 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(acm->total_values, acm, 16); |
| 736 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(tmp, acm, 16); |
| 737 | acm->total_valuescxx . . $ ACMStream#total_values. += tmp << 16; |
| 738 | if (acm->total_valuescxx . . $ ACMStream#total_values. == 0) |
| 739 | return ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 740 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(acm->info.channels, acm, 16); |
| 741 | if (acm->infocxx . . $ ACMStream#info..channelscxx . . $ ACMInfo#channels. < 1 || acm->infocxx . . $ ACMStream#info..channelscxx . . $ ACMInfo#channels. > 2) |
| 742 | return ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 743 | acm->infocxx . . $ ACMStream#info..acm_channelscxx . . $ ACMInfo#acm_channels. = acm->infocxx . . $ ACMStream#info..channelscxx . . $ ACMInfo#channels.; |
| 744 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(acm->info.rate, acm, 16); |
| 745 | if (acm->infocxx . . $ ACMStream#info..ratecxx . . $ ACMInfo#rate. < 4096) |
| 746 | return ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 747 | |
| 748 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(acm->info.acm_level, acm, 4); |
| 749 | GET_BITScxx . . $ `third_party/libacm/decode.c:147:9`!(acm->info.acm_rows, acm, 12); |
| 750 | if (!acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows.) |
| 751 | return ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | /*********************************************** |
| 756 | * Public functions |
| 757 | ***********************************************/ |
| 758 | |
| 759 | int acm_open_decodercxx . . $ acm_open_decoder(eab838f56467f41e).(ACMStreamcxx . . $ ACMStream# **res, void *arg, struct acm_io_callbackscxx . . $ acm_io_callbacks# io_cb, int force_chans) |
| 760 | { |
| 761 | int err = ACM_ERR_OTHERcxx . . $ `third_party/libacm/libacm.h:32:9`!; |
| 762 | ACMStreamcxx . . $ ACMStream# *acm; |
| 763 | |
| 764 | acm = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*acm)); |
| 765 | if (!acm) |
| 766 | return err; |
| 767 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(acm, 0, sizeof(*acm)); |
| 768 | |
| 769 | acm->io_argcxx . . $ ACMStream#io_arg. = arg; |
| 770 | acm->iocxx . . $ ACMStream#io. = io_cb; |
| 771 | |
| 772 | if (acm->iocxx . . $ ACMStream#io..get_length_funccxx . . $ acm_io_callbacks#get_length_func.) { |
| 773 | acm->data_lencxx . . $ ACMStream#data_len. = acm->iocxx . . $ ACMStream#io..get_length_funccxx . . $ acm_io_callbacks#get_length_func.(acm->io_argcxx . . $ ACMStream#io_arg.); |
| 774 | } else { |
| 775 | acm->data_lencxx . . $ ACMStream#data_len. = 0; |
| 776 | } |
| 777 | |
| 778 | acm->buf_maxcxx . . $ ACMStream#buf_max. = ACM_BUFLENcxx . . $ `third_party/libacm/decode.c:30:9`!; |
| 779 | acm->bufcxx . . $ ACMStream#buf. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(acm->buf_maxcxx . . $ ACMStream#buf_max.); |
| 780 | if (!acm->bufcxx . . $ ACMStream#buf.) |
| 781 | goto err_out; |
| 782 | |
| 783 | /* read header data */ |
| 784 | err = ACM_ERR_NOT_ACMcxx . . $ `third_party/libacm/libacm.h:34:9`!; |
| 785 | if (read_headercxx . . $ read_header(ed2c4f9031459999).(acm) < 0) |
| 786 | goto err_out; |
| 787 | |
| 788 | /* |
| 789 | * Overwrite channel info if requested, if force_chans == 0 |
| 790 | * use channel count from the header. |
| 791 | * For force_chans == -1, assume that "plain" ACM files are always stereo |
| 792 | * (there are many plain ACM files in the wild that are really stereo |
| 793 | * even though the header specifies 1 channel), but still trust the |
| 794 | * header of WAVC ACM files, as those seem to be correct. |
| 795 | */ |
| 796 | if (force_chans > 0) |
| 797 | acm->infocxx . . $ ACMStream#info..channelscxx . . $ ACMInfo#channels. = force_chans; |
| 798 | else if (force_chans == -1 && !acm->wavc_filecxx . . $ ACMStream#wavc_file. && acm->infocxx . . $ ACMStream#info..channelscxx . . $ ACMInfo#channels. < 2) |
| 799 | acm->infocxx . . $ ACMStream#info..channelscxx . . $ ACMInfo#channels. = 2; |
| 800 | /* else if force_chans == 0, trust the file's header */ |
| 801 | |
| 802 | /* calculate blocks */ |
| 803 | acm->infocxx . . $ ACMStream#info..acm_colscxx . . $ ACMInfo#acm_cols. = 1 << acm->infocxx . . $ ACMStream#info..acm_levelcxx . . $ ACMInfo#acm_level.; |
| 804 | acm->wrapbuf_lencxx . . $ ACMStream#wrapbuf_len. = 2 * acm->infocxx . . $ ACMStream#info..acm_colscxx . . $ ACMInfo#acm_cols. - 2; |
| 805 | acm->block_lencxx . . $ ACMStream#block_len. = acm->infocxx . . $ ACMStream#info..acm_rowscxx . . $ ACMInfo#acm_rows. * acm->infocxx . . $ ACMStream#info..acm_colscxx . . $ ACMInfo#acm_cols.; |
| 806 | |
| 807 | /* allocate */ |
| 808 | acm->blockcxx . . $ ACMStream#block. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(acm->block_lencxx . . $ ACMStream#block_len. * sizeof(int)); |
| 809 | acm->wrapbufcxx . . $ ACMStream#wrapbuf. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(acm->wrapbuf_lencxx . . $ ACMStream#wrapbuf_len. * sizeof(int)); |
| 810 | acm->ampbufcxx . . $ ACMStream#ampbuf. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(0x10000 * sizeof(int)); |
| 811 | acm->midbufcxx . . $ ACMStream#midbuf. = acm->ampbufcxx . . $ ACMStream#ampbuf. + 0x8000; |
| 812 | |
| 813 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(acm->wrapbufcxx . . $ ACMStream#wrapbuf., 0, acm->wrapbuf_lencxx . . $ ACMStream#wrapbuf_len. * sizeof(int)); |
| 814 | |
| 815 | *res = acm; |
| 816 | return ACM_OKcxx . . $ `third_party/libacm/libacm.h:31:9`!; |
| 817 | |
| 818 | err_out: |
| 819 | /* disable callbacks */ |
| 820 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&acm->iocxx . . $ ACMStream#io., 0, sizeof(acm->iocxx . . $ ACMStream#io.)); |
| 821 | acm->io_argcxx . . $ ACMStream#io_arg. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 822 | |
| 823 | acm_closecxx . . $ acm_close(54ee7bf75f7d9c31).(acm); |
| 824 | return err; |
| 825 | } |
| 826 | |
| 827 | int acm_readcxx . . $ acm_read(659aa9e0d18d03b8).(ACMStreamcxx . . $ ACMStream# *acm, void *dst, unsigned numbytes, |
| 828 | int bigendianp, int wordlen, int sgned) |
| 829 | { |
| 830 | int avail, gotbytes = 0, err; |
| 831 | int *src, numwords; |
| 832 | |
| 833 | if (wordlen == 2) |
| 834 | numwords = numbytes / 2; |
| 835 | else |
| 836 | return ACM_ERR_BADFMTcxx . . $ `third_party/libacm/libacm.h:36:9`!; |
| 837 | |
| 838 | if (acm->stream_poscxx . . $ ACMStream#stream_pos. >= acm->total_valuescxx . . $ ACMStream#total_values.) |
| 839 | return 0; |
| 840 | |
| 841 | if (!acm->block_readycxx . . $ ACMStream#block_ready.) { |
| 842 | err = decode_blockcxx . . $ decode_block(ed2c4f9031459999).(acm); |
| 843 | if (err == ACM_EXPECTED_EOFcxx . . $ `third_party/libacm/decode.c:32:9`!) |
| 844 | return 0; |
| 845 | if (err < 0) |
| 846 | return err; |
| 847 | } |
| 848 | |
| 849 | /* check how many words can be read */ |
| 850 | avail = acm->block_lencxx . . $ ACMStream#block_len. - acm->block_poscxx . . $ ACMStream#block_pos.; |
| 851 | if (avail < numwords) |
| 852 | numwords = avail; |
| 853 | |
| 854 | if (acm->stream_poscxx . . $ ACMStream#stream_pos. + numwords > acm->total_valuescxx . . $ ACMStream#total_values.) |
| 855 | numwords = acm->total_valuescxx . . $ ACMStream#total_values. - acm->stream_poscxx . . $ ACMStream#stream_pos.; |
| 856 | |
| 857 | if (acm->infocxx . . $ ACMStream#info..channelscxx . . $ ACMInfo#channels. > 1) |
| 858 | numwords -= numwords % acm->infocxx . . $ ACMStream#info..channelscxx . . $ ACMInfo#channels.; |
| 859 | |
| 860 | /* convert, but if dst == NULL, simulate */ |
| 861 | if (dst != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 862 | src = acm->blockcxx . . $ ACMStream#block. + acm->block_poscxx . . $ ACMStream#block_pos.; |
| 863 | gotbytes = output_valuescxx . . $ output_values(45be0bde0584cd8d).(src, dst, numwords, |
| 864 | acm->infocxx . . $ ACMStream#info..acm_levelcxx . . $ ACMInfo#acm_level., |
| 865 | bigendianp, wordlen, sgned); |
| 866 | } else |
| 867 | gotbytes = numwords * wordlen; |
| 868 | |
| 869 | if (gotbytes >= 0) { |
| 870 | acm->stream_poscxx . . $ ACMStream#stream_pos. += numwords; |
| 871 | acm->block_poscxx . . $ ACMStream#block_pos. += numwords; |
| 872 | if (acm->block_poscxx . . $ ACMStream#block_pos. == acm->block_lencxx . . $ ACMStream#block_len.) |
| 873 | acm->block_readycxx . . $ ACMStream#block_ready. = 0; |
| 874 | } |
| 875 | |
| 876 | return gotbytes; |
| 877 | } |
| 878 | |
| 879 | void acm_closecxx . . $ acm_close(54ee7bf75f7d9c31).(ACMStreamcxx . . $ ACMStream# *acm) |
| 880 | { |
| 881 | if (acm == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 882 | return; |
| 883 | if (acm->iocxx . . $ ACMStream#io..close_funccxx . . $ acm_io_callbacks#close_func.) |
| 884 | acm->iocxx . . $ ACMStream#io..close_funccxx . . $ acm_io_callbacks#close_func.(acm->io_argcxx . . $ ACMStream#io_arg.); |
| 885 | if (acm->bufcxx . . $ ACMStream#buf.) |
| 886 | freecxx . . $ free(5d22bdacc48458e8).(acm->bufcxx . . $ ACMStream#buf.); |
| 887 | if (acm->blockcxx . . $ ACMStream#block.) |
| 888 | freecxx . . $ free(5d22bdacc48458e8).(acm->blockcxx . . $ ACMStream#block.); |
| 889 | if (acm->wrapbufcxx . . $ ACMStream#wrapbuf.) |
| 890 | freecxx . . $ free(5d22bdacc48458e8).(acm->wrapbufcxx . . $ ACMStream#wrapbuf.); |
| 891 | if (acm->ampbufcxx . . $ ACMStream#ampbuf.) |
| 892 | freecxx . . $ free(5d22bdacc48458e8).(acm->ampbufcxx . . $ ACMStream#ampbuf.); |
| 893 | freecxx . . $ free(5d22bdacc48458e8).(acm); |
| 894 | } |
| 895 |