1 /*
2 * Micronas SC-4 audio decoder
3 * Copyright (c) 2022 Paul B Mahol
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
29
30 static const int16_t
steps[16] = {
31 4084, 18, 41, 64, 112, 198, 355, 1122,
32 1122, 355, 198, 112, 64, 41, 18, 4084,
33 };
34
35 static const int16_t
diffs[16] = {
36 2048, 4, 135, 213, 273, 323, 373, 425,
37 425, 373, 323, 273, 213, 135, 4, 2048,
38 };
39
47
50
52
55
57 {
59
62 case 8000:
63 case 11025:
65 break;
66 case 16000:
67 case 32000:
69 break;
70 }
71
72 return 0;
73 }
74
76 #define WEIGHTSBITS 26
77
79 {
82
84
85 for (
int i = 0;
i < 6;
i++) {
86 const int sign =
FFSIGN(
c->diffs_tab[
i]);
87 c->weights_tab[
i] = (
c->weights_tab[
i] * 255LL) / 256;
88 c->weights_tab[
i] += (1LL << (
WEIGHTSBITS + 1)) * sign * isign;
89 }
90
91 memmove(&
c->diffs_tab[1], &
c->diffs_tab[0], 5 *
sizeof(
int32_t));
92
94 c->pred =
c->new_pred;
95
96 dotpr = 0;
97 for (
int i = 0;
i < 6;
i++)
99
102 c->pred =
c->pred * 9 / 10;
103
105 }
106
108 {
110 uint32_t
step, newstep;
112
113 diff_sign = nibble >> 3;
116 newstep =
step & 0xfff;
117 if (newstep >> 11 == 0)
118 adiff = (((
step & 0x7f) + 0x80) * 128) >>
119 (14 - (newstep >> 7));
120 delta = diff_sign ? -adiff : adiff;
123 nibble =
steps[nibble];
124 newstep = nibble * 32 -
c->last_step & 0x1ffff;
125 newstep = ((newstep >> 5) + (newstep & 0x10000 ? 0x1000 : 0) +
c->last_step) & 0x1fff;
126 c->last_step =
av_clip(newstep, 544, 5120);
127
129 }
130
133 {
136 uint32_t hdr;
138
140
144
145 hdr = bytestream2_peek_be32(gb);
146 if (hdr ==
s->marker) {
148 }
else if ((hdr >> 16) ==
s->marker) {
150 }
151
152 {
155 int n;
156
157 for (n = 0; n < 29; n++) {
158 int nibble = bytestream2_get_byte(gb);
162 break;
163 }
164
165 if (n == 29 && bytestream2_get_byte(gb) != 0x55)
167 }
168
169 *got_frame_ptr = 1;
170
172 }
173
183 #if FF_API_SUBFRAMES
184 AV_CODEC_CAP_SUBFRAMES |
185 #endif
189 };