Mercurial > libavcodec.hg
comparison adpcm.c @ 7258:48c9043b1372 libavcodec
Use bytestream and AV_RL* functions in ADPCM code where possible
author | reimar |
---|---|
date | Sun, 13 Jul 2008 14:12:51 +0000 |
parents | 9b836800690a |
children | 9de4bc7d4938 |
comparison
equal
deleted
inserted
replaced
7257:9b836800690a | 7258:48c9043b1372 |
---|---|
970 | 970 |
971 // samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1; | 971 // samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1; |
972 | 972 |
973 for(i=0; i<avctx->channels; i++){ | 973 for(i=0; i<avctx->channels; i++){ |
974 cs = &(c->status[i]); | 974 cs = &(c->status[i]); |
975 cs->predictor = *samples++ = (int16_t)(src[0] + (src[1]<<8)); | 975 cs->predictor = *samples++ = (int16_t)bytestream_get_le16(&src); |
976 src+=2; | |
977 | 976 |
978 cs->step_index = *src++; | 977 cs->step_index = *src++; |
979 if (cs->step_index > 88){ | 978 if (cs->step_index > 88){ |
980 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); | 979 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); |
981 cs->step_index = 88; | 980 cs->step_index = 88; |
994 src += 4*st; | 993 src += 4*st; |
995 } | 994 } |
996 break; | 995 break; |
997 case CODEC_ID_ADPCM_4XM: | 996 case CODEC_ID_ADPCM_4XM: |
998 cs = &(c->status[0]); | 997 cs = &(c->status[0]); |
999 c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2; | 998 c->status[0].predictor= (int16_t)bytestream_get_le16(&src); |
1000 if(st){ | 999 if(st){ |
1001 c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2; | 1000 c->status[1].predictor= (int16_t)bytestream_get_le16(&src); |
1002 } | 1001 } |
1003 c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2; | 1002 c->status[0].step_index= (int16_t)bytestream_get_le16(&src); |
1004 if(st){ | 1003 if(st){ |
1005 c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2; | 1004 c->status[1].step_index= (int16_t)bytestream_get_le16(&src); |
1006 } | 1005 } |
1007 if (cs->step_index < 0) cs->step_index = 0; | 1006 if (cs->step_index < 0) cs->step_index = 0; |
1008 if (cs->step_index > 88) cs->step_index = 88; | 1007 if (cs->step_index > 88) cs->step_index = 88; |
1009 | 1008 |
1010 m= (buf_size - (src - buf))>>st; | 1009 m= (buf_size - (src - buf))>>st; |
1028 return -1; | 1027 return -1; |
1029 block_predictor[0] = av_clip(*src++, 0, 7); | 1028 block_predictor[0] = av_clip(*src++, 0, 7); |
1030 block_predictor[1] = 0; | 1029 block_predictor[1] = 0; |
1031 if (st) | 1030 if (st) |
1032 block_predictor[1] = av_clip(*src++, 0, 7); | 1031 block_predictor[1] = av_clip(*src++, 0, 7); |
1033 c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); | 1032 c->status[0].idelta = (int16_t)bytestream_get_le16(&src); |
1034 src+=2; | |
1035 if (st){ | 1033 if (st){ |
1036 c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); | 1034 c->status[1].idelta = (int16_t)bytestream_get_le16(&src); |
1037 src+=2; | |
1038 } | 1035 } |
1039 c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]]; | 1036 c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]]; |
1040 c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]]; | 1037 c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]]; |
1041 c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]]; | 1038 c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]]; |
1042 c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]]; | 1039 c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]]; |
1043 | 1040 |
1044 c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); | 1041 c->status[0].sample1 = bytestream_get_le16(&src); |
1045 src+=2; | 1042 if (st) c->status[1].sample1 = bytestream_get_le16(&src); |
1046 if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); | 1043 c->status[0].sample2 = bytestream_get_le16(&src); |
1047 if (st) src+=2; | 1044 if (st) c->status[1].sample2 = bytestream_get_le16(&src); |
1048 c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); | |
1049 src+=2; | |
1050 if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00)); | |
1051 if (st) src+=2; | |
1052 | 1045 |
1053 *samples++ = c->status[0].sample2; | 1046 *samples++ = c->status[0].sample2; |
1054 if (st) *samples++ = c->status[1].sample2; | 1047 if (st) *samples++ = c->status[1].sample2; |
1055 *samples++ = c->status[0].sample1; | 1048 *samples++ = c->status[0].sample1; |
1056 if (st) *samples++ = c->status[1].sample1; | 1049 if (st) *samples++ = c->status[1].sample1; |
1062 break; | 1055 break; |
1063 case CODEC_ID_ADPCM_IMA_DK4: | 1056 case CODEC_ID_ADPCM_IMA_DK4: |
1064 if (avctx->block_align != 0 && buf_size > avctx->block_align) | 1057 if (avctx->block_align != 0 && buf_size > avctx->block_align) |
1065 buf_size = avctx->block_align; | 1058 buf_size = avctx->block_align; |
1066 | 1059 |
1067 c->status[0].predictor = (int16_t)(src[0] | (src[1] << 8)); | 1060 c->status[0].predictor = (int16_t)bytestream_get_le16(&src); |
1068 c->status[0].step_index = src[2]; | 1061 c->status[0].step_index = *src++; |
1069 src += 4; | 1062 src++; |
1070 *samples++ = c->status[0].predictor; | 1063 *samples++ = c->status[0].predictor; |
1071 if (st) { | 1064 if (st) { |
1072 c->status[1].predictor = (int16_t)(src[0] | (src[1] << 8)); | 1065 c->status[1].predictor = (int16_t)bytestream_get_le16(&src); |
1073 c->status[1].step_index = src[2]; | 1066 c->status[1].step_index = *src++; |
1074 src += 4; | 1067 src++; |
1075 *samples++ = c->status[1].predictor; | 1068 *samples++ = c->status[1].predictor; |
1076 } | 1069 } |
1077 while (src < buf + buf_size) { | 1070 while (src < buf + buf_size) { |
1078 | 1071 |
1079 /* take care of the top nibble (always left or mono channel) */ | 1072 /* take care of the top nibble (always left or mono channel) */ |
1097 buf_size = avctx->block_align; | 1090 buf_size = avctx->block_align; |
1098 | 1091 |
1099 if(buf_size + 16 > (samples_end - samples)*3/8) | 1092 if(buf_size + 16 > (samples_end - samples)*3/8) |
1100 return -1; | 1093 return -1; |
1101 | 1094 |
1102 c->status[0].predictor = (int16_t)(src[10] | (src[11] << 8)); | 1095 c->status[0].predictor = (int16_t)AV_RL16(src + 10); |
1103 c->status[1].predictor = (int16_t)(src[12] | (src[13] << 8)); | 1096 c->status[1].predictor = (int16_t)AV_RL16(src + 12); |
1104 c->status[0].step_index = src[14]; | 1097 c->status[0].step_index = src[14]; |
1105 c->status[1].step_index = src[15]; | 1098 c->status[1].step_index = src[15]; |
1106 /* sign extend the predictors */ | 1099 /* sign extend the predictors */ |
1107 src += 16; | 1100 src += 16; |
1108 diff_channel = c->status[1].predictor; | 1101 diff_channel = c->status[1].predictor; |
1194 if (samples_in_chunk >= ((buf_size - 12) * 2)) { | 1187 if (samples_in_chunk >= ((buf_size - 12) * 2)) { |
1195 src += buf_size; | 1188 src += buf_size; |
1196 break; | 1189 break; |
1197 } | 1190 } |
1198 src += 4; | 1191 src += 4; |
1199 current_left_sample = (int16_t)AV_RL16(src); | 1192 current_left_sample = (int16_t)bytestream_get_le16(&src); |
1200 src += 2; | 1193 previous_left_sample = (int16_t)bytestream_get_le16(&src); |
1201 previous_left_sample = (int16_t)AV_RL16(src); | 1194 current_right_sample = (int16_t)bytestream_get_le16(&src); |
1202 src += 2; | 1195 previous_right_sample = (int16_t)bytestream_get_le16(&src); |
1203 current_right_sample = (int16_t)AV_RL16(src); | |
1204 src += 2; | |
1205 previous_right_sample = (int16_t)AV_RL16(src); | |
1206 src += 2; | |
1207 | 1196 |
1208 for (count1 = 0; count1 < samples_in_chunk/28;count1++) { | 1197 for (count1 = 0; count1 < samples_in_chunk/28;count1++) { |
1209 coeff1l = ea_adpcm_table[ *src >> 4 ]; | 1198 coeff1l = ea_adpcm_table[ *src >> 4 ]; |
1210 coeff2l = ea_adpcm_table[(*src >> 4 ) + 4]; | 1199 coeff2l = ea_adpcm_table[(*src >> 4 ) + 4]; |
1211 coeff1r = ea_adpcm_table[*src & 0x0F]; | 1200 coeff1r = ea_adpcm_table[*src & 0x0F]; |