Mercurial > libavcodec.hg
comparison adpcm.c @ 4594:a96d905dcbaa libavcodec
Add av_ prefix to clip functions
author | reimar |
---|---|
date | Sun, 25 Feb 2007 10:27:12 +0000 |
parents | 6018c147ea93 |
children | 3c6c557aa977 |
comparison
equal
deleted
inserted
replaced
4593:2aea8bf268d8 | 4594:a96d905dcbaa |
---|---|
207 { | 207 { |
208 int delta = sample - c->prev_sample; | 208 int delta = sample - c->prev_sample; |
209 int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8; | 209 int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8; |
210 c->prev_sample = c->prev_sample + ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8); | 210 c->prev_sample = c->prev_sample + ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8); |
211 CLAMP_TO_SHORT(c->prev_sample); | 211 CLAMP_TO_SHORT(c->prev_sample); |
212 c->step_index = clip(c->step_index + index_table[nibble], 0, 88); | 212 c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88); |
213 return nibble; | 213 return nibble; |
214 } | 214 } |
215 | 215 |
216 static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample) | 216 static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample) |
217 { | 217 { |
222 nibble= sample - predictor; | 222 nibble= sample - predictor; |
223 if(nibble>=0) bias= c->idelta/2; | 223 if(nibble>=0) bias= c->idelta/2; |
224 else bias=-c->idelta/2; | 224 else bias=-c->idelta/2; |
225 | 225 |
226 nibble= (nibble + bias) / c->idelta; | 226 nibble= (nibble + bias) / c->idelta; |
227 nibble= clip(nibble, -8, 7)&0x0F; | 227 nibble= av_clip(nibble, -8, 7)&0x0F; |
228 | 228 |
229 predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta; | 229 predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta; |
230 CLAMP_TO_SHORT(predictor); | 230 CLAMP_TO_SHORT(predictor); |
231 | 231 |
232 c->sample2 = c->sample1; | 232 c->sample2 = c->sample1; |
252 nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8; | 252 nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8; |
253 | 253 |
254 c->predictor = c->predictor + ((c->step * yamaha_difflookup[nibble]) / 8); | 254 c->predictor = c->predictor + ((c->step * yamaha_difflookup[nibble]) / 8); |
255 CLAMP_TO_SHORT(c->predictor); | 255 CLAMP_TO_SHORT(c->predictor); |
256 c->step = (c->step * yamaha_indexscale[nibble]) >> 8; | 256 c->step = (c->step * yamaha_indexscale[nibble]) >> 8; |
257 c->step = clip(c->step, 127, 24567); | 257 c->step = av_clip(c->step, 127, 24567); |
258 | 258 |
259 return nibble; | 259 return nibble; |
260 } | 260 } |
261 | 261 |
262 typedef struct TrellisPath { | 262 typedef struct TrellisPath { |
322 const int step = nodes[j]->step; | 322 const int step = nodes[j]->step; |
323 int nidx; | 323 int nidx; |
324 if(version == CODEC_ID_ADPCM_MS) { | 324 if(version == CODEC_ID_ADPCM_MS) { |
325 const int predictor = ((nodes[j]->sample1 * c->coeff1) + (nodes[j]->sample2 * c->coeff2)) / 256; | 325 const int predictor = ((nodes[j]->sample1 * c->coeff1) + (nodes[j]->sample2 * c->coeff2)) / 256; |
326 const int div = (sample - predictor) / step; | 326 const int div = (sample - predictor) / step; |
327 const int nmin = clip(div-range, -8, 6); | 327 const int nmin = av_clip(div-range, -8, 6); |
328 const int nmax = clip(div+range, -7, 7); | 328 const int nmax = av_clip(div+range, -7, 7); |
329 for(nidx=nmin; nidx<=nmax; nidx++) { | 329 for(nidx=nmin; nidx<=nmax; nidx++) { |
330 const int nibble = nidx & 0xf; | 330 const int nibble = nidx & 0xf; |
331 int dec_sample = predictor + nidx * step; | 331 int dec_sample = predictor + nidx * step; |
332 #define STORE_NODE(NAME, STEP_INDEX)\ | 332 #define STORE_NODE(NAME, STEP_INDEX)\ |
333 int d;\ | 333 int d;\ |
370 } | 370 } |
371 } else if(version == CODEC_ID_ADPCM_IMA_WAV) { | 371 } else if(version == CODEC_ID_ADPCM_IMA_WAV) { |
372 #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\ | 372 #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\ |
373 const int predictor = nodes[j]->sample1;\ | 373 const int predictor = nodes[j]->sample1;\ |
374 const int div = (sample - predictor) * 4 / STEP_TABLE;\ | 374 const int div = (sample - predictor) * 4 / STEP_TABLE;\ |
375 int nmin = clip(div-range, -7, 6);\ | 375 int nmin = av_clip(div-range, -7, 6);\ |
376 int nmax = clip(div+range, -6, 7);\ | 376 int nmax = av_clip(div+range, -6, 7);\ |
377 if(nmin<=0) nmin--; /* distinguish -0 from +0 */\ | 377 if(nmin<=0) nmin--; /* distinguish -0 from +0 */\ |
378 if(nmax<0) nmax--;\ | 378 if(nmax<0) nmax--;\ |
379 for(nidx=nmin; nidx<=nmax; nidx++) {\ | 379 for(nidx=nmin; nidx<=nmax; nidx++) {\ |
380 const int nibble = nidx<0 ? 7-nidx : nidx;\ | 380 const int nibble = nidx<0 ? 7-nidx : nidx;\ |
381 int dec_sample = predictor + (STEP_TABLE * yamaha_difflookup[nibble]) / 8;\ | 381 int dec_sample = predictor + (STEP_TABLE * yamaha_difflookup[nibble]) / 8;\ |
382 STORE_NODE(NAME, STEP_INDEX);\ | 382 STORE_NODE(NAME, STEP_INDEX);\ |
383 } | 383 } |
384 LOOP_NODES(ima, step_table[step], clip(step + index_table[nibble], 0, 88)); | 384 LOOP_NODES(ima, step_table[step], av_clip(step + index_table[nibble], 0, 88)); |
385 } else { //CODEC_ID_ADPCM_YAMAHA | 385 } else { //CODEC_ID_ADPCM_YAMAHA |
386 LOOP_NODES(yamaha, step, clip((step * yamaha_indexscale[nibble]) >> 8, 127, 24567)); | 386 LOOP_NODES(yamaha, step, av_clip((step * yamaha_indexscale[nibble]) >> 8, 127, 24567)); |
387 #undef LOOP_NODES | 387 #undef LOOP_NODES |
388 #undef STORE_NODE | 388 #undef STORE_NODE |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
732 } | 732 } |
733 | 733 |
734 c->predictor += (c->step * yamaha_difflookup[nibble]) / 8; | 734 c->predictor += (c->step * yamaha_difflookup[nibble]) / 8; |
735 CLAMP_TO_SHORT(c->predictor); | 735 CLAMP_TO_SHORT(c->predictor); |
736 c->step = (c->step * yamaha_indexscale[nibble]) >> 8; | 736 c->step = (c->step * yamaha_indexscale[nibble]) >> 8; |
737 c->step = clip(c->step, 127, 24567); | 737 c->step = av_clip(c->step, 127, 24567); |
738 return c->predictor; | 738 return c->predictor; |
739 } | 739 } |
740 | 740 |
741 static void xa_decode(short *out, const unsigned char *in, | 741 static void xa_decode(short *out, const unsigned char *in, |
742 ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc) | 742 ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc) |
972 if (avctx->block_align != 0 && buf_size > avctx->block_align) | 972 if (avctx->block_align != 0 && buf_size > avctx->block_align) |
973 buf_size = avctx->block_align; | 973 buf_size = avctx->block_align; |
974 n = buf_size - 7 * avctx->channels; | 974 n = buf_size - 7 * avctx->channels; |
975 if (n < 0) | 975 if (n < 0) |
976 return -1; | 976 return -1; |
977 block_predictor[0] = clip(*src++, 0, 7); | 977 block_predictor[0] = av_clip(*src++, 0, 7); |
978 block_predictor[1] = 0; | 978 block_predictor[1] = 0; |
979 if (st) | 979 if (st) |
980 block_predictor[1] = clip(*src++, 0, 7); | 980 block_predictor[1] = av_clip(*src++, 0, 7); |
981 c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); | 981 c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); |
982 src+=2; | 982 src+=2; |
983 if (st){ | 983 if (st){ |
984 c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); | 984 c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); |
985 src+=2; | 985 src+=2; |
1297 else | 1297 else |
1298 c->status[i].predictor += vpdiff; | 1298 c->status[i].predictor += vpdiff; |
1299 | 1299 |
1300 c->status[i].step_index += table[delta & (~signmask)]; | 1300 c->status[i].step_index += table[delta & (~signmask)]; |
1301 | 1301 |
1302 c->status[i].step_index = clip(c->status[i].step_index, 0, 88); | 1302 c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88); |
1303 c->status[i].predictor = clip(c->status[i].predictor, -32768, 32767); | 1303 c->status[i].predictor = av_clip(c->status[i].predictor, -32768, 32767); |
1304 | 1304 |
1305 *samples++ = c->status[i].predictor; | 1305 *samples++ = c->status[i].predictor; |
1306 } | 1306 } |
1307 } | 1307 } |
1308 | 1308 |