comparison libfaad2/tns.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: tns.c,v 1.22 2003/09/09 18:09:52 menno Exp $ 25 ** $Id: tns.c,v 1.2 2003/10/03 22:22:27 alex Exp $
26 **/ 26 **/
27 27
28 #include "common.h" 28 #include "common.h"
29 #include "structs.h" 29 #include "structs.h"
30 30
31 #include "syntax.h" 31 #include "syntax.h"
32 #include "tns.h" 32 #include "tns.h"
33
34
35 /* static function declarations */
36 static void tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_compress,
37 uint8_t *coef, real_t *a);
38 static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
39 uint8_t order);
40 static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
41 uint8_t order);
42
33 43
34 #ifdef _MSC_VER 44 #ifdef _MSC_VER
35 #pragma warning(disable:4305) 45 #pragma warning(disable:4305)
36 #pragma warning(disable:4244) 46 #pragma warning(disable:4244)
37 #endif 47 #endif
69 void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index, 79 void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
70 uint8_t object_type, real_t *spec, uint16_t frame_len) 80 uint8_t object_type, real_t *spec, uint16_t frame_len)
71 { 81 {
72 uint8_t w, f, tns_order; 82 uint8_t w, f, tns_order;
73 int8_t inc; 83 int8_t inc;
74 uint16_t bottom, top, start, end, size; 84 int16_t size;
85 uint16_t bottom, top, start, end;
75 uint16_t nshort = frame_len/8; 86 uint16_t nshort = frame_len/8;
76 real_t lpc[TNS_MAX_ORDER+1]; 87 real_t lpc[TNS_MAX_ORDER+1];
77 88
78 if (!ics->tns_data_present) 89 if (!ics->tns_data_present)
79 return; 90 return;
91 continue; 102 continue;
92 103
93 tns_decode_coef(tns_order, tns->coef_res[w]+3, 104 tns_decode_coef(tns_order, tns->coef_res[w]+3,
94 tns->coef_compress[w][f], tns->coef[w][f], lpc); 105 tns->coef_compress[w][f], tns->coef[w][f], lpc);
95 106
96 start = ics->swb_offset[min(bottom, ics->max_sfb)]; 107 start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
97 end = ics->swb_offset[min(top, ics->max_sfb)]; 108 start = min(start, ics->max_sfb);
98 109 start = ics->swb_offset[start];
99 if ((size = end - start) <= 0) 110
111 end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
112 end = min(end, ics->max_sfb);
113 end = ics->swb_offset[end];
114
115 size = end - start;
116 if (size <= 0)
100 continue; 117 continue;
101 118
102 if (tns->direction[w][f]) 119 if (tns->direction[w][f])
103 { 120 {
104 inc = -1; 121 inc = -1;
116 void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index, 133 void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
117 uint8_t object_type, real_t *spec, uint16_t frame_len) 134 uint8_t object_type, real_t *spec, uint16_t frame_len)
118 { 135 {
119 uint8_t w, f, tns_order; 136 uint8_t w, f, tns_order;
120 int8_t inc; 137 int8_t inc;
121 uint16_t bottom, top, start, end, size; 138 int16_t size;
139 uint16_t bottom, top, start, end;
122 uint16_t nshort = frame_len/8; 140 uint16_t nshort = frame_len/8;
123 real_t lpc[TNS_MAX_ORDER+1]; 141 real_t lpc[TNS_MAX_ORDER+1];
124 142
125 if (!ics->tns_data_present) 143 if (!ics->tns_data_present)
126 return; 144 return;
138 continue; 156 continue;
139 157
140 tns_decode_coef(tns_order, tns->coef_res[w]+3, 158 tns_decode_coef(tns_order, tns->coef_res[w]+3,
141 tns->coef_compress[w][f], tns->coef[w][f], lpc); 159 tns->coef_compress[w][f], tns->coef[w][f], lpc);
142 160
143 start = ics->swb_offset[min(bottom, ics->max_sfb)]; 161 start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
144 end = ics->swb_offset[min(top, ics->max_sfb)]; 162 start = min(start, ics->max_sfb);
145 163 start = ics->swb_offset[start];
146 if ((size = end - start) <= 0) 164
165 end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
166 end = min(end, ics->max_sfb);
167 end = ics->swb_offset[end];
168
169 size = end - start;
170 if (size <= 0)
147 continue; 171 continue;
148 172
149 if (tns->direction[w][f]) 173 if (tns->direction[w][f])
150 { 174 {
151 inc = -1; 175 inc = -1;
190 /* Conversion to LPC coefficients */ 214 /* Conversion to LPC coefficients */
191 a[0] = COEF_CONST(1.0); 215 a[0] = COEF_CONST(1.0);
192 for (m = 1; m <= order; m++) 216 for (m = 1; m <= order; m++)
193 { 217 {
194 for (i = 1; i < m; i++) /* loop only while i<m */ 218 for (i = 1; i < m; i++) /* loop only while i<m */
195 b[i] = a[i] + MUL_C_C(tmp2[m-1], a[m-i]); 219 b[i] = a[i] + MUL_C(tmp2[m-1], a[m-i]);
196 220
197 for (i = 1; i < m; i++) /* loop only while i<m */ 221 for (i = 1; i < m; i++) /* loop only while i<m */
198 a[i] = b[i]; 222 a[i] = b[i];
199 223
200 a[m] = tmp2[m-1]; /* changed */ 224 a[m] = tmp2[m-1]; /* changed */
223 for (i = 0; i < size; i++) 247 for (i = 0; i < size; i++)
224 { 248 {
225 y = *spectrum; 249 y = *spectrum;
226 250
227 for (j = 0; j < order; j++) 251 for (j = 0; j < order; j++)
228 y -= MUL_R_C(state[j], lpc[j+1]); 252 y -= MUL_C(state[j], lpc[j+1]);
229 253
230 for (j = order-1; j > 0; j--) 254 for (j = order-1; j > 0; j--)
231 state[j] = state[j-1]; 255 state[j] = state[j-1];
232 256
233 state[0] = y; 257 state[0] = y;
258 for (i = 0; i < size; i++) 282 for (i = 0; i < size; i++)
259 { 283 {
260 y = *spectrum; 284 y = *spectrum;
261 285
262 for (j = 0; j < order; j++) 286 for (j = 0; j < order; j++)
263 y += MUL_R_C(state[j], lpc[j+1]); 287 y += MUL_C(state[j], lpc[j+1]);
264 288
265 for (j = order-1; j > 0; j--) 289 for (j = order-1; j > 0; j--)
266 state[j] = state[j-1]; 290 state[j] = state[j-1];
267 291
268 state[0] = *spectrum; 292 state[0] = *spectrum;