FFmpeg
Macros | Functions
aaccoder_nmr.h File Reference
#include <float.h>
#include <string.h>
#include "libavutil/mathematics.h"
#include "mathops.h"
#include "avcodec.h"
#include "put_bits.h"
#include "aac.h"
#include "aacenc.h"
#include "aactab.h"
#include "aacenctab.h"

Go to the source code of this file.

Macros

#define NMR_SFBITS(d)   ff_aac_scalefactor_bits[av_clip((d) + SCALE_DIFF_ZERO, 0, 2*SCALE_MAX_DIFF)]
 AAC encoder NMR scalefactor coder. More...
 
#define NMR_ITERS   14 /* lambda binary-search iters */
 
#define NMR_IFINE   9 /* fine-pass lambda iters */
 
#define NMR_CITERS   7 /* coarse-pass lambda iters */
 
#define NMR_CWARM
 
#define NMR_COARSE
 
#define NMR_STEP   1 /* fine-pass scalefactor candidate granularity */
 
#define NMR_PNS_BITS   9 /* approx cost in bits of signalling PNS */
 
#define NMR_PNS_HOLE_FRAC   0.5f
 
#define NMR_PNS_HOLE_SPREAD   0.5f
 
#define NMR_RC_K_CBR   0.5f
 
#define NMR_RC_ITERS   8 /* lambda bisection iters when clamping an over-cap frame */
 
#define NMR_RC_CORR   1.5f
 
#define NMR_CBR_BUF   512
 
#define NMR_RC_CITERS   3 /* corridor coarse-pass iters */
 
#define NMR_BURST_GAP   10
 
#define NMR_BURST_GAIN   8.0f
 
#define NMR_RC_FITERS   4 /* corridor fine-pass iters */
 
#define NMR_RC_TRACK   0.1f /* per-frame pull of the corridor centre toward the realized lambda */
 
#define NMR_PNS_NDGATE   4.0f
 
#define NMR_PNS_MAX_ET   8.0f
 
#define NMR_PNS_LAM   100.0f
 

Functions

static float nmr_solve (AACEncContext *s, const float(*nd)[NMR_NCAND], const int(*nb)[NMR_NCAND], const int *blo, const int *bnc, int step, const int *act, int nact, int destbits, int *chosen, float lo_l, float hi_l, int iters)
 Viterbi over the coding sequence act0..nact-1, with lambda binary-searched so the coded size ~ destbits. More...
 
static int nmr_band_curve (AACEncContext *s, SingleChannelElement *sce, int w, int g, int start, int lo, int step, int maxn, float invthr, float maxval, float *nd_row, int *nb_row)
 
static void search_for_quantizers_nmr (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
 

Macro Definition Documentation

◆ NMR_SFBITS

#define NMR_SFBITS (   d)    ff_aac_scalefactor_bits[av_clip((d) + SCALE_DIFF_ZERO, 0, 2*SCALE_MAX_DIFF)]

AAC encoder NMR scalefactor coder.

Optimizes the same noise-to-mask objective as the two-loop coder, but with an optimal Viterbi search over scalefactors instead of a heuristic loop. For each coded band the per-scalefactor distortion/bits curve is precomputed, then a trellis over the (window-group, band) coding sequence minimizes sum_g = dist_g(sf_g)/threshold_g + lambda * (spectral_bits_g(sf_g) + scalefactor_differential_bits) with |sf_g - sf_{g-1}| <= SCALE_MAX_DIFF as a constraint, and lambda binary-searched so the coded size meets the per-frame bit budget

Perceptual noise substitution (PNS) is integrated into the same objective: once the trellis settles on its operating lambda, each noise-like band (flagged by mark_pns) is offered a terminal "code as noise" candidate whose cost is nmr_pns + lambda*NMR_PNS_BITS. Because NMR_PNS_BITS is far below a band's spectral bit count, this candidate only wins when lambda is large, i.e. when the encoder is struggling to hold the bitrate. The bits freed by the chosen PNS bands are then re-spent by a second trellis pass over the remaining bands.

Definition at line 58 of file aaccoder_nmr.h.

◆ NMR_ITERS

#define NMR_ITERS   14 /* lambda binary-search iters */

Definition at line 60 of file aaccoder_nmr.h.

◆ NMR_IFINE

#define NMR_IFINE   9 /* fine-pass lambda iters */

Definition at line 61 of file aaccoder_nmr.h.

◆ NMR_CITERS

#define NMR_CITERS   7 /* coarse-pass lambda iters */

Definition at line 62 of file aaccoder_nmr.h.

◆ NMR_CWARM

#define NMR_CWARM
Value:
5 /* coarse-pass iters when warm-started off the previous frame's
* lambda: the bracket spans 10 octaves instead of ~43, so fewer
* bisection steps reach the same resolution */

Definition at line 63 of file aaccoder_nmr.h.

◆ NMR_COARSE

#define NMR_COARSE
Value:
8 /* two-pass coarse->fine grid step, cuts the Viterbi ncand^2 with no
* quality loss, 0 disables it (single full-resolution pass) */

Definition at line 64 of file aaccoder_nmr.h.

◆ NMR_STEP

#define NMR_STEP   1 /* fine-pass scalefactor candidate granularity */

Definition at line 65 of file aaccoder_nmr.h.

◆ NMR_PNS_BITS

#define NMR_PNS_BITS   9 /* approx cost in bits of signalling PNS */

Definition at line 67 of file aaccoder_nmr.h.

◆ NMR_PNS_HOLE_FRAC

#define NMR_PNS_HOLE_FRAC   0.5f

Definition at line 71 of file aaccoder_nmr.h.

◆ NMR_PNS_HOLE_SPREAD

#define NMR_PNS_HOLE_SPREAD   0.5f

Definition at line 72 of file aaccoder_nmr.h.

◆ NMR_RC_K_CBR

#define NMR_RC_K_CBR   0.5f

Definition at line 76 of file aaccoder_nmr.h.

◆ NMR_RC_ITERS

#define NMR_RC_ITERS   8 /* lambda bisection iters when clamping an over-cap frame */

Definition at line 78 of file aaccoder_nmr.h.

◆ NMR_RC_CORR

#define NMR_RC_CORR   1.5f

Definition at line 81 of file aaccoder_nmr.h.

◆ NMR_CBR_BUF

#define NMR_CBR_BUF   512

Definition at line 85 of file aaccoder_nmr.h.

◆ NMR_RC_CITERS

#define NMR_RC_CITERS   3 /* corridor coarse-pass iters */

Definition at line 86 of file aaccoder_nmr.h.

◆ NMR_BURST_GAP

#define NMR_BURST_GAP   10

Definition at line 90 of file aaccoder_nmr.h.

◆ NMR_BURST_GAIN

#define NMR_BURST_GAIN   8.0f

Definition at line 91 of file aaccoder_nmr.h.

◆ NMR_RC_FITERS

#define NMR_RC_FITERS   4 /* corridor fine-pass iters */

Definition at line 92 of file aaccoder_nmr.h.

◆ NMR_RC_TRACK

#define NMR_RC_TRACK   0.1f /* per-frame pull of the corridor centre toward the realized lambda */

Definition at line 93 of file aaccoder_nmr.h.

◆ NMR_PNS_NDGATE

#define NMR_PNS_NDGATE   4.0f

Definition at line 96 of file aaccoder_nmr.h.

◆ NMR_PNS_MAX_ET

#define NMR_PNS_MAX_ET   8.0f

Definition at line 100 of file aaccoder_nmr.h.

◆ NMR_PNS_LAM

#define NMR_PNS_LAM   100.0f

Definition at line 104 of file aaccoder_nmr.h.

Function Documentation

◆ nmr_solve()

static float nmr_solve ( AACEncContext s,
const float(*)  nd[NMR_NCAND],
const int(*)  nb[NMR_NCAND],
const int *  blo,
const int *  bnc,
int  step,
const int *  act,
int  nact,
int  destbits,
int *  chosen,
float  lo_l,
float  hi_l,
int  iters 
)
static

Viterbi over the coding sequence act0..nact-1, with lambda binary-searched so the coded size ~ destbits.

Fills chosen[band] for every band referenced by act. Returns the operating lambda. node cost = dist/threshold + lambda*spectral_bits; edge cost = lambda*sf_differential_bits; |delta sf| <= SCALE_MAX_DIFF hard.

Definition at line 113 of file aaccoder_nmr.h.

◆ nmr_band_curve()

static int nmr_band_curve ( AACEncContext s,
SingleChannelElement sce,
int  w,
int  g,
int  start,
int  lo,
int  step,
int  maxn,
float  invthr,
float  maxval,
float nd_row,
int *  nb_row 
)
static

Definition at line 177 of file aaccoder_nmr.h.

◆ search_for_quantizers_nmr()

static void search_for_quantizers_nmr ( AVCodecContext avctx,
AACEncContext s,
SingleChannelElement sce,
const float  lambda 
)
static

Definition at line 201 of file aaccoder_nmr.h.