|
FFmpeg
|
#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 1536 |
| #define | NMR_SLEW 1.6f |
| #define | NMR_SLEW_RUN 1.15f /* within short runs */ |
| #define | NMR_RC_CITERS 3 /* corridor coarse-pass iters */ |
| #define | NMR_TRANS_PM 2.0f |
| #define | NMR_ZERO_STICKY 0.5f |
| #define | NMR_BURST_GAP 10 |
| #define | NMR_BURST_GAIN 8.0f |
| #define | NMR_SHORT_BOOST 2.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 |
| #define | NMR_PNS_ENTER 0.7f |
| #define | NMR_PNS_STAY 1.4f |
| #define | NMR_PNS_ON 8 |
| #define | NMR_PNS_OFF 4 |
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 | nmr_bail_channel (SingleChannelElement *sce) |
| static int | nmr_setup_channel (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, NMRSlot *t) |
| static int | nmr_slot_bits (const NMRSlot *t, const int(*nb)[NMR_NCAND], int step) |
| static int | nmr_eval_slots (AACEncContext *s, NMRSlot *const *sl, int nsl, int step, float lam) |
| static float | nmr_solve_slots (AACEncContext *s, NMRSlot *const *sl, int nsl, int step, int destbits, float lo_l, float hi_l, int iters) |
| static void | nmr_commit_channel (AACEncContext *s, NMRSlot *t) |
| static void | nmr_solve_group (AVCodecContext *avctx, AACEncContext *s, const float lambda, NMRSlot *const *sl, int nsl, int chans, int rc_eligible, int rc_global, int rc_rate_frame, int rc_bmax) |
| static void | search_for_quantizers_nmr (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda) |
| #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.
Definition at line 60 of file aaccoder_nmr.h.
| #define NMR_IFINE 9 /* fine-pass lambda iters */ |
Definition at line 61 of file aaccoder_nmr.h.
| #define NMR_CITERS 7 /* coarse-pass lambda iters */ |
Definition at line 62 of file aaccoder_nmr.h.
| #define NMR_CWARM |
Definition at line 63 of file aaccoder_nmr.h.
| #define NMR_COARSE |
Definition at line 64 of file aaccoder_nmr.h.
| #define NMR_STEP 1 /* fine-pass scalefactor candidate granularity */ |
Definition at line 65 of file aaccoder_nmr.h.
| #define NMR_PNS_BITS 9 /* approx cost in bits of signalling PNS */ |
Definition at line 67 of file aaccoder_nmr.h.
| #define NMR_PNS_HOLE_FRAC 0.5f |
Definition at line 71 of file aaccoder_nmr.h.
| #define NMR_PNS_HOLE_SPREAD 0.5f |
Definition at line 72 of file aaccoder_nmr.h.
| #define NMR_RC_K_CBR 0.5f |
Definition at line 76 of file aaccoder_nmr.h.
| #define NMR_RC_ITERS 8 /* lambda bisection iters when clamping an over-cap frame */ |
Definition at line 78 of file aaccoder_nmr.h.
| #define NMR_RC_CORR 1.5f |
Definition at line 81 of file aaccoder_nmr.h.
| #define NMR_CBR_BUF 1536 |
Definition at line 84 of file aaccoder_nmr.h.
| #define NMR_SLEW 1.6f |
Definition at line 87 of file aaccoder_nmr.h.
Definition at line 88 of file aaccoder_nmr.h.
| #define NMR_RC_CITERS 3 /* corridor coarse-pass iters */ |
Definition at line 89 of file aaccoder_nmr.h.
| #define NMR_TRANS_PM 2.0f |
Definition at line 93 of file aaccoder_nmr.h.
| #define NMR_ZERO_STICKY 0.5f |
Definition at line 97 of file aaccoder_nmr.h.
| #define NMR_BURST_GAP 10 |
Definition at line 101 of file aaccoder_nmr.h.
| #define NMR_BURST_GAIN 8.0f |
Definition at line 102 of file aaccoder_nmr.h.
| #define NMR_SHORT_BOOST 2.0f |
Definition at line 105 of file aaccoder_nmr.h.
| #define NMR_RC_FITERS 4 /* corridor fine-pass iters */ |
Definition at line 106 of file aaccoder_nmr.h.
Definition at line 107 of file aaccoder_nmr.h.
| #define NMR_PNS_NDGATE 4.0f |
Definition at line 110 of file aaccoder_nmr.h.
| #define NMR_PNS_MAX_ET 8.0f |
Definition at line 114 of file aaccoder_nmr.h.
| #define NMR_PNS_LAM 100.0f |
Definition at line 118 of file aaccoder_nmr.h.
| #define NMR_PNS_ENTER 0.7f |
Definition at line 121 of file aaccoder_nmr.h.
| #define NMR_PNS_STAY 1.4f |
Definition at line 122 of file aaccoder_nmr.h.
| #define NMR_PNS_ON 8 |
Definition at line 125 of file aaccoder_nmr.h.
| #define NMR_PNS_OFF 4 |
Definition at line 126 of file aaccoder_nmr.h.
|
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 135 of file aaccoder_nmr.h.
|
static |
Definition at line 199 of file aaccoder_nmr.h.
Referenced by nmr_setup_channel(), and nmr_solve_group().
|
static |
Definition at line 225 of file aaccoder_nmr.h.
|
static |
Definition at line 238 of file aaccoder_nmr.h.
|
static |
Definition at line 455 of file aaccoder_nmr.h.
Referenced by nmr_solve_group().
|
static |
Definition at line 467 of file aaccoder_nmr.h.
Referenced by nmr_solve_group(), and nmr_solve_slots().
|
static |
Definition at line 484 of file aaccoder_nmr.h.
Referenced by nmr_solve_group().
|
static |
Definition at line 504 of file aaccoder_nmr.h.
|
static |
Definition at line 592 of file aaccoder_nmr.h.
|
static |
Definition at line 898 of file aaccoder_nmr.h.
1.8.17