Mercurial > libavcodec.hg
comparison adpcm.c @ 3127:6bae70889b35 libavcodec
add Creative 8 bits ADPCM schemes support
author | aurel |
---|---|
date | Thu, 16 Feb 2006 00:09:23 +0000 |
parents | 0b546eab515d |
children | 58dc6ca8c92d |
comparison
equal
deleted
inserted
replaced
3126:05a10f97d510 | 3127:6bae70889b35 |
---|---|
512 CLAMP_TO_SHORT(predictor); | 512 CLAMP_TO_SHORT(predictor); |
513 c->predictor = predictor; | 513 c->predictor = predictor; |
514 return (short)predictor; | 514 return (short)predictor; |
515 } | 515 } |
516 | 516 |
517 static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift) | |
518 { | |
519 int sign, delta, diff; | |
520 | |
521 sign = nibble & (1<<(size-1)); | |
522 delta = nibble & ((1<<(size-1))-1); | |
523 diff = delta << (7 + c->step + shift); | |
524 | |
525 if (sign) | |
526 c->predictor -= diff; | |
527 else | |
528 c->predictor += diff; | |
529 | |
530 /* clamp result */ | |
531 if (c->predictor > 16256) | |
532 c->predictor = 16256; | |
533 else if (c->predictor < -16384) | |
534 c->predictor = -16384; | |
535 | |
536 /* calculate new step */ | |
537 if (delta >= (2*size - 3) && c->step < 3) | |
538 c->step++; | |
539 else if (delta == 0 && c->step > 0) | |
540 c->step--; | |
541 | |
542 return (short) c->predictor; | |
543 } | |
544 | |
517 static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble) | 545 static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble) |
518 { | 546 { |
519 if(!c->step) { | 547 if(!c->step) { |
520 c->predictor = 0; | 548 c->predictor = 0; |
521 c->step = 127; | 549 c->step = 127; |
642 return 0; | 670 return 0; |
643 | 671 |
644 samples = data; | 672 samples = data; |
645 src = buf; | 673 src = buf; |
646 | 674 |
647 st = avctx->channels == 2; | 675 st = avctx->channels == 2 ? 1 : 0; |
648 | 676 |
649 switch(avctx->codec->id) { | 677 switch(avctx->codec->id) { |
650 case CODEC_ID_ADPCM_IMA_QT: | 678 case CODEC_ID_ADPCM_IMA_QT: |
651 n = (buf_size - 2);/* >> 2*avctx->channels;*/ | 679 n = (buf_size - 2);/* >> 2*avctx->channels;*/ |
652 channel = c->channel; | 680 channel = c->channel; |
971 src[0] & 0x0F); | 999 src[0] & 0x0F); |
972 } | 1000 } |
973 src++; | 1001 src++; |
974 } | 1002 } |
975 break; | 1003 break; |
1004 case CODEC_ID_ADPCM_SBPRO_4: | |
1005 case CODEC_ID_ADPCM_SBPRO_3: | |
1006 case CODEC_ID_ADPCM_SBPRO_2: | |
1007 if (!c->status[0].step_index) { | |
1008 /* the first byte is a raw sample */ | |
1009 *samples++ = 128 * (*src++ - 0x80); | |
1010 if (st) | |
1011 *samples++ = 128 * (*src++ - 0x80); | |
1012 c->status[0].step_index = 1; | |
1013 } | |
1014 if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) { | |
1015 while (src < buf + buf_size) { | |
1016 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], | |
1017 (src[0] >> 4) & 0x0F, 4, 0); | |
1018 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], | |
1019 src[0] & 0x0F, 4, 0); | |
1020 src++; | |
1021 } | |
1022 } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) { | |
1023 while (src < buf + buf_size) { | |
1024 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], | |
1025 (src[0] >> 5) & 0x07, 3, 0); | |
1026 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], | |
1027 (src[0] >> 2) & 0x07, 3, 0); | |
1028 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], | |
1029 src[0] & 0x03, 2, 0); | |
1030 src++; | |
1031 } | |
1032 } else { | |
1033 while (src < buf + buf_size) { | |
1034 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], | |
1035 (src[0] >> 6) & 0x03, 2, 2); | |
1036 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], | |
1037 (src[0] >> 4) & 0x03, 2, 2); | |
1038 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], | |
1039 (src[0] >> 2) & 0x03, 2, 2); | |
1040 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], | |
1041 src[0] & 0x03, 2, 2); | |
1042 src++; | |
1043 } | |
1044 } | |
1045 break; | |
976 case CODEC_ID_ADPCM_SWF: | 1046 case CODEC_ID_ADPCM_SWF: |
977 { | 1047 { |
978 GetBitContext gb; | 1048 GetBitContext gb; |
979 const int *table; | 1049 const int *table; |
980 int k0, signmask; | 1050 int k0, signmask; |
1115 ADPCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx); | 1185 ADPCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx); |
1116 ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea); | 1186 ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea); |
1117 ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct); | 1187 ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct); |
1118 ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf); | 1188 ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf); |
1119 ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha); | 1189 ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha); |
1190 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4); | |
1191 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3); | |
1192 ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); | |
1120 | 1193 |
1121 #undef ADPCM_CODEC | 1194 #undef ADPCM_CODEC |