| @@ -44,7 +44,7 @@ · 43 unmodified lines |
| 44 | #include "mathops.h" | 44 | #include "mathops.h" |
| 45 | | 45 | |
| 46 | typedef struct DPCMContext { | 46 | typedef struct DPCMContext { |
| 47 | int16_t square_array[256]; | 47 | int16_t array[256]; |
| 48 | int sample[2]; ///< previous sample (for SOL_DPCM) | 48 | int sample[2]; ///< previous sample (for SOL_DPCM) |
| 49 | const int8_t *sol_table; ///< delta table for SOL_DPCM | 49 | const int8_t *sol_table; ///< delta table for SOL_DPCM |
| 50 | } DPCMContext; | 50 | } DPCMContext; |
| @@ -130,8 +130,8 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) · 79 unmodified lines |
| 130 | /* initialize square table */ | 130 | /* initialize square table */ |
| 131 | for (i = 0; i < 128; i++) { | 131 | for (i = 0; i < 128; i++) { |
| 132 | int16_t square = i * i; | 132 | int16_t square = i * i; |
| 133 | s->square_array[i ] = square; | 133 | s->array[i ] = square; |
| 134 | s->square_array[i + 128] = -square; | 134 | s->array[i + 128] = -square; |
| 135 | } | 135 | } |
| 136 | break; | 136 | break; |
| 137 | | 137 | |
| @@ -156,7 +156,25 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) · 18 unmodified lines |
| 156 | case AV_CODEC_ID_SDX2_DPCM: | 156 | case AV_CODEC_ID_SDX2_DPCM: |
| 157 | for (i = -128; i < 128; i++) { | 157 | for (i = -128; i < 128; i++) { |
| 158 | int16_t square = i * i * 2; | 158 | int16_t square = i * i * 2; |
| 159 | s->square_array[i+128] = i < 0 ? -square: square; | 159 | s->array[i+128] = i < 0 ? -square: square; |
| | 160 | } |
| | 161 | break; |
| | 162 | |
| | 163 | case AV_CODEC_ID_GREMLIN_DPCM: { |
| | 164 | int delta = 0; |
| | 165 | int code = 64; |
| | 166 | int step = 45; |
| | 167 | |
| | 168 | s->array[0] = 0; |
| | 169 | for (i = 0; i < 127; i++) { |
| | 170 | delta += (code >> 5); |
| | 171 | code += step; |
| | 172 | step += 2; |
| | 173 | |
| | 174 | s->array[i*2 + 1] = delta; |
| | 175 | s->array[i*2 + 2] = -delta; |
| | 176 | } |
| | 177 | s->array[255] = delta + (code >> 5); |
| 160 | } | 178 | } |
| 161 | break; | 179 | break; |
| 162 | | 180 | |
| @@ -207,6 +225,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 44 unmodified lines |
| 207 | else | 225 | else |
| 208 | out = buf_size; | 226 | out = buf_size; |
| 209 | break; | 227 | break; |
| | 228 | case AV_CODEC_ID_GREMLIN_DPCM: |
| 210 | case AV_CODEC_ID_SDX2_DPCM: | 229 | case AV_CODEC_ID_SDX2_DPCM: |
| 211 | out = buf_size; | 230 | out = buf_size; |
| 212 | break; | 231 | break; |
| @@ -240,7 +259,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 27 unmodified lines |
| 240 | | 259 | |
| 241 | /* decode the samples */ | 260 | /* decode the samples */ |
| 242 | while (output_samples < samples_end) { | 261 | while (output_samples < samples_end) { |
| 243 | predictor[ch] += s->square_array[bytestream2_get_byteu(&gb)]; | 262 | predictor[ch] += s->array[bytestream2_get_byteu(&gb)]; |
| 244 | predictor[ch] = av_clip_int16(predictor[ch]); | 263 | predictor[ch] = av_clip_int16(predictor[ch]); |
| 245 | *output_samples++ = predictor[ch]; | 264 | *output_samples++ = predictor[ch]; |
| 246 | | 265 | |
| @@ -335,12 +354,24 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 88 unmodified lines |
| 335 | | 354 | |
| 336 | if (!(n & 1)) | 355 | if (!(n & 1)) |
| 337 | s->sample[ch] = 0; | 356 | s->sample[ch] = 0; |
| 338 | s->sample[ch] += s->square_array[n + 128]; | 357 | s->sample[ch] += s->array[n + 128]; |
| 339 | s->sample[ch] = av_clip_int16(s->sample[ch]); | 358 | s->sample[ch] = av_clip_int16(s->sample[ch]); |
| 340 | *output_samples++ = s->sample[ch]; | 359 | *output_samples++ = s->sample[ch]; |
| 341 | ch ^= stereo; | 360 | ch ^= stereo; |
| 342 | } | 361 | } |
| 343 | break; | 362 | break; |
| | 363 | |
| | 364 | case AV_CODEC_ID_GREMLIN_DPCM: { |
| | 365 | int idx = 0; |
| | 366 | |
| | 367 | while (output_samples < samples_end) { |
| | 368 | uint8_t n = bytestream2_get_byteu(&gb); |
| | 369 | |
| | 370 | *output_samples++ = s->sample[idx] += s->array[n]; |
| | 371 | idx ^= 1; |
| | 372 | } |
| | 373 | } |
| | 374 | break; |
| 344 | } | 375 | } |
| 345 | | 376 | |
| 346 | *got_frame_ptr = 1; | 377 | *got_frame_ptr = 1; |
| @@ -360,6 +391,7 @@ AVCodec ff_ ## name_ ## _decoder = { \ · 13 unmodified lines |
| 360 | .capabilities = AV_CODEC_CAP_DR1, \ | 391 | .capabilities = AV_CODEC_CAP_DR1, \ |
| 361 | } | 392 | } |
| 362 | | 393 | |
| | 394 | DPCM_DECODER(AV_CODEC_ID_GREMLIN_DPCM, gremlin_dpcm, "DPCM Gremlin"); |
| 363 | DPCM_DECODER(AV_CODEC_ID_INTERPLAY_DPCM, interplay_dpcm, "DPCM Interplay"); | 395 | DPCM_DECODER(AV_CODEC_ID_INTERPLAY_DPCM, interplay_dpcm, "DPCM Interplay"); |
| 364 | DPCM_DECODER(AV_CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ"); | 396 | DPCM_DECODER(AV_CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ"); |
| 365 | DPCM_DECODER(AV_CODEC_ID_SDX2_DPCM, sdx2_dpcm, "DPCM Squareroot-Delta-Exact"); | 397 | DPCM_DECODER(AV_CODEC_ID_SDX2_DPCM, sdx2_dpcm, "DPCM Squareroot-Delta-Exact"); |