sbr_qmf.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: sbr_qmf.c,v 1.3 2005/11/01 21:41:43 gabest Exp $
00031 **/
00032 
00033 #include "common.h"
00034 #include "structs.h"
00035 
00036 #ifdef SBR_DEC
00037 
00038 
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include "sbr_dct.h"
00042 #include "sbr_qmf.h"
00043 #include "sbr_qmf_c.h"
00044 #include "sbr_syntax.h"
00045 
00046 qmfa_info *qmfa_init(uint8_t channels)
00047 {
00048     qmfa_info *qmfa = (qmfa_info*)faad_malloc(sizeof(qmfa_info));
00049 
00050         /* x is implemented as double ringbuffer */
00051     qmfa->x = (real_t*)faad_malloc(2 * channels * 10 * sizeof(real_t));
00052     memset(qmfa->x, 0, 2 * channels * 10 * sizeof(real_t));
00053 
00054         /* ringbuffer index */
00055         qmfa->x_index = 0;
00056 
00057     qmfa->channels = channels;
00058 
00059     return qmfa;
00060 }
00061 
00062 void qmfa_end(qmfa_info *qmfa)
00063 {
00064     if (qmfa)
00065     {
00066         if (qmfa->x) faad_free(qmfa->x);
00067         faad_free(qmfa);
00068     }
00069 }
00070 
00071 void sbr_qmf_analysis_32(sbr_info *sbr, qmfa_info *qmfa, const real_t *input,
00072                          qmf_t X[MAX_NTSRHFG][64], uint8_t offset, uint8_t kx)
00073 {
00074     ALIGN real_t u[64];
00075 #ifndef SBR_LOW_POWER
00076     ALIGN real_t in_real[32], in_imag[32], out_real[32], out_imag[32];
00077 #else
00078     ALIGN real_t y[32];
00079 #endif
00080     uint32_t in = 0;
00081     uint8_t l;
00082 
00083     /* qmf subsample l */
00084     for (l = 0; l < sbr->numTimeSlotsRate; l++)
00085     {
00086         int16_t n;
00087 
00088         /* shift input buffer x */
00089                 /* input buffer is not shifted anymore, x is implemented as double ringbuffer */
00090         //memmove(qmfa->x + 32, qmfa->x, (320-32)*sizeof(real_t));
00091 
00092         /* add new samples to input buffer x */
00093         for (n = 32 - 1; n >= 0; n--)
00094         {
00095 #ifdef FIXED_POINT
00096             qmfa->x[qmfa->x_index + n] = qmfa->x[qmfa->x_index + n + 320] = (input[in++]) >> 4;
00097 #else
00098             qmfa->x[qmfa->x_index + n] = qmfa->x[qmfa->x_index + n + 320] = input[in++];
00099 #endif
00100         }
00101 
00102         /* window and summation to create array u */
00103         for (n = 0; n < 64; n++)
00104         {
00105             u[n] = MUL_F(qmfa->x[qmfa->x_index + n], qmf_c[2*n]) +
00106                 MUL_F(qmfa->x[qmfa->x_index + n + 64], qmf_c[2*(n + 64)]) +
00107                 MUL_F(qmfa->x[qmfa->x_index + n + 128], qmf_c[2*(n + 128)]) +
00108                 MUL_F(qmfa->x[qmfa->x_index + n + 192], qmf_c[2*(n + 192)]) +
00109                 MUL_F(qmfa->x[qmfa->x_index + n + 256], qmf_c[2*(n + 256)]);
00110         }
00111 
00112                 /* update ringbuffer index */
00113                 qmfa->x_index -= 32;
00114                 if (qmfa->x_index < 0)
00115                         qmfa->x_index = (320-32);
00116 
00117         /* calculate 32 subband samples by introducing X */
00118 #ifdef SBR_LOW_POWER
00119         y[0] = u[48];
00120         for (n = 1; n < 16; n++)
00121             y[n] = u[n+48] + u[48-n];
00122         for (n = 16; n < 32; n++)
00123             y[n] = -u[n-16] + u[48-n];
00124 
00125         DCT3_32_unscaled(u, y);
00126 
00127         for (n = 0; n < 32; n++)
00128         {
00129             if (n < kx)
00130             {
00131 #ifdef FIXED_POINT
00132                 QMF_RE(X[l + offset][n]) = u[n] /*<< 1*/;
00133 #else
00134                 QMF_RE(X[l + offset][n]) = 2. * u[n];
00135 #endif
00136             } else {
00137                 QMF_RE(X[l + offset][n]) = 0;
00138             }
00139         }
00140 #else
00141 
00142         // Reordering of data moved from DCT_IV to here
00143         in_imag[31] = u[1];
00144         in_real[0] = u[0];
00145         for (n = 1; n < 31; n++)
00146         {
00147             in_imag[31 - n] = u[n+1];
00148             in_real[n] = -u[64-n];
00149         }
00150         in_imag[0] = u[32];
00151         in_real[31] = -u[33];
00152 
00153         // dct4_kernel is DCT_IV without reordering which is done before and after FFT
00154         dct4_kernel(in_real, in_imag, out_real, out_imag);
00155 
00156         // Reordering of data moved from DCT_IV to here
00157         for (n = 0; n < 16; n++) {
00158             if (2*n+1 < kx) {
00159 #ifdef FIXED_POINT
00160                 QMF_RE(X[l + offset][2*n])   = out_real[n];
00161                 QMF_IM(X[l + offset][2*n])   = out_imag[n];
00162                 QMF_RE(X[l + offset][2*n+1]) = -out_imag[31-n];
00163                 QMF_IM(X[l + offset][2*n+1]) = -out_real[31-n];
00164 #else
00165                 QMF_RE(X[l + offset][2*n])   = 2. * out_real[n];
00166                 QMF_IM(X[l + offset][2*n])   = 2. * out_imag[n];
00167                 QMF_RE(X[l + offset][2*n+1]) = -2. * out_imag[31-n];
00168                 QMF_IM(X[l + offset][2*n+1]) = -2. * out_real[31-n];
00169 #endif
00170             } else {
00171                 if (2*n < kx) {
00172 #ifdef FIXED_POINT
00173                     QMF_RE(X[l + offset][2*n])   = out_real[n];
00174                     QMF_IM(X[l + offset][2*n])   = out_imag[n];
00175 #else
00176                     QMF_RE(X[l + offset][2*n])   = 2. * out_real[n];
00177                     QMF_IM(X[l + offset][2*n])   = 2. * out_imag[n];
00178 #endif
00179                 }
00180                 else {
00181                     QMF_RE(X[l + offset][2*n]) = 0;
00182                     QMF_IM(X[l + offset][2*n]) = 0;
00183                 }
00184                 QMF_RE(X[l + offset][2*n+1]) = 0;
00185                 QMF_IM(X[l + offset][2*n+1]) = 0;
00186             }
00187         }
00188 #endif
00189     }
00190 }
00191 
00192 static const complex_t qmf32_pre_twiddle[] =
00193 {
00194     { FRAC_CONST(0.999924701839145), FRAC_CONST(-0.012271538285720) },
00195     { FRAC_CONST(0.999322384588350), FRAC_CONST(-0.036807222941359) },
00196     { FRAC_CONST(0.998118112900149), FRAC_CONST(-0.061320736302209) },
00197     { FRAC_CONST(0.996312612182778), FRAC_CONST(-0.085797312344440) },
00198     { FRAC_CONST(0.993906970002356), FRAC_CONST(-0.110222207293883) },
00199     { FRAC_CONST(0.990902635427780), FRAC_CONST(-0.134580708507126) },
00200     { FRAC_CONST(0.987301418157858), FRAC_CONST(-0.158858143333861) },
00201     { FRAC_CONST(0.983105487431216), FRAC_CONST(-0.183039887955141) },
00202     { FRAC_CONST(0.978317370719628), FRAC_CONST(-0.207111376192219) },
00203     { FRAC_CONST(0.972939952205560), FRAC_CONST(-0.231058108280671) },
00204     { FRAC_CONST(0.966976471044852), FRAC_CONST(-0.254865659604515) },
00205     { FRAC_CONST(0.960430519415566), FRAC_CONST(-0.278519689385053) },
00206     { FRAC_CONST(0.953306040354194), FRAC_CONST(-0.302005949319228) },
00207     { FRAC_CONST(0.945607325380521), FRAC_CONST(-0.325310292162263) },
00208     { FRAC_CONST(0.937339011912575), FRAC_CONST(-0.348418680249435) },
00209     { FRAC_CONST(0.928506080473216), FRAC_CONST(-0.371317193951838) },
00210     { FRAC_CONST(0.919113851690058), FRAC_CONST(-0.393992040061048) },
00211     { FRAC_CONST(0.909167983090522), FRAC_CONST(-0.416429560097637) },
00212     { FRAC_CONST(0.898674465693954), FRAC_CONST(-0.438616238538528) },
00213     { FRAC_CONST(0.887639620402854), FRAC_CONST(-0.460538710958240) },
00214     { FRAC_CONST(0.876070094195407), FRAC_CONST(-0.482183772079123) },
00215     { FRAC_CONST(0.863972856121587), FRAC_CONST(-0.503538383725718) },
00216     { FRAC_CONST(0.851355193105265), FRAC_CONST(-0.524589682678469) },
00217     { FRAC_CONST(0.838224705554838), FRAC_CONST(-0.545324988422046) },
00218     { FRAC_CONST(0.824589302785025), FRAC_CONST(-0.565731810783613) },
00219     { FRAC_CONST(0.810457198252595), FRAC_CONST(-0.585797857456439) },
00220     { FRAC_CONST(0.795836904608884), FRAC_CONST(-0.605511041404326) },
00221     { FRAC_CONST(0.780737228572094), FRAC_CONST(-0.624859488142386) },
00222     { FRAC_CONST(0.765167265622459), FRAC_CONST(-0.643831542889791) },
00223     { FRAC_CONST(0.749136394523459), FRAC_CONST(-0.662415777590172) },
00224     { FRAC_CONST(0.732654271672413), FRAC_CONST(-0.680600997795453) },
00225     { FRAC_CONST(0.715730825283819), FRAC_CONST(-0.698376249408973) }
00226 };
00227 
00228 qmfs_info *qmfs_init(uint8_t channels)
00229 {
00230     qmfs_info *qmfs = (qmfs_info*)faad_malloc(sizeof(qmfs_info));
00231 
00232         /* v is a double ringbuffer */
00233     qmfs->v = (real_t*)faad_malloc(2 * channels * 20 * sizeof(real_t));
00234     memset(qmfs->v, 0, 2 * channels * 20 * sizeof(real_t));
00235 
00236     qmfs->v_index = 0;
00237 
00238     qmfs->channels = channels;
00239 
00240     return qmfs;
00241 }
00242 
00243 void qmfs_end(qmfs_info *qmfs)
00244 {
00245     if (qmfs)
00246     {
00247         if (qmfs->v) faad_free(qmfs->v);
00248         faad_free(qmfs);
00249     }
00250 }
00251 
00252 #ifdef SBR_LOW_POWER
00253 
00254 void sbr_qmf_synthesis_32(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
00255                           real_t *output)
00256 {
00257     ALIGN real_t x[16];
00258     ALIGN real_t y[16];
00259     int32_t n, k, out = 0;
00260     uint8_t l;
00261 
00262     /* qmf subsample l */
00263     for (l = 0; l < sbr->numTimeSlotsRate; l++)
00264     {
00265         /* shift buffers */
00266         /* we are not shifting v, it is a double ringbuffer */
00267         //memmove(qmfs->v + 64, qmfs->v, (640-64)*sizeof(real_t));
00268 
00269         /* calculate 64 samples */
00270         for (k = 0; k < 16; k++)
00271         {
00272 #ifdef FIXED_POINT
00273             y[k] = (QMF_RE(X[l][k]) - QMF_RE(X[l][31 - k]));
00274             x[k] = (QMF_RE(X[l][k]) + QMF_RE(X[l][31 - k]));
00275 #else
00276             y[k] = (QMF_RE(X[l][k]) - QMF_RE(X[l][31 - k])) / 32.0;
00277             x[k] = (QMF_RE(X[l][k]) + QMF_RE(X[l][31 - k])) / 32.0;
00278 #endif
00279         }
00280 
00281         /* even n samples */
00282         DCT2_16_unscaled(x, x);
00283         /* odd n samples */
00284         DCT4_16(y, y);
00285 
00286         for (n = 8; n < 24; n++)
00287         {
00288             qmfs->v[qmfs->v_index + n*2] = qmfs->v[qmfs->v_index + 640 + n*2] = x[n-8];
00289             qmfs->v[qmfs->v_index + n*2+1] = qmfs->v[qmfs->v_index + 640 + n*2+1] = y[n-8];
00290         }
00291         for (n = 0; n < 16; n++)
00292         {
00293             qmfs->v[qmfs->v_index + n] = qmfs->v[qmfs->v_index + 640 + n] = qmfs->v[qmfs->v_index + 32-n];
00294         }
00295         qmfs->v[qmfs->v_index + 48] = qmfs->v[qmfs->v_index + 640 + 48] = 0;
00296         for (n = 1; n < 16; n++)
00297         {
00298             qmfs->v[qmfs->v_index + 48+n] = qmfs->v[qmfs->v_index + 640 + 48+n] = -qmfs->v[qmfs->v_index + 48-n];
00299         }
00300 
00301         /* calculate 32 output samples and window */
00302         for (k = 0; k < 32; k++)
00303         {
00304             output[out++] = MUL_F(qmfs->v[qmfs->v_index + k], qmf_c[2*k]) +
00305                 MUL_F(qmfs->v[qmfs->v_index + 96 + k], qmf_c[64 + 2*k]) +
00306                 MUL_F(qmfs->v[qmfs->v_index + 128 + k], qmf_c[128 + 2*k]) +
00307                 MUL_F(qmfs->v[qmfs->v_index + 224 + k], qmf_c[192 + 2*k]) +
00308                 MUL_F(qmfs->v[qmfs->v_index + 256 + k], qmf_c[256 + 2*k]) +
00309                 MUL_F(qmfs->v[qmfs->v_index + 352 + k], qmf_c[320 + 2*k]) +
00310                 MUL_F(qmfs->v[qmfs->v_index + 384 + k], qmf_c[384 + 2*k]) +
00311                 MUL_F(qmfs->v[qmfs->v_index + 480 + k], qmf_c[448 + 2*k]) +
00312                 MUL_F(qmfs->v[qmfs->v_index + 512 + k], qmf_c[512 + 2*k]) +
00313                 MUL_F(qmfs->v[qmfs->v_index + 608 + k], qmf_c[576 + 2*k]);
00314         }
00315 
00316         /* update the ringbuffer index */
00317         qmfs->v_index -= 64;
00318         if (qmfs->v_index < 0)
00319             qmfs->v_index = (640-64);
00320     }
00321 }
00322 
00323 void sbr_qmf_synthesis_64(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
00324                           real_t *output)
00325 {
00326     ALIGN real_t x[64];
00327     ALIGN real_t y[64];
00328     int32_t n, k, out = 0;
00329     uint8_t l;
00330 
00331 
00332     /* qmf subsample l */
00333     for (l = 0; l < sbr->numTimeSlotsRate; l++)
00334     {
00335         /* shift buffers */
00336         /* we are not shifting v, it is a double ringbuffer */
00337         //memmove(qmfs->v + 128, qmfs->v, (1280-128)*sizeof(real_t));
00338 
00339         /* calculate 128 samples */
00340         for (k = 0; k < 32; k++)
00341         {
00342 #ifdef FIXED_POINT
00343             y[k] = (QMF_RE(X[l][k]) - QMF_RE(X[l][63 - k]));
00344             x[k] = (QMF_RE(X[l][k]) + QMF_RE(X[l][63 - k]));
00345 #else
00346             y[k] = (QMF_RE(X[l][k]) - QMF_RE(X[l][63 - k])) / 32.0;
00347             x[k] = (QMF_RE(X[l][k]) + QMF_RE(X[l][63 - k])) / 32.0;
00348 #endif
00349         }
00350 
00351         /* even n samples */
00352         DCT2_32_unscaled(x, x);
00353         /* odd n samples */
00354         DCT4_32(y, y);
00355 
00356         for (n = 16; n < 48; n++)
00357         {
00358             qmfs->v[qmfs->v_index + n*2]   = qmfs->v[qmfs->v_index + 1280 + n*2]   = x[n-16];
00359             qmfs->v[qmfs->v_index + n*2+1] = qmfs->v[qmfs->v_index + 1280 + n*2+1] = y[n-16];
00360         }
00361         for (n = 0; n < 32; n++)
00362         {
00363             qmfs->v[qmfs->v_index + n] = qmfs->v[qmfs->v_index + 1280 + n] = qmfs->v[qmfs->v_index + 64-n];
00364         }
00365         qmfs->v[qmfs->v_index + 96] = qmfs->v[qmfs->v_index + 1280 + 96] = 0;
00366         for (n = 1; n < 32; n++)
00367         {
00368             qmfs->v[qmfs->v_index + 96+n] = qmfs->v[qmfs->v_index + 1280 + 96+n] = -qmfs->v[qmfs->v_index + 96-n];
00369         }
00370 
00371         /* calculate 64 output samples and window */
00372         for (k = 0; k < 64; k++)
00373         {
00374             output[out++] = MUL_F(qmfs->v[qmfs->v_index + k], qmf_c[k]) +
00375                 MUL_F(qmfs->v[qmfs->v_index + 192 + k], qmf_c[64 + k]) +
00376                 MUL_F(qmfs->v[qmfs->v_index + 256 + k], qmf_c[128 + k]) +
00377                 MUL_F(qmfs->v[qmfs->v_index + 256 + 192 + k], qmf_c[128 + 64 + k]) +
00378                 MUL_F(qmfs->v[qmfs->v_index + 512 + k], qmf_c[256 + k]) +
00379                 MUL_F(qmfs->v[qmfs->v_index + 512 + 192 + k], qmf_c[256 + 64 + k]) +
00380                 MUL_F(qmfs->v[qmfs->v_index + 768 + k], qmf_c[384 + k]) +
00381                 MUL_F(qmfs->v[qmfs->v_index + 768 + 192 + k], qmf_c[384 + 64 + k]) +
00382                 MUL_F(qmfs->v[qmfs->v_index + 1024 + k], qmf_c[512 + k]) +
00383                 MUL_F(qmfs->v[qmfs->v_index + 1024 + 192 + k], qmf_c[512 + 64 + k]);
00384         }
00385 
00386         /* update the ringbuffer index */
00387         qmfs->v_index -= 128;
00388         if (qmfs->v_index < 0)
00389             qmfs->v_index = (1280-128);
00390     }
00391 }
00392 #else
00393 void sbr_qmf_synthesis_32(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
00394                           real_t *output)
00395 {
00396     ALIGN real_t x1[32], x2[32];
00397 #ifndef FIXED_POINT
00398     real_t scale = 1.f/64.f;
00399 #endif
00400     int32_t n, k, out = 0;
00401     uint8_t l;
00402 
00403 
00404     /* qmf subsample l */
00405     for (l = 0; l < sbr->numTimeSlotsRate; l++)
00406     {
00407         /* shift buffer v */
00408         /* buffer is not shifted, we are using a ringbuffer */
00409         //memmove(qmfs->v + 64, qmfs->v, (640-64)*sizeof(real_t));
00410 
00411         /* calculate 64 samples */
00412         /* complex pre-twiddle */
00413         for (k = 0; k < 32; k++)
00414         {
00415             x1[k] = MUL_F(QMF_RE(X[l][k]), RE(qmf32_pre_twiddle[k])) - MUL_F(QMF_IM(X[l][k]), IM(qmf32_pre_twiddle[k]));
00416             x2[k] = MUL_F(QMF_IM(X[l][k]), RE(qmf32_pre_twiddle[k])) + MUL_F(QMF_RE(X[l][k]), IM(qmf32_pre_twiddle[k]));
00417 
00418 #ifndef FIXED_POINT
00419             x1[k] *= scale;
00420             x2[k] *= scale;
00421 #else
00422             x1[k] >>= 1;
00423             x2[k] >>= 1;
00424 #endif
00425         }
00426 
00427         /* transform */
00428         DCT4_32(x1, x1);
00429         DST4_32(x2, x2);
00430 
00431         for (n = 0; n < 32; n++)
00432         {
00433             qmfs->v[qmfs->v_index + n]      = qmfs->v[qmfs->v_index + 640 + n]      = -x1[n] + x2[n];
00434             qmfs->v[qmfs->v_index + 63 - n] = qmfs->v[qmfs->v_index + 640 + 63 - n] =  x1[n] + x2[n];
00435         }
00436 
00437         /* calculate 32 output samples and window */
00438         for (k = 0; k < 32; k++)
00439         {
00440             output[out++] = MUL_F(qmfs->v[qmfs->v_index + k], qmf_c[2*k]) +
00441                 MUL_F(qmfs->v[qmfs->v_index + 96 + k], qmf_c[64 + 2*k]) +
00442                 MUL_F(qmfs->v[qmfs->v_index + 128 + k], qmf_c[128 + 2*k]) +
00443                 MUL_F(qmfs->v[qmfs->v_index + 224 + k], qmf_c[192 + 2*k]) +
00444                 MUL_F(qmfs->v[qmfs->v_index + 256 + k], qmf_c[256 + 2*k]) +
00445                 MUL_F(qmfs->v[qmfs->v_index + 352 + k], qmf_c[320 + 2*k]) +
00446                 MUL_F(qmfs->v[qmfs->v_index + 384 + k], qmf_c[384 + 2*k]) +
00447                 MUL_F(qmfs->v[qmfs->v_index + 480 + k], qmf_c[448 + 2*k]) +
00448                 MUL_F(qmfs->v[qmfs->v_index + 512 + k], qmf_c[512 + 2*k]) +
00449                 MUL_F(qmfs->v[qmfs->v_index + 608 + k], qmf_c[576 + 2*k]);
00450         }
00451 
00452         /* update ringbuffer index */
00453         qmfs->v_index -= 64;
00454         if (qmfs->v_index < 0)
00455             qmfs->v_index = (640 - 64);
00456     }
00457 }
00458 
00459 void sbr_qmf_synthesis_64(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
00460                           real_t *output)
00461 {
00462 //    ALIGN real_t x1[64], x2[64];
00463 #ifndef SBR_LOW_POWER
00464     ALIGN real_t in_real1[32], in_imag1[32], out_real1[32], out_imag1[32];
00465     ALIGN real_t in_real2[32], in_imag2[32], out_real2[32], out_imag2[32];
00466 #endif
00467     qmf_t * pX;
00468     real_t * pring_buffer_1, * pring_buffer_3;
00469 //    real_t * ptemp_1, * ptemp_2;
00470 #ifdef PREFER_POINTERS
00471     // These pointers are used if target platform has autoinc address generators
00472     real_t * pring_buffer_2, * pring_buffer_4;
00473     real_t * pring_buffer_5, * pring_buffer_6;
00474     real_t * pring_buffer_7, * pring_buffer_8;
00475     real_t * pring_buffer_9, * pring_buffer_10;
00476     const real_t * pqmf_c_1, * pqmf_c_2, * pqmf_c_3, * pqmf_c_4;
00477     const real_t * pqmf_c_5, * pqmf_c_6, * pqmf_c_7, * pqmf_c_8;
00478     const real_t * pqmf_c_9, * pqmf_c_10;
00479 #endif // #ifdef PREFER_POINTERS
00480 #ifndef FIXED_POINT
00481     real_t scale = 1.f/64.f;
00482 #endif
00483     int32_t n, k, out = 0;
00484     uint8_t l;
00485 
00486 
00487     /* qmf subsample l */
00488     for (l = 0; l < sbr->numTimeSlotsRate; l++)
00489     {
00490         /* shift buffer v */
00491                 /* buffer is not shifted, we use double ringbuffer */
00492                 //memmove(qmfs->v + 128, qmfs->v, (1280-128)*sizeof(real_t));
00493 
00494         /* calculate 128 samples */
00495 #ifndef FIXED_POINT
00496 
00497         pX = X[l];
00498 
00499         in_imag1[31] = scale*QMF_RE(pX[1]);
00500         in_real1[0]  = scale*QMF_RE(pX[0]);
00501         in_imag2[31] = scale*QMF_IM(pX[63-1]);
00502         in_real2[0]  = scale*QMF_IM(pX[63-0]);
00503         for (k = 1; k < 31; k++)
00504         {
00505             in_imag1[31 - k] = scale*QMF_RE(pX[2*k + 1]);
00506             in_real1[     k] = scale*QMF_RE(pX[2*k    ]);
00507             in_imag2[31 - k] = scale*QMF_IM(pX[63 - (2*k + 1)]);
00508             in_real2[     k] = scale*QMF_IM(pX[63 - (2*k    )]);
00509         }
00510         in_imag1[0]  = scale*QMF_RE(pX[63]);
00511         in_real1[31] = scale*QMF_RE(pX[62]);
00512         in_imag2[0]  = scale*QMF_IM(pX[63-63]);
00513         in_real2[31] = scale*QMF_IM(pX[63-62]);
00514 
00515 #else
00516 
00517         pX = X[l];
00518 
00519         in_imag1[31] = QMF_RE(pX[1]) >> 1;
00520         in_real1[0]  = QMF_RE(pX[0]) >> 1;
00521         in_imag2[31] = QMF_IM(pX[62]) >> 1;
00522         in_real2[0]  = QMF_IM(pX[63]) >> 1;
00523         for (k = 1; k < 31; k++)
00524         {
00525             in_imag1[31 - k] = QMF_RE(pX[2*k + 1]) >> 1;
00526             in_real1[     k] = QMF_RE(pX[2*k    ]) >> 1;
00527             in_imag2[31 - k] = QMF_IM(pX[63 - (2*k + 1)]) >> 1;
00528             in_real2[     k] = QMF_IM(pX[63 - (2*k    )]) >> 1;
00529         }
00530         in_imag1[0]  = QMF_RE(pX[63]) >> 1;
00531         in_real1[31] = QMF_RE(pX[62]) >> 1;
00532         in_imag2[0]  = QMF_IM(pX[0]) >> 1;
00533         in_real2[31] = QMF_IM(pX[1]) >> 1;
00534 
00535 #endif
00536 
00537 
00538         // dct4_kernel is DCT_IV without reordering which is done before and after FFT
00539         dct4_kernel(in_real1, in_imag1, out_real1, out_imag1);
00540         dct4_kernel(in_real2, in_imag2, out_real2, out_imag2);
00541 
00542 
00543         pring_buffer_1 = qmfs->v + qmfs->v_index;
00544         pring_buffer_3 = pring_buffer_1 + 1280;
00545 #ifdef PREFER_POINTERS
00546         pring_buffer_2 = pring_buffer_1 + 127;
00547         pring_buffer_4 = pring_buffer_1 + (1280 + 127);
00548 #endif // #ifdef PREFER_POINTERS
00549 //        ptemp_1 = x1;
00550 //        ptemp_2 = x2;
00551 #ifdef PREFER_POINTERS
00552         for (n = 0; n < 32; n ++)
00553         {
00554             //real_t x1 = *ptemp_1++;
00555             //real_t x2 = *ptemp_2++;
00556             // pring_buffer_3 and pring_buffer_4 are needed only for double ring buffer
00557             *pring_buffer_1++ = *pring_buffer_3++ = out_real2[n] - out_real1[n];
00558             *pring_buffer_2-- = *pring_buffer_4-- = out_real2[n] + out_real1[n];
00559             //x1 = *ptemp_1++;
00560             //x2 = *ptemp_2++;
00561             *pring_buffer_1++ = *pring_buffer_3++ = out_imag2[31-n] + out_imag1[31-n];
00562             *pring_buffer_2-- = *pring_buffer_4-- = out_imag2[31-n] - out_imag1[31-n];
00563         }
00564 #else // #ifdef PREFER_POINTERS
00565 
00566         for (n = 0; n < 32; n++)
00567         {
00568             // pring_buffer_3 and pring_buffer_4 are needed only for double ring buffer
00569             pring_buffer_1[2*n]         = pring_buffer_3[2*n]         = out_real2[n] - out_real1[n];
00570             pring_buffer_1[127-2*n]     = pring_buffer_3[127-2*n]     = out_real2[n] + out_real1[n];
00571             pring_buffer_1[2*n+1]       = pring_buffer_3[2*n+1]       = out_imag2[31-n] + out_imag1[31-n];
00572             pring_buffer_1[127-(2*n+1)] = pring_buffer_3[127-(2*n+1)] = out_imag2[31-n] - out_imag1[31-n];
00573         }
00574 
00575 #endif // #ifdef PREFER_POINTERS
00576 
00577         pring_buffer_1 = qmfs->v + qmfs->v_index;
00578 #ifdef PREFER_POINTERS
00579         pring_buffer_2 = pring_buffer_1 + 192;
00580         pring_buffer_3 = pring_buffer_1 + 256;
00581         pring_buffer_4 = pring_buffer_1 + (256 + 192);
00582         pring_buffer_5 = pring_buffer_1 + 512;
00583         pring_buffer_6 = pring_buffer_1 + (512 + 192);
00584         pring_buffer_7 = pring_buffer_1 + 768;
00585         pring_buffer_8 = pring_buffer_1 + (768 + 192);
00586         pring_buffer_9 = pring_buffer_1 + 1024;
00587         pring_buffer_10 = pring_buffer_1 + (1024 + 192);
00588         pqmf_c_1 = qmf_c;
00589         pqmf_c_2 = qmf_c + 64;
00590         pqmf_c_3 = qmf_c + 128;
00591         pqmf_c_4 = qmf_c + 192;
00592         pqmf_c_5 = qmf_c + 256;
00593         pqmf_c_6 = qmf_c + 320;
00594         pqmf_c_7 = qmf_c + 384;
00595         pqmf_c_8 = qmf_c + 448;
00596         pqmf_c_9 = qmf_c + 512;
00597         pqmf_c_10 = qmf_c + 576;
00598 #endif // #ifdef PREFER_POINTERS
00599 
00600         /* calculate 64 output samples and window */
00601         for (k = 0; k < 64; k++)
00602         {
00603 #ifdef PREFER_POINTERS
00604             output[out++] =
00605                 MUL_F(*pring_buffer_1++,  *pqmf_c_1++) +
00606                 MUL_F(*pring_buffer_2++,  *pqmf_c_2++) +
00607                 MUL_F(*pring_buffer_3++,  *pqmf_c_3++) +
00608                 MUL_F(*pring_buffer_4++,  *pqmf_c_4++) +
00609                 MUL_F(*pring_buffer_5++,  *pqmf_c_5++) +
00610                 MUL_F(*pring_buffer_6++,  *pqmf_c_6++) +
00611                 MUL_F(*pring_buffer_7++,  *pqmf_c_7++) +
00612                 MUL_F(*pring_buffer_8++,  *pqmf_c_8++) +
00613                 MUL_F(*pring_buffer_9++,  *pqmf_c_9++) +
00614                 MUL_F(*pring_buffer_10++, *pqmf_c_10++);
00615 #else // #ifdef PREFER_POINTERS
00616             output[out++] =
00617                 MUL_F(pring_buffer_1[k+0],          qmf_c[k+0])   +
00618                 MUL_F(pring_buffer_1[k+192],        qmf_c[k+64])  +
00619                 MUL_F(pring_buffer_1[k+256],        qmf_c[k+128]) +
00620                 MUL_F(pring_buffer_1[k+(256+192)],  qmf_c[k+192]) +
00621                 MUL_F(pring_buffer_1[k+512],        qmf_c[k+256]) +
00622                 MUL_F(pring_buffer_1[k+(512+192)],  qmf_c[k+320]) +
00623                 MUL_F(pring_buffer_1[k+768],        qmf_c[k+384]) +
00624                 MUL_F(pring_buffer_1[k+(768+192)],  qmf_c[k+448]) +
00625                 MUL_F(pring_buffer_1[k+1024],       qmf_c[k+512]) +
00626                 MUL_F(pring_buffer_1[k+(1024+192)], qmf_c[k+576]);
00627 #endif // #ifdef PREFER_POINTERS
00628         }
00629 
00630         /* update ringbuffer index */
00631         qmfs->v_index -= 128;
00632         if (qmfs->v_index < 0)
00633             qmfs->v_index = (1280 - 128);
00634     }
00635 }
00636 #endif
00637 
00638 #endif

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