/proc/self/cwd/libfaad/lt_predict.c
Line | Count | Source |
1 | | /* |
2 | | ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding |
3 | | ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com |
4 | | ** |
5 | | ** This program is free software; you can redistribute it and/or modify |
6 | | ** it under the terms of the GNU General Public License as published by |
7 | | ** the Free Software Foundation; either version 2 of the License, or |
8 | | ** (at your option) any later version. |
9 | | ** |
10 | | ** This program is distributed in the hope that it will be useful, |
11 | | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | ** GNU General Public License for more details. |
14 | | ** |
15 | | ** You should have received a copy of the GNU General Public License |
16 | | ** along with this program; if not, write to the Free Software |
17 | | ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | | ** |
19 | | ** Any non-GPL usage of this software or parts of this software is strictly |
20 | | ** forbidden. |
21 | | ** |
22 | | ** The "appropriate copyright message" mentioned in section 2c of the GPLv2 |
23 | | ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com" |
24 | | ** |
25 | | ** Commercial non-GPL licensing of this software is possible. |
26 | | ** For more info contact Nero AG through Mpeg4AAClicense@nero.com. |
27 | | ** |
28 | | ** $Id: lt_predict.c,v 1.27 2007/11/01 12:33:31 menno Exp $ |
29 | | **/ |
30 | | |
31 | | |
32 | | #include "common.h" |
33 | | #include "structs.h" |
34 | | |
35 | | #ifdef LTP_DEC |
36 | | |
37 | | #include <stdlib.h> |
38 | | #include "syntax.h" |
39 | | #include "lt_predict.h" |
40 | | #include "filtbank.h" |
41 | | #include "tns.h" |
42 | | |
43 | | |
44 | | /* static function declarations */ |
45 | | static int16_t real_to_int16(real_t sig_in); |
46 | | |
47 | | |
48 | | /* check if the object type is an object type that can have LTP */ |
49 | | uint8_t is_ltp_ot(uint8_t object_type) |
50 | 1.42M | { |
51 | 1.42M | #ifdef LTP_DEC |
52 | 1.42M | if ((object_type == LTP) |
53 | 806k | #ifdef ERROR_RESILIENCE |
54 | 806k | || (object_type == ER_LTP) |
55 | 780k | #endif |
56 | 780k | #ifdef LD_DEC |
57 | 780k | || (object_type == LD) |
58 | 1.42M | #endif |
59 | 1.42M | ) |
60 | 651k | { |
61 | 651k | return 1; |
62 | 651k | } |
63 | 771k | #endif |
64 | | |
65 | 771k | return 0; |
66 | 1.42M | } |
67 | | |
68 | | ALIGN static const real_t codebook[8] = |
69 | | { |
70 | | REAL_CONST(0.570829), |
71 | | REAL_CONST(0.696616), |
72 | | REAL_CONST(0.813004), |
73 | | REAL_CONST(0.911304), |
74 | | REAL_CONST(0.984900), |
75 | | REAL_CONST(1.067894), |
76 | | REAL_CONST(1.194601), |
77 | | REAL_CONST(1.369533) |
78 | | }; |
79 | | |
80 | | void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec, |
81 | | int16_t *lt_pred_stat, fb_info *fb, uint8_t win_shape, |
82 | | uint8_t win_shape_prev, uint8_t sr_index, |
83 | | uint8_t object_type, uint16_t frame_len) |
84 | 242k | { |
85 | 242k | uint8_t sfb; |
86 | 242k | uint16_t bin, i, num_samples; |
87 | 242k | ALIGN real_t x_est[2048]; |
88 | 242k | ALIGN real_t X_est[2048]; |
89 | | |
90 | 242k | if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) |
91 | 227k | { |
92 | 227k | if (ltp->data_present) |
93 | 15.2k | { |
94 | 15.2k | num_samples = frame_len << 1; |
95 | | |
96 | 29.5M | for(i = 0; i < num_samples; i++) |
97 | 29.4M | { |
98 | | /* The extra lookback M (N/2 for LD, 0 for LTP) is handled |
99 | | in the buffer updating */ |
100 | | |
101 | | #if 0 |
102 | | x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag], |
103 | | codebook[ltp->coef]); |
104 | | #else |
105 | | /* lt_pred_stat is a 16 bit int, multiplied with the fixed point real |
106 | | this gives a real for x_est |
107 | | */ |
108 | 29.4M | x_est[i] = (real_t)lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef]; |
109 | 29.4M | #endif |
110 | 29.4M | } |
111 | | |
112 | 15.2k | filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev, |
113 | 15.2k | x_est, X_est, object_type, frame_len); |
114 | | |
115 | 15.2k | tns_encode_frame(ics, &(ics->tns), sr_index, object_type, X_est, |
116 | 15.2k | frame_len); |
117 | | |
118 | 31.5k | for (sfb = 0; sfb < ltp->last_band; sfb++) |
119 | 16.3k | { |
120 | 16.3k | if (ltp->long_used[sfb]) |
121 | 8.32k | { |
122 | 8.32k | uint16_t low = ics->swb_offset[sfb]; |
123 | 8.32k | uint16_t high = min(ics->swb_offset[sfb+1], ics->swb_offset_max); |
124 | | |
125 | 132k | for (bin = low; bin < high; bin++) |
126 | 124k | { |
127 | 124k | spec[bin] += X_est[bin]; |
128 | 124k | } |
129 | 8.32k | } |
130 | 16.3k | } |
131 | 15.2k | } |
132 | 227k | } |
133 | 242k | } |
134 | | |
135 | | #ifdef FIXED_POINT |
136 | | static INLINE int16_t real_to_int16(real_t sig_in) |
137 | 326M | { |
138 | 326M | if (sig_in >= 0) |
139 | 324M | { |
140 | 324M | if (sig_in <= 0x7FFFFFFF - (1 << (REAL_BITS-1))) |
141 | 324M | sig_in += (1 << (REAL_BITS-1)); |
142 | 324M | if (sig_in >= REAL_CONST(32768)) |
143 | 259k | return 32767; |
144 | 324M | } else { |
145 | 2.04M | if (sig_in >= (int32_t)0x80000000 + (1 << (REAL_BITS-1))) |
146 | 2.04M | sig_in += -(1 << (REAL_BITS-1)); |
147 | 2.04M | if (sig_in <= REAL_CONST(-32768)) |
148 | 215k | return -32768; |
149 | 2.04M | } |
150 | | |
151 | 326M | return (int16_t)(sig_in >> REAL_BITS); |
152 | 326M | } |
153 | | #else |
154 | | static INLINE int16_t real_to_int16(real_t sig_in) |
155 | 159M | { |
156 | 159M | if (sig_in >= 0) |
157 | 156M | { |
158 | 156M | #ifndef HAS_LRINTF |
159 | 156M | sig_in += 0.5f; |
160 | 156M | #endif |
161 | 156M | if (sig_in >= 32768.0f) |
162 | 451k | return 32767; |
163 | 156M | } else { |
164 | 3.38M | #ifndef HAS_LRINTF |
165 | 3.38M | sig_in += -0.5f; |
166 | 3.38M | #endif |
167 | 3.38M | if (sig_in <= -32768.0f) |
168 | 450k | return -32768; |
169 | 3.38M | } |
170 | | |
171 | 159M | return (int16_t)lrintf(sig_in); |
172 | 159M | } |
173 | | #endif |
174 | | |
175 | | void lt_update_state(int16_t *lt_pred_stat, real_t *time, real_t *overlap, |
176 | | uint16_t frame_len, uint8_t object_type) |
177 | 242k | { |
178 | 242k | uint16_t i; |
179 | | |
180 | | /* |
181 | | * The reference point for index i and the content of the buffer |
182 | | * lt_pred_stat are arranged so that lt_pred_stat(0 ... N/2 - 1) contains the |
183 | | * last aliased half window from the IMDCT, and lt_pred_stat(N/2 ... N-1) |
184 | | * is always all zeros. The rest of lt_pred_stat (i<0) contains the previous |
185 | | * fully reconstructed time domain samples, i.e., output of the decoder. |
186 | | * |
187 | | * These values are shifted up by N*2 to avoid (i<0) |
188 | | * |
189 | | * For the LD object type an extra 512 samples lookback is accomodated here. |
190 | | */ |
191 | 242k | #ifdef LD_DEC |
192 | 242k | if (object_type == LD) |
193 | 5.25k | { |
194 | 2.59M | for (i = 0; i < frame_len; i++) |
195 | 2.59M | { |
196 | 2.59M | lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len]; |
197 | 2.59M | lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)]; |
198 | 2.59M | lt_pred_stat[(frame_len * 2) + i] = real_to_int16(time[i]); |
199 | 2.59M | lt_pred_stat[(frame_len * 3) + i] = real_to_int16(overlap[i]); |
200 | 2.59M | } |
201 | 236k | } else { |
202 | 236k | #endif |
203 | 240M | for (i = 0; i < frame_len; i++) |
204 | 240M | { |
205 | 240M | lt_pred_stat[i] = lt_pred_stat[i + frame_len]; |
206 | 240M | lt_pred_stat[frame_len + i] = real_to_int16(time[i]); |
207 | 240M | lt_pred_stat[(frame_len * 2) + i] = real_to_int16(overlap[i]); |
208 | | #if 0 /* set to zero once upon initialisation */ |
209 | | lt_pred_stat[(frame_len * 3) + i] = 0; |
210 | | #endif |
211 | 240M | } |
212 | 236k | #ifdef LD_DEC |
213 | 236k | } |
214 | 242k | #endif |
215 | 242k | } |
216 | | |
217 | | #endif |