adpcm.c File Reference

ADPCM decoders Features and limitations: More...

#include "avcodec.h"
#include "get_bits.h"
#include "put_bits.h"
#include "bytestream.h"
#include "adpcm.h"
#include "adpcm_data.h"
#include "internal.h"
Include dependency graph for adpcm.c:

Go to the source code of this file.

Data Structures

struct  ADPCMDecodeContext
 

Macros

#define DK3_GET_NEXT_NIBBLE()
 
#define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_)
 

Typedefs

typedef struct ADPCMDecodeContext ADPCMDecodeContext
 

Functions

static av_cold int adpcm_decode_init (AVCodecContext *avctx)
 
static short adpcm_ima_expand_nibble (ADPCMChannelStatus *c, char nibble, int shift)
 
static int adpcm_ima_qt_expand_nibble (ADPCMChannelStatus *c, int nibble, int shift)
 
static short adpcm_ms_expand_nibble (ADPCMChannelStatus *c, int nibble)
 
static short adpcm_ima_oki_expand_nibble (ADPCMChannelStatus *c, int nibble)
 
static short adpcm_ct_expand_nibble (ADPCMChannelStatus *c, char nibble)
 
static short adpcm_sbpro_expand_nibble (ADPCMChannelStatus *c, char nibble, int size, int shift)
 
static short adpcm_yamaha_expand_nibble (ADPCMChannelStatus *c, unsigned char nibble)
 
static int xa_decode (AVCodecContext *avctx, int16_t *out0, int16_t *out1, const uint8_t *in, ADPCMChannelStatus *left, ADPCMChannelStatus *right, int channels, int sample_offset)
 
static void adpcm_swf_decode (AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
 
static int get_nb_samples (AVCodecContext *avctx, GetByteContext *gb, int buf_size, int *coded_samples)
 Get the number of samples that will be decoded from the packet. More...
 
static int adpcm_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_4XM, sample_fmts_s16p, adpcm_4xm,"ADPCM 4X Movie")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_AFC, sample_fmts_s16p, adpcm_afc,"ADPCM Nintendo Gamecube AFC")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_CT, sample_fmts_s16, adpcm_ct,"ADPCM Creative Technology")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_EA, sample_fmts_s16, adpcm_ea,"ADPCM Electronic Arts")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa,"ADPCM Electronic Arts Maxis CDROM XA")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_EA_R1, sample_fmts_s16p, adpcm_ea_r1,"ADPCM Electronic Arts R1")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_EA_R2, sample_fmts_s16p, adpcm_ea_r2,"ADPCM Electronic Arts R2")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_EA_R3, sample_fmts_s16p, adpcm_ea_r3,"ADPCM Electronic Arts R3")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas,"ADPCM Electronic Arts XAS")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv,"ADPCM IMA AMV")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc,"ADPCM IMA CRYO APC")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3,"ADPCM IMA Duck DK3")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4,"ADPCM IMA Duck DK4")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_EA_EACS, sample_fmts_s16, adpcm_ima_ea_eacs,"ADPCM IMA Electronic Arts EACS")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_EA_SEAD, sample_fmts_s16, adpcm_ima_ea_sead,"ADPCM IMA Electronic Arts SEAD")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_ISS, sample_fmts_s16, adpcm_ima_iss,"ADPCM IMA Funcom ISS")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_OKI, sample_fmts_s16, adpcm_ima_oki,"ADPCM IMA Dialogic OKI")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt,"ADPCM IMA QuickTime")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg,"ADPCM IMA Loki SDL MJPEG")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav,"ADPCM IMA WAV")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws,"ADPCM IMA Westwood")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_MS, sample_fmts_s16, adpcm_ms,"ADPCM Microsoft")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2,"ADPCM Sound Blaster Pro 2-bit")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3,"ADPCM Sound Blaster Pro 2.6-bit")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4,"ADPCM Sound Blaster Pro 4-bit")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_SWF, sample_fmts_s16, adpcm_swf,"ADPCM Shockwave Flash")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_THP, sample_fmts_s16p, adpcm_thp,"ADPCM Nintendo Gamecube THP")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_XA, sample_fmts_s16p, adpcm_xa,"ADPCM CDROM XA")
 
 ADPCM_DECODER (AV_CODEC_ID_ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha,"ADPCM Yamaha")
 

Variables

static const int xa_adpcm_table [5][2]
 
static const int ea_adpcm_table []
 
static const int swf_index_tables [4][16]
 
static enum AVSampleFormat sample_fmts_s16 []
 
static enum AVSampleFormat sample_fmts_s16p []
 
static enum AVSampleFormat sample_fmts_both []
 

Detailed Description

Macro Definition Documentation

#define ADPCM_DECODER (   id_,
  sample_fmts_,
  name_,
  long_name_ 
)
Value:
AVCodec ff_ ## name_ ## _decoder = { \
.name = #name_, \
.type = AVMEDIA_TYPE_AUDIO, \
.id = id_, \
.priv_data_size = sizeof(ADPCMDecodeContext), \
.capabilities = CODEC_CAP_DR1, \
.long_name = NULL_IF_CONFIG_SMALL(long_name_), \
.sample_fmts = sample_fmts_, \
}
struct ADPCMDecodeContext ADPCMDecodeContext
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold int adpcm_decode_init(AVCodecContext *avctx)
Definition: adpcm.c:92
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: adpcm.c:615
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868

Definition at line 1390 of file adpcm.c.

#define DK3_GET_NEXT_NIBBLE ( )
Value:
if (decode_top_nibble_next) { \
nibble = last_byte >> 4; \
decode_top_nibble_next = 0; \
} else { \
last_byte = bytestream2_get_byteu(&gb); \
nibble = last_byte & 0x0F; \
decode_top_nibble_next = 1; \
}

Referenced by adpcm_decode_frame().

Typedef Documentation

Function Documentation

static short adpcm_ct_expand_nibble ( ADPCMChannelStatus c,
char  nibble 
)
inlinestatic

Definition at line 252 of file adpcm.c.

Referenced by adpcm_decode_frame().

static int adpcm_decode_frame ( AVCodecContext avctx,
void data,
int *  got_frame_ptr,
AVPacket avpkt 
)
static

Definition at line 615 of file adpcm.c.

static av_cold int adpcm_decode_init ( AVCodecContext avctx)
static

Definition at line 92 of file adpcm.c.

ADPCM_DECODER ( AV_CODEC_ID_ADPCM_4XM  ,
sample_fmts_s16p  ,
adpcm_4xm  ,
"ADPCM 4X Movie"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_AFC  ,
sample_fmts_s16p  ,
adpcm_afc  ,
"ADPCM Nintendo Gamecube AFC"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_CT  ,
sample_fmts_s16  ,
adpcm_ct  ,
"ADPCM Creative Technology"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_EA  ,
sample_fmts_s16  ,
adpcm_ea  ,
"ADPCM Electronic Arts"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_EA_MAXIS_XA  ,
sample_fmts_s16  ,
adpcm_ea_maxis_xa  ,
"ADPCM Electronic Arts Maxis CDROM XA"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_EA_R1  ,
sample_fmts_s16p  ,
adpcm_ea_r1  ,
"ADPCM Electronic Arts R1  
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_EA_R2  ,
sample_fmts_s16p  ,
adpcm_ea_r2  ,
"ADPCM Electronic Arts R2  
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_EA_R3  ,
sample_fmts_s16p  ,
adpcm_ea_r3  ,
"ADPCM Electronic Arts R3  
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_EA_XAS  ,
sample_fmts_s16p  ,
adpcm_ea_xas  ,
"ADPCM Electronic Arts XAS"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_AMV  ,
sample_fmts_s16  ,
adpcm_ima_amv  ,
"ADPCM IMA AMV"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_APC  ,
sample_fmts_s16  ,
adpcm_ima_apc  ,
"ADPCM IMA CRYO APC"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_DK3  ,
sample_fmts_s16  ,
adpcm_ima_dk3  ,
"ADPCM IMA Duck DK3"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_DK4  ,
sample_fmts_s16  ,
adpcm_ima_dk4  ,
"ADPCM IMA Duck DK4"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_EA_EACS  ,
sample_fmts_s16  ,
adpcm_ima_ea_eacs  ,
"ADPCM IMA Electronic Arts EACS"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_EA_SEAD  ,
sample_fmts_s16  ,
adpcm_ima_ea_sead  ,
"ADPCM IMA Electronic Arts SEAD"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_ISS  ,
sample_fmts_s16  ,
adpcm_ima_iss  ,
"ADPCM IMA Funcom ISS"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_OKI  ,
sample_fmts_s16  ,
adpcm_ima_oki  ,
"ADPCM IMA Dialogic OKI"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_QT  ,
sample_fmts_s16p  ,
adpcm_ima_qt  ,
"ADPCM IMA QuickTime"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_SMJPEG  ,
sample_fmts_s16  ,
adpcm_ima_smjpeg  ,
"ADPCM IMA Loki SDL MJPEG"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_WAV  ,
sample_fmts_s16p  ,
adpcm_ima_wav  ,
"ADPCM IMA WAV"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_IMA_WS  ,
sample_fmts_both  ,
adpcm_ima_ws  ,
"ADPCM IMA Westwood"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_MS  ,
sample_fmts_s16  ,
adpcm_ms  ,
"ADPCM Microsoft"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_SBPRO_2  ,
sample_fmts_s16  ,
adpcm_sbpro_2  ,
"ADPCM Sound Blaster Pro 2-bit"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_SBPRO_3  ,
sample_fmts_s16  ,
adpcm_sbpro_3  ,
"ADPCM Sound Blaster Pro 2.6-bit"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_SBPRO_4  ,
sample_fmts_s16  ,
adpcm_sbpro_4  ,
"ADPCM Sound Blaster Pro 4-bit"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_SWF  ,
sample_fmts_s16  ,
adpcm_swf  ,
"ADPCM Shockwave Flash"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_THP  ,
sample_fmts_s16p  ,
adpcm_thp  ,
"ADPCM Nintendo Gamecube THP"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_XA  ,
sample_fmts_s16p  ,
adpcm_xa  ,
"ADPCM CDROM XA"   
)
ADPCM_DECODER ( AV_CODEC_ID_ADPCM_YAMAHA  ,
sample_fmts_s16  ,
adpcm_yamaha  ,
"ADPCM Yamaha"   
)
static short adpcm_ima_expand_nibble ( ADPCMChannelStatus c,
char  nibble,
int  shift 
)
inlinestatic

Definition at line 164 of file adpcm.c.

Referenced by adpcm_decode_frame().

static short adpcm_ima_oki_expand_nibble ( ADPCMChannelStatus c,
int  nibble 
)
inlinestatic

Definition at line 231 of file adpcm.c.

Referenced by adpcm_decode_frame().

static int adpcm_ima_qt_expand_nibble ( ADPCMChannelStatus c,
int  nibble,
int  shift 
)
inlinestatic

Definition at line 190 of file adpcm.c.

Referenced by adpcm_decode_frame().

static short adpcm_ms_expand_nibble ( ADPCMChannelStatus c,
int  nibble 
)
inlinestatic

Definition at line 216 of file adpcm.c.

Referenced by adpcm_decode_frame().

static short adpcm_sbpro_expand_nibble ( ADPCMChannelStatus c,
char  nibble,
int  size,
int  shift 
)
inlinestatic

Definition at line 273 of file adpcm.c.

Referenced by adpcm_decode_frame().

static void adpcm_swf_decode ( AVCodecContext avctx,
const uint8_t buf,
int  buf_size,
int16_t *  samples 
)
static

Definition at line 387 of file adpcm.c.

Referenced by adpcm_decode_frame().

static short adpcm_yamaha_expand_nibble ( ADPCMChannelStatus c,
unsigned char  nibble 
)
inlinestatic

Definition at line 293 of file adpcm.c.

Referenced by adpcm_decode_frame().

static int get_nb_samples ( AVCodecContext avctx,
GetByteContext gb,
int  buf_size,
int *  coded_samples 
)
static

Get the number of samples that will be decoded from the packet.

In one case, this is actually the maximum number of samples possible to decode with the given buf_size.

Parameters
[out]coded_samplesset to the number of samples as coded in the packet, or 0 if the codec does not encode the number of samples in each frame.

Definition at line 453 of file adpcm.c.

Referenced by adpcm_decode_frame().

static int xa_decode ( AVCodecContext avctx,
int16_t *  out0,
int16_t *  out1,
const uint8_t in,
ADPCMChannelStatus left,
ADPCMChannelStatus right,
int  channels,
int  sample_offset 
)
static

Definition at line 307 of file adpcm.c.

Referenced by adpcm_decode_frame().

Variable Documentation

const int ea_adpcm_table[]
static
Initial value:
= {
0, 240, 460, 392,
0, 0, -208, -220,
0, 1, 3, 4,
7, 8, 10, 11,
0, -1, -3, -4
}

Definition at line 69 of file adpcm.c.

Referenced by adpcm_decode_frame().

enum AVSampleFormat sample_fmts_both[]
static
Initial value:

Definition at line 1386 of file adpcm.c.

enum AVSampleFormat sample_fmts_s16[]
static
Initial value:

Definition at line 1382 of file adpcm.c.

enum AVSampleFormat sample_fmts_s16p[]
static
Initial value:

Definition at line 1384 of file adpcm.c.

const int swf_index_tables[4][16]
static
Initial value:
= {
{ -1, 2 },
{ -1, -1, 2, 4 },
{ -1, -1, -1, -1, 2, 4, 6, 8 },
{ -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
}

Definition at line 78 of file adpcm.c.

Referenced by adpcm_swf_decode().

const int xa_adpcm_table[5][2]
static
Initial value:
= {
{ 0, 0 },
{ 60, 0 },
{ 115, -52 },
{ 98, -55 },
{ 122, -60 }
}

Definition at line 61 of file adpcm.c.

Referenced by xa_decode().