annotate libfaad2/sbr_fbt.c @ 10846:579c83157193

Fixed PAUSED message (it was too long :)
author lumag
date Wed, 10 Sep 2003 14:56:56 +0000
parents e989150f8216
children 3185f64f6350
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
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
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 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
25 ** $Id: sbr_fbt.c,v 1.1 2003/07/29 08:20:13 menno Exp $
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 /* Calculate frequency band tables */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "sbr_syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "sbr_fbt.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 /* calculate the start QMF channel for the master frequency band table */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 /* parameter is also called k0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 uint16_t qmf_start_channel(uint8_t bs_start_freq, uint8_t bs_samplerate_mode,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 uint32_t sample_rate)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 static int8_t offset[7][16] = {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 { -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
48 { -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
49 { -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
50 { -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
51 { -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
52 { -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
53 { 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
54 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 uint8_t startMin;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 if (sample_rate >= 64000)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 startMin = (uint8_t)((5000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 } else if (sample_rate < 32000) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 startMin = (uint8_t)((3000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 startMin = (uint8_t)((4000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 if (bs_samplerate_mode)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 switch (sample_rate)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 case 16000:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 return startMin + offset[0][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 case 22050:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 return startMin + offset[1][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 case 24000:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 return startMin + offset[2][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 case 32000:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 return startMin + offset[3][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 default:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 if (sample_rate > 64000)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 return startMin + offset[5][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 } else { /* 44100 <= sample_rate <= 64000 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 return startMin + offset[4][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 return startMin + offset[6][bs_start_freq];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 static int32_t longcmp(const void *a, const void *b)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 return ((int32_t)(*(int32_t*)a - *(int32_t*)b));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 /* calculate the stop QMF channel for the master frequency band table */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 /* parameter is also called k2 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 uint16_t qmf_stop_channel(uint8_t bs_stop_freq, uint32_t sample_rate,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 uint16_t k0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 if (bs_stop_freq == 15)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 return min(64, k0 * 3);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 } else if (bs_stop_freq == 14) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 return min(64, k0 * 2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 uint8_t stopMin;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 int32_t stopDk[13], stopDk_t[14], k2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 if (sample_rate >= 64000)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 stopMin = (uint8_t)((10000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 } else if (sample_rate < 32000) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 stopMin = (uint8_t)((6000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 stopMin = (uint8_t)((8000.*128.)/(float)sample_rate + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 for (i = 0; i <= 13; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 stopDk_t[i] = (int32_t)(stopMin*pow(64.0/stopMin, i/13.0) + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 for (i = 0; i < 13; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 stopDk[i] = stopDk_t[i+1] - stopDk_t[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 /* needed? or does this always reverse the array? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 qsort(stopDk, 13, sizeof(stopDk[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 k2 = stopMin;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 for (i = 0; i < bs_stop_freq; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 k2 += stopDk[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 return min(64, k2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 /* calculate the master frequency table from k0, k2, bs_freq_scale
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 and bs_alter_scale
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 version for bs_freq_scale = 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 void master_frequency_table_fs0(sbr_info *sbr, uint16_t k0, uint16_t k2,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 uint8_t bs_alter_scale)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 int8_t incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 uint8_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 uint8_t dk;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 uint32_t nrBands, k2Achieved;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 int32_t k2Diff, vDk[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 memset(vDk, 0, 64*sizeof(int32_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 /* mft only defined for k2 > k0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 if (k2 <= k0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 sbr->N_master = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 dk = bs_alter_scale ? 2 : 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 nrBands = 2 * (int32_t)((float)(k2-k0)/(dk*2) + (-1+dk)/2.0f);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 nrBands = min(nrBands, 64);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 k2Achieved = k0 + nrBands * dk;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 k2Diff = k2 - k2Achieved;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 /* for (k = 0; k <= nrBands; k++) Typo fix */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 for (k = 0; k < nrBands; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 vDk[k] = dk;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 if (k2Diff)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 incr = (k2Diff > 0) ? -1 : 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 k = (k2Diff > 0) ? (nrBands-1) : 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 while (k2Diff != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 vDk[k] -= incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 k += incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 k2Diff += incr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 sbr->f_master[0] = k0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 for (k = 1; k <= nrBands; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 sbr->f_master[k] = sbr->f_master[k-1] + vDk[k-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 sbr->N_master = nrBands;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 sbr->N_master = min(sbr->N_master, 64);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 printf("f_master[%d]: ", nrBands);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 for (k = 0; k <= nrBands; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 printf("%d ", sbr->f_master[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 version for bs_freq_scale > 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 void master_frequency_table(sbr_info *sbr, uint16_t k0, uint16_t k2,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 uint8_t bs_freq_scale, uint8_t bs_alter_scale)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 uint8_t k, bands, twoRegions;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 uint16_t k1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 uint32_t nrBand0, nrBand1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 int32_t vDk0[64], vDk1[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 int32_t vk0[64], vk1[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 float warp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 uint8_t temp1[] = { 12, 10, 8 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 float temp2[] = { 1.0, 1.3 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 /* without memset code enters infinte loop,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 so there must be some wrong table access */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 memset(vDk0, 0, 64*sizeof(int32_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 memset(vDk1, 0, 64*sizeof(int32_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 memset(vk0, 0, 64*sizeof(int32_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 memset(vk1, 0, 64*sizeof(int32_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 /* mft only defined for k2 > k0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 if (k2 <= k0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 sbr->N_master = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 bands = temp1[bs_freq_scale-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 warp = temp2[bs_alter_scale];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 if ((float)k2/(float)k0 > 2.2449)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 twoRegions = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 k1 = 2 * k0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 twoRegions = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 k1 = k2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 nrBand0 = 2 * (int32_t)(bands * log((float)k1/(float)k0)/(2.0*log(2.0)) + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 nrBand0 = min(nrBand0, 64);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 for (k = 0; k <= nrBand0; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 /* MAPLE */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 vDk0[k] = (int32_t)(k0 * pow((float)k1/(float)k0, (k+1)/(float)nrBand0)+0.5) -
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 (int32_t)(k0 * pow((float)k1/(float)k0, k/(float)nrBand0)+0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 /* needed? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 vk0[0] = k0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 for (k = 1; k <= nrBand0; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 vk0[k] = vk0[k-1] + vDk0[k-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 if (!twoRegions)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 for (k = 0; k <= nrBand0; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 sbr->f_master[k] = vk0[k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270 sbr->N_master = nrBand0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 sbr->N_master = min(sbr->N_master, 64);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 nrBand1 = 2 * (int32_t)(bands * log((float)k2/(float)k1)/(2.0 * log(2.0) * warp) + 0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 nrBand1 = min(nrBand1, 64);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 for (k = 0; k <= nrBand1 - 1; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 vDk1[k] = (int32_t)(k1 * pow((float)k2/(float)k1, (k+1)/(float)nrBand1)+0.5) -
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 (int32_t)(k1 * pow((float)k2/(float)k1, k/(float)nrBand1)+0.5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 if (vDk1[0] < vDk0[nrBand0 - 1])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 int32_t change;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 /* needed? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 qsort(vDk1, nrBand1 + 1, sizeof(vDk1[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 change = vDk0[nrBand0 - 1] - vDk1[0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 vDk1[0] = vDk0[nrBand0 - 1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 vDk1[nrBand1 - 1] = vDk1[nrBand1 - 1] - change;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295 /* needed? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 vk1[0] = k1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 for (k = 1; k <= nrBand1; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 vk1[k] = vk1[k-1] + vDk1[k-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 sbr->N_master = nrBand0 + nrBand1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 sbr->N_master = min(sbr->N_master, 64);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 for (k = 0; k <= nrBand0; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 sbr->f_master[k] = vk0[k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309 for (k = nrBand0 + 1; k <= sbr->N_master; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 sbr->f_master[k] = vk1[k - nrBand0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 printf("f_master[%d]: ", sbr->N_master);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 for (k = 0; k <= sbr->N_master; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318 printf("%d ", sbr->f_master[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 /* calculate the derived frequency border tables from f_master */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 void derived_frequency_table(sbr_info *sbr, uint8_t bs_xover_band,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326 uint16_t k2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 uint8_t k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 uint32_t minus;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331 sbr->N_high = sbr->N_master - bs_xover_band;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 /* is this accurate? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334 sbr->N_low = sbr->N_high/2 + (sbr->N_high - 2 * (sbr->N_high/2));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
335
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336 sbr->n[0] = sbr->N_low;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337 sbr->n[1] = sbr->N_high;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
338
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339 for (k = 0; k <= sbr->N_high; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 sbr->f_table_res[HI_RES][k] = sbr->f_master[k + bs_xover_band];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
342 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 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
345 sbr->kx = sbr->f_table_res[HI_RES][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347 /* correct? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 minus = (sbr->N_high & 1) ? 1 : 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 for (k = 0; k <= sbr->N_low; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 if (k == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353 i = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 i = 2*k - minus;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356 sbr->f_table_res[LO_RES][k] = sbr->f_table_res[HI_RES][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358 /* end correct? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 printf("f_table_res[HI_RES][%d]: ", sbr->N_high);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362 for (k = 0; k <= sbr->N_high; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 printf("%d ", sbr->f_table_res[HI_RES][k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369 printf("f_table_res[LO_RES][%d]: ", sbr->N_low);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 for (k = 0; k <= sbr->N_low; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 printf("%d ", sbr->f_table_res[LO_RES][k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
374 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377 sbr->N_Q = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 if (sbr->bs_noise_bands == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 sbr->N_Q = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 /* MAPLE */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 sbr->N_Q = max(1, (int32_t)(sbr->bs_noise_bands*(log(k2/(float)sbr->kx)/log(2.0)) + 0.5));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384 if (sbr->N_Q == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385 sbr->N_Q = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387 sbr->N_Q = min(5, sbr->N_Q);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389 for (k = 0; k <= sbr->N_Q; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
391 if (k == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 i = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393 else /* is this accurate? */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 i = i + (int32_t)((sbr->N_low - i)/(sbr->N_Q + 1 - k));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395 sbr->f_table_noise[k] = sbr->f_table_res[LO_RES][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
396 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
397
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398 /* build table for mapping k to g in hf patching */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
399 for (k = 0; k < 64; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 uint8_t g;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 for (g = 0; g < sbr->N_Q; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404 if ((sbr->f_table_noise[g] <= k) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 (k < sbr->f_table_noise[g+1]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 sbr->table_map_k_to_g[k] = g;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
413 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
414 printf("f_table_noise[%d]: ", sbr->N_Q);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415 for (k = 0; k <= sbr->N_Q; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417 printf("%d ", sbr->f_table_noise[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 /* TODO: blegh, ugly */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424 /* Modified to calculate for all possible bs_limiter_bands always
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 * This reduces the number calls to this functions needed (now only on
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426 * header reset)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 void limiter_frequency_table(sbr_info *sbr)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
429 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430 static real_t limiterBandsPerOctave[] = { REAL_CONST(1.2),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 REAL_CONST(2), REAL_CONST(3) };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 uint8_t k, s;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433 int8_t nrLim;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434 int32_t limTable[100 /*TODO*/];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435 uint8_t patchBorders[64/*??*/];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
436 real_t limBands;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
437
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438 sbr->f_table_lim[0][0] = sbr->f_table_res[LO_RES][0] - sbr->kx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439 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
440 sbr->N_L[0] = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
442 for (s = 1; s < 4; s++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
444 memset(limTable, 0, 100*sizeof(int32_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
446 limBands = limiterBandsPerOctave[s - 1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448 patchBorders[0] = sbr->kx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 for (k = 1; k <= sbr->noPatches; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
451 patchBorders[k] = patchBorders[k-1] + sbr->patchNoSubbands[k-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
453
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
454 for (k = 0; k <= sbr->N_low; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
455 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456 limTable[k] = sbr->f_table_res[LO_RES][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
457 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458 for (k = 1; k < sbr->noPatches; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460 limTable[k+sbr->N_low] = patchBorders[k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463 /* needed */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464 qsort(limTable, sbr->noPatches + sbr->N_low, sizeof(limTable[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465 k = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 nrLim = sbr->noPatches + sbr->N_low - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468 if (nrLim < 0) // TODO: BIG FAT PROBLEM
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471 restart:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472 if (k <= nrLim)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 real_t nOctaves;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476 if (limTable[k-1] != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477 nOctaves = REAL_CONST(log((float)limTable[k]/(float)limTable[k-1])/log(2.0));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
479 nOctaves = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481 if ((MUL(nOctaves,limBands)) < REAL_CONST(0.49))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484 if (limTable[k] != limTable[k-1])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486 uint8_t found = 0, found2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 for (i = 0; i <= sbr->noPatches; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
489 if (limTable[k] == patchBorders[i])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
490 found = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
491 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 if (found)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
494 found2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 for (i = 0; i <= sbr->noPatches; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 if (limTable[k-1] == patchBorders[i])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
498 found2 = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 if (found2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
502 k++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 goto restart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505 /* remove (k-1)th element */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
506 limTable[k-1] = sbr->f_table_res[LO_RES][sbr->N_low];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
507 qsort(limTable, sbr->noPatches + sbr->N_low, sizeof(limTable[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508 nrLim--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
509 goto restart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
512 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
513 /* remove kth element */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
514 limTable[k] = sbr->f_table_res[LO_RES][sbr->N_low];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515 qsort(limTable, nrLim, sizeof(limTable[0]), longcmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
516 nrLim--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
517 goto restart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
518 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
519 k++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
520 goto restart;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
521 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
522 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
524 sbr->N_L[s] = nrLim;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 for (k = 0; k <= nrLim; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
526 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
527 sbr->f_table_lim[s][k] = limTable[k] - sbr->kx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
528 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
529
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
530 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
531 printf("f_table_lim[%d][%d]: ", s, sbr->N_L[s]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
532 for (k = 0; k <= sbr->N_L[s]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
533 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
534 printf("%d ", sbr->f_table_lim[s][k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
535 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
536 printf("\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
537 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
538 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
539 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
540
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
541 #endif