FFmpeg
Data Structures | Macros | Functions | Variables
adpcm.c File Reference
#include "config_components.h"
#include "avcodec.h"
#include "get_bits.h"
#include "bytestream.h"
#include "adpcm.h"
#include "adpcm_data.h"
#include "codec_internal.h"
#include "decode.h"
#include "libavutil/attributes.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_, name_, long_name_)
 
#define ADPCM_DECODER_1(id_, name_, long_name_)
 
#define ADPCM_DECODER_2(enabled, codec_id, name, long_name)   ADPCM_DECODER_ ## enabled(codec_id, name, long_name)
 
#define ADPCM_DECODER_3(config, codec_id, name, long_name)   ADPCM_DECODER_2(config, codec_id, name, long_name)
 
#define ADPCM_DECODER(codec, name, 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_escape_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)
 
int16_t ff_adpcm_ima_qt_expand_nibble (ADPCMChannelStatus *c, int nibble)
 
static void decode_adpcm_ima_hvqm2 (AVCodecContext *avctx, int16_t *outbuf, int samples_to_do, int frame_format, GetByteContext *gb)
 
static void decode_adpcm_ima_hvqm4 (AVCodecContext *avctx, int16_t *outbuf, int samples_to_do, int frame_format, GetByteContext *gb)
 
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_circus_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 adpcm_sanyo_expand3 (ADPCMChannelStatus *c, int bits)
 
static int adpcm_sanyo_expand4 (ADPCMChannelStatus *c, int bits)
 
static int adpcm_sanyo_expand5 (ADPCMChannelStatus *c, int bits)
 
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, AVFrame *frame, 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]
 

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

◆ CASE_1

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

Definition at line 72 of file adpcm.c.

◆ CASE_2

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

Definition at line 76 of file adpcm.c.

◆ CASE_3

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

Definition at line 78 of file adpcm.c.

◆ CASE

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

Definition at line 80 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_,
  name_,
  long_name_ 
)

Definition at line 2950 of file adpcm.c.

◆ ADPCM_DECODER_1

#define ADPCM_DECODER_1 (   id_,
  name_,
  long_name_ 
)
Value:
const FFCodec ff_ ## name_ ## _decoder = { \
.p.name = #name_, \
CODEC_LONG_NAME(long_name_), \
.p.type = AVMEDIA_TYPE_AUDIO, \
.p.id = id_, \
.p.capabilities = AV_CODEC_CAP_DR1, \
.priv_data_size = sizeof(ADPCMDecodeContext), \
.flush = adpcm_flush, \
};

Definition at line 2951 of file adpcm.c.

◆ ADPCM_DECODER_2

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

Definition at line 2963 of file adpcm.c.

◆ ADPCM_DECODER_3

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

Definition at line 2965 of file adpcm.c.

◆ ADPCM_DECODER

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

Definition at line 2967 of file adpcm.c.

Function Documentation

◆ adpcm_flush()

static av_cold void adpcm_flush ( AVCodecContext avctx)
static

Definition at line 2908 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 254 of file adpcm.c.

◆ adpcm_agm_expand_nibble()

static int16_t adpcm_agm_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble 
)
inlinestatic

Definition at line 380 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_ima_escape_expand_nibble()

static int16_t adpcm_ima_escape_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble 
)
inlinestatic

Definition at line 424 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 447 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 473 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 496 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 512 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 532 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ ff_adpcm_ima_qt_expand_nibble()

int16_t ff_adpcm_ima_qt_expand_nibble ( ADPCMChannelStatus c,
int  nibble 
)

◆ decode_adpcm_ima_hvqm2()

static void decode_adpcm_ima_hvqm2 ( AVCodecContext avctx,
int16_t *  outbuf,
int  samples_to_do,
int  frame_format,
GetByteContext gb 
)
static

Definition at line 583 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ decode_adpcm_ima_hvqm4()

static void decode_adpcm_ima_hvqm4 ( AVCodecContext avctx,
int16_t *  outbuf,
int  samples_to_do,
int  frame_format,
GetByteContext gb 
)
static

Definition at line 620 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 663 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 682 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 703 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 724 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 744 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 758 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_circus_expand_nibble()

static int16_t adpcm_circus_expand_nibble ( ADPCMChannelStatus c,
uint8_t  nibble 
)
inlinestatic

Definition at line 767 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 788 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 823 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 911 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 969 of file adpcm.c.

Referenced by adpcm_decode_frame(), and adpcm_encode_frame().

◆ adpcm_sanyo_expand3()

static int adpcm_sanyo_expand3 ( ADPCMChannelStatus c,
int  bits 
)
static

Definition at line 986 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_sanyo_expand4()

static int adpcm_sanyo_expand4 ( ADPCMChannelStatus c,
int  bits 
)
static

Definition at line 1029 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_sanyo_expand5()

static int adpcm_sanyo_expand5 ( ADPCMChannelStatus c,
int  bits 
)
static

Definition at line 1088 of file adpcm.c.

Referenced by adpcm_decode_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 1163 of file adpcm.c.

Referenced by adpcm_decode_frame().

◆ adpcm_decode_frame()

static int adpcm_decode_frame ( AVCodecContext avctx,
AVFrame frame,
int *  got_frame_ptr,
AVPacket avpkt 
)
static

Definition at line 1442 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 84 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 92 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 97 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 111 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 121 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 130 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 135 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 140 of file adpcm.c.

◆ adpcm_index_tables

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

Definition at line 145 of file adpcm.c.

Referenced by adpcm_ima_wav_expand_nibble().

◆ mtaf_stepsize

const int16_t mtaf_stepsize[32][16]
static

Definition at line 152 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 219 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 228 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 235 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 239 of file adpcm.c.

Referenced by adpcm_ima_mtf_expand_nibble().

adpcm_index_table5
static const int8_t adpcm_index_table5[32]
Definition: adpcm.c:140
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
FFCodec
Definition: codec_internal.h:127
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
ADPCM_DECODER_3
#define ADPCM_DECODER_3(config, codec_id, name, long_name)
Definition: adpcm.c:2965
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:347
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
adpcm_decode_frame
static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: adpcm.c:1442
ADPCMDecodeContext
Definition: adpcm.c:246
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:579
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
adpcm_index_table3
static const int8_t adpcm_index_table3[8]
Definition: adpcm.c:135
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
ff_adpcm_index_table
const int8_t ff_adpcm_index_table[16]
Definition: adpcm_data.c:30
adpcm_flush
static void adpcm_flush(AVCodecContext *avctx)
Definition: adpcm.c:2908
adpcm_index_table2
static const int8_t adpcm_index_table2[4]
Definition: adpcm.c:130
adpcm_decode_init
static av_cold int adpcm_decode_init(AVCodecContext *avctx)
Definition: adpcm.c:254