FFmpeg
Data Structures | Macros | Functions | Variables
adpcm.c File Reference
#include "avcodec.h"
#include "get_bits.h"
#include "bytestream.h"
#include "adpcm.h"
#include "adpcm_data.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  ADPCMDecodeContext
 

Macros

#define CASE_0(codec_id, ...)
 
#define CASE_1(codec_id, ...)
 
#define CASE_2(enabled, codec_id, ...)   CASE_ ## enabled(codec_id, __VA_ARGS__)
 
#define CASE_3(config, codec_id, ...)   CASE_2(config, codec_id, __VA_ARGS__)
 
#define CASE(codec, ...)   CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
 
#define DK3_GET_NEXT_NIBBLE()
 
#define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
 
#define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_)
 
#define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name)   ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
 
#define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name)   ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
 
#define ADPCM_DECODER(codec, name, sample_fmts, long_name)
 

Functions

static void adpcm_flush (AVCodecContext *avctx)
 
static av_cold int adpcm_decode_init (AVCodecContext *avctx)
 
static int16_t adpcm_agm_expand_nibble (ADPCMChannelStatus *c, int8_t nibble)
 
static int16_t adpcm_ima_expand_nibble (ADPCMChannelStatus *c, int8_t nibble, int shift)
 
static int16_t adpcm_ima_alp_expand_nibble (ADPCMChannelStatus *c, int8_t nibble, int shift)
 
static int16_t adpcm_ima_mtf_expand_nibble (ADPCMChannelStatus *c, int nibble)
 
static int16_t adpcm_ima_cunning_expand_nibble (ADPCMChannelStatus *c, int8_t nibble)
 
static int16_t adpcm_ima_wav_expand_nibble (ADPCMChannelStatus *c, GetBitContext *gb, int bps)
 
static int adpcm_ima_qt_expand_nibble (ADPCMChannelStatus *c, int nibble)
 
static int16_t adpcm_ms_expand_nibble (ADPCMChannelStatus *c, int nibble)
 
static int16_t adpcm_ima_oki_expand_nibble (ADPCMChannelStatus *c, int nibble)
 
static int16_t adpcm_ct_expand_nibble (ADPCMChannelStatus *c, int8_t nibble)
 
static int16_t adpcm_sbpro_expand_nibble (ADPCMChannelStatus *c, int8_t nibble, int size, int shift)
 
static int16_t adpcm_yamaha_expand_nibble (ADPCMChannelStatus *c, uint8_t nibble)
 
static int16_t adpcm_mtaf_expand_nibble (ADPCMChannelStatus *c, uint8_t nibble)
 
static int16_t adpcm_zork_expand_nibble (ADPCMChannelStatus *c, uint8_t 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)
 
int16_t ff_adpcm_argo_expand_nibble (ADPCMChannelStatus *cs, int nibble, int shift, int flag)
 
static int get_nb_samples (AVCodecContext *avctx, GetByteContext *gb, int buf_size, int *coded_samples, int *approx_nb_samples)
 Get the number of samples (per channel) that will be decoded from the packet. More...
 
static int adpcm_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 

Variables

static const int8_t xa_adpcm_table [5][2]
 
static const int16_t afc_coeffs [2][16]
 
static const int16_t ea_adpcm_table []
 
static const int8_t ima_cunning_index_table [9]
 
static const int16_t ima_cunning_step_table [61]
 
static const int8_t adpcm_index_table2 [4]
 
static const int8_t adpcm_index_table3 [8]
 
static const int8_t adpcm_index_table5 [32]
 
static const int8_t *const adpcm_index_tables [4]
 
static const int16_t mtaf_stepsize [32][16]
 
static const int16_t oki_step_table [49]
 
static const int8_t swf_index_tables [4][16]
 
static const int8_t zork_index_table [8]
 
static const int8_t mtf_index_table [16]
 
static enum AVSampleFormat sample_fmts_s16 []
 
static enum AVSampleFormat sample_fmts_s16p []
 
static enum AVSampleFormat sample_fmts_both []
 

Detailed Description

ADPCM decoders Features and limitations:

Reference documents: http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead] http://www.geocities.com/SiliconValley/8682/aud3.txt [dead] http://openquicktime.sourceforge.net/ XAnim sources (xa_codec.c) http://xanim.polter.net/ http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead] SoX source code http://sox.sourceforge.net/

CD-ROM XA: http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead] vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead] readstr http://www.geocities.co.jp/Playtown/2004/

Definition in file adpcm.c.

Macro Definition Documentation

◆ CASE_0

#define CASE_0 (   codec_id,
  ... 
)

Definition at line 64 of file adpcm.c.

◆ CASE_1

#define CASE_1 (   codec_id,
  ... 
)
Value:
case codec_id: \
{ __VA_ARGS__ } \
break;

Definition at line 65 of file adpcm.c.

◆ CASE_2

#define CASE_2 (   enabled,
  codec_id,
  ... 
)    CASE_ ## enabled(codec_id, __VA_ARGS__)

Definition at line 69 of file adpcm.c.

◆ CASE_3

#define CASE_3 (   config,
  codec_id,
  ... 
)    CASE_2(config, codec_id, __VA_ARGS__)

Definition at line 71 of file adpcm.c.

◆ CASE

#define CASE (   codec,
  ... 
)    CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)

Definition at line 73 of file adpcm.c.

◆ DK3_GET_NEXT_NIBBLE

#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; \
}

◆ ADPCM_DECODER_0

#define ADPCM_DECODER_0 (   id_,
  sample_fmts_,
  name_,
  long_name_ 
)

Definition at line 2278 of file adpcm.c.

◆ ADPCM_DECODER_1

#define ADPCM_DECODER_1 (   id_,
  sample_fmts_,
  name_,
  long_name_ 
)
Value:
const AVCodec ff_ ## name_ ## _decoder = { \
.name = #name_, \
.long_name = NULL_IF_CONFIG_SMALL(long_name_), \
.type = AVMEDIA_TYPE_AUDIO, \
.id = id_, \
.priv_data_size = sizeof(ADPCMDecodeContext), \
.capabilities = AV_CODEC_CAP_DR1, \
.sample_fmts = sample_fmts_, \
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
};

Definition at line 2279 of file adpcm.c.

◆ ADPCM_DECODER_2

#define ADPCM_DECODER_2 (   enabled,
  codec_id,
  name,
  sample_fmts,
  long_name 
)    ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)

Definition at line 2293 of file adpcm.c.

◆ ADPCM_DECODER_3

#define ADPCM_DECODER_3 (   config,
  codec_id,
  name,
  sample_fmts,
  long_name 
)    ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)

Definition at line 2295 of file adpcm.c.

◆ ADPCM_DECODER

#define ADPCM_DECODER (   codec,
  name,
  sample_fmts,
  long_name 
)
Value:
ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
name, sample_fmts, long_name)

Definition at line 2297 of file adpcm.c.

Function Documentation

◆ adpcm_flush()

static void adpcm_flush ( AVCodecContext avctx)
static

Definition at line 2228 of file adpcm.c.

Referenced by adpcm_decode_init().

◆ adpcm_decode_init()

static av_cold int adpcm_decode_init ( AVCodecContext avctx)
static

Definition at line 247 of file adpcm.c.

◆ adpcm_agm_expand_nibble()

static int16_t adpcm_agm_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble 
)
inlinestatic

Definition at line 348 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ima_expand_nibble()

static int16_t adpcm_ima_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble,
int  shift 
)
inlinestatic

Definition at line 392 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ima_alp_expand_nibble()

static int16_t adpcm_ima_alp_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble,
int  shift 
)
inlinestatic

Definition at line 418 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ima_mtf_expand_nibble()

static int16_t adpcm_ima_mtf_expand_nibble ( ADPCMChannelStatus c,
int  nibble 
)
inlinestatic

Definition at line 441 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ima_cunning_expand_nibble()

static int16_t adpcm_ima_cunning_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble 
)
inlinestatic

Definition at line 457 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ima_wav_expand_nibble()

static int16_t adpcm_ima_wav_expand_nibble ( ADPCMChannelStatus c,
GetBitContext gb,
int  bps 
)
inlinestatic

Definition at line 477 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ima_qt_expand_nibble()

static int adpcm_ima_qt_expand_nibble ( ADPCMChannelStatus c,
int  nibble 
)
inlinestatic

Definition at line 500 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ms_expand_nibble()

static int16_t adpcm_ms_expand_nibble ( ADPCMChannelStatus c,
int  nibble 
)
inlinestatic

Definition at line 526 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ima_oki_expand_nibble()

static int16_t adpcm_ima_oki_expand_nibble ( ADPCMChannelStatus c,
int  nibble 
)
inlinestatic

Definition at line 545 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ct_expand_nibble()

static int16_t adpcm_ct_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble 
)
inlinestatic

Definition at line 566 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_sbpro_expand_nibble()

static int16_t adpcm_sbpro_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble,
int  size,
int  shift 
)
inlinestatic

Definition at line 587 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_yamaha_expand_nibble()

static int16_t adpcm_yamaha_expand_nibble ( ADPCMChannelStatus c,
uint8_t  nibble 
)
inlinestatic

Definition at line 607 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_mtaf_expand_nibble()

static int16_t adpcm_mtaf_expand_nibble ( ADPCMChannelStatus c,
uint8_t  nibble 
)
inlinestatic

Definition at line 621 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_zork_expand_nibble()

static int16_t adpcm_zork_expand_nibble ( ADPCMChannelStatus c,
uint8_t  nibble 
)
inlinestatic

Definition at line 630 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ xa_decode()

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 665 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_swf_decode()

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

Definition at line 753 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ ff_adpcm_argo_expand_nibble()

int16_t ff_adpcm_argo_expand_nibble ( ADPCMChannelStatus cs,
int  nibble,
int  shift,
int  flag 
)

Definition at line 810 of file adpcm.c.

Referenced by adpcm_decode_frame(), and adpcm_encode_frame().

◆ get_nb_samples()

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

Get the number of samples (per channel) 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.
[out]approx_nb_samplesset to non-zero if the number of samples returned is an approximation.

Definition at line 838 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_decode_frame()

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

Definition at line 1057 of file adpcm.c.

Variable Documentation

◆ xa_adpcm_table

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

Definition at line 77 of file adpcm.c.

Referenced by adpcm_decode_frame(), and xa_decode().

◆ afc_coeffs

const int16_t afc_coeffs[2][16]
static
Initial value:
= {
{ 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, -1024, -1024, -2048 },
{ 0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048, -1024, 1024, 0, 0 }
}

Definition at line 85 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ ea_adpcm_table

const int16_t 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 90 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ ima_cunning_index_table

const int8_t ima_cunning_index_table[9]
static
Initial value:
= {
-1, -1, -1, -1, 1, 2, 3, 4, -1
}

Definition at line 104 of file adpcm.c.

Referenced by adpcm_ima_cunning_expand_nibble().

◆ ima_cunning_step_table

const int16_t ima_cunning_step_table[61]
static
Initial value:
= {
1, 1, 1, 1, 2, 2, 3, 3, 4, 5,
6, 7, 8, 10, 12, 14, 16, 20, 24, 28,
32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
192, 224, 256, 320, 384, 448, 512, 640, 768, 896,
1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584, 4096, 5120,
6144, 7168, 8192, 10240, 12288, 14336, 16384, 20480, 24576, 28672, 0
}

Definition at line 114 of file adpcm.c.

Referenced by adpcm_ima_cunning_expand_nibble().

◆ adpcm_index_table2

const int8_t adpcm_index_table2[4]
static
Initial value:
= {
-1, 2,
-1, 2,
}

Definition at line 123 of file adpcm.c.

◆ adpcm_index_table3

const int8_t adpcm_index_table3[8]
static
Initial value:
= {
-1, -1, 1, 2,
-1, -1, 1, 2,
}

Definition at line 128 of file adpcm.c.

◆ adpcm_index_table5

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

Definition at line 133 of file adpcm.c.

◆ adpcm_index_tables

const int8_t* const adpcm_index_tables[4]
static
Initial value:

Definition at line 138 of file adpcm.c.

Referenced by adpcm_ima_wav_expand_nibble().

◆ mtaf_stepsize

const int16_t mtaf_stepsize[32][16]
static

Definition at line 145 of file adpcm.c.

Referenced by adpcm_mtaf_expand_nibble().

◆ oki_step_table

const int16_t oki_step_table[49]
static
Initial value:
= {
16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
}

Definition at line 212 of file adpcm.c.

Referenced by adpcm_ima_oki_expand_nibble().

◆ swf_index_tables

const int8_t 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 221 of file adpcm.c.

Referenced by adpcm_swf_decode().

◆ zork_index_table

const int8_t zork_index_table[8]
static
Initial value:
= {
-1, -1, -1, 1, 4, 7, 10, 12,
}

Definition at line 228 of file adpcm.c.

Referenced by adpcm_zork_expand_nibble().

◆ mtf_index_table

const int8_t mtf_index_table[16]
static
Initial value:
= {
8, 6, 4, 2, -1, -1, -1, -1,
-1, -1, -1, -1, 2, 4, 6, 8,
}

Definition at line 232 of file adpcm.c.

Referenced by adpcm_ima_mtf_expand_nibble().

◆ sample_fmts_s16

enum AVSampleFormat sample_fmts_s16[]
static
Initial value:

Definition at line 2270 of file adpcm.c.

◆ sample_fmts_s16p

enum AVSampleFormat sample_fmts_s16p[]
static
Initial value:

Definition at line 2272 of file adpcm.c.

◆ sample_fmts_both

enum AVSampleFormat sample_fmts_both[]
static
Initial value:

Definition at line 2274 of file adpcm.c.

AVCodec
AVCodec.
Definition: codec.h:202
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:42
adpcm_index_table5
static const int8_t adpcm_index_table5[32]
Definition: adpcm.c:133
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
init
static int init
Definition: av_tx.c:47
adpcm_flush
static void adpcm_flush(AVCodecContext *avctx)
Definition: adpcm.c:2228
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
flush
static void flush(AVCodecContext *avctx)
Definition: aacdec_template.c:593
ADPCMDecodeContext
Definition: adpcm.c:239
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
adpcm_index_table3
static const int8_t adpcm_index_table3[8]
Definition: adpcm.c:128
ADPCM_DECODER_3
#define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name)
Definition: adpcm.c:2295
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:209
ff_adpcm_index_table
const int8_t ff_adpcm_index_table[16]
Definition: adpcm_data.c:30
adpcm_index_table2
static const int8_t adpcm_index_table2[4]
Definition: adpcm.c:123
adpcm_decode_init
static av_cold int adpcm_decode_init(AVCodecContext *avctx)
Definition: adpcm.c:247
adpcm_decode_frame
static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: adpcm.c:1057