annotate aacpsy.c @ 12159:25ac974ce96d libavcodec

aacenc: psy_3gpp_init(): Calculate barks on demand.
author alexc
date Wed, 14 Jul 2010 04:10:31 +0000
parents 2e7db647fef8
children e0bed2f0f9f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7606
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
1 /*
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
2 * AAC encoder psychoacoustic model
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
3 * Copyright (C) 2008 Konstantin Shishkov
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
4 *
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
5 * This file is part of FFmpeg.
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
6 *
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
11 *
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
15 * Lesser General Public License for more details.
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
16 *
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
20 */
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
21
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 9944
diff changeset
23 * @file
7606
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
24 * AAC encoder psychoacoustic model
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
25 */
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
26
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
27 #include "avcodec.h"
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
28 #include "aactab.h"
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
29 #include "psymodel.h"
7606
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
30
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
31 /***********************************
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
32 * TODOs:
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
33 * thresholds linearization after their modifications for attaining given bitrate
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
34 * try other bitrate controlling mechanism (maybe use ratecontrol.c?)
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
35 * control quality for quality-based output
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
36 **********************************/
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
37
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
38 /**
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
39 * constants for 3GPP AAC psychoacoustic model
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
40 * @{
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
41 */
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
42 #define PSY_3GPP_SPREAD_LOW 1.5f // spreading factor for ascending threshold spreading (15 dB/Bark)
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
43 #define PSY_3GPP_SPREAD_HI 3.0f // spreading factor for descending threshold spreading (30 dB/Bark)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
44
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
45 #define PSY_3GPP_RPEMIN 0.01f
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
46 #define PSY_3GPP_RPELEV 2.0f
7606
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
47 /**
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
48 * @}
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
49 */
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
50
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
51 /**
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
52 * information for single band used by 3GPP TS26.403-inspired psychoacoustic model
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
53 */
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
54 typedef struct Psy3gppBand{
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
55 float energy; ///< band energy
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
56 float ffac; ///< form factor
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
57 float thr; ///< energy threshold
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
58 float min_snr; ///< minimal SNR
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
59 float thr_quiet; ///< threshold in quiet
7606
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
60 }Psy3gppBand;
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
61
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
62 /**
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
63 * single/pair channel context for psychoacoustic model
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
64 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
65 typedef struct Psy3gppChannel{
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
66 Psy3gppBand band[128]; ///< bands information
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
67 Psy3gppBand prev_band[128]; ///< bands information from the previous frame
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
68
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
69 float win_energy; ///< sliding average of channel energy
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
70 float iir_state[2]; ///< hi-pass IIR filter state
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
71 uint8_t next_grouping; ///< stored grouping scheme for the next frame (in case of 8 short window sequence)
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
72 enum WindowSequence next_window_seq; ///< window sequence to be used in the next frame
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
73 }Psy3gppChannel;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
74
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
75 /**
7606
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
76 * psychoacoustic model frame type-dependent coefficients
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
77 */
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
78 typedef struct Psy3gppCoeffs{
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
79 float ath [64]; ///< absolute threshold of hearing per bands
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
80 float barks [64]; ///< Bark value for each spectral band in long frame
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
81 float spread_low[64]; ///< spreading factor for low-to-high threshold spreading in long frame
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
82 float spread_hi [64]; ///< spreading factor for high-to-low threshold spreading in long frame
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
83 }Psy3gppCoeffs;
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
84
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
85 /**
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
86 * 3GPP TS26.403-inspired psychoacoustic model specific data
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
87 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
88 typedef struct Psy3gppContext{
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
89 Psy3gppCoeffs psy_coef[2];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
90 Psy3gppChannel *ch;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
91 }Psy3gppContext;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
92
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
93 /**
7606
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
94 * Calculate Bark value for given line.
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
95 */
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
96 static av_cold float calc_bark(float f)
7606
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
97 {
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
98 return 13.3f * atanf(0.00076f * f) + 3.5f * atanf((f / 7500.0f) * (f / 7500.0f));
e24539743ed8 Add okayed chunks of AAC encoder psychoacoustic model
kostya
parents:
diff changeset
99 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
100
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
101 #define ATH_ADD 4
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
102 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
103 * Calculate ATH value for given frequency.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
104 * Borrowed from Lame.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
105 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
106 static av_cold float ath(float f, float add)
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
107 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
108 f /= 1000.0f;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
109 return 3.64 * pow(f, -0.8)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
110 - 6.8 * exp(-0.6 * (f - 3.4) * (f - 3.4))
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
111 + 6.0 * exp(-0.15 * (f - 8.7) * (f - 8.7))
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
112 + (0.6 + 0.04 * add) * 0.001 * f * f * f * f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
113 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
114
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
115 static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
116 Psy3gppContext *pctx;
12159
25ac974ce96d aacenc: psy_3gpp_init(): Calculate barks on demand.
alexc
parents: 11998
diff changeset
117 float bark;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
118 int i, j, g, start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
119 float prev, minscale, minath;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
120
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
121 ctx->model_priv_data = av_mallocz(sizeof(Psy3gppContext));
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
122 pctx = (Psy3gppContext*) ctx->model_priv_data;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
123
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
124 minath = ath(3410, ATH_ADD);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
125 for (j = 0; j < 2; j++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
126 Psy3gppCoeffs *coeffs = &pctx->psy_coef[j];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
127 i = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
128 prev = 0.0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
129 for (g = 0; g < ctx->num_bands[j]; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
130 i += ctx->bands[j][g];
12159
25ac974ce96d aacenc: psy_3gpp_init(): Calculate barks on demand.
alexc
parents: 11998
diff changeset
131 bark = calc_bark((i-1) * ctx->avctx->sample_rate / 2048.0);
25ac974ce96d aacenc: psy_3gpp_init(): Calculate barks on demand.
alexc
parents: 11998
diff changeset
132 coeffs->barks[g] = (bark + prev) / 2.0;
25ac974ce96d aacenc: psy_3gpp_init(): Calculate barks on demand.
alexc
parents: 11998
diff changeset
133 prev = bark;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
134 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
135 for (g = 0; g < ctx->num_bands[j] - 1; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
136 coeffs->spread_low[g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_LOW);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
137 coeffs->spread_hi [g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_HI);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
138 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
139 start = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
140 for (g = 0; g < ctx->num_bands[j]; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
141 minscale = ath(ctx->avctx->sample_rate * start / 1024.0, ATH_ADD);
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
142 for (i = 1; i < ctx->bands[j][g]; i++)
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9938
diff changeset
143 minscale = FFMIN(minscale, ath(ctx->avctx->sample_rate * (start + i) / 1024.0 / 2.0, ATH_ADD));
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
144 coeffs->ath[g] = minscale - minath;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
145 start += ctx->bands[j][g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
146 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
147 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
148
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
149 pctx->ch = av_mallocz(sizeof(Psy3gppChannel) * ctx->avctx->channels);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
150 return 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
151 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
152
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
153 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
154 * IIR filter used in block switching decision
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
155 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
156 static float iir_filter(int in, float state[2])
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
157 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
158 float ret;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
159
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
160 ret = 0.7548f * (in - state[0]) + 0.5095f * state[1];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
161 state[0] = in;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
162 state[1] = ret;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
163 return ret;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
164 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
165
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
166 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
167 * window grouping information stored as bits (0 - new group, 1 - group continues)
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
168 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
169 static const uint8_t window_grouping[9] = {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
170 0xB6, 0x6C, 0xD8, 0xB2, 0x66, 0xC6, 0x96, 0x36, 0x36
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
171 };
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
172
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
173 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
174 * Tell encoder which window types to use.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
175 * @see 3GPP TS26.403 5.4.1 "Blockswitching"
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
176 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
177 static FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
178 const int16_t *audio, const int16_t *la,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
179 int channel, int prev_type)
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
180 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
181 int i, j;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
182 int br = ctx->avctx->bit_rate / ctx->avctx->channels;
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
183 int attack_ratio = br <= 16000 ? 18 : 10;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
184 Psy3gppContext *pctx = (Psy3gppContext*) ctx->model_priv_data;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
185 Psy3gppChannel *pch = &pctx->ch[channel];
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
186 uint8_t grouping = 0;
11998
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
187 int next_type = pch->next_window_seq;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
188 FFPsyWindowInfo wi;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
189
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
190 memset(&wi, 0, sizeof(wi));
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
191 if (la) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
192 float s[8], v;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
193 int switch_to_eight = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
194 float sum = 0.0, sum2 = 0.0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
195 int attack_n = 0;
11998
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
196 int stay_short = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
197 for (i = 0; i < 8; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
198 for (j = 0; j < 128; j++) {
11728
907ac02ef561 aacenc: Fix psy logic.
alexc
parents: 11644
diff changeset
199 v = iir_filter(la[(i*128+j)*ctx->avctx->channels], pch->iir_state);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
200 sum += v*v;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
201 }
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
202 s[i] = sum;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
203 sum2 += sum;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
204 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
205 for (i = 0; i < 8; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
206 if (s[i] > pch->win_energy * attack_ratio) {
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
207 attack_n = i + 1;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
208 switch_to_eight = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
209 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
210 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
211 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
212 pch->win_energy = pch->win_energy*7/8 + sum2/64;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
213
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
214 wi.window_type[1] = prev_type;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
215 switch (prev_type) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
216 case ONLY_LONG_SEQUENCE:
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
217 wi.window_type[0] = switch_to_eight ? LONG_START_SEQUENCE : ONLY_LONG_SEQUENCE;
11998
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
218 next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : ONLY_LONG_SEQUENCE;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
219 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
220 case LONG_START_SEQUENCE:
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
221 wi.window_type[0] = EIGHT_SHORT_SEQUENCE;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
222 grouping = pch->next_grouping;
11998
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
223 next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
224 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
225 case LONG_STOP_SEQUENCE:
11998
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
226 wi.window_type[0] = switch_to_eight ? LONG_START_SEQUENCE : ONLY_LONG_SEQUENCE;
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
227 next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : ONLY_LONG_SEQUENCE;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
228 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
229 case EIGHT_SHORT_SEQUENCE:
11998
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
230 stay_short = next_type == EIGHT_SHORT_SEQUENCE || switch_to_eight;
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
231 wi.window_type[0] = stay_short ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
232 grouping = next_type == EIGHT_SHORT_SEQUENCE ? pch->next_grouping : 0;
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
233 next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
234 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
235 }
11998
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
236
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
237 pch->next_grouping = window_grouping[attack_n];
11998
2e7db647fef8 aacenc: Fix window decision logic.
alexc
parents: 11728
diff changeset
238 pch->next_window_seq = next_type;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
239 } else {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
240 for (i = 0; i < 3; i++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
241 wi.window_type[i] = prev_type;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
242 grouping = (prev_type == EIGHT_SHORT_SEQUENCE) ? window_grouping[0] : 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
243 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
244
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
245 wi.window_shape = 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
246 if (wi.window_type[0] != EIGHT_SHORT_SEQUENCE) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
247 wi.num_windows = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
248 wi.grouping[0] = 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
249 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
250 int lastgrp = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
251 wi.num_windows = 8;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
252 for (i = 0; i < 8; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
253 if (!((grouping >> i) & 1))
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
254 lastgrp = i;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
255 wi.grouping[lastgrp]++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
256 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
257 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
258
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
259 return wi;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
260 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
261
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
262 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
263 * Calculate band thresholds as suggested in 3GPP TS26.403
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
264 */
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
265 static void psy_3gpp_analyze(FFPsyContext *ctx, int channel,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
266 const float *coefs, FFPsyWindowInfo *wi)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
267 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
268 Psy3gppContext *pctx = (Psy3gppContext*) ctx->model_priv_data;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
269 Psy3gppChannel *pch = &pctx->ch[channel];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
270 int start = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
271 int i, w, g;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
272 const int num_bands = ctx->num_bands[wi->num_windows == 8];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
273 const uint8_t* band_sizes = ctx->bands[wi->num_windows == 8];
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
274 Psy3gppCoeffs *coeffs = &pctx->psy_coef[wi->num_windows == 8];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
275
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
276 //calculate energies, initial thresholds and related values - 5.4.2 "Threshold Calculation"
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
277 for (w = 0; w < wi->num_windows*16; w += 16) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
278 for (g = 0; g < num_bands; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
279 Psy3gppBand *band = &pch->band[w+g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
280 band->energy = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
281 for (i = 0; i < band_sizes[g]; i++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
282 band->energy += coefs[start+i] * coefs[start+i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
283 band->energy *= 1.0f / (512*512);
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
284 band->thr = band->energy * 0.001258925f;
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
285 start += band_sizes[g];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
286
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
287 ctx->psy_bands[channel*PSY_MAX_BANDS+w+g].energy = band->energy;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
288 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
289 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
290 //modify thresholds - spread, threshold in quiet - 5.4.3 "Spreaded Energy Calculation"
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
291 for (w = 0; w < wi->num_windows*16; w += 16) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
292 Psy3gppBand *band = &pch->band[w];
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
293 for (g = 1; g < num_bands; g++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
294 band[g].thr = FFMAX(band[g].thr, band[g-1].thr * coeffs->spread_low[g-1]);
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
295 for (g = num_bands - 2; g >= 0; g--)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
296 band[g].thr = FFMAX(band[g].thr, band[g+1].thr * coeffs->spread_hi [g]);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
297 for (g = 0; g < num_bands; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
298 band[g].thr_quiet = FFMAX(band[g].thr, coeffs->ath[g]);
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
299 if (wi->num_windows != 8 && wi->window_type[1] != EIGHT_SHORT_SEQUENCE)
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9938
diff changeset
300 band[g].thr_quiet = FFMAX(PSY_3GPP_RPEMIN*band[g].thr_quiet,
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9938
diff changeset
301 FFMIN(band[g].thr_quiet,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
302 PSY_3GPP_RPELEV*pch->prev_band[w+g].thr_quiet));
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
303 band[g].thr = FFMAX(band[g].thr, band[g].thr_quiet * 0.25);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
304
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
305 ctx->psy_bands[channel*PSY_MAX_BANDS+w+g].threshold = band[g].thr;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
306 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
307 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
308 memcpy(pch->prev_band, pch->band, sizeof(pch->band));
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
309 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
310
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
311 static av_cold void psy_3gpp_end(FFPsyContext *apc)
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
312 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
313 Psy3gppContext *pctx = (Psy3gppContext*) apc->model_priv_data;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
314 av_freep(&pctx->ch);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
315 av_freep(&apc->model_priv_data);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
316 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
317
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
318
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
319 const FFPsyModel ff_aac_psy_model =
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
320 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
321 .name = "3GPP TS 26.403-inspired model",
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
322 .init = psy_3gpp_init,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
323 .window = psy_3gpp_window,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
324 .analyze = psy_3gpp_analyze,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
325 .end = psy_3gpp_end,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents: 8718
diff changeset
326 };