adxdec.c File Reference

#include "avcodec.h"
#include "adx.h"

Go to the source code of this file.

Functions

static void adx_decode (short *out, const unsigned char *in, PREV *prev)
static void adx_decode_stereo (short *out, const unsigned char *in, PREV *prev)
static int adx_decode_header (AVCodecContext *avctx, const unsigned char *buf, size_t bufsize)
static int adx_decode_frame (AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf0, int buf_size)

Variables

AVCodec adpcm_adx_decoder


Function Documentation

static void adx_decode ( short *  out,
const unsigned char *  in,
PREV prev 
) [static]

Definition at line 35 of file adxdec.c.

References av_clip_int16(), AV_RB16, BASEVOL, s0, PREV::s1, s1, PREV::s2, s2, SCALE1, and SCALE2.

Referenced by adx_decode_frame(), and adx_decode_stereo().

00036 {
00037     int scale = AV_RB16(in);
00038     int i;
00039     int s0,s1,s2,d;
00040 
00041 //    printf("%x ",scale);
00042 
00043     in+=2;
00044     s1 = prev->s1;
00045     s2 = prev->s2;
00046     for(i=0;i<16;i++) {
00047         d = in[i];
00048         // d>>=4; if (d&8) d-=16;
00049         d = ((signed char)d >> 4);
00050         s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14;
00051         s2 = s1;
00052         s1 = av_clip_int16(s0);
00053         *out++=s1;
00054 
00055         d = in[i];
00056         //d&=15; if (d&8) d-=16;
00057         d = ((signed char)(d<<4) >> 4);
00058         s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14;
00059         s2 = s1;
00060         s1 = av_clip_int16(s0);
00061         *out++=s1;
00062     }
00063     prev->s1 = s1;
00064     prev->s2 = s2;
00065 
00066 }

static int adx_decode_frame ( AVCodecContext avctx,
void *  data,
int *  data_size,
const uint8_t *  buf0,
int  buf_size 
) [static]

Definition at line 97 of file adxdec.c.

References adx_decode(), adx_decode_header(), adx_decode_stereo(), c, AVCodecContext::channels, AVCodecContext::priv_data, and samples.

00100 {
00101     ADXContext *c = avctx->priv_data;
00102     short *samples = data;
00103     const uint8_t *buf = buf0;
00104     int rest = buf_size;
00105 
00106     if (!c->header_parsed) {
00107         int hdrsize = adx_decode_header(avctx,buf,rest);
00108         if (hdrsize==0) return -1;
00109         c->header_parsed = 1;
00110         buf  += hdrsize;
00111         rest -= hdrsize;
00112     }
00113 
00114     /* 18 bytes of data are expanded into 32*2 bytes of audio,
00115        so guard against buffer overflows */
00116     if(rest/18 > *data_size/64)
00117         rest = (*data_size/64) * 18;
00118 
00119     if (c->in_temp) {
00120         int copysize = 18*avctx->channels - c->in_temp;
00121         memcpy(c->dec_temp+c->in_temp,buf,copysize);
00122         rest -= copysize;
00123         buf  += copysize;
00124         if (avctx->channels==1) {
00125             adx_decode(samples,c->dec_temp,c->prev);
00126             samples += 32;
00127         } else {
00128             adx_decode_stereo(samples,c->dec_temp,c->prev);
00129             samples += 32*2;
00130         }
00131     }
00132     //
00133     if (avctx->channels==1) {
00134         while(rest>=18) {
00135             adx_decode(samples,buf,c->prev);
00136             rest-=18;
00137             buf+=18;
00138             samples+=32;
00139         }
00140     } else {
00141         while(rest>=18*2) {
00142             adx_decode_stereo(samples,buf,c->prev);
00143             rest-=18*2;
00144             buf+=18*2;
00145             samples+=32*2;
00146         }
00147     }
00148     //
00149     c->in_temp = rest;
00150     if (rest) {
00151         memcpy(c->dec_temp,buf,rest);
00152         buf+=rest;
00153     }
00154     *data_size = (uint8_t*)samples - (uint8_t*)data;
00155 //    printf("%d:%d ",buf-buf0,*data_size); fflush(stdout);
00156     return buf-buf0;
00157 }

static int adx_decode_header ( AVCodecContext avctx,
const unsigned char *  buf,
size_t  bufsize 
) [static]

Definition at line 82 of file adxdec.c.

References AV_RB32, AVCodecContext::bit_rate, AVCodecContext::channels, offset, and AVCodecContext::sample_rate.

Referenced by adx_decode_frame().

00083 {
00084     int offset;
00085 
00086     if (buf[0]!=0x80) return 0;
00087     offset = (AV_RB32(buf)^0x80000000)+4;
00088     if (bufsize<offset || memcmp(buf+offset-6,"(c)CRI",6)) return 0;
00089 
00090     avctx->channels    = buf[7];
00091     avctx->sample_rate = AV_RB32(buf+8);
00092     avctx->bit_rate    = avctx->sample_rate*avctx->channels*18*8/32;
00093 
00094     return offset;
00095 }

static void adx_decode_stereo ( short *  out,
const unsigned char *  in,
PREV prev 
) [static]

Definition at line 68 of file adxdec.c.

References adx_decode().

Referenced by adx_decode_frame().

00069 {
00070     short tmp[32*2];
00071     int i;
00072 
00073     adx_decode(tmp   ,in   ,prev);
00074     adx_decode(tmp+32,in+18,prev+1);
00075     for(i=0;i<32;i++) {
00076         out[i*2]   = tmp[i];
00077         out[i*2+1] = tmp[i+32];
00078     }
00079 }


Variable Documentation

AVCodec adpcm_adx_decoder

Initial value:

 {
    "adpcm_adx",
    CODEC_TYPE_AUDIO,
    CODEC_ID_ADPCM_ADX,
    sizeof(ADXContext),
    NULL,
    NULL,
    NULL,
    adx_decode_frame,
    .long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX"),
}

Definition at line 159 of file adxdec.c.


Generated on Thu Aug 28 16:44:30 2008 for libextractor by  doxygen 1.5.1