Exemplo n.º 1
0
/*
 *
 * \brief Initialize one low power transposer instance
 *
 *
 */
int
createLppTransposer (HANDLE_SBR_LPP_TRANS hLppTrans,
                     unsigned char highBandStartSb,
                     unsigned char *v_k_master,
                     unsigned char numMaster,
                     unsigned char usb,
                     unsigned char nCols,
                     unsigned char* noiseBandTable,
                     unsigned char noNoiseBands,
                     unsigned short fs,
                     unsigned char  chan
                     )
{
  HANDLE_SBR_LPP_TRANS hs;

  COUNT_sub_start("createLppTransposer");

  PTR_INIT(1);
  hs = hLppTrans;

  PTR_INIT(1);
  hs->pSettings = &sbr_TransposerSettings;

  MOVE(1);
  hs->pSettings->nCols = nCols;

  PTR_INIT(2); /* pointer for sbr_LpcFilterStatesReal[chan][0],
                              sbr_LpcFilterStatesReal[chan][1] */
  MOVE(2);
  hs->lpcFilterStatesReal[0] = sbr_LpcFilterStatesReal[chan][0];
  hs->lpcFilterStatesReal[1] = sbr_LpcFilterStatesReal[chan][1];

#ifndef LP_SBR_ONLY
  PTR_INIT(2); /* pointer for sbr_LpcFilterStatesImag[chan][0],
                              sbr_LpcFilterStatesImag[chan][1] */
  MOVE(2);
  hs->lpcFilterStatesImag[0] = sbr_LpcFilterStatesImag[chan][0];
  hs->lpcFilterStatesImag[1] = sbr_LpcFilterStatesImag[chan][1];
#endif

  BRANCH(1);
  if (chan==0) {
    MOVE(1);
    hs->pSettings->nCols = nCols;

    FUNC(9);
    COUNT_sub_end();
    return resetLppTransposer (hs,
                               0,
                               highBandStartSb,
                               v_k_master,
                               numMaster,
                               noiseBandTable,
                               noNoiseBands,
                               usb,
                               fs);
  }
  COUNT_sub_end();
  return 0;
}
Exemplo n.º 2
0
/*!
  \brief     resets sbr decoder structure
  \return    errorCode, 0 if successful
*/
SBR_ERROR
resetSbrDec (HANDLE_SBR_DEC hSbrDec,
             HANDLE_SBR_HEADER_DATA hHeaderData,
             HANDLE_SBR_PREV_FRAME_DATA hPrevFrameData,
             const int useLP,
             const int downsampleFac
            )
{
    SBR_ERROR sbrError = SBRDEC_OK;

    int old_lsb = hSbrDec->SynthesisQMF.lsb;
    int new_lsb = hHeaderData->freqBandData.lowSubband;
    int l, startBand, stopBand, startSlot, size;

    int source_scale, target_scale, delta_scale, target_lsb, target_usb, reserve;
    FIXP_DBL maxVal;

    /* overlapBuffer point to first (6) slots */
    FIXP_DBL  **OverlapBufferReal = hSbrDec->QmfBufferReal;
    FIXP_DBL  **OverlapBufferImag = hSbrDec->QmfBufferImag;

    /* assign qmf time slots */
    assignTimeSlots( hSbrDec, hHeaderData->numberTimeSlots * hHeaderData->timeStep, useLP);



    resetSbrEnvelopeCalc (&hSbrDec->SbrCalculateEnvelope);

    hSbrDec->SynthesisQMF.lsb = hHeaderData->freqBandData.lowSubband;
    hSbrDec->SynthesisQMF.usb = fixMin((INT)hSbrDec->SynthesisQMF.no_channels, (INT)hHeaderData->freqBandData.highSubband);

    hSbrDec->AnalysiscQMF.lsb = hSbrDec->SynthesisQMF.lsb;
    hSbrDec->AnalysiscQMF.usb = hSbrDec->SynthesisQMF.usb;


    /*
      The following initialization of spectral data in the overlap buffer
      is required for dynamic x-over or a change of the start-freq for 2 reasons:

      1. If the lowband gets _wider_, unadjusted data would remain

      2. If the lowband becomes _smaller_, the highest bands of the old lowband
         must be cleared because the whitening would be affected
    */
    startBand = old_lsb;
    stopBand  = new_lsb;
    startSlot = hHeaderData->timeStep * (hPrevFrameData->stopPos - hHeaderData->numberTimeSlots);
    size      = fixMax(0,stopBand-startBand);

    /* keep already adjusted data in the x-over-area */
    if (!useLP) {
        for (l=startSlot; l<hSbrDec->LppTrans.pSettings->overlap; l++) {
            FDKmemclear(&OverlapBufferReal[l][startBand], size*sizeof(FIXP_DBL));
            FDKmemclear(&OverlapBufferImag[l][startBand], size*sizeof(FIXP_DBL));
        }
    } else
        for (l=startSlot; l<hSbrDec->LppTrans.pSettings->overlap ; l++) {
            FDKmemclear(&OverlapBufferReal[l][startBand], size*sizeof(FIXP_DBL));
        }


    /*
      reset LPC filter states
    */
    startBand = fixMin(old_lsb,new_lsb);
    stopBand  = fixMax(old_lsb,new_lsb);
    size      = fixMax(0,stopBand-startBand);

    FDKmemclear(&hSbrDec->LppTrans.lpcFilterStatesReal[0][startBand], size*sizeof(FIXP_DBL));
    FDKmemclear(&hSbrDec->LppTrans.lpcFilterStatesReal[1][startBand], size*sizeof(FIXP_DBL));
    if (!useLP) {
        FDKmemclear(&hSbrDec->LppTrans.lpcFilterStatesImag[0][startBand], size*sizeof(FIXP_DBL));
        FDKmemclear(&hSbrDec->LppTrans.lpcFilterStatesImag[1][startBand], size*sizeof(FIXP_DBL));
    }


    /*
      Rescale already processed spectral data between old and new x-over frequency.
      This must be done because of the separate scalefactors for lowband and highband.
    */
    startBand = fixMin(old_lsb,new_lsb);
    stopBand =  fixMax(old_lsb,new_lsb);

    if (new_lsb > old_lsb) {
        /* The x-over-area was part of the highband before and will now belong to the lowband */
        source_scale = hSbrDec->sbrScaleFactor.ov_hb_scale;
        target_scale = hSbrDec->sbrScaleFactor.ov_lb_scale;
        target_lsb   = 0;
        target_usb   = old_lsb;
    }
    else {
        /* The x-over-area was part of the lowband before and will now belong to the highband */
        source_scale = hSbrDec->sbrScaleFactor.ov_lb_scale;
        target_scale = hSbrDec->sbrScaleFactor.ov_hb_scale;
        /* jdr: The values old_lsb and old_usb might be wrong because the previous frame might have been "upsamling". */
        target_lsb   = hSbrDec->SynthesisQMF.lsb;
        target_usb   = hSbrDec->SynthesisQMF.usb;
    }

    /* Shift left all samples of the x-over-area as much as possible
       An unnecessary coarse scale could cause ov_lb_scale or ov_hb_scale to be
       adapted and the accuracy in the next frame would seriously suffer! */

    maxVal = maxSubbandSample( OverlapBufferReal,
                               (useLP) ? NULL : OverlapBufferImag,
                               startBand,
                               stopBand,
                               0,
                               startSlot);

    reserve = CntLeadingZeros(maxVal)-1;
    reserve = fixMin(reserve,DFRACT_BITS-1-source_scale);

    rescaleSubbandSamples( OverlapBufferReal,
                           (useLP) ? NULL : OverlapBufferImag,
                           startBand,
                           stopBand,
                           0,
                           startSlot,
                           reserve);
    source_scale += reserve;

    delta_scale = target_scale - source_scale;

    if (delta_scale > 0) { /* x-over-area is dominant */
        delta_scale = -delta_scale;
        startBand = target_lsb;
        stopBand = target_usb;

        if (new_lsb > old_lsb) {
            /* The lowband has to be rescaled */
            hSbrDec->sbrScaleFactor.ov_lb_scale = source_scale;
        }
        else {
            /* The highband has be be rescaled */
            hSbrDec->sbrScaleFactor.ov_hb_scale = source_scale;
        }
    }

    FDK_ASSERT(startBand <= stopBand);

    if (!useLP) {
        for (l=0; l<startSlot; l++) {
            scaleValues( OverlapBufferReal[l] + startBand, stopBand-startBand, delta_scale );
            scaleValues( OverlapBufferImag[l] + startBand, stopBand-startBand, delta_scale );
        }
    } else
        for (l=0; l<startSlot; l++) {
            scaleValues( OverlapBufferReal[l] + startBand, stopBand-startBand, delta_scale );
        }


    /*
      Initialize transposer and limiter
    */
    sbrError = resetLppTransposer (&hSbrDec->LppTrans,
                                   hHeaderData->freqBandData.lowSubband,
                                   hHeaderData->freqBandData.v_k_master,
                                   hHeaderData->freqBandData.numMaster,
                                   hHeaderData->freqBandData.freqBandTableNoise,
                                   hHeaderData->freqBandData.nNfb,
                                   hHeaderData->freqBandData.highSubband,
                                   hHeaderData->sbrProcSmplRate);
    if (sbrError != SBRDEC_OK)
        return sbrError;

    sbrError = ResetLimiterBands ( hHeaderData->freqBandData.limiterBandTable,
                                   &hHeaderData->freqBandData.noLimiterBands,
                                   hHeaderData->freqBandData.freqBandTable[0],
                                   hHeaderData->freqBandData.nSfb[0],
                                   hSbrDec->LppTrans.pSettings->patchParam,
                                   hSbrDec->LppTrans.pSettings->noOfPatches,
                                   hHeaderData->bs_data.limiterBands);


    return sbrError;
}