lirc anc lircc are MPlayer-only, so add LDFLAGS for MPlayer link only.
[mplayer/glamo.git] / libfaad2 / ssr.c
bloba707dbb528cdd8b7fafeb466e04644329931b2f5
1 /*
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2004 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.
19 ** Any non-GPL usage of this software or parts of this software is strictly
20 ** forbidden.
22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
25 ** $Id: ssr.c,v 1.15 2004/09/04 14:56:29 menno Exp $
26 **/
28 #include "common.h"
29 #include "structs.h"
31 #ifdef SSR_DEC
33 #include "syntax.h"
34 #include "filtbank.h"
35 #include "ssr.h"
36 #include "ssr_fb.h"
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)
44 uint8_t band;
45 uint16_t ssr_frame_len = frame_len/SSR_BANDS;
46 real_t time_tmp[2048] = {0};
47 real_t output[1024] = {0};
49 for (band = 0; band < SSR_BANDS; band++)
51 int16_t j;
53 /* uneven bands have inverted frequency scale */
54 if (band == 1 || band == 3)
56 for (j = 0; j < ssr_frame_len/2; j++)
58 real_t tmp;
59 tmp = freq_in[j + ssr_frame_len*band];
60 freq_in[j + ssr_frame_len*band] =
61 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band];
62 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band] = tmp;
66 /* non-overlapping inverse filterbank for SSR */
67 ssr_ifilter_bank(fb, window_sequence, window_shape, window_shape_prev,
68 freq_in + band*ssr_frame_len, time_tmp + band*ssr_frame_len,
69 ssr_frame_len);
71 /* gain control */
72 ssr_gain_control(ssr, time_tmp, output, overlap, prev_fmd,
73 band, window_sequence, ssr_frame_len);
76 /* inverse pqf to bring subbands together again */
77 ssr_ipqf(ssr, output, time_out, ipqf_buffer, frame_len, SSR_BANDS);
80 static void ssr_gain_control(ssr_info *ssr, real_t *data, real_t *output,
81 real_t *overlap, real_t *prev_fmd, uint8_t band,
82 uint8_t window_sequence, uint16_t frame_len)
84 uint16_t i;
85 real_t gc_function[2*1024/SSR_BANDS];
87 if (window_sequence != EIGHT_SHORT_SEQUENCE)
89 ssr_gc_function(ssr, &prev_fmd[band * frame_len*2],
90 gc_function, window_sequence, band, frame_len);
92 for (i = 0; i < frame_len*2; i++)
93 data[band * frame_len*2 + i] *= gc_function[i];
94 for (i = 0; i < frame_len; i++)
96 output[band*frame_len + i] = overlap[band*frame_len + i] +
97 data[band*frame_len*2 + i];
99 for (i = 0; i < frame_len; i++)
101 overlap[band*frame_len + i] =
102 data[band*frame_len*2 + frame_len + i];
104 } else {
105 uint8_t w;
106 for (w = 0; w < 8; w++)
108 uint16_t frame_len8 = frame_len/8;
109 uint16_t frame_len16 = frame_len/16;
111 ssr_gc_function(ssr, &prev_fmd[band*frame_len*2 + w*frame_len*2/8],
112 gc_function, window_sequence, frame_len);
114 for (i = 0; i < frame_len8*2; i++)
115 data[band*frame_len*2 + w*frame_len8*2+i] *= gc_function[i];
116 for (i = 0; i < frame_len8; i++)
118 overlap[band*frame_len + i + 7*frame_len16 + w*frame_len8] +=
119 data[band*frame_len*2 + 2*w*frame_len8 + i];
121 for (i = 0; i < frame_len8; i++)
123 overlap[band*frame_len + i + 7*frame_len16 + (w+1)*frame_len8] =
124 data[band*frame_len*2 + 2*w*frame_len8 + frame_len8 + i];
127 for (i = 0; i < frame_len; i++)
128 output[band*frame_len + i] = overlap[band*frame_len + i];
129 for (i = 0; i < frame_len; i++)
130 overlap[band*frame_len + i] = overlap[band*frame_len + i + frame_len];
134 static void ssr_gc_function(ssr_info *ssr, real_t *prev_fmd,
135 real_t *gc_function, uint8_t window_sequence,
136 uint8_t band, uint16_t frame_len)
138 uint16_t i;
139 uint16_t len_area1, len_area2;
140 int32_t aloc[10];
141 real_t alev[10];
143 switch (window_sequence)
145 case ONLY_LONG_SEQUENCE:
146 len_area1 = frame_len/SSR_BANDS;
147 len_area2 = 0;
148 break;
149 case LONG_START_SEQUENCE:
150 len_area1 = (frame_len/SSR_BANDS)*7/32;
151 len_area2 = (frame_len/SSR_BANDS)/16;
152 break;
153 case EIGHT_SHORT_SEQUENCE:
154 len_area1 = (frame_len/8)/SSR_BANDS;
155 len_area2 = 0;
156 break;
157 case LONG_STOP_SEQUENCE:
158 len_area1 = (frame_len/SSR_BANDS);
159 len_area2 = 0;
160 break;
163 /* decode bitstream information */
165 /* build array M */
168 for (i = 0; i < frame_len*2; i++)
169 gc_function[i] = 1;
172 #endif