Mercurial > mplayer.hg
comparison libfaad2/lt_predict.c @ 12527:4a370c80fe5c
update to the 2.0 release of faad, patch by adland
author | diego |
---|---|
date | Wed, 02 Jun 2004 22:59:04 +0000 |
parents | 3185f64f6350 |
children | d81145997036 |
comparison
equal
deleted
inserted
replaced
12526:e183ad37d24c | 12527:4a370c80fe5c |
---|---|
1 /* | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | 2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding |
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
4 ** | 4 ** |
5 ** This program is free software; you can redistribute it and/or modify | 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 | 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 | 7 ** the Free Software Foundation; either version 2 of the License, or |
8 ** (at your option) any later version. | 8 ** (at your option) any later version. |
20 ** forbidden. | 20 ** forbidden. |
21 ** | 21 ** |
22 ** Commercial non-GPL licensing of this software is possible. | 22 ** Commercial non-GPL licensing of this software is possible. |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | 23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. |
24 ** | 24 ** |
25 ** $Id: lt_predict.c,v 1.12 2003/09/09 18:09:52 menno Exp $ | 25 ** $Id: lt_predict.c,v 1.2 2003/10/03 22:22:27 alex Exp $ |
26 **/ | 26 **/ |
27 | 27 |
28 | 28 |
29 #include "common.h" | 29 #include "common.h" |
30 #include "structs.h" | 30 #include "structs.h" |
35 #include "syntax.h" | 35 #include "syntax.h" |
36 #include "lt_predict.h" | 36 #include "lt_predict.h" |
37 #include "filtbank.h" | 37 #include "filtbank.h" |
38 #include "tns.h" | 38 #include "tns.h" |
39 | 39 |
40 static real_t codebook[8] = | 40 |
41 { | 41 /* static function declarations */ |
42 COEF_CONST(0.570829), | 42 static int16_t real_to_int16(real_t sig_in); |
43 COEF_CONST(0.696616), | 43 |
44 COEF_CONST(0.813004), | 44 |
45 COEF_CONST(0.911304), | 45 /* check if the object type is an object type that can have LTP */ |
46 COEF_CONST(0.984900), | 46 uint8_t is_ltp_ot(uint8_t object_type) |
47 COEF_CONST(1.067894), | 47 { |
48 COEF_CONST(1.194601), | 48 #ifdef LTP_DEC |
49 COEF_CONST(1.369533) | 49 if ((object_type == LTP) |
50 #ifdef ERROR_RESILIENCE | |
51 || (object_type == ER_LTP) | |
52 #endif | |
53 #ifdef LD_DEC | |
54 || (object_type == LD) | |
55 #endif | |
56 #ifdef SCALABLE_DEC | |
57 || (object_type == 6) /* TODO */ | |
58 #endif | |
59 ) | |
60 { | |
61 return 1; | |
62 } | |
63 #endif | |
64 | |
65 return 0; | |
66 } | |
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) | |
50 }; | 78 }; |
51 | 79 |
52 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec, | 80 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec, |
53 real_t *lt_pred_stat, fb_info *fb, uint8_t win_shape, | 81 int16_t *lt_pred_stat, fb_info *fb, uint8_t win_shape, |
54 uint8_t win_shape_prev, uint8_t sr_index, | 82 uint8_t win_shape_prev, uint8_t sr_index, |
55 uint8_t object_type, uint16_t frame_len) | 83 uint8_t object_type, uint16_t frame_len) |
56 { | 84 { |
57 uint8_t sfb; | 85 uint8_t sfb; |
58 uint16_t bin, i, num_samples; | 86 uint16_t bin, i, num_samples; |
59 real_t *x_est; | 87 ALIGN real_t x_est[2048]; |
60 real_t *X_est; | 88 ALIGN real_t X_est[2048]; |
61 | 89 |
62 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) | 90 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) |
63 { | 91 { |
64 if (ltp->data_present) | 92 if (ltp->data_present) |
65 { | 93 { |
66 num_samples = frame_len << 1; | 94 num_samples = frame_len << 1; |
67 | |
68 x_est = (real_t*)malloc(num_samples*sizeof(real_t)); | |
69 X_est = (real_t*)malloc(num_samples*sizeof(real_t)); | |
70 | 95 |
71 for(i = 0; i < num_samples; i++) | 96 for(i = 0; i < num_samples; i++) |
72 { | 97 { |
73 /* The extra lookback M (N/2 for LD, 0 for LTP) is handled | 98 /* The extra lookback M (N/2 for LD, 0 for LTP) is handled |
74 in the buffer updating */ | 99 in the buffer updating */ |
100 | |
101 #if 0 | |
75 x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag], | 102 x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag], |
76 codebook[ltp->coef]); | 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 x_est[i] = (real_t)lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef]; | |
109 #endif | |
77 } | 110 } |
78 | 111 |
79 filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev, | 112 filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev, |
80 x_est, X_est, object_type, frame_len); | 113 x_est, X_est, object_type, frame_len); |
81 | 114 |
93 { | 126 { |
94 spec[bin] += X_est[bin]; | 127 spec[bin] += X_est[bin]; |
95 } | 128 } |
96 } | 129 } |
97 } | 130 } |
98 | |
99 free(x_est); | |
100 free(X_est); | |
101 } | 131 } |
102 } | 132 } |
103 } | 133 } |
104 | 134 |
105 void lt_update_state(real_t *lt_pred_stat, real_t *time, real_t *overlap, | 135 #ifdef FIXED_POINT |
136 static INLINE int16_t real_to_int16(real_t sig_in) | |
137 { | |
138 if (sig_in >= 0) | |
139 { | |
140 sig_in += (1 << (REAL_BITS-1)); | |
141 if (sig_in >= REAL_CONST(32768)) | |
142 return 32767; | |
143 } else { | |
144 sig_in += -(1 << (REAL_BITS-1)); | |
145 if (sig_in <= REAL_CONST(-32768)) | |
146 return -32768; | |
147 } | |
148 | |
149 return (sig_in >> REAL_BITS); | |
150 } | |
151 #else | |
152 static INLINE int16_t real_to_int16(real_t sig_in) | |
153 { | |
154 if (sig_in >= 0) | |
155 { | |
156 #ifndef HAS_LRINTF | |
157 sig_in += 0.5f; | |
158 #endif | |
159 if (sig_in >= 32768.0f) | |
160 return 32767; | |
161 } else { | |
162 #ifndef HAS_LRINTF | |
163 sig_in += -0.5f; | |
164 #endif | |
165 if (sig_in <= -32768.0f) | |
166 return -32768; | |
167 } | |
168 | |
169 return lrintf(sig_in); | |
170 } | |
171 #endif | |
172 | |
173 void lt_update_state(int16_t *lt_pred_stat, real_t *time, real_t *overlap, | |
106 uint16_t frame_len, uint8_t object_type) | 174 uint16_t frame_len, uint8_t object_type) |
107 { | 175 { |
108 uint16_t i; | 176 uint16_t i; |
109 | 177 |
110 /* | 178 /* |
123 { | 191 { |
124 for (i = 0; i < frame_len; i++) | 192 for (i = 0; i < frame_len; i++) |
125 { | 193 { |
126 lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len]; | 194 lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len]; |
127 lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)]; | 195 lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)]; |
128 lt_pred_stat[(frame_len * 2) + i] = time[i]; | 196 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(time[i]); |
129 lt_pred_stat[(frame_len * 3) + i] = overlap[i]; | 197 lt_pred_stat[(frame_len * 3) + i] = real_to_int16(overlap[i]); |
130 } | 198 } |
131 } else { | 199 } else { |
132 #endif | 200 #endif |
133 for (i = 0; i < frame_len; i++) | 201 for (i = 0; i < frame_len; i++) |
134 { | 202 { |
135 lt_pred_stat[i] = lt_pred_stat[i + frame_len]; | 203 lt_pred_stat[i] = lt_pred_stat[i + frame_len]; |
136 lt_pred_stat[frame_len + i] = time[i]; | 204 lt_pred_stat[frame_len + i] = real_to_int16(time[i]); |
137 lt_pred_stat[(frame_len * 2) + i] = overlap[i]; | 205 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(overlap[i]); |
138 #if 0 /* set to zero once upon initialisation */ | 206 #if 0 /* set to zero once upon initialisation */ |
139 lt_pred_stat[(frame_len * 3) + i] = 0; | 207 lt_pred_stat[(frame_len * 3) + i] = 0; |
140 #endif | 208 #endif |
141 } | 209 } |
142 #ifdef LD_DEC | 210 #ifdef LD_DEC |