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 
25 #include <stdint.h>
26 
28 #include "libavutil/float_dsp.h"
29 #include "libavutil/mem_internal.h"
30 #include "libavutil/tx.h"
31 
32 #include "avcodec.h"
33 #include "put_bits.h"
34 
35 #include "aac.h"
36 #include "aacencdsp.h"
37 #include "audio_frame_queue.h"
38 #include "psymodel.h"
39 
40 #include "lpc.h"
41 
42 #define CLIP_AVOIDANCE_FACTOR 0.95f
43 
44 typedef enum AACCoder {
48 
50 }AACCoder;
51 
52 /**
53  * Predictor State
54  */
55 typedef struct PredictorState {
56  float cor0;
57  float cor1;
58  float var0;
59  float var1;
60  float r0;
61  float r1;
62  float k1;
63  float x_est;
65 
66 typedef struct AACEncOptions {
67  int coder;
68  int pns;
69  int tns;
70  int pce;
71  int mid_side;
73  int nmr_speed; ///< NMR coder speed level: 0 = slowest/best, higher is faster
75 
76 /**
77  * Individual Channel Stream
78  */
79 typedef struct IndividualChannelStream {
80  uint8_t max_sfb; ///< number of scalefactor bands per group
82  uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sine window.
83  uint8_t group_len[8];
84  const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window
85  const uint8_t *swb_sizes; ///< table of scalefactor band sizes for a particular window
86  int num_swb; ///< number of scalefactor window bands
87  int num_windows;
88  int tns_max_bands;
89  uint8_t window_clipping[8]; ///< set if a certain window is near clipping
90  float clip_avoidance_factor; ///< set if any window is near clipping to the necessary atennuation factor to avoid it
92 
93 /**
94  * Temporal Noise Shaping
95  */
96 typedef struct TemporalNoiseShaping {
97  int present;
98  int n_filt[8];
99  int length[8][4];
100  int direction[8][4];
101  int order[8][4];
103  float coef[8][4][TNS_MAX_ORDER];
105 
106 /**
107  * Single Channel Element - used for both SCE and LFE elements.
108  */
109 typedef struct SingleChannelElement {
113  enum BandType band_type[128]; ///< band types
114  enum BandType band_alt[128]; ///< alternative band type
115  int sf_idx[128]; ///< scalefactor indices
116  uint8_t zeroes[128]; ///< band is not coded
117  uint8_t can_pns[128]; ///< band is allowed to PNS (informative)
118  float is_ener[128]; ///< Intensity stereo pos
119  float pns_ener[128]; ///< Noise energy values
120  DECLARE_ALIGNED(32, float, pcoeffs)[1024]; ///< coefficients for IMDCT, pristine
121  DECLARE_ALIGNED(32, float, coeffs)[1024]; ///< coefficients for IMDCT, maybe processed
122  DECLARE_ALIGNED(32, float, ret_buf)[2048]; ///< PCM output buffer
125 
126 /**
127  * channel element - generic struct for SCE/CPE/CCE/LFE
128  */
129 typedef struct ChannelElement {
130  // CPE specific
131  int common_window; ///< Set if channels share a common 'IndividualChannelStream' in bitstream.
132  int ms_mode; ///< Signals mid/side stereo flags coding mode
133  uint8_t is_mode; ///< Set if any bands have been encoded using intensity stereo
134  uint8_t ms_mask[128]; ///< Set if mid/side stereo is used for each scalefactor window band
135  uint8_t is_mask[128]; ///< Set if intensity stereo is used
136  // shared
139 
140 struct AACEncContext;
141 
142 typedef struct AACCoefficientsEncoder {
144  SingleChannelElement *sce, const float lambda);
146  int win, int group_len, const float lambda);
147  void (*quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size,
148  int scale_idx, int cb, const float lambda, int rtz);
158 
160 
162  float rd;
163  float energy;
164  int bits;
165  char cb;
166  char rtz;
167  uint16_t generation;
169 
170 /** per-band scalefactor candidates above the finest codeable sf (NMR coder) */
171 #define NMR_NCAND 96
172 
173 /**
174  * NMR coder per-band candidate cost curves (~96 KiB) and rate-control carry-over
175  */
176 /**
177  * Per-channel trellis state for one solve. A channel pair (CPE) is solved
178  * jointly against a pooled budget: the first channel's setup is stored here
179  * and committed together with the second channel under one shared lambda.
180  */
181 typedef struct NMRSlot {
183  int si; ///< curve-bank index (nd/nb slot)
184  int cur_ch; ///< encoder channel index (psy/cache context)
185  int nbnd; ///< coded-band count, 0 = nothing codeable
186  int is8; ///< EIGHT_SHORT frame
187  int bidx[128]; ///< sce band index (w*16+g)
188  int bw[128], bg[128], bst[128]; ///< window group, swb, coef start
189  int blo[128]; ///< finest candidate scalefactor
190  int bnc[128]; ///< number of candidates
191  int chosen[128];
192  int act[128]; ///< active (non-PNS) band coding order
193  int nact;
194  int minsf[128];
195  float maxvals[128];
196  float thr[128]; ///< allocation-law effective threshold
197  float thr_real[128]; ///< real masking threshold (PNS gates)
198  float tnsg[128]; ///< TNS synthesis gain per band for THIS solve (1 = uncovered), M/S-aware (pair max)
199  float pener[128]; ///< band energy (PNS noise target)
200  float pspread[128]; ///< band tonality spread (1 = noise)
201  uint8_t is_pns[128]; ///< band coded as noise
202 } NMRSlot;
203 
204 typedef struct AACNMRCurves {
205  float nd[2][128][NMR_NCAND]; ///< dist / threshold per candidate, per pair slot
206  int nb[2][128][NMR_NCAND]; ///< spectral bits per candidate, per pair slot
207  NMRSlot slot[2]; ///< pair slots (solo solves use slot 0)
208  int pair; ///< current element is a CPE: pool the pair budget
209  int rc_gl; ///< rc_global latched at frame start: the corridor bootstrap must not flip the CPE defer logic between channels of one frame
210  int rc_fill_seeded; ///< reservoir seeded full at stream start (decoder buffer starts full)
211  int pending; ///< slot 0 holds a deferred first channel
212  uint8_t zero_prev[16][128]; ///< per-channel band zero state last frame (zeroing hysteresis)
213  int zero_nw[16]; ///< window count zero_prev was recorded on
214  float thr_prev[16][64]; ///< per-channel long-grid law thresholds of the previous frame
215  uint8_t thr_prev_ok[16]; ///< thr_prev holds a long-frame measurement
216  uint8_t pns_prev[16][128]; ///< per-channel PNS state last frame (decision hysteresis)
217  uint8_t pns_run_on[16][128]; ///< consecutive frames the band has WANTED PNS
218  uint8_t pns_run_off[16][128]; ///< consecutive frames the band has wanted OUT
219  uint8_t smode[16][128]; ///< per-pair previous stereo mode per band, two banks per pair (long/short grid): each grid's memory persists across the other's frames instead of being wiped at window switches
220  uint8_t smode_band[8][128]; ///< last decided stereo mode per band index (side-band tests)
221  uint8_t tns8_prev[16]; ///< short-TNS accepted last frame (per channel): Schmitt state for the accept bar
222  uint8_t sinit[16]; ///< stereo state bank initialized
223  int smode_nw[8]; ///< window count the stored modes were decided on
224  float sema_es[16][128]; ///< smoothed side energy per band (stereo-decision EMA)
225  float sema_em[16][128]; ///< smoothed mid energy per band
226  float sema_img[16][128]; ///< smoothed I/S image-error/mask ratio per band
227  float lam[16]; ///< per-channel operating lambda of the previous frame, 0 = none yet
228  int counted[16]; ///< per-channel bits the trellis accounted for in the last solve
229  float side_ema; ///< running estimate of real-minus-counted bits per frame
230  int side_inited; ///< side_ema holds a measurement
231 
232  int64_t rc_frame_num; ///< frame the reservoir was last advanced for
233  float lam_rc; ///< global-lambda rate control: operating lambda, 0 until bootstrapped
234  int rc_fill; ///< virtual bit reservoir fill, + = bits saved vs nominal
235  int frames_since_short; ///< long-block frames since the last short run (the "gap"): large = isolated transient
236  int prev_was_short; ///< previous frame was a short block (for run-start detection)
237  float run_burst; ///< transient bit-burst factor, set at run start and held across the short run
238  float lam_slew; ///< final operating lambda of the previous RC frame (slew-limiter state)
239  float nd_ema; ///< smoothed achieved distortion/real-mask over long-frame coded bands (1 = at threshold; >>1 flags psy-unreliable noise-class content)
240  float press; ///< rate-pressure ramp [0,1]: lambda EMA against anchors that scale up when nd_ema flags noise-class content (psy masks unreliable there, lambda reads inflated)
241  float lam_short_ema; ///< smoothed operating lambda of short frames
242  float lam_long_ema; ///< smoothed operating lambda of long frames
243  float lam_floor; ///< lambda min-tracker (snaps down, +2%/frame up): sustained-strain floor; bursty spikes at a comfortable rate cannot raise it
244 } AACNMRCurves;
245 
246 typedef struct AACPCEInfo {
248  uint8_t num_ele[4]; ///< front, side, back, lfe
249  uint8_t pairing[3][8]; ///< front, side, back
250  uint8_t index[4][8]; ///< front, side, back, lfe
251  uint8_t config_map[16]; ///< configs the encoder's channel specific settings
252  uint8_t reorder_map[16]; ///< maps channels from lavc to aac order
253 } AACPCEInfo;
254 
255 /**
256  * AAC encoder context
257  */
258 typedef struct AACEncContext {
260  AACEncOptions options; ///< encoding options
262  AVTXContext *mdct1024; ///< long (1024 samples) frame transform context
264  AVTXContext *mdct128; ///< short (128 samples) frame transform context
267  AACPCEInfo pce; ///< PCE data, if needed
268  float *planar_samples[16]; ///< saved preprocessed input
269 
270  int profile; ///< copied from avctx
271  int needs_pce; ///< flag for non-standard layout
272  LPCContext lpc; ///< used by TNS
273  int samplerate_index; ///< MPEG-4 samplerate index
274  int channels; ///< channel count
275  int bandwidth; ///< coding bandwidth in Hz, fixed at init; the psy model and the coders' band cutoff agree on it
276  const uint8_t *reorder_map; ///< lavc to aac reorder map
277  const uint8_t *chan_map; ///< channel configuration map
278 
279  ChannelElement *cpe; ///< channel elements
282  int cur_channel; ///< current channel for coder context
284  float lambda;
285  int last_frame_pb_count; ///< number of bits for the previous frame
286  float lambda_sum; ///< sum(lambda), for Qvg reporting
287  int lambda_count; ///< count(lambda), for Qvg reporting
288  /* tool-usage stats, reported at close: per-coded-band for PNS (channel bands),
289  * per-coded-pair-band for M/S and I/S (CPE bands) */
290  uint64_t stat_ch_bands, stat_pns; ///< coded channel-bands, of which PNS
291  uint64_t stat_cpe_bands, stat_ms, stat_is; ///< coded CPE pair-bands, of which M/S, I/S
292  uint64_t stat_chans, stat_short; ///< coded channels, of which short-block (transient)
293  uint64_t stat_tns_long, stat_tns_short; ///< TNS-active channels among long / short blocks
294  enum RawDataBlockType cur_type; ///< channel group type cur_channel belongs to
295 
297  DECLARE_ALIGNED(32, int, qcoefs)[96]; ///< quantized coefficients
298  DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients
299 
301  AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]; ///< memoization area for quantize_band_cost
302 
304  AACNMRCurves *nmr; ///< NMR coder scratch (NULL unless coder == nmr)
305 
306  struct {
307  float *samples;
308  } buffer;
309 } AACEncContext;
310 
312 
313 
314 #endif /* AVCODEC_AACENC_H */
AACQuantizeBandCostCacheEntry
Definition: aacenc.h:161
NMRSlot::is8
int is8
EIGHT_SHORT frame.
Definition: aacenc.h:186
AACNMRCurves::counted
int counted[16]
per-channel bits the trellis accounted for in the last solve
Definition: aacenc.h:228
NMRSlot::chosen
int chosen[128]
Definition: aacenc.h:191
SingleChannelElement::band_alt
enum BandType band_alt[128]
alternative band type
Definition: aacenc.h:114
AACCoefficientsEncoder::apply_tns_filt
void(* apply_tns_filt)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:150
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:145
NMRSlot::cur_ch
int cur_ch
encoder channel index (psy/cache context)
Definition: aacenc.h:184
AACEncContext::planar_samples
float * planar_samples[16]
saved preprocessed input
Definition: aacenc.h:268
AACCoefficientsEncoder::search_for_quantizers
void(* search_for_quantizers)(AVCodecContext *avctx, struct AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aacenc.h:143
SingleChannelElement::predictor_state
struct PredictorState * predictor_state
Definition: aacdec.h:231
NMRSlot::tnsg
float tnsg[128]
TNS synthesis gain per band for THIS solve (1 = uncovered), M/S-aware (pair max)
Definition: aacenc.h:198
AACQuantizeBandCostCacheEntry::cb
char cb
Definition: aacenc.h:165
AACNMRCurves::sema_em
float sema_em[16][128]
smoothed mid energy per band
Definition: aacenc.h:225
SingleChannelElement::can_pns
uint8_t can_pns[128]
band is allowed to PNS (informative)
Definition: aacenc.h:117
AACEncContext::needs_pce
int needs_pce
flag for non-standard layout
Definition: aacenc.h:271
SingleChannelElement::pulse
Pulse pulse
Definition: aacenc.h:112
mem_internal.h
AACNMRCurves::frames_since_short
int frames_since_short
long-block frames since the last short run (the "gap"): large = isolated transient
Definition: aacenc.h:235
AACEncOptions::coder
int coder
Definition: aacenc.h:67
out
static FILE * out
Definition: movenc.c:55
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:247
AACEncDSPContext
Definition: aacencdsp.h:24
AACEncContext::av_class
AVClass * av_class
Definition: aacenc.h:259
AVTXContext
Definition: tx_priv.h:235
int64_t
long long int64_t
Definition: coverity.c:34
SingleChannelElement::zeroes
uint8_t zeroes[128]
band is not coded
Definition: aacenc.h:116
AACNMRCurves::rc_frame_num
int64_t rc_frame_num
frame the reservoir was last advanced for
Definition: aacenc.h:232
NMRSlot::bg
int bg[128]
Definition: aacenc.h:188
NMRSlot::si
int si
curve-bank index (nd/nb slot)
Definition: aacenc.h:183
TemporalNoiseShaping::coef_idx
int coef_idx[8][4][TNS_MAX_ORDER]
Definition: aacenc.h:102
AACCoefficientsEncoder::search_for_pns
void(* search_for_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
Definition: aacenc.h:152
NMRSlot::thr
float thr[128]
allocation-law effective threshold
Definition: aacenc.h:196
AACCoefficientsEncoder::search_for_ms
void(* search_for_ms)(struct AACEncContext *s, ChannelElement *cpe)
Definition: aacenc.h:155
AACEncContext::nmr
AACNMRCurves * nmr
NMR coder scratch (NULL unless coder == nmr)
Definition: aacenc.h:304
AACEncContext::samplerate_index
int samplerate_index
MPEG-4 samplerate index.
Definition: aacenc.h:273
AACEncContext::aacdsp
AACEncDSPContext aacdsp
Definition: aacenc.h:303
MAX_PREDICTORS
#define MAX_PREDICTORS
Definition: aac.h:89
AACNMRCurves::side_ema
float side_ema
running estimate of real-minus-counted bits per frame
Definition: aacenc.h:229
TemporalNoiseShaping::present
int present
Definition: aacdec.h:192
AACEncContext::stat_ch_bands
uint64_t stat_ch_bands
Definition: aacenc.h:290
AACCoefficientsEncoder::search_for_tns
void(* search_for_tns)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:154
AAC_CODER_NB
@ AAC_CODER_NB
Definition: aacenc.h:49
NMRSlot::maxvals
float maxvals[128]
Definition: aacenc.h:195
lpc.h
AACQuantizeBandCostCacheEntry::generation
uint16_t generation
Definition: aacenc.h:167
AACNMRCurves::smode_nw
int smode_nw[8]
window count the stored modes were decided on
Definition: aacenc.h:223
ChannelElement::ch
SingleChannelElement ch[2]
Definition: aacdec.h:302
PredictorState::x_est
float x_est
Definition: aac_defines.h:138
AACEncContext::stat_ms
uint64_t stat_ms
Definition: aacenc.h:291
AACEncContext::chan_map
const uint8_t * chan_map
channel configuration map
Definition: aacenc.h:277
AAC_CODER_FAST
@ AAC_CODER_FAST
Definition: aacenc.h:46
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
PredictorState::var1
float var1
Definition: aac_defines.h:134
IndividualChannelStream::num_swb
int num_swb
number of scalefactor window bands
Definition: aacdec.h:178
LPCContext
Definition: lpc.h:51
AACEncContext::stat_tns_short
uint64_t stat_tns_short
TNS-active channels among long / short blocks.
Definition: aacenc.h:293
ff_quantize_band_cost_cache_init
void ff_quantize_band_cost_cache_init(struct AACEncContext *s)
Definition: aacenc.c:373
NMRSlot::blo
int blo[128]
finest candidate scalefactor
Definition: aacenc.h:189
AACNMRCurves::sinit
uint8_t sinit[16]
stereo state bank initialized
Definition: aacenc.h:222
SingleChannelElement::coeffs
float coeffs[1024]
coefficients for IMDCT, maybe processed
Definition: aacenc.h:121
AACNMRCurves::thr_prev_ok
uint8_t thr_prev_ok[16]
thr_prev holds a long-frame measurement
Definition: aacenc.h:215
AACEncContext::psy
FFPsyContext psy
Definition: aacenc.h:280
SingleChannelElement::ret_buf
float ret_buf[2048]
PCM output buffer.
Definition: aacenc.h:122
ChannelElement::ms_mode
int ms_mode
Signals mid/side stereo flags coding mode.
Definition: aacenc.h:132
audio_frame_queue.h
IndividualChannelStream::window_clipping
uint8_t window_clipping[8]
set if a certain window is near clipping
Definition: aacdec.h:185
AACEncContext::options
AACEncOptions options
encoding options
Definition: aacenc.h:260
AACEncOptions::pce
int pce
Definition: aacenc.h:70
AACEncContext::stat_pns
uint64_t stat_pns
coded channel-bands, of which PNS
Definition: aacenc.h:290
SingleChannelElement::ics
IndividualChannelStream ics
Definition: aacdec.h:218
AACNMRCurves::pending
int pending
slot 0 holds a deferred first channel
Definition: aacenc.h:211
AACNMRCurves::rc_fill
int rc_fill
virtual bit reservoir fill, + = bits saved vs nominal
Definition: aacenc.h:234
AACEncContext::fdsp
AVFloatDSPContext * fdsp
Definition: aacenc.h:266
AACEncContext::stat_short
uint64_t stat_short
coded channels, of which short-block (transient)
Definition: aacenc.h:292
AACEncContext::lambda_count
int lambda_count
count(lambda), for Qvg reporting
Definition: aacenc.h:287
PredictorState::cor0
float cor0
Definition: aac_defines.h:131
IndividualChannelStream::clip_avoidance_factor
float clip_avoidance_factor
set if any window is near clipping to the necessary atennuation factor to avoid it
Definition: aacenc.h:90
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
AACPCEInfo::index
uint8_t index[4][8]
front, side, back, lfe
Definition: aacenc.h:250
AACEncContext::lambda_sum
float lambda_sum
sum(lambda), for Qvg reporting
Definition: aacenc.h:286
ff_aac_coders
const AACCoefficientsEncoder ff_aac_coders[]
Definition: aaccoder.c:827
IndividualChannelStream::swb_sizes
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window
Definition: aacenc.h:85
TemporalNoiseShaping::direction
int direction[8][4]
Definition: aacdec.h:195
AudioFrameQueue
Definition: audio_frame_queue.h:32
AACEncOptions::nmr_speed
int nmr_speed
NMR coder speed level: 0 = slowest/best, higher is faster.
Definition: aacenc.h:73
PredictorState
Predictor State.
Definition: aac_defines.h:130
AACEncContext::reorder_map
const uint8_t * reorder_map
lavc to aac reorder map
Definition: aacenc.h:276
NMRSlot::minsf
int minsf[128]
Definition: aacenc.h:194
AACEncContext::stat_tns_long
uint64_t stat_tns_long
Definition: aacenc.h:293
IndividualChannelStream
Individual Channel Stream.
Definition: aacdec.h:169
AACPCEInfo::reorder_map
uint8_t reorder_map[16]
maps channels from lavc to aac order
Definition: aacenc.h:252
AACQuantizeBandCostCacheEntry::energy
float energy
Definition: aacenc.h:163
PutBitContext
Definition: put_bits.h:50
NMRSlot::bst
int bst[128]
window group, swb, coef start
Definition: aacenc.h:188
AACNMRCurves::lam_rc
float lam_rc
global-lambda rate control: operating lambda, 0 until bootstrapped
Definition: aacenc.h:233
AACNMRCurves::lam
float lam[16]
per-channel operating lambda of the previous frame, 0 = none yet
Definition: aacenc.h:227
AACNMRCurves::zero_prev
uint8_t zero_prev[16][128]
per-channel band zero state last frame (zeroing hysteresis)
Definition: aacenc.h:212
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
ChannelElement::is_mask
uint8_t is_mask[128]
Set if intensity stereo is used.
Definition: aacenc.h:135
NMRSlot::pener
float pener[128]
band energy (PNS noise target)
Definition: aacenc.h:199
AACPCEInfo::pairing
uint8_t pairing[3][8]
front, side, back
Definition: aacenc.h:249
AACNMRCurves::smode_band
uint8_t smode_band[8][128]
last decided stereo mode per band index (side-band tests)
Definition: aacenc.h:220
SingleChannelElement::is_ener
float is_ener[128]
Intensity stereo pos.
Definition: aacenc.h:118
IndividualChannelStream::use_kb_window
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sine window.
Definition: aacdec.h:172
AACEncContext::cur_type
enum RawDataBlockType cur_type
channel group type cur_channel belongs to
Definition: aacenc.h:294
NMRSlot::sce
struct SingleChannelElement * sce
Definition: aacenc.h:182
ChannelElement::ms_mask
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
Definition: aacdec.h:300
aac.h
AACEncContext::mdct128_fn
av_tx_fn mdct128_fn
Definition: aacenc.h:265
AACEncContext::random_state
int random_state
Definition: aacenc.h:283
TNS_MAX_ORDER
#define TNS_MAX_ORDER
Definition: aac.h:36
AACEncContext::quantize_band_cost_cache_generation
uint16_t quantize_band_cost_cache_generation
Definition: aacenc.h:300
AACNMRCurves
Definition: aacenc.h:204
SingleChannelElement::sf_idx
int sf_idx[128]
scalefactor indices
Definition: aacenc.h:115
AACNMRCurves::rc_fill_seeded
int rc_fill_seeded
reservoir seeded full at stream start (decoder buffer starts full)
Definition: aacenc.h:210
AACEncContext::qcoefs
int qcoefs[96]
quantized coefficients
Definition: aacenc.h:297
float_dsp.h
NMRSlot::bw
int bw[128]
Definition: aacenc.h:188
AACNMRCurves::pair
int pair
current element is a CPE: pool the pair budget
Definition: aacenc.h:208
AACEncOptions::tns
int tns
Definition: aacenc.h:69
AACPCEInfo
Definition: aacenc.h:246
AACEncContext::samples
float * samples
Definition: aacenc.h:307
IndividualChannelStream::window_sequence
enum WindowSequence window_sequence[2]
Definition: aacdec.h:171
AACCoefficientsEncoder::set_special_band_scalefactors
void(* set_special_band_scalefactors)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:151
AACEncContext::channels
int channels
channel count
Definition: aacenc.h:274
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
AACNMRCurves::pns_prev
uint8_t pns_prev[16][128]
per-channel PNS state last frame (decision hysteresis)
Definition: aacenc.h:216
BandType
BandType
Definition: aac.h:70
size
int size
Definition: twinvq_data.h:10344
AACEncContext::stat_chans
uint64_t stat_chans
Definition: aacenc.h:292
AACNMRCurves::prev_was_short
int prev_was_short
previous frame was a short block (for run-start detection)
Definition: aacenc.h:236
NMRSlot::is_pns
uint8_t is_pns[128]
band coded as noise
Definition: aacenc.h:201
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:147
NMR_NCAND
#define NMR_NCAND
per-band scalefactor candidates above the finest codeable sf (NMR coder)
Definition: aacenc.h:171
AVFloatDSPContext
Definition: float_dsp.h:24
AAC_CODER_TWOLOOP
@ AAC_CODER_TWOLOOP
Definition: aacenc.h:45
NMRSlot::act
int act[128]
active (non-PNS) band coding order
Definition: aacenc.h:192
NMRSlot::pspread
float pspread[128]
band tonality spread (1 = noise)
Definition: aacenc.h:200
ChannelElement::common_window
int common_window
Set if channels share a common 'IndividualChannelStream' in bitstream.
Definition: aacenc.h:131
AACCoefficientsEncoder::mark_pns
void(* mark_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
Definition: aacenc.h:153
AACNMRCurves::side_inited
int side_inited
side_ema holds a measurement
Definition: aacenc.h:230
AACEncContext::mdct1024
AVTXContext * mdct1024
long (1024 samples) frame transform context
Definition: aacenc.h:262
AACNMRCurves::sema_es
float sema_es[16][128]
smoothed side energy per band (stereo-decision EMA)
Definition: aacenc.h:224
SingleChannelElement::band_type
enum BandType band_type[128]
band types
Definition: aacdec.h:221
AACNMRCurves::lam_slew
float lam_slew
final operating lambda of the previous RC frame (slew-limiter state)
Definition: aacenc.h:238
SingleChannelElement::pns_ener
float pns_ener[128]
Noise energy values.
Definition: aacenc.h:119
AACNMRCurves::zero_nw
int zero_nw[16]
window count zero_prev was recorded on
Definition: aacenc.h:213
AACEncContext::cur_channel
int cur_channel
current channel for coder context
Definition: aacenc.h:282
AACCoder
AACCoder
Definition: aacenc.h:44
NMRSlot::nact
int nact
Definition: aacenc.h:193
AACNMRCurves::sema_img
float sema_img[16][128]
smoothed I/S image-error/mask ratio per band
Definition: aacenc.h:226
AACPCEInfo::config_map
uint8_t config_map[16]
configs the encoder's channel specific settings
Definition: aacenc.h:251
AACNMRCurves::tns8_prev
uint8_t tns8_prev[16]
short-TNS accepted last frame (per channel): Schmitt state for the accept bar
Definition: aacenc.h:221
AACEncOptions::intensity_stereo
int intensity_stereo
Definition: aacenc.h:72
RawDataBlockType
RawDataBlockType
Definition: aac.h:43
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aacdec.h:217
NMRSlot::bnc
int bnc[128]
number of candidates
Definition: aacenc.h:190
IndividualChannelStream::num_windows
int num_windows
Definition: aacdec.h:179
AACQuantizeBandCostCacheEntry::rd
float rd
Definition: aacenc.h:162
AACCoefficientsEncoder::search_for_is
void(* search_for_is)(struct AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe)
Definition: aacenc.h:156
SingleChannelElement::pcoeffs
float pcoeffs[1024]
coefficients for IMDCT, pristine
Definition: aacenc.h:120
AACNMRCurves::smode
uint8_t smode[16][128]
per-pair previous stereo mode per band, two banks per pair (long/short grid): each grid's memory pers...
Definition: aacenc.h:219
NMRSlot::nbnd
int nbnd
coded-band count, 0 = nothing codeable
Definition: aacenc.h:185
aacencdsp.h
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aacdec.h:296
IndividualChannelStream::swb_offset
const uint16_t * swb_offset
table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular wind...
Definition: aacdec.h:177
s
uint8_t s
Definition: llvidencdsp.c:39
AACQuantizeBandCostCacheEntry::bits
int bits
Definition: aacenc.h:164
NMRSlot::thr_real
float thr_real[128]
real masking threshold (PNS gates)
Definition: aacenc.h:197
AACPCEInfo::num_ele
uint8_t num_ele[4]
front, side, back, lfe
Definition: aacenc.h:248
TemporalNoiseShaping::order
int order[8][4]
Definition: aacdec.h:196
NMRSlot::bidx
int bidx[128]
sce band index (w*16+g)
Definition: aacenc.h:187
AACEncContext::quantize_band_cost_cache
AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]
memoization area for quantize_band_cost
Definition: aacenc.h:301
PredictorState::r1
float r1
Definition: aac_defines.h:136
IndividualChannelStream::tns_max_bands
int tns_max_bands
Definition: aacdec.h:180
AAC_CODER_NMR
@ AAC_CODER_NMR
Definition: aacenc.h:47
AACCoefficientsEncoder
Definition: aacenc.h:142
TemporalNoiseShaping::length
int length[8][4]
Definition: aacdec.h:194
AACEncOptions::pns
int pns
Definition: aacenc.h:68
avcodec.h
AACEncOptions::mid_side
int mid_side
Definition: aacenc.h:71
AACEncContext::profile
int profile
copied from avctx
Definition: aacenc.h:270
AACNMRCurves::lam_long_ema
float lam_long_ema
smoothed operating lambda of long frames
Definition: aacenc.h:242
AACEncContext::lpc
LPCContext lpc
used by TNS
Definition: aacenc.h:272
AACNMRCurves::run_burst
float run_burst
transient bit-burst factor, set at run start and held across the short run
Definition: aacenc.h:237
PredictorState::var0
float var0
Definition: aac_defines.h:133
AACNMRCurves::lam_floor
float lam_floor
lambda min-tracker (snaps down, +2%/frame up): sustained-strain floor; bursty spikes at a comfortable...
Definition: aacenc.h:243
TemporalNoiseShaping::coef
float coef[8][4][TNS_MAX_ORDER]
Definition: aacenc.h:103
AACEncContext::afq
AudioFrameQueue afq
Definition: aacenc.h:296
SingleChannelElement::tns
TemporalNoiseShaping tns
Definition: aacdec.h:220
AACEncContext::pce
AACPCEInfo pce
PCE data, if needed.
Definition: aacenc.h:267
AACEncContext
AAC encoder context.
Definition: aacenc.h:258
PredictorState::r0
float r0
Definition: aac_defines.h:135
AACQuantizeBandCostCacheEntry::rtz
char rtz
Definition: aacenc.h:166
AACCoefficientsEncoder::encode_tns_info
void(* encode_tns_info)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:149
AACEncContext::last_frame_pb_count
int last_frame_pb_count
number of bits for the previous frame
Definition: aacenc.h:285
AVCodecContext
main external API structure.
Definition: avcodec.h:443
AACEncContext::mdct128
AVTXContext * mdct128
short (128 samples) frame transform context
Definition: aacenc.h:264
AACEncContext::stat_cpe_bands
uint64_t stat_cpe_bands
Definition: aacenc.h:291
AACEncContext::scoefs
float scoefs[1024]
scaled coefficients
Definition: aacenc.h:298
channel_layout.h
AACNMRCurves::press
float press
rate-pressure ramp [0,1]: lambda EMA against anchors that scale up when nd_ema flags noise-class cont...
Definition: aacenc.h:240
TemporalNoiseShaping
Temporal Noise Shaping.
Definition: aacdec.h:191
AACNMRCurves::nd_ema
float nd_ema
smoothed achieved distortion/real-mask over long-frame coded bands (1 = at threshold; >>1 flags psy-u...
Definition: aacenc.h:239
AACNMRCurves::slot
NMRSlot slot[2]
pair slots (solo solves use slot 0)
Definition: aacenc.h:207
ChannelElement::is_mode
uint8_t is_mode
Set if any bands have been encoded using intensity stereo.
Definition: aacenc.h:133
AACNMRCurves::thr_prev
float thr_prev[16][64]
per-channel long-grid law thresholds of the previous frame
Definition: aacenc.h:214
AACEncContext::coder
const AACCoefficientsEncoder * coder
Definition: aacenc.h:281
AACEncContext::buffer
struct AACEncContext::@39 buffer
NMRSlot
NMR coder per-band candidate cost curves (~96 KiB) and rate-control carry-over.
Definition: aacenc.h:181
AACEncContext::stat_is
uint64_t stat_is
coded CPE pair-bands, of which M/S, I/S
Definition: aacenc.h:291
AACNMRCurves::rc_gl
int rc_gl
rc_global latched at frame start: the corridor bootstrap must not flip the CPE defer logic between ch...
Definition: aacenc.h:209
AACNMRCurves::pns_run_on
uint8_t pns_run_on[16][128]
consecutive frames the band has WANTED PNS
Definition: aacenc.h:217
AACEncContext::pb
PutBitContext pb
Definition: aacenc.h:261
PredictorState::k1
float k1
Definition: aac_defines.h:137
IndividualChannelStream::max_sfb
uint8_t max_sfb
number of scalefactor bands per group
Definition: aacdec.h:170
Pulse
Definition: aac.h:103
AACEncContext::mdct1024_fn
av_tx_fn mdct1024_fn
Definition: aacenc.h:263
AACEncContext::bandwidth
int bandwidth
coding bandwidth in Hz, fixed at init; the psy model and the coders' band cutoff agree on it
Definition: aacenc.h:275
WindowSequence
WindowSequence
Definition: aac.h:63
AACNMRCurves::nb
int nb[2][128][NMR_NCAND]
spectral bits per candidate, per pair slot
Definition: aacenc.h:206
AACNMRCurves::lam_short_ema
float lam_short_ema
smoothed operating lambda of short frames
Definition: aacenc.h:241
AACEncContext::lambda
float lambda
Definition: aacenc.h:284
put_bits.h
FFPsyContext
context used by psychoacoustic model
Definition: psymodel.h:89
IndividualChannelStream::group_len
uint8_t group_len[8]
Definition: aacdec.h:175
AACEncOptions
Definition: aacenc.h:66
psymodel.h
TemporalNoiseShaping::n_filt
int n_filt[8]
Definition: aacdec.h:193
PredictorState::cor1
float cor1
Definition: aac_defines.h:132
tx.h
AACNMRCurves::pns_run_off
uint8_t pns_run_off[16][128]
consecutive frames the band has wanted OUT
Definition: aacenc.h:218
AACNMRCurves::nd
float nd[2][128][NMR_NCAND]
dist / threshold per candidate, per pair slot
Definition: aacenc.h:205
AACEncContext::cpe
ChannelElement * cpe
channel elements
Definition: aacenc.h:279
AACPCEInfo::layout
AVChannelLayout layout
Definition: aacenc.h:247