FFmpeg
aacenc.h
Go to the documentation of this file.
1 /*
2  * AAC encoder
3  * Copyright (C) 2008 Konstantin Shishkov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVCODEC_AACENC_H
23 #define AVCODEC_AACENC_H
24 
26 #include "libavutil/float_dsp.h"
27 #include "libavutil/mem_internal.h"
28 
29 #include "avcodec.h"
30 #include "put_bits.h"
31 
32 #include "aac.h"
33 #include "audio_frame_queue.h"
34 #include "psymodel.h"
35 
36 #include "lpc.h"
37 
38 typedef enum AACCoder {
42 
44 }AACCoder;
45 
46 typedef struct AACEncOptions {
47  int coder;
48  int pns;
49  int tns;
50  int ltp;
51  int pce;
52  int pred;
53  int mid_side;
56 
57 struct AACEncContext;
58 
59 typedef struct AACCoefficientsEncoder {
61  SingleChannelElement *sce, const float lambda);
63  int win, int group_len, const float lambda);
64  void (*quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size,
65  int scale_idx, int cb, const float lambda, int rtz);
67  void (*encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
79  void (*search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
84 
86 
88  float rd;
89  float energy;
90  int bits;
91  char cb;
92  char rtz;
93  uint16_t generation;
95 
96 typedef struct AACPCEInfo {
98  int num_ele[4]; ///< front, side, back, lfe
99  int pairing[3][8]; ///< front, side, back
100  int index[4][8]; ///< front, side, back, lfe
101  uint8_t config_map[16]; ///< configs the encoder's channel specific settings
102  uint8_t reorder_map[16]; ///< maps channels from lavc to aac order
103 } AACPCEInfo;
104 
105 /**
106  * AAC encoder context
107  */
108 typedef struct AACEncContext {
110  AACEncOptions options; ///< encoding options
112  FFTContext mdct1024; ///< long (1024 samples) frame transform context
113  FFTContext mdct128; ///< short (128 samples) frame transform context
115  AACPCEInfo pce; ///< PCE data, if needed
116  float *planar_samples[16]; ///< saved preprocessed input
117 
118  int profile; ///< copied from avctx
119  int needs_pce; ///< flag for non-standard layout
120  LPCContext lpc; ///< used by TNS
121  int samplerate_index; ///< MPEG-4 samplerate index
122  int channels; ///< channel count
123  const uint8_t *reorder_map; ///< lavc to aac reorder map
124  const uint8_t *chan_map; ///< channel configuration map
125 
126  ChannelElement *cpe; ///< channel elements
130  int cur_channel; ///< current channel for coder context
132  float lambda;
133  int last_frame_pb_count; ///< number of bits for the previous frame
134  float lambda_sum; ///< sum(lambda), for Qvg reporting
135  int lambda_count; ///< count(lambda), for Qvg reporting
136  enum RawDataBlockType cur_type; ///< channel group type cur_channel belongs to
137 
139  DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients
140  DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients
141 
143  AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]; ///< memoization area for quantize_band_cost
144 
145  void (*abs_pow34)(float *out, const float *in, const int size);
146  void (*quant_bands)(int *out, const float *in, const float *scaled,
147  int size, int is_signed, int maxval, const float Q34,
148  const float rounding);
149 
150  struct {
151  float *samples;
152  } buffer;
153 } AACEncContext;
154 
158 
159 
160 #endif /* AVCODEC_AACENC_H */
AACQuantizeBandCostCacheEntry
Definition: aacenc.h:87
AACCoefficientsEncoder::apply_tns_filt
void(* apply_tns_filt)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:72
AACEncOptions::ltp
int ltp
Definition: aacenc.h:50
AACCoefficientsEncoder::encode_window_bands_info
void(* encode_window_bands_info)(struct AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Definition: aacenc.h:62
AACEncContext::planar_samples
float * planar_samples[16]
saved preprocessed input
Definition: aacenc.h:116
AACCoefficientsEncoder::search_for_quantizers
void(* search_for_quantizers)(AVCodecContext *avctx, struct AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aacenc.h:60
AACQuantizeBandCostCacheEntry::cb
char cb
Definition: aacenc.h:91
AACEncContext::needs_pce
int needs_pce
flag for non-standard layout
Definition: aacenc.h:119
mem_internal.h
AACEncOptions::coder
int coder
Definition: aacenc.h:47
out
FILE * out
Definition: movenc.c:54
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:239
AACEncContext::av_class
AVClass * av_class
Definition: aacenc.h:109
AACEncContext::abs_pow34
void(* abs_pow34)(float *out, const float *in, const int size)
Definition: aacenc.h:145
AACCoefficientsEncoder::search_for_pns
void(* search_for_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
Definition: aacenc.h:76
AACCoefficientsEncoder::search_for_ms
void(* search_for_ms)(struct AACEncContext *s, ChannelElement *cpe)
Definition: aacenc.h:80
AACEncContext::samplerate_index
int samplerate_index
MPEG-4 samplerate index.
Definition: aacenc.h:121
AACCoefficientsEncoder::search_for_tns
void(* search_for_tns)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:78
AAC_CODER_NB
@ AAC_CODER_NB
Definition: aacenc.h:43
lpc.h
AACQuantizeBandCostCacheEntry::generation
uint16_t generation
Definition: aacenc.h:93
AACCoefficientsEncoder::update_ltp
void(* update_ltp)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:73
AACEncContext::chan_map
const uint8_t * chan_map
channel configuration map
Definition: aacenc.h:124
AAC_CODER_FAST
@ AAC_CODER_FAST
Definition: aacenc.h:41
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
LPCContext
Definition: lpc.h:53
ff_quantize_band_cost_cache_init
void ff_quantize_band_cost_cache_init(struct AACEncContext *s)
Definition: aacenc.c:400
AACEncContext::psy
FFPsyContext psy
Definition: aacenc.h:127
audio_frame_queue.h
AACEncContext::options
AACEncOptions options
encoding options
Definition: aacenc.h:110
AACEncOptions::pce
int pce
Definition: aacenc.h:51
AACPCEInfo::num_ele
int num_ele[4]
front, side, back, lfe
Definition: aacenc.h:98
AACEncContext::fdsp
AVFloatDSPContext * fdsp
Definition: aacenc.h:114
AACEncContext::lambda_count
int lambda_count
count(lambda), for Qvg reporting
Definition: aacenc.h:135
AACEncContext::lambda_sum
float lambda_sum
sum(lambda), for Qvg reporting
Definition: aacenc.h:134
ff_aac_coders
const AACCoefficientsEncoder ff_aac_coders[]
Definition: aaccoder.c:1119
s
#define s(width, name)
Definition: cbs_vp9.c:256
AACEncContext::mdct1024
FFTContext mdct1024
long (1024 samples) frame transform context
Definition: aacenc.h:112
AudioFrameQueue
Definition: audio_frame_queue.h:32
AACEncContext::reorder_map
const uint8_t * reorder_map
lavc to aac reorder map
Definition: aacenc.h:123
AACCoefficientsEncoder::adjust_common_ltp
void(* adjust_common_ltp)(struct AACEncContext *s, ChannelElement *cpe)
Definition: aacenc.h:70
AACPCEInfo::reorder_map
uint8_t reorder_map[16]
maps channels from lavc to aac order
Definition: aacenc.h:102
AACQuantizeBandCostCacheEntry::energy
float energy
Definition: aacenc.h:89
AACCoefficientsEncoder::encode_ltp_info
void(* encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window)
Definition: aacenc.h:67
PutBitContext
Definition: put_bits.h:50
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
AACEncContext::cur_type
enum RawDataBlockType cur_type
channel group type cur_channel belongs to
Definition: aacenc.h:136
AACCoefficientsEncoder::search_for_pred
void(* search_for_pred)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:82
aac.h
AACEncContext::random_state
int random_state
Definition: aacenc.h:131
AACCoefficientsEncoder::ltp_insert_new_frame
void(* ltp_insert_new_frame)(struct AACEncContext *s)
Definition: aacenc.h:74
AACEncContext::quantize_band_cost_cache_generation
uint16_t quantize_band_cost_cache_generation
Definition: aacenc.h:142
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AACCoefficientsEncoder::adjust_common_pred
void(* adjust_common_pred)(struct AACEncContext *s, ChannelElement *cpe)
Definition: aacenc.h:69
AACEncContext::qcoefs
int qcoefs[96]
quantized coefficients
Definition: aacenc.h:139
float_dsp.h
AACCoefficientsEncoder::apply_main_pred
void(* apply_main_pred)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:71
AACEncOptions::tns
int tns
Definition: aacenc.h:49
AACPCEInfo
Definition: aacenc.h:96
AACEncContext::samples
float * samples
Definition: aacenc.h:151
AAC_CODER_ANMR
@ AAC_CODER_ANMR
Definition: aacenc.h:39
AACCoefficientsEncoder::set_special_band_scalefactors
void(* set_special_band_scalefactors)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:75
AACEncContext::channels
int channels
channel count
Definition: aacenc.h:122
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:293
size
int size
Definition: twinvq_data.h:10344
AACCoefficientsEncoder::quantize_and_encode_band
void(* quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size, int scale_idx, int cb, const float lambda, int rtz)
Definition: aacenc.h:64
AACEncContext::buffer
struct AACEncContext::@7 buffer
FFPsyPreprocessContext
Definition: psymodel.c:93
AVFloatDSPContext
Definition: float_dsp.h:24
AACEncContext::quant_bands
void(* quant_bands)(int *out, const float *in, const float *scaled, int size, int is_signed, int maxval, const float Q34, const float rounding)
Definition: aacenc.h:146
AAC_CODER_TWOLOOP
@ AAC_CODER_TWOLOOP
Definition: aacenc.h:40
ff_aac_coder_init_mips
void ff_aac_coder_init_mips(AACEncContext *c)
Definition: aaccoder_mips.c:2484
AACCoefficientsEncoder::mark_pns
void(* mark_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
Definition: aacenc.h:77
AACPCEInfo::index
int index[4][8]
front, side, back, lfe
Definition: aacenc.h:100
AACEncContext::cur_channel
int cur_channel
current channel for coder context
Definition: aacenc.h:130
AACCoder
AACCoder
Definition: aacenc.h:38
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:116
AACPCEInfo::config_map
uint8_t config_map[16]
configs the encoder's channel specific settings
Definition: aacenc.h:101
FFTContext
Definition: fft.h:76
AACEncOptions::intensity_stereo
int intensity_stereo
Definition: aacenc.h:54
AACCoefficientsEncoder::encode_main_pred
void(* encode_main_pred)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:68
RawDataBlockType
RawDataBlockType
Definition: aac.h:57
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aac.h:249
AACEncContext::mdct128
FFTContext mdct128
short (128 samples) frame transform context
Definition: aacenc.h:113
AACQuantizeBandCostCacheEntry::rd
float rd
Definition: aacenc.h:88
AACCoefficientsEncoder::search_for_is
void(* search_for_is)(struct AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe)
Definition: aacenc.h:81
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aac.h:276
AACPCEInfo::pairing
int pairing[3][8]
front, side, back
Definition: aacenc.h:99
AACQuantizeBandCostCacheEntry::bits
int bits
Definition: aacenc.h:90
ff_aac_dsp_init_x86
void ff_aac_dsp_init_x86(AACEncContext *s)
Definition: aacencdsp_init.c:35
AACEncContext::quantize_band_cost_cache
AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]
memoization area for quantize_band_cost
Definition: aacenc.h:143
AACEncContext::psypp
struct FFPsyPreprocessContext * psypp
Definition: aacenc.h:128
AACCoefficientsEncoder
Definition: aacenc.h:59
AACEncOptions::pns
int pns
Definition: aacenc.h:48
avcodec.h
AACEncOptions::mid_side
int mid_side
Definition: aacenc.h:53
AACEncContext::profile
int profile
copied from avctx
Definition: aacenc.h:118
AACEncContext::lpc
LPCContext lpc
used by TNS
Definition: aacenc.h:120
AACEncContext::afq
AudioFrameQueue afq
Definition: aacenc.h:138
AACEncContext::pce
AACPCEInfo pce
PCE data, if needed.
Definition: aacenc.h:115
AACEncContext
AAC encoder context.
Definition: aacenc.h:108
AACQuantizeBandCostCacheEntry::rtz
char rtz
Definition: aacenc.h:92
AACCoefficientsEncoder::encode_tns_info
void(* encode_tns_info)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:66
AACEncContext::last_frame_pb_count
int last_frame_pb_count
number of bits for the previous frame
Definition: aacenc.h:133
AVCodecContext
main external API structure.
Definition: avcodec.h:398
AACCoefficientsEncoder::search_for_ltp
void(* search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window)
Definition: aacenc.h:79
AACEncContext::scoefs
float scoefs[1024]
scaled coefficients
Definition: aacenc.h:140
channel_layout.h
AACEncContext::coder
const AACCoefficientsEncoder * coder
Definition: aacenc.h:129
AACEncContext::pb
PutBitContext pb
Definition: aacenc.h:111
AACEncOptions::pred
int pred
Definition: aacenc.h:52
AACEncContext::lambda
float lambda
Definition: aacenc.h:132
put_bits.h
FFPsyContext
context used by psychoacoustic model
Definition: psymodel.h:89
AACEncOptions
Definition: aacenc.h:46
psymodel.h
AACEncContext::cpe
ChannelElement * cpe
channel elements
Definition: aacenc.h:126
AACPCEInfo::layout
AVChannelLayout layout
Definition: aacenc.h:97