Commit eae904a4 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[fix] ambisonics upmix for stereo

parent c6e86bbd
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -940,34 +940,32 @@ ivas_error ivas_jbm_dec_render(
    else if ( st_ivas->ivas_format == STEREO_FORMAT )
#endif
    {
#ifdef FIX_1419_MONO_STEREO_UMX
        *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
#endif

        /* Rendering */
        if ( st_ivas->renderer_type == RENDERER_MC )
        {
#ifndef FIX_1419_MONO_STEREO_UMX
            *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
#endif
            ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc, p_output );
        }
#ifdef FIX_1419_MONO_STEREO_UMX
        else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
        {
            /* Only upmix to ambisonics if spatial parameters exist */
            // TODO default render config is not enabled here, the GetDefault API func is never used
            if ( st_ivas->hRenderConfig != NULL && !st_ivas->hRenderConfig->mono_stereo_upmix_config.spatialEnabled )
            {
                ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
            }
            else
        {
            if ( st_ivas->ivas_format == MONO_FORMAT )
            {
                    // TODO route mono to W; probably same as ivas_jbm_dec_tc_buffer_playout
                /* routed to W */
                ivas_jbm_dec_tc_buffer_playout( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output );
            }
            else if ( st_ivas->ivas_format == STEREO_FORMAT )
            {
                    // TODO route stereo to W±Y
                    // p_output[0] = 0.5f * ( p_output[0] + p_output[1] ); // W = (L + R ) / 2
                    // p_output[1] = 0.5f * ( p_output[0] - p_output[1] ); // Y = (L - R ) / 2
                for ( n = 0; n < *nSamplesRendered; n++ )
                {
                    p_output[0][n] = 0.5f * ( p_output[0][n] + p_output[1][n] ); /* W = 0.5 * ( L + R ) */
                    p_output[1][n] = 0.5f * ( p_output[0][n] - p_output[1][n] ); /* Y = 0.5 * ( L - R ) */
                }
            }
        }