1 /*
2 * AAC encoder long term prediction extension
3 * Copyright (C) 2015 Rostislav Pehlivanov
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 long term prediction extension
25 * @author Rostislav Pehlivanov ( atomnuker gmail com )
26 */
27
31
32 /**
33 * Encode LTP data.
34 */
36 int common_window)
37 {
41 return;
42 if (common_window)
46 return;
51 }
52
54 {
55 int i, ch,
tag, chans, cur_channel, start_ch = 0;
58 for (
i = 0;
i <
s->chan_map[0];
i++) {
60 tag =
s->chan_map[
i+1];
62 for (ch = 0; ch < chans; ch++) {
64 cur_channel = start_ch + ch;
65 /* New sample + overlap */
67 memcpy(&sce->
ltp_state[1024], &
s->planar_samples[cur_channel][2048], 1024*
sizeof(sce->
ltp_state[0]));
70 }
71 start_ch += chans;
72 }
73 }
74
76 {
77 int i, j, lag = 0, max_corr = 0;
78 float max_ratio = 0.0f;
79 for (
i = 0;
i < 2048;
i++) {
80 float corr, s0 = 0.0f, s1 = 0.0f;
81 const int start =
FFMAX(0,
i - 1024);
82 for (j = start; j < 2048; j++) {
83 const int idx = j -
i + 1024;
84 s0 += new[j]*buf[idx];
85 s1 += buf[idx]*buf[idx];
86 }
87 corr = s1 > 0.0f ? s0/sqrt(s1) : 0.0f;
88 if (corr > max_corr) {
89 max_corr = corr;
91 max_ratio = corr/(2048-start);
92 }
93 }
97 }
98
100 {
101 int i, samples_num = 2048;
104 return;
105 }
else if (ltp->
lag < 1024) {
106 samples_num = ltp->
lag + 1024;
107 }
108 for (
i = 0;
i < samples_num;
i++)
109 buf[
i] = ltp->
coef*buf[
i + 2048 - ltp->
lag];
110 memset(&buf[
i], 0, (2048 -
i)*
sizeof(
float));
111 }
112
113 /**
114 * Process LTP parameters
115 * @see Patent WO2006070265A1
116 */
118 {
120 const float *
samples = &
s->planar_samples[
s->cur_channel][1024];
121
123 return;
124
125 /* Calculate lag */
128 }
129
131 {
132 int sfb, count = 0;
135
140 return;
141 }
142
145 if (sum != 2) {
147 } else {
148 count++;
149 }
150 }
151
154 }
155
156 /**
157 * Mark LTP sfb's
158 */
160 int common_window)
161 {
162 int w,
g, w2,
i, start = 0, count = 0;
164 float *C34 = &
s->scoefs[128*0], *PCD = &
s->scoefs[128*1];
165 float *PCD34 = &
s->scoefs[128*2];
167
172 }
173 return;
174 }
175
177 return;
178
180 start = 0;
184 if (
w*16+
g > max_ltp) {
186 continue;
187 }
189 int bits_tmp1, bits_tmp2;
190 FFPsyBand *band = &
s->psy.ch[
s->cur_channel].psy_bands[(
w+w2)*16+
g];
204 }
211 count++;
212 }
214 }
215 }
216
219
220 /* Reset any marked sfbs */
223 start = 0;
229 }
230 }
231 }
233 }
234 }
235 }
236 }