00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030 #include "avcodec.h"
00031
00033 typedef struct EightSvxContext {
00034 int16_t fib_acc;
00035 const int16_t *table;
00036 } EightSvxContext;
00037
00038 static const int16_t fibonacci[16] = { -34<<8, -21<<8, -13<<8, -8<<8, -5<<8, -3<<8, -2<<8, -1<<8,
00039 0, 1<<8, 2<<8, 3<<8, 5<<8, 8<<8, 13<<8, 21<<8 };
00040 static const int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8,
00041 0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 };
00042
00044 static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
00045 AVPacket *avpkt)
00046 {
00047 const uint8_t *buf = avpkt->data;
00048 int buf_size = avpkt->size;
00049 EightSvxContext *esc = avctx->priv_data;
00050 int16_t *out_data = data;
00051 int consumed = buf_size;
00052 const uint8_t *buf_end = buf + buf_size;
00053
00054 if((*data_size >> 2) < buf_size)
00055 return -1;
00056
00057 if(avctx->frame_number == 0) {
00058 esc->fib_acc = buf[1] << 8;
00059 buf_size -= 2;
00060 buf += 2;
00061 }
00062
00063 *data_size = buf_size << 2;
00064
00065 while(buf < buf_end) {
00066 uint8_t d = *buf++;
00067 esc->fib_acc += esc->table[d & 0x0f];
00068 *out_data++ = esc->fib_acc;
00069 esc->fib_acc += esc->table[d >> 4];
00070 *out_data++ = esc->fib_acc;
00071 }
00072
00073 return consumed;
00074 }
00075
00077 static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
00078 {
00079 EightSvxContext *esc = avctx->priv_data;
00080
00081 switch(avctx->codec->id) {
00082 case CODEC_ID_8SVX_FIB:
00083 esc->table = fibonacci;
00084 break;
00085 case CODEC_ID_8SVX_EXP:
00086 esc->table = exponential;
00087 break;
00088 default:
00089 return -1;
00090 }
00091 avctx->sample_fmt = SAMPLE_FMT_S16;
00092 return 0;
00093 }
00094
00095 AVCodec eightsvx_fib_decoder = {
00096 .name = "8svx_fib",
00097 .type = AVMEDIA_TYPE_AUDIO,
00098 .id = CODEC_ID_8SVX_FIB,
00099 .priv_data_size = sizeof (EightSvxContext),
00100 .init = eightsvx_decode_init,
00101 .decode = eightsvx_decode_frame,
00102 .long_name = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
00103 };
00104
00105 AVCodec eightsvx_exp_decoder = {
00106 .name = "8svx_exp",
00107 .type = AVMEDIA_TYPE_AUDIO,
00108 .id = CODEC_ID_8SVX_EXP,
00109 .priv_data_size = sizeof (EightSvxContext),
00110 .init = eightsvx_decode_init,
00111 .decode = eightsvx_decode_frame,
00112 .long_name = NULL_IF_CONFIG_SMALL("8SVX exponential"),
00113 };