ssr.c

00001 /*
00002 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
00003 ** Copyright (C) 2003-2005 M. Bakker, Ahead Software AG, http://www.nero.com
00004 **  
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 ** 
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 ** 
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software 
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 **
00019 ** Any non-GPL usage of this software or parts of this software is strictly
00020 ** forbidden.
00021 **
00022 ** Software using this code must display the following message visibly in the
00023 ** software:
00024 ** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Ahead Software, www.nero.com"
00025 ** in, for example, the about-box or help/startup screen.
00026 **
00027 ** Commercial non-GPL licensing of this software is possible.
00028 ** For more info contact Ahead Software through [email protected].
00029 **
00030 ** $Id: ssr.c,v 1.2 2005/11/01 21:41:43 gabest Exp $
00031 **/
00032 
00033 #include "common.h"
00034 #include "structs.h"
00035 
00036 #ifdef SSR_DEC
00037 
00038 #include "syntax.h"
00039 #include "filtbank.h"
00040 #include "ssr.h"
00041 #include "ssr_fb.h"
00042 
00043 void ssr_decode(ssr_info *ssr, fb_info *fb, uint8_t window_sequence,
00044                 uint8_t window_shape, uint8_t window_shape_prev,
00045                 real_t *freq_in, real_t *time_out, real_t *overlap,
00046                 real_t ipqf_buffer[SSR_BANDS][96/4],
00047                 real_t *prev_fmd, uint16_t frame_len)
00048 {
00049     uint8_t band;
00050     uint16_t ssr_frame_len = frame_len/SSR_BANDS;
00051     real_t time_tmp[2048] = {0};
00052     real_t output[1024] = {0};
00053 
00054     for (band = 0; band < SSR_BANDS; band++)
00055     {
00056         int16_t j;
00057 
00058         /* uneven bands have inverted frequency scale */
00059         if (band == 1 || band == 3)
00060         {
00061             for (j = 0; j < ssr_frame_len/2; j++)
00062             {
00063                 real_t tmp;
00064                 tmp = freq_in[j + ssr_frame_len*band];
00065                 freq_in[j + ssr_frame_len*band] =
00066                     freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band];
00067                 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band] = tmp;
00068             }
00069         }
00070 
00071         /* non-overlapping inverse filterbank for SSR */
00072         ssr_ifilter_bank(fb, window_sequence, window_shape, window_shape_prev,
00073             freq_in + band*ssr_frame_len, time_tmp + band*ssr_frame_len,
00074             ssr_frame_len);
00075 
00076         /* gain control */
00077         ssr_gain_control(ssr, time_tmp, output, overlap, prev_fmd,
00078             band, window_sequence, ssr_frame_len);
00079     }
00080 
00081     /* inverse pqf to bring subbands together again */
00082     ssr_ipqf(ssr, output, time_out, ipqf_buffer, frame_len, SSR_BANDS);
00083 }
00084 
00085 static void ssr_gain_control(ssr_info *ssr, real_t *data, real_t *output,
00086                              real_t *overlap, real_t *prev_fmd, uint8_t band,
00087                              uint8_t window_sequence, uint16_t frame_len)
00088 {
00089     uint16_t i;
00090     real_t gc_function[2*1024/SSR_BANDS];
00091 
00092     if (window_sequence != EIGHT_SHORT_SEQUENCE)
00093     {
00094         ssr_gc_function(ssr, &prev_fmd[band * frame_len*2],
00095             gc_function, window_sequence, band, frame_len);
00096 
00097         for (i = 0; i < frame_len*2; i++)
00098             data[band * frame_len*2 + i] *= gc_function[i];
00099         for (i = 0; i < frame_len; i++)
00100         {
00101             output[band*frame_len + i] = overlap[band*frame_len + i] +
00102                 data[band*frame_len*2 + i];
00103         }
00104         for (i = 0; i < frame_len; i++)
00105         {
00106             overlap[band*frame_len + i] =
00107                 data[band*frame_len*2 + frame_len + i];
00108         }
00109     } else {
00110         uint8_t w;
00111         for (w = 0; w < 8; w++)
00112         {
00113             uint16_t frame_len8 = frame_len/8;
00114             uint16_t frame_len16 = frame_len/16;
00115 
00116             ssr_gc_function(ssr, &prev_fmd[band*frame_len*2 + w*frame_len*2/8],
00117                 gc_function, window_sequence, frame_len);
00118 
00119             for (i = 0; i < frame_len8*2; i++)
00120                 data[band*frame_len*2 + w*frame_len8*2+i] *= gc_function[i];
00121             for (i = 0; i < frame_len8; i++)
00122             {
00123                 overlap[band*frame_len + i + 7*frame_len16 + w*frame_len8] +=
00124                     data[band*frame_len*2 + 2*w*frame_len8 + i];
00125             }
00126             for (i = 0; i < frame_len8; i++)
00127             {
00128                 overlap[band*frame_len + i + 7*frame_len16 + (w+1)*frame_len8] =
00129                     data[band*frame_len*2 + 2*w*frame_len8 + frame_len8 + i];
00130             }
00131         }
00132         for (i = 0; i < frame_len; i++)
00133             output[band*frame_len + i] = overlap[band*frame_len + i];
00134         for (i = 0; i < frame_len; i++)
00135             overlap[band*frame_len + i] = overlap[band*frame_len + i + frame_len];
00136     }
00137 }
00138 
00139 static void ssr_gc_function(ssr_info *ssr, real_t *prev_fmd,
00140                             real_t *gc_function, uint8_t window_sequence,
00141                             uint8_t band, uint16_t frame_len)
00142 {
00143     uint16_t i;
00144     uint16_t len_area1, len_area2;
00145     int32_t aloc[10];
00146     real_t alev[10];
00147 
00148     switch (window_sequence)
00149     {
00150     case ONLY_LONG_SEQUENCE:
00151         len_area1 = frame_len/SSR_BANDS;
00152         len_area2 = 0;
00153         break;
00154     case LONG_START_SEQUENCE:
00155         len_area1 = (frame_len/SSR_BANDS)*7/32;
00156         len_area2 = (frame_len/SSR_BANDS)/16;
00157         break;
00158     case EIGHT_SHORT_SEQUENCE:
00159         len_area1 = (frame_len/8)/SSR_BANDS;
00160         len_area2 = 0;
00161         break;
00162     case LONG_STOP_SEQUENCE:
00163         len_area1 = (frame_len/SSR_BANDS);
00164         len_area2 = 0;
00165         break;
00166     }
00167 
00168     /* decode bitstream information */
00169 
00170     /* build array M */
00171 
00172 
00173     for (i = 0; i < frame_len*2; i++)
00174         gc_function[i] = 1;
00175 }
00176 
00177 #endif

Generated on Tue Dec 13 14:47:47 2005 for guliverkli by  doxygen 1.4.5