| @@ -35,6 +35,8 @@ typedef struct WavArcContext { · 34 unmodified lines |
| 35 | int shift; | 35 | int shift; |
| 36 | int nb_samples; | 36 | int nb_samples; |
| 37 | int offset; | 37 | int offset; |
| | 38 | int align; |
| | 39 | int add; |
| 38 | | 40 | |
| 39 | int eof; | 41 | int eof; |
| 40 | int skip; | 42 | int skip; |
| @@ -68,22 +70,32 @@ static av_cold int wavarc_init(AVCodecContext *avctx) · 27 unmodified lines |
| 68 | av_channel_layout_default(&avctx->ch_layout, AV_RL16(avctx->extradata + 38)); | 70 | av_channel_layout_default(&avctx->ch_layout, AV_RL16(avctx->extradata + 38)); |
| 69 | avctx->sample_rate = AV_RL32(avctx->extradata + 40); | 71 | avctx->sample_rate = AV_RL32(avctx->extradata + 40); |
| 70 | | 72 | |
| | 73 | s->align = avctx->ch_layout.nb_channels; |
| | 74 | |
| 71 | switch (AV_RL16(avctx->extradata + 50)) { | 75 | switch (AV_RL16(avctx->extradata + 50)) { |
| 72 | case 8: avctx->sample_fmt = AV_SAMPLE_FMT_U8P; break; | 76 | case 8: avctx->sample_fmt = AV_SAMPLE_FMT_U8P; break; |
| 73 | case 16: avctx->sample_fmt = AV_SAMPLE_FMT_S16P; break; | 77 | case 16: s->align *= 2; |
| | 78 | avctx->sample_fmt = AV_SAMPLE_FMT_S16P; break; |
| 74 | } | 79 | } |
| 75 | | 80 | |
| 76 | s->shift = 0; | 81 | s->shift = 0; |
| 77 | switch (avctx->codec_tag) { | 82 | switch (avctx->codec_tag) { |
| | 83 | case MKTAG('0','C','P','Y'): |
| | 84 | s->nb_samples = 640; |
| | 85 | s->offset = 0; |
| | 86 | s->add = 0; |
| | 87 | break; |
| 78 | case MKTAG('1','D','I','F'): | 88 | case MKTAG('1','D','I','F'): |
| 79 | s->nb_samples = 256; | 89 | s->nb_samples = 256; |
| 80 | s->offset = 4; | 90 | s->offset = 4; |
| | 91 | s->add = 0x80; |
| 81 | break; | 92 | break; |
| 82 | case MKTAG('2','S','L','P'): | 93 | case MKTAG('2','S','L','P'): |
| 83 | case MKTAG('3','N','L','P'): | 94 | case MKTAG('3','N','L','P'): |
| 84 | case MKTAG('4','A','L','P'): | 95 | case MKTAG('4','A','L','P'): |
| 85 | s->nb_samples = 570; | 96 | s->nb_samples = 570; |
| 86 | s->offset = 70; | 97 | s->offset = 70; |
| | 98 | s->add = 0x80; |
| 87 | break; | 99 | break; |
| 88 | default: | 100 | default: |
| 89 | return AVERROR_INVALIDDATA; | 101 | return AVERROR_INVALIDDATA; |
| @@ -142,6 +154,19 @@ static void do_stereo(WavArcContext *s, int ch, int correlated, int len) · 52 unmodified lines |
| 142 | } | 154 | } |
| 143 | } | 155 | } |
| 144 | | 156 | |
| | 157 | static int decode_0cpy(AVCodecContext *avctx, |
| | 158 | WavArcContext *s, GetBitContext *gb) |
| | 159 | { |
| | 160 | int bits = s->align * 8; |
| | 161 | s->nb_samples = FFMIN(640, get_bits_left(gb) / bits); |
| | 162 | |
| | 163 | for (int n = 0; n < s->nb_samples; n++) { |
| | 164 | for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) |
| | 165 | s->samples[ch][n] = get_bits(gb, bits); |
| | 166 | } |
| | 167 | return 0; |
| | 168 | } |
| | 169 | |
| 145 | static int decode_1dif(AVCodecContext *avctx, | 170 | static int decode_1dif(AVCodecContext *avctx, |
| 146 | WavArcContext *s, GetBitContext *gb) | 171 | WavArcContext *s, GetBitContext *gb) |
| 147 | { | 172 | { |
| @@ -375,6 +400,9 @@ static int wavarc_decode(AVCodecContext *avctx, AVFrame *frame, · 227 unmodified lines |
| 375 | skip_bits(gb, s->skip); | 400 | skip_bits(gb, s->skip); |
| 376 | | 401 | |
| 377 | switch (avctx->codec_tag) { | 402 | switch (avctx->codec_tag) { |
| | 403 | case MKTAG('0','C','P','Y'): |
| | 404 | ret = decode_0cpy(avctx, s, gb); |
| | 405 | break; |
| 378 | case MKTAG('1','D','I','F'): | 406 | case MKTAG('1','D','I','F'): |
| 379 | ret = decode_1dif(avctx, s, gb); | 407 | ret = decode_1dif(avctx, s, gb); |
| 380 | break; | 408 | break; |
| @@ -413,7 +441,7 @@ fail: · 32 unmodified lines |
| 413 | const int *src = s->samples[ch] + s->offset; | 441 | const int *src = s->samples[ch] + s->offset; |
| 414 | | 442 | |
| 415 | for (int n = 0; n < frame->nb_samples; n++) | 443 | for (int n = 0; n < frame->nb_samples; n++) |
| 416 | dst[n] = src[n] * (1 << s->shift) + 0x80U; | 444 | dst[n] = src[n] * (1 << s->shift) + s->add; |
| 417 | } | 445 | } |
| 418 | break; | 446 | break; |
| 419 | case AV_SAMPLE_FMT_S16P: | 447 | case AV_SAMPLE_FMT_S16P: |