annotate libfaad2/ssr.c @ 17115:dbe315450a32

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