📄 drm_dec.c
字号:
/*** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR and PS decoding** Copyright (C) 2003-2004 M. Bakker, Ahead Software 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.**** Commercial non-GPL licensing of this software is possible.** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.**** $Id: drm_dec.c,v 1.5 2004/09/04 14:56:28 menno Exp $**/#include <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>#include "common.h"#ifdef DRM#include "sbr_dec.h"#include "drm_dec.h"#include "bits.h"/* constants */#define DECAY_CUTOFF 3#define DECAY_SLOPE 0.05f/* type definitaions */typedef const int8_t (*drm_ps_huff_tab)[2];/* binary search huffman tables */static const int8_t f_huffman_sa[][2] = { { /*0*/ -15, 1 }, /* index 0: 1 bits: x */ { 2, 3 }, /* index 1: 2 bits: 1x */ { /*7*/ -8, 4 }, /* index 2: 3 bits: 10x */ { 5, 6 }, /* index 3: 3 bits: 11x */ { /*1*/ -14, /*-1*/ -16 }, /* index 4: 4 bits: 101x */ { /*-2*/ -17, 7 }, /* index 5: 4 bits: 110x */ { 8, 9 }, /* index 6: 4 bits: 111x */ { /*2*/ -13, /*-3*/ -18 }, /* index 7: 5 bits: 1101x */ { /*3*/ -12, 10 }, /* index 8: 5 bits: 1110x */ { 11, 12 }, /* index 9: 5 bits: 1111x */ { /*4*/ -11, /*5*/ -10 }, /* index 10: 6 bits: 11101x */ { /*-4*/ -19, /*-5*/ -20 }, /* index 11: 6 bits: 11110x */ { /*6*/ -9, 13 }, /* index 12: 6 bits: 11111x */ { /*-7*/ -22, /*-6*/ -21 } /* index 13: 7 bits: 111111x */};static const int8_t t_huffman_sa[][2] = { { /*0*/ -15, 1 }, /* index 0: 1 bits: x */ { 2, 3 }, /* index 1: 2 bits: 1x */ { /*-1*/ -16, /*1*/ -14 }, /* index 2: 3 bits: 10x */ { 4, 5 }, /* index 3: 3 bits: 11x */ { /*-2*/ -17, /*2*/ -13 }, /* index 4: 4 bits: 110x */ { 6, 7 }, /* index 5: 4 bits: 111x */ { /*-3*/ -18, /*3*/ -12 }, /* index 6: 5 bits: 1110x */ { 8, 9 }, /* index 7: 5 bits: 1111x */ { /*-4*/ -19, /*4*/ -11 }, /* index 8: 6 bits: 11110x */ { 10, 11 }, /* index 9: 6 bits: 11111x */ { /*-5*/ -20, /*5*/ -10 }, /* index 10: 7 bits: 111110x */ { /*-6*/ -21, 12 }, /* index 11: 7 bits: 111111x */ { /*-7*/ -22, 13 }, /* index 12: 8 bits: 1111111x */ { /*6*/ -9, /*7*/ -8 } /* index 13: 9 bits: 11111111x */};static const int8_t f_huffman_pan[][2] = { { /*0*/ -15, 1 }, /* index 0: 1 bits: x */ { /*-1*/ -16, 2 }, /* index 1: 2 bits: 1x */ { /*1*/ -14, 3 }, /* index 2: 3 bits: 11x */ { 4, 5 }, /* index 3: 4 bits: 111x */ { /*-2*/ -17, /*2*/ -13 }, /* index 4: 5 bits: 1110x */ { 6, 7 }, /* index 5: 5 bits: 1111x */ { /*-3*/ -18, /*3*/ -12 }, /* index 6: 6 bits: 11110x */ { 8, 9 }, /* index 7: 6 bits: 11111x */ { /*-4*/ -19, /*4*/ -11 }, /* index 8: 7 bits: 111110x */ { 10, 11 }, /* index 9: 7 bits: 111111x */ { /*-5*/ -20, /*5*/ -10 }, /* index 10: 8 bits: 1111110x */ { 12, 13 }, /* index 11: 8 bits: 1111111x */ { /*-6*/ -21, /*6*/ -9 }, /* index 12: 9 bits: 11111110x */ { /*-7*/ -22, 14 }, /* index 13: 9 bits: 11111111x */ { /*7*/ -8, 15 }, /* index 14: 10 bits: 111111111x */ { 16, 17 }, /* index 15: 11 bits: 1111111111x */ { /*-8*/ -23, /*8*/ -7 }, /* index 16: 12 bits: 11111111110x */ { 18, 19 }, /* index 17: 12 bits: 11111111111x */ { /*-10*/ -25, 20 }, /* index 18: 13 bits: 111111111110x */ { 21, 22 }, /* index 19: 13 bits: 111111111111x */ { /*-9*/ -24, /*9*/ -6 }, /* index 20: 14 bits: 1111111111101x */ { /*10*/ -5, 23 }, /* index 21: 14 bits: 1111111111110x */ { 24, 25 }, /* index 22: 14 bits: 1111111111111x */ { /*-13*/ -28, /*-11*/ -26 }, /* index 23: 15 bits: 11111111111101x */ { /*11*/ -4, /*13*/ -2 }, /* index 24: 15 bits: 11111111111110x */ { 26, 27 }, /* index 25: 15 bits: 11111111111111x */ { /*-14*/ -29, /*-12*/ -27 }, /* index 26: 16 bits: 111111111111110x */ { /*12*/ -3, /*14*/ -1 } /* index 27: 16 bits: 111111111111111x */};static const int8_t t_huffman_pan[][2] = { { /*0*/ -15, 1 }, /* index 0: 1 bits: x */ { /*-1*/ -16, 2 }, /* index 1: 2 bits: 1x */ { /*1*/ -14, 3 }, /* index 2: 3 bits: 11x */ { /*-2*/ -17, 4 }, /* index 3: 4 bits: 111x */ { /*2*/ -13, 5 }, /* index 4: 5 bits: 1111x */ { /*-3*/ -18, 6 }, /* index 5: 6 bits: 11111x */ { /*3*/ -12, 7 }, /* index 6: 7 bits: 111111x */ { /*-4*/ -19, 8 }, /* index 7: 8 bits: 1111111x */ { /*4*/ -11, 9 }, /* index 8: 9 bits: 11111111x */ { 10, 11 }, /* index 9: 10 bits: 111111111x */ { /*-5*/ -20, /*5*/ -10 }, /* index 10: 11 bits: 1111111110x */ { 12, 13 }, /* index 11: 11 bits: 1111111111x */ { /*-6*/ -21, /*6*/ -9 }, /* index 12: 12 bits: 11111111110x */ { 14, 15 }, /* index 13: 12 bits: 11111111111x */ { /*-7*/ -22, /*7*/ -8 }, /* index 14: 13 bits: 111111111110x */ { 16, 17 }, /* index 15: 13 bits: 111111111111x */ { /*-8*/ -23, /*8*/ -7 }, /* index 16: 14 bits: 1111111111110x */ { 18, 19 }, /* index 17: 14 bits: 1111111111111x */ { /*-10*/ -25, /*10*/ -5 }, /* index 18: 15 bits: 11111111111110x */ { 20, 21 }, /* index 19: 15 bits: 11111111111111x */ { /*-9*/ -24, /*9*/ -6 }, /* index 20: 16 bits: 111111111111110x */ { 22, 23 }, /* index 21: 16 bits: 111111111111111x */ { 24, 25 }, /* index 22: 17 bits: 1111111111111110x */ { 26, 27 }, /* index 23: 17 bits: 1111111111111111x */ { /*-14*/ -29, /*-13*/ -28 }, /* index 24: 18 bits: 11111111111111100x */ { /*-12*/ -27, /*-11*/ -26 }, /* index 25: 18 bits: 11111111111111101x */ { /*11*/ -4, /*12*/ -3 }, /* index 26: 18 bits: 11111111111111110x */ { /*13*/ -2, /*14*/ -1 } /* index 27: 18 bits: 11111111111111111x */};/* There are 3 classes in the standard but the last 2 are identical */static const real_t sa_quant[8][2] = { { FRAC_CONST(0.0000), FRAC_CONST(0.0000) }, { FRAC_CONST(0.0501), FRAC_CONST(0.1778) }, { FRAC_CONST(0.0706), FRAC_CONST(0.2818) }, { FRAC_CONST(0.0995), FRAC_CONST(0.4467) }, { FRAC_CONST(0.1399), FRAC_CONST(0.5623) }, { FRAC_CONST(0.1957), FRAC_CONST(0.7079) }, { FRAC_CONST(0.2713), FRAC_CONST(0.8913) }, { FRAC_CONST(0.3699), FRAC_CONST(1.0000) },};/* We don't need the actual quantizer values */#if 0static const real_t pan_quant[8][5] = { { COEF_CONST(0.0000), COEF_CONST(0.0000), COEF_CONST(0.0000), COEF_CONST(0.0000), COEF_CONST(0.0000) }, { COEF_CONST(0.1661), COEF_CONST(0.1661), COEF_CONST(0.3322), COEF_CONST(0.3322), COEF_CONST(0.3322) }, { COEF_CONST(0.3322), COEF_CONST(0.3322), COEF_CONST(0.6644), COEF_CONST(0.8305), COEF_CONST(0.8305) }, { COEF_CONST(0.4983), COEF_CONST(0.6644), COEF_CONST(0.9966), COEF_CONST(1.4949), COEF_CONST(1.6610) }, { COEF_CONST(0.6644), COEF_CONST(0.9966), COEF_CONST(1.4949), COEF_CONST(2.1593), COEF_CONST(2.4914) }, { COEF_CONST(0.8305), COEF_CONST(1.3288), COEF_CONST(2.1593), COEF_CONST(2.9897), COEF_CONST(3.4880) }, { COEF_CONST(0.9966), COEF_CONST(1.8271), COEF_CONST(2.8236), COEF_CONST(3.8202), COEF_CONST(4.6507) }, { COEF_CONST(1.3288), COEF_CONST(2.3253), COEF_CONST(3.4880), COEF_CONST(4.6507), COEF_CONST(5.8134) },};#endif/* 2^(pan_quant[x][y] */static const real_t pan_pow_2_pos[8][5] = { { REAL_CONST(1.0000000), REAL_CONST(1.0000000), REAL_CONST(1.0000000), REAL_CONST(1.0000000), REAL_CONST(1.0000000) }, { REAL_CONST(1.1220021), REAL_CONST(1.1220021), REAL_CONST(1.2589312), REAL_CONST(1.2589312), REAL_CONST(1.2589312) }, { REAL_CONST(1.2589312), REAL_CONST(1.2589312), REAL_CONST(1.5849090), REAL_CONST(1.7783016), REAL_CONST(1.7783016) }, { REAL_CONST(1.4125481), REAL_CONST(1.5849090), REAL_CONST(1.9952921), REAL_CONST(2.8184461), REAL_CONST(3.1623565) }, { REAL_CONST(1.5849090), REAL_CONST(1.9952922), REAL_CONST(2.8184461), REAL_CONST(4.4669806), REAL_CONST(5.6232337) }, { REAL_CONST(1.7783016), REAL_CONST(2.5119365), REAL_CONST(4.4669806), REAL_CONST(7.9430881), REAL_CONST(11.219994) }, { REAL_CONST(1.9952921), REAL_CONST(3.5482312), REAL_CONST(7.0792671), REAL_CONST(14.125206), REAL_CONST(25.118876) }, { REAL_CONST(2.5119365), REAL_CONST(5.0116998), REAL_CONST(11.219994), REAL_CONST(25.118876), REAL_CONST(56.235140) }};/* 2^(-pan_quant[x][y] */static const real_t pan_pow_2_neg[8][5] = { { REAL_CONST(1), REAL_CONST(1), REAL_CONST(1), REAL_CONST(1), REAL_CONST(1) }, { REAL_CONST(0.8912487), REAL_CONST(0.8912487), REAL_CONST(0.7943242), REAL_CONST(0.7943242), REAL_CONST(0.7943242) }, { REAL_CONST(0.7943242), REAL_CONST(0.7943242), REAL_CONST(0.6309511), REAL_CONST(0.5623344), REAL_CONST(0.5623344) }, { REAL_CONST(0.7079405), REAL_CONST(0.6309511), REAL_CONST(0.5011797), REAL_CONST(0.3548054), REAL_CONST(0.3162199) }, { REAL_CONST(0.6309511), REAL_CONST(0.5011797), REAL_CONST(0.3548054), REAL_CONST(0.2238649), REAL_CONST(0.1778336) }, { REAL_CONST(0.5623343), REAL_CONST(0.3980992), REAL_CONST(0.2238649), REAL_CONST(0.1258956), REAL_CONST(0.0891266) }, { REAL_CONST(0.5011797), REAL_CONST(0.2818306), REAL_CONST(0.1412576), REAL_CONST(0.0707954), REAL_CONST(0.0398107) }, { REAL_CONST(0.3980992), REAL_CONST(0.1995331), REAL_CONST(0.0891267), REAL_CONST(0.0398107), REAL_CONST(0.0177825) }};/* 2^(pan_quant[x][y]/30) */static const real_t pan_pow_2_30_pos[8][5] = { { COEF_CONST(1), COEF_CONST(1), COEF_CONST(1), COEF_CONST(1), COEF_CONST(1) }, { COEF_CONST(1.003845098), COEF_CONST(1.003845098), COEF_CONST(1.007704982), COEF_CONST(1.007704982), COEF_CONST(1.007704982) }, { COEF_CONST(1.007704982), COEF_CONST(1.007704982), COEF_CONST(1.01546933), COEF_CONST(1.019373909), COEF_CONST(1.019373909) }, { COEF_CONST(1.011579706), COEF_CONST(1.01546933), COEF_CONST(1.023293502), COEF_CONST(1.035142941), COEF_CONST(1.039123167) }, { COEF_CONST(1.01546933), COEF_CONST(1.023293502), COEF_CONST(1.035142941), COEF_CONST(1.051155908), COEF_CONST(1.059252598) }, { COEF_CONST(1.019373909), COEF_CONST(1.03117796), COEF_CONST(1.051155908), COEF_CONST(1.071518432), COEF_CONST(1.0839263) }, { COEF_CONST(1.023293502), COEF_CONST(1.043118698), COEF_CONST(1.067414119), COEF_CONST(1.092277933), COEF_CONST(1.113439626) }, { COEF_CONST(1.03117796), COEF_CONST(1.055195268), COEF_CONST(1.0839263), COEF_CONST(1.113439626), COEF_CONST(1.143756546) }};/* 2^(-pan_quant[x][y]/30) */static const real_t pan_pow_2_30_neg[8][5] = { { COEF_CONST(1), COEF_CONST(1), COEF_CONST(1), COEF_CONST(1), COEF_CONST(1) }, { COEF_CONST(0.99616963), COEF_CONST(0.99616963), COEF_CONST(0.992353931), COEF_CONST(0.992353931), COEF_CONST(0.99235393) }, { COEF_CONST(0.992353931), COEF_CONST(0.992353931), COEF_CONST(0.984766325), COEF_CONST(0.980994305), COEF_CONST(0.980994305) }, { COEF_CONST(0.988552848), COEF_CONST(0.984766325), COEF_CONST(0.977236734), COEF_CONST(0.966050157), COEF_CONST(0.962349827) }, { COEF_CONST(0.984766325), COEF_CONST(0.977236734), COEF_CONST(0.966050157), COEF_CONST(0.951333663), COEF_CONST(0.944061881) }, { COEF_CONST(0.980994305), COEF_CONST(0.969764715), COEF_CONST(0.951333663), COEF_CONST(0.933255062), COEF_CONST(0.922571949) }, { COEF_CONST(0.977236734), COEF_CONST(0.958663671), COEF_CONST(0.936843519), COEF_CONST(0.915517901), COEF_CONST(0.898117847) }, { COEF_CONST(0.969764715), COEF_CONST(0.947691892), COEF_CONST(0.922571949), COEF_CONST(0.898117847), COEF_CONST(0.874311936) }};static const real_t g_decayslope[MAX_SA_BAND] = { FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.95),FRAC_CONST(0.9), FRAC_CONST(0.85), FRAC_CONST(0.8), FRAC_CONST(0.75),FRAC_CONST(0.7), FRAC_CONST(0.65),FRAC_CONST(0.6), FRAC_CONST(0.55),FRAC_CONST(0.5), FRAC_CONST(0.45), FRAC_CONST(0.4), FRAC_CONST(0.35),FRAC_CONST(0.3), FRAC_CONST(0.25),FRAC_CONST(0.2), FRAC_CONST(0.15), FRAC_CONST(0.1), FRAC_CONST(0.05),FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0)};static const real_t sa_sqrt_1_minus[8][2] = { { FRAC_CONST(1), FRAC_CONST(1) }, { FRAC_CONST(0.998744206), FRAC_CONST(0.984066644) }, { FRAC_CONST(0.997504707), FRAC_CONST(0.959473168) }, { FRAC_CONST(0.995037562), FRAC_CONST(0.894683804) }, { FRAC_CONST(0.990165638), FRAC_CONST(0.826933317) }, { FRAC_CONST(0.980663811), FRAC_CONST(0.706312672) }, { FRAC_CONST(0.962494836), FRAC_CONST(0.45341406) }, { FRAC_CONST(0.929071574), FRAC_CONST(0) }};static const uint8_t sa_freq_scale[9][2] = { { 0, 0},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -