Mercurial > audlegacy
comparison Plugins/Input/aac/libfaad2/specrec.c @ 199:0a2ad94e8607 trunk
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
author | chainsaw |
---|---|
date | Wed, 16 Nov 2005 16:21:11 -0800 |
parents | fa848bd484d8 |
children | 82872e29d7cb |
comparison
equal
deleted
inserted
replaced
198:5a338b31e393 | 199:0a2ad94e8607 |
---|---|
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. |
9 ** | 9 ** |
10 ** This program is distributed in the hope that it will be useful, | 10 ** This program is distributed in the hope that it will be useful, |
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 ** GNU General Public License for more details. | 13 ** GNU General Public License for more details. |
14 ** | 14 ** |
15 ** You should have received a copy of the GNU General Public License | 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 | 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. | 17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 ** | 18 ** |
19 ** Any non-GPL usage of this software or parts of this software is strictly | 19 ** Any non-GPL usage of this software or parts of this software is strictly |
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: specrec.c,v 1.33 2003/11/12 20:47:59 menno Exp $ | 25 ** $Id: specrec.c,v 1.56 2004/09/08 09:43:11 gcp Exp $ |
26 **/ | 26 **/ |
27 | 27 |
28 /* | 28 /* |
29 Spectral reconstruction: | 29 Spectral reconstruction: |
30 - grouping/sectioning | 30 - grouping/sectioning |
34 | 34 |
35 #include "common.h" | 35 #include "common.h" |
36 #include "structs.h" | 36 #include "structs.h" |
37 | 37 |
38 #include <string.h> | 38 #include <string.h> |
39 #include <stdlib.h> | |
39 #include "specrec.h" | 40 #include "specrec.h" |
41 #include "filtbank.h" | |
40 #include "syntax.h" | 42 #include "syntax.h" |
41 #include "iq_table.h" | 43 #include "iq_table.h" |
42 #include "ms.h" | 44 #include "ms.h" |
43 #include "is.h" | 45 #include "is.h" |
44 #include "pns.h" | 46 #include "pns.h" |
45 #include "tns.h" | 47 #include "tns.h" |
48 #include "drc.h" | |
46 #include "lt_predict.h" | 49 #include "lt_predict.h" |
47 #include "ic_predict.h" | 50 #include "ic_predict.h" |
48 #ifdef SSR_DEC | 51 #ifdef SSR_DEC |
49 #include "ssr.h" | 52 #include "ssr.h" |
50 #include "ssr_fb.h" | 53 #include "ssr_fb.h" |
51 #endif | 54 #endif |
52 | 55 |
56 | |
57 /* static function declarations */ | |
58 static uint8_t quant_to_spec(NeAACDecHandle hDecoder, | |
59 ic_stream *ics, int16_t *quant_data, | |
60 real_t *spec_data, uint16_t frame_len); | |
61 | |
62 | |
53 #ifdef LD_DEC | 63 #ifdef LD_DEC |
54 static uint8_t num_swb_512_window[] = | 64 ALIGN static const uint8_t num_swb_512_window[] = |
55 { | 65 { |
56 0, 0, 0, 36, 36, 37, 31, 31, 0, 0, 0, 0 | 66 0, 0, 0, 36, 36, 37, 31, 31, 0, 0, 0, 0 |
57 }; | 67 }; |
58 static uint8_t num_swb_480_window[] = | 68 ALIGN static const uint8_t num_swb_480_window[] = |
59 { | 69 { |
60 0, 0, 0, 35, 35, 37, 30, 30, 0, 0, 0, 0 | 70 0, 0, 0, 35, 35, 37, 30, 30, 0, 0, 0, 0 |
61 }; | 71 }; |
62 #endif | 72 #endif |
63 | 73 |
64 static uint8_t num_swb_960_window[] = | 74 ALIGN static const uint8_t num_swb_960_window[] = |
65 { | 75 { |
66 40, 40, 45, 49, 49, 49, 46, 46, 42, 42, 42, 40 | 76 40, 40, 45, 49, 49, 49, 46, 46, 42, 42, 42, 40 |
67 }; | 77 }; |
68 | 78 |
69 static uint8_t num_swb_1024_window[] = | 79 ALIGN static const uint8_t num_swb_1024_window[] = |
70 { | 80 { |
71 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40 | 81 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40 |
72 }; | 82 }; |
73 | 83 |
74 static uint8_t num_swb_128_window[] = | 84 ALIGN static const uint8_t num_swb_128_window[] = |
75 { | 85 { |
76 12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15 | 86 12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15 |
77 }; | 87 }; |
78 | 88 |
79 static uint16_t swb_offset_1024_96[] = | 89 ALIGN static const uint16_t swb_offset_1024_96[] = |
80 { | 90 { |
81 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, | 91 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, |
82 64, 72, 80, 88, 96, 108, 120, 132, 144, 156, 172, 188, 212, 240, | 92 64, 72, 80, 88, 96, 108, 120, 132, 144, 156, 172, 188, 212, 240, |
83 276, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024 | 93 276, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024 |
84 }; | 94 }; |
85 | 95 |
86 static uint16_t swb_offset_128_96[] = | 96 ALIGN static const uint16_t swb_offset_128_96[] = |
87 { | 97 { |
88 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 | 98 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 |
89 }; | 99 }; |
90 | 100 |
91 static uint16_t swb_offset_1024_64[] = | 101 ALIGN static const uint16_t swb_offset_1024_64[] = |
92 { | 102 { |
93 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, | 103 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, |
94 64, 72, 80, 88, 100, 112, 124, 140, 156, 172, 192, 216, 240, 268, | 104 64, 72, 80, 88, 100, 112, 124, 140, 156, 172, 192, 216, 240, 268, |
95 304, 344, 384, 424, 464, 504, 544, 584, 624, 664, 704, 744, 784, 824, | 105 304, 344, 384, 424, 464, 504, 544, 584, 624, 664, 704, 744, 784, 824, |
96 864, 904, 944, 984, 1024 | 106 864, 904, 944, 984, 1024 |
97 }; | 107 }; |
98 | 108 |
99 static uint16_t swb_offset_128_64[] = | 109 ALIGN static const uint16_t swb_offset_128_64[] = |
100 { | 110 { |
101 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 | 111 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 |
102 }; | 112 }; |
103 | 113 |
104 | 114 ALIGN static const uint16_t swb_offset_1024_48[] = |
105 static uint16_t swb_offset_1024_48[] = | |
106 { | 115 { |
107 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, | 116 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, |
108 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292, | 117 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292, |
109 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, | 118 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, |
110 768, 800, 832, 864, 896, 928, 1024 | 119 768, 800, 832, 864, 896, 928, 1024 |
111 }; | 120 }; |
112 | 121 |
113 #ifdef LD_DEC | 122 #ifdef LD_DEC |
114 static uint16_t swb_offset_512_48[] = | 123 ALIGN static const uint16_t swb_offset_512_48[] = |
115 { | 124 { |
116 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 68, 76, 84, | 125 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 68, 76, 84, |
117 92, 100, 112, 124, 136, 148, 164, 184, 208, 236, 268, 300, 332, 364, 396, | 126 92, 100, 112, 124, 136, 148, 164, 184, 208, 236, 268, 300, 332, 364, 396, |
118 428, 460, 512 | 127 428, 460, 512 |
119 }; | 128 }; |
120 | 129 |
121 static uint16_t swb_offset_480_48[] = | 130 ALIGN static const uint16_t swb_offset_480_48[] = |
122 { | 131 { |
123 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72 ,80 ,88, | 132 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72 ,80 ,88, |
124 96, 108, 120, 132, 144, 156, 172, 188, 212, 240, 272, 304, 336, 368, 400, | 133 96, 108, 120, 132, 144, 156, 172, 188, 212, 240, 272, 304, 336, 368, 400, |
125 432, 480 | 134 432, 480 |
126 }; | 135 }; |
127 #endif | 136 #endif |
128 | 137 |
129 static uint16_t swb_offset_128_48[] = | 138 ALIGN static const uint16_t swb_offset_128_48[] = |
130 { | 139 { |
131 0, 4, 8, 12, 16, 20, 28, 36, 44, 56, 68, 80, 96, 112, 128 | 140 0, 4, 8, 12, 16, 20, 28, 36, 44, 56, 68, 80, 96, 112, 128 |
132 }; | 141 }; |
133 | 142 |
134 static uint16_t swb_offset_1024_32[] = | 143 ALIGN static const uint16_t swb_offset_1024_32[] = |
135 { | 144 { |
136 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, | 145 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, |
137 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292, | 146 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292, |
138 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, | 147 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, |
139 768, 800, 832, 864, 896, 928, 960, 992, 1024 | 148 768, 800, 832, 864, 896, 928, 960, 992, 1024 |
140 }; | 149 }; |
141 | 150 |
142 #ifdef LD_DEC | 151 #ifdef LD_DEC |
143 static uint16_t swb_offset_512_32[] = | 152 ALIGN static const uint16_t swb_offset_512_32[] = |
144 { | 153 { |
145 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80, | 154 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80, |
146 88, 96, 108, 120, 132, 144, 160, 176, 192, 212, 236, 260, 288, 320, 352, | 155 88, 96, 108, 120, 132, 144, 160, 176, 192, 212, 236, 260, 288, 320, 352, |
147 384, 416, 448, 480, 512 | 156 384, 416, 448, 480, 512 |
148 }; | 157 }; |
149 | 158 |
150 static uint16_t swb_offset_480_32[] = | 159 ALIGN static const uint16_t swb_offset_480_32[] = |
151 { | 160 { |
152 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, | 161 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, |
153 88, 96, 104, 112, 124, 136, 148, 164, 180, 200, 224, 256, 288, 320, 352, | 162 88, 96, 104, 112, 124, 136, 148, 164, 180, 200, 224, 256, 288, 320, 352, |
154 384, 416, 448, 480 | 163 384, 416, 448, 480 |
155 }; | 164 }; |
156 #endif | 165 #endif |
157 | 166 |
158 static uint16_t swb_offset_1024_24[] = | 167 ALIGN static const uint16_t swb_offset_1024_24[] = |
159 { | 168 { |
160 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, | 169 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, |
161 76, 84, 92, 100, 108, 116, 124, 136, 148, 160, 172, 188, 204, 220, | 170 76, 84, 92, 100, 108, 116, 124, 136, 148, 160, 172, 188, 204, 220, |
162 240, 260, 284, 308, 336, 364, 396, 432, 468, 508, 552, 600, 652, 704, | 171 240, 260, 284, 308, 336, 364, 396, 432, 468, 508, 552, 600, 652, 704, |
163 768, 832, 896, 960, 1024 | 172 768, 832, 896, 960, 1024 |
164 }; | 173 }; |
165 | 174 |
166 #ifdef LD_DEC | 175 #ifdef LD_DEC |
167 static uint16_t swb_offset_512_24[] = | 176 ALIGN static const uint16_t swb_offset_512_24[] = |
168 { | 177 { |
169 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, | 178 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, |
170 80, 92, 104, 120, 140, 164, 192, 224, 256, 288, 320, 352, 384, 416, | 179 80, 92, 104, 120, 140, 164, 192, 224, 256, 288, 320, 352, 384, 416, |
171 448, 480, 512 | 180 448, 480, 512 |
172 }; | 181 }; |
173 | 182 |
174 static uint16_t swb_offset_480_24[] = | 183 ALIGN static const uint16_t swb_offset_480_24[] = |
175 { | 184 { |
176 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, 80, 92, 104, 120, | 185 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, 80, 92, 104, 120, |
177 140, 164, 192, 224, 256, 288, 320, 352, 384, 416, 448, 480 | 186 140, 164, 192, 224, 256, 288, 320, 352, 384, 416, 448, 480 |
178 }; | 187 }; |
179 #endif | 188 #endif |
180 | 189 |
181 static uint16_t swb_offset_128_24[] = | 190 ALIGN static const uint16_t swb_offset_128_24[] = |
182 { | 191 { |
183 0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 64, 76, 92, 108, 128 | 192 0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 64, 76, 92, 108, 128 |
184 }; | 193 }; |
185 | 194 |
186 static uint16_t swb_offset_1024_16[] = | 195 ALIGN static const uint16_t swb_offset_1024_16[] = |
187 { | 196 { |
188 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 100, 112, 124, | 197 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 100, 112, 124, |
189 136, 148, 160, 172, 184, 196, 212, 228, 244, 260, 280, 300, 320, 344, | 198 136, 148, 160, 172, 184, 196, 212, 228, 244, 260, 280, 300, 320, 344, |
190 368, 396, 424, 456, 492, 532, 572, 616, 664, 716, 772, 832, 896, 960, 1024 | 199 368, 396, 424, 456, 492, 532, 572, 616, 664, 716, 772, 832, 896, 960, 1024 |
191 }; | 200 }; |
192 | 201 |
193 static uint16_t swb_offset_128_16[] = | 202 ALIGN static const uint16_t swb_offset_128_16[] = |
194 { | 203 { |
195 0, 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 60, 72, 88, 108, 128 | 204 0, 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 60, 72, 88, 108, 128 |
196 }; | 205 }; |
197 | 206 |
198 static uint16_t swb_offset_1024_8[] = | 207 ALIGN static const uint16_t swb_offset_1024_8[] = |
199 { | 208 { |
200 0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 172, | 209 0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 172, |
201 188, 204, 220, 236, 252, 268, 288, 308, 328, 348, 372, 396, 420, 448, | 210 188, 204, 220, 236, 252, 268, 288, 308, 328, 348, 372, 396, 420, 448, |
202 476, 508, 544, 580, 620, 664, 712, 764, 820, 880, 944, 1024 | 211 476, 508, 544, 580, 620, 664, 712, 764, 820, 880, 944, 1024 |
203 }; | 212 }; |
204 | 213 |
205 static uint16_t swb_offset_128_8[] = | 214 ALIGN static const uint16_t swb_offset_128_8[] = |
206 { | 215 { |
207 0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 60, 72, 88, 108, 128 | 216 0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 60, 72, 88, 108, 128 |
208 }; | 217 }; |
209 | 218 |
210 static uint16_t *swb_offset_1024_window[] = | 219 ALIGN static const uint16_t *swb_offset_1024_window[] = |
211 { | 220 { |
212 swb_offset_1024_96, /* 96000 */ | 221 swb_offset_1024_96, /* 96000 */ |
213 swb_offset_1024_96, /* 88200 */ | 222 swb_offset_1024_96, /* 88200 */ |
214 swb_offset_1024_64, /* 64000 */ | 223 swb_offset_1024_64, /* 64000 */ |
215 swb_offset_1024_48, /* 48000 */ | 224 swb_offset_1024_48, /* 48000 */ |
222 swb_offset_1024_16, /* 11025 */ | 231 swb_offset_1024_16, /* 11025 */ |
223 swb_offset_1024_8 /* 8000 */ | 232 swb_offset_1024_8 /* 8000 */ |
224 }; | 233 }; |
225 | 234 |
226 #ifdef LD_DEC | 235 #ifdef LD_DEC |
227 static uint16_t *swb_offset_512_window[] = | 236 ALIGN static const uint16_t *swb_offset_512_window[] = |
228 { | 237 { |
229 0, /* 96000 */ | 238 0, /* 96000 */ |
230 0, /* 88200 */ | 239 0, /* 88200 */ |
231 0, /* 64000 */ | 240 0, /* 64000 */ |
232 swb_offset_512_48, /* 48000 */ | 241 swb_offset_512_48, /* 48000 */ |
238 0, /* 12000 */ | 247 0, /* 12000 */ |
239 0, /* 11025 */ | 248 0, /* 11025 */ |
240 0 /* 8000 */ | 249 0 /* 8000 */ |
241 }; | 250 }; |
242 | 251 |
243 static uint16_t *swb_offset_480_window[] = | 252 ALIGN static const uint16_t *swb_offset_480_window[] = |
244 { | 253 { |
245 0, /* 96000 */ | 254 0, /* 96000 */ |
246 0, /* 88200 */ | 255 0, /* 88200 */ |
247 0, /* 64000 */ | 256 0, /* 64000 */ |
248 swb_offset_480_48, /* 48000 */ | 257 swb_offset_480_48, /* 48000 */ |
255 0, /* 11025 */ | 264 0, /* 11025 */ |
256 0 /* 8000 */ | 265 0 /* 8000 */ |
257 }; | 266 }; |
258 #endif | 267 #endif |
259 | 268 |
260 static uint16_t *swb_offset_128_window[] = | 269 ALIGN static const uint16_t *swb_offset_128_window[] = |
261 { | 270 { |
262 swb_offset_128_96, /* 96000 */ | 271 swb_offset_128_96, /* 96000 */ |
263 swb_offset_128_96, /* 88200 */ | 272 swb_offset_128_96, /* 88200 */ |
264 swb_offset_128_64, /* 64000 */ | 273 swb_offset_128_64, /* 64000 */ |
265 swb_offset_128_48, /* 48000 */ | 274 swb_offset_128_48, /* 48000 */ |
286 scalefactor window band named swb of the window actually used | 295 scalefactor window band named swb of the window actually used |
287 - determine sect_sfb_offset[g][section],the offset of the first coefficient | 296 - determine sect_sfb_offset[g][section],the offset of the first coefficient |
288 in section named section. This offset depends on window_sequence and | 297 in section named section. This offset depends on window_sequence and |
289 scale_factor_grouping and is needed to decode the spectral_data(). | 298 scale_factor_grouping and is needed to decode the spectral_data(). |
290 */ | 299 */ |
291 uint8_t window_grouping_info(faacDecHandle hDecoder, ic_stream *ics) | 300 uint8_t window_grouping_info(NeAACDecHandle hDecoder, ic_stream *ics) |
292 { | 301 { |
293 uint8_t i, g; | 302 uint8_t i, g; |
294 | 303 |
295 uint8_t sf_index = hDecoder->sf_index; | 304 uint8_t sf_index = hDecoder->sf_index; |
296 | 305 |
398 default: | 407 default: |
399 return 1; | 408 return 1; |
400 } | 409 } |
401 } | 410 } |
402 | 411 |
412 /* iquant() * | |
413 /* output = sign(input)*abs(input)^(4/3) */ | |
414 /**/ | |
415 static INLINE real_t iquant(int16_t q, const real_t *tab, uint8_t *error) | |
416 { | |
417 #ifdef FIXED_POINT | |
418 /* For FIXED_POINT the iq_table is prescaled by 3 bits (iq_table[]/8) */ | |
419 /* BIG_IQ_TABLE allows you to use the full 8192 value table, if this is not | |
420 * defined a 1026 value table and interpolation will be used | |
421 */ | |
422 #ifndef BIG_IQ_TABLE | |
423 static const real_t errcorr[] = { | |
424 REAL_CONST(0), REAL_CONST(1.0/8.0), REAL_CONST(2.0/8.0), REAL_CONST(3.0/8.0), | |
425 REAL_CONST(4.0/8.0), REAL_CONST(5.0/8.0), REAL_CONST(6.0/8.0), REAL_CONST(7.0/8.0), | |
426 REAL_CONST(0) | |
427 }; | |
428 real_t x1, x2; | |
429 #endif | |
430 int16_t sgn = 1; | |
431 | |
432 if (q < 0) | |
433 { | |
434 q = -q; | |
435 sgn = -1; | |
436 } | |
437 | |
438 if (q < IQ_TABLE_SIZE) | |
439 { | |
440 //#define IQUANT_PRINT | |
441 #ifdef IQUANT_PRINT | |
442 //printf("0x%.8X\n", sgn * tab[q]); | |
443 printf("%d\n", sgn * tab[q]); | |
444 #endif | |
445 return sgn * tab[q]; | |
446 } | |
447 | |
448 #ifndef BIG_IQ_TABLE | |
449 if (q >= 8192) | |
450 { | |
451 *error = 17; | |
452 return 0; | |
453 } | |
454 | |
455 /* linear interpolation */ | |
456 x1 = tab[q>>3]; | |
457 x2 = tab[(q>>3) + 1]; | |
458 return sgn * 16 * (MUL_R(errcorr[q&7],(x2-x1)) + x1); | |
459 #else | |
460 *error = 17; | |
461 return 0; | |
462 #endif | |
463 | |
464 #else | |
465 if (q < 0) | |
466 { | |
467 /* tab contains a value for all possible q [0,8192] */ | |
468 if (-q < IQ_TABLE_SIZE) | |
469 return -tab[-q]; | |
470 | |
471 *error = 17; | |
472 return 0; | |
473 } else { | |
474 /* tab contains a value for all possible q [0,8192] */ | |
475 if (q < IQ_TABLE_SIZE) | |
476 return tab[q]; | |
477 | |
478 *error = 17; | |
479 return 0; | |
480 } | |
481 #endif | |
482 } | |
483 | |
484 #ifndef FIXED_POINT | |
485 ALIGN static const real_t pow2sf_tab[] = { | |
486 2.9802322387695313E-008, 5.9604644775390625E-008, 1.1920928955078125E-007, | |
487 2.384185791015625E-007, 4.76837158203125E-007, 9.5367431640625E-007, | |
488 1.9073486328125E-006, 3.814697265625E-006, 7.62939453125E-006, | |
489 1.52587890625E-005, 3.0517578125E-005, 6.103515625E-005, | |
490 0.0001220703125, 0.000244140625, 0.00048828125, | |
491 0.0009765625, 0.001953125, 0.00390625, | |
492 0.0078125, 0.015625, 0.03125, | |
493 0.0625, 0.125, 0.25, | |
494 0.5, 1.0, 2.0, | |
495 4.0, 8.0, 16.0, 32.0, | |
496 64.0, 128.0, 256.0, | |
497 512.0, 1024.0, 2048.0, | |
498 4096.0, 8192.0, 16384.0, | |
499 32768.0, 65536.0, 131072.0, | |
500 262144.0, 524288.0, 1048576.0, | |
501 2097152.0, 4194304.0, 8388608.0, | |
502 16777216.0, 33554432.0, 67108864.0, | |
503 134217728.0, 268435456.0, 536870912.0, | |
504 1073741824.0, 2147483648.0, 4294967296.0, | |
505 8589934592.0, 17179869184.0, 34359738368.0, | |
506 68719476736.0, 137438953472.0, 274877906944.0 | |
507 }; | |
508 #endif | |
509 | |
510 /* quant_to_spec: perform dequantisation and scaling | |
511 * and in case of short block it also does the deinterleaving | |
512 */ | |
403 /* | 513 /* |
404 For ONLY_LONG_SEQUENCE windows (num_window_groups = 1, | 514 For ONLY_LONG_SEQUENCE windows (num_window_groups = 1, |
405 window_group_length[0] = 1) the spectral data is in ascending spectral | 515 window_group_length[0] = 1) the spectral data is in ascending spectral |
406 order. | 516 order. |
407 For the EIGHT_SHORT_SEQUENCE window, the spectral order depends on the | 517 For the EIGHT_SHORT_SEQUENCE window, the spectral order depends on the |
418 window_group_length[0] = 8), the result is that spectral data of all eight | 528 window_group_length[0] = 8), the result is that spectral data of all eight |
419 SHORT_WINDOWs is interleaved by scalefactor window bands. | 529 SHORT_WINDOWs is interleaved by scalefactor window bands. |
420 - Within a scalefactor window band, the coefficients are in ascending | 530 - Within a scalefactor window band, the coefficients are in ascending |
421 spectral order. | 531 spectral order. |
422 */ | 532 */ |
423 static void quant_to_spec(ic_stream *ics, real_t *spec_data, uint16_t frame_len) | 533 static uint8_t quant_to_spec(NeAACDecHandle hDecoder, |
424 { | 534 ic_stream *ics, int16_t *quant_data, |
535 real_t *spec_data, uint16_t frame_len) | |
536 { | |
537 ALIGN static const real_t pow2_table[] = | |
538 { | |
539 COEF_CONST(1.0), | |
540 COEF_CONST(1.1892071150027210667174999705605), /* 2^0.25 */ | |
541 COEF_CONST(1.4142135623730950488016887242097), /* 2^0.5 */ | |
542 COEF_CONST(1.6817928305074290860622509524664) /* 2^0.75 */ | |
543 }; | |
544 const real_t *tab = iq_table; | |
545 | |
425 uint8_t g, sfb, win; | 546 uint8_t g, sfb, win; |
426 uint16_t width, bin, k, gindex; | 547 uint16_t width, bin, k, gindex, wa, wb; |
427 | 548 uint8_t error = 0; /* Init error flag */ |
428 real_t tmp_spec[1024] = {0}; | 549 #ifndef FIXED_POINT |
550 real_t scf; | |
551 #endif | |
429 | 552 |
430 k = 0; | 553 k = 0; |
431 gindex = 0; | 554 gindex = 0; |
432 | 555 |
433 for (g = 0; g < ics->num_window_groups; g++) | 556 for (g = 0; g < ics->num_window_groups; g++) |
436 uint16_t gincrease = 0; | 559 uint16_t gincrease = 0; |
437 uint16_t win_inc = ics->swb_offset[ics->num_swb]; | 560 uint16_t win_inc = ics->swb_offset[ics->num_swb]; |
438 | 561 |
439 for (sfb = 0; sfb < ics->num_swb; sfb++) | 562 for (sfb = 0; sfb < ics->num_swb; sfb++) |
440 { | 563 { |
564 int32_t exp, frac; | |
565 | |
441 width = ics->swb_offset[sfb+1] - ics->swb_offset[sfb]; | 566 width = ics->swb_offset[sfb+1] - ics->swb_offset[sfb]; |
442 | 567 |
443 for (win = 0; win < ics->window_group_length[g]; win++) | 568 /* this could be scalefactor for IS or PNS, those can be negative or bigger then 255 */ |
569 /* just ignore them */ | |
570 if (ics->scale_factors[g][sfb] < 0 || ics->scale_factors[g][sfb] > 255) | |
444 { | 571 { |
445 for (bin = 0; bin < width; bin += 4) | 572 exp = 0; |
446 { | 573 frac = 0; |
447 tmp_spec[gindex+(win*win_inc)+j+bin+0] = spec_data[k+0]; | 574 } else { |
448 tmp_spec[gindex+(win*win_inc)+j+bin+1] = spec_data[k+1]; | 575 /* ics->scale_factors[g][sfb] must be between 0 and 255 */ |
449 tmp_spec[gindex+(win*win_inc)+j+bin+2] = spec_data[k+2]; | 576 exp = (ics->scale_factors[g][sfb] /* - 100 */) >> 2; |
450 tmp_spec[gindex+(win*win_inc)+j+bin+3] = spec_data[k+3]; | 577 /* frac must always be > 0 */ |
451 gincrease += 4; | 578 frac = (ics->scale_factors[g][sfb] /* - 100 */) & 3; |
452 k += 4; | |
453 } | |
454 } | 579 } |
455 j += width; | 580 |
456 } | |
457 gindex += gincrease; | |
458 } | |
459 | |
460 memcpy(spec_data, tmp_spec, frame_len*sizeof(real_t)); | |
461 } | |
462 | |
463 #ifndef FIXED_POINT | |
464 void build_tables(real_t *pow2_table) | |
465 { | |
466 uint16_t i; | |
467 | |
468 /* build pow(2, 0.25*x) table for scalefactors */ | |
469 for(i = 0; i < POW_TABLE_SIZE; i++) | |
470 { | |
471 pow2_table[i] = REAL_CONST(pow(2.0, 0.25 * (i-100))); | |
472 } | |
473 } | |
474 #endif | |
475 | |
476 static INLINE real_t iquant(int16_t q, real_t *tab) | |
477 { | |
478 #ifdef FIXED_POINT | 581 #ifdef FIXED_POINT |
479 static const real_t errcorr[] = { | 582 exp -= 25; |
480 REAL_CONST(0), REAL_CONST(1.0/8.0), REAL_CONST(2.0/8.0), REAL_CONST(3.0/8.0), | |
481 REAL_CONST(4.0/8.0), REAL_CONST(5.0/8.0), REAL_CONST(6.0/8.0), REAL_CONST(7.0/8.0), | |
482 REAL_CONST(0) | |
483 }; | |
484 real_t x1, x2; | |
485 int16_t sgn = 1; | |
486 | |
487 if (q < 0) | |
488 { | |
489 q = -q; | |
490 sgn = -1; | |
491 } | |
492 | |
493 if (q < IQ_TABLE_SIZE) | |
494 return sgn * tab[q]; | |
495 | |
496 /* linear interpolation */ | |
497 x1 = tab[q>>3]; | |
498 x2 = tab[(q>>3) + 1]; | |
499 return sgn * 16 * (MUL_R(errcorr[q&7],(x2-x1)) + x1); | |
500 #else | |
501 real_t sgn = REAL_CONST(1.0); | |
502 | |
503 if (q < 0) | |
504 { | |
505 q = -q; | |
506 sgn = REAL_CONST(-1.0); | |
507 } | |
508 | |
509 if (q < IQ_TABLE_SIZE) | |
510 return sgn * tab[q]; | |
511 | |
512 return sgn * (real_t)pow(q, 4.0/3.0); | |
513 #endif | |
514 } | |
515 | |
516 static void inverse_quantization(real_t *x_invquant, int16_t *x_quant, uint16_t frame_len) | |
517 { | |
518 int16_t i; | |
519 real_t *tab = iq_table; | |
520 | |
521 for(i = 0; i < frame_len; i+=4) | |
522 { | |
523 x_invquant[i] = iquant(x_quant[i], tab); | |
524 x_invquant[i+1] = iquant(x_quant[i+1], tab); | |
525 x_invquant[i+2] = iquant(x_quant[i+2], tab); | |
526 x_invquant[i+3] = iquant(x_quant[i+3], tab); | |
527 } | |
528 } | |
529 | |
530 #ifndef FIXED_POINT | |
531 static INLINE real_t get_scale_factor_gain(uint16_t scale_factor, real_t *pow2_table) | |
532 { | |
533 if (scale_factor < POW_TABLE_SIZE) | |
534 return pow2_table[scale_factor]; | |
535 else | |
536 return REAL_CONST(pow(2.0, 0.25 * (scale_factor - 100))); | |
537 } | |
538 #else | |
539 static real_t pow2_table[] = | |
540 { | |
541 COEF_CONST(0.59460355750136053335874998528024), /* 2^-0.75 */ | |
542 COEF_CONST(0.70710678118654752440084436210485), /* 2^-0.5 */ | |
543 COEF_CONST(0.84089641525371454303112547623321), /* 2^-0.25 */ | |
544 COEF_CONST(1.0), | |
545 COEF_CONST(1.1892071150027210667174999705605), /* 2^0.25 */ | |
546 COEF_CONST(1.4142135623730950488016887242097), /* 2^0.5 */ | |
547 COEF_CONST(1.6817928305074290860622509524664) /* 2^0.75 */ | |
548 }; | |
549 #endif | |
550 | |
551 static void apply_scalefactors(faacDecHandle hDecoder, ic_stream *ics, | |
552 real_t *x_invquant, uint16_t frame_len) | |
553 { | |
554 uint8_t g, sfb; | |
555 uint16_t top; | |
556 #ifndef FIXED_POINT | |
557 real_t scale; | |
558 #else | |
559 int32_t exp, frac; | |
560 #endif | |
561 uint8_t groups = 0; | |
562 uint16_t nshort = frame_len/8; | |
563 | |
564 for (g = 0; g < ics->num_window_groups; g++) | |
565 { | |
566 uint16_t k = 0; | |
567 | |
568 /* using this nshort*groups doesn't hurt long blocks, because | |
569 long blocks only have 1 group, so that means 'groups' is | |
570 always 0 for long blocks | |
571 */ | |
572 for (sfb = 0; sfb < ics->max_sfb; sfb++) | |
573 { | |
574 top = ics->sect_sfb_offset[g][sfb+1]; | |
575 | |
576 #ifndef FIXED_POINT | |
577 scale = get_scale_factor_gain(ics->scale_factors[g][sfb], hDecoder->pow2_table); | |
578 #else | |
579 exp = (ics->scale_factors[g][sfb] - 100) / 4; | |
580 frac = (ics->scale_factors[g][sfb] - 100) % 4; | |
581 | |
582 /* IMDCT pre-scaling */ | 583 /* IMDCT pre-scaling */ |
583 if (hDecoder->object_type == LD) | 584 if (hDecoder->object_type == LD) |
584 { | 585 { |
585 exp -= 6 /*9*/; | 586 exp -= 6 /*9*/; |
586 } else { | 587 } else { |
587 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | 588 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) |
588 exp -= 4 /*7*/; | 589 exp -= 4 /*7*/; |
589 else | 590 else |
590 exp -= 7 /*10*/; | 591 exp -= 7 /*10*/; |
591 } | 592 } |
592 #if (REAL_BITS == 16) | 593 #endif |
593 exp--; | 594 |
594 #endif | 595 wa = gindex + j; |
595 #endif | 596 |
596 | 597 #ifndef FIXED_POINT |
597 /* minimum size of a sf band is 4 and always a multiple of 4 */ | 598 scf = pow2sf_tab[exp/*+25*/] * pow2_table[frac]; |
598 for ( ; k < top; k += 4) | 599 #endif |
600 | |
601 for (win = 0; win < ics->window_group_length[g]; win++) | |
599 { | 602 { |
603 for (bin = 0; bin < width; bin += 4) | |
604 { | |
600 #ifndef FIXED_POINT | 605 #ifndef FIXED_POINT |
601 x_invquant[k+(groups*nshort)] = x_invquant[k+(groups*nshort)] * scale; | 606 wb = wa + bin; |
602 x_invquant[k+(groups*nshort)+1] = x_invquant[k+(groups*nshort)+1] * scale; | 607 |
603 x_invquant[k+(groups*nshort)+2] = x_invquant[k+(groups*nshort)+2] * scale; | 608 spec_data[wb+0] = iquant(quant_data[k+0], tab, &error) * scf; |
604 x_invquant[k+(groups*nshort)+3] = x_invquant[k+(groups*nshort)+3] * scale; | 609 spec_data[wb+1] = iquant(quant_data[k+1], tab, &error) * scf; |
610 spec_data[wb+2] = iquant(quant_data[k+2], tab, &error) * scf; | |
611 spec_data[wb+3] = iquant(quant_data[k+3], tab, &error) * scf; | |
612 | |
605 #else | 613 #else |
606 if (exp < 0) | 614 real_t iq0 = iquant(quant_data[k+0], tab, &error); |
607 { | 615 real_t iq1 = iquant(quant_data[k+1], tab, &error); |
608 x_invquant[k+(groups*nshort)] >>= -exp; | 616 real_t iq2 = iquant(quant_data[k+2], tab, &error); |
609 x_invquant[k+(groups*nshort)+1] >>= -exp; | 617 real_t iq3 = iquant(quant_data[k+3], tab, &error); |
610 x_invquant[k+(groups*nshort)+2] >>= -exp; | 618 |
611 x_invquant[k+(groups*nshort)+3] >>= -exp; | 619 wb = wa + bin; |
612 } else { | 620 |
613 x_invquant[k+(groups*nshort)] <<= exp; | 621 if (exp < 0) |
614 x_invquant[k+(groups*nshort)+1] <<= exp; | 622 { |
615 x_invquant[k+(groups*nshort)+2] <<= exp; | 623 spec_data[wb+0] = iq0 >>= -exp; |
616 x_invquant[k+(groups*nshort)+3] <<= exp; | 624 spec_data[wb+1] = iq1 >>= -exp; |
625 spec_data[wb+2] = iq2 >>= -exp; | |
626 spec_data[wb+3] = iq3 >>= -exp; | |
627 } else { | |
628 spec_data[wb+0] = iq0 <<= exp; | |
629 spec_data[wb+1] = iq1 <<= exp; | |
630 spec_data[wb+2] = iq2 <<= exp; | |
631 spec_data[wb+3] = iq3 <<= exp; | |
632 } | |
633 if (frac != 0) | |
634 { | |
635 spec_data[wb+0] = MUL_C(spec_data[wb+0],pow2_table[frac]); | |
636 spec_data[wb+1] = MUL_C(spec_data[wb+1],pow2_table[frac]); | |
637 spec_data[wb+2] = MUL_C(spec_data[wb+2],pow2_table[frac]); | |
638 spec_data[wb+3] = MUL_C(spec_data[wb+3],pow2_table[frac]); | |
639 } | |
640 | |
641 //#define SCFS_PRINT | |
642 #ifdef SCFS_PRINT | |
643 printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+0]); | |
644 printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+1]); | |
645 printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+2]); | |
646 printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+3]); | |
647 //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+0]); | |
648 //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+1]); | |
649 //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+2]); | |
650 //printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+3]); | |
651 #endif | |
652 #endif | |
653 | |
654 gincrease += 4; | |
655 k += 4; | |
617 } | 656 } |
618 | 657 wa += win_inc; |
619 if (frac) | |
620 { | |
621 x_invquant[k+(groups*nshort)] = MUL_C(x_invquant[k+(groups*nshort)],pow2_table[frac + 3]); | |
622 x_invquant[k+(groups*nshort)+1] = MUL_C(x_invquant[k+(groups*nshort)+1],pow2_table[frac + 3]); | |
623 x_invquant[k+(groups*nshort)+2] = MUL_C(x_invquant[k+(groups*nshort)+2],pow2_table[frac + 3]); | |
624 x_invquant[k+(groups*nshort)+3] = MUL_C(x_invquant[k+(groups*nshort)+3],pow2_table[frac + 3]); | |
625 } | |
626 #endif | |
627 } | 658 } |
628 } | 659 j += width; |
629 groups += ics->window_group_length[g]; | 660 } |
630 } | 661 gindex += gincrease; |
662 } | |
663 | |
664 return error; | |
631 } | 665 } |
632 | 666 |
633 void reconstruct_single_channel(faacDecHandle hDecoder, ic_stream *ics, | 667 static uint8_t allocate_single_channel(NeAACDecHandle hDecoder, uint8_t channel, |
634 element *sce, int16_t *spec_data) | 668 uint8_t output_channels) |
635 { | 669 { |
636 real_t spec_coef[1024]; | 670 uint8_t mul = 1; |
637 | |
638 /* inverse quantization */ | |
639 inverse_quantization(spec_coef, spec_data, hDecoder->frameLength); | |
640 | |
641 /* apply scalefactors */ | |
642 apply_scalefactors(hDecoder, ics, spec_coef, hDecoder->frameLength); | |
643 | |
644 /* deinterleave short block grouping */ | |
645 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | |
646 quant_to_spec(ics, spec_coef, hDecoder->frameLength); | |
647 | |
648 | |
649 /* pns decoding */ | |
650 pns_decode(ics, NULL, spec_coef, NULL, hDecoder->frameLength, 0, hDecoder->object_type); | |
651 | 671 |
652 #ifdef MAIN_DEC | 672 #ifdef MAIN_DEC |
653 /* MAIN object type prediction */ | 673 /* MAIN object type prediction */ |
654 if (hDecoder->object_type == MAIN) | 674 if (hDecoder->object_type == MAIN) |
655 { | 675 { |
656 /* allocate the state only when needed */ | 676 /* allocate the state only when needed */ |
657 if (hDecoder->pred_stat[sce->channel] == NULL) | 677 if (hDecoder->pred_stat[channel] == NULL) |
658 { | 678 { |
659 hDecoder->pred_stat[sce->channel] = (pred_state*)malloc(hDecoder->frameLength * sizeof(pred_state)); | 679 hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state)); |
660 reset_all_predictors(hDecoder->pred_stat[sce->channel], hDecoder->frameLength); | 680 reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength); |
661 } | 681 } |
662 | 682 } |
683 #endif | |
684 | |
685 #ifdef LTP_DEC | |
686 if (is_ltp_ot(hDecoder->object_type)) | |
687 { | |
688 /* allocate the state only when needed */ | |
689 if (hDecoder->lt_pred_stat[channel] == NULL) | |
690 { | |
691 hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
692 memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
693 } | |
694 } | |
695 #endif | |
696 | |
697 if (hDecoder->time_out[channel] == NULL) | |
698 { | |
699 mul = 1; | |
700 #ifdef SBR_DEC | |
701 hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; | |
702 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
703 { | |
704 /* SBR requires 2 times as much output data */ | |
705 mul = 2; | |
706 hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; | |
707 } | |
708 #endif | |
709 hDecoder->time_out[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); | |
710 memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); | |
711 } | |
712 #if (defined(PS_DEC) || defined(DRM_PS)) | |
713 if (output_channels == 2) | |
714 { | |
715 if (hDecoder->time_out[channel+1] == NULL) | |
716 { | |
717 hDecoder->time_out[channel+1] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); | |
718 memset(hDecoder->time_out[channel+1], 0, mul*hDecoder->frameLength*sizeof(real_t)); | |
719 } | |
720 } | |
721 #endif | |
722 | |
723 if (hDecoder->fb_intermed[channel] == NULL) | |
724 { | |
725 hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); | |
726 memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t)); | |
727 } | |
728 | |
729 #ifdef SSR_DEC | |
730 if (hDecoder->object_type == SSR) | |
731 { | |
732 if (hDecoder->ssr_overlap[channel] == NULL) | |
733 { | |
734 hDecoder->ssr_overlap[channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
735 memset(hDecoder->ssr_overlap[channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
736 } | |
737 if (hDecoder->prev_fmd[channel] == NULL) | |
738 { | |
739 uint16_t k; | |
740 hDecoder->prev_fmd[channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
741 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
742 hDecoder->prev_fmd[channel][k] = REAL_CONST(-1); | |
743 } | |
744 } | |
745 #endif | |
746 | |
747 return 0; | |
748 } | |
749 | |
750 static uint8_t allocate_channel_pair(NeAACDecHandle hDecoder, | |
751 uint8_t channel, uint8_t paired_channel) | |
752 { | |
753 uint8_t mul = 1; | |
754 | |
755 #ifdef MAIN_DEC | |
756 /* MAIN object type prediction */ | |
757 if (hDecoder->object_type == MAIN) | |
758 { | |
759 /* allocate the state only when needed */ | |
760 if (hDecoder->pred_stat[channel] == NULL) | |
761 { | |
762 hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state)); | |
763 reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength); | |
764 } | |
765 if (hDecoder->pred_stat[paired_channel] == NULL) | |
766 { | |
767 hDecoder->pred_stat[paired_channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state)); | |
768 reset_all_predictors(hDecoder->pred_stat[paired_channel], hDecoder->frameLength); | |
769 } | |
770 } | |
771 #endif | |
772 | |
773 #ifdef LTP_DEC | |
774 if (is_ltp_ot(hDecoder->object_type)) | |
775 { | |
776 /* allocate the state only when needed */ | |
777 if (hDecoder->lt_pred_stat[channel] == NULL) | |
778 { | |
779 hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
780 memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
781 } | |
782 if (hDecoder->lt_pred_stat[paired_channel] == NULL) | |
783 { | |
784 hDecoder->lt_pred_stat[paired_channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
785 memset(hDecoder->lt_pred_stat[paired_channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
786 } | |
787 } | |
788 #endif | |
789 | |
790 if (hDecoder->time_out[channel] == NULL) | |
791 { | |
792 mul = 1; | |
793 #ifdef SBR_DEC | |
794 hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; | |
795 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
796 { | |
797 /* SBR requires 2 times as much output data */ | |
798 mul = 2; | |
799 hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; | |
800 } | |
801 #endif | |
802 hDecoder->time_out[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); | |
803 memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); | |
804 } | |
805 if (hDecoder->time_out[paired_channel] == NULL) | |
806 { | |
807 hDecoder->time_out[paired_channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); | |
808 memset(hDecoder->time_out[paired_channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); | |
809 } | |
810 | |
811 if (hDecoder->fb_intermed[channel] == NULL) | |
812 { | |
813 hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); | |
814 memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t)); | |
815 } | |
816 if (hDecoder->fb_intermed[paired_channel] == NULL) | |
817 { | |
818 hDecoder->fb_intermed[paired_channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); | |
819 memset(hDecoder->fb_intermed[paired_channel], 0, hDecoder->frameLength*sizeof(real_t)); | |
820 } | |
821 | |
822 #ifdef SSR_DEC | |
823 if (hDecoder->object_type == SSR) | |
824 { | |
825 if (hDecoder->ssr_overlap[cpe->channel] == NULL) | |
826 { | |
827 hDecoder->ssr_overlap[cpe->channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
828 memset(hDecoder->ssr_overlap[cpe->channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
829 } | |
830 if (hDecoder->ssr_overlap[cpe->paired_channel] == NULL) | |
831 { | |
832 hDecoder->ssr_overlap[cpe->paired_channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
833 memset(hDecoder->ssr_overlap[cpe->paired_channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
834 } | |
835 if (hDecoder->prev_fmd[cpe->channel] == NULL) | |
836 { | |
837 uint16_t k; | |
838 hDecoder->prev_fmd[cpe->channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
839 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
840 hDecoder->prev_fmd[cpe->channel][k] = REAL_CONST(-1); | |
841 } | |
842 if (hDecoder->prev_fmd[cpe->paired_channel] == NULL) | |
843 { | |
844 uint16_t k; | |
845 hDecoder->prev_fmd[cpe->paired_channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
846 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
847 hDecoder->prev_fmd[cpe->paired_channel][k] = REAL_CONST(-1); | |
848 } | |
849 } | |
850 #endif | |
851 | |
852 return 0; | |
853 } | |
854 | |
855 uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics, | |
856 element *sce, int16_t *spec_data) | |
857 { | |
858 uint8_t retval, output_channels; | |
859 ALIGN real_t spec_coef[1024]; | |
860 | |
861 #ifdef PROFILE | |
862 int64_t count = faad_get_ts(); | |
863 #endif | |
864 | |
865 | |
866 /* always allocate 2 channels, PS can always "suddenly" turn up */ | |
867 #if (defined(PS_DEC) || defined(DRM_PS)) | |
868 output_channels = 2; | |
869 #else | |
870 output_channels = 1; | |
871 #endif | |
872 | |
873 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0) | |
874 { | |
875 /* element_output_channels not set yet */ | |
876 hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels; | |
877 } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != output_channels) { | |
878 /* element inconsistency */ | |
879 return 21; | |
880 } | |
881 | |
882 if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0) | |
883 { | |
884 retval = allocate_single_channel(hDecoder, sce->channel, output_channels); | |
885 if (retval > 0) | |
886 return retval; | |
887 | |
888 hDecoder->element_alloced[hDecoder->fr_ch_ele] = 1; | |
889 } | |
890 | |
891 | |
892 /* dequantisation and scaling */ | |
893 retval = quant_to_spec(hDecoder, ics, spec_data, spec_coef, hDecoder->frameLength); | |
894 if (retval > 0) | |
895 return retval; | |
896 | |
897 #ifdef PROFILE | |
898 count = faad_get_ts() - count; | |
899 hDecoder->requant_cycles += count; | |
900 #endif | |
901 | |
902 | |
903 /* pns decoding */ | |
904 pns_decode(ics, NULL, spec_coef, NULL, hDecoder->frameLength, 0, hDecoder->object_type); | |
905 | |
906 #ifdef MAIN_DEC | |
907 /* MAIN object type prediction */ | |
908 if (hDecoder->object_type == MAIN) | |
909 { | |
663 /* intra channel prediction */ | 910 /* intra channel prediction */ |
664 ic_prediction(ics, spec_coef, hDecoder->pred_stat[sce->channel], hDecoder->frameLength, | 911 ic_prediction(ics, spec_coef, hDecoder->pred_stat[sce->channel], hDecoder->frameLength, |
665 hDecoder->sf_index); | 912 hDecoder->sf_index); |
666 | 913 |
667 /* In addition, for scalefactor bands coded by perceptual | 914 /* In addition, for scalefactor bands coded by perceptual |
685 } | 932 } |
686 ics->ltp.lag = hDecoder->ltp_lag[sce->channel]; | 933 ics->ltp.lag = hDecoder->ltp_lag[sce->channel]; |
687 } | 934 } |
688 #endif | 935 #endif |
689 | 936 |
690 /* allocate the state only when needed */ | |
691 if (hDecoder->lt_pred_stat[sce->channel] == NULL) | |
692 { | |
693 hDecoder->lt_pred_stat[sce->channel] = (int16_t*)malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
694 memset(hDecoder->lt_pred_stat[sce->channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
695 } | |
696 | |
697 /* long term prediction */ | 937 /* long term prediction */ |
698 lt_prediction(ics, &(ics->ltp), spec_coef, hDecoder->lt_pred_stat[sce->channel], hDecoder->fb, | 938 lt_prediction(ics, &(ics->ltp), spec_coef, hDecoder->lt_pred_stat[sce->channel], hDecoder->fb, |
699 ics->window_shape, hDecoder->window_shape_prev[sce->channel], | 939 ics->window_shape, hDecoder->window_shape_prev[sce->channel], |
700 hDecoder->sf_index, hDecoder->object_type, hDecoder->frameLength); | 940 hDecoder->sf_index, hDecoder->object_type, hDecoder->frameLength); |
701 } | 941 } |
710 { | 950 { |
711 if (!hDecoder->drc->exclude_mask[sce->channel] || !hDecoder->drc->excluded_chns_present) | 951 if (!hDecoder->drc->exclude_mask[sce->channel] || !hDecoder->drc->excluded_chns_present) |
712 drc_decode(hDecoder->drc, spec_coef); | 952 drc_decode(hDecoder->drc, spec_coef); |
713 } | 953 } |
714 | 954 |
715 if (hDecoder->time_out[sce->channel] == NULL) | |
716 { | |
717 hDecoder->time_out[sce->channel] = (real_t*)malloc(hDecoder->frameLength*2*sizeof(real_t)); | |
718 memset(hDecoder->time_out[sce->channel], 0, hDecoder->frameLength*2*sizeof(real_t)); | |
719 } | |
720 | |
721 /* filter bank */ | 955 /* filter bank */ |
722 #ifdef SSR_DEC | 956 #ifdef SSR_DEC |
723 if (hDecoder->object_type != SSR) | 957 if (hDecoder->object_type != SSR) |
724 { | 958 { |
725 #endif | 959 #endif |
726 ifilter_bank(hDecoder->fb, ics->window_sequence, ics->window_shape, | 960 ifilter_bank(hDecoder->fb, ics->window_sequence, ics->window_shape, |
727 hDecoder->window_shape_prev[sce->channel], spec_coef, | 961 hDecoder->window_shape_prev[sce->channel], spec_coef, |
728 hDecoder->time_out[sce->channel], hDecoder->object_type, hDecoder->frameLength); | 962 hDecoder->time_out[sce->channel], hDecoder->fb_intermed[sce->channel], |
963 hDecoder->object_type, hDecoder->frameLength); | |
729 #ifdef SSR_DEC | 964 #ifdef SSR_DEC |
730 } else { | 965 } else { |
731 if (hDecoder->ssr_overlap[sce->channel] == NULL) | |
732 { | |
733 hDecoder->ssr_overlap[sce->channel] = (real_t*)malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
734 memset(hDecoder->ssr_overlap[sce->channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
735 } | |
736 if (hDecoder->prev_fmd[sce->channel] == NULL) | |
737 { | |
738 uint16_t k; | |
739 hDecoder->prev_fmd[sce->channel] = (real_t*)malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
740 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
741 hDecoder->prev_fmd[sce->channel][k] = REAL_CONST(-1); | |
742 } | |
743 | |
744 ssr_decode(&(ics->ssr), hDecoder->fb, ics->window_sequence, ics->window_shape, | 966 ssr_decode(&(ics->ssr), hDecoder->fb, ics->window_sequence, ics->window_shape, |
745 hDecoder->window_shape_prev[sce->channel], spec_coef, hDecoder->time_out[sce->channel], | 967 hDecoder->window_shape_prev[sce->channel], spec_coef, hDecoder->time_out[sce->channel], |
746 hDecoder->ssr_overlap[sce->channel], hDecoder->ipqf_buffer[sce->channel], hDecoder->prev_fmd[sce->channel], | 968 hDecoder->ssr_overlap[sce->channel], hDecoder->ipqf_buffer[sce->channel], hDecoder->prev_fmd[sce->channel], |
747 hDecoder->frameLength); | 969 hDecoder->frameLength); |
748 } | 970 } |
753 | 975 |
754 #ifdef LTP_DEC | 976 #ifdef LTP_DEC |
755 if (is_ltp_ot(hDecoder->object_type)) | 977 if (is_ltp_ot(hDecoder->object_type)) |
756 { | 978 { |
757 lt_update_state(hDecoder->lt_pred_stat[sce->channel], hDecoder->time_out[sce->channel], | 979 lt_update_state(hDecoder->lt_pred_stat[sce->channel], hDecoder->time_out[sce->channel], |
758 hDecoder->time_out[sce->channel]+hDecoder->frameLength, hDecoder->frameLength, hDecoder->object_type); | 980 hDecoder->fb_intermed[sce->channel], hDecoder->frameLength, hDecoder->object_type); |
759 } | 981 } |
760 #endif | 982 #endif |
983 | |
984 #ifdef SBR_DEC | |
985 if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
986 && hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) | |
987 { | |
988 uint8_t ele = hDecoder->fr_ch_ele; | |
989 uint8_t ch = sce->channel; | |
990 | |
991 /* following case can happen when forceUpSampling == 1 */ | |
992 if (hDecoder->sbr[ele] == NULL) | |
993 { | |
994 hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, | |
995 hDecoder->element_id[ele], 2*get_sample_rate(hDecoder->sf_index), | |
996 hDecoder->downSampledSBR | |
997 #ifdef DRM | |
998 , 0 | |
999 #endif | |
1000 ); | |
1001 } | |
1002 | |
1003 if (sce->ics1.window_sequence == EIGHT_SHORT_SEQUENCE) | |
1004 hDecoder->sbr[ele]->maxAACLine = 8*sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)]; | |
1005 else | |
1006 hDecoder->sbr[ele]->maxAACLine = sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)]; | |
1007 | |
1008 /* check if any of the PS tools is used */ | |
1009 #if (defined(PS_DEC) || defined(DRM_PS)) | |
1010 if (hDecoder->ps_used[ele] == 0) | |
1011 { | |
1012 #endif | |
1013 retval = sbrDecodeSingleFrame(hDecoder->sbr[ele], hDecoder->time_out[ch], | |
1014 hDecoder->postSeekResetFlag, hDecoder->downSampledSBR); | |
1015 #if (defined(PS_DEC) || defined(DRM_PS)) | |
1016 } else { | |
1017 retval = sbrDecodeSingleFramePS(hDecoder->sbr[ele], hDecoder->time_out[ch], | |
1018 hDecoder->time_out[ch+1], hDecoder->postSeekResetFlag, | |
1019 hDecoder->downSampledSBR); | |
1020 } | |
1021 #endif | |
1022 if (retval > 0) | |
1023 return retval; | |
1024 } else if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
1025 && !hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) | |
1026 { | |
1027 return 23; | |
1028 } | |
1029 #endif | |
1030 | |
1031 /* copy L to R when no PS is used */ | |
1032 #if (defined(PS_DEC) || defined(DRM_PS)) | |
1033 if ((hDecoder->ps_used[hDecoder->fr_ch_ele] == 0)) | |
1034 { | |
1035 uint8_t ele = hDecoder->fr_ch_ele; | |
1036 uint8_t ch = sce->channel; | |
1037 uint16_t frame_size = (hDecoder->sbr_alloced[ele]) ? 2 : 1; | |
1038 frame_size *= hDecoder->frameLength*sizeof(real_t); | |
1039 | |
1040 memcpy(hDecoder->time_out[ch+1], hDecoder->time_out[ch], frame_size); | |
1041 } | |
1042 #endif | |
1043 | |
1044 return 0; | |
761 } | 1045 } |
762 | 1046 |
763 void reconstruct_channel_pair(faacDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2, | 1047 uint8_t reconstruct_channel_pair(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2, |
764 element *cpe, int16_t *spec_data1, int16_t *spec_data2) | 1048 element *cpe, int16_t *spec_data1, int16_t *spec_data2) |
765 { | 1049 { |
766 real_t spec_coef1[1024]; | 1050 uint8_t retval; |
767 real_t spec_coef2[1024]; | 1051 ALIGN real_t spec_coef1[1024]; |
768 | 1052 ALIGN real_t spec_coef2[1024]; |
769 /* inverse quantization */ | 1053 |
770 inverse_quantization(spec_coef1, spec_data1, hDecoder->frameLength); | 1054 #ifdef PROFILE |
771 inverse_quantization(spec_coef2, spec_data2, hDecoder->frameLength); | 1055 int64_t count = faad_get_ts(); |
772 | 1056 #endif |
773 /* apply scalefactors */ | 1057 if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0) |
774 apply_scalefactors(hDecoder, ics1, spec_coef1, hDecoder->frameLength); | 1058 { |
775 apply_scalefactors(hDecoder, ics2, spec_coef2, hDecoder->frameLength); | 1059 retval = allocate_channel_pair(hDecoder, cpe->channel, (uint8_t)cpe->paired_channel); |
776 | 1060 if (retval > 0) |
777 /* deinterleave short block grouping */ | 1061 return retval; |
778 if (ics1->window_sequence == EIGHT_SHORT_SEQUENCE) | 1062 |
779 quant_to_spec(ics1, spec_coef1, hDecoder->frameLength); | 1063 hDecoder->element_alloced[hDecoder->fr_ch_ele] = 1; |
780 if (ics2->window_sequence == EIGHT_SHORT_SEQUENCE) | 1064 } |
781 quant_to_spec(ics2, spec_coef2, hDecoder->frameLength); | 1065 |
1066 /* dequantisation and scaling */ | |
1067 retval = quant_to_spec(hDecoder, ics1, spec_data1, spec_coef1, hDecoder->frameLength); | |
1068 if (retval > 0) | |
1069 return retval; | |
1070 retval = quant_to_spec(hDecoder, ics2, spec_data2, spec_coef2, hDecoder->frameLength); | |
1071 if (retval > 0) | |
1072 return retval; | |
1073 | |
1074 #ifdef PROFILE | |
1075 count = faad_get_ts() - count; | |
1076 hDecoder->requant_cycles += count; | |
1077 #endif | |
782 | 1078 |
783 | 1079 |
784 /* pns decoding */ | 1080 /* pns decoding */ |
785 if (ics1->ms_mask_present) | 1081 if (ics1->ms_mask_present) |
786 { | 1082 { |
791 } | 1087 } |
792 | 1088 |
793 /* mid/side decoding */ | 1089 /* mid/side decoding */ |
794 ms_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength); | 1090 ms_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength); |
795 | 1091 |
1092 #if 0 | |
1093 { | |
1094 int i; | |
1095 for (i = 0; i < 1024; i++) | |
1096 { | |
1097 //printf("%d\n", spec_coef1[i]); | |
1098 printf("0x%.8X\n", spec_coef1[i]); | |
1099 } | |
1100 for (i = 0; i < 1024; i++) | |
1101 { | |
1102 //printf("%d\n", spec_coef2[i]); | |
1103 printf("0x%.8X\n", spec_coef2[i]); | |
1104 } | |
1105 } | |
1106 #endif | |
1107 | |
796 /* intensity stereo decoding */ | 1108 /* intensity stereo decoding */ |
797 is_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength); | 1109 is_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength); |
1110 | |
1111 #if 0 | |
1112 { | |
1113 int i; | |
1114 for (i = 0; i < 1024; i++) | |
1115 { | |
1116 printf("%d\n", spec_coef1[i]); | |
1117 //printf("0x%.8X\n", spec_coef1[i]); | |
1118 } | |
1119 for (i = 0; i < 1024; i++) | |
1120 { | |
1121 printf("%d\n", spec_coef2[i]); | |
1122 //printf("0x%.8X\n", spec_coef2[i]); | |
1123 } | |
1124 } | |
1125 #endif | |
798 | 1126 |
799 #ifdef MAIN_DEC | 1127 #ifdef MAIN_DEC |
800 /* MAIN object type prediction */ | 1128 /* MAIN object type prediction */ |
801 if (hDecoder->object_type == MAIN) | 1129 if (hDecoder->object_type == MAIN) |
802 { | 1130 { |
803 /* allocate the state only when needed */ | |
804 if (hDecoder->pred_stat[cpe->channel] == NULL) | |
805 { | |
806 hDecoder->pred_stat[cpe->channel] = (pred_state*)malloc(hDecoder->frameLength * sizeof(pred_state)); | |
807 reset_all_predictors(hDecoder->pred_stat[cpe->channel], hDecoder->frameLength); | |
808 } | |
809 if (hDecoder->pred_stat[cpe->paired_channel] == NULL) | |
810 { | |
811 hDecoder->pred_stat[cpe->paired_channel] = (pred_state*)malloc(hDecoder->frameLength * sizeof(pred_state)); | |
812 reset_all_predictors(hDecoder->pred_stat[cpe->paired_channel], hDecoder->frameLength); | |
813 } | |
814 | |
815 /* intra channel prediction */ | 1131 /* intra channel prediction */ |
816 ic_prediction(ics1, spec_coef1, hDecoder->pred_stat[cpe->channel], hDecoder->frameLength, | 1132 ic_prediction(ics1, spec_coef1, hDecoder->pred_stat[cpe->channel], hDecoder->frameLength, |
817 hDecoder->sf_index); | 1133 hDecoder->sf_index); |
818 ic_prediction(ics2, spec_coef2, hDecoder->pred_stat[cpe->paired_channel], hDecoder->frameLength, | 1134 ic_prediction(ics2, spec_coef2, hDecoder->pred_stat[cpe->paired_channel], hDecoder->frameLength, |
819 hDecoder->sf_index); | 1135 hDecoder->sf_index); |
829 | 1145 |
830 #ifdef LTP_DEC | 1146 #ifdef LTP_DEC |
831 if (is_ltp_ot(hDecoder->object_type)) | 1147 if (is_ltp_ot(hDecoder->object_type)) |
832 { | 1148 { |
833 ltp_info *ltp1 = &(ics1->ltp); | 1149 ltp_info *ltp1 = &(ics1->ltp); |
834 ltp_info *ltp2 = (cpe->common_window) ? &(ics2->ltp2) : &(ics2->ltp) ; | 1150 ltp_info *ltp2 = (cpe->common_window) ? &(ics2->ltp2) : &(ics2->ltp); |
835 #ifdef LD_DEC | 1151 #ifdef LD_DEC |
836 if (hDecoder->object_type == LD) | 1152 if (hDecoder->object_type == LD) |
837 { | 1153 { |
838 if (ltp1->data_present) | 1154 if (ltp1->data_present) |
839 { | 1155 { |
848 } | 1164 } |
849 ltp2->lag = hDecoder->ltp_lag[cpe->paired_channel]; | 1165 ltp2->lag = hDecoder->ltp_lag[cpe->paired_channel]; |
850 } | 1166 } |
851 #endif | 1167 #endif |
852 | 1168 |
853 /* allocate the state only when needed */ | |
854 if (hDecoder->lt_pred_stat[cpe->channel] == NULL) | |
855 { | |
856 hDecoder->lt_pred_stat[cpe->channel] = (int16_t*)malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
857 memset(hDecoder->lt_pred_stat[cpe->channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
858 } | |
859 if (hDecoder->lt_pred_stat[cpe->paired_channel] == NULL) | |
860 { | |
861 hDecoder->lt_pred_stat[cpe->paired_channel] = (int16_t*)malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
862 memset(hDecoder->lt_pred_stat[cpe->paired_channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
863 } | |
864 | |
865 /* long term prediction */ | 1169 /* long term prediction */ |
866 lt_prediction(ics1, ltp1, spec_coef1, hDecoder->lt_pred_stat[cpe->channel], hDecoder->fb, | 1170 lt_prediction(ics1, ltp1, spec_coef1, hDecoder->lt_pred_stat[cpe->channel], hDecoder->fb, |
867 ics1->window_shape, hDecoder->window_shape_prev[cpe->channel], | 1171 ics1->window_shape, hDecoder->window_shape_prev[cpe->channel], |
868 hDecoder->sf_index, hDecoder->object_type, hDecoder->frameLength); | 1172 hDecoder->sf_index, hDecoder->object_type, hDecoder->frameLength); |
869 lt_prediction(ics2, ltp2, spec_coef2, hDecoder->lt_pred_stat[cpe->paired_channel], hDecoder->fb, | 1173 lt_prediction(ics2, ltp2, spec_coef2, hDecoder->lt_pred_stat[cpe->paired_channel], hDecoder->fb, |
885 drc_decode(hDecoder->drc, spec_coef1); | 1189 drc_decode(hDecoder->drc, spec_coef1); |
886 if (!hDecoder->drc->exclude_mask[cpe->paired_channel] || !hDecoder->drc->excluded_chns_present) | 1190 if (!hDecoder->drc->exclude_mask[cpe->paired_channel] || !hDecoder->drc->excluded_chns_present) |
887 drc_decode(hDecoder->drc, spec_coef2); | 1191 drc_decode(hDecoder->drc, spec_coef2); |
888 } | 1192 } |
889 | 1193 |
890 if (hDecoder->time_out[cpe->channel] == NULL) | |
891 { | |
892 hDecoder->time_out[cpe->channel] = (real_t*)malloc(hDecoder->frameLength*2*sizeof(real_t)); | |
893 memset(hDecoder->time_out[cpe->channel], 0, hDecoder->frameLength*2*sizeof(real_t)); | |
894 } | |
895 if (hDecoder->time_out[cpe->paired_channel] == NULL) | |
896 { | |
897 hDecoder->time_out[cpe->paired_channel] = (real_t*)malloc(hDecoder->frameLength*2*sizeof(real_t)); | |
898 memset(hDecoder->time_out[cpe->paired_channel], 0, hDecoder->frameLength*2*sizeof(real_t)); | |
899 } | |
900 | |
901 /* filter bank */ | 1194 /* filter bank */ |
902 #ifdef SSR_DEC | 1195 #ifdef SSR_DEC |
903 if (hDecoder->object_type != SSR) | 1196 if (hDecoder->object_type != SSR) |
904 { | 1197 { |
905 #endif | 1198 #endif |
906 ifilter_bank(hDecoder->fb, ics1->window_sequence, ics1->window_shape, | 1199 ifilter_bank(hDecoder->fb, ics1->window_sequence, ics1->window_shape, |
907 hDecoder->window_shape_prev[cpe->channel], spec_coef1, | 1200 hDecoder->window_shape_prev[cpe->channel], spec_coef1, |
908 hDecoder->time_out[cpe->channel], hDecoder->object_type, hDecoder->frameLength); | 1201 hDecoder->time_out[cpe->channel], hDecoder->fb_intermed[cpe->channel], |
1202 hDecoder->object_type, hDecoder->frameLength); | |
909 ifilter_bank(hDecoder->fb, ics2->window_sequence, ics2->window_shape, | 1203 ifilter_bank(hDecoder->fb, ics2->window_sequence, ics2->window_shape, |
910 hDecoder->window_shape_prev[cpe->paired_channel], spec_coef2, | 1204 hDecoder->window_shape_prev[cpe->paired_channel], spec_coef2, |
911 hDecoder->time_out[cpe->paired_channel], hDecoder->object_type, hDecoder->frameLength); | 1205 hDecoder->time_out[cpe->paired_channel], hDecoder->fb_intermed[cpe->paired_channel], |
1206 hDecoder->object_type, hDecoder->frameLength); | |
912 #ifdef SSR_DEC | 1207 #ifdef SSR_DEC |
913 } else { | 1208 } else { |
914 if (hDecoder->ssr_overlap[cpe->channel] == NULL) | |
915 { | |
916 hDecoder->ssr_overlap[cpe->channel] = (real_t*)malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
917 memset(hDecoder->ssr_overlap[cpe->channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
918 } | |
919 if (hDecoder->ssr_overlap[cpe->paired_channel] == NULL) | |
920 { | |
921 hDecoder->ssr_overlap[cpe->paired_channel] = (real_t*)malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
922 memset(hDecoder->ssr_overlap[cpe->paired_channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
923 } | |
924 if (hDecoder->prev_fmd[cpe->channel] == NULL) | |
925 { | |
926 uint16_t k; | |
927 hDecoder->prev_fmd[cpe->channel] = (real_t*)malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
928 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
929 hDecoder->prev_fmd[cpe->channel][k] = REAL_CONST(-1); | |
930 } | |
931 if (hDecoder->prev_fmd[cpe->paired_channel] == NULL) | |
932 { | |
933 uint16_t k; | |
934 hDecoder->prev_fmd[cpe->paired_channel] = (real_t*)malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
935 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
936 hDecoder->prev_fmd[cpe->paired_channel][k] = REAL_CONST(-1); | |
937 } | |
938 | |
939 ssr_decode(&(ics1->ssr), hDecoder->fb, ics1->window_sequence, ics1->window_shape, | 1209 ssr_decode(&(ics1->ssr), hDecoder->fb, ics1->window_sequence, ics1->window_shape, |
940 hDecoder->window_shape_prev[cpe->channel], spec_coef1, hDecoder->time_out[cpe->channel], | 1210 hDecoder->window_shape_prev[cpe->channel], spec_coef1, hDecoder->time_out[cpe->channel], |
941 hDecoder->ssr_overlap[cpe->channel], hDecoder->ipqf_buffer[cpe->channel], | 1211 hDecoder->ssr_overlap[cpe->channel], hDecoder->ipqf_buffer[cpe->channel], |
942 hDecoder->prev_fmd[cpe->channel], hDecoder->frameLength); | 1212 hDecoder->prev_fmd[cpe->channel], hDecoder->frameLength); |
943 ssr_decode(&(ics2->ssr), hDecoder->fb, ics2->window_sequence, ics2->window_shape, | 1213 ssr_decode(&(ics2->ssr), hDecoder->fb, ics2->window_sequence, ics2->window_shape, |
953 | 1223 |
954 #ifdef LTP_DEC | 1224 #ifdef LTP_DEC |
955 if (is_ltp_ot(hDecoder->object_type)) | 1225 if (is_ltp_ot(hDecoder->object_type)) |
956 { | 1226 { |
957 lt_update_state(hDecoder->lt_pred_stat[cpe->channel], hDecoder->time_out[cpe->channel], | 1227 lt_update_state(hDecoder->lt_pred_stat[cpe->channel], hDecoder->time_out[cpe->channel], |
958 hDecoder->time_out[cpe->channel]+hDecoder->frameLength, hDecoder->frameLength, hDecoder->object_type); | 1228 hDecoder->fb_intermed[cpe->channel], hDecoder->frameLength, hDecoder->object_type); |
959 lt_update_state(hDecoder->lt_pred_stat[cpe->paired_channel], hDecoder->time_out[cpe->paired_channel], | 1229 lt_update_state(hDecoder->lt_pred_stat[cpe->paired_channel], hDecoder->time_out[cpe->paired_channel], |
960 hDecoder->time_out[cpe->paired_channel]+hDecoder->frameLength, hDecoder->frameLength, | 1230 hDecoder->fb_intermed[cpe->paired_channel], hDecoder->frameLength, hDecoder->object_type); |
961 hDecoder->object_type); | 1231 } |
962 } | 1232 #endif |
963 #endif | 1233 |
1234 #ifdef SBR_DEC | |
1235 if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
1236 && hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) | |
1237 { | |
1238 uint8_t ele = hDecoder->fr_ch_ele; | |
1239 uint8_t ch0 = cpe->channel; | |
1240 uint8_t ch1 = cpe->paired_channel; | |
1241 | |
1242 /* following case can happen when forceUpSampling == 1 */ | |
1243 if (hDecoder->sbr[ele] == NULL) | |
1244 { | |
1245 hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, | |
1246 hDecoder->element_id[ele], 2*get_sample_rate(hDecoder->sf_index), | |
1247 hDecoder->downSampledSBR | |
1248 #ifdef DRM | |
1249 , 0 | |
1250 #endif | |
1251 ); | |
1252 } | |
1253 | |
1254 if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE) | |
1255 hDecoder->sbr[ele]->maxAACLine = 8*cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)]; | |
1256 else | |
1257 hDecoder->sbr[ele]->maxAACLine = cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)]; | |
1258 | |
1259 retval = sbrDecodeCoupleFrame(hDecoder->sbr[ele], | |
1260 hDecoder->time_out[ch0], hDecoder->time_out[ch1], | |
1261 hDecoder->postSeekResetFlag, hDecoder->downSampledSBR); | |
1262 if (retval > 0) | |
1263 return retval; | |
1264 } else if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
1265 && !hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) | |
1266 { | |
1267 return 23; | |
1268 } | |
1269 #endif | |
1270 | |
1271 return 0; | |
964 } | 1272 } |