Commit 9f39d1a8 authored by sagnowski's avatar sagnowski
Browse files

Fix TD processing in split rendering

parent 1ca09d32
Loading
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -2581,7 +2581,20 @@ ivas_error ivas_jbm_dec_render_fx(
    IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    {
#ifdef FIX_1119_SPLIT_RENDERING_VOIP /* NOTE(sgi): BASOP special - not in float version */
        const Word32* p_output_fx_const[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS];

        nchan_out_syn_output = BINAURAL_CHANNELS * st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses;

        /* Save TD signals for pose correction if they are to be used */
        if ( st_ivas->hSplitBinRend->hMultiBinTdData != NULL )
        {
            FOR( i = 0; i < nchan_out_syn_output; i++ )
            {
                p_output_fx_const[i] = p_output_fx[i];
            }
            ivas_TD_RINGBUF_PushChannels( st_ivas->hSplitBinRend->hMultiBinTdData, p_output_fx_const, *nSamplesRendered ); // TODO(sgi): change num_samples_per_channel to unsigned
        }

#ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR  // TODO(sgi): verify if this is needed in BASOP
        if ( st_ivas->flushing )
        {
+25 −35
Original line number Diff line number Diff line
@@ -1356,23 +1356,8 @@ static ivas_error isar_render_poses(
    }
#endif

    IF ( !ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type ) )
    {
#if 1 /* NOTE(sgi): Workaround for bit width mismatch */
        Word32 pcmBuf32[960 * 16];

        for (int i = 0; i < *nOutSamples * hIvasDec->st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS; ++i)
        {
            // NOTE(sgi2det): Is this even correct or do we need to adjust the Q-format?
            pcmBuf32[i] = pcmBuf[i];
        }
#endif

        // NOTE(sgi2det): We need signal in 32 bit here, but get only 16 bit from IVAS_DEC_GetSamplesRenderer...
        //                The float version of that function has switchable output format (int16 or float) but not in BASOP.
        //                Any ideas for a better solution than this pcmBuf32?
        ivas_TD_RINGBUF_PushInterleaved( st_ivas->hSplitBinRend->hMultiBinTdData, pcmBuf32, *nOutSamples );
    }
// NOTE: Here BASOP differs from float version. In float, we push samples to TD ring buffer here. In BASOP, TD signals are only available in 16 bit here.
// To save TD signals in 32-bit precision, samples are pushed via ivas_TD_RINGBUF_PushChannels in ivas_jbm_dec_render_fx within IVAS_DEC_GetSamplesRenderer.

    return error;
}
@@ -1389,7 +1374,7 @@ static ivas_error isar_generate_metadata_and_bitstream(
    Word32 **p_head_pose_buf,                               /* i/o: PCM buffer with head-pose data     */
    Word16 nSamples,                                        /* i  : duration of audio (in samples per channel) for which metadata should be generated */
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits,               /* o  : output split rendering bits        */
    Word16* td_q                             /* o  : Q-format of the TD output if rendering from CLDFB */
    Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]    /* o  : Q-format of each channel of p_head_pose_buf */
)
{
    // NOTE(sgi2det): Code in this function was moved and adapted from IVAS_DEC_GetSplitBinauralBitstream,
@@ -1475,8 +1460,7 @@ static ivas_error isar_generate_metadata_and_bitstream(
        Quaternion.z_fx = 0;
    }
    // NOTE(sgi): BASOP special - not in float version
    Word16 q1 = 31, q2 = 31, Q_buff = 31;
    Word16 Q_out[CLDFB_NO_COL_MAX];
    Word16 q1 = 31, q2 = 31, Q_buff;
    Q_out[0] = 31;

    IF( EQ_16( cldfb_in_flag, 1 ) )
@@ -1518,6 +1502,7 @@ static ivas_error isar_generate_metadata_and_bitstream(
        }
        Q_out[0] = add( Q_out[0], Q11 );
        Q_out[1] = Q_out[0];
        Q_buff = Q31 + Q6; // TODO(sgi): likely unneeded
    }

    IF( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( &hSplitBinRend->splitrend,
@@ -1534,11 +1519,6 @@ static ivas_error isar_generate_metadata_and_bitstream(
        return error;
    }

    IF( EQ_16( cldfb_in_flag, 1 ) )
    {
        *td_q = Q_out[0];
    }

    return IVAS_ERR_OK;
}
#endif /* FIX_1119_SPLIT_RENDERING_VOIP */
@@ -1759,7 +1739,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    Word16 i;
    Word16 pcm_out_flag;
    Word16 numSamplesPerChannelToOutput;
    Word16 td_q = 11;
    Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS];

    test();
    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
@@ -1792,7 +1772,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
        p_head_pose_buf[i] = head_pose_buf[i];
    }

    if ( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nOutSamples, splitRendBits, &td_q ) ) != IVAS_ERR_OK )
    if ( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nOutSamples, splitRendBits, Q_out ) ) != IVAS_ERR_OK )
    {
        return error;
    }
@@ -1800,6 +1780,10 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    /* convert to int16 with limiting for BINAURAL_SPLIT_PCM */
    if ( pcm_out_flag )
    {
        FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
        {
            scale_sig32( p_head_pose_buf[i], numSamplesPerChannelToOutput, sub( Q11, Q_out[i] ) ); // Q11
        }
        if ( st_ivas->hDecoderConfig->render_framesize == IVAS_RENDER_FRAMESIZE_5MS )
        {
#ifndef DISABLE_LIMITER
@@ -1814,7 +1798,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
#ifdef DEBUGGING
        st_ivas->noClipping +=
#endif
            ivas_syn_output_fx( p_head_pose_buf, td_q, numSamplesPerChannelToOutput, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf_out );
            ivas_syn_output_fx( p_head_pose_buf, Q11, numSamplesPerChannelToOutput, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf_out );
    }
#else
    Decoder_Struct *st_ivas;
@@ -5443,10 +5427,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples
#ifdef FIX_1119_SPLIT_RENDERING_VOIP
    IF( hIvasDec->hasDecodedFirstGoodFrame && splitRendBits != NULL )
    {
        Word16 td_q = 11;;
        Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS];
        Word16 i;

        /* Analyse head poses over entire frame, generate ISAR metadata and maybe encode if split coded */
        IF( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nSamplesRendered, splitRendBits, &td_q ) ) != IVAS_ERR_OK )
        IF( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nSamplesRendered, splitRendBits, Q_out ) ) != IVAS_ERR_OK )
        {
            return error;
        }
@@ -5454,6 +5439,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples
        /* Synthesise PCM output if split PCM */
        IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
        {
            FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
            {
                scale_sig32( p_head_pose_buf[i], *nSamplesRendered, sub( Q11, Q_out[i] ) ); // Q11
            }

            IF( st_ivas->hDecoderConfig->render_framesize == IVAS_RENDER_FRAMESIZE_5MS )
            {
#ifndef DISABLE_LIMITER
@@ -5468,7 +5458,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples
#ifdef DEBUGGING
            st_ivas->noClipping +=
#endif
                ivas_syn_output_fx( p_head_pose_buf, td_q, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf );
                ivas_syn_output_fx( p_head_pose_buf, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf );
        }
    }
#endif