Commit 9ecd5e21 authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

proper flushing of SR audio data

parent 8a5cfa2c
Loading
Loading
Loading
Loading
Loading
+21 −6
Original line number Diff line number Diff line
@@ -2917,18 +2917,29 @@ static ivas_error decodeG192(
        }

        /* flush remaining audio */
        if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK )
        if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf,
#ifdef FIX_1342_PROPER_FLUSH_IN_SR        
                                    splitRendBits,
#endif        
            &nSamplesFlushed ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) );
            goto cleanup;
        }

#ifdef FIX_1342_PROPER_FLUSH_IN_SR
        if ( !isSplitCoded )
        {
#endif            
            /* Write current frame */
            if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, nSamplesFlushed * nOutChannels ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nOutput audio file writer error\n" );
                goto cleanup;
            }
#ifdef FIX_1342_PROPER_FLUSH_IN_SR        
        }
#endif

        /* Write ISM metadata to external file(s) */
        if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
@@ -3846,7 +3857,11 @@ static ivas_error decodeVoIP(
    int16_t nSamplesFlushed = 0;

    /* flush remaining audio */
    if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK )
    if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf,
#ifdef FIX_1342_PROPER_FLUSH_IN_SR
     splitRendBits,
#endif     
      &nSamplesFlushed ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) );
        goto cleanup;
+2 −1
Original line number Diff line number Diff line
@@ -159,7 +159,8 @@
/* only BE switches wrt wrt. TS 26.258 V3.0 */

/*#define FIX_I4_OL_PITCH*/                             /* fix open-loop pitch used for EVS core switching */
#define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR      /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */
/*#define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR*/  /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering; disabled, superseded by FIX_1342_PROPER_FLUSH_IN_SR */
#define FIX_1342_PROPER_FLUSH_IN_SR                     /* FhG: Proper implementation of decoder flush with split rendering, using isar_render_poses + isar_generate_metadata_and_bitstream */
#define NONBE_1122_KEEP_EVS_MODE_UNCHANGED              /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR.  */
#define FIX_FLOAT_1539_G192_FORMAT_SWITCH               /* Nokia: reintroduce format switching for g192 bitstreams */

+47 −6
Original line number Diff line number Diff line
@@ -4315,6 +4315,9 @@ ivas_error IVAS_DEC_Flush(
    const int16_t nSamplesPerChannel,         /* i  : number of samples per channel requested to be written to output buffer        */
    const IVAS_DEC_PCM_TYPE pcmType,          /* i  : type for the decoded PCM resolution                                           */
    void *pcmBuf,                             /* o  : output synthesis signal                                                       */
#ifdef FIX_1342_PROPER_FLUSH_IN_SR            
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o  : output split rendering bits; NULL when not applicable                         */
#endif    
    int16_t *nSamplesFlushed                  /* o  : number of samples flushed                                                     */
)
{
@@ -4339,7 +4342,45 @@ ivas_error IVAS_DEC_Flush(
    error = IVAS_ERR_OK;
    if ( nSamplesToRender > 0 && hIvasDec->st_ivas->ivas_format != MONO_FORMAT )
    {
#ifdef FIX_1342_PROPER_FLUSH_IN_SR
        if ( is_split_rendering_enabled( hIvasDec->st_ivas->hDecoderConfig, hIvasDec->st_ivas->hRenderConfig ) )
        {
            int16_t i, nOutSamples = 0;
            bool needNewFrame;
            const int16_t splitFrameSize = isar_get_frame_size( hIvasDec->st_ivas );
            float head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k];
            float *p_head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES];

            for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i )
            {
                p_head_pose_buf[i] = head_pose_buf[i];
            }

            /* Render remaining buffered audio into the SR ring buffers using the
               correctly-sized internal float buffer to avoid writing beyond the end of the pcmBuf */
            if ( ( error = isar_render_poses( hIvasDec, splitFrameSize, &nOutSamples, &needNewFrame ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            *nSamplesFlushed = nOutSamples;

            /* Flush the remaing audio output in SR mode. Metadata generation is handled during normal decoding */
            if ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
            {
#ifndef DISABLE_LIMITER
                ivas_limiter_dec( hIvasDec->st_ivas->hLimiter, p_head_pose_buf, hIvasDec->st_ivas->hDecoderConfig->nchan_out, nOutSamples, hIvasDec->st_ivas->BER_detect );
#endif
                ivas_syn_output( p_head_pose_buf, nOutSamples, hIvasDec->st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf );
            }
        }
        else
        {
#endif 
            error = ivas_dec_render( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcm_type_API_to_internal( pcmType ), pcmBuf );
#ifdef FIX_1342_PROPER_FLUSH_IN_SR
        }
#endif        
    }
    else
    {
+3 −0
Original line number Diff line number Diff line
@@ -335,6 +335,9 @@ ivas_error IVAS_DEC_Flush(
    const int16_t nSamplesPerChannel,           /* i  : number of samples per channel requested to be written to output buffer  */
    const IVAS_DEC_PCM_TYPE pcmType,            /* i  : type for the decoded PCM resolution                                     */
    void *pcmBuf,                               /* o  : output synthesis signal                                                 */
#ifdef FIX_1342_PROPER_FLUSH_IN_SR            
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits,   /* o  : output split rendering bits; NULL when not applicable                   */
#endif    
    int16_t *nSamplesFlushed                    /* o  : number of samples flushed                                               */
);