| @@ -35,6 +35,8 @@ typedef struct WavArcContext { · 34 unmodified lines |
| 35 | 35 | int shift; |
| 36 | 36 | int nb_samples; |
| 37 | 37 | int offset; |
| 38 | + int align; |
| 39 | + int add; |
| 38 | 40 | |
| 39 | 41 | int eof; |
| 40 | 42 | int skip; |
| @@ -68,22 +70,32 @@ static av_cold int wavarc_init(AVCodecContext *avctx) · 27 unmodified lines |
| 68 | 70 | av_channel_layout_default(&avctx->ch_layout, AV_RL16(avctx->extradata + 38)); |
| 69 | 71 | avctx->sample_rate = AV_RL32(avctx->extradata + 40); |
| 70 | 72 | |
| 73 | + s->align = avctx->ch_layout.nb_channels; |
| 74 | + |
| 71 | 75 | switch (AV_RL16(avctx->extradata + 50)) { |
| 72 | 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 | 81 | s->shift = 0; |
| 77 | 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 | 88 | case MKTAG('1','D','I','F'): |
| 79 | 89 | s->nb_samples = 256; |
| 80 | 90 | s->offset = 4; |
| 91 | + s->add = 0x80; |
| 81 | 92 | break; |
| 82 | 93 | case MKTAG('2','S','L','P'): |
| 83 | 94 | case MKTAG('3','N','L','P'): |
| 84 | 95 | case MKTAG('4','A','L','P'): |
| 85 | 96 | s->nb_samples = 570; |
| 86 | 97 | s->offset = 70; |
| 98 | + s->add = 0x80; |
| 87 | 99 | break; |
| 88 | 100 | default: |
| 89 | 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 | 170 | static int decode_1dif(AVCodecContext *avctx, |
| 146 | 171 | WavArcContext *s, GetBitContext *gb) |
| 147 | 172 | { |
| @@ -375,6 +400,9 @@ static int wavarc_decode(AVCodecContext *avctx, AVFrame *frame, · 227 unmodified lines |
| 375 | 400 | skip_bits(gb, s->skip); |
| 376 | 401 | |
| 377 | 402 | switch (avctx->codec_tag) { |
| 403 | + case MKTAG('0','C','P','Y'): |
| 404 | + ret = decode_0cpy(avctx, s, gb); |
| 405 | + break; |
| 378 | 406 | case MKTAG('1','D','I','F'): |
| 379 | 407 | ret = decode_1dif(avctx, s, gb); |
| 380 | 408 | break; |
| @@ -413,7 +441,7 @@ fail: · 32 unmodified lines |
| 413 | 441 | const int *src = s->samples[ch] + s->offset; |
| 414 | 442 | |
| 415 | 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 | 446 | break; |
| 419 | 447 | case AV_SAMPLE_FMT_S16P: |