Commit 7a52e2c2 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Encoder code cleanup, Q-info doc for decoder and renderer

parent 8f97e97c
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Back(
{
    JB4_CIRCULARBUFFER_ELEMENT ret;

    IF( NE_32( h->writePos, 0U ) )
    IF( h->writePos != 0U )
    {
        ret = h->data[h->writePos - 1];
        move32();
@@ -408,7 +408,7 @@ void JB4_CIRCULARBUFFER_MinAndPercentile(

    /* init output variables */
    minEle = h->data[h->readPos];

    move32();
    /* To calculate the percentile, a number of elements with the highest values are collected in maxElements in
     * ascending sorted order. This array has a size of nElementsToIgnore plus one. This additional element is the
     * lowest of all maxElements, and is called the percentile of all elements. */
+6 −7
Original line number Diff line number Diff line
@@ -139,7 +139,6 @@ ivas_error JB4_INPUTBUFFER_Init(
    h->readPos = 0;
    move16();
    h->compareFunction = compareFunction;
    move16();

    return IVAS_ERR_OK;
}
@@ -213,8 +212,8 @@ Word16 JB4_INPUTBUFFER_Enque(
        {
            IF( replace != 0 )
            {
                *replacedElement = h->data[L_add( h->readPos, middle ) % h->capacity];
                h->data[L_add( h->readPos, middle ) % h->capacity] = element;
                *replacedElement = h->data[( h->readPos + middle ) % h->capacity];
                h->data[( h->readPos + middle ) % h->capacity] = element;
                return 0;
            }
            return 1;
@@ -235,7 +234,7 @@ Word16 JB4_INPUTBUFFER_Enque(
        canMoveRight = (UWord16) LT_32( insertPos, h->writePos );
        canMoveLeft = (UWord16) GT_32( insertPos, h->writePos );
    }

    test();
    assert( canMoveRight != 0 || canMoveLeft != 0 );

    IF( canMoveRight )
@@ -260,7 +259,7 @@ Word16 JB4_INPUTBUFFER_Enque(
        /* move lower elements to the left and insert before insertPos */
        FOR( j = 0; j < low; j++ )
        {
            h->data[L_add( L_sub( h->readPos, 1 ), j )] = h->data[L_add( h->readPos, j )];
            h->data[( h->readPos - 1 ) + j] = h->data[h->readPos + j];
        }

        h->data[insertPos - 1] = element;
@@ -337,12 +336,12 @@ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element(
    /* return h->data[(h->readPos + index) % h->capacity] without error handling */
    IF( LT_32( L_add( h->readPos, index ), h->capacity ) )
    {
        ret = h->data[L_add( h->readPos, index )];
        ret = h->data[( h->readPos + index )];
    }
    ELSE
    {
        /* wrap around */
        ret = h->data[L_sub( L_add( h->readPos, index ), h->capacity )];
        ret = h->data[( ( h->readPos + index ) - h->capacity )];
    }

    return ret;
+25 −28
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ struct JB4
    UWord32 FecOffWin[10];
    UWord32 optimum_offset;

    Word32 netLossRate_fx;
    Word32 netLossRate_fx; // Q15
    Word32 nPartialCopiesUsed;
    Word32 last_nLost;
    Word32 last_ntot;
@@ -479,22 +479,22 @@ Word16 JB4_PushDataUnit(
    {
        IF( dataUnit->partialCopyOffset == 0 )
        {
            if ( h->rfOffset2Active > 0 )
            IF( h->rfOffset2Active > 0 )
            {
                h->rfOffset2Active = sub( h->rfOffset2Active, 1 );
                move16();
            }
            if ( h->rfOffset3Active > 0 )
            IF( h->rfOffset3Active > 0 )
            {
                h->rfOffset3Active = sub( h->rfOffset3Active, 1 );
                move16();
            }
            if ( h->rfOffset5Active > 0 )
            IF( h->rfOffset5Active > 0 )
            {
                h->rfOffset5Active = sub( h->rfOffset5Active, 1 );
                move16();
            }
            if ( h->rfOffset7Active > 0 )
            IF( h->rfOffset7Active > 0 )
            {
                h->rfOffset7Active = sub( h->rfOffset7Active, 1 );
                move16();
@@ -641,13 +641,13 @@ Word16 JB4_getFECoffset(
Word16 JB4_FECoffset(
    JB4_HANDLE h )
{
    IF( LT_32( h->netLossRate_fx, 1634 ) )
    IF( LT_32( h->netLossRate_fx, 1634 /*.05f in Q15*/ ) )
    {
        return (Word16) 0;
        return 0;
    }
    ELSE
    {
        return (Word16) 1;
        return 1;
    }
}

@@ -663,7 +663,7 @@ Word16 JB4_PopDataUnit(
    Word16 ret;

    assert( sysTime >= h->prevPopSysTime );
    if ( GT_64( sysTime, W_add( h->prevPopSysTime, 20 ) ) )
    IF( GT_64( sysTime, W_add( h->prevPopSysTime, 20 ) ) )
    {
        h->lastPlayoutOffset = L_add( h->lastPlayoutOffset, 20 );
        move32();
@@ -780,6 +780,7 @@ static Word16 JB4_adaptPlayout(
    bool stretchTime;

    /* reset scale */
    test();
    IF( scale == NULL || maxScaling == NULL )
    {
        return -1;
@@ -901,13 +902,9 @@ static void JB4_adaptActivePlayout(
        {
            IF( convertToLateLoss )
            {
#ifndef IVAS_FLOAT_FIXED
                JB4_dropFromBuffer( h );
#else
                JB4_dropFromBuffer( h );
                h->nLostOrStretched = L_add( h->nLostOrStretched, 1 );
                move32();
#endif
            }
            ELSE IF( dropEarly )
            {
@@ -924,8 +921,8 @@ static void JB4_adaptActivePlayout(
                Word32 temp = BASOP_Util_Divide3232_Scale_cadence( W_extract_l( W_sub( dropRateMax, dropRateMin ) ), W_extract_l( dropGapMax ), &exp );
                /* limit gap to [gapMin,gapMax] and calculate current drop rate from gap */
                Word64 temp2 = W_mult0_32_32( W_extract_l( JB4_MIN( gap, dropGapMax ) ), temp );
                Word64 temp3 = W_shr( temp2, 31 - exp );
                Word64 diff = W_sub( W_shl( temp3 + 1, 31 - exp ), temp2 );
                Word64 temp3 = W_shr( temp2, sub( 31, exp ) );
                Word64 diff = W_sub( W_shl( W_add( temp3, 1 ), sub( 31, exp ) ), temp2 );
                if ( LE_64( diff, 21 ) )
                {
                    temp3 = W_add( temp3, 1 );
@@ -1124,7 +1121,7 @@ static Word16 JB4_inspectBufferForDropping(
    {
        Word16 temp, exp;
        temp = BASOP_Util_Divide3232_Scale( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ), (Word32) ( h->frameDuration ), &exp );
        seqNrDiff = L_shl( temp, sub( exp, 15 ) );
        seqNrDiff = L_shl( temp, sub( exp, 15 ) ); // Q0
    }
    ELSE
    {
@@ -1219,7 +1216,7 @@ static Word16 JB4_checkDtxDropping(
        Word16 temp, exp;
        temp = BASOP_Util_Divide3232_Scale( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ),
                                            (Word32) ( h->frameDuration ), &exp );
        seqNrDiff = L_shl( temp, exp - 15 );
        seqNrDiff = L_shl( temp, sub( exp, 15 ) ); // Q0
        if ( seqNrDiff <= 0 )
        {
            /* no not drop first active frame */
@@ -1270,7 +1267,7 @@ static void JB4_estimateShortTermJitter(
        {
            duration = (UWord32) W_sub( maxTime, minTime );
            maxDuration = (UWord32) W_shl( h->timeScale, 2 );
            WHILE( GT_64( duration, maxDuration ) )
            WHILE( duration > maxDuration )
            {
                JB4_CIRCULARBUFFER_Deque( h->stJitterFifo, &dequedElement );
                JB4_CIRCULARBUFFER_Deque( h->stTimeStampFifo, &dequedElement );
@@ -1294,13 +1291,13 @@ static void JB4_estimateShortTermJitter(
        temp = BASOP_Util_Divide3232_Scale( maxElement, (Word32) h->frameDuration, &exp );
        IF( exp < 0 )
        {
            temp = L_shl( temp, exp );
            temp = L_shl( temp, exp ); // Q31
            exp = 0;
            move16();
        }
        IF( temp != 0 )
        {
            temp = L_shr( ceil_fixed( temp, 15 - exp ), 15 - exp );
            temp = L_shr( ceil_fixed( temp, sub( 15, exp ) ), sub( 15, exp ) ); // Q31
        }
        h->stJitter = (UWord32) W_mult0_32_32( temp, h->frameDuration );
        move32();
@@ -1383,7 +1380,7 @@ static void JB4_popFromBuffer(
                maxval = h->FecOffWin[i];
                move16();
                h->optimum_offset = i;
                move16();
                move32();
            }
            h->FecOffWin[i] = 0;
            move32();
@@ -1404,7 +1401,7 @@ static void JB4_popFromBuffer(
        test();
        IF( lost != 0 && total_rec != 0 )
        {
            h->netLossRate_fx = divide3232( lost, total_rec );
            h->netLossRate_fx = divide3232( lost, total_rec ); // Q15
        }
        ELSE
        {
@@ -1430,7 +1427,7 @@ static void JB4_popFromBuffer(
                test();
                IF( frameoffset > 0 && LT_16( frameoffset, MAXOFFSET ) )
                {
                    h->FecOffWin[frameoffset] = W_extract_l( W_add( h->FecOffWin[frameoffset], 1 ) );
                    h->FecOffWin[frameoffset] = (UWord32) ( W_add( h->FecOffWin[frameoffset], 1 ) );
                    move32();
                }
            }
@@ -1503,7 +1500,7 @@ static void JB4_popFromBuffer(
            test();
            IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence )
            {
                frameoffset = extract_l( Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ) );
                frameoffset = extract_l( Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ) ); // Q0
                test();
                IF( ( frameoffset > 0 ) && LT_16( frameoffset, MAXOFFSET ) )
                {
@@ -1523,7 +1520,7 @@ static void JB4_popFromBuffer(
        /* separate concealments since last available pop in lost and stretched */
        Word16 exp;
        nStretched = BASOP_Util_Divide3232_Scale( tsDiff, h->frameDuration, &exp );
        nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) );
        nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); // Q0
        assert( h->nLostOrStretched >= nStretched );
        h->nLost = (UWord32) W_add( h->nLost, W_sub( h->nLostOrStretched, nStretched ) );
        /* jitter-induced insertion (e.g. buffer underflow) */
@@ -1622,7 +1619,7 @@ static void JB4_dropFromBuffer(
        /* separate concealments since last available pop in lost and stretched */
        Word16 exp;
        nStretched = BASOP_Util_Divide3232_Scale( tsDiff, (Word32) h->frameDuration, &exp );
        nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) );
        nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); // Q0
        assert( h->nLostOrStretched >= nStretched );

        /* convert stretching followed by shrinking to late-loss */
@@ -1636,8 +1633,7 @@ static void JB4_dropFromBuffer(
            move32();
            move32();
            move32();
            move32();
            if ( !dataUnit->silenceIndicator )
            IF( !dataUnit->silenceIndicator )
            {
                /* JBM induced removal of a speech frame (intentional frame dropping) */
                h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, 1 );
@@ -1752,6 +1748,7 @@ static Word16 JB4_inputBufferCompareFunction(
    Word16 result;

    *replaceWithNewElementIfEqual = 0;
    move16();
    newDataUnit = (JB4_DATAUNIT_HANDLE) newElement;
    arrayDataUnit = (JB4_DATAUNIT_HANDLE) arrayElement;
    diff = JB4_rtpTimeStampDiff( arrayDataUnit->timeStamp, newDataUnit->timeStamp );
+103 −72

File changed.

Preview size limit exceeded, changes collapsed.

+5 −3
Original line number Diff line number Diff line
@@ -144,8 +144,10 @@ bool apa_set_quality( apa_state_t *s, Word32 quality, UWord16 qualityred, UWord1

bool apa_exit( apa_state_t **s );

#ifndef IVAS_FLOAT_FIXED
uint8_t apa_exec( apa_state_t *s, const float a_in[], uint16_t l_in, uint16_t maxScaling, float a_out[], uint16_t *l_out );
uint8_t apa_exec_ivas_fx( apa_state_t *s, const Word16 a_in[], uint16_t l_in, uint16_t maxScaling, Word16 a_out[], uint16_t *l_out );
uint8_t apa_exec_fx( apa_state_t *s, const Word16 a_in[], uint16_t l_in, uint16_t maxScaling, Word16 a_out[], uint16_t *l_out );

#else
uint8_t apa_exec_ivas_fx( apa_state_t *s, const Word16 a_in[], UWord16 l_in, UWord16 maxScaling, Word16 a_out[], UWord16 *l_out );
uint8_t apa_exec_fx( apa_state_t *s, const Word16 a_in[], UWord16 l_in, UWord16 maxScaling, Word16 a_out[], UWord16 *l_out );
#endif
#endif /* JBM_PCMDSP_APA_H */
Loading