specificTo.mpeg.pAaRealDelayBufferQmf[k], FIRST_DELAY_SB*sizeof(FIXP_DBL));
}
length = (usb-FIRST_DELAY_SB)*sizeof(FIXP_DBL);
if(length>0) {
FDKmemclear(h_ps_d->specificTo.mpeg.pAaRealDelayBufferQmf[0], length);
FDKmemclear(h_ps_d->specificTo.mpeg.pAaImagDelayBufferQmf[0], length);
}
length = (fixMin(NO_DELAY_BUFFER_BANDS,(INT)usb)-FIRST_DELAY_SB)*sizeof(FIXP_DBL);
if(length>0) {
for (k=1 ; k < h_ps_d->specificTo.mpeg.noSampleDelay; k++) {
FDKmemclear(h_ps_d->specificTo.mpeg.pAaRealDelayBufferQmf[k], length);
FDKmemclear(h_ps_d->specificTo.mpeg.pAaImagDelayBufferQmf[k], length);
}
}
}
h_ps_d->specificTo.mpeg.lastUsb = usb;
} /* env == 0 */
if (h_ps_d->bsData[h_ps_d->processSlot].mpeg.bFineIidQ)
{
PScaleFactors = ScaleFactorsFine; /* values are shiftet right by one */
noIidSteps = NO_IID_STEPS_FINE;
/*pQuantizedIIDs = quantizedIIDsFine;*/
}
else
{
PScaleFactors = ScaleFactors; /* values are shiftet right by one */
noIidSteps = NO_IID_STEPS;
/*pQuantizedIIDs = quantizedIIDs;*/
}
/* dequantize and decode */
for ( group = 0; group < NO_IID_GROUPS; group++ ) {
bin = bins2groupMap20[group];
/*!
type 'A' rotation
mixing procedure R_a, used in baseline version
Scale-factor vectors c1 and c2 are precalculated in initPsTables () and stored in
scaleFactors[] and scaleFactorsFine[] = pScaleFactors [].
From the linearized IID parameters (intensity differences), two scale factors are
calculated. They are used to obtain the coefficients h11... h22.
*/
/* ScaleR and ScaleL are scaled by 1 shift right */
ScaleR = PScaleFactors[noIidSteps + h_ps_d->specificTo.mpeg.coef.aaIidIndexMapped[env][bin]];
ScaleL = PScaleFactors[noIidSteps - h_ps_d->specificTo.mpeg.coef.aaIidIndexMapped[env][bin]];
Beta = fMult (fMult( Alphas[h_ps_d->specificTo.mpeg.coef.aaIccIndexMapped[env][bin]], ( ScaleR - ScaleL )), FIXP_SQRT05);
Alpha = Alphas[h_ps_d->specificTo.mpeg.coef.aaIccIndexMapped[env][bin]]>>1;
/* Alpha and Beta are now both scaled by 2 shifts right */
/* calculate the coefficients h11... h22 from scale-factors and ICC parameters */
/* h values are scaled by 1 shift right */
{
FIXP_DBL trigData[4];
inline_fixp_cos_sin(Beta + Alpha, Beta - Alpha, 2, trigData);
h11r = fMult( ScaleL, trigData[0]);
h12r = fMult( ScaleR, trigData[2]);
h21r = fMult( ScaleL, trigData[1]);
h22r = fMult( ScaleR, trigData[3]);
}
/*****************************************************************************************/
/* Interpolation of the matrices H11... H22: */
/* */
/* H11(k,n) = H11(k,n[e]) + (n-n[e]) * (H11(k,n[e+1] - H11(k,n[e])) / (n[e+1] - n[e]) */
/* ... */
/*****************************************************************************************/
/* invL = 1/(length of envelope) */
invL = FX_DBL2FX_SGL(GetInvInt(h_ps_d->bsData[h_ps_d->processSlot].mpeg.aEnvStartStop[env + 1] - h_ps_d->bsData[h_ps_d->processSlot].mpeg.aEnvStartStop[env]));
h_ps_d->specificTo.mpeg.coef.H11r[group] = h_ps_d->specificTo.mpeg.h11rPrev[group];
h_ps_d->specificTo.mpeg.coef.H12r[group] = h_ps_d->specificTo.mpeg.h12rPrev[group];
h_ps_d->specificTo.mpeg.coef.H21r[group] = h_ps_d->specificTo.mpeg.h21rPrev[group];
h_ps_d->specificTo.mpeg.coef.H22r[group] = h_ps_d->specificTo.mpeg.h22rPrev[group];
h_ps_d->specificTo.mpeg.coef.DeltaH11r[group] = fMult ( h11r - h_ps_d->specificTo.mpeg.coef.H11r[group], invL );
h_ps_d->specificTo.mpeg.coef.DeltaH12r[group] = fMult ( h12r - h_ps_d->specificTo.mpeg.coef.H12r[group], invL );
h_ps_d->specificTo.mpeg.coef.DeltaH21r[group] = fMult ( h21r - h_ps_d->specificTo.mpeg.coef.H21r[group], invL );
h_ps_d->specificTo.mpeg.coef.DeltaH22r[group] = fMult ( h22r - h_ps_d->specificTo.mpeg.coef.H22r[group], invL );
/* update prev coefficients for interpolation in next envelope */
h_ps_d->specificTo.mpeg.h11rPrev[group] = h11r;
h_ps_d->specificTo.mpeg.h12rPrev[group] = h12r;
h_ps_d->specificTo.mpeg.h21rPrev[group] = h21r;
h_ps_d->specificTo.mpeg.h22rPrev[group] = h22r;
} /* group loop */
}
static void applySlotBasedRotation( HANDLE_PS_DEC h_ps_d, /*!< pointer to the module state */
FIXP_DBL *mHybridRealLeft, /*!< hybrid values real left */
FIXP_DBL *mHybridImagLeft, /*!< hybrid values imag left */
FIXP_DBL *QmfLeftReal, /*!< real bands left qmf channel */
FIXP_DBL *QmfLeftImag, /*!< imag bands left qmf channel */
FIXP_DBL *mHybridRealRight, /*!< hybrid values real right */
FIXP_DBL *mHybridImagRight, /*!< hybrid values imag right */
FIXP_DBL *QmfRightReal, /*!< real bands right qmf channel */
FIXP_DBL *QmfRightImag /*!< imag bands right qmf channel */
)
{
INT group;
INT subband;
FIXP_DBL *RESTRICT HybrLeftReal;
FIXP_DBL *RESTRICT HybrLeftImag;
FIXP_DBL *RESTRICT HybrRightReal;
FIXP_DBL *RESTRICT HybrRightImag;
FIXP_DBL tmpLeft, tmpRight;
/**********************************************************************************************/
/*!
Mapping
The number of stereo bands that is actually used depends on the number of availble
parameters for IID and ICC:
nr. of IID para.| nr. of ICC para. | nr. of Stereo bands
----------------|------------------|-------------------
10,20 | 10,20 | 20
10,20 | 34 | 34
34 | 10,20 | 34
34 | 34 | 34
In the case the number of parameters for IIS and ICC differs from the number of stereo
bands, a mapping from the lower number to the higher number of parameters is applied.
Index mapping of IID and ICC parameters is already done in psbitdec.cpp. Further mapping is
not needed here in baseline version.
**********************************************************************************************/
/************************************************************************************************/
/*!
Mixing
To generate the QMF subband signals for the subband samples n = n[e]+1 ,,, n_[e+1] the
parameters at position n[e] and n[e+1] are required as well as the subband domain signals
s_k(n) and d_k(n) for n = n[e]+1... n_[e+1]. n[e] represents the start position for
envelope e. The border positions n[e] are handled in DecodePS().
The stereo sub subband signals are constructed as:
l_k(n) = H11(k,n) s_k(n) + H21(k,n) d_k(n)
r_k(n) = H21(k,n) s_k(n) + H22(k,n) d_k(n)
In order to obtain the matrices H11(k,n)... H22 (k,n), the vectors h11(b)... h22(b) need to
be calculated first (b: parameter index). Depending on ICC mode either mixing procedure R_a
or R_b is used for that. For both procedures, the parameters for parameter position n[e+1]
is used.
************************************************************************************************/
/************************************************************************************************/
/*!
Phase parameters
With disabled phase parameters (which is the case in baseline version), the H-matrices are
just calculated by:
H11(k,n[e+1] = h11(b(k))
(...)
b(k): parameter index according to mapping table
Processing of the samples in the sub subbands
this loop includes the interpolation of the coefficients Hxx
************************************************************************************************/
/* loop thru all groups ... */
HybrLeftReal = mHybridRealLeft;
HybrLeftImag = mHybridImagLeft;
HybrRightReal = mHybridRealRight;
HybrRightImag = mHybridImagRight;
/******************************************************/
/* construct stereo sub subband signals according to: */
/* */
/* l_k(n) = H11(k,n) s_k(n) + H21(k,n) d_k(n) */
/* r_k(n) = H12(k,n) s_k(n) + H22(k,n) d_k(n) */
/******************************************************/
for ( group = 0; group < SUBQMF_GROUPS; group++ ) {
h_ps_d->specificTo.mpeg.coef.H11r[group] += h_ps_d->specificTo.mpeg.coef.DeltaH11r[group];
h_ps_d->specificTo.mpeg.coef.H12r[group] += h_ps_d->specificTo.mpeg.coef.DeltaH12r[group];
h_ps_d->specificTo.mpeg.coef.H21r[group] += h_ps_d->specificTo.mpeg.coef.DeltaH21r[group];
h_ps_d->specificTo.mpeg.coef.H22r[group] += h_ps_d->specificTo.mpeg.coef.DeltaH22r[group];
subband = groupBorders20[group];
tmpLeft = fMultAddDiv2( fMultDiv2(h_ps_d->specificTo.mpeg.coef.H11r[group], HybrLeftReal[subband]), h_ps_d->specificTo.mpeg.coef.H21r[group], HybrRightReal[subband]);
tmpRight = fMultAddDiv2( fMultDiv2(h_ps_d->specificTo.mpeg.coef.H12r[group], HybrLeftReal[subband]), h_ps_d->specificTo.mpeg.coef.H22r[group], HybrRightReal[subband]);
HybrLeftReal [subband] = tmpLeft<<1;
HybrRightReal[subband] = tmpRight<<1;
tmpLeft = fMultAdd( fMultDiv2(h_ps_d->specificTo.mpeg.coef.H11r[group], HybrLeftImag[subband]), h_ps_d->specificTo.mpeg.coef.H21r[group], HybrRightImag[subband]);
tmpRight = fMultAdd( fMultDiv2(h_ps_d->specificTo.mpeg.coef.H12r[group], HybrLeftImag[subband]), h_ps_d->specificTo.mpeg.coef.H22r[group], HybrRightImag[subband]);
HybrLeftImag [subband] = tmpLeft;
HybrRightImag[subband] = tmpRight;
}
/* continue in the qmf buffers */
HybrLeftReal = QmfLeftReal;
HybrLeftImag = QmfLeftImag;
HybrRightReal = QmfRightReal;
HybrRightImag = QmfRightImag;
for (; group < NO_IID_GROUPS; group++ ) {
h_ps_d->specificTo.mpeg.coef.H11r[group] += h_ps_d->specificTo.mpeg.coef.DeltaH11r[group];
h_ps_d->specificTo.mpeg.coef.H12r[group] += h_ps_d->specificTo.mpeg.coef.DeltaH12r[group];
h_ps_d->specificTo.mpeg.coef.H21r[group] += h_ps_d->specificTo.mpeg.coef.DeltaH21r[group];
h_ps_d->specificTo.mpeg.coef.H22r[group] += h_ps_d->specificTo.mpeg.coef.DeltaH22r[group];
for ( subband = groupBorders20[group]; subband < groupBorders20[group + 1]; subband++ )
{
tmpLeft = fMultAdd( fMultDiv2(h_ps_d->specificTo.mpeg.coef.H11r[group], HybrLeftReal[subband]), h_ps_d->specificTo.mpeg.coef.H21r[group], HybrRightReal[subband]);
tmpRight = fMultAdd( fMultDiv2(h_ps_d->specificTo.mpeg.coef.H12r[group], HybrLeftReal[subband]), h_ps_d->specificTo.mpeg.coef.H22r[group], HybrRightReal[subband]);
HybrLeftReal [subband] = tmpLeft;
HybrRightReal[subband] = tmpRight;
tmpLeft = fMultAdd( fMultDiv2(h_ps_d->specificTo.mpeg.coef.H11r[group], HybrLeftImag[subband]), h_ps_d->specificTo.mpeg.coef.H21r[group], HybrRightImag[subband]);
tmpRight = fMultAdd( fMultDiv2(h_ps_d->specificTo.mpeg.coef.H12r[group], HybrLeftImag[subband]), h_ps_d->specificTo.mpeg.coef.H22r[group], HybrRightImag[subband]);
HybrLeftImag [subband] = tmpLeft;
HybrRightImag[subband] = tmpRight;
} /* subband */
}
}
/***************************************************************************/
/*!
\brief Applies IID, ICC, IPD and OPD parameters to the current frame.
\return none
****************************************************************************/
void
ApplyPsSlot( HANDLE_PS_DEC h_ps_d, /*!< handle PS_DEC*/
FIXP_DBL **rIntBufferLeft, /*!< real bands left qmf channel (38x64) */
FIXP_DBL **iIntBufferLeft, /*!< imag bands left qmf channel (38x64) */
FIXP_DBL *rIntBufferRight, /*!< real bands right qmf channel (38x64) */
FIXP_DBL *iIntBufferRight /*!< imag bands right qmf channel (38x64) */
)
{
/*!
The 64-band QMF representation of the monaural signal generated by the SBR tool
is used as input of the PS tool. After the PS processing, the outputs of the left
and right hybrid synthesis filterbanks are used to generate the stereo output
signal.
------------- ---------- -------------
| Hybrid | M_n[k,m] | | L_n[k,m] | Hybrid | l[n]
m[n] --->| analysis |--------->| |--------->| synthesis |----->
| filter bank | | | | filter bank |
------------- | Stereo | -------------
| | recon- |
| | stuction |
\|/ | |
------------- | |
| De- | D_n[k,m] | |
| correlation |--------->| |
------------- | | -------------
| | R_n[k,m] | Hybrid | r[n]
| |--------->| synthesis |----->
IID, ICC ------------------------>| | | filter bank |
(IPD, OPD) ---------- -------------
m[n]: QMF represantation of the mono input
M_n[k,m]: (sub-)sub-band domain signals of the mono input
D_n[k,m]: decorrelated (sub-)sub-band domain signals
L_n[k,m]: (sub-)sub-band domain signals of the left output
R_n[k,m]: (sub-)sub-band domain signals of the right output
l[n],r[n]: left/right output signals
*/
/* get temporary hybrid qmf values of one timeslot */
C_ALLOC_SCRATCH_START(hybridRealLeft, FIXP_DBL, NO_SUB_QMF_CHANNELS);
C_ALLOC_SCRATCH_START(hybridImagLeft, FIXP_DBL, NO_SUB_QMF_CHANNELS);
C_ALLOC_SCRATCH_START(hybridRealRight, FIXP_DBL, NO_SUB_QMF_CHANNELS);
C_ALLOC_SCRATCH_START(hybridImagRight, FIXP_DBL, NO_SUB_QMF_CHANNELS);
SCHAR sf_IntBuffer = h_ps_d->sf_IntBuffer;
/* clear workbuffer */
FDKmemclear(hybridRealLeft, NO_SUB_QMF_CHANNELS*sizeof(FIXP_DBL));
FDKmemclear(hybridImagLeft, NO_SUB_QMF_CHANNELS*sizeof(FIXP_DBL));
FDKmemclear(hybridRealRight, NO_SUB_QMF_CHANNELS*sizeof(FIXP_DBL));
FDKmemclear(hybridImagRight, NO_SUB_QMF_CHANNELS*sizeof(FIXP_DBL));
/*!
Hybrid analysis filterbank:
The lower 3 (5) of the 64 QMF subbands are further split to provide better frequency resolution.
for PS processing.
For the 10 and 20 stereo bands configuration, the QMF band H_0(w) is split
up into 8 (sub-) sub-bands and the QMF bands H_1(w) and H_2(w) are spit into 2 (sub-)
4th. (See figures 8.20 and 8.22 of ISO/IEC 14496-3:2001/FDAM 2:2004(E) )
*/
if (h_ps_d->procFrameBased == 1) /* If we have switched from frame to slot based processing */
{ /* fill hybrid delay buffer. */
h_ps_d->procFrameBased = 0;
fillHybridDelayLine( rIntBufferLeft,
iIntBufferLeft,
hybridRealLeft,
hybridImagLeft,
hybridRealRight,
hybridImagRight,
&h_ps_d->specificTo.mpeg.hybrid );
}
slotBasedHybridAnalysis ( rIntBufferLeft[HYBRID_FILTER_DELAY], /* qmf filterbank values */
iIntBufferLeft[HYBRID_FILTER_DELAY], /* qmf filterbank values */
hybridRealLeft, /* hybrid filterbank values */
hybridImagLeft, /* hybrid filterbank values */
&h_ps_d->specificTo.mpeg.hybrid); /* hybrid filterbank handle */
SCHAR hybridScal = h_ps_d->specificTo.mpeg.hybrid.sf_mQmfBuffer;
/*!
Decorrelation:
By means of all-pass filtering and delaying, the (sub-)sub-band samples s_k(n) are
converted into de-correlated (sub-)sub-band samples d_k(n).
- k: frequency in hybrid spectrum
- n: time index
*/
deCorrelateSlotBased( h_ps_d, /* parametric stereo decoder handle */
hybridRealLeft, /* left hybrid time slot */
hybridImagLeft,
hybridScal, /* scale factor of left hybrid time slot */
rIntBufferLeft[0], /* left qmf time slot */
iIntBufferLeft[0],
sf_IntBuffer, /* scale factor of left and right qmf time slot */
hybridRealRight, /* right hybrid time slot */
hybridImagRight,
rIntBufferRight, /* right qmf time slot */
iIntBufferRight );
/*!
Stereo Processing:
The sets of (sub-)sub-band samples s_k(n) and d_k(n) are processed according to
the stereo cues which are defined per stereo band.
*/
applySlotBasedRotation( h_ps_d, /* parametric stereo decoder handle */
hybridRealLeft, /* left hybrid time slot */
hybridImagLeft,
rIntBufferLeft[0], /* left qmf time slot */
iIntBufferLeft[0],
hybridRealRight, /* right hybrid time slot */
hybridImagRight,
rIntBufferRight, /* right qmf time slot */
iIntBufferRight );
/*!
Hybrid synthesis filterbank:
The stereo processed hybrid subband signals l_k(n) and r_k(n) are fed into the hybrid synthesis
filterbanks which are identical to the 64 complex synthesis filterbank of the SBR tool. The
input to the filterbank are slots of 64 QMF samples. For each slot the filterbank outputs one
block of 64 samples of one reconstructed stereo channel. The hybrid synthesis filterbank is
computed seperatly for the left and right channel.
*/
/* left channel */
slotBasedHybridSynthesis ( hybridRealLeft, /* one timeslot of hybrid filterbank values */
hybridImagLeft,
rIntBufferLeft[0], /* one timeslot of qmf filterbank values */
iIntBufferLeft[0],
&h_ps_d->specificTo.mpeg.hybrid ); /* hybrid filterbank handle */
/* right channel */
slotBasedHybridSynthesis ( hybridRealRight, /* one timeslot of hybrid filterbank values */
hybridImagRight,
rIntBufferRight, /* one timeslot of qmf filterbank values */
iIntBufferRight,
&h_ps_d->specificTo.mpeg.hybrid ); /* hybrid filterbank handle */
/* free temporary hybrid qmf values of one timeslot */
C_ALLOC_SCRATCH_END(hybridImagRight, FIXP_DBL, NO_SUB_QMF_CHANNELS);
C_ALLOC_SCRATCH_END(hybridRealRight, FIXP_DBL, NO_SUB_QMF_CHANNELS);
C_ALLOC_SCRATCH_END(hybridImagLeft, FIXP_DBL, NO_SUB_QMF_CHANNELS);
C_ALLOC_SCRATCH_END(hybridRealLeft, FIXP_DBL, NO_SUB_QMF_CHANNELS);
}/* END ApplyPsSlot */
/***************************************************************************/
/*!
\brief assigns timeslots to an array
\return
****************************************************************************/
static void assignTimeSlotsPS (FIXP_DBL *bufAdr,
FIXP_DBL **bufPtr,
const int numSlots,
const int numChan)
{
FIXP_DBL *ptr;
int slot;
ptr = bufAdr;
for(slot=0; slot < numSlots; slot++) {
bufPtr [slot] = ptr;
ptr += numChan;
}
}