Commit 6792cf63 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi

AAC-Decoder: SBR delay for gapless

Revise decoder output delay determination. The output delay consisted of
  concealment and limiter delay. SBR delay was not covered but must be
  considered for gapless playback delay compensation.

Bug 9428126

Change-Id: I67483712c284de9b5378694f9db7acbed2547dd7
parent 8e087bf3
......@@ -110,7 +110,7 @@ amm-info@iis.fraunhofer.de
/* Decoder library info */
#define AACDECODER_LIB_VL0 2
#define AACDECODER_LIB_VL1 5
#define AACDECODER_LIB_VL2 9
#define AACDECODER_LIB_VL2 10
#define AACDECODER_LIB_TITLE "AAC Decoder Lib"
#define AACDECODER_LIB_BUILD_DATE __DATE__
#define AACDECODER_LIB_BUILD_TIME __TIME__
......@@ -954,19 +954,22 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_DecodeFrame(
if (sbrError == SBRDEC_OK) {
#define UPS_SCALE 2 /* Maximum upsampling factor is 4 (CELP+SBR) */
FIXP_DBL upsampleFactor = FL2FXCONST_DBL(1.0f/(1<<UPS_SCALE));
/* Update data in streaminfo structure. Assume that the SBR upsampling factor is either 1 or 2 */
self->flags |= AC_SBR_PRESENT;
if (self->streamInfo.aacSampleRate != self->streamInfo.sampleRate) {
if (self->streamInfo.frameSize == 768) {
self->streamInfo.frameSize = (self->streamInfo.aacSamplesPerFrame * 8) / 3;
upsampleFactor = FL2FXCONST_DBL(8.0f/(3<<UPS_SCALE));
} else {
self->streamInfo.frameSize = self->streamInfo.aacSamplesPerFrame << 1;
upsampleFactor = FL2FXCONST_DBL(2.0f/(1<<UPS_SCALE));
}
}
/* Correct the additional concealment delay figures */
self->streamInfo.outputDelay -= self->sbrParams.bsDelay * self->streamInfo.aacSamplesPerFrame;
self->streamInfo.outputDelay += self->sbrParams.bsDelay * self->streamInfo.frameSize;
/* Apply upsampling factor to both the core frame length and the core delay */
self->streamInfo.frameSize = (INT)fMult((FIXP_DBL)self->streamInfo.aacSamplesPerFrame<<UPS_SCALE, upsampleFactor);
self->streamInfo.outputDelay = (UINT)(INT)fMult((FIXP_DBL)self->streamInfo.outputDelay<<UPS_SCALE, upsampleFactor);
self->streamInfo.outputDelay += sbrDecoder_GetDelay( self->hSbrDecoder );
if (self->psPossible) {
self->flags |= AC_PS_PRESENT;
......
......@@ -331,6 +331,13 @@ SBR_ERROR sbrDecoder_Close ( HANDLE_SBRDECODER *self );
*/
INT sbrDecoder_GetLibInfo( LIB_INFO *info );
/**
* \brief Determine the modules output signal delay in samples.
* \param self SBR decoder handle.
* \return The number of samples signal delay added by the module.
*/
UINT sbrDecoder_GetDelay( const HANDLE_SBRDECODER self );
#ifdef __cplusplus
}
......
......@@ -179,6 +179,7 @@ typedef FREQ_BAND_DATA *HANDLE_FREQ_BAND_DATA;
#define SBRDEC_LOW_POWER 16 /* Flag indicating that Low Power QMF mode shall be used. */
#define SBRDEC_PS_DECODED 32 /* Flag indicating that PS was decoded and rendered. */
#define SBRDEC_LD_MPS_QMF 512 /* Flag indicating that the LD-MPS QMF shall be used. */
#define SBRDEC_DOWNSAMPLE 8192 /* Flag indicating that the downsampling mode is used. */
#define SBRDEC_FLUSH 16384 /* Flag is used to flush all elements in use. */
#define SBRDEC_FORCE_RESET 32768 /* Flag is used to force a reset of all elements in use. */
......
......@@ -137,7 +137,7 @@ amm-info@iis.fraunhofer.de
/* Decoder library info */
#define SBRDECODER_LIB_VL0 2
#define SBRDECODER_LIB_VL1 2
#define SBRDECODER_LIB_VL2 5
#define SBRDECODER_LIB_VL2 6
#define SBRDECODER_LIB_TITLE "SBR Decoder"
#define SBRDECODER_LIB_BUILD_DATE __DATE__
#define SBRDECODER_LIB_BUILD_TIME __TIME__
......@@ -251,8 +251,10 @@ SBR_ERROR sbrDecoder_ResetElement (
if ( sampleRateIn == sampleRateOut ) {
synDownsampleFac = 2;
self->flags |= SBRDEC_DOWNSAMPLE;
} else {
synDownsampleFac = 1;
self->flags &= ~SBRDEC_DOWNSAMPLE;
}
self->synDownsampleFac = synDownsampleFac;
......@@ -1582,3 +1584,34 @@ INT sbrDecoder_GetLibInfo( LIB_INFO *info )
return 0;
}
UINT sbrDecoder_GetDelay( const HANDLE_SBRDECODER self )
{
UINT outputDelay = 0;
if ( self != NULL) {
UINT flags = self->flags;
/* See chapter 1.6.7.2 of ISO/IEC 14496-3 for the GA-SBR figures below. */
/* Are we initialized? */
if ( (self->numSbrChannels > 0)
&& (self->numSbrElements > 0) )
{
/* Add QMF synthesis delay */
if ( (flags & SBRDEC_ELD_GRID)
&& IS_LOWDELAY(self->coreCodec) ) {
/* Low delay SBR: */
{
outputDelay += (flags & SBRDEC_DOWNSAMPLE) ? 32 : 64; /* QMF synthesis */
}
}
else if (!IS_USAC(self->coreCodec)) {
/* By the method of elimination this is the GA (AAC-LC, HE-AAC, ...) branch: */
outputDelay += (flags & SBRDEC_DOWNSAMPLE) ? 481 : 962;
}
}
}
return (outputDelay);
}
......@@ -232,6 +232,14 @@ typedef enum
} AUDIO_OBJECT_TYPE;
#define IS_USAC(aot) \
((aot) == AOT_USAC \
|| (aot) == AOT_RSVD50)
#define IS_LOWDELAY(aot) \
((aot) == AOT_ER_AAC_LD \
|| (aot) == AOT_ER_AAC_ELD)
/** Channel Mode ( 1-7 equals MPEG channel configurations, others are arbitrary). */
typedef enum {
MODE_INVALID = -1,
......
......@@ -99,7 +99,7 @@ amm-info@iis.fraunhofer.de
/* library info */
#define SYS_LIB_VL0 1
#define SYS_LIB_VL1 3
#define SYS_LIB_VL2 5
#define SYS_LIB_VL2 6
#define SYS_LIB_TITLE "System Integration Library"
#define SYS_LIB_BUILD_DATE __DATE__
#define SYS_LIB_BUILD_TIME __TIME__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment