[FFmpeg-cvslog] aacenc: Add support for Perceptual Noise Substitution energy values
Rostislav Pehlivanov
git at videolan.org
Mon Apr 13 04:36:20 CEST 2015
ffmpeg | branch: master | Rostislav Pehlivanov <atomnuker at gmail.com> | Sun Apr 12 05:50:34 2015 +0100| [f7f71b5795d708763eb0c55fe5e2cb051b2b69f4] | committer: Michael Niedermayer
aacenc: Add support for Perceptual Noise Substitution energy values
This commit implements support for writing the noise energy values used in PNS.
The difference between regular scalefactors and noise energy values is that the latter
require a small preamble (NOISE_PRE + energy_value_diff) to be written as the first
noise-containing band. Any following noise energy values use the previous one to
base their "diff" on. Ordinary scalefactors remain unchanged other than that they ignore the noise values.
This commit should not change anything by itself, the following commits will bring it in use.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f7f71b5795d708763eb0c55fe5e2cb051b2b69f4
---
libavcodec/aac.h | 3 +++
libavcodec/aacenc.c | 17 ++++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index b25b40c..2701386 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -141,6 +141,9 @@ typedef struct PredictorState {
#define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard
#define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference
+#define NOISE_PRE 256 ///< preamble for NOISE_BT, put in bitstream with the first noise band
+#define NOISE_PRE_BITS 9 ///< length of preamble
+
/**
* Long Term Prediction
*/
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 7015a27..5288afb 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -388,15 +388,26 @@ static void encode_band_info(AACEncContext *s, SingleChannelElement *sce)
static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s,
SingleChannelElement *sce)
{
- int off = sce->sf_idx[0], diff;
+ int diff, off_sf = sce->sf_idx[0], off_pns = sce->sf_idx[0];
+ int noise_flag = 1;
int i, w;
for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
for (i = 0; i < sce->ics.max_sfb; i++) {
if (!sce->zeroes[w*16 + i]) {
- diff = sce->sf_idx[w*16 + i] - off + SCALE_DIFF_ZERO;
+ if (sce->band_type[w*16 + i] == NOISE_BT) {
+ diff = sce->sf_idx[w*16 + i] - off_pns;
+ off_pns = sce->sf_idx[w*16 + i];
+ if (noise_flag-- > 0) {
+ put_bits(&s->pb, NOISE_PRE_BITS, diff + NOISE_PRE);
+ continue;
+ }
+ } else {
+ diff = sce->sf_idx[w*16 + i] - off_sf;
+ off_sf = sce->sf_idx[w*16 + i];
+ }
+ diff += SCALE_DIFF_ZERO;
av_assert0(diff >= 0 && diff <= 120);
- off = sce->sf_idx[w*16 + i];
put_bits(&s->pb, ff_aac_scalefactor_bits[diff], ff_aac_scalefactor_code[diff]);
}
}
More information about the ffmpeg-cvslog
mailing list