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"

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, 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]
 
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 68 of file adpcm.c.

◆ CASE_1

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

Definition at line 69 of file adpcm.c.

◆ CASE_2

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

Definition at line 73 of file adpcm.c.

◆ CASE_3

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

Definition at line 75 of file adpcm.c.

◆ CASE

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

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

◆ ADPCM_DECODER_1

#define ADPCM_DECODER_1 (   id_,
  sample_fmts_,
  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, \
.p.sample_fmts = sample_fmts_, \
.priv_data_size = sizeof(ADPCMDecodeContext), \
.flush = adpcm_flush, \
};

Definition at line 2330 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 2343 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 2345 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 2347 of file adpcm.c.

Function Documentation

◆ adpcm_flush()

static void adpcm_flush ( AVCodecContext avctx)
static

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

◆ adpcm_agm_expand_nibble()

static int16_t adpcm_agm_expand_nibble ( ADPCMChannelStatus c,
int8_t  nibble 
)
inlinestatic

Definition at line 356 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 400 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 426 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 449 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 465 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 485 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 508 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 534 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 553 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 574 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 595 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 615 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 629 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 638 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 673 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 761 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 819 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 847 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 1069 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 81 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 89 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 94 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 108 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 118 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 127 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 132 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 137 of file adpcm.c.

◆ adpcm_index_tables

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

Definition at line 142 of file adpcm.c.

Referenced by adpcm_ima_wav_expand_nibble().

◆ mtaf_stepsize

const int16_t mtaf_stepsize[32][16]
static

Definition at line 149 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 216 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 225 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 232 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 236 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 2321 of file adpcm.c.

◆ sample_fmts_s16p

enum AVSampleFormat sample_fmts_s16p[]
static
Initial value:

Definition at line 2323 of file adpcm.c.

◆ sample_fmts_both

enum AVSampleFormat sample_fmts_both[]
static
Initial value:

Definition at line 2325 of file adpcm.c.

adpcm_index_table5
static const int8_t adpcm_index_table5[32]
Definition: adpcm.c:137
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:947
FFCodec
Definition: codec_internal.h:127
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
adpcm_flush
static void adpcm_flush(AVCodecContext *avctx)
Definition: adpcm.c:2279
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:386
adpcm_decode_frame
static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: adpcm.c:1069
ADPCMDecodeContext
Definition: adpcm.c:243
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
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
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
adpcm_index_table3
static const int8_t adpcm_index_table3[8]
Definition: adpcm.c:132
ADPCM_DECODER_3
#define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name)
Definition: adpcm.c:2345
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
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:127
adpcm_decode_init
static av_cold int adpcm_decode_init(AVCodecContext *avctx)
Definition: adpcm.c:251