| @@ -44,7 +44,7 @@ · 43 unmodified lines |
| 44 | 44 | #include "mathops.h" |
| 45 | 45 | |
| 46 | 46 | typedef struct DPCMContext { |
| 47 | | − int16_t square_array[256]; |
| 47 | + int16_t array[256]; |
| 48 | 48 | int sample[2]; ///< previous sample (for SOL_DPCM) |
| 49 | 49 | const int8_t *sol_table; ///< delta table for SOL_DPCM |
| 50 | 50 | } DPCMContext; |
| @@ -130,8 +130,8 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) · 79 unmodified lines |
| 130 | 130 | /* initialize square table */ |
| 131 | 131 | for (i = 0; i < 128; i++) { |
| 132 | 132 | int16_t square = i * i; |
| 133 | | − s->square_array[i ] = square; |
| 134 | | − s->square_array[i + 128] = -square; |
| 133 | + s->array[i ] = square; |
| 134 | + s->array[i + 128] = -square; |
| 135 | 135 | } |
| 136 | 136 | break; |
| 137 | 137 | |
| @@ -156,7 +156,25 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) · 18 unmodified lines |
| 156 | 156 | case AV_CODEC_ID_SDX2_DPCM: |
| 157 | 157 | for (i = -128; i < 128; i++) { |
| 158 | 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 | 179 | break; |
| 162 | 180 | |
| @@ -207,6 +225,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 44 unmodified lines |
| 207 | 225 | else |
| 208 | 226 | out = buf_size; |
| 209 | 227 | break; |
| 228 | + case AV_CODEC_ID_GREMLIN_DPCM: |
| 210 | 229 | case AV_CODEC_ID_SDX2_DPCM: |
| 211 | 230 | out = buf_size; |
| 212 | 231 | break; |
| @@ -240,7 +259,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 27 unmodified lines |
| 240 | 259 | |
| 241 | 260 | /* decode the samples */ |
| 242 | 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 | 263 | predictor[ch] = av_clip_int16(predictor[ch]); |
| 245 | 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 | 355 | if (!(n & 1)) |
| 337 | 356 | s->sample[ch] = 0; |
| 338 | | − s->sample[ch] += s->square_array[n + 128]; |
| 357 | + s->sample[ch] += s->array[n + 128]; |
| 339 | 358 | s->sample[ch] = av_clip_int16(s->sample[ch]); |
| 340 | 359 | *output_samples++ = s->sample[ch]; |
| 341 | 360 | ch ^= stereo; |
| 342 | 361 | } |
| 343 | 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 | 377 | *got_frame_ptr = 1; |
| @@ -360,6 +391,7 @@ AVCodec ff_ ## name_ ## _decoder = { \ · 13 unmodified lines |
| 360 | 391 | .capabilities = AV_CODEC_CAP_DR1, \ |
| 361 | 392 | } |
| 362 | 393 | |
| 394 | +DPCM_DECODER(AV_CODEC_ID_GREMLIN_DPCM, gremlin_dpcm, "DPCM Gremlin"); |
| 363 | 395 | DPCM_DECODER(AV_CODEC_ID_INTERPLAY_DPCM, interplay_dpcm, "DPCM Interplay"); |
| 364 | 396 | DPCM_DECODER(AV_CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ"); |
| 365 | 397 | DPCM_DECODER(AV_CODEC_ID_SDX2_DPCM, sdx2_dpcm, "DPCM Squareroot-Delta-Exact"); |