annotate libfaad2/tns.c @ 29017:c9a2d95c580a

New vdpau deinterlacing code needs one reference surface less.
author cehoyos
date Tue, 24 Mar 2009 21:47:56 +0000
parents 59b6fa5b4201
children e83eef58b30a
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
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
10725
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 **
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
25 ** $Id: tns.c,v 1.35 2004/09/04 14:56:29 menno Exp $
10725
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
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
34
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
35 /* static function declarations */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
36 static void tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_compress,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
37 uint8_t *coef, real_t *a);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
38 static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
39 uint8_t order);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
40 static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
41 uint8_t order);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
42
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
43
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 #ifdef _MSC_VER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 #pragma warning(disable:4305)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 #pragma warning(disable:4244)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 static real_t tns_coef_0_3[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
50 COEF_CONST(0.0), COEF_CONST(0.4338837391), COEF_CONST(0.7818314825), COEF_CONST(0.9749279122),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
51 COEF_CONST(-0.9848077530), COEF_CONST(-0.8660254038), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
52 COEF_CONST(-0.4338837391), COEF_CONST(-0.7818314825), COEF_CONST(-0.9749279122), COEF_CONST(-0.9749279122),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
53 COEF_CONST(-0.9848077530), COEF_CONST(-0.8660254038), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 static real_t tns_coef_0_4[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
57 COEF_CONST(0.0), COEF_CONST(0.2079116908), COEF_CONST(0.4067366431), COEF_CONST(0.5877852523),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
58 COEF_CONST(0.7431448255), COEF_CONST(0.8660254038), COEF_CONST(0.9510565163), COEF_CONST(0.9945218954),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
59 COEF_CONST(-0.9957341763), COEF_CONST(-0.9618256432), COEF_CONST(-0.8951632914), COEF_CONST(-0.7980172273),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
60 COEF_CONST(-0.6736956436), COEF_CONST(-0.5264321629), COEF_CONST(-0.3612416662), COEF_CONST(-0.1837495178)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 static real_t tns_coef_1_3[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
64 COEF_CONST(0.0), COEF_CONST(0.4338837391), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
65 COEF_CONST(0.9749279122), COEF_CONST(0.7818314825), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
66 COEF_CONST(-0.4338837391), COEF_CONST(-0.7818314825), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
67 COEF_CONST(-0.7818314825), COEF_CONST(-0.4338837391), COEF_CONST(-0.6427876097), COEF_CONST(-0.3420201433)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 static real_t tns_coef_1_4[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
71 COEF_CONST(0.0), COEF_CONST(0.2079116908), COEF_CONST(0.4067366431), COEF_CONST(0.5877852523),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
72 COEF_CONST(-0.6736956436), COEF_CONST(-0.5264321629), COEF_CONST(-0.3612416662), COEF_CONST(-0.1837495178),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
73 COEF_CONST(0.9945218954), COEF_CONST(0.9510565163), COEF_CONST(0.8660254038), COEF_CONST(0.7431448255),
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
74 COEF_CONST(-0.6736956436), COEF_CONST(-0.5264321629), COEF_CONST(-0.3612416662), COEF_CONST(-0.1837495178)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 /* TNS decoding for one channel and frame */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 uint8_t object_type, real_t *spec, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 uint8_t w, f, tns_order;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 int8_t inc;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
84 int16_t size;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
85 uint16_t bottom, top, start, end;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 uint16_t nshort = frame_len/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 real_t lpc[TNS_MAX_ORDER+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 if (!ics->tns_data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 for (w = 0; w < ics->num_windows; w++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 bottom = ics->num_swb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 for (f = 0; f < tns->n_filt[w]; f++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 top = bottom;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 bottom = max(top - tns->length[w][f], 0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 if (!tns_order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 continue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 tns_decode_coef(tns_order, tns->coef_res[w]+3,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 tns->coef_compress[w][f], tns->coef[w][f], lpc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
107 start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
108 start = min(start, ics->max_sfb);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
109 start = ics->swb_offset[start];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
111 end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
112 end = min(end, ics->max_sfb);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
113 end = ics->swb_offset[end];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
114
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
115 size = end - start;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
116 if (size <= 0)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 continue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 if (tns->direction[w][f])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 inc = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 start = end - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 inc = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 tns_ar_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 /* TNS encoding for one channel and frame */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 uint8_t object_type, real_t *spec, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 uint8_t w, f, tns_order;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 int8_t inc;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
138 int16_t size;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
139 uint16_t bottom, top, start, end;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 uint16_t nshort = frame_len/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 real_t lpc[TNS_MAX_ORDER+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 if (!ics->tns_data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 for (w = 0; w < ics->num_windows; w++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 bottom = ics->num_swb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 for (f = 0; f < tns->n_filt[w]; f++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 top = bottom;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 bottom = max(top - tns->length[w][f], 0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 if (!tns_order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 continue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 tns_decode_coef(tns_order, tns->coef_res[w]+3,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 tns->coef_compress[w][f], tns->coef[w][f], lpc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
161 start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
162 start = min(start, ics->max_sfb);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
163 start = ics->swb_offset[start];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
165 end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
166 end = min(end, ics->max_sfb);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
167 end = ics->swb_offset[end];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
168
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
169 size = end - start;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
170 if (size <= 0)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 continue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 if (tns->direction[w][f])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 inc = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 start = end - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 inc = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 tns_ma_filter(&spec[(w*nshort)+start], size, inc, lpc, tns_order);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 /* Decoder transmitted coefficients for one TNS filter */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 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
188 uint8_t *coef, real_t *a)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 uint8_t i, m;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 /* Conversion to signed integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 for (i = 0; i < order; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 if (coef_compress == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 if (coef_res_bits == 3)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 tmp2[i] = tns_coef_0_3[coef[i]];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 tmp2[i] = tns_coef_0_4[coef[i]];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 } else {
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_1_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_1_4[coef[i]];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 /* Conversion to LPC coefficients */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 a[0] = COEF_CONST(1.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 for (m = 1; m <= order; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 for (i = 1; i < m; i++) /* loop only while i<m */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
219 b[i] = a[i] + MUL_C(tmp2[m-1], a[m-i]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 for (i = 1; i < m; i++) /* loop only while i<m */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 a[i] = b[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 a[m] = tmp2[m-1]; /* changed */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 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
229 uint8_t order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 - Simple all-pole filter of order "order" defined by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 y(n) = x(n) - lpc[1]*y(n-1) - ... - lpc[order]*y(n-order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 - The state variables of the filter are initialized to zero every time
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 - The output data is written over the input data ("in-place operation")
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 - An input vector of "size" samples is processed and the index increment
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 to the next data sample is given by "inc"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 uint8_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 uint16_t i;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
242 real_t y;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
243 /* state is stored as a double ringbuffer */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
244 real_t state[2*TNS_MAX_ORDER] = {0};
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
245 int8_t state_index = 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 for (i = 0; i < size; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 y = *spectrum;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 for (j = 0; j < order; j++)
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
252 y -= MUL_C(state[state_index+j], lpc[j+1]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
254 /* double ringbuffer state */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
255 state_index--;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
256 if (state_index < 0)
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
257 state_index = order-1;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
258 state[state_index] = state[state_index + order] = y;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 *spectrum = y;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 spectrum += inc;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
262
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
263 //#define TNS_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
264 #ifdef TNS_PRINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
265 //printf("%d\n", y);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
266 printf("0x%.8X\n", y);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
267 #endif
10725
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
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 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
272 uint8_t order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 - Simple all-zero filter of order "order" defined by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 y(n) = x(n) + a(2)*x(n-1) + ... + a(order+1)*x(n-order)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 - The state variables of the filter are initialized to zero every time
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 - The output data is written over the input data ("in-place operation")
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 - An input vector of "size" samples is processed and the index increment
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 to the next data sample is given by "inc"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 uint8_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 uint16_t i;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
285 real_t y;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
286 /* state is stored as a double ringbuffer */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
287 real_t state[2*TNS_MAX_ORDER] = {0};
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
288 int8_t state_index = 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 for (i = 0; i < size; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 y = *spectrum;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 for (j = 0; j < order; j++)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
295 y += MUL_C(state[j], lpc[j+1]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
297 /* double ringbuffer state */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
298 state_index--;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
299 if (state_index < 0)
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
300 state_index = order-1;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
301 state[state_index] = state[state_index + order] = *spectrum;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 *spectrum = y;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 spectrum += inc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 }