Commit ef72ebae authored by norvell's avatar norvell
Browse files

Added fix for clipping in TD renderer under FIX_I214_CLIPPING_STANDALONE_REND

parent 67672513
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@
#define FIX_MCT_UNINIT_MEM                              /* Issue 166: Reading of uninitialized memory in TCX range coder */
#define FIX_IGF_NOISE_REPETITION                        /* Issue 182: fix repetition of same noise in IGF */
#define FIX_126_MDFT_FB_STATIC_MEM                      /* Issue 126: reduce static mem consumption of the MDFT FB for non-SBA formats */

#define FIX_I214_CLIPPING_STANDALONE_REND               /* Issue 214: TD standalone renderer does not handle clipping */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
+33 −0
Original line number Diff line number Diff line
@@ -123,6 +123,10 @@ int main( int argc, char *argv[] )
    int16_t *MixFrameWav;
    int16_t *input_buff;
    int16_t nChannels;
#ifdef FIX_I214_CLIPPING_STANDALONE_REND
    float tmp;
    int32_t noClipping;
#endif
    FILE *f_input;
    FILE *f_output;
    FILE *f_quat_traj;
@@ -135,6 +139,9 @@ int main( int argc, char *argv[] )
    MixFrameWav = count_malloc( 2 * L_FRAME48k * sizeof( int16_t ) );
    input_buff = count_malloc( MAX_CICP_CHANNELS * L_FRAME48k * sizeof( int16_t ) );
    nChannels = 0;
#ifdef FIX_I214_CLIPPING_STANDALONE_REND
    noClipping = 0;
#endif

    for ( i = 0; i < 2 * L_FRAME48k; i++ )
    {
@@ -326,8 +333,13 @@ int main( int argc, char *argv[] )
#endif

    /* Init limiter */
#ifdef FIX_I214_CLIPPING_STANDALONE_REND
    st_ivas->hLimiter = ivas_limiter_open( NumLdspks, st_ivas->hDecoderConfig->output_Fs );
    st_ivas->hDecoderConfig->nchan_out = NumLdspks;
#else
    st_ivas->hLimiter = ivas_limiter_open( nChannels, st_ivas->hDecoderConfig->output_Fs );
    st_ivas->hDecoderConfig->nchan_out = nChannels;
#endif
    st_ivas->hLimiter->strong_saturation_count = 0;
    st_ivas->hLimiter->gain = 1.f;
    st_ivas->hLimiter->release_heuristic = 0.f;
@@ -448,7 +460,22 @@ int main( int argc, char *argv[] )
        {
            for ( nS = 0; nS < NumLdspks; nS++ )
            {
#ifdef FIX_I214_CLIPPING_STANDALONE_REND
                tmp = output[nS][n + offset] + 0.5f * sign( output[nS][n + offset] );
                if ( tmp > MAX16B_FLT )
                {
                    tmp = MAX16B_FLT;
                    noClipping++;
                }
                if ( tmp < MIN16B_FLT )
                {
                    tmp = MIN16B_FLT;
                    noClipping++;
                }
                MixFrameWav[n * NumLdspks + nS] = (int16_t) ( tmp );
#else
                MixFrameWav[n * NumLdspks + nS] = (int16_t) ( output[nS][n + offset] + 0.5f * sign( output[nS][n + offset] ) );
#endif
            }
        }
        fwrite( MixFrameWav, sizeof( int16_t ), ( currFrameLength - offset ) * NumLdspks, f_output );
@@ -504,6 +531,12 @@ int main( int argc, char *argv[] )
#endif

    fprintf( stdout, "Done rendering %d frames.\n", nFrameCount );
#ifdef FIX_I214_CLIPPING_STANDALONE_REND
    if ( noClipping > 0 )
    {
        fprintf( stderr, "*** Clipping on %ld samples.\n", noClipping );
    }
#endif
    /* system( "pause" ); */
    return 0;
}