FFmpeg
Loading...
Searching...
No Matches
adpcm.c File Reference

ADPCM decoders Features and limitations: More...

#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, ...)
 
#define CASE_3(config, codec_id, ...)
 
#define CASE(codec, ...)
 
#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)
 
#define ADPCM_DECODER_3(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_rhetorex_expand_nibble (ADPCMChannelStatus *c, uint16_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.
 
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 const int16_t rhetorex_step [128]
 
static const int16_t rhetorex_index [8]
 

Detailed Description

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;
enum AVCodecID codec_id

Definition at line 72 of file adpcm.c.

◆ CASE_2

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

Definition at line 76 of file adpcm.c.

◆ CASE_3

#define CASE_3 ( config,
codec_id,
... )
Value:
CASE_2(config, codec_id, __VA_ARGS__)
#define CASE_2(enabled, codec_id,...)
Definition adpcm.c:76

Definition at line 78 of file adpcm.c.

◆ CASE

#define CASE ( codec,
... )
Value:
CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
#define CASE_3(config, codec_id,...)
Definition adpcm.c:78

Definition at line 80 of file adpcm.c.

Referenced by adpcm_decode_frame(), and get_nb_samples().

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

Referenced by adpcm_decode_frame().

◆ ADPCM_DECODER_0

#define ADPCM_DECODER_0 ( id_,
name_,
long_name_ )

Definition at line 3012 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, \
};
static void adpcm_flush(AVCodecContext *avctx)
Definition adpcm.c:2970
static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition adpcm.c:1497
static av_cold int adpcm_decode_init(AVCodecContext *avctx)
Definition adpcm.c:277
#define FF_CODEC_DECODE_CB(func)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201

Definition at line 3013 of file adpcm.c.

◆ ADPCM_DECODER_2

#define ADPCM_DECODER_2 ( enabled,
codec_id,
name,
long_name )
Value:
ADPCM_DECODER_ ## enabled(codec_id, name, long_name)
const char * name
Definition qsvenc.c:142

Definition at line 3025 of file adpcm.c.

◆ ADPCM_DECODER_3

#define ADPCM_DECODER_3 ( config,
codec_id,
name,
long_name )
Value:
ADPCM_DECODER_2(config, codec_id, name, long_name)
#define ADPCM_DECODER_2(enabled, codec_id, name, long_name)
Definition adpcm.c:3025

Definition at line 3027 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)
#define ADPCM_DECODER_3(config, codec_id, name, long_name)
Definition adpcm.c:3027

Definition at line 3029 of file adpcm.c.

Function Documentation

◆ adpcm_flush()

static av_cold void adpcm_flush ( AVCodecContext * avctx)
static

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

◆ adpcm_agm_expand_nibble()

static int16_t adpcm_agm_expand_nibble ( ADPCMChannelStatus * c,
int8_t nibble )
inlinestatic

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

◆ adpcm_ima_expand_nibble()

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

Definition at line 471 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 497 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 520 of file adpcm.c.

◆ adpcm_ima_cunning_expand_nibble()

static int16_t adpcm_ima_cunning_expand_nibble ( ADPCMChannelStatus * c,
int8_t nibble )
inlinestatic

Definition at line 536 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 556 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 607 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 644 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 687 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 706 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 727 of file adpcm.c.

◆ adpcm_rhetorex_expand_nibble()

static int16_t adpcm_rhetorex_expand_nibble ( ADPCMChannelStatus * c,
uint16_t nibble )
inlinestatic

Definition at line 748 of file adpcm.c.

◆ adpcm_sbpro_expand_nibble()

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

Definition at line 776 of file adpcm.c.

◆ adpcm_yamaha_expand_nibble()

static int16_t adpcm_yamaha_expand_nibble ( ADPCMChannelStatus * c,
uint8_t nibble )
inlinestatic

Definition at line 796 of file adpcm.c.

◆ adpcm_mtaf_expand_nibble()

static int16_t adpcm_mtaf_expand_nibble ( ADPCMChannelStatus * c,
uint8_t nibble )
inlinestatic

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

◆ adpcm_zork_expand_nibble()

static int16_t adpcm_zork_expand_nibble ( ADPCMChannelStatus * c,
uint8_t nibble )
inlinestatic

Definition at line 840 of file adpcm.c.

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

◆ adpcm_swf_decode()

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

Definition at line 963 of file adpcm.c.

◆ ff_adpcm_argo_expand_nibble()

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

Definition at line 1021 of file adpcm.c.

Referenced by adpcm_encode_frame().

◆ adpcm_sanyo_expand3()

static int adpcm_sanyo_expand3 ( ADPCMChannelStatus * c,
int bits )
static

Definition at line 1038 of file adpcm.c.

◆ adpcm_sanyo_expand4()

static int adpcm_sanyo_expand4 ( ADPCMChannelStatus * c,
int bits )
static

Definition at line 1081 of file adpcm.c.

◆ adpcm_sanyo_expand5()

static int adpcm_sanyo_expand5 ( ADPCMChannelStatus * c,
int bits )
static

Definition at line 1140 of file adpcm.c.

◆ 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 1215 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 1497 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 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.

◆ 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.

◆ 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:
= {
}
static const int8_t adpcm_index_table3[8]
Definition adpcm.c:135
static const int8_t adpcm_index_table2[4]
Definition adpcm.c:130
static const int8_t adpcm_index_table5[32]
Definition adpcm.c:140
const int8_t ff_adpcm_index_table[16]
Definition adpcm_data.c:30

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().

◆ rhetorex_step

const int16_t rhetorex_step[128]
static
Initial value:
= {
40, 130, 232, 350, 493, 673, 927, 1382,
60, 195, 348, 526, 740, 1010, 1391, 2074,
85, 277, 494, 745, 1048, 1431, 1971, 2938,
121, 391, 697, 1052, 1480, 2021, 2782, 4148,
176, 570, 1017, 1535, 2158, 2947, 4058, 6050,
257, 831, 1482, 2236, 3145, 4295, 5913, 8815,
373, 1206, 2151, 3245, 4564, 6232, 8579, 12791,
534, 1728, 3082, 4649, 6538, 8928, 12290, 18323,
782, 2527, 4507, 6798, 9560, 13055, 17971, 26793,
1115, 3603, 6426, 9692, 13631, 18614, 25623, 32767,
1620, 5233, 9334, 14078, 19799, 27036, 32767, 32767,
2361, 7630, 13608, 20526, 28866, 32767, 32767, 32767,
3447, 11136, 19860, 29955, 32767, 32767, 32767, 32767,
4865, 15717, 28031, 32767, 32767, 32767, 32767, 32767,
6888, 22255, 32767, 32767, 32767, 32767, 32767, 32767,
-10336, 32144, 5984,-24288, 4752, 24112, 24688,-26336,
}

Definition at line 244 of file adpcm.c.

Referenced by adpcm_rhetorex_expand_nibble().

◆ rhetorex_index

const int16_t rhetorex_index[8]
static
Initial value:
= {
-83, -55, -27, 163, 374, 677, 1864, 3408,
}

Definition at line 263 of file adpcm.c.

Referenced by adpcm_rhetorex_expand_nibble().