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