Commit 8106a458 authored by vaclav's avatar vaclav
Browse files

fixes towards support of 'stereo' output

parent de5ff795
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@

#ifdef DEBUGGING

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

#define DEBUG_MODE_INFO                     /* output most important parameters to the subdirectory "res/" */
#ifdef DEBUG_MODE_INFO
+5 −9
Original line number Diff line number Diff line
@@ -601,7 +601,7 @@ ivas_error ivas_init_decoder(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure        */
)
{
    int16_t i, k, n;
    int16_t i, n;
    int16_t sce_id, cpe_id;
    int16_t numCldfbAnalyses;
    int16_t numCldfbSyntheses;
@@ -815,13 +815,11 @@ ivas_error ivas_init_decoder(
        }
    }
    else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
    {
    {
        if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
        {
            return error;
        }
        }

        if ( st_ivas->ivas_format == MASA_FORMAT )
        {
@@ -858,10 +856,8 @@ ivas_error ivas_init_decoder(
                    {
                        return error;
                    }
                    for ( k = 0; k < DIRAC_MAX_NBANDS; k++ )
                    {
                        st_ivas->hSpar->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k];
                    }

                    mvs2s( 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;
                }
                else
+259 −160
Original line number Diff line number Diff line
@@ -451,20 +451,16 @@ ivas_error ivas_sba_dec_reconfigure(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
)
{
    int16_t n;
    int16_t i, n;
    int16_t sce_id, cpe_id;
    int16_t nchan_transport;
    int16_t nchan_transport_old;
    int16_t nchan_transport, nchan_transport_old;
#ifndef SBA_BITRATE_SWITCHING
    int32_t sba_total_brate;
    int16_t nSCE_old;
    int16_t nCPE_old;
#endif
    int16_t nSCE_old, nCPE_old;
    AUDIO_CONFIG intern_config_old;
    int16_t numCldfbAnalyses_old;
    int16_t numCldfbAnalyses;
    int16_t numCldfbSyntheses;
    int16_t numCldfbSyntheses_old;
    int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses_old, numCldfbSyntheses;
    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;
@@ -484,7 +480,9 @@ ivas_error ivas_sba_dec_reconfigure(
#endif
    ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
    numCldfbAnalyses = 0;
#ifndef SBA_BITRATE_SWITCHING
    sba_total_brate = ivas_total_brate;
#endif

    nSCE_old = st_ivas->nSCE;
    nCPE_old = st_ivas->nCPE;
@@ -502,6 +500,7 @@ ivas_error ivas_sba_dec_reconfigure(
    st_ivas->nchan_transport = nchan_transport;
#endif

#ifndef SBA_BITRATE_SWITCHING
    /* renderer might have changed */
    intern_config_old = st_ivas->intern_config;
    ivas_renderer_select( st_ivas );
@@ -511,6 +510,7 @@ ivas_error ivas_sba_dec_reconfigure(
    {
        ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
    }
#endif

    if ( st_ivas->sba_mode != SBA_MODE_SPAR )
    {
@@ -538,6 +538,8 @@ ivas_error ivas_sba_dec_reconfigure(
                return error;
            }
        }

        st_ivas->sba_dirac_stereo_flag = 0;
#endif

        sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER );
@@ -563,6 +565,19 @@ ivas_error ivas_sba_dec_reconfigure(
    }
#endif

#ifdef SBA_BITRATE_SWITCHING
    /* renderer might have changed */
    intern_config_old = st_ivas->intern_config;
    ivas_renderer_select( st_ivas );

    /* side effect of the renderer selection can be a changed internal config */
    if ( st_ivas->intern_config != intern_config_old )
    {
        ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
    }
#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 ) )
    {
@@ -583,6 +598,7 @@ 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 )
    //else if ( ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC || st_ivas->renderer_type == RENDERER_DIRAC ) && st_ivas->sba_mode == SBA_MODE_SPAR )
    {
        if ( st_ivas->hDirAC != NULL )
        {
@@ -598,11 +614,7 @@ ivas_error ivas_sba_dec_reconfigure(
                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 );
            mvs2s( 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;
        }
    }
@@ -649,6 +661,48 @@ ivas_error ivas_sba_dec_reconfigure(
            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() */
        }

#ifdef SBA_BITRATE_SWITCHING
        if ( st_ivas->hSCE[0] != NULL ) // VE: TBV if code below can be reused
        {
            if ( st_ivas->sba_dirac_stereo_flag )
            {
                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
            {
                st_ivas->hSCE[0]->save_synth = NULL;
                st_ivas->hSCE[0]->save_hb_synth = NULL;
            }
        }


        /* 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 */
        }
        else
        {
        }
#endif

        for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
        {
            st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
@@ -799,6 +853,10 @@ ivas_error ivas_sba_dec_reconfigure(
            }
        }

#ifdef SBA_BITRATE_SWITCHING
    }
#endif

    /*-----------------------------------------------------------------*
         * HP20 memories
         *-----------------------------------------------------------------*/
@@ -868,11 +926,11 @@ ivas_error ivas_sba_dec_reconfigure(
        }

        for ( i = 0; i < n; i++ )

        {
            st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i];
            old_mem_hp20_out[i] = NULL;
        }

        for ( ; i < nchan_transport_old; i++ )
        {
            count_free( old_mem_hp20_out[i] );
@@ -882,8 +940,49 @@ ivas_error ivas_sba_dec_reconfigure(
        count_free( old_mem_hp20_out );
        old_mem_hp20_out = NULL;
    }
#ifdef SBA_BITRATE_SWITCHING
    else if( st_ivas->sba_dirac_stereo_flag != sba_dirac_stereo_flag_old ) // VE: needs more work once SBA low-bitrate coding is updated
    {
        if( st_ivas->sba_dirac_stereo_flag )
        {
            float **old_mem_hp20_out;
            old_mem_hp20_out = st_ivas->mem_hp20_out;

            if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( 2 * sizeof( float * ) ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
            }

            st_ivas->mem_hp20_out[0] = old_mem_hp20_out[0];

            if ( ( st_ivas->mem_hp20_out[1] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
            }

            set_f( st_ivas->mem_hp20_out[1], 0.0f, L_HP20_MEM );
        }
        else
        {
            if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( 1 * sizeof( float * ) ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
            }

            if( st_ivas->mem_hp20_out[1] != NULL )
            {
            }

            count_free( st_ivas->mem_hp20_out[1] );
            st_ivas->mem_hp20_out[1] = NULL;

        }
    }
#endif
#ifndef SBA_BITRATE_SWITCHING
}
#endif

/*-----------------------------------------------------------------*
     * CLDFB instances
     *-----------------------------------------------------------------*/
+1 −1
Original line number Diff line number Diff line
@@ -876,7 +876,7 @@ typedef struct ivas_spar_dec_lib_t
    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;
    int32_t i_subframe; // VE2DB: change to int16_t

#ifdef DEBUG_SBA_AUDIO_DUMP
    int16_t numOutChannels;