OSDN Git Service

wwww
[proj16/16.git] / src / lib / doslib / ext / faad / ssr.c
1 /*
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2005 M. Bakker, Nero 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 ** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23 ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24 **
25 ** Commercial non-GPL licensing of this software is possible.
26 ** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27 **
28 ** $Id: ssr.c,v 1.19 2007/11/01 12:33:36 menno Exp $
29 **/
30
31 #include "common.h"
32 #include "structs.h"
33
34 #ifdef SSR_DEC
35
36 #include "syntax.h"
37 #include "filtbank.h"
38 #include "ssr.h"
39 #include "ssr_fb.h"
40
41 void ssr_decode(ssr_info *ssr, fb_info *fb, uint8_t window_sequence,
42                 uint8_t window_shape, uint8_t window_shape_prev,
43                 real_t *freq_in, real_t *time_out, real_t *overlap,
44                 real_t ipqf_buffer[SSR_BANDS][96/4],
45                 real_t *prev_fmd, uint16_t frame_len)
46 {
47     uint8_t band;
48     uint16_t ssr_frame_len = frame_len/SSR_BANDS;
49     real_t time_tmp[2048] = {0};
50     real_t output[1024] = {0};
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, band, 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                             uint8_t band, 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