• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/8svx.c

Go to the documentation of this file.
00001 /*
00002  * 8SVX audio decoder
00003  * Copyright (C) 2008 Jaikrishnan Menon
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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                                  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 
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     avctx->sample_fmt = SAMPLE_FMT_S16;
00090     return 0;
00091 }
00092 
00093 AVCodec eightsvx_fib_decoder = {
00094   .name           = "8svx_fib",
00095   .type           = CODEC_TYPE_AUDIO,
00096   .id             = CODEC_ID_8SVX_FIB,
00097   .priv_data_size = sizeof (EightSvxContext),
00098   .init           = eightsvx_decode_init,
00099   .decode         = eightsvx_decode_frame,
00100   .long_name      = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
00101 };
00102 
00103 AVCodec eightsvx_exp_decoder = {
00104   .name           = "8svx_exp",
00105   .type           = CODEC_TYPE_AUDIO,
00106   .id             = CODEC_ID_8SVX_EXP,
00107   .priv_data_size = sizeof (EightSvxContext),
00108   .init           = eightsvx_decode_init,
00109   .decode         = eightsvx_decode_frame,
00110   .long_name      = NULL_IF_CONFIG_SMALL("8SVX exponential"),
00111 };

Generated on Tue Nov 4 2014 12:59:21 for ffmpeg by  doxygen 1.7.1