ssr_ipqf.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_ipqf.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 "ssr.h"
00039 #include "ssr_ipqf.h"
00040 
00041 static real_t **app_pqfbuf;
00042 static real_t **pp_q0, **pp_t0, **pp_t1;
00043 
00044 void gc_set_protopqf(real_t *p_proto)
00045 {
00046     int j;
00047     static real_t a_half[48] =
00048     {
00049         1.2206911375946939E-05,  1.7261986723798209E-05,  1.2300093657077942E-05,
00050         -1.0833943097791965E-05, -5.7772498639901686E-05, -1.2764767618947719E-04,
00051         -2.0965186675013334E-04, -2.8166673689263850E-04, -3.1234860429017460E-04,
00052         -2.6738519958452353E-04, -1.1949424681824722E-04,  1.3965139412648678E-04,
00053         4.8864136409185725E-04,  8.7044629275148344E-04,  1.1949430269934793E-03,
00054         1.3519708175026700E-03,  1.2346314373964412E-03,  7.6953209114159191E-04,
00055         -5.2242432579537141E-05, -1.1516092887213454E-03, -2.3538469841711277E-03,
00056         -3.4033123072127277E-03, -4.0028551071986133E-03, -3.8745415659693259E-03,
00057         -2.8321073426874310E-03, -8.5038892323704195E-04,  1.8856751185350931E-03,
00058         4.9688741735340923E-03,  7.8056704536795926E-03,  9.7027909685901654E-03,
00059         9.9960423120166159E-03,  8.2019366335594487E-03,  4.1642072876103365E-03,
00060         -1.8364453822737758E-03, -9.0384863094167686E-03, -1.6241528177129844E-02,
00061         -2.1939551286300665E-02, -2.4533179947088161E-02, -2.2591663337768787E-02,
00062         -1.5122066420044672E-02, -1.7971713448186293E-03,  1.6903413428575379E-02,
00063         3.9672315874127042E-02,  6.4487527248102796E-02,  8.8850025474701726E-02,
00064         0.1101132906105560    ,  0.1258540205143761    ,  0.1342239368467012    
00065     };
00066 
00067     for (j = 0; j < 48; ++j)
00068     {
00069         p_proto[j] = p_proto[95-j] = a_half[j];
00070     }
00071 }
00072 
00073 void gc_setcoef_eff_pqfsyn(int mm,
00074                            int kk,
00075                            real_t *p_proto,
00076                            real_t ***ppp_q0,
00077                            real_t ***ppp_t0,
00078                            real_t ***ppp_t1)
00079 {
00080     int i, k, n;
00081     real_t      w;
00082 
00083     /* Set 1st Mul&Acc Coef's */
00084     *ppp_q0 = (real_t **) calloc(mm, sizeof(real_t *));
00085     for (n = 0; n < mm; ++n)
00086     {
00087         (*ppp_q0)[n] = (real_t *) calloc(mm, sizeof(real_t));
00088     }
00089     for (n = 0; n < mm/2; ++n)
00090     {
00091         for (i = 0; i < mm; ++i)
00092         {
00093             w = (2*i+1)*(2*n+1-mm)*M_PI/(4*mm);
00094             (*ppp_q0)[n][i] = 2.0 * cos((real_t) w);
00095 
00096             w = (2*i+1)*(2*(mm+n)+1-mm)*M_PI/(4*mm);
00097             (*ppp_q0)[n + mm/2][i] = 2.0 * cos((real_t) w);
00098         }
00099     }
00100 
00101     /* Set 2nd Mul&Acc Coef's */
00102     *ppp_t0 = (real_t **) calloc(mm, sizeof(real_t *));
00103     *ppp_t1 = (real_t **) calloc(mm, sizeof(real_t *));
00104     for (n = 0; n < mm; ++n)
00105     {
00106         (*ppp_t0)[n] = (real_t *) calloc(kk, sizeof(real_t));
00107         (*ppp_t1)[n] = (real_t *) calloc(kk, sizeof(real_t));
00108     }
00109     for (n = 0; n < mm; ++n)
00110     {
00111         for (k = 0; k < kk; ++k)
00112         {
00113             (*ppp_t0)[n][k] = mm * p_proto[2*k    *mm + n];
00114             (*ppp_t1)[n][k] = mm * p_proto[(2*k+1)*mm + n];
00115 
00116             if (k%2 != 0)
00117             {
00118                 (*ppp_t0)[n][k] = -(*ppp_t0)[n][k];
00119                 (*ppp_t1)[n][k] = -(*ppp_t1)[n][k];
00120             }
00121         }
00122     }
00123 }
00124 
00125 void ssr_ipqf(ssr_info *ssr, real_t *in_data, real_t *out_data,
00126               real_t buffer[SSR_BANDS][96/4],
00127               uint16_t frame_len, uint8_t bands)
00128 {
00129     static int initFlag = 0;
00130     real_t a_pqfproto[PQFTAPS];
00131 
00132     int i;
00133 
00134     if (initFlag == 0)
00135     {
00136         gc_set_protopqf(a_pqfproto);
00137         gc_setcoef_eff_pqfsyn(SSR_BANDS, PQFTAPS/(2*SSR_BANDS), a_pqfproto,
00138             &pp_q0, &pp_t0, &pp_t1);
00139         initFlag = 1;
00140     }
00141 
00142     for (i = 0; i < frame_len / SSR_BANDS; i++)
00143     {
00144         int l, n, k;
00145         int mm = SSR_BANDS;
00146         int kk = PQFTAPS/(2*SSR_BANDS);
00147 
00148         for (n = 0; n < mm; n++)
00149         {
00150             for (k = 0; k < 2*kk-1; k++)
00151             {
00152                 buffer[n][k] = buffer[n][k+1];
00153             }
00154         }
00155 
00156         for (n = 0; n < mm; n++)
00157         {
00158             real_t acc = 0.0;
00159             for (l = 0; l < mm; l++)
00160             {
00161                 acc += pp_q0[n][l] * in_data[l*frame_len/SSR_BANDS + i];
00162             }
00163             buffer[n][2*kk-1] = acc;
00164         }
00165 
00166         for (n = 0; n < mm/2; n++)
00167         {
00168             real_t acc = 0.0;
00169             for (k = 0; k < kk; k++)
00170             {
00171                 acc += pp_t0[n][k] * buffer[n][2*kk-1-2*k];
00172             }
00173             for (k = 0; k < kk; ++k)
00174             {
00175                 acc += pp_t1[n][k] * buffer[n + mm/2][2*kk-2-2*k];
00176             }
00177             out_data[i*SSR_BANDS + n] = acc;
00178 
00179             acc = 0.0;
00180             for (k = 0; k < kk; k++)
00181             {
00182                 acc += pp_t0[mm-1-n][k] * buffer[n][2*kk-1-2*k];
00183             }
00184             for (k = 0; k < kk; k++)
00185             {
00186                 acc -= pp_t1[mm-1-n][k] * buffer[n + mm/2][2*kk-2-2*k];
00187             }
00188             out_data[i*SSR_BANDS + mm-1-n] = acc;
00189         }
00190     }
00191 }
00192 
00193 #endif

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