FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
dcaenc.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/ffmath.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "dca.h"
#include "dcaadpcm.h"
#include "dcamath.h"
#include "dca_core.h"
#include "dcadata.h"
#include "dcaenc.h"
#include "internal.h"
#include "mathops.h"
#include "put_bits.h"

Go to the source code of this file.

Data Structures

struct  CompressionOptions
 
struct  DCAEncContext
 
struct  cplx32
 

Macros

#define MAX_CHANNELS   6
 
#define DCA_MAX_FRAME_SIZE   16384
 
#define DCA_HEADER_SIZE   13
 
#define DCA_LFE_SAMPLES   8
 
#define DCAENC_SUBBANDS   32
 
#define SUBFRAMES   1
 
#define SUBSUBFRAMES   2
 
#define SUBBAND_SAMPLES   (SUBFRAMES * SUBSUBFRAMES * 8)
 
#define AUBANDS   25
 
#define USED_1ABITS   1
 
#define USED_26ABITS   4
 
#define DCAENC_FLAGS   AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 

Typedefs

typedef void(* walk_band_t )(DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
 

Functions

static double hom (double f)
 
static double gammafilter (int i, double f)
 
static int subband_bufer_alloc (DCAEncContext *c)
 
static void subband_bufer_free (DCAEncContext *c)
 
static int encode_init (AVCodecContext *avctx)
 
static av_cold int encode_close (AVCodecContext *avctx)
 
static int32_t cos_t (int x)
 
static int32_t sin_t (int x)
 
static int32_t half32 (int32_t a)
 
static void subband_transform (DCAEncContext *c, const int32_t *input)
 
static void lfe_downsample (DCAEncContext *c, const int32_t *input)
 
static void fft (const int32_t in[2 *256], cplx32 out[256])
 
static int32_t get_cb (int32_t in)
 
static int32_t add_cb (int32_t a, int32_t b)
 
static void adjust_jnd (int samplerate_index, const int32_t in[512], int32_t out_cb[256])
 
static void walk_band_low (DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
 
static void walk_band_high (DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
 
static void update_band_masking (DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
 
static void calc_masking (DCAEncContext *c, const int32_t *input)
 
static int32_t find_peak (const int32_t *in, int len)
 
static void find_peaks (DCAEncContext *c)
 
static void adpcm_analysis (DCAEncContext *c)
 
static int32_t get_step_size (const DCAEncContext *c, int ch, int band)
 
static int calc_one_scale (int32_t peak_cb, int abits, softfloat *quant)
 
static void quantize_adpcm_subband (DCAEncContext *c, int ch, int band)
 
static void quantize_adpcm (DCAEncContext *c)
 
static void quantize_pcm (DCAEncContext *c)
 
static void accumulate_huff_bit_consumption (int abits, int32_t *quantized, uint32_t *result)
 
static uint32_t set_best_code (uint32_t vlc_bits[DCA_CODE_BOOKS][7], uint32_t clc_bits[DCA_CODE_BOOKS], int32_t res[DCA_CODE_BOOKS])
 
static uint32_t set_best_abits_code (int abits[DCAENC_SUBBANDS], int bands, int32_t *res)
 
static int init_quantization_noise (DCAEncContext *c, int noise, int forbid_zero)
 
static void assign_bits (DCAEncContext *c)
 
static void shift_history (DCAEncContext *c, const int32_t *input)
 
static void fill_in_adpcm_bufer (DCAEncContext *c)
 
static void calc_lfe_scales (DCAEncContext *c)
 
static void put_frame_header (DCAEncContext *c)
 
static void put_primary_audio_header (DCAEncContext *c)
 
static void put_subframe_samples (DCAEncContext *c, int ss, int band, int ch)
 
static void put_subframe (DCAEncContext *c, int subframe)
 
static int encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 

Variables

static int32_t cos_table [2048]
 
static int32_t band_interpolation [2][512]
 
static int32_t band_spectrum [2][8]
 
static int32_t auf [9][AUBANDS][256]
 
static int32_t cb_to_add [256]
 
static int32_t cb_to_level [2048]
 
static int32_t lfe_fir_64i [512]
 
static const int snr_fudge = 128
 
static const AVOption options []
 
static const AVClass dcaenc_class
 
static const AVCodecDefault defaults []
 
AVCodec ff_dca_encoder
 

Macro Definition Documentation

#define MAX_CHANNELS   6

Definition at line 40 of file dcaenc.c.

Referenced by encode_init(), init_quantization_noise(), and subband_bufer_alloc().

#define DCA_MAX_FRAME_SIZE   16384

Definition at line 41 of file dcaenc.c.

Referenced by encode_init().

#define DCA_HEADER_SIZE   13

Definition at line 42 of file dcaenc.c.

#define DCA_LFE_SAMPLES   8

Definition at line 43 of file dcaenc.c.

Referenced by find_peaks(), lfe_downsample(), and put_subframe().

#define DCAENC_SUBBANDS   32

Definition at line 45 of file dcaenc.c.

Referenced by encode_init(), put_primary_audio_header(), put_subframe(), and subband_bufer_alloc().

#define SUBFRAMES   1
#define SUBSUBFRAMES   2

Definition at line 47 of file dcaenc.c.

Referenced by calc_masking(), and put_subframe().

#define SUBBAND_SAMPLES   (SUBFRAMES * SUBSUBFRAMES * 8)
#define AUBANDS   25

Definition at line 49 of file dcaenc.c.

Referenced by adjust_jnd(), and encode_init().

#define USED_1ABITS   1

Definition at line 658 of file dcaenc.c.

Referenced by assign_bits(), and init_quantization_noise().

#define USED_26ABITS   4

Definition at line 659 of file dcaenc.c.

Referenced by assign_bits(), and init_quantization_noise().

Definition at line 1261 of file dcaenc.c.

Typedef Documentation

typedef void(* walk_band_t)(DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)

Definition at line 528 of file dcaenc.c.

Function Documentation

static double hom ( double  f)
static

Definition at line 106 of file dcaenc.c.

Referenced by encode_init().

static double gammafilter ( int  i,
double  f 
)
static

Definition at line 116 of file dcaenc.c.

Referenced by encode_init().

static int subband_bufer_alloc ( DCAEncContext c)
static

Definition at line 125 of file dcaenc.c.

Referenced by encode_init().

static void subband_bufer_free ( DCAEncContext c)
static

Definition at line 146 of file dcaenc.c.

Referenced by encode_close().

static int encode_init ( AVCodecContext avctx)
static

Definition at line 152 of file dcaenc.c.

static av_cold int encode_close ( AVCodecContext avctx)
static

Definition at line 296 of file dcaenc.c.

static int32_t cos_t ( int  x)
inlinestatic

Definition at line 306 of file dcaenc.c.

Referenced by fft(), sin_t(), and subband_transform().

static int32_t sin_t ( int  x)
inlinestatic

Definition at line 311 of file dcaenc.c.

Referenced by fft().

static int32_t half32 ( int32_t  a)
inlinestatic

Definition at line 316 of file dcaenc.c.

Referenced by fft().

static void subband_transform ( DCAEncContext c,
const int32_t input 
)
static

Definition at line 321 of file dcaenc.c.

Referenced by encode_frame().

static void lfe_downsample ( DCAEncContext c,
const int32_t input 
)
static

Definition at line 371 of file dcaenc.c.

Referenced by encode_frame().

static void fft ( const int32_t  in[2 *256],
cplx32  out[256] 
)
static

Definition at line 406 of file dcaenc.c.

Referenced by adjust_jnd(), headphone_fast_convolute(), and sofalizer_fast_convolute().

static int32_t get_cb ( int32_t  in)
static

Definition at line 473 of file dcaenc.c.

Referenced by adjust_jnd(), and find_peak().

static int32_t add_cb ( int32_t  a,
int32_t  b 
)
static

Definition at line 487 of file dcaenc.c.

Referenced by adjust_jnd().

static void adjust_jnd ( int  samplerate_index,
const int32_t  in[512],
int32_t  out_cb[256] 
)
static

Definition at line 497 of file dcaenc.c.

Referenced by calc_masking().

static void walk_band_low ( DCAEncContext c,
int  band,
int  channel,
walk_band_t  walk,
int32_t arg 
)
static

Definition at line 532 of file dcaenc.c.

Referenced by calc_masking().

static void walk_band_high ( DCAEncContext c,
int  band,
int  channel,
walk_band_t  walk,
int32_t arg 
)
static

Definition at line 547 of file dcaenc.c.

Referenced by calc_masking().

static void update_band_masking ( DCAEncContext c,
int  band1,
int  band2,
int  f,
int32_t  spectrum1,
int32_t  spectrum2,
int  channel,
int32_t arg 
)
static

Definition at line 562 of file dcaenc.c.

Referenced by calc_masking().

static void calc_masking ( DCAEncContext c,
const int32_t input 
)
static

Definition at line 572 of file dcaenc.c.

Referenced by encode_frame().

static int32_t find_peak ( const int32_t in,
int  len 
)
inlinestatic

Definition at line 607 of file dcaenc.c.

Referenced by adpcm_analysis(), and find_peaks().

static void find_peaks ( DCAEncContext c)
static

Definition at line 619 of file dcaenc.c.

Referenced by encode_frame().

static void adpcm_analysis ( DCAEncContext c)
static

Definition at line 634 of file dcaenc.c.

Referenced by encode_frame().

static int32_t get_step_size ( const DCAEncContext c,
int  ch,
int  band 
)
inlinestatic

Definition at line 661 of file dcaenc.c.

Referenced by fill_in_adpcm_bufer(), and quantize_adpcm_subband().

static int calc_one_scale ( int32_t  peak_cb,
int  abits,
softfloat quant 
)
static

Definition at line 673 of file dcaenc.c.

Referenced by calc_lfe_scales(), init_quantization_noise(), and quantize_adpcm_subband().

static void quantize_adpcm_subband ( DCAEncContext c,
int  ch,
int  band 
)
inlinestatic

Definition at line 705 of file dcaenc.c.

Referenced by quantize_adpcm().

static void quantize_adpcm ( DCAEncContext c)
static

Definition at line 720 of file dcaenc.c.

Referenced by init_quantization_noise().

static void quantize_pcm ( DCAEncContext c)
static

Definition at line 730 of file dcaenc.c.

Referenced by init_quantization_noise().

static void accumulate_huff_bit_consumption ( int  abits,
int32_t quantized,
uint32_t *  result 
)
static

Definition at line 741 of file dcaenc.c.

Referenced by init_quantization_noise().

static uint32_t set_best_code ( uint32_t  vlc_bits[DCA_CODE_BOOKS][7],
uint32_t  clc_bits[DCA_CODE_BOOKS],
int32_t  res[DCA_CODE_BOOKS] 
)
static

Definition at line 748 of file dcaenc.c.

Referenced by init_quantization_noise().

static uint32_t set_best_abits_code ( int  abits[DCAENC_SUBBANDS],
int  bands,
int32_t res 
)
static

Definition at line 787 of file dcaenc.c.

Referenced by init_quantization_noise().

static int init_quantization_noise ( DCAEncContext c,
int  noise,
int  forbid_zero 
)
static

Definition at line 814 of file dcaenc.c.

Referenced by assign_bits().

static void assign_bits ( DCAEncContext c)
static

Definition at line 888 of file dcaenc.c.

Referenced by encode_frame().

static void shift_history ( DCAEncContext c,
const int32_t input 
)
static

Definition at line 930 of file dcaenc.c.

Referenced by encode_frame().

static void fill_in_adpcm_bufer ( DCAEncContext c)
static

Definition at line 942 of file dcaenc.c.

Referenced by encode_frame().

static void calc_lfe_scales ( DCAEncContext c)
static

Definition at line 977 of file dcaenc.c.

Referenced by encode_frame().

static void put_frame_header ( DCAEncContext c)
static

Definition at line 983 of file dcaenc.c.

Referenced by encode_frame().

static void put_primary_audio_header ( DCAEncContext c)
static

Definition at line 1066 of file dcaenc.c.

Referenced by encode_frame().

static void put_subframe_samples ( DCAEncContext c,
int  ss,
int  band,
int  ch 
)
static

Definition at line 1113 of file dcaenc.c.

Referenced by put_subframe().

static void put_subframe ( DCAEncContext c,
int  subframe 
)
static

Definition at line 1146 of file dcaenc.c.

Referenced by encode_frame().

static int encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int got_packet_ptr 
)
static

Definition at line 1217 of file dcaenc.c.

Variable Documentation

int32_t cos_table[2048]
static

Definition at line 97 of file dcaenc.c.

Referenced by cos_t(), and encode_init().

int32_t band_interpolation[2][512]
static

Definition at line 98 of file dcaenc.c.

Referenced by encode_init().

int32_t band_spectrum[2][8]
static

Definition at line 99 of file dcaenc.c.

Referenced by encode_init().

int32_t auf[9][AUBANDS][256]
static

Definition at line 100 of file dcaenc.c.

Referenced by adjust_jnd(), and encode_init().

int32_t cb_to_add[256]
static

Definition at line 101 of file dcaenc.c.

Referenced by add_cb(), and encode_init().

int32_t cb_to_level[2048]
static

Definition at line 102 of file dcaenc.c.

Referenced by calc_one_scale(), encode_init(), get_cb(), and quantize_adpcm_subband().

int32_t lfe_fir_64i[512]
static

Definition at line 103 of file dcaenc.c.

Referenced by encode_init(), and lfe_downsample().

const int snr_fudge = 128
static

Definition at line 657 of file dcaenc.c.

Referenced by assign_bits().

const AVOption options[]
static
Initial value:
= {
{ "dca_adpcm", "Use ADPCM encoding", 0x42, AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DCAENC_FLAGS },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define DCAENC_FLAGS
Definition: dcaenc.c:1261

Definition at line 1263 of file dcaenc.c.

const AVClass dcaenc_class
static
Initial value:
= {
.class_name = "DCA (DTS Coherent Acoustics)",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:86
av_default_item_name
static const AVOption options[]
Definition: dcaenc.c:1263

Definition at line 1268 of file dcaenc.c.

const AVCodecDefault defaults[]
static
Initial value:
= {
{ "b", "1411200" },
{ NULL },
}
#define NULL
Definition: coverity.c:32

Definition at line 1275 of file dcaenc.c.

AVCodec ff_dca_encoder
Initial value:
= {
.name = "dca",
.long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
.priv_data_size = sizeof(DCAEncContext),
.close = encode_close,
.encode2 = encode_frame,
.capabilities = AV_CODEC_CAP_EXPERIMENTAL,
.supported_samplerates = sample_rates,
.channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
0 },
.defaults = defaults,
.priv_class = &dcaenc_class,
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:1057
#define AV_CH_LAYOUT_STEREO
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: dcaenc.c:1217
#define AV_CH_LAYOUT_5POINT0
static av_cold int encode_close(AVCodecContext *avctx)
Definition: dcaenc.c:296
signed 32 bits
Definition: samplefmt.h:62
#define AV_CH_LAYOUT_5POINT1
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
#define AV_CH_LAYOUT_2_2
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static int encode_init(AVCodecContext *avctx)
Definition: dcaenc.c:152
sample_rates
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
static const AVCodecDefault defaults[]
Definition: dcaenc.c:1275
#define AV_CH_LAYOUT_MONO
static const AVClass dcaenc_class
Definition: dcaenc.c:1268

Definition at line 1280 of file dcaenc.c.