- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# sbr_dec.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 Mpeg4AAClicense@nero.com.
    00029 **
    00030 ** $Id: sbr_dec.c,v 1.3 2005/11/01 21:41:43 gabest Exp $
    00031 **/
    00032
    00033
    00034 #include "common.h"
    00035 #include "structs.h"
    00036
    00037 #ifdef SBR_DEC
    00038
    00039 #include <string.h>
    00040 #include <stdlib.h>
    00041
    00042 #include "syntax.h"
    00043 #include "bits.h"
    00044 #include "sbr_syntax.h"
    00045 #include "sbr_qmf.h"
    00046 #include "sbr_hfgen.h"
    00047 #include "sbr_hfadj.h"
    00048
    00049
    00050 /* static function declarations */
    00051 static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch);
    00052 static void sbr_save_matrix(sbr_info *sbr, uint8_t ch);
    00053
    00054
    00055 sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac,
    00056                         uint32_t sample_rate, uint8_t downSampledSBR
    00057 #ifdef DRM
    00058                                                 , uint8_t IsDRM
    00059 #endif
    00060                         )
    00061 {
    00062     sbr_info *sbr = faad_malloc(sizeof(sbr_info));
    00063     memset(sbr, 0, sizeof(sbr_info));
    00064
    00065     /* save id of the parent element */
    00066     sbr->id_aac = id_aac;
    00067     sbr->sample_rate = sample_rate;
    00068
    00069     sbr->bs_freq_scale = 2;
    00070     sbr->bs_alter_scale = 1;
    00071     sbr->bs_noise_bands = 2;
    00072     sbr->bs_limiter_bands = 2;
    00073     sbr->bs_limiter_gains = 2;
    00074     sbr->bs_interpol_freq = 1;
    00075     sbr->bs_smoothing_mode = 1;
    00076     sbr->bs_start_freq = 5;
    00077     sbr->bs_amp_res = 1;
    00078     sbr->bs_samplerate_mode = 1;
    00079     sbr->prevEnvIsShort[0] = -1;
    00080     sbr->prevEnvIsShort[1] = -1;
    00081     sbr->header_count = 0;
    00082     sbr->Reset = 1;
    00083
    00084 #ifdef DRM
    00085     sbr->Is_DRM_SBR = IsDRM;
    00086 #endif
    00087     sbr->tHFGen = T_HFGEN;
    00088     sbr->tHFAdj = T_HFADJ;
    00089
    00090     sbr->bsco = 0;
    00091     sbr->bsco_prev = 0;
    00092     sbr->M_prev = 0;
    00093     sbr->frame_len = framelength;
    00094
    00095     /* force sbr reset */
    00096     sbr->bs_start_freq_prev = -1;
    00097
    00098     if (framelength == 960)
    00099     {
    00100         sbr->numTimeSlotsRate = RATE * NO_TIME_SLOTS_960;
    00101         sbr->numTimeSlots = NO_TIME_SLOTS_960;
    00102     } else {
    00103         sbr->numTimeSlotsRate = RATE * NO_TIME_SLOTS;
    00104         sbr->numTimeSlots = NO_TIME_SLOTS;
    00105     }
    00106
    00107     sbr->GQ_ringbuf_index[0] = 0;
    00108     sbr->GQ_ringbuf_index[1] = 0;
    00109
    00110     if (id_aac == ID_CPE)
    00111     {
    00112         /* stereo */
    00113         uint8_t j;
    00114         sbr->qmfa[0] = qmfa_init(32);
    00115         sbr->qmfa[1] = qmfa_init(32);
    00116         sbr->qmfs[0] = qmfs_init((downSampledSBR)?32:64);
    00117         sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64);
    00118
    00119         for (j = 0; j < 5; j++)
    00120         {
    00121             sbr->G_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
    00122             sbr->G_temp_prev[1][j] = faad_malloc(64*sizeof(real_t));
    00123             sbr->Q_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
    00124             sbr->Q_temp_prev[1][j] = faad_malloc(64*sizeof(real_t));
    00125         }
    00126
    00127         memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
    00128         memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
    00129     } else {
    00130         /* mono */
    00131         uint8_t j;
    00132         sbr->qmfa[0] = qmfa_init(32);
    00133         sbr->qmfs[0] = qmfs_init((downSampledSBR)?32:64);
    00134         sbr->qmfs[1] = NULL;
    00135
    00136         for (j = 0; j < 5; j++)
    00137         {
    00138             sbr->G_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
    00139             sbr->Q_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
    00140         }
    00141
    00142         memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
    00143     }
    00144
    00145     return sbr;
    00146 }
    00147
    00148 void sbrDecodeEnd(sbr_info *sbr)
    00149 {
    00150     uint8_t j;
    00151
    00152     if (sbr)
    00153     {
    00154         qmfa_end(sbr->qmfa[0]);
    00155         qmfs_end(sbr->qmfs[0]);
    00156         if (sbr->qmfs[1] != NULL)
    00157         {
    00158             qmfa_end(sbr->qmfa[1]);
    00159             qmfs_end(sbr->qmfs[1]);
    00160         }
    00161
    00162         for (j = 0; j < 5; j++)
    00163         {
    00164             if (sbr->G_temp_prev[0][j]) faad_free(sbr->G_temp_prev[0][j]);
    00165             if (sbr->Q_temp_prev[0][j]) faad_free(sbr->Q_temp_prev[0][j]);
    00166             if (sbr->G_temp_prev[1][j]) faad_free(sbr->G_temp_prev[1][j]);
    00167             if (sbr->Q_temp_prev[1][j]) faad_free(sbr->Q_temp_prev[1][j]);
    00168         }
    00169
    00170 #ifdef PS_DEC
    00171         if (sbr->ps != NULL)
    00172             ps_free(sbr->ps);
    00173 #endif
    00174
    00175 #ifdef DRM_PS
    00176         if (sbr->drm_ps != NULL)
    00177             drm_ps_free(sbr->drm_ps);
    00178 #endif
    00179
    00180         faad_free(sbr);
    00181     }
    00182 }
    00183
    00184 void sbrReset(sbr_info *sbr)
    00185 {
    00186     uint8_t j;
    00187     if (sbr->qmfa[0] != NULL)
    00188         memset(sbr->qmfa[0]->x, 0, 2 * sbr->qmfa[0]->channels * 10 * sizeof(real_t));
    00189     if (sbr->qmfa[1] != NULL)
    00190         memset(sbr->qmfa[1]->x, 0, 2 * sbr->qmfa[1]->channels * 10 * sizeof(real_t));
    00191     if (sbr->qmfs[0] != NULL)
    00192         memset(sbr->qmfs[0]->v, 0, 2 * sbr->qmfs[0]->channels * 20 * sizeof(real_t));
    00193     if (sbr->qmfs[1] != NULL)
    00194         memset(sbr->qmfs[1]->v, 0, 2 * sbr->qmfs[1]->channels * 20 * sizeof(real_t));
    00195
    00196     for (j = 0; j < 5; j++)
    00197     {
    00198         if (sbr->G_temp_prev[0][j] != NULL)
    00199             memset(sbr->G_temp_prev[0][j], 0, 64*sizeof(real_t));
    00200         if (sbr->G_temp_prev[1][j] != NULL)
    00201             memset(sbr->G_temp_prev[1][j], 0, 64*sizeof(real_t));
    00202         if (sbr->Q_temp_prev[0][j] != NULL)
    00203             memset(sbr->Q_temp_prev[0][j], 0, 64*sizeof(real_t));
    00204         if (sbr->Q_temp_prev[1][j] != NULL)
    00205             memset(sbr->Q_temp_prev[1][j], 0, 64*sizeof(real_t));
    00206     }
    00207
    00208     memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
    00209     memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
    00210
    00211     sbr->GQ_ringbuf_index[0] = 0;
    00212     sbr->GQ_ringbuf_index[1] = 0;
    00213     sbr->header_count = 0;
    00214     sbr->Reset = 1;
    00215
    00216     sbr->L_E_prev[0] = 0;
    00217     sbr->L_E_prev[1] = 0;
    00218     sbr->bs_freq_scale = 2;
    00219     sbr->bs_alter_scale = 1;
    00220     sbr->bs_noise_bands = 2;
    00221     sbr->bs_limiter_bands = 2;
    00222     sbr->bs_limiter_gains = 2;
    00223     sbr->bs_interpol_freq = 1;
    00224     sbr->bs_smoothing_mode = 1;
    00225     sbr->bs_start_freq = 5;
    00226     sbr->bs_amp_res = 1;
    00227     sbr->bs_samplerate_mode = 1;
    00228     sbr->prevEnvIsShort[0] = -1;
    00229     sbr->prevEnvIsShort[1] = -1;
    00230     sbr->bsco = 0;
    00231     sbr->bsco_prev = 0;
    00232     sbr->M_prev = 0;
    00233     sbr->bs_start_freq_prev = -1;
    00234
    00235     sbr->f_prev[0] = 0;
    00236     sbr->f_prev[1] = 0;
    00237     for (j = 0; j < MAX_M; j++)
    00238     {
    00239         sbr->E_prev[0][j] = 0;
    00240         sbr->Q_prev[0][j] = 0;
    00241         sbr->E_prev[1][j] = 0;
    00242         sbr->Q_prev[1][j] = 0;
    00243         sbr->bs_add_harmonic_prev[0][j] = 0;
    00244         sbr->bs_add_harmonic_prev[1][j] = 0;
    00245     }
    00246     sbr->bs_add_harmonic_flag_prev[0] = 0;
    00247     sbr->bs_add_harmonic_flag_prev[1] = 0;
    00248 }
    00249
    00250 static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch)
    00251 {
    00252     uint8_t i;
    00253
    00254     /* save data for next frame */
    00255     sbr->kx_prev = sbr->kx;
    00256     sbr->M_prev = sbr->M;
    00257     sbr->bsco_prev = sbr->bsco;
    00258
    00259     sbr->L_E_prev[ch] = sbr->L_E[ch];
    00260
    00261     /* sbr->L_E[ch] can become 0 on files with bit errors */
    00262     if (sbr->L_E[ch] <= 0)
    00263         return 19;
    00264
    00265     sbr->f_prev[ch] = sbr->f[ch][sbr->L_E[ch] - 1];
    00266     for (i = 0; i < MAX_M; i++)
    00267     {
    00268         sbr->E_prev[ch][i] = sbr->E[ch][i][sbr->L_E[ch] - 1];
    00269         sbr->Q_prev[ch][i] = sbr->Q[ch][i][sbr->L_Q[ch] - 1];
    00270     }
    00271
    00272     for (i = 0; i < MAX_M; i++)
    00273     {
    00274         sbr->bs_add_harmonic_prev[ch][i] = sbr->bs_add_harmonic[ch][i];
    00275     }
    00276     sbr->bs_add_harmonic_flag_prev[ch] = sbr->bs_add_harmonic_flag[ch];
    00277
    00278     if (sbr->l_A[ch] == sbr->L_E[ch])
    00279         sbr->prevEnvIsShort[ch] = 0;
    00280     else
    00281         sbr->prevEnvIsShort[ch] = -1;
    00282
    00283     return 0;
    00284 }
    00285
    00286 static void sbr_save_matrix(sbr_info *sbr, uint8_t ch)
    00287 {
    00288     uint8_t i;
    00289
    00290     for (i = 0; i < sbr->tHFGen; i++)
    00291     {
    00292         memmove(sbr->Xsbr[ch][i], sbr->Xsbr[ch][i+sbr->numTimeSlotsRate], 64 * sizeof(qmf_t));
    00293     }
    00294     for (i = sbr->tHFGen; i < MAX_NTSRHFG; i++)
    00295     {
    00296         memset(sbr->Xsbr[ch][i], 0, 64 * sizeof(qmf_t));
    00297     }
    00298 }
    00299
    00300 static uint8_t sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_NTSR][64],
    00301                                    uint8_t ch, uint8_t dont_process,
    00302                                    const uint8_t downSampledSBR)
    00303 {
    00304     int16_t k, l;
    00305     uint8_t ret = 0;
    00306
    00307 #ifdef SBR_LOW_POWER
    00308     ALIGN real_t deg[64];
    00309 #endif
    00310
    00311 #ifdef DRM
    00312     if (sbr->Is_DRM_SBR)
    00313     {
    00314         sbr->bsco = max((int32_t)sbr->maxAACLine*32/(int32_t)sbr->frame_len - (int32_t)sbr->kx, 0);
    00315     } else {
    00316 #endif
    00317         sbr->bsco = 0;
    00318 #ifdef DRM
    00319     }
    00320 #endif
    00321
    00322
    00323 //#define PRE_QMF_PRINT
    00324 #ifdef PRE_QMF_PRINT
    00325     {
    00326         int i;
    00327         for (i = 0; i < 1024; i++)
    00328         {
    00329             printf("%d\n", channel_buf[i]);
    00330         }
    00331     }
    00332 #endif
    00333
    00334
    00335     /* subband analysis */
    00336     if (dont_process)
    00337         sbr_qmf_analysis_32(sbr, sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, 32);
    00338     else
    00339         sbr_qmf_analysis_32(sbr, sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, sbr->kx);
    00340
    00341     if (!dont_process)
    00342     {
    00343 #if 1
    00344         /* insert high frequencies here */
    00345         /* hf generation using patching */
    00346         hf_generation(sbr, sbr->Xsbr[ch], sbr->Xsbr[ch]
    00347 #ifdef SBR_LOW_POWER
    00348             ,deg
    00349 #endif
    00350             ,ch);
    00351 #endif
    00352
    00353 #if 0 //def SBR_LOW_POWER
    00354         for (l = sbr->t_E[ch][0]; l < sbr->t_E[ch][sbr->L_E[ch]]; l++)
    00355         {
    00356             for (k = 0; k < sbr->kx; k++)
    00357             {
    00358                 QMF_RE(sbr->Xsbr[ch][sbr->tHFAdj + l][k]) = 0;
    00359             }
    00360         }
    00361 #endif
    00362
    00363 #if 1
    00364         /* hf adjustment */
    00365         ret = hf_adjustment(sbr, sbr->Xsbr[ch]
    00366 #ifdef SBR_LOW_POWER
    00367             ,deg
    00368 #endif
    00369             ,ch);
    00370 #endif
    00371         if (ret > 0)
    00372         {
    00373             dont_process = 1;
    00374         }
    00375     }
    00376
    00377     if ((sbr->just_seeked != 0) || dont_process)
    00378     {
    00379         for (l = 0; l < sbr->numTimeSlotsRate; l++)
    00380         {
    00381             for (k = 0; k < 32; k++)
    00382             {
    00383                 QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
    00384 #ifndef SBR_LOW_POWER
    00385                 QMF_IM(X[l][k]) = QMF_IM(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
    00386 #endif
    00387             }
    00388             for (k = 32; k < 64; k++)
    00389             {
    00390                 QMF_RE(X[l][k]) = 0;
    00391 #ifndef SBR_LOW_POWER
    00392                 QMF_IM(X[l][k]) = 0;
    00393 #endif
    00394             }
    00395         }
    00396     } else {
    00397         for (l = 0; l < sbr->numTimeSlotsRate; l++)
    00398         {
    00399             uint8_t kx_band, M_band, bsco_band;
    00400
    00401             if (l < sbr->t_E[ch][0])
    00402             {
    00403                 kx_band = sbr->kx_prev;
    00404                 M_band = sbr->M_prev;
    00405                 bsco_band = sbr->bsco_prev;
    00406             } else {
    00407                 kx_band = sbr->kx;
    00408                 M_band = sbr->M;
    00409                 bsco_band = sbr->bsco;
    00410             }
    00411
    00412 #ifndef SBR_LOW_POWER
    00413             for (k = 0; k < kx_band + bsco_band; k++)
    00414             {
    00415                 QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
    00416                 QMF_IM(X[l][k]) = QMF_IM(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
    00417             }
    00418             for (k = kx_band + bsco_band; k < kx_band + M_band; k++)
    00419             {
    00420                 QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
    00421                 QMF_IM(X[l][k]) = QMF_IM(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
    00422             }
    00423             for (k = max(kx_band + bsco_band, kx_band + M_band); k < 64; k++)
    00424             {
    00425                 QMF_RE(X[l][k]) = 0;
    00426                 QMF_IM(X[l][k]) = 0;
    00427             }
    00428 #else
    00429             for (k = 0; k < kx_band + bsco_band; k++)
    00430             {
    00431                 QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
    00432             }
    00433             for (k = kx_band + bsco_band; k < min(kx_band + M_band, 63); k++)
    00434             {
    00435                 QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
    00436             }
    00437             for (k = max(kx_band + bsco_band, kx_band + M_band); k < 64; k++)
    00438             {
    00439                 QMF_RE(X[l][k]) = 0;
    00440             }
    00441             QMF_RE(X[l][kx_band - 1 + bsco_band]) +=
    00442                 QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][kx_band - 1 + bsco_band]);
    00443 #endif
    00444         }
    00445     }
    00446
    00447     return ret;
    00448 }
    00449
    00450 uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
    00451                              const uint8_t just_seeked, const uint8_t downSampledSBR)
    00452 {
    00453     uint8_t dont_process = 0;
    00454     uint8_t ret = 0;
    00455     ALIGN qmf_t X[MAX_NTSR][64];
    00456
    00457     if (sbr == NULL)
    00458         return 20;
    00459
    00460     /* case can occur due to bit errors */
    00461     if (sbr->id_aac != ID_CPE)
    00462         return 21;
    00463
    00464     if (sbr->ret || (sbr->header_count == 0))
    00465     {
    00466         /* don't process just upsample */
    00467         dont_process = 1;
    00468
    00469         /* Re-activate reset for next frame */
    00470         if (sbr->ret && sbr->Reset)
    00471             sbr->bs_start_freq_prev = -1;
    00472     }
    00473
    00474     if (just_seeked)
    00475     {
    00476         sbr->just_seeked = 1;
    00477     } else {
    00478         sbr->just_seeked = 0;
    00479     }
    00480
    00481     sbr->ret += sbr_process_channel(sbr, left_chan, X, 0, dont_process, downSampledSBR);
    00482     /* subband synthesis */
    00483     if (downSampledSBR)
    00484     {
    00485         sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X, left_chan);
    00486     } else {
    00487         sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X, left_chan);
    00488     }
    00489
    00490     sbr->ret += sbr_process_channel(sbr, right_chan, X, 1, dont_process, downSampledSBR);
    00491     /* subband synthesis */
    00492     if (downSampledSBR)
    00493     {
    00494         sbr_qmf_synthesis_32(sbr, sbr->qmfs[1], X, right_chan);
    00495     } else {
    00496         sbr_qmf_synthesis_64(sbr, sbr->qmfs[1], X, right_chan);
    00497     }
    00498
    00499     if (sbr->bs_header_flag)
    00500         sbr->just_seeked = 0;
    00501
    00502     if (sbr->header_count != 0 && sbr->ret == 0)
    00503     {
    00504         ret = sbr_save_prev_data(sbr, 0);
    00505         if (ret) return ret;
    00506         ret = sbr_save_prev_data(sbr, 1);
    00507         if (ret) return ret;
    00508     }
    00509
    00510     sbr_save_matrix(sbr, 0);
    00511     sbr_save_matrix(sbr, 1);
    00512
    00513     sbr->frame++;
    00514
    00515 //#define POST_QMF_PRINT
    00516 #ifdef POST_QMF_PRINT
    00517     {
    00518         int i;
    00519         for (i = 0; i < 2048; i++)
    00520         {
    00521             printf("%d\n", left_chan[i]);
    00522         }
    00523         for (i = 0; i < 2048; i++)
    00524         {
    00525             printf("%d\n", right_chan[i]);
    00526         }
    00527     }
    00528 #endif
    00529
    00530     return 0;
    00531 }
    00532
    00533 uint8_t sbrDecodeSingleFrame(sbr_info *sbr, real_t *channel,
    00534                              const uint8_t just_seeked, const uint8_t downSampledSBR)
    00535 {
    00536     uint8_t dont_process = 0;
    00537     uint8_t ret = 0;
    00538     ALIGN qmf_t X[MAX_NTSR][64];
    00539
    00540     if (sbr == NULL)
    00541         return 20;
    00542
    00543     /* case can occur due to bit errors */
    00544     if (sbr->id_aac != ID_SCE && sbr->id_aac != ID_LFE)
    00545         return 21;
    00546
    00547     if (sbr->ret || (sbr->header_count == 0))
    00548     {
    00549         /* don't process just upsample */
    00550         dont_process = 1;
    00551
    00552         /* Re-activate reset for next frame */
    00553         if (sbr->ret && sbr->Reset)
    00554             sbr->bs_start_freq_prev = -1;
    00555     }
    00556
    00557     if (just_seeked)
    00558     {
    00559         sbr->just_seeked = 1;
    00560     } else {
    00561         sbr->just_seeked = 0;
    00562     }
    00563
    00564     sbr->ret += sbr_process_channel(sbr, channel, X, 0, dont_process, downSampledSBR);
    00565     /* subband synthesis */
    00566     if (downSampledSBR)
    00567     {
    00568         sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X, channel);
    00569     } else {
    00570         sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X, channel);
    00571     }
    00572
    00573     if (sbr->bs_header_flag)
    00574         sbr->just_seeked = 0;
    00575
    00576     if (sbr->header_count != 0 && sbr->ret == 0)
    00577     {
    00578         ret = sbr_save_prev_data(sbr, 0);
    00579         if (ret) return ret;
    00580     }
    00581
    00582     sbr_save_matrix(sbr, 0);
    00583
    00584     sbr->frame++;
    00585
    00586 //#define POST_QMF_PRINT
    00587 #ifdef POST_QMF_PRINT
    00588     {
    00589         int i;
    00590         for (i = 0; i < 2048; i++)
    00591         {
    00592             printf("%d\n", channel[i]);
    00593         }
    00594     }
    00595 #endif
    00596
    00597     return 0;
    00598 }
    00599
    00600 #if (defined(PS_DEC) || defined(DRM_PS))
    00601 uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *right_channel,
    00602                                const uint8_t just_seeked, const uint8_t downSampledSBR)
    00603 {
    00604     uint8_t l, k;
    00605     uint8_t dont_process = 0;
    00606     uint8_t ret = 0;
    00607     ALIGN qmf_t X_left[38][64] = {{0}};
    00608     ALIGN qmf_t X_right[38][64] = {{0}}; /* must set this to 0 */
    00609
    00610     if (sbr == NULL)
    00611         return 20;
    00612
    00613     /* case can occur due to bit errors */
    00614     if (sbr->id_aac != ID_SCE && sbr->id_aac != ID_LFE)
    00615         return 21;
    00616
    00617     if (sbr->ret || (sbr->header_count == 0))
    00618     {
    00619         /* don't process just upsample */
    00620         dont_process = 1;
    00621
    00622         /* Re-activate reset for next frame */
    00623         if (sbr->ret && sbr->Reset)
    00624             sbr->bs_start_freq_prev = -1;
    00625     }
    00626
    00627     if (just_seeked)
    00628     {
    00629         sbr->just_seeked = 1;
    00630     } else {
    00631         sbr->just_seeked = 0;
    00632     }
    00633
    00634     if (sbr->qmfs[1] == NULL)
    00635     {
    00636         sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64);
    00637     }
    00638
    00639     sbr->ret += sbr_process_channel(sbr, left_channel, X_left, 0, dont_process, downSampledSBR);
    00640
    00641     /* copy some extra data for PS */
    00642     for (l = 32; l < 38; l++)
    00643     {
    00644         for (k = 0; k < 5; k++)
    00645         {
    00646             QMF_RE(X_left[l][k]) = QMF_RE(sbr->Xsbr[0][sbr->tHFAdj+l][k]);
    00647             QMF_IM(X_left[l][k]) = QMF_IM(sbr->Xsbr[0][sbr->tHFAdj+l][k]);
    00648         }
    00649     }
    00650
    00651     /* perform parametric stereo */
    00652 #ifdef DRM_PS
    00653     if (sbr->Is_DRM_SBR)
    00654     {
    00655         drm_ps_decode(sbr->drm_ps, (sbr->ret > 0), X_left, X_right);
    00656     } else {
    00657 #endif
    00658 #ifdef PS_DEC
    00659         ps_decode(sbr->ps, X_left, X_right);
    00660 #endif
    00661 #ifdef DRM_PS
    00662     }
    00663 #endif
    00664
    00665     /* subband synthesis */
    00666     if (downSampledSBR)
    00667     {
    00668         sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X_left, left_channel);
    00669         sbr_qmf_synthesis_32(sbr, sbr->qmfs[1], X_right, right_channel);
    00670     } else {
    00671         sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X_left, left_channel);
    00672         sbr_qmf_synthesis_64(sbr, sbr->qmfs[1], X_right, right_channel);
    00673     }
    00674
    00675     if (sbr->bs_header_flag)
    00676         sbr->just_seeked = 0;
    00677
    00678     if (sbr->header_count != 0 && sbr->ret == 0)
    00679     {
    00680         ret = sbr_save_prev_data(sbr, 0);
    00681         if (ret) return ret;
    00682     }
    00683
    00684     sbr_save_matrix(sbr, 0);
    00685
    00686     sbr->frame++;
    00687
    00688     return 0;
    00689 }
    00690 #endif
    00691
    00692 #endif