annotate libfaad2/sbr_fbt.c @ 14564:f85875877de9

tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
author nicodvb
date Fri, 21 Jan 2005 20:50:09 +0000
parents 6d50ef45a058
children 2ae5ab4331ca
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 **
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
26 ** $Id: sbr_fbt.c,v 1.4 2004/06/23 13:50:51 diego Exp $
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 /* Calculate frequency band tables */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 #include "sbr_syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 #include "sbr_fbt.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
42 /* static function declarations */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
43 static int32_t find_bands(uint8_t warp, uint8_t bands, uint8_t a0, uint8_t a1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
44
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
45
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 /* calculate the start QMF channel for the master frequency band table */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 /* parameter is also called k0 */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
48 uint8_t qmf_start_channel(uint8_t bs_start_freq, uint8_t bs_samplerate_mode,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 uint32_t sample_rate)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
51 static const uint8_t startMinTable[12] = { 7, 7, 10, 11, 12, 16, 16,
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
52 17, 24, 32, 35, 48 };
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
53 static const uint8_t offsetIndexTable[12] = { 5, 5, 4, 4, 4, 3, 2, 1, 0,
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
54 6, 6, 6 };
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
55 static const int8_t offset[7][16] = {
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 { -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 { -5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 { -6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 { -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 { -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 { 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24, 28, 33 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 };
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
64 uint8_t startMin = startMinTable[get_sr_index(sample_rate)];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
65 uint8_t offsetIndex = offsetIndexTable[get_sr_index(sample_rate)];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
67 #if 0 /* replaced with table (startMinTable) */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 if (sample_rate >= 64000)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 startMin = (uint8_t)((5000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 } else if (sample_rate < 32000) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 startMin = (uint8_t)((3000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 startMin = (uint8_t)((4000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 }
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
76 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 if (bs_samplerate_mode)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
80 return startMin + offset[offsetIndex][bs_start_freq];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
81
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
82 #if 0 /* replaced by offsetIndexTable */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 switch (sample_rate)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 case 16000:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 return startMin + offset[0][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 case 22050:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 return startMin + offset[1][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 case 24000:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 return startMin + offset[2][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 case 32000:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 return startMin + offset[3][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 default:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 if (sample_rate > 64000)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 return startMin + offset[5][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 } else { /* 44100 <= sample_rate <= 64000 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 return startMin + offset[4][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 }
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
101 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 return startMin + offset[6][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 }
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 static int longcmp(const void *a, const void *b)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
109 return ((int)(*(int32_t*)a - *(int32_t*)b));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 /* calculate the stop QMF channel for the master frequency band table */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 /* parameter is also called k2 */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
114 uint8_t qmf_stop_channel(uint8_t bs_stop_freq, uint32_t sample_rate,
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
115 uint8_t k0)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 if (bs_stop_freq == 15)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 return min(64, k0 * 3);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 } else if (bs_stop_freq == 14) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 return min(64, k0 * 2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 } else {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
123 static const uint8_t stopMinTable[12] = { 13, 15, 20, 21, 23,
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
124 32, 32, 35, 48, 64, 70, 96 };
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
125 static const int8_t offset[12][14] = {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
126 { 0, 2, 4, 6, 8, 11, 14, 18, 22, 26, 31, 37, 44, 51 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
127 { 0, 2, 4, 6, 8, 11, 14, 18, 22, 26, 31, 36, 42, 49 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
128 { 0, 2, 4, 6, 8, 11, 14, 17, 21, 25, 29, 34, 39, 44 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
129 { 0, 2, 4, 6, 8, 11, 14, 17, 20, 24, 28, 33, 38, 43 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
130 { 0, 2, 4, 6, 8, 11, 14, 17, 20, 24, 28, 32, 36, 41 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
131 { 0, 2, 4, 6, 8, 10, 12, 14, 17, 20, 23, 26, 29, 32 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
132 { 0, 2, 4, 6, 8, 10, 12, 14, 17, 20, 23, 26, 29, 32 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
133 { 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 20, 23, 26, 29 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
134 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
135 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
136 { 0, -1, -2, -3, -4, -5, -6, -6, -6, -6, -6, -6, -6, -6 },
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
137 { 0, -3, -6, -9, -12, -15, -18, -20, -22, -24, -26, -28, -30, -32 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
138 };
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
139 #if 0
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 int32_t stopDk[13], stopDk_t[14], k2;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
142 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
143 uint8_t stopMin = stopMinTable[get_sr_index(sample_rate)];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
145 #if 0 /* replaced by table lookup */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 if (sample_rate >= 64000)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 stopMin = (uint8_t)((10000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 } else if (sample_rate < 32000) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 stopMin = (uint8_t)((6000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 stopMin = (uint8_t)((8000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 }
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
154 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
156 #if 0 /* replaced by table lookup */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
157 /* diverging power series */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 for (i = 0; i <= 13; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 stopDk_t[i] = (int32_t)(stopMin*pow(64.0/stopMin, i/13.0) + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 for (i = 0; i < 13; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 stopDk[i] = stopDk_t[i+1] - stopDk_t[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
167 /* needed? */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 qsort(stopDk, 13, sizeof(stopDk[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 k2 = stopMin;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 for (i = 0; i < bs_stop_freq; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 k2 += stopDk[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 return min(64, k2);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
176 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
177 /* bs_stop_freq <= 13 */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
178 return min(64, stopMin + offset[get_sr_index(sample_rate)][min(bs_stop_freq, 13)]);
10725
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 return 0;
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 /* calculate the master frequency table from k0, k2, bs_freq_scale
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 and bs_alter_scale
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 version for bs_freq_scale = 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
189 uint8_t master_frequency_table_fs0(sbr_info *sbr, uint8_t k0, uint8_t k2,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
190 uint8_t bs_alter_scale)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 int8_t incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 uint8_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 uint8_t dk;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 uint32_t nrBands, k2Achieved;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
196 int32_t k2Diff, vDk[64] = {0};
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 /* mft only defined for k2 > k0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 if (k2 <= k0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 sbr->N_master = 0;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
202 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 dk = bs_alter_scale ? 2 : 1;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
206
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
207 #if 0 /* replaced by float-less design */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 nrBands = 2 * (int32_t)((float)(k2-k0)/(dk*2) + (-1+dk)/2.0f);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
209 #else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
210 if (bs_alter_scale)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
211 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
212 nrBands = (((k2-k0+2)>>2)<<1);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
213 } else {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
214 nrBands = (((k2-k0)>>1)<<1);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
215 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
216 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
217 nrBands = min(nrBands, 63);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
218 if (nrBands <= 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
219 return 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 k2Achieved = k0 + nrBands * dk;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 k2Diff = k2 - k2Achieved;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 for (k = 0; k < nrBands; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 vDk[k] = dk;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 if (k2Diff)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 incr = (k2Diff > 0) ? -1 : 1;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
229 k = (uint8_t) ((k2Diff > 0) ? (nrBands-1) : 0);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 while (k2Diff != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 vDk[k] -= incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 k += incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 k2Diff += incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 sbr->f_master[0] = k0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 for (k = 1; k <= nrBands; k++)
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
241 sbr->f_master[k] = (uint8_t)(sbr->f_master[k-1] + vDk[k-1]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
243 sbr->N_master = (uint8_t)nrBands;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
244 sbr->N_master = (min(sbr->N_master, 64));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 printf("f_master[%d]: ", nrBands);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 for (k = 0; k <= nrBands; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 printf("%d ", sbr->f_master[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
254
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
255 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
258 /*
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
259 This function finds the number of bands using this formula:
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
260 bands * log(a1/a0)/log(2.0) + 0.5
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
261 */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
262 static int32_t find_bands(uint8_t warp, uint8_t bands, uint8_t a0, uint8_t a1)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
263 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
264 #ifdef FIXED_POINT
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
265 /* table with log2() values */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
266 static const real_t log2Table[65] = {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
267 COEF_CONST(0.0), COEF_CONST(0.0), COEF_CONST(1.0000000000), COEF_CONST(1.5849625007),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
268 COEF_CONST(2.0000000000), COEF_CONST(2.3219280949), COEF_CONST(2.5849625007), COEF_CONST(2.8073549221),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
269 COEF_CONST(3.0000000000), COEF_CONST(3.1699250014), COEF_CONST(3.3219280949), COEF_CONST(3.4594316186),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
270 COEF_CONST(3.5849625007), COEF_CONST(3.7004397181), COEF_CONST(3.8073549221), COEF_CONST(3.9068905956),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
271 COEF_CONST(4.0000000000), COEF_CONST(4.0874628413), COEF_CONST(4.1699250014), COEF_CONST(4.2479275134),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
272 COEF_CONST(4.3219280949), COEF_CONST(4.3923174228), COEF_CONST(4.4594316186), COEF_CONST(4.5235619561),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
273 COEF_CONST(4.5849625007), COEF_CONST(4.6438561898), COEF_CONST(4.7004397181), COEF_CONST(4.7548875022),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
274 COEF_CONST(4.8073549221), COEF_CONST(4.8579809951), COEF_CONST(4.9068905956), COEF_CONST(4.9541963104),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
275 COEF_CONST(5.0000000000), COEF_CONST(5.0443941194), COEF_CONST(5.0874628413), COEF_CONST(5.1292830169),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
276 COEF_CONST(5.1699250014), COEF_CONST(5.2094533656), COEF_CONST(5.2479275134), COEF_CONST(5.2854022189),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
277 COEF_CONST(5.3219280949), COEF_CONST(5.3575520046), COEF_CONST(5.3923174228), COEF_CONST(5.4262647547),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
278 COEF_CONST(5.4594316186), COEF_CONST(5.4918530963), COEF_CONST(5.5235619561), COEF_CONST(5.5545888517),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
279 COEF_CONST(5.5849625007), COEF_CONST(5.6147098441), COEF_CONST(5.6438561898), COEF_CONST(5.6724253420),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
280 COEF_CONST(5.7004397181), COEF_CONST(5.7279204546), COEF_CONST(5.7548875022), COEF_CONST(5.7813597135),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
281 COEF_CONST(5.8073549221), COEF_CONST(5.8328900142), COEF_CONST(5.8579809951), COEF_CONST(5.8826430494),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
282 COEF_CONST(5.9068905956), COEF_CONST(5.9307373376), COEF_CONST(5.9541963104), COEF_CONST(5.9772799235),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
283 COEF_CONST(6.0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
284 };
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
285 real_t r0 = log2Table[a0]; /* coef */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
286 real_t r1 = log2Table[a1]; /* coef */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
287 real_t r2 = (r1 - r0); /* coef */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
288
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
289 if (warp)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
290 r2 = MUL_C(r2, COEF_CONST(1.0/1.3));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
291
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
292 /* convert r2 to real and then multiply and round */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
293 r2 = (r2 >> (COEF_BITS-REAL_BITS)) * bands + (1<<(REAL_BITS-1));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
294
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
295 return (r2 >> REAL_BITS);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
296 #else
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
297 real_t div = (real_t)log(2.0);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
298 if (warp) div *= (real_t)1.3;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
299
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
300 return (int32_t)(bands * log((float)a1/(float)a0)/div + 0.5);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
301 #endif
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
302 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
303
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
304 static real_t find_initial_power(uint8_t bands, uint8_t a0, uint8_t a1)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
305 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
306 #ifdef FIXED_POINT
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
307 /* table with log() values */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
308 static const real_t logTable[65] = {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
309 COEF_CONST(0.0), COEF_CONST(0.0), COEF_CONST(0.6931471806), COEF_CONST(1.0986122887),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
310 COEF_CONST(1.3862943611), COEF_CONST(1.6094379124), COEF_CONST(1.7917594692), COEF_CONST(1.9459101491),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
311 COEF_CONST(2.0794415417), COEF_CONST(2.1972245773), COEF_CONST(2.3025850930), COEF_CONST(2.3978952728),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
312 COEF_CONST(2.4849066498), COEF_CONST(2.5649493575), COEF_CONST(2.6390573296), COEF_CONST(2.7080502011),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
313 COEF_CONST(2.7725887222), COEF_CONST(2.8332133441), COEF_CONST(2.8903717579), COEF_CONST(2.9444389792),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
314 COEF_CONST(2.9957322736), COEF_CONST(3.0445224377), COEF_CONST(3.0910424534), COEF_CONST(3.1354942159),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
315 COEF_CONST(3.1780538303), COEF_CONST(3.2188758249), COEF_CONST(3.2580965380), COEF_CONST(3.2958368660),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
316 COEF_CONST(3.3322045102), COEF_CONST(3.3672958300), COEF_CONST(3.4011973817), COEF_CONST(3.4339872045),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
317 COEF_CONST(3.4657359028), COEF_CONST(3.4965075615), COEF_CONST(3.5263605246), COEF_CONST(3.5553480615),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
318 COEF_CONST(3.5835189385), COEF_CONST(3.6109179126), COEF_CONST(3.6375861597), COEF_CONST(3.6635616461),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
319 COEF_CONST(3.6888794541), COEF_CONST(3.7135720667), COEF_CONST(3.7376696183), COEF_CONST(3.7612001157),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
320 COEF_CONST(3.7841896339), COEF_CONST(3.8066624898), COEF_CONST(3.8286413965), COEF_CONST(3.8501476017),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
321 COEF_CONST(3.8712010109), COEF_CONST(3.8918202981), COEF_CONST(3.9120230054), COEF_CONST(3.9318256327),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
322 COEF_CONST(3.9512437186), COEF_CONST(3.9702919136), COEF_CONST(3.9889840466), COEF_CONST(4.0073331852),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
323 COEF_CONST(4.0253516907), COEF_CONST(4.0430512678), COEF_CONST(4.0604430105), COEF_CONST(4.0775374439),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
324 COEF_CONST(4.0943445622), COEF_CONST(4.1108738642), COEF_CONST(4.1271343850), COEF_CONST(4.1431347264),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
325 COEF_CONST(4.158883083)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
326 };
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
327 /* standard Taylor polynomial coefficients for exp(x) around 0 */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
328 /* a polynomial around x=1 is more precise, as most values are around 1.07,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
329 but this is just fine already */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
330 static const real_t c1 = COEF_CONST(1.0);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
331 static const real_t c2 = COEF_CONST(1.0/2.0);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
332 static const real_t c3 = COEF_CONST(1.0/6.0);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
333 static const real_t c4 = COEF_CONST(1.0/24.0);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
334
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
335 real_t r0 = logTable[a0]; /* coef */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
336 real_t r1 = logTable[a1]; /* coef */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
337 real_t r2 = (r1 - r0) / bands; /* coef */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
338 real_t rexp = c1 + MUL_C((c1 + MUL_C((c2 + MUL_C((c3 + MUL_C(c4,r2)), r2)), r2)), r2);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
339
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
340 return (rexp >> (COEF_BITS-REAL_BITS)); /* real */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
341 #else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
342 return (real_t)pow((real_t)a1/(real_t)a0, 1.0/(real_t)bands);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
343 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
344 }
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
345
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347 version for bs_freq_scale > 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
349 uint8_t master_frequency_table(sbr_info *sbr, uint8_t k0, uint8_t k2,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
350 uint8_t bs_freq_scale, uint8_t bs_alter_scale)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 uint8_t k, bands, twoRegions;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
353 uint8_t k1;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
354 uint8_t nrBand0, nrBand1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
355 int32_t vDk0[64] = {0}, vDk1[64] = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
356 int32_t vk0[64] = {0}, vk1[64] = {0};
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
357 uint8_t temp1[] = { 6, 5, 4 };
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
358 real_t q, qk;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
359 int32_t A_1;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
360 #ifdef FIXED_POINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
361 real_t rk2, rk0;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
362 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 /* mft only defined for k2 > k0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 if (k2 <= k0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 sbr->N_master = 0;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
368 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 bands = temp1[bs_freq_scale-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
373 #ifdef FIXED_POINT
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
374 rk0 = (real_t)k0 << REAL_BITS;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
375 rk2 = (real_t)k2 << REAL_BITS;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
376 if (rk2 > MUL_C(rk0, COEF_CONST(2.2449)))
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
377 #else
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 if ((float)k2/(float)k0 > 2.2449)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
379 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 twoRegions = 1;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
382 k1 = k0 << 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384 twoRegions = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385 k1 = k2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
388 nrBand0 = (uint8_t)(2 * find_bands(0, bands, k0, k1));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
389 nrBand0 = min(nrBand0, 63);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
390 if (nrBand0 <= 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
391 return 1;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
392
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
393 q = find_initial_power(nrBand0, k0, k1);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
394 #ifdef FIXED_POINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
395 qk = (real_t)k0 << REAL_BITS;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
396 //A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
397 A_1 = k0;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
398 #else
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
399 qk = REAL_CONST(k0);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
400 A_1 = (int32_t)(qk + .5);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
401 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 for (k = 0; k <= nrBand0; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
404 int32_t A_0 = A_1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
405 #ifdef FIXED_POINT
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
406 qk = MUL_R(qk,q);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
407 A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
408 #else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
409 qk *= q;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
410 A_1 = (int32_t)(qk + 0.5);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
411 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
412 vDk0[k] = A_1 - A_0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
413 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
414
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415 /* needed? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418 vk0[0] = k0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 for (k = 1; k <= nrBand0; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 vk0[k] = vk0[k-1] + vDk0[k-1];
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
422 if (vDk0[k-1] == 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
423 return 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426 if (!twoRegions)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 for (k = 0; k <= nrBand0; k++)
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
429 sbr->f_master[k] = (uint8_t) vk0[k];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 sbr->N_master = nrBand0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 sbr->N_master = min(sbr->N_master, 64);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
433 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
436 nrBand1 = (uint8_t)(2 * find_bands(1 /* warped */, bands, k1, k2));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
437 nrBand1 = min(nrBand1, 63);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
439 q = find_initial_power(nrBand1, k1, k2);
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
440 #ifdef FIXED_POINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
441 qk = (real_t)k1 << REAL_BITS;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
442 //A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
443 A_1 = k1;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
444 #else
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
445 qk = REAL_CONST(k1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
446 A_1 = (int32_t)(qk + .5);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
447 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448 for (k = 0; k <= nrBand1 - 1; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
450 int32_t A_0 = A_1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
451 #ifdef FIXED_POINT
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
452 qk = MUL_R(qk,q);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
453 A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
454 #else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
455 qk *= q;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
456 A_1 = (int32_t)(qk + 0.5);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
457 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
458 vDk1[k] = A_1 - A_0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 if (vDk1[0] < vDk0[nrBand0 - 1])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463 int32_t change;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465 /* needed? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 qsort(vDk1, nrBand1 + 1, sizeof(vDk1[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467 change = vDk0[nrBand0 - 1] - vDk1[0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468 vDk1[0] = vDk0[nrBand0 - 1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 vDk1[nrBand1 - 1] = vDk1[nrBand1 - 1] - change;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472 /* needed? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473 qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 vk1[0] = k1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475 for (k = 1; k <= nrBand1; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477 vk1[k] = vk1[k-1] + vDk1[k-1];
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
478 if (vDk1[k-1] == 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
479 return 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482 sbr->N_master = nrBand0 + nrBand1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483 sbr->N_master = min(sbr->N_master, 64);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484 for (k = 0; k <= nrBand0; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
486 sbr->f_master[k] = (uint8_t) vk0[k];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488 for (k = nrBand0 + 1; k <= sbr->N_master; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
489 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
490 sbr->f_master[k] = (uint8_t) vk1[k - nrBand0];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
491 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
494 printf("f_master[%d]: ", sbr->N_master);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 for (k = 0; k <= sbr->N_master; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 printf("%d ", sbr->f_master[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
498 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
501
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
502 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505 /* calculate the derived frequency border tables from f_master */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
506 uint8_t derived_frequency_table(sbr_info *sbr, uint8_t bs_xover_band,
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
507 uint8_t k2)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
509 uint8_t k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 uint32_t minus;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
512 /* The following relation shall be satisfied: bs_xover_band < N_Master */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
513 if (sbr->N_master <= bs_xover_band)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
514 return 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
516 sbr->N_high = sbr->N_master - bs_xover_band;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
517 sbr->N_low = (sbr->N_high>>1) + (sbr->N_high - ((sbr->N_high>>1)<<1));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
518
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
519 sbr->n[0] = sbr->N_low;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
520 sbr->n[1] = sbr->N_high;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
521
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
522 for (k = 0; k <= sbr->N_high; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
524 sbr->f_table_res[HI_RES][k] = sbr->f_master[k + bs_xover_band];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
526
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
527 sbr->M = sbr->f_table_res[HI_RES][sbr->N_high] - sbr->f_table_res[HI_RES][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
528 sbr->kx = sbr->f_table_res[HI_RES][0];
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
529 if (sbr->kx > 32)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
530 return 1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
531 if (sbr->kx + sbr->M > 64)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
532 return 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
533
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
534 minus = (sbr->N_high & 1) ? 1 : 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
535
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
536 for (k = 0; k <= sbr->N_low; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
537 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
538 if (k == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
539 i = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
540 else
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
541 i = (uint8_t)(2*k - minus);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
542 sbr->f_table_res[LO_RES][k] = sbr->f_table_res[HI_RES][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
543 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
544
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
545 #if 0
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
546 printf("bs_freq_scale: %d\n", sbr->bs_freq_scale);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
547 printf("bs_limiter_bands: %d\n", sbr->bs_limiter_bands);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
548 printf("f_table_res[HI_RES][%d]: ", sbr->N_high);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
549 for (k = 0; k <= sbr->N_high; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
550 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
551 printf("%d ", sbr->f_table_res[HI_RES][k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
552 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
553 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
554 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
555 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
556 printf("f_table_res[LO_RES][%d]: ", sbr->N_low);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
557 for (k = 0; k <= sbr->N_low; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
558 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
559 printf("%d ", sbr->f_table_res[LO_RES][k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
560 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
561 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
562 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
563
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
564 sbr->N_Q = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
565 if (sbr->bs_noise_bands == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
566 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
567 sbr->N_Q = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
568 } else {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
569 #if 0
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
570 sbr->N_Q = max(1, (int32_t)(sbr->bs_noise_bands*(log(k2/(float)sbr->kx)/log(2.0)) + 0.5));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
571 #else
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
572 sbr->N_Q = (uint8_t)(max(1, find_bands(0, sbr->bs_noise_bands, sbr->kx, k2)));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
573 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
574 sbr->N_Q = min(5, sbr->N_Q);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
575 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
576
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
577 for (k = 0; k <= sbr->N_Q; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
578 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
579 if (k == 0)
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
580 {
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
581 i = 0;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
582 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
583 /* i = i + (int32_t)((sbr->N_low - i)/(sbr->N_Q + 1 - k)); */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
584 i = i + (sbr->N_low - i)/(sbr->N_Q + 1 - k);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
585 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
586 sbr->f_table_noise[k] = sbr->f_table_res[LO_RES][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
587 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
588
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
589 /* build table for mapping k to g in hf patching */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
590 for (k = 0; k < 64; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
591 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
592 uint8_t g;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
593 for (g = 0; g < sbr->N_Q; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
594 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
595 if ((sbr->f_table_noise[g] <= k) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
596 (k < sbr->f_table_noise[g+1]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
597 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
598 sbr->table_map_k_to_g[k] = g;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
599 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
600 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
601 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
602 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
603
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
604 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
605 printf("f_table_noise[%d]: ", sbr->N_Q);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
606 for (k = 0; k <= sbr->N_Q; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
607 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
608 printf("%d ", sbr->f_table_noise[k] - sbr->kx);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
609 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
610 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
611 #endif
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
612
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
613 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
614 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
615
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
616 /* TODO: blegh, ugly */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
617 /* Modified to calculate for all possible bs_limiter_bands always
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
618 * This reduces the number calls to this functions needed (now only on
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
619 * header reset)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
620 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
621 void limiter_frequency_table(sbr_info *sbr)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
622 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
623 #if 0
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
624 static const real_t limiterBandsPerOctave[] = { REAL_CONST(1.2),
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
625 REAL_CONST(2), REAL_CONST(3) };
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
626 #else
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
627 static const real_t limiterBandsCompare[] = { REAL_CONST(1.327152),
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
628 REAL_CONST(1.185093), REAL_CONST(1.119872) };
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
629 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
630 uint8_t k, s;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
631 int8_t nrLim;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
632 #if 0
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
633 real_t limBands;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
634 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
635
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
636 sbr->f_table_lim[0][0] = sbr->f_table_res[LO_RES][0] - sbr->kx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
637 sbr->f_table_lim[0][1] = sbr->f_table_res[LO_RES][sbr->N_low] - sbr->kx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
638 sbr->N_L[0] = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
639
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
640 #if 0
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
641 printf("f_table_lim[%d][%d]: ", 0, sbr->N_L[0]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
642 for (k = 0; k <= sbr->N_L[0]; k++)
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
643 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
644 printf("%d ", sbr->f_table_lim[0][k]);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
645 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
646 printf("\n");
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
647 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
648
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
649 for (s = 1; s < 4; s++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
650 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
651 int32_t limTable[100 /*TODO*/] = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
652 uint8_t patchBorders[64/*??*/] = {0};
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
653
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
654 #if 0
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
655 limBands = limiterBandsPerOctave[s - 1];
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
656 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
657
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
658 patchBorders[0] = sbr->kx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
659 for (k = 1; k <= sbr->noPatches; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
660 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
661 patchBorders[k] = patchBorders[k-1] + sbr->patchNoSubbands[k-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
662 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
663
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
664 for (k = 0; k <= sbr->N_low; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
665 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
666 limTable[k] = sbr->f_table_res[LO_RES][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
667 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
668 for (k = 1; k < sbr->noPatches; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
669 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
670 limTable[k+sbr->N_low] = patchBorders[k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
671 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
672
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
673 /* needed */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
674 qsort(limTable, sbr->noPatches + sbr->N_low, sizeof(limTable[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
675 k = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
676 nrLim = sbr->noPatches + sbr->N_low - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
677
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
678 if (nrLim < 0) // TODO: BIG FAT PROBLEM
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
679 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
680
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
681 restart:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
682 if (k <= nrLim)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
683 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
684 real_t nOctaves;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
685
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
686 if (limTable[k-1] != 0)
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
687 #if 0
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
688 nOctaves = REAL_CONST(log((float)limTable[k]/(float)limTable[k-1])/log(2.0));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
689 #else
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
690 #ifdef FIXED_POINT
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
691 nOctaves = DIV_R((limTable[k]<<REAL_BITS),REAL_CONST(limTable[k-1]));
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
692 #else
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
693 nOctaves = (real_t)limTable[k]/(real_t)limTable[k-1];
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
694 #endif
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
695 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
696 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
697 nOctaves = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
698
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
699 #if 0
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
700 if ((MUL_R(nOctaves,limBands)) < REAL_CONST(0.49))
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
701 #else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
702 if (nOctaves < limiterBandsCompare[s - 1])
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
703 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
704 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
705 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
706 if (limTable[k] != limTable[k-1])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
707 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
708 uint8_t found = 0, found2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
709 for (i = 0; i <= sbr->noPatches; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
710 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
711 if (limTable[k] == patchBorders[i])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
712 found = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
713 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
714 if (found)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
715 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
716 found2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
717 for (i = 0; i <= sbr->noPatches; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
718 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
719 if (limTable[k-1] == patchBorders[i])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
720 found2 = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
721 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
722 if (found2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
723 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
724 k++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
725 goto restart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
726 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
727 /* remove (k-1)th element */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
728 limTable[k-1] = sbr->f_table_res[LO_RES][sbr->N_low];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
729 qsort(limTable, sbr->noPatches + sbr->N_low, sizeof(limTable[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
730 nrLim--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
731 goto restart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
732 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
733 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
734 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
735 /* remove kth element */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
736 limTable[k] = sbr->f_table_res[LO_RES][sbr->N_low];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
737 qsort(limTable, nrLim, sizeof(limTable[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
738 nrLim--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
739 goto restart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
740 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
741 k++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
742 goto restart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
743 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
744 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
745
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
746 sbr->N_L[s] = nrLim;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
747 for (k = 0; k <= nrLim; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
748 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
749 sbr->f_table_lim[s][k] = limTable[k] - sbr->kx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
750 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
751
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
752 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
753 printf("f_table_lim[%d][%d]: ", s, sbr->N_L[s]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
754 for (k = 0; k <= sbr->N_L[s]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
755 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
756 printf("%d ", sbr->f_table_lim[s][k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
757 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
758 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
759 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
760 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
761 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
762
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
763 #endif