History

avcodec/adpcm_argo: support decoding multiple frames

Increases decode speed significantly.

Zane van Iperen committed 6 years ago

Commit 9eabe9c1 parent 624f6df1 file · +8 −8Browse files

Unified · Split

libavcodec/adpcm.c+8−8
@@ -181,7 +181,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 180 unmodified lines
181 c->vqa_version = AV_RL16(avctx->extradata);181 c->vqa_version = AV_RL16(avctx->extradata);
182 break;182 break;
183 case AV_CODEC_ID_ADPCM_ARGO:183 case AV_CODEC_ID_ADPCM_ARGO:
184 if (avctx->bits_per_coded_sample != 4)184 if (avctx->bits_per_coded_sample != 4 || avctx->block_align != 17 * avctx->channels)
185 return AVERROR_INVALIDDATA;185 return AVERROR_INVALIDDATA;
186 break;186 break;
187 case AV_CODEC_ID_ADPCM_ZORK:187 case AV_CODEC_ID_ADPCM_ZORK:
@@ -745,11 +745,6 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, · 557 unmodified lines
745 return 0;745 return 0;
746 nb_samples = 64;746 nb_samples = 64;
747 break;747 break;
748 case AV_CODEC_ID_ADPCM_ARGO:
749 if (buf_size < 17 * ch)
750 return 0;
751 nb_samples = 32;
752 break;
753 /* simple 4-bit adpcm */748 /* simple 4-bit adpcm */
754 case AV_CODEC_ID_ADPCM_CT:749 case AV_CODEC_ID_ADPCM_CT:
755 case AV_CODEC_ID_ADPCM_IMA_APC:750 case AV_CODEC_ID_ADPCM_IMA_APC:
@@ -922,6 +917,9 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, · 166 unmodified lines
922 case AV_CODEC_ID_ADPCM_PSX:917 case AV_CODEC_ID_ADPCM_PSX:
923 nb_samples = buf_size / (16 * ch) * 28;918 nb_samples = buf_size / (16 * ch) * 28;
924 break;919 break;
920 case AV_CODEC_ID_ADPCM_ARGO:
921 nb_samples = buf_size / avctx->block_align * 32;
922 break;
925 case AV_CODEC_ID_ADPCM_ZORK:923 case AV_CODEC_ID_ADPCM_ZORK:
926 nb_samples = buf_size / ch;924 nb_samples = buf_size / ch;
927 break;925 break;
@@ -2023,22 +2021,24 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 1095 unmodified lines
2023 * Each block relies on the previous two samples of each channel.2021 * Each block relies on the previous two samples of each channel.
2024 * They should be 0 initially.2022 * They should be 0 initially.
2025 */2023 */
2024 for (int block = 0; block < avpkt->size / avctx->block_align; block++) {
2026 for (channel = 0; channel < avctx->channels; channel++) {2025 for (channel = 0; channel < avctx->channels; channel++) {
2027 int control, shift;2026 int control, shift;
2028 2027
2029 samples = samples_p[channel];2028 samples = samples_p[channel] + block * 32;
2030 cs = c->status + channel;2029 cs = c->status + channel;
2031 2030
2032 /* Get the control byte and decode the samples, 2 at a time. */2031 /* Get the control byte and decode the samples, 2 at a time. */
2033 control = bytestream2_get_byteu(&gb);2032 control = bytestream2_get_byteu(&gb);
2034 shift = (control >> 4) + 2;2033 shift = (control >> 4) + 2;
2035 2034
2036 for (n = 0; n < nb_samples / 2; n++) {2035 for (n = 0; n < 16; n++) {
2037 int sample = bytestream2_get_byteu(&gb);2036 int sample = bytestream2_get_byteu(&gb);
2038 *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 4, shift, control & 0x04);2037 *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 4, shift, control & 0x04);
2039 *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 0, shift, control & 0x04);2038 *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 0, shift, control & 0x04);
2040 }2039 }
2041 }2040 }
2041 }
2042 break;2042 break;
2043 case AV_CODEC_ID_ADPCM_ZORK:2043 case AV_CODEC_ID_ADPCM_ZORK:
2044 if (!c->has_status) {2044 if (!c->has_status) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t