annotate libfaad2/ssr.c @ 14585:81059277538c

Be less verbose with -v (do not print a line for each demuxed packet)
author rtognimp
date Mon, 24 Jan 2005 21:52:24 +0000
parents d81145997036
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
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
26 ** $Id: ssr.c,v 1.3 2004/06/02 22:59:03 diego Exp $
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 #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 SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "filtbank.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "ssr.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "ssr_fb.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 void ssr_decode(ssr_info *ssr, fb_info *fb, uint8_t window_sequence,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 uint8_t window_shape, uint8_t window_shape_prev,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 real_t *freq_in, real_t *time_out, real_t *overlap,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 real_t ipqf_buffer[SSR_BANDS][96/4],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 real_t *prev_fmd, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 uint8_t band;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 uint16_t ssr_frame_len = frame_len/SSR_BANDS;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
48 real_t time_tmp[2048] = {0};
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
49 real_t output[1024] = {0};
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 for (band = 0; band < SSR_BANDS; band++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 int16_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 /* uneven bands have inverted frequency scale */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 if (band == 1 || band == 3)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 for (j = 0; j < ssr_frame_len/2; j++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 real_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 tmp = freq_in[j + ssr_frame_len*band];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 freq_in[j + ssr_frame_len*band] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band] = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 /* non-overlapping inverse filterbank for SSR */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 ssr_ifilter_bank(fb, window_sequence, window_shape, window_shape_prev,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 freq_in + band*ssr_frame_len, time_tmp + band*ssr_frame_len,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 ssr_frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 /* gain control */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 ssr_gain_control(ssr, time_tmp, output, overlap, prev_fmd,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 band, window_sequence, ssr_frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 /* inverse pqf to bring subbands together again */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 ssr_ipqf(ssr, output, time_out, ipqf_buffer, frame_len, SSR_BANDS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 static void ssr_gain_control(ssr_info *ssr, real_t *data, real_t *output,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 real_t *overlap, real_t *prev_fmd, uint8_t band,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 uint8_t window_sequence, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 real_t gc_function[2*1024/SSR_BANDS];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 if (window_sequence != EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 ssr_gc_function(ssr, &prev_fmd[band * frame_len*2],
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
92 gc_function, window_sequence, band, frame_len);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 for (i = 0; i < frame_len*2; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 data[band * frame_len*2 + i] *= gc_function[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 output[band*frame_len + i] = overlap[band*frame_len + i] +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 data[band*frame_len*2 + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 overlap[band*frame_len + i] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 data[band*frame_len*2 + frame_len + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 uint8_t w;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 for (w = 0; w < 8; w++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 uint16_t frame_len8 = frame_len/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 uint16_t frame_len16 = frame_len/16;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 ssr_gc_function(ssr, &prev_fmd[band*frame_len*2 + w*frame_len*2/8],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 gc_function, window_sequence, frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 for (i = 0; i < frame_len8*2; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 data[band*frame_len*2 + w*frame_len8*2+i] *= gc_function[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 for (i = 0; i < frame_len8; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 overlap[band*frame_len + i + 7*frame_len16 + w*frame_len8] +=
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 data[band*frame_len*2 + 2*w*frame_len8 + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 for (i = 0; i < frame_len8; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 overlap[band*frame_len + i + 7*frame_len16 + (w+1)*frame_len8] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 data[band*frame_len*2 + 2*w*frame_len8 + frame_len8 + 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 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 output[band*frame_len + i] = overlap[band*frame_len + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 overlap[band*frame_len + i] = overlap[band*frame_len + i + frame_len];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 static void ssr_gc_function(ssr_info *ssr, real_t *prev_fmd,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 real_t *gc_function, uint8_t window_sequence,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
138 uint8_t band, uint16_t frame_len)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 uint16_t len_area1, len_area2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 int32_t aloc[10];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 real_t alev[10];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 switch (window_sequence)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 case ONLY_LONG_SEQUENCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 len_area1 = frame_len/SSR_BANDS;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 len_area2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 case LONG_START_SEQUENCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 len_area1 = (frame_len/SSR_BANDS)*7/32;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 len_area2 = (frame_len/SSR_BANDS)/16;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 case EIGHT_SHORT_SEQUENCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 len_area1 = (frame_len/8)/SSR_BANDS;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 len_area2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 case LONG_STOP_SEQUENCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 len_area1 = (frame_len/SSR_BANDS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 len_area2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 /* decode bitstream information */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 /* build array M */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 for (i = 0; i < frame_len*2; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 gc_function[i] = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 #endif