comparison g726.c @ 1792:7da4bdafe42e libavcodec

use clip() from common.h ignore sample_rate==8000 limit if strict_std_compliance < 0
author michael
date Sat, 07 Feb 2004 15:33:00 +0000
parents 5e5c3d4a1e82
children fac680cf3008
comparison
equal deleted inserted replaced
1791:5e5c3d4a1e82 1792:7da4bdafe42e
51 51
52 exp = f1->exp + f2->exp; 52 exp = f1->exp + f2->exp;
53 res = (((f1->mant * f2->mant) + 0x30) >> 4) << 7; 53 res = (((f1->mant * f2->mant) + 0x30) >> 4) << 7;
54 res = exp > 26 ? res << (exp - 26) : res >> (26 - exp); 54 res = exp > 26 ? res << (exp - 26) : res >> (26 - exp);
55 return (f1->sign ^ f2->sign) ? -res : res; 55 return (f1->sign ^ f2->sign) ? -res : res;
56 }
57
58 static inline int clamp(int value, int min, int max)
59 {
60 if (value < min)
61 return min;
62 else if (value > max)
63 return max;
64 else
65 return value;
66 } 56 }
67 57
68 static inline int sgn(int value) 58 static inline int sgn(int value)
69 { 59 {
70 return (value < 0) ? -1 : 1; 60 return (value < 0) ? -1 : 1;
218 c->a[1] = 0; 208 c->a[1] = 0;
219 for (i=0; i<6; i++) 209 for (i=0; i<6; i++)
220 c->b[i] = 0; 210 c->b[i] = 0;
221 } else { 211 } else {
222 /* This is a bit crazy, but it really is +255 not +256 */ 212 /* This is a bit crazy, but it really is +255 not +256 */
223 fa1 = clamp((-c->a[0]*c->pk[0]*pk0)>>5, -256, 255); 213 fa1 = clip((-c->a[0]*c->pk[0]*pk0)>>5, -256, 255);
224 214
225 c->a[1] += 128*pk0*c->pk[1] + fa1 - (c->a[1]>>7); 215 c->a[1] += 128*pk0*c->pk[1] + fa1 - (c->a[1]>>7);
226 c->a[1] = clamp(c->a[1], -12288, 12288); 216 c->a[1] = clip(c->a[1], -12288, 12288);
227 c->a[0] += 64*3*pk0*c->pk[0] - (c->a[0] >> 8); 217 c->a[0] += 64*3*pk0*c->pk[0] - (c->a[0] >> 8);
228 c->a[0] = clamp(c->a[0], -(15360 - c->a[1]), 15360 - c->a[1]); 218 c->a[0] = clip(c->a[0], -(15360 - c->a[1]), 15360 - c->a[1]);
229 219
230 for (i=0; i<6; i++) 220 for (i=0; i<6; i++)
231 c->b[i] += 128*dq0*sgn(-c->dq[i].sign) - (c->b[i]>>8); 221 c->b[i] += 128*dq0*sgn(-c->dq[i].sign) - (c->b[i]>>8);
232 } 222 }
233 223
253 c->ap += (-c->ap) >> 4; 243 c->ap += (-c->ap) >> 4;
254 else 244 else
255 c->ap += (0x200 - c->ap) >> 4; 245 c->ap += (0x200 - c->ap) >> 4;
256 246
257 /* Update Yu and Yl */ 247 /* Update Yu and Yl */
258 c->yu = clamp(c->y + (((c->tbls->W[I] << 5) - c->y) >> 5), 544, 5120); 248 c->yu = clip(c->y + (((c->tbls->W[I] << 5) - c->y) >> 5), 544, 5120);
259 c->yl += c->yu + ((-c->yl)>>6); 249 c->yl += c->yu + ((-c->yl)>>6);
260 250
261 /* Next iteration for Y */ 251 /* Next iteration for Y */
262 al = (c->ap >= 256) ? 1<<6 : c->ap >> 2; 252 al = (c->ap >= 256) ? 1<<6 : c->ap >> 2;
263 c->y = (c->yl + (c->yu - (c->yl>>6))*al) >> 6; 253 c->y = (c->yl + (c->yu - (c->yl>>6))*al) >> 6;
269 c->sez = c->se >> 1; 259 c->sez = c->se >> 1;
270 for (i=0; i<2; i++) 260 for (i=0; i<2; i++)
271 c->se += mult(i2f(c->a[i] >> 2, &f), &c->sr[i]); 261 c->se += mult(i2f(c->a[i] >> 2, &f), &c->sr[i]);
272 c->se >>= 1; 262 c->se >>= 1;
273 263
274 return clamp(re_signal << 2, -0xffff, 0xffff); 264 return clip(re_signal << 2, -0xffff, 0xffff);
275 } 265 }
276 266
277 static int g726_reset(G726Context* c, int bit_rate) 267 static int g726_reset(G726Context* c, int bit_rate)
278 { 268 {
279 int i; 269 int i;
327 317
328 static int g726_init(AVCodecContext * avctx) 318 static int g726_init(AVCodecContext * avctx)
329 { 319 {
330 AVG726Context* c = (AVG726Context*)avctx->priv_data; 320 AVG726Context* c = (AVG726Context*)avctx->priv_data;
331 321
332 if (avctx->sample_rate != 8000 || avctx->channels != 1 || 322 if (avctx->channels != 1 ||
333 (avctx->bit_rate != 16000 && avctx->bit_rate != 24000 && 323 (avctx->bit_rate != 16000 && avctx->bit_rate != 24000 &&
334 avctx->bit_rate != 32000 && avctx->bit_rate != 40000)) { 324 avctx->bit_rate != 32000 && avctx->bit_rate != 40000)) {
325 av_log(avctx, AV_LOG_ERROR, "G726: unsupported audio format\n");
326 return -1;
327 }
328 if (avctx->sample_rate != 8000 && avctx->strict_std_compliance>=0) {
335 av_log(avctx, AV_LOG_ERROR, "G726: unsupported audio format\n"); 329 av_log(avctx, AV_LOG_ERROR, "G726: unsupported audio format\n");
336 return -1; 330 return -1;
337 } 331 }
338 g726_reset(&c->c, avctx->bit_rate); 332 g726_reset(&c->c, avctx->bit_rate);
339 c->code_size = c->c.tbls->bits; 333 c->code_size = c->c.tbls->bits;