Commit e4a16a91 authored by vaclav's avatar vaclav
Browse files

fixes for 'stereo' output

parent 4a66efbd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3079,7 +3079,7 @@ void ivas_sba_getTCs(
);

ivas_error ivas_sba_linear_renderer(
    float output_f[][L_FRAME48k],                               /* i/o: synthesized core-coder transport channels/DirAC output  */
    float output[][L_FRAME48k],                                 /* i/o: synthesized core-coder transport channels/DirAC output  */
    const int16_t output_frame,                                 /* i  : output frame length per channel                         */
    const int16_t nchan_in,                                     /* i  : number of input ambisonics channels                     */
    const AUDIO_CONFIG output_config,                           /* i  : output audio configuration                              */
@@ -3969,7 +3969,7 @@ void ivas_spar_get_parameters(
    const int16_t num_ch_out,                                   /* i  : number of channels out                  */
    const int16_t num_ch_in,                                    /* i  : number of channels in                   */
    const int16_t num_spar_bands,                               /* i  : number of SPAR bands                    */
    float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]   /* o  : mixing matrix               */
    float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o  : mixing matrix               */
);

ivas_error ivas_spar_md_dec_init(
+6 −0
Original line number Diff line number Diff line
@@ -944,6 +944,9 @@ ivas_error ivas_init_decoder(
            }

            st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
#ifdef SBA_BITRATE_SWITCHING
            st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
#endif
        }

        if ( st_ivas->nCPE > 1 )
@@ -1140,6 +1143,9 @@ ivas_error ivas_init_decoder(
                }

                st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
#ifdef SBA_BITRATE_SWITCHING
                st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
#endif
            }

            /* set CNA/CNG flags */
+60 −65
Original line number Diff line number Diff line
@@ -452,7 +452,7 @@ ivas_error ivas_sba_dec_reconfigure(
)
{
#ifdef SBA_BITRATE_SWITCHING
    int16_t i, n;
    int16_t i, n, output_frame;
    int16_t sce_id, cpe_id;
    int16_t nSCE_old, nCPE_old, nchan_transport_old;
    int16_t nchan_hp20_old, nchan_hp20;
@@ -465,6 +465,7 @@ ivas_error ivas_sba_dec_reconfigure(
    ivas_error error;

    hDecoderConfig = st_ivas->hDecoderConfig;
    output_frame = ( int16_t )( hDecoderConfig->output_Fs / FRAMES_PER_SEC );
    error = IVAS_ERR_OK;

    ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
@@ -498,12 +499,12 @@ ivas_error ivas_sba_dec_reconfigure(
        ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs );
        st_ivas->hSpar = NULL;

        st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO );

        if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO );
    }
    else
    {
@@ -631,55 +632,31 @@ ivas_error ivas_sba_dec_reconfigure(
     * Allocate, initalize, and configure SCE/CPE/MCT handles
     *-----------------------------------------------------------------*/

    if ( st_ivas->nchan_transport == nchan_transport_old )
    /* remove dummy CPE element for DFT stereo-like upmix */
    if ( sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag )
    {
        for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
        {
            st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
            st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
        }
        st_ivas->hCPE[0]->hCoreCoder[0] = NULL;
        st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
        destroy_cpe_dec( st_ivas->hCPE[0] );
        st_ivas->hCPE[0] = NULL;

#ifdef SBA_BITRATE_SWITCHING
        if ( st_ivas->hSCE[0] != NULL )
        {
            if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old )
            {
                int16_t output_frame = ( int16_t )( hDecoderConfig->output_Fs / FRAMES_PER_SEC );

                if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
                {
                    return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) );
                }
                set_zero( st_ivas->hSCE[0]->save_synth, output_frame );

                if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
                {
                    return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) );
                }
                set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame );
            }
            else if( !st_ivas->sba_dirac_stereo_flag )
            {
            count_free( st_ivas->hSCE[0]->save_synth );
            st_ivas->hSCE[0]->save_synth = NULL;

            count_free( st_ivas->hSCE[0]->save_hb_synth );
            st_ivas->hSCE[0]->save_hb_synth = NULL;
        }
    }

        /* create CPE element for DFT Stereo like upmix */
        if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old )
        {
            if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
    if ( st_ivas->nchan_transport == nchan_transport_old )
    {
                return error;
            }

            st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
        }
        else if( sba_dirac_stereo_flag_old )
        for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
        {
            //destroy_cpe_dec( st_ivas->hCPE[0] );
            st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
            st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
        }
#endif

        for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
        {
@@ -713,17 +690,6 @@ ivas_error ivas_sba_dec_reconfigure(
        {
            destroy_sce_dec( st_ivas->hSCE[sce_id] );
            st_ivas->hSCE[sce_id] = NULL;

            /* remove dummy CPE needed for 1TC->Stereo rendering via DFT stereo*/
            if ( sba_dirac_stereo_flag_old )
            {
#ifdef DEBUGGING
                assert( st_ivas->hCPE[0] );
#endif
                st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
                destroy_cpe_dec( st_ivas->hCPE[0] );
                st_ivas->hCPE[0] = NULL;
            }
        }

        for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
@@ -775,17 +741,6 @@ ivas_error ivas_sba_dec_reconfigure(
            }
        }

        /* create CPE element for DFT Stereo like upmix */
        if ( st_ivas->sba_dirac_stereo_flag )
        {
            if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
        }

        if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
        {
            if ( nCPE_old == 1 )
@@ -832,6 +787,40 @@ ivas_error ivas_sba_dec_reconfigure(
        }
    }

    /* create dummy CPE element for DFT stereo-like upmix */
    if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old )
    {
        if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        // VE: TBV - just reset for now
        set_f( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) );

        st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
        st_ivas->hCPE[0]->hCoreCoder[1] = NULL;

        if( st_ivas->hSCE[0]->save_synth == NULL )
        {
            if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) );
            }
            set_zero( st_ivas->hSCE[0]->save_synth, output_frame );
        }

        if ( st_ivas->hSCE[0]->save_hb_synth == NULL )
        {
            if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) );
            }
            set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame );
        }
    }


    /*-----------------------------------------------------------------*
     * HP20 memories
     *-----------------------------------------------------------------*/
@@ -954,6 +943,12 @@ ivas_error ivas_sba_dec_reconfigure(
        }
    }

    /* CLDFB Interpolation weights */
    if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses ) )
    {
        ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig );
    }

    /*-----------------------------------------------------------------*
     * Set CNA/CNG flags
     *-----------------------------------------------------------------*/
+7 −7
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t outpu
 *-------------------------------------------------------------------*/

ivas_error ivas_sba_linear_renderer(
    float output_f[][L_FRAME48k],         /* i/o: synthesized core-coder transport channels/DirAC output  */
    float output[][L_FRAME48k],           /* i/o: synthesized core-coder transport channels/DirAC output  */
    const int16_t output_frame,           /* i  : output frame length per channel                         */
    const int16_t nchan_in,               /* i  : number of input ambisonics channels                     */
    const AUDIO_CONFIG output_config,     /* i  : output audio configuration                              */
@@ -92,7 +92,7 @@ ivas_error ivas_sba_linear_renderer(
            {
                for ( i = 0; i < output_frame; i++ )
                {
                    output_f[0][i] += output_f[1][i];
                    output[0][i] += output[1][i];
                }
            }
            /* else: do nothing, MONO = W*/
@@ -106,9 +106,9 @@ ivas_error ivas_sba_linear_renderer(
                /*Build L/R cardioids*/
                for ( i = 0; i < output_frame; i++ )
                {
                    dmx_l = 0.5f * ( output_f[0][i] + output_f[1][i] );          /* cardioid_left  = 0.5(W + Y) */
                    output_f[1][i] = 0.5f * ( output_f[0][i] - output_f[1][i] ); /* cardioid_right = 0.5(W - Y) */
                    output_f[0][i] = dmx_l;
                    dmx_l = 0.5f * ( output[0][i] + output[1][i] );        /* cardioid_left  = 0.5(W + Y) */
                    output[1][i] = 0.5f * ( output[0][i] - output[1][i] ); /* cardioid_right = 0.5(W - Y) */
                    output[0][i] = dmx_l;
                }
            }
            break;
@@ -118,14 +118,14 @@ ivas_error ivas_sba_linear_renderer(
        case AUDIO_CONFIG_5_1_4:
        case AUDIO_CONFIG_7_1_4:
        case AUDIO_CONFIG_LS_CUSTOM:
            ivas_sba_mtx_mult( output_f, output_frame, nchan_hoa, output_setup, hoa_dec_mtx );
            ivas_sba_mtx_mult( output, output_frame, nchan_hoa, output_setup, hoa_dec_mtx );
            break;
        case AUDIO_CONFIG_FOA:  /* Ambisonics output, order: 1 */
        case AUDIO_CONFIG_HOA2: /* Ambisonics output, order: 2 */
        case AUDIO_CONFIG_HOA3: /* Ambisonics output, order: 3 */
            for ( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ )
            {
                set_zero( output_f[i], output_frame );
                set_zero( output[i], output_frame );
            }
            break;
        default:
+5 −5
Original line number Diff line number Diff line
@@ -775,7 +775,7 @@ void ivas_spar_get_parameters(
    const int16_t num_ch_out,
    const int16_t num_ch_in,
    const int16_t num_spar_bands,
    float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] )
    float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] )
{
    int16_t spar_band, out_ch, in_ch;
    float weight, weight_20ms;
@@ -797,19 +797,19 @@ void ivas_spar_get_parameters(
                {
                    if ( hSpar->i_subframe > 3 )
                    {
                        par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] +
                        mixer_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] +
                                                            weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band];
                    }
                    else
                    {
                        par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band];
                        mixer_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band];
                    }
                }
                else
                {
                    /* 20ms Transport channel reconstruction with matching encoder/decoder processing */
                    int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */
                    par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band];
                    mixer_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band];
                }
            }
        }
@@ -898,7 +898,7 @@ void ivas_spar_dec_upmixer(
    hSpar = st_ivas->hSpar;
    hDecoderConfig = st_ivas->hDecoderConfig;
    num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands;
    nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
    nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; // VE: == st_ivas->nchan_transport

    num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands;
    numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans;