History

avcodec: add Gremlin DPCM decoder

Paul B Mahol committed 9 years ago

Commit 29bdcf51 parent 22a25ab6 files · +50 −8Browse files

Unified · Split

6 files
  1. libavcodec/Makefile +1 −0
  2. libavcodec/allcodecs.c +1 −0
  3. libavcodec/avcodec.h +1 −0
  4. libavcodec/codec_desc.c +7 −0
  5. libavcodec/dpcm.c +38 −6
  6. libavcodec/version.h +2 −2
libavcodec/Makefile+1−0
@@ -310,6 +310,7 @@ OBJS-$(CONFIG_G723_1_ENCODER) += g723_1enc.o g723_1.o \ · 309 unmodified lines
310310 OBJS-$(CONFIG_G729_DECODER) += g729dec.o lsp.o celp_math.o celp_filters.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfilter.o
311311 OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o
312312 OBJS-$(CONFIG_GIF_ENCODER) += gif.o lzwenc.o
313+OBJS-$(CONFIG_GREMLIN_DPCM_DECODER) += dpcm.o
313314 OBJS-$(CONFIG_GSM_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o
314315 OBJS-$(CONFIG_GSM_MS_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o
315316 OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261data.o h261.o
libavcodec/allcodecs.c+1−0
@@ -520,6 +520,7 @@ static void register_all(void) · 519 unmodified lines
520520 REGISTER_DECODER(PCM_ZORK, pcm_zork);
521521
522522 /* DPCM codecs */
523+ REGISTER_DECODER(GREMLIN_DPCM, gremlin_dpcm);
523524 REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm);
524525 REGISTER_ENCDEC (ROQ_DPCM, roq_dpcm);
525526 REGISTER_DECODER(SOL_DPCM, sol_dpcm);
libavcodec/avcodec.h+1−0
@@ -548,6 +548,7 @@ enum AVCodecID { · 547 unmodified lines
548548 AV_CODEC_ID_SOL_DPCM,
549549
550550 AV_CODEC_ID_SDX2_DPCM = 0x14800,
551+ AV_CODEC_ID_GREMLIN_DPCM,
551552
552553 /* audio codecs */
553554 AV_CODEC_ID_MP2 = 0x15000,
libavcodec/codec_desc.c+7−0
@@ -2249,6 +2249,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 2248 unmodified lines
22492249 .long_name = NULL_IF_CONFIG_SMALL("DPCM Squareroot-Delta-Exact"),
22502250 .props = AV_CODEC_PROP_LOSSY,
22512251 },
2252+ {
2253+ .id = AV_CODEC_ID_GREMLIN_DPCM,
2254+ .type = AVMEDIA_TYPE_AUDIO,
2255+ .name = "gremlin_dpcm",
2256+ .long_name = NULL_IF_CONFIG_SMALL("DPCM Gremlin"),
2257+ .props = AV_CODEC_PROP_LOSSY,
2258+ },
22522259
22532260 /* audio codecs */
22542261 {
libavcodec/dpcm.c+38−6
@@ -44,7 +44,7 @@ · 43 unmodified lines
4444 #include "mathops.h"
4545
4646 typedef struct DPCMContext {
47− int16_t square_array[256];
47+ int16_t array[256];
4848 int sample[2]; ///< previous sample (for SOL_DPCM)
4949 const int8_t *sol_table; ///< delta table for SOL_DPCM
5050 } DPCMContext;
@@ -130,8 +130,8 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) · 79 unmodified lines
130130 /* initialize square table */
131131 for (i = 0; i < 128; i++) {
132132 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;
135135 }
136136 break;
137137
@@ -156,7 +156,25 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) · 18 unmodified lines
156156 case AV_CODEC_ID_SDX2_DPCM:
157157 for (i = -128; i < 128; i++) {
158158 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);
160178 }
161179 break;
162180
@@ -207,6 +225,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 44 unmodified lines
207225 else
208226 out = buf_size;
209227 break;
228+ case AV_CODEC_ID_GREMLIN_DPCM:
210229 case AV_CODEC_ID_SDX2_DPCM:
211230 out = buf_size;
212231 break;
@@ -240,7 +259,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 27 unmodified lines
240259
241260 /* decode the samples */
242261 while (output_samples < samples_end) {
243− predictor[ch] += s->square_array[bytestream2_get_byteu(&gb)];
262+ predictor[ch] += s->array[bytestream2_get_byteu(&gb)];
244263 predictor[ch] = av_clip_int16(predictor[ch]);
245264 *output_samples++ = predictor[ch];
246265
@@ -335,12 +354,24 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 88 unmodified lines
335354
336355 if (!(n & 1))
337356 s->sample[ch] = 0;
338− s->sample[ch] += s->square_array[n + 128];
357+ s->sample[ch] += s->array[n + 128];
339358 s->sample[ch] = av_clip_int16(s->sample[ch]);
340359 *output_samples++ = s->sample[ch];
341360 ch ^= stereo;
342361 }
343362 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;
344375 }
345376
346377 *got_frame_ptr = 1;
@@ -360,6 +391,7 @@ AVCodec ff_ ## name_ ## _decoder = { \ · 13 unmodified lines
360391 .capabilities = AV_CODEC_CAP_DR1, \
361392 }
362393
394+DPCM_DECODER(AV_CODEC_ID_GREMLIN_DPCM, gremlin_dpcm, "DPCM Gremlin");
363395 DPCM_DECODER(AV_CODEC_ID_INTERPLAY_DPCM, interplay_dpcm, "DPCM Interplay");
364396 DPCM_DECODER(AV_CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ");
365397 DPCM_DECODER(AV_CODEC_ID_SDX2_DPCM, sdx2_dpcm, "DPCM Squareroot-Delta-Exact");
libavcodec/version.h+2−2
@@ -28,8 +28,8 @@ · 27 unmodified lines
2828 #include "libavutil/version.h"
2929
3030 #define LIBAVCODEC_VERSION_MAJOR 57
31−#define LIBAVCODEC_VERSION_MINOR 96
32−#define LIBAVCODEC_VERSION_MICRO 101
31+#define LIBAVCODEC_VERSION_MINOR 97
32+#define LIBAVCODEC_VERSION_MICRO 100
3333
3434 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3535 LIBAVCODEC_VERSION_MINOR, \

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