annotate libfaad2/ssr.c @ 11379:7f02819e58e0

-sws 0 && -ssf chs fixed
author michael
date Tue, 04 Nov 2003 13:52:12 +0000
parents 3185f64f6350
children 4a370c80fe5c
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 **
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
25 ** $Id: ssr.c,v 1.5 2003/09/09 18:09:52 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;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 real_t time_tmp[2048];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 real_t output[1024];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 memset(output, 0, 1024*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 memset(time_tmp, 0, 2048*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 for (band = 0; band < SSR_BANDS; band++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 int16_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 /* uneven bands have inverted frequency scale */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 if (band == 1 || band == 3)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 for (j = 0; j < ssr_frame_len/2; j++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 real_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 tmp = freq_in[j + ssr_frame_len*band];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 freq_in[j + 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];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band] = tmp;
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
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 /* non-overlapping inverse filterbank for SSR */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 ssr_ifilter_bank(fb, window_sequence, window_shape, window_shape_prev,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 freq_in + band*ssr_frame_len, time_tmp + band*ssr_frame_len,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 ssr_frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 /* gain control */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 ssr_gain_control(ssr, time_tmp, output, overlap, prev_fmd,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 band, window_sequence, ssr_frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 /* inverse pqf to bring subbands together again */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 ssr_ipqf(ssr, output, time_out, ipqf_buffer, frame_len, SSR_BANDS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 static void ssr_gain_control(ssr_info *ssr, real_t *data, real_t *output,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 real_t *overlap, real_t *prev_fmd, uint8_t band,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 uint8_t window_sequence, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 real_t gc_function[2*1024/SSR_BANDS];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 if (window_sequence != EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 ssr_gc_function(ssr, &prev_fmd[band * frame_len*2],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 gc_function, window_sequence, frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 for (i = 0; i < frame_len*2; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 data[band * frame_len*2 + i] *= gc_function[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 output[band*frame_len + i] = overlap[band*frame_len + i] +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 data[band*frame_len*2 + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 overlap[band*frame_len + i] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 data[band*frame_len*2 + frame_len + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 uint8_t w;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 for (w = 0; w < 8; w++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 uint16_t frame_len8 = frame_len/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 uint16_t frame_len16 = frame_len/16;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 ssr_gc_function(ssr, &prev_fmd[band*frame_len*2 + w*frame_len*2/8],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 gc_function, window_sequence, frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 for (i = 0; i < frame_len8*2; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 data[band*frame_len*2 + w*frame_len8*2+i] *= gc_function[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 for (i = 0; i < frame_len8; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 overlap[band*frame_len + i + 7*frame_len16 + w*frame_len8] +=
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 data[band*frame_len*2 + 2*w*frame_len8 + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 for (i = 0; i < frame_len8; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 overlap[band*frame_len + i + 7*frame_len16 + (w+1)*frame_len8] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 data[band*frame_len*2 + 2*w*frame_len8 + frame_len8 + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 output[band*frame_len + i] = overlap[band*frame_len + i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 overlap[band*frame_len + i] = overlap[band*frame_len + i + frame_len];
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
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 static void ssr_gc_function(ssr_info *ssr, real_t *prev_fmd,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 real_t *gc_function, uint8_t window_sequence,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 uint16_t len_area1, len_area2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 int32_t aloc[10];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 real_t alev[10];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 switch (window_sequence)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 case ONLY_LONG_SEQUENCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 len_area1 = frame_len/SSR_BANDS;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 len_area2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 case LONG_START_SEQUENCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 len_area1 = (frame_len/SSR_BANDS)*7/32;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 len_area2 = (frame_len/SSR_BANDS)/16;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 case EIGHT_SHORT_SEQUENCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 len_area1 = (frame_len/8)/SSR_BANDS;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 len_area2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 case LONG_STOP_SEQUENCE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 len_area1 = (frame_len/SSR_BANDS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 len_area2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 break;
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 /* decode bitstream information */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 /* build array M */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 for (i = 0; i < frame_len*2; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 gc_function[i] = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 #endif