1 /*
2 * AAC encoder trellis codebook selector
3 * Copyright (C) 2008-2009 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 /**
23 * @file
24 * AAC encoder trellis codebook selector
25 * @author Konstantin Shishkov
26 */
27
28 /**
29 * This file contains a template for the codebook_trellis_rate selector function.
30 * It needs to be provided, externally, as an already included declaration,
31 * the following functions from aacenc_quantization/util.h. They're not included
32 * explicitly here to make it possible to provide alternative implementations:
33 * - quantize_band_cost_bits
34 * - abs_pow34_v
35 */
36
37 #ifndef AVCODEC_AACCODER_TRELLIS_H
38 #define AVCODEC_AACCODER_TRELLIS_H
39
48
49 /**
50 * structure used in optimal codebook search
51 */
53 int prev_idx;
///< pointer to the previous path point
57
58
60 int win,
int group_len,
const float lambda)
61 {
67 const int run_esc = (1 <<
run_bits) - 1;
68 int idx, ppos, count;
69 int stackrun[120], stackcb[120], stack_len;
71 int next_mincb = 0;
72
73 s->aacdsp.abs_pow34(
s->scoefs, sce->
coeffs, 1024);
79 }
80 for (swb = 0; swb < max_sfb; swb++) {
83 float cost_stay_here = path[swb][0].
cost;
84 float cost_get_here = next_minbits +
run_bits + 4;
88 if (cost_get_here < cost_stay_here) {
89 path[swb+1][0].
prev_idx = next_mincb;
90 path[swb+1][0].
cost = cost_get_here;
91 path[swb+1][0].
run = 1;
92 } else {
94 path[swb+1][0].
cost = cost_stay_here;
95 path[swb+1][0].
run = path[swb][0].
run + 1;
96 }
97 next_minbits = path[swb+1][0].
cost;
98 next_mincb = 0;
100 path[swb+1][
cb].
cost = 61450;
102 path[swb+1][
cb].
run = 0;
103 }
104 } else {
105 float minbits = next_minbits;
106 int mincb = next_mincb;
110 next_mincb = 0;
111 for (
cb = 0;
cb < startcb;
cb++) {
112 path[swb+1][
cb].
cost = 61450;
114 path[swb+1][
cb].
run = 0;
115 }
117 float cost_stay_here, cost_get_here;
120 path[swb+1][
cb].
cost = 61450;
122 path[swb+1][
cb].
run = 0;
123 continue;
124 }
125 for (
w = 0;
w < group_len;
w++) {
127 &
s->scoefs[start +
w*128],
size,
131 }
137 if (cost_get_here < cost_stay_here) {
139 path[swb+1][
cb].
cost = cost_get_here;
140 path[swb+1][
cb].
run = 1;
141 } else {
143 path[swb+1][
cb].
cost = cost_stay_here;
145 }
146 if (path[swb+1][
cb].cost < next_minbits) {
147 next_minbits = path[swb+1][
cb].
cost;
149 }
150 }
151 }
153 }
154
155 //convert resulting path from backward-linked list
156 stack_len = 0;
157 idx = 0;
159 if (path[max_sfb][
cb].cost < path[max_sfb][idx].cost)
161 ppos = max_sfb;
162 while (ppos > 0) {
165 stackrun[stack_len] = path[ppos][
cb].
run;
166 stackcb [stack_len] =
cb;
168 ppos -= path[ppos][
cb].
run;
169 stack_len++;
170 }
171 //perform actual band info encoding
172 start = 0;
173 for (
i = stack_len - 1;
i >= 0;
i--) {
178 //XXX: memset when band_type is also uint8_t
179 for (j = 0; j < count; j++) {
181 start++;
182 }
183 while (count >= run_esc) {
185 count -= run_esc;
186 }
188 }
189 }
190
191
192 #endif /* AVCODEC_AACCODER_TRELLIS_H */