Esempio n. 1
0
/*
 * read and decode the data for the next 1024 output samples
 * return -1 if there was an error
 */
int huffdecode(faacDecHandle hDecoder, int id, MC_Info *mip, byte *win,
               Wnd_Shape *wshape,
               byte **cb_map, int **factors,
               byte **group, byte *hasmask, byte **mask, byte *max_sfb,
               int **lpflag, int **prstflag,
               NOK_LT_PRED_STATUS **nok_ltp_status,
               TNS_frame_info **tns, Float **coef)
{
    int i, tag, common_window, ch, widx, first=0, last=0;

    int global_gain;  /* not used in this routine */
    Info info;

    tag = faad_getbits(&hDecoder->ld, LEN_TAG);

    switch(id) {
    case ID_SCE:
        common_window = 0;
        break;
    case ID_CPE:
        common_window = faad_get1bit(&hDecoder->ld); /* common_window */
        break;
    default:
        /* CommonWarning("Unknown id"); */
        return(-1);
    }

    if ((ch = chn_config(hDecoder, id, tag, common_window, mip)) < 0)
        return -1;

    switch(id) {
    case ID_SCE:
        widx = mip->ch_info[ch].widx;
        first = ch;
        last = ch;
        hasmask[widx] = 0;
        break;
    case ID_CPE:
        first = ch;
        last = mip->ch_info[ch].paired_ch;
        if (common_window) {
            widx = mip->ch_info[ch].widx;
            if (!get_ics_info(hDecoder, &win[widx], &wshape[widx].this_bk, group[widx],
                &max_sfb[widx], lpflag[widx], prstflag[widx],
                nok_ltp_status[widx],nok_ltp_status[mip->ch_info[ch].paired_ch], common_window))
                return -1;

            hasmask[widx] = getmask(hDecoder, hDecoder->winmap[win[widx]], group[widx],
                max_sfb[widx], mask[widx]);
        }
        else {
            hasmask[mip->ch_info[first].widx] = 0;
            hasmask[mip->ch_info[last].widx] = 0;
        }
        break;
    }

    for (i=first; i<=last; i++) {
        widx = mip->ch_info[i].widx;
        SetMemory(coef[i], 0, LN2*sizeof(Float));

        if(!getics(hDecoder, &info, common_window, &win[widx], &wshape[widx].this_bk,
            group[widx], &max_sfb[widx], lpflag[widx], prstflag[widx],
            cb_map[i], coef[i], &global_gain, factors[i], nok_ltp_status[widx],
            tns[i]))
            return -1;
    }

    return 0;
}
/*----------------------------------------------------------------------------
; FUNCTION CODE
----------------------------------------------------------------------------*/
Int huffdecode(
    Int           id_syn_ele,
    BITS          *pInputStream,
    tDec_Int_File *pVars,
    tDec_Int_Chan *pChVars[])

{
    /*----------------------------------------------------------------------------
    ; Define all local variables
    ----------------------------------------------------------------------------*/
    Int      ch;
    Int      common_window;
    Int      hasmask;
    Int      status   = SUCCESS;
    Int      num_channels = 0;
    MC_Info  *pMcInfo;

    per_chan_share_w_fxpCoef *pChLeftShare;  /* Helper pointer */
    per_chan_share_w_fxpCoef *pChRightShare; /* Helper pointer */
    /*----------------------------------------------------------------------------
    ; Function body here
    ----------------------------------------------------------------------------*/

    get9_n_lessbits(
        LEN_TAG,
        pInputStream);

    /* suppose an un-supported id_syn_ele will never be passed */

    common_window = 0;

    if (id_syn_ele == ID_CPE)
    {
        common_window =
            get1bits(pInputStream);
    }

    pMcInfo = &pVars->mc_info;

    /*
     *  check if provided info (num of channels) on audio config,
     *  matches read bitstream data, if not, allow update only once.
     *  In almost all cases it should match.
     */
#if 0     
    if ((pMcInfo->ch_info[0].cpe != id_syn_ele))
    {
        if (pVars->mc_info.implicit_channeling)     /* check done only once */
        {
            pMcInfo->ch_info[0].cpe = id_syn_ele & 1; /*  collect info from bitstream
                                                     *  implicit_channeling flag is locked
                                                     *  after 1st frame, to avoid toggling
                                                     *  parameter in the middle of the clip
                                                     */
            pMcInfo->nch = (id_syn_ele & 1) + 1;     /* update number of channels */
        }
        else
        {
            status = 1; /* ERROR break if syntax error persist  */
        }
    }
#endif

    if (status == SUCCESS)
    {
        if (id_syn_ele == ID_SCE)
        {

            num_channels = 1;
            pVars->hasmask = 0;
        }
        else if (id_syn_ele == ID_CPE)
        {
            pChLeftShare = pChVars[LEFT]->pShareWfxpCoef;
            pChRightShare = pChVars[RIGHT]->pShareWfxpCoef;
            num_channels = 2;

            if (common_window != FALSE)
            {

                status = get_ics_info(
                             (tMP4AudioObjectType) pVars->mc_info.audioObjectType,
                             pInputStream,
                             (Bool)common_window,
                             (WINDOW_SEQUENCE *) & pChVars[LEFT]->wnd,
                             (WINDOW_SHAPE *) & pChVars[LEFT]->wnd_shape_this_bk,
                             pChLeftShare->group,
                             (Int *) & pChLeftShare->max_sfb,
                             pVars->winmap,
                             (LT_PRED_STATUS *) & pChLeftShare->lt_status,
                             (LT_PRED_STATUS *) & pChRightShare->lt_status);

                if (status == SUCCESS)
                {
                    /* copy left channel info to right channel */
                    pChVars[RIGHT]->wnd = pChVars[LEFT]->wnd;
                    pChVars[RIGHT]->wnd_shape_this_bk =
                        pChVars[LEFT]->wnd_shape_this_bk;
                    pChRightShare->max_sfb = pChLeftShare->max_sfb;
                    pv_memcpy(
                        pChRightShare->group,
                        pChLeftShare->group,
                        NSHORT*sizeof(pChLeftShare->group[0]));

                    hasmask = getmask(
                                  pVars->winmap[pChVars[LEFT]->wnd],
                                  pInputStream,
                                  pChLeftShare->group,
                                  pChLeftShare->max_sfb,
                                  pVars->mask);

                    if (hasmask == MASK_ERROR)
                    {
                        status = 1; /* ERROR code */
                    }
                    pVars->hasmask  = hasmask;

                } /* if (status == 0) */
            }
            else
            {
                pVars->hasmask  = 0;
            } /* if (common_window) */

        } /* if (id_syn_ele) */
        else if (id_syn_ele == ID_LFE)
        {
            num_channels = 1;
            pVars->hasmask = 0;
        } /* if (id_syn_ele) == ID_LFE */

    } /* if (status) */

    ch = 0;
    while ((ch < num_channels) && (status == SUCCESS))
    {
        pChLeftShare = pChVars[ch]->pShareWfxpCoef;

        status = getics(
                     pInputStream,
                     common_window,
                     pVars,
                     pChVars[ch],
                     pChLeftShare->group,
                     &pChLeftShare->max_sfb,
                     pChLeftShare->cb_map,
                     &pChLeftShare->tns,
                     pVars->winmap,
                     &pVars->share.a.pulseInfo,
                     pVars->share.a.sect);

        ch++;

    } /* while (ch) */

    /*----------------------------------------------------------------------------
    ; Return status
    ----------------------------------------------------------------------------*/

    return status;

} /* huffdecode */