1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_huff.c,v 1.21 2007/11/01 12:33:35 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include "sbr_syntax.h"
#include "bits.h"
#include "sbr_huff.h"
#include "sbr_e_nf.h"
/*
* Huffman tables describe structure and symbols of Huffman trees. Huffman tree
* is a kind of binary tree, i. e. each node is either a leaf or has 2 child
* nodes. Items of Huffman table describe non-leaf nodes, that is why those are
* represented by a pair of integers. Depending on a bit value left (0-th) or
* right (1-st) child chosen. If value is non-negative, then it is an index
* of next inner node. Otherwise it encodes a leaf (Huffman symbol). To get the
* symbol value 64 is added to leaf value. Since all integers are int8_t, the
* range of symbol values is -64..63.
*
* Note: table with N entries describes tree with N+1 leaves.
* Note: it is possible to extend range to -64..64, since index 0 is forbidden.
* Note: it is possible to extend the range even further by using deltas instead
* of absolute indices, switching to uint8_t, and employing all the values
* bigger than maximal delta.
*/
typedef const int8_t (*sbr_huff_tab)[2];
static const int8_t t_huffman_env_1_5dB[120][2] = {
{ 1, 2 }, { -64, -65 }, { 3, 4 }, { -63, -66 },
{ 5, 6 }, { -62, -67 }, { 7, 8 }, { -61, -68 },
{ 9, 10 }, { -60, -69 }, { 11, 12 }, { -59, -70 },
{ 13, 14 }, { -58, -71 }, { 15, 16 }, { -57, -72 },
{ 17, 18 }, { -73, -56 }, { 19, 21 }, { -74, 20 },
{ -55, -75 }, { 22, 26 }, { 23, 24 }, { -54, -76 },
{ -77, 25 }, { -53, -78 }, { 27, 34 }, { 28, 29 },
{ -52, -79 }, { 30, 31 }, { -80, -51 }, { 32, 33 },
{ -83, -82 }, { -81, -50 }, { 35, 57 }, { 36, 40 },
{ 37, 38 }, { -88, -84 }, { -48, 39 }, { -90, -85 },
{ 41, 46 }, { 42, 43 }, { -49, -87 }, { 44, 45 },
{ -89, -86 }, {-124,-123 }, { 47, 50 }, { 48, 49 },
{-122,-121 }, {-120,-119 }, { 51, 54 }, { 52, 53 },
{-118,-117 }, {-116,-115 }, { 55, 56 }, {-114,-113 },
{-112,-111 }, { 58, 89 }, { 59, 74 }, { 60, 67 },
{ 61, 64 }, { 62, 63 }, {-110,-109 }, {-108,-107 },
{ 65, 66 }, {-106,-105 }, {-104,-103 }, { 68, 71 },
{ 69, 70 }, {-102,-101 }, {-100, -99 }, { 72, 73 },
{ -98, -97 }, { -96, -95 }, { 75, 82 }, { 76, 79 },
{ 77, 78 }, { -94, -93 }, { -92, -91 }, { 80, 81 },
{ -47, -46 }, { -45, -44 }, { 83, 86 }, { 84, 85 },
{ -43, -42 }, { -41, -40 }, { 87, 88 }, { -39, -38 },
{ -37, -36 }, { 90, 105 }, { 91, 98 }, { 92, 95 },
{ 93, 94 }, { -35, -34 }, { -33, -32 }, { 96, 97 },
{ -31, -30 }, { -29, -28 }, { 99, 102 }, { 100, 101 },
{ -27, -26 }, { -25, -24 }, { 103, 104 }, { -23, -22 },
{ -21, -20 }, { 106, 113 }, { 107, 110 }, { 108, 109 },
{ -19, -18 }, { -17, -16 }, { 111, 112 }, { -15, -14 },
{ -13, -12 }, { 114, 117 }, { 115, 116 }, { -11, -10 },
{ -9, -8 }, { 118, 119 }, { -7, -6 }, { -5, -4 }
};
static const int8_t f_huffman_env_1_5dB[120][2] = {
{ 1, 2 }, { -64, -65 }, { 3, 4 }, { -63, -66 },
{ 5, 6 }, { -67, -62 }, { 7, 8 }, { -68, -61 },
{ 9, 10 }, { -69, -60 }, { 11, 13 }, { -70, 12 },
{ -59, -71 }, { 14, 16 }, { -58, 15 }, { -72, -57 },
{ 17, 19 }, { -73, 18 }, { -56, -74 }, { 20, 23 },
{ 21, 22 }, { -55, -75 }, { -54, -53 }, { 24, 27 },
{ 25, 26 }, { -76, -52 }, { -77, -51 }, { 28, 31 },
{ 29, 30 }, { -50, -78 }, { -79, -49 }, { 32, 36 },
{ 33, 34 }, { -48, -47 }, { -80, 35 }, { -81, -82 },
{ 37, 47 }, { 38, 41 }, { 39, 40 }, { -83, -46 },
{ -45, -84 }, { 42, 44 }, { -85, 43 }, { -44, -43 },
{ 45, 46 }, { -88, -87 }, { -86, -90 }, { 48, 66 },
{ 49, 56 }, { 50, 53 }, { 51, 52 }, { -92, -42 },
{ -41, -39 }, { 54, 55 }, {-105, -89 }, { -38, -37 },
{ 57, 60 }, { 58, 59 }, { -94, -91 }, { -40, -36 },
{ 61, 63 }, { -20, 62 }, {-115,-110 }, { 64, 65 },
{-108,-107 }, {-101, -97 }, { 67, 89 }, { 68, 75 },
{ 69, 72 }, { 70, 71 }, { -95, -93 }, { -34, -27 },
{ 73, 74 }, { -22, -17 }, { -16,-124 }, { 76, 82 },
{ 77, 79 }, {-123, 78 }, {-122,-121 }, { 80, 81 },
{-120,-119 }, {-118,-117 }, { 83, 86 }, { 84, 85 },
{-116,-114 }, {-113,-112 }, { 87, 88 }, {-111,-109 },
{-106,-104 }, { 90, 105 }, { 91, 98 }, { 92, 95 },
{ 93, 94 }, {-103,-102 }, {-100, -99 }, { 96, 97 },
{ -98, -96 }, { -35, -33 }, { 99, 102 }, { 100, 101 },
{ -32, -31 }, { -30, -29 }, { 103, 104 }, { -28, -26 },
{ -25, -24 }, { 106, 113 }, { 107, 110 }, { 108, 109 },
{ -23, -21 }, { -19, -18 }, { 111, 112 }, { -15, -14 },
{ -13, -12 }, { 114, 117 }, { 115, 116 }, { -11, -10 },
{ -9, -8 }, { 118, 119 }, { -7, -6 }, { -5, -4 }
};
static const int8_t t_huffman_env_bal_1_5dB[48][2] = {
{-64, 1}, {-62, 2}, {-66, 3}, {-60, 4}, {-68, 5},
{-58, 6}, {-70, 7}, {-56, 8}, {-72, 9}, {10, 11},
{-74, -54}, {12, 13}, {-76, -52}, {14, 28}, {15, 21},
{16, 18}, {-50, 17}, {-78, -48}, {19, 20}, {-112, -110},
{-108, -106}, {22, 25}, {23, 24}, {-104, -102}, {-100, -98},
{26, 27}, {-96, -94}, {-92, -90}, {29, 36}, {30, 33},
{31, 32}, {-88, -86}, {-84, -82}, {34, 35}, {-80, -46},
{-44, -42}, {37, 41}, {38, 39}, {-40, -38}, {-36, 40},
{-34, -32}, {42, 45}, {43, 44}, {-30, -28}, {-26, -24},
{46, 47}, {-22, -20}, {-18, -16}
};
static const int8_t f_huffman_env_bal_1_5dB[48][2] = {
{-64, 1}, {-66, 2}, {-62, 3}, {-68, 4}, {-60, 5},
{-58, 6}, {-70, 7}, {-72, 8}, {-56, 9}, {10, 11},
{-74, -54}, {-76, 12}, {-52, 13}, {14, 17}, {-78, 15},
{-50, 16}, {-48, -82}, {18, 32}, {19, 25}, {20, 22},
{-80, 21}, {-112, -110}, {23, 24}, {-108, -106}, {-104, -102},
{26, 29}, {27, 28}, {-100, -98}, {-96, -94}, {30, 31},
{-92, -90}, {-88, -86}, {33, 40}, {34, 37}, {35, 36},
{-84, -46}, {-44, -42}, {38, 39}, {-40, -38}, {-36, -34},
{41, 44}, {42, 43}, {-32, -30}, {-28, -26}, {45, 46},
{-24, -22}, {-20, 47}, {-18, -16}
};
static const int8_t t_huffman_env_3_0dB[62][2] = {
{ -64, 1 }, { -65, 2 }, { -63, 3 }, { -66, 4 },
{ -62, 5 }, { -67, 6 }, { -61, 7 }, { -68, 8 },
{ -60, 9 }, { 10, 11 }, { -69, -59 }, { 12, 14 },
{ -70, 13 }, { -71, -58 }, { 15, 18 }, { 16, 17 },
{ -72, -57 }, { -73, -74 }, { 19, 22 }, { -56, 20 },
{ -55, 21 }, { -54, -77 }, { 23, 31 }, { 24, 25 },
{ -75, -76 }, { 26, 27 }, { -78, -53 }, { 28, 29 },
{ -52, -95 }, { -94, 30 }, { -93, -92 }, { 32, 47 },
{ 33, 40 }, { 34, 37 }, { 35, 36 }, { -91, -90 },
{ -89, -88 }, { 38, 39 }, { -87, -86 }, { -85, -84 },
{ 41, 44 }, { 42, 43 }, { -83, -82 }, { -81, -80 },
{ 45, 46 }, { -79, -51 }, { -50, -49 }, { 48, 55 },
{ 49, 52 }, { 50, 51 }, { -48, -47 }, { -46, -45 },
{ 53, 54 }, { -44, -43 }, { -42, -41 }, { 56, 59 },
{ 57, 58 }, { -40, -39 }, { -38, -37 }, { 60, 61 },
{ -36, -35 }, { -34, -33 }
};
static const int8_t f_huffman_env_3_0dB[62][2] = {
{ -64, 1 }, { -65, 2 }, { -63, 3 }, { -66, 4 },
{ -62, 5 }, { -67, 6 }, { 7, 8 }, { -61, -68 },
{ 9, 10 }, { -60, -69 }, { 11, 12 }, { -59, -70 },
{ 13, 14 }, { -58, -71 }, { 15, 16 }, { -57, -72 },
{ 17, 19 }, { -56, 18 }, { -55, -73 }, { 20, 24 },
{ 21, 22 }, { -74, -54 }, { -53, 23 }, { -75, -76 },
{ 25, 30 }, { 26, 27 }, { -52, -51 }, { 28, 29 },
{ -77, -79 }, { -50, -49 }, { 31, 39 }, { 32, 35 },
{ 33, 34 }, { -78, -46 }, { -82, -88 }, { 36, 37 },
{ -83, -48 }, { -47, 38 }, { -86, -85 }, { 40, 47 },
{ 41, 44 }, { 42, 43 }, { -80, -44 }, { -43, -42 },
{ 45, 46 }, { -39, -87 }, { -84, -40 }, { 48, 55 },
{ 49, 52 }, { 50, 51 }, { -95, -94 }, { -93, -92 },
{ 53, 54 }, { -91, -90 }, { -89, -81 }, { 56, 59 },
{ 57, 58 }, { -45, -41 }, { -38, -37 }, { 60, 61 },
{ -36, -35 }, { -34, -33 }
};
static const int8_t t_huffman_env_bal_3_0dB[24][2] = {
{-64, 1}, {-62, 2}, {-66, 3}, {-68, 4}, {-60, 5}, {-58, 6},
{-70, 7}, {-72, 8}, {-56, 9}, {10, 16}, {11, 13}, {-74, 12},
{-88, -86}, {14, 15}, {-84, -82}, {-80, -78}, {17, 20}, {18, 19},
{-76, -54}, {-52, -50}, {21, 22}, {-48, -46}, {-44, 23}, {-42, -40}
};
static const int8_t f_huffman_env_bal_3_0dB[24][2] = {
{-64, 1}, {-66, 2}, {-62, 3}, {-68, 4}, {-60, 5}, {-58, 6},
{-70, 7}, {-72, 8}, {-56, 9}, {10, 13}, {-74, 11}, {-54, 12},
{-52, -88}, {14, 17}, {15, 16}, {-86, -84}, {-82, -80}, {18, 21},
{19, 20}, {-78, -76}, {-50, -48}, {22, 23}, {-46, -44}, {-42, -40}
};
static const int8_t t_huffman_noise_3_0dB[62][2] = {
{ -64, 1 }, { -63, 2 }, { -65, 3 }, { -66, 4 },
{ -62, 5 }, { -67, 6 }, { 7, 8 }, { -61, -68 },
{ 9, 30 }, { 10, 15 }, { -60, 11 }, { -69, 12 },
{ 13, 14 }, { -59, -53 }, { -95, -94 }, { 16, 23 },
{ 17, 20 }, { 18, 19 }, { -93, -92 }, { -91, -90 },
{ 21, 22 }, { -89, -88 }, { -87, -86 }, { 24, 27 },
{ 25, 26 }, { -85, -84 }, { -83, -82 }, { 28, 29 },
{ -81, -80 }, { -79, -78 }, { 31, 46 }, { 32, 39 },
{ 33, 36 }, { 34, 35 }, { -77, -76 }, { -75, -74 },
{ 37, 38 }, { -73, -72 }, { -71, -70 }, { 40, 43 },
{ 41, 42 }, { -58, -57 }, { -56, -55 }, { 44, 45 },
{ -54, -52 }, { -51, -50 }, { 47, 54 }, { 48, 51 },
{ 49, 50 }, { -49, -48 }, { -47, -46 }, { 52, 53 },
{ -45, -44 }, { -43, -42 }, { 55, 58 }, { 56, 57 },
{ -41, -40 }, { -39, -38 }, { 59, 60 }, { -37, -36 },
{ -35, 61 }, { -34, -33 }
};
static const int8_t t_huffman_noise_bal_3_0dB[24][2] = {
{-64, 1}, {-66, 2}, {-62, 3}, {4, 9}, {-68, 5}, {-60, 6},
{7, 8}, {-88, -86}, {-84, -82}, {10, 17}, {11, 14}, {12, 13},
{-80, -78}, {-76, -74}, {15, 16}, {-72, -70}, {-58, -56}, {18, 21},
{19, 20}, {-54, -52}, {-50, -48}, {22, 23}, {-46, -44}, {-42, -40}
};
static INLINE int16_t sbr_huff_dec(bitfile *ld, sbr_huff_tab t_huff)
{
uint8_t bit;
int16_t index = 0;
while (index >= 0)
{
bit = (uint8_t)faad_get1bit(ld);
index = t_huff[index][bit];
}
return index + 64;
}
/* table 10 */
void sbr_envelope(bitfile *ld, sbr_info *sbr, uint8_t ch)
{
uint8_t env, band;
int8_t delta = 0;
sbr_huff_tab t_huff, f_huff;
if ((sbr->L_E[ch] == 1) && (sbr->bs_frame_class[ch] == FIXFIX))
sbr->amp_res[ch] = 0;
else
sbr->amp_res[ch] = sbr->bs_amp_res;
if ((sbr->bs_coupling) && (ch == 1))
{
delta = 1;
if (sbr->amp_res[ch])
{
t_huff = t_huffman_env_bal_3_0dB;
f_huff = f_huffman_env_bal_3_0dB;
} else {
t_huff = t_huffman_env_bal_1_5dB;
f_huff = f_huffman_env_bal_1_5dB;
}
} else {
delta = 0;
if (sbr->amp_res[ch])
{
t_huff = t_huffman_env_3_0dB;
f_huff = f_huffman_env_3_0dB;
} else {
t_huff = t_huffman_env_1_5dB;
f_huff = f_huffman_env_1_5dB;
}
}
for (env = 0; env < sbr->L_E[ch]; env++)
{
if (sbr->bs_df_env[ch][env] == 0)
{
if ((sbr->bs_coupling == 1) && (ch == 1))
{
if (sbr->amp_res[ch])
{
sbr->E[ch][0][env] = (uint16_t)(faad_getbits(ld, 5
DEBUGVAR(1,272,"sbr_envelope(): bs_data_env")) << delta);
} else {
sbr->E[ch][0][env] = (uint16_t)(faad_getbits(ld, 6
DEBUGVAR(1,273,"sbr_envelope(): bs_data_env")) << delta);
}
} else {
if (sbr->amp_res[ch])
{
sbr->E[ch][0][env] = (uint16_t)(faad_getbits(ld, 6
DEBUGVAR(1,274,"sbr_envelope(): bs_data_env")) << delta);
} else {
sbr->E[ch][0][env] = (uint16_t)(faad_getbits(ld, 7
DEBUGVAR(1,275,"sbr_envelope(): bs_data_env")) << delta);
}
}
for (band = 1; band < sbr->n[sbr->f[ch][env]]; band++)
{
sbr->E[ch][band][env] = (sbr_huff_dec(ld, f_huff));
}
} else {
for (band = 0; band < sbr->n[sbr->f[ch][env]]; band++)
{
sbr->E[ch][band][env] = (sbr_huff_dec(ld, t_huff));
}
}
}
extract_envelope_data(sbr, ch);
}
/* table 11 */
void sbr_noise(bitfile *ld, sbr_info *sbr, uint8_t ch)
{
uint8_t noise, band;
int8_t delta = 0;
sbr_huff_tab t_huff, f_huff;
if ((sbr->bs_coupling == 1) && (ch == 1))
{
delta = 1;
t_huff = t_huffman_noise_bal_3_0dB;
f_huff = f_huffman_env_bal_3_0dB;
} else {
delta = 0;
t_huff = t_huffman_noise_3_0dB;
f_huff = f_huffman_env_3_0dB;
}
for (noise = 0; noise < sbr->L_Q[ch]; noise++)
{
if(sbr->bs_df_noise[ch][noise] == 0)
{
if ((sbr->bs_coupling == 1) && (ch == 1))
{
sbr->Q[ch][0][noise] = (faad_getbits(ld, 5
DEBUGVAR(1,276,"sbr_noise(): bs_data_noise")) << delta);
} else {
sbr->Q[ch][0][noise] = (faad_getbits(ld, 5
DEBUGVAR(1,277,"sbr_noise(): bs_data_noise")) << delta);
}
for (band = 1; band < sbr->N_Q; band++)
{
sbr->Q[ch][band][noise] = (sbr_huff_dec(ld, f_huff));
}
} else {
for (band = 0; band < sbr->N_Q; band++)
{
sbr->Q[ch][band][noise] = (sbr_huff_dec(ld, t_huff));
}
}
}
extract_noise_floor_data(sbr, ch);
}
#endif
|