annotate libfaad2/tns.c @ 10764:06ebe990fa92

Ignore .depend.
author diego
date Sun, 31 Aug 2003 23:07:28 +0000
parents e989150f8216
children 3185f64f6350
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
25 ** $Id: tns.c,v 1.21 2003/07/29 08:20:14 menno Exp $
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #include "tns.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 static real_t tns_coef_0_3[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 0x0, 0x6F13013, 0xC8261BA, 0xF994E02,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 0xF03E3A3A, 0xF224C28C, 0xF5B72457, 0xFA8715E3,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 0xF90ECFED, 0xF37D9E46, 0xF066B1FE, 0xF066B1FE,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 0xF03E3A3A, 0xF224C28C, 0xF5B72457, 0xFA8715E3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 static real_t tns_coef_0_4[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 0x0, 0x3539B35, 0x681FE48, 0x9679182,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 0xBE3EBD4, 0xDDB3D74, 0xF378709, 0xFE98FCA,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 0xF011790B, 0xF09C5CB7, 0xF1AD6942, 0xF33B524A,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 0xF5388AEB, 0xF793BBDF, 0xFA385AA9, 0xFD0F5CAB
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 static real_t tns_coef_1_3[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 0x0, 0x6F13013, 0xF5B72457, 0xFA8715E3,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 0xF994E02, 0xC8261BA, 0xF5B72457, 0xFA8715E3,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 0xF90ECFED, 0xF37D9E46, 0xF5B72457, 0xFA8715E3,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 0xF37D9E46, 0xF90ECFED, 0xF5B72457, 0xFA8715E3
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 static real_t tns_coef_1_4[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 0x0, 0x3539B35, 0x681FE48, 0x9679182,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 0xF5388AEB, 0xF793BBDF, 0xFA385AA9, 0xFD0F5CAB,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 0xFE98FCA, 0xF378709, 0xDDB3D74, 0xBE3EBD4,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 0xF5388AEB, 0xF793BBDF, 0xFA385AA9, 0xFD0F5CAB
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 #ifdef _MSC_VER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 #pragma warning(disable:4305)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 #pragma warning(disable:4244)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 static real_t tns_coef_0_3[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 0.0, 0.4338837391, 0.7818314825, 0.9749279122,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 -0.9848077530, -0.8660254038, -0.6427876097, -0.3420201433,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 -0.4338837391, -0.7818314825, -0.9749279122, -0.9749279122,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 -0.9848077530, -0.8660254038, -0.6427876097, -0.3420201433
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 static real_t tns_coef_0_4[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 0.0, 0.2079116908, 0.4067366431, 0.5877852523,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 0.7431448255, 0.8660254038, 0.9510565163, 0.9945218954,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 -0.9957341763, -0.9618256432, -0.8951632914, -0.7980172273,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 -0.6736956436, -0.5264321629, -0.3612416662, -0.1837495178
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 static real_t tns_coef_1_3[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 0.0, 0.4338837391, -0.6427876097, -0.3420201433,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 0.9749279122, 0.7818314825, -0.6427876097, -0.3420201433,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 -0.4338837391, -0.7818314825, -0.6427876097, -0.3420201433,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 -0.7818314825, -0.4338837391, -0.6427876097, -0.3420201433
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 static real_t tns_coef_1_4[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 0.0, 0.2079116908, 0.4067366431, 0.5877852523,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 -0.6736956436, -0.5264321629, -0.3612416662, -0.1837495178,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 0.9945218954, 0.9510565163, 0.8660254038, 0.7431448255,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 -0.6736956436, -0.5264321629, -0.3612416662, -0.1837495178
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 /* TNS decoding for one channel and frame */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 uint8_t object_type, real_t *spec, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 uint8_t w, f, tns_order;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 int8_t inc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 uint16_t bottom, top, start, end, size;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 uint16_t nshort = frame_len/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 real_t lpc[TNS_MAX_ORDER+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 if (!ics->tns_data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 for (w = 0; w < ics->num_windows; w++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 bottom = ics->num_swb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 for (f = 0; f < tns->n_filt[w]; f++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 top = bottom;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 bottom = max(top - tns->length[w][f], 0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 if (!tns_order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 continue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 tns_decode_coef(tns_order, tns->coef_res[w]+3,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 tns->coef_compress[w][f], tns->coef[w][f], lpc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 start = ics->swb_offset[min(bottom, ics->max_sfb)];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 end = ics->swb_offset[min(top, ics->max_sfb)];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 if ((size = end - start) <= 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 continue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 if (tns->direction[w][f])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 inc = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 start = end - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 inc = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 tns_ar_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 /* TNS encoding for one channel and frame */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 uint8_t object_type, real_t *spec, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 uint8_t w, f, tns_order;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 int8_t inc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 uint16_t bottom, top, start, end, size;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 uint16_t nshort = frame_len/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 real_t lpc[TNS_MAX_ORDER+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 if (!ics->tns_data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 for (w = 0; w < ics->num_windows; w++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 bottom = ics->num_swb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 for (f = 0; f < tns->n_filt[w]; f++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 top = bottom;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 bottom = max(top - tns->length[w][f], 0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 if (!tns_order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 continue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 tns_decode_coef(tns_order, tns->coef_res[w]+3,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 tns->coef_compress[w][f], tns->coef[w][f], lpc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 start = ics->swb_offset[min(bottom, ics->max_sfb)];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 end = ics->swb_offset[min(top, ics->max_sfb)];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 if ((size = end - start) <= 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 continue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 if (tns->direction[w][f])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 inc = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 start = end - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 inc = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 tns_ma_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 /* Decoder transmitted coefficients for one TNS filter */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 static void tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_compress,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 uint8_t *coef, real_t *a)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 uint8_t i, m;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 /* Conversion to signed integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 for (i = 0; i < order; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 if (coef_compress == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 if (coef_res_bits == 3)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 tmp2[i] = tns_coef_0_3[coef[i]];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 tmp2[i] = tns_coef_0_4[coef[i]];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 if (coef_res_bits == 3)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 tmp2[i] = tns_coef_1_3[coef[i]];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 tmp2[i] = tns_coef_1_4[coef[i]];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 /* Conversion to LPC coefficients */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 a[0] = COEF_CONST(1.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 for (m = 1; m <= order; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 for (i = 1; i < m; i++) /* loop only while i<m */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 b[i] = a[i] + MUL_C_C(tmp2[m-1], a[m-i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 for (i = 1; i < m; i++) /* loop only while i<m */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 a[i] = b[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 a[m] = tmp2[m-1]; /* changed */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 uint8_t order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 - Simple all-pole filter of order "order" defined by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 y(n) = x(n) - lpc[1]*y(n-1) - ... - lpc[order]*y(n-order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 - The state variables of the filter are initialized to zero every time
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 - The output data is written over the input data ("in-place operation")
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 - An input vector of "size" samples is processed and the index increment
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 to the next data sample is given by "inc"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 uint8_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 real_t y, state[TNS_MAX_ORDER];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 for (i = 0; i < order; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 state[i] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 for (i = 0; i < size; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 y = *spectrum;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 for (j = 0; j < order; j++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 y -= MUL_R_C(state[j], lpc[j+1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 for (j = order-1; j > 0; j--)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 state[j] = state[j-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 state[0] = y;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 *spectrum = y;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 spectrum += inc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270 static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 uint8_t order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 - Simple all-zero filter of order "order" defined by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 y(n) = x(n) + a(2)*x(n-1) + ... + a(order+1)*x(n-order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 - The state variables of the filter are initialized to zero every time
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 - The output data is written over the input data ("in-place operation")
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 - An input vector of "size" samples is processed and the index increment
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 to the next data sample is given by "inc"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 uint8_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 real_t y, state[TNS_MAX_ORDER];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 for (i = 0; i < order; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 state[i] = REAL_CONST(0.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 for (i = 0; i < size; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 y = *spectrum;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 for (j = 0; j < order; j++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 y += MUL_R_C(state[j], lpc[j+1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 for (j = order-1; j > 0; j--)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 state[j] = state[j-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 state[0] = *spectrum;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 *spectrum = y;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 spectrum += inc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 }