Mercurial > audlegacy
comparison Plugins/Input/aac/libfaad2/lt_predict.c @ 61:fa848bd484d8 trunk
[svn] Move plugins to Plugins/
author | nenolod |
---|---|
date | Fri, 28 Oct 2005 22:58:11 -0700 |
parents | |
children | 0a2ad94e8607 |
comparison
equal
deleted
inserted
replaced
60:1771f253e1b2 | 61:fa848bd484d8 |
---|---|
1 /* | |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
3 ** Copyright (C) 2003 M. Bakker, Ahead Software 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 ** Commercial non-GPL licensing of this software is possible. | |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
24 ** | |
25 ** $Id: lt_predict.c,v 1.18 2003/11/12 20:47:58 menno Exp $ | |
26 **/ | |
27 | |
28 | |
29 #include "common.h" | |
30 #include "structs.h" | |
31 | |
32 #ifdef LTP_DEC | |
33 | |
34 #include <stdlib.h> | |
35 #include "syntax.h" | |
36 #include "lt_predict.h" | |
37 #include "filtbank.h" | |
38 #include "tns.h" | |
39 | |
40 /* check if the object type is an object type that can have LTP */ | |
41 uint8_t is_ltp_ot(uint8_t object_type) | |
42 { | |
43 #ifdef LTP_DEC | |
44 if ((object_type == LTP) | |
45 #ifdef ERROR_RESILIENCE | |
46 || (object_type == ER_LTP) | |
47 #endif | |
48 #ifdef LD_DEC | |
49 || (object_type == LD) | |
50 #endif | |
51 ) | |
52 { | |
53 return 1; | |
54 } | |
55 #endif | |
56 | |
57 return 0; | |
58 } | |
59 | |
60 static real_t codebook[8] = | |
61 { | |
62 REAL_CONST(0.570829), | |
63 REAL_CONST(0.696616), | |
64 REAL_CONST(0.813004), | |
65 REAL_CONST(0.911304), | |
66 REAL_CONST(0.984900), | |
67 REAL_CONST(1.067894), | |
68 REAL_CONST(1.194601), | |
69 REAL_CONST(1.369533) | |
70 }; | |
71 | |
72 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec, | |
73 int16_t *lt_pred_stat, fb_info *fb, uint8_t win_shape, | |
74 uint8_t win_shape_prev, uint8_t sr_index, | |
75 uint8_t object_type, uint16_t frame_len) | |
76 { | |
77 uint8_t sfb; | |
78 uint16_t bin, i, num_samples; | |
79 real_t x_est[2048]; | |
80 real_t X_est[2048]; | |
81 | |
82 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) | |
83 { | |
84 if (ltp->data_present) | |
85 { | |
86 num_samples = frame_len << 1; | |
87 | |
88 for(i = 0; i < num_samples; i++) | |
89 { | |
90 /* The extra lookback M (N/2 for LD, 0 for LTP) is handled | |
91 in the buffer updating */ | |
92 | |
93 #if 0 | |
94 x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag], | |
95 codebook[ltp->coef]); | |
96 #else | |
97 /* lt_pred_stat is a 16 bit int, multiplied with the fixed point real | |
98 this gives a real for x_est | |
99 */ | |
100 x_est[i] = (real_t)lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef]; | |
101 #endif | |
102 } | |
103 | |
104 filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev, | |
105 x_est, X_est, object_type, frame_len); | |
106 | |
107 tns_encode_frame(ics, &(ics->tns), sr_index, object_type, X_est, | |
108 frame_len); | |
109 | |
110 for (sfb = 0; sfb < ltp->last_band; sfb++) | |
111 { | |
112 if (ltp->long_used[sfb]) | |
113 { | |
114 uint16_t low = ics->swb_offset[sfb]; | |
115 uint16_t high = ics->swb_offset[sfb+1]; | |
116 | |
117 for (bin = low; bin < high; bin++) | |
118 { | |
119 spec[bin] += X_est[bin]; | |
120 } | |
121 } | |
122 } | |
123 } | |
124 } | |
125 } | |
126 | |
127 #ifdef FIXED_POINT | |
128 INLINE int16_t real_to_int16(real_t sig_in) | |
129 { | |
130 if (sig_in >= 0) | |
131 { | |
132 sig_in += (1 << (REAL_BITS-1)); | |
133 if (sig_in > REAL_CONST(32767)) | |
134 sig_in = 32767.0f; | |
135 } else { | |
136 sig_in += -(1 << (REAL_BITS-1)); | |
137 if (sig_in < REAL_CONST(-32768)) | |
138 sig_in = -32768.0f; | |
139 } | |
140 | |
141 return (sig_in >> REAL_BITS); | |
142 } | |
143 #else | |
144 INLINE int16_t real_to_int16(real_t sig_in) | |
145 { | |
146 if (sig_in >= 0) | |
147 { | |
148 #ifndef HAS_LRINTF | |
149 sig_in += 0.5f; | |
150 #endif | |
151 if (sig_in > REAL_CONST(32767)) | |
152 sig_in = 32767.0f; | |
153 } else { | |
154 #ifndef HAS_LRINTF | |
155 sig_in -= 0.5f; | |
156 #endif | |
157 if (sig_in < REAL_CONST(-32768)) | |
158 sig_in = -32768.0f; | |
159 } | |
160 | |
161 return lrintf(sig_in); | |
162 } | |
163 #endif | |
164 | |
165 void lt_update_state(int16_t *lt_pred_stat, real_t *time, real_t *overlap, | |
166 uint16_t frame_len, uint8_t object_type) | |
167 { | |
168 uint16_t i; | |
169 | |
170 /* | |
171 * The reference point for index i and the content of the buffer | |
172 * lt_pred_stat are arranged so that lt_pred_stat(0 ... N/2 - 1) contains the | |
173 * last aliased half window from the IMDCT, and lt_pred_stat(N/2 ... N-1) | |
174 * is always all zeros. The rest of lt_pred_stat (i<0) contains the previous | |
175 * fully reconstructed time domain samples, i.e., output of the decoder. | |
176 * | |
177 * These values are shifted up by N*2 to avoid (i<0) | |
178 * | |
179 * For the LD object type an extra 512 samples lookback is accomodated here. | |
180 */ | |
181 #ifdef LD_DEC | |
182 if (object_type == LD) | |
183 { | |
184 for (i = 0; i < frame_len; i++) | |
185 { | |
186 lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len]; | |
187 lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)]; | |
188 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(time[i]); | |
189 lt_pred_stat[(frame_len * 3) + i] = real_to_int16(overlap[i]); | |
190 } | |
191 } else { | |
192 #endif | |
193 for (i = 0; i < frame_len; i++) | |
194 { | |
195 lt_pred_stat[i] = lt_pred_stat[i + frame_len]; | |
196 lt_pred_stat[frame_len + i] = real_to_int16(time[i]); | |
197 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(overlap[i]); | |
198 #if 0 /* set to zero once upon initialisation */ | |
199 lt_pred_stat[(frame_len * 3) + i] = 0; | |
200 #endif | |
201 } | |
202 #ifdef LD_DEC | |
203 } | |
204 #endif | |
205 } | |
206 | |
207 #endif |