Commit de5ff795 authored by vaclav's avatar vaclav
Browse files

first bunch of fixes; under SBA_BITRATE_SWITCHING

parent 4fc98050
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -3879,6 +3879,14 @@ void ivas_spar_md_enc_close(
    ivas_spar_md_enc_state_t **hMdEnc                           /* i/o: SPAR MD encoder handle                  */
);

#ifdef SBA_BITRATE_SWITCHING
ivas_error ivas_spar_md_enc_init(
    ivas_spar_md_enc_state_t *hMdEnc,                           /* o  : MD encoder handle                       */
    const ENCODER_CONFIG_HANDLE hEncoderConfig,                 /* i  : configuration structure                 */
    const int16_t sba_order                                     /* i  : Ambisonic (SBA) order                   */
);
#endif

ivas_error ivas_spar_md_enc_process(
    ivas_spar_md_enc_state_t *hMdEnc,                           /* i/o: SPAR MD encoder handle                  */
    const ENCODER_CONFIG_HANDLE hEncoderConfig,                 /* i  : configuration structure                 */
+2 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@

/*#define MEM_COUNT_DETAILS*/                   /* RAM counting tool: print per sub-structure details */

/*#define DEBUG_MODE_INFO*/                     /* output most important parameters to the subdirectory "res/" */
#define DEBUG_MODE_INFO                     /* output most important parameters to the subdirectory "res/" */
#ifdef DEBUG_MODE_INFO
/*#define DEBUG_MODE_ACELP*/                    /* output most important ACELP core parameters to the subdirectory "res/" */
/*#define DEBUG_MODE_TCX*/                      /* output most important TCX core parameters to the subdirectory "res/" */
@@ -149,6 +149,7 @@
#define SPAR_SCALING_HARMONIZATION                      /* Issue 80: Changes to harmonize scaling in spar */
#define SBA_INTERN_CONFIG_FIX_HOA2                      /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/
#define FIX_I98_HANDLES_TO_NULL                         /* Issue 98: do the setting of all handles to NULL in one place */
#define SBA_BITRATE_SWITCHING                           /* Issue 114: suppport bitrate switching in SBA */


/* ################## End DEVELOPMENT switches ######################### */
+94 −13
Original line number Diff line number Diff line
@@ -466,8 +466,10 @@ ivas_error ivas_sba_dec_reconfigure(
    int16_t sba_dirac_stereo_flag_old;
    uint16_t i;
    int32_t ivas_total_brate, last_ivas_total_brate;
    DECODER_CONFIG_HANDLE hDecoderConfig;
    ivas_error error;

    hDecoderConfig = st_ivas->hDecoderConfig;
    error = IVAS_ERR_OK;

    ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
@@ -477,6 +479,9 @@ ivas_error ivas_sba_dec_reconfigure(
     * Allocate, initalize, and configure SBA and rendering handles
     *-----------------------------------------------------------------*/

#ifdef SBA_BITRATE_SWITCHING
    st_ivas->sba_mode = ivas_sba_mode_select( last_ivas_total_brate );
#endif
    ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
    numCldfbAnalyses = 0;
    sba_total_brate = ivas_total_brate;
@@ -486,10 +491,16 @@ ivas_error ivas_sba_dec_reconfigure(
    nchan_transport_old = st_ivas->nchan_transport;
    sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag;

#ifdef SBA_BITRATE_SWITCHING
    st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate );
#endif

    st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order );

#ifndef SBA_BITRATE_SWITCHING
    ivas_sba_config( sba_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode );
    st_ivas->nchan_transport = nchan_transport;
#endif

    /* renderer might have changed */
    intern_config_old = st_ivas->intern_config;
@@ -503,7 +514,13 @@ ivas_error ivas_sba_dec_reconfigure(

    if ( st_ivas->sba_mode != SBA_MODE_SPAR )
    {
        st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO );
#ifdef SBA_BITRATE_SWITCHING
        ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs );
        st_ivas->hSpar = NULL;
#endif

        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;
@@ -513,16 +530,39 @@ ivas_error ivas_sba_dec_reconfigure(
    {
        int16_t sba_order_internal;

#ifdef SBA_BITRATE_SWITCHING
        if ( st_ivas->hSpar == NULL )
        {
            if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
#endif

        sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER );
        ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format );
        ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format );

        if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar,
        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, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }

#ifdef SBA_BITRATE_SWITCHING
    nchan_transport = st_ivas->nchan_transport;

    if ( nchan_transport == 1 )
    {
        st_ivas->element_mode_init = IVAS_SCE;
    }
    else
    {
        st_ivas->element_mode_init = IVAS_CPE_MDCT;
    }
#endif

    if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC &&
         ( last_ivas_total_brate > IVAS_SID_4k4 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) )
    {
@@ -541,6 +581,47 @@ ivas_error ivas_sba_dec_reconfigure(
            }
        }
    }
#ifdef SBA_BITRATE_SWITCHING // VE: TBD - possibly merge with the above
    else if( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode == SBA_MODE_SPAR )
    {
        if ( st_ivas->hDirAC != NULL )
        {
            if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else
        {
            if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            for ( n = 0; n < DIRAC_MAX_NBANDS; n++ )
            {
                st_ivas->hSpar->dirac_to_spar_md_bands[n] = st_ivas->hDirAC->dirac_to_spar_md_bands[n];
            }
            //mvr2r( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS );
            st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
        }
    }
#endif
#ifdef SBA_BITRATE_SWITCHINGaa
    else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode == SBA_MODE_SPAR ) )
    {
        if ( st_ivas->hDirAC != NULL )
        {
            ivas_dirac_dec_close( st_ivas->hDirAC );
            st_ivas->hDirAC = NULL;
        }

        if ( st_ivas->hVBAPdata != NULL )
        {
            vbap_free_data( &( st_ivas->hVBAPdata ) );
        }
    }
#endif
    else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) )
    {
        if ( st_ivas->hDirAC != NULL )
@@ -833,7 +914,7 @@ ivas_error ivas_sba_dec_reconfigure(
        /* create additional CLDFB synthesis instances */
        for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ )
        {
            if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
            if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
            {
                return error;
            }
@@ -855,7 +936,7 @@ ivas_error ivas_sba_dec_reconfigure(
        /* create additional CLDFB synthesis instances */
        for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ )
        {
            if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
            if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
            {
                return error;
            }
+15 −7
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@
 * Local function prototypes
 *--------------------------------------------------------------------*/

static void ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 );
static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 );


/*-------------------------------------------------------------------------
@@ -254,7 +254,7 @@ ivas_error ivas_spar_dec(
    st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
    st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */

    ivas_spar_dec_MD( st_ivas, st0 );
    error = ivas_spar_dec_MD( st_ivas, st0 );

    *nb_bits_read = st0->next_bit_pos + nb_bits_read_orig;
    st0->bit_stream = bit_stream_orig;
@@ -604,18 +604,23 @@ int16_t ivas_is_res_channel(
 * IVAS SPAR MD decoder
 *-------------------------------------------------------------------*/

static void ivas_spar_dec_MD(
static ivas_error ivas_spar_dec_MD(
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle                             */
    Decoder_State *st0       /* i/o: decoder state structure - for bitstream handling*/
)
{
    int16_t num_channels, table_idx, num_bands_out, bfi, sba_order;
    int32_t ivas_total_brate;
    DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig;
    SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
    DECODER_CONFIG_HANDLE hDecoderConfig;
    SPAR_DEC_HANDLE hSpar;
    ivas_error error;

    wmops_sub_start( "ivas_spar_dec_MD" );

    hDecoderConfig = st_ivas->hDecoderConfig;
    hSpar = st_ivas->hSpar;
    error = IVAS_ERR_OK;

    /*---------------------------------------------------------------------*
     * Initialization
     *---------------------------------------------------------------------*/
@@ -639,7 +644,10 @@ static void ivas_spar_dec_MD(
                hSpar->hMdDec->table_idx = table_idx;
                hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking;

                ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels );
                if ( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
        }

@@ -693,7 +701,7 @@ static void ivas_spar_dec_MD(
    }

    wmops_sub_end();
    return;
    return error;
}


+1 −1
Original line number Diff line number Diff line
@@ -873,7 +873,7 @@ typedef struct ivas_spar_dec_lib_t
    int16_t AGC_flag;
    ivas_agc_dec_state_t *hAgcDec;
    PCA_DEC_STATE *hPCA;
    int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS];
    int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; // VE2DB: could only hDirAC->dirac_to_spar_md_bands be used all the time, or it is defined as a pointer here?
    int16_t enc_param_start_band;
    int32_t core_nominal_brate; /* Nominal bitrate for core coding  */
    int32_t i_subframe;
Loading