52 f->mant =
i? (i<<6) >>
f->exp : 1<<5;
61 res = (((f1->
mant * f2->
mant) + 0x30) >> 4);
62 res =
exp > 19 ? res << (
exp - 19) : res >> (19 -
exp);
63 return (f1->
sign ^ f2->
sign) ? -res : res;
68 return (
value < 0) ? -1 : 1;
105 { 116, 365, 365, 116 };
107 { -22, 439, 439, -22 };
112 { 7, 217, 330, INT_MAX };
114 { INT16_MIN, 135, 273, 373, 373, 273, 135, INT16_MIN };
116 { -4, 30, 137, 582, 582, 137, 30, -4 };
118 { 0, 1, 2, 7, 7, 2, 1, 0 };
121 { -125, 79, 177, 245, 299, 348, 399, INT_MAX };
123 { INT16_MIN, 4, 135, 213, 273, 323, 373, 425,
124 425, 373, 323, 273, 213, 135, 4, INT16_MIN };
126 { -12, 18, 41, 64, 112, 198, 355, 1122,
127 1122, 355, 198, 112, 64, 41, 18, -12};
129 { 0, 0, 0, 1, 1, 1, 3, 7, 7, 3, 1, 1, 1, 0, 0, 0 };
132 { -122, -16, 67, 138, 197, 249, 297, 338,
133 377, 412, 444, 474, 501, 527, 552, INT_MAX };
135 { INT16_MIN, -66, 28, 104, 169, 224, 274, 318,
136 358, 395, 429, 459, 488, 514, 539, 566,
137 566, 539, 514, 488, 459, 429, 395, 358,
138 318, 274, 224, 169, 104, 28, -66, INT16_MIN };
140 { 14, 14, 24, 39, 40, 41, 58, 100,
141 141, 179, 219, 280, 358, 440, 529, 696,
142 696, 529, 440, 358, 280, 219, 179, 141,
143 100, 58, 41, 40, 39, 24, 14, 14 };
145 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6,
146 6, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
160 int sign,
exp,
i, dln;
168 dln = ((
exp<<7) + (((
d<<7)>>
exp)&0x7f)) - (
c->y>>2);
170 while (
c->tbls.quant[
i] < INT_MAX &&
c->tbls.quant[
i] < dln)
175 if (
c->code_size != 2 &&
i == 0)
188 dql =
c->tbls.iquant[
i] + (
c->y >> 2);
189 dex = (dql>>7) & 0
xf;
190 dqt = (1<<7) + (dql & 0x7f);
191 return (dql < 0) ? 0 : ((dqt<<dex) >> 7);
196 int dq, re_signal, pk0, fa1,
i, tr, ylint, ylfrac, thr2, al, dq0;
198 int I_sig= I >> (
c->code_size - 1);
203 ylint = (
c->yl >> 15);
204 ylfrac = (
c->yl >> 10) & 0x1f;
205 thr2 = (ylint > 9) ? 0x1f << 10 : (0x20 + ylfrac) << ylint;
206 tr= (
c->td == 1 && dq > ((3*thr2)>>2));
210 re_signal = (int16_t)(
c->se + dq);
213 pk0 = (
c->sez + dq) ?
sgn(
c->sez + dq) : 0;
214 dq0 = dq ?
sgn(dq) : 0;
224 c->a[1] += 128*pk0*
c->pk[1] + fa1 - (
c->a[1]>>7);
225 c->a[1] =
av_clip(
c->a[1], -12288, 12288);
226 c->a[0] += 64*3*pk0*
c->pk[0] - (
c->a[0] >> 8);
227 c->a[0] =
av_clip(
c->a[0], -(15360 -
c->a[1]), 15360 -
c->a[1]);
230 c->b[
i] += 128*dq0*
sgn(-
c->dq[
i].sign) - (
c->b[
i]>>8);
235 c->pk[0] = pk0 ? pk0 : 1;
237 i2f(re_signal, &
c->sr[0]);
239 c->dq[
i] =
c->dq[
i-1];
241 c->dq[0].sign = I_sig;
243 c->td =
c->a[1] < -11776;
246 c->dms += (
c->tbls.F[I]<<4) + ((-
c->dms) >> 5);
247 c->dml += (
c->tbls.F[I]<<4) + ((-
c->dml) >> 7);
251 c->ap += (-
c->ap) >> 4;
252 if (
c->y <= 1535 ||
c->td ||
abs((
c->dms << 2) -
c->dml) >= (
c->dml >> 3))
257 c->yu =
av_clip(
c->y +
c->tbls.W[I] + ((-
c->y)>>5), 544, 5120);
258 c->yl +=
c->yu + ((-
c->yl)>>6);
261 al = (
c->ap >= 256) ? 1<<6 :
c->ap >> 2;
262 c->y = (
c->yl + (
c->yu - (
c->yl>>6))*al) >> 6;
273 return av_clip(re_signal * 4, -0xffff, 0xffff);
281 for (
i=0;
i<2;
i++) {
282 c->sr[
i].mant = 1<<5;
285 for (
i=0;
i<6;
i++) {
286 c->dq[
i].mant = 1<<5;
296 #if CONFIG_ADPCM_G726_ENCODER || CONFIG_ADPCM_G726LE_ENCODER
312 c->little_endian = !strcmp(avctx->
codec->
name,
"g726le");
317 "allowed when the compliance level is higher than unofficial. "
318 "Resample or reduce the compliance level.\n");
335 c->code_size =
av_clip(
c->code_size, 2, 5);
343 avctx->
frame_size = ((
int[]){ 4096, 2736, 2048, 1640 })[
c->code_size - 2];
352 const int16_t *
samples = (
const int16_t *)
frame->data[0];
361 for (
i = 0;
i <
frame->nb_samples;
i++)
362 if (
c->little_endian) {
368 if (
c->little_endian) {
378 #define OFFSET(x) offsetof(G726Context, x)
379 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
385 static const AVClass g726_class = {
398 #if CONFIG_ADPCM_G726_ENCODER
406 .
init = g726_encode_init,
407 .encode2 = g726_encode_frame,
410 .priv_class = &g726_class,
416 #if CONFIG_ADPCM_G726LE_ENCODER
424 .
init = g726_encode_init,
425 .encode2 = g726_encode_frame,
428 .priv_class = &g726_class,
434 #if CONFIG_ADPCM_G726_DECODER || CONFIG_ADPCM_G726LE_DECODER
446 c->little_endian = !strcmp(avctx->
codec->
name,
"g726le");
449 if (
c->code_size < 2 ||
c->code_size > 5) {
461 int *got_frame_ptr,
AVPacket *avpkt)
464 const uint8_t *buf = avpkt->
data;
465 int buf_size = avpkt->
size;
469 int out_samples,
ret;
471 out_samples = buf_size * 8 /
c->code_size;
474 frame->nb_samples = out_samples;
481 while (out_samples--)
501 #if CONFIG_ADPCM_G726_DECODER
508 .
init = g726_decode_init,
509 .
decode = g726_decode_frame,
510 .
flush = g726_decode_flush,
516 #if CONFIG_ADPCM_G726LE_DECODER
522 .
init = g726_decode_init,
523 .
decode = g726_decode_frame,
524 .
flush = g726_decode_flush,