10725
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
|
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
|
|
4 **
|
|
5 ** This program is free software; you can redistribute it and/or modify
|
|
6 ** it under the terms of the GNU General Public License as published by
|
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
|
8 ** (at your option) any later version.
|
|
9 **
|
|
10 ** This program is distributed in the hope that it will be useful,
|
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ** GNU General Public License for more details.
|
|
14 **
|
|
15 ** You should have received a copy of the GNU General Public License
|
|
16 ** along with this program; if not, write to the Free Software
|
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 **
|
|
19 ** Any non-GPL usage of this software or parts of this software is strictly
|
|
20 ** forbidden.
|
|
21 **
|
|
22 ** Commercial non-GPL licensing of this software is possible.
|
|
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
|
|
24 **
|
|
25 ** $Id: ssr.c,v 1.4 2003/07/29 08:20:14 menno Exp $
|
|
26 **/
|
|
27
|
|
28 #include "common.h"
|
|
29 #include "structs.h"
|
|
30
|
|
31 #ifdef SSR_DEC
|
|
32
|
|
33 #include "syntax.h"
|
|
34 #include "filtbank.h"
|
|
35 #include "ssr.h"
|
|
36 #include "ssr_fb.h"
|
|
37
|
|
38 void ssr_decode(ssr_info *ssr, fb_info *fb, uint8_t window_sequence,
|
|
39 uint8_t window_shape, uint8_t window_shape_prev,
|
|
40 real_t *freq_in, real_t *time_out, real_t *overlap,
|
|
41 real_t ipqf_buffer[SSR_BANDS][96/4],
|
|
42 real_t *prev_fmd, uint16_t frame_len)
|
|
43 {
|
|
44 uint8_t band;
|
|
45 uint16_t ssr_frame_len = frame_len/SSR_BANDS;
|
|
46 real_t time_tmp[2048];
|
|
47 real_t output[1024];
|
|
48
|
|
49 memset(output, 0, 1024*sizeof(real_t));
|
|
50 memset(time_tmp, 0, 2048*sizeof(real_t));
|
|
51
|
|
52 for (band = 0; band < SSR_BANDS; band++)
|
|
53 {
|
|
54 int16_t j;
|
|
55
|
|
56 /* uneven bands have inverted frequency scale */
|
|
57 if (band == 1 || band == 3)
|
|
58 {
|
|
59 for (j = 0; j < ssr_frame_len/2; j++)
|
|
60 {
|
|
61 real_t tmp;
|
|
62 tmp = freq_in[j + ssr_frame_len*band];
|
|
63 freq_in[j + ssr_frame_len*band] =
|
|
64 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band];
|
|
65 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band] = tmp;
|
|
66 }
|
|
67 }
|
|
68
|
|
69 /* non-overlapping inverse filterbank for SSR */
|
|
70 ssr_ifilter_bank(fb, window_sequence, window_shape, window_shape_prev,
|
|
71 freq_in + band*ssr_frame_len, time_tmp + band*ssr_frame_len,
|
|
72 ssr_frame_len);
|
|
73
|
|
74 /* gain control */
|
|
75 ssr_gain_control(ssr, time_tmp, output, overlap, prev_fmd,
|
|
76 band, window_sequence, ssr_frame_len);
|
|
77 }
|
|
78
|
|
79 /* inverse pqf to bring subbands together again */
|
|
80 ssr_ipqf(ssr, output, time_out, ipqf_buffer, frame_len, SSR_BANDS);
|
|
81 }
|
|
82
|
|
83 static void ssr_gain_control(ssr_info *ssr, real_t *data, real_t *output,
|
|
84 real_t *overlap, real_t *prev_fmd, uint8_t band,
|
|
85 uint8_t window_sequence, uint16_t frame_len)
|
|
86 {
|
|
87 uint16_t i;
|
|
88 real_t gc_function[2*1024/SSR_BANDS];
|
|
89
|
|
90 if (window_sequence != EIGHT_SHORT_SEQUENCE)
|
|
91 {
|
|
92 ssr_gc_function(ssr, &prev_fmd[band * frame_len*2],
|
|
93 gc_function, window_sequence, frame_len);
|
|
94
|
|
95 for (i = 0; i < frame_len*2; i++)
|
|
96 data[band * frame_len*2 + i] *= gc_function[i];
|
|
97 for (i = 0; i < frame_len; i++)
|
|
98 {
|
|
99 output[band*frame_len + i] = overlap[band*frame_len + i] +
|
|
100 data[band*frame_len*2 + i];
|
|
101 }
|
|
102 for (i = 0; i < frame_len; i++)
|
|
103 {
|
|
104 overlap[band*frame_len + i] =
|
|
105 data[band*frame_len*2 + frame_len + i];
|
|
106 }
|
|
107 } else {
|
|
108 uint8_t w;
|
|
109 for (w = 0; w < 8; w++)
|
|
110 {
|
|
111 uint16_t frame_len8 = frame_len/8;
|
|
112 uint16_t frame_len16 = frame_len/16;
|
|
113
|
|
114 ssr_gc_function(ssr, &prev_fmd[band*frame_len*2 + w*frame_len*2/8],
|
|
115 gc_function, window_sequence, frame_len);
|
|
116
|
|
117 for (i = 0; i < frame_len8*2; i++)
|
|
118 data[band*frame_len*2 + w*frame_len8*2+i] *= gc_function[i];
|
|
119 for (i = 0; i < frame_len8; i++)
|
|
120 {
|
|
121 overlap[band*frame_len + i + 7*frame_len16 + w*frame_len8] +=
|
|
122 data[band*frame_len*2 + 2*w*frame_len8 + i];
|
|
123 }
|
|
124 for (i = 0; i < frame_len8; i++)
|
|
125 {
|
|
126 overlap[band*frame_len + i + 7*frame_len16 + (w+1)*frame_len8] =
|
|
127 data[band*frame_len*2 + 2*w*frame_len8 + frame_len8 + i];
|
|
128 }
|
|
129 }
|
|
130 for (i = 0; i < frame_len; i++)
|
|
131 output[band*frame_len + i] = overlap[band*frame_len + i];
|
|
132 for (i = 0; i < frame_len; i++)
|
|
133 overlap[band*frame_len + i] = overlap[band*frame_len + i + frame_len];
|
|
134 }
|
|
135 }
|
|
136
|
|
137 static void ssr_gc_function(ssr_info *ssr, real_t *prev_fmd,
|
|
138 real_t *gc_function, uint8_t window_sequence,
|
|
139 uint16_t frame_len)
|
|
140 {
|
|
141 uint16_t i;
|
|
142 uint16_t len_area1, len_area2;
|
|
143 int32_t aloc[10];
|
|
144 real_t alev[10];
|
|
145
|
|
146 switch (window_sequence)
|
|
147 {
|
|
148 case ONLY_LONG_SEQUENCE:
|
|
149 len_area1 = frame_len/SSR_BANDS;
|
|
150 len_area2 = 0;
|
|
151 break;
|
|
152 case LONG_START_SEQUENCE:
|
|
153 len_area1 = (frame_len/SSR_BANDS)*7/32;
|
|
154 len_area2 = (frame_len/SSR_BANDS)/16;
|
|
155 break;
|
|
156 case EIGHT_SHORT_SEQUENCE:
|
|
157 len_area1 = (frame_len/8)/SSR_BANDS;
|
|
158 len_area2 = 0;
|
|
159 break;
|
|
160 case LONG_STOP_SEQUENCE:
|
|
161 len_area1 = (frame_len/SSR_BANDS);
|
|
162 len_area2 = 0;
|
|
163 break;
|
|
164 }
|
|
165
|
|
166 /* decode bitstream information */
|
|
167
|
|
168 /* build array M */
|
|
169
|
|
170
|
|
171 for (i = 0; i < frame_len*2; i++)
|
|
172 gc_function[i] = 1;
|
|
173 }
|
|
174
|
|
175 #endif
|