diff --git a/lib_com/ivas_mcmasa_com.c b/lib_com/ivas_mcmasa_com.c index 34196431960ff0c06977c3703a7cb0632965f3d8..098b89e3a9635bd48cef6215d2f059ae956647df 100644 --- a/lib_com/ivas_mcmasa_com.c +++ b/lib_com/ivas_mcmasa_com.c @@ -34,8 +34,116 @@ #include "ivas_prot.h" #include "options.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif +#ifdef IVAS_FLOAT_FIXED +#define MCMASA_MONOBITRATIO_64k_Q31 ( 536870912 ) +#define MCMASA_MONOBITRATIO_Q31 ( 644245095 ) +/*--------------------------------------------------------------------------* + * ivas_mcmasa_setNumTransportChannels() + * + * Set number of transport channels in McMASA + *--------------------------------------------------------------------------*/ + +void ivas_mcmasa_setNumTransportChannels_fx( + Word16 *nchan_transport, /* o : Pointer to number of transport channels to be set */ + Word16 *element_mode, /* o : Pointer to element mode to be set */ + const Word32 ivas_total_brate /* i : Total bitrate of IVAS */ +) +{ + IF( GE_32( ivas_total_brate, IVAS_48k ) ) + { + *nchan_transport = 2; + move16(); + *element_mode = IVAS_CPE_MDCT; + move16(); + } + ELSE + { + *nchan_transport = 1; + move16(); + *element_mode = IVAS_SCE; + move16(); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_mcmasa_set_separate_channel_mode() + * + * Set separate channel parameters in McMASA based on bitrate + *--------------------------------------------------------------------------*/ + +void ivas_mcmasa_set_separate_channel_mode_fx( + UWord8 *separateChannelEnabled, /* o : Pointer to separate channel toggle */ + Word16 *separateChannelIndex, /* o : Pointer to separate channel index */ + const Word32 ivas_total_brate /* i : Total bitrate of IVAS */ +) +{ + IF( GE_32( ivas_total_brate, MCMASA_SEPARATE_BRATE ) ) + { + *separateChannelEnabled = 1; + *separateChannelIndex = 2; /* Center channel */ + move16(); + } + ELSE + { + *separateChannelEnabled = 0; + *separateChannelIndex = 0; + move16(); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_mcmasa_split_brate() + * + * Split the total bitrate to elements in McMASA + *--------------------------------------------------------------------------*/ + +void ivas_mcmasa_split_brate_fx( + const UWord8 separateChannelEnabled, /* i : Transport running in "separate channel" mode */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate available to be split */ + const Word16 nSCE, /* i : Number of SCEs in use (0 or 1) */ + const Word16 nCPE, /* i : Number of CPEs in use (0 or 1) */ + Word32 *brate_sce, /* o : Pointer to SCE element bitrate */ + Word32 *brate_cpe /* o : Pointer to CPE element bitrate */ +) +{ + IF( separateChannelEnabled ) + { + /* 25% of total bitrate is used for SCE below 96 kb/s (separated mono channel), otherwise 30% */ + IF( LT_32( ivas_total_brate, IVAS_96k ) ) + { + *brate_sce = (Word32) ( Mpy_32_32( MCMASA_MONOBITRATIO_64k_Q31, ivas_total_brate ) ); // Q0 + } + ELSE + { + *brate_sce = (Word32) ( Mpy_32_32( MCMASA_MONOBITRATIO_Q31, ivas_total_brate ) ); // Q0 + } + + *brate_cpe = L_sub( ivas_total_brate, *brate_sce ); + } + ELSE + { + Word16 tmp_e = 0; + Word16 tmp = BASOP_Util_Divide3216_Scale( ivas_total_brate, ( add( nCPE, nSCE ) ), &tmp_e ); + *brate_sce = GT_16( nSCE, 0 ) ? ( L_shr( (Word32) tmp, negate( add( 1, tmp_e ) ) ) ) : 0; + move32(); + *brate_cpe = GT_16( nCPE, 0 ) ? ( L_shr( (Word32) tmp, negate( add( 1, tmp_e ) ) ) ) : 0; + move32(); + } + + return; +} +#endif /*--------------------------------------------------------------------------* * ivas_mcmasa_setNumTransportChannels() * diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 8dfa630f500886ded777c6a8b749aabdd1c1afc2..c111f0d22164db8938dfd939d2bc66145525faa4 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -544,4 +544,25 @@ void stereo_cng_compute_PScorr_fx( const Word16 L_frame_1 /* i : L_frame channel 1 */ ); +void ivas_mcmasa_setNumTransportChannels_fx( + Word16 *nchan_transport, /* o : Pointer to number of transport channels to be set */ + Word16 *element_mode, /* o : Pointer to element mode to be set */ + const Word32 ivas_total_brate /* i : Total bitrate of IVAS */ +); + +void ivas_mcmasa_set_separate_channel_mode_fx( + UWord8 *separateChannelEnabled, /* o : Pointer to separate channel toggle */ + Word16 *separateChannelIndex, /* o : Pointer to separate channel index */ + const Word32 ivas_total_brate /* i : Total bitrate of IVAS */ +); + +void ivas_mcmasa_split_brate_fx( + const UWord8 separateChannelEnabled, /* i : Transport running in "separate channel" mode */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate available to be split */ + const Word16 nSCE, /* i : Number of SCEs in use (0 or 1) */ + const Word16 nCPE, /* i : Number of CPEs in use (0 or 1) */ + Word32 *brate_sce, /* o : Pointer to SCE element bitrate */ + Word32 *brate_cpe /* o : Pointer to CPE element bitrate */ +); + #endif \ No newline at end of file diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 134c89dc9bd67734f1be190ba3c6679cd72d5850..ae58fda4cdd1069f934404074743b88aa4d44af7 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -908,9 +908,15 @@ ivas_error ivas_init_decoder( IF ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) { +#ifdef IVAS_FLOAT_FIXED + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); + + ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); +#else ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); +#endif } ivas_renderer_select( st_ivas ); @@ -927,7 +933,11 @@ ivas_error ivas_init_decoder( IF ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) { +#ifdef IVAS_FLOAT_FIXED + ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); +#else ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); +#endif IF ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.separateChannelEnabled ) { @@ -1530,7 +1540,11 @@ ivas_error ivas_init_decoder( { Word32 brate_sce, brate_cpe; +#ifdef IVAS_FLOAT_FIXED + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); +#else ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); +#endif IF ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { @@ -1570,7 +1584,11 @@ ivas_error ivas_init_decoder( } } +#ifdef IVAS_FLOAT_FIXED + ivas_mcmasa_split_brate_fx( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); +#else ivas_mcmasa_split_brate( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); +#endif FOR ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 63ad353a19dc389b02282a4956e1a445124181fd..e3f5fc3cb877db34d650f2d5b72f188959b9d536 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -63,15 +63,24 @@ ivas_error ivas_mcmasa_dec_reconfig( #endif /* get new McMASA settings */ +#ifdef IVAS_FLOAT_FIXED + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); + ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); +#else ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); +#endif /* transport channel settings may affect renderer */ ivas_renderer_select( st_ivas ); /* renderer change may affect internal config */ ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); +#ifdef IVAS_FLOAT_FIXED + ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); +#else ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); +#endif #ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 64344b712bacf2c5925d6637c9f6e51b3a9b9468..3c971f231e5c23a7194c81f7a1497179216bba21 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1025,7 +1025,11 @@ static ivas_error ivas_mc_dec_reconfig( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { +#ifdef IVAS_FLOAT_FIXED + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); +#else ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); +#endif if ( last_mc_mode != MC_MODE_MCMASA ) { @@ -1136,8 +1140,13 @@ static ivas_error ivas_mc_dec_reconfig( { uint8_t separateChannelEnabled; int16_t separateChannelIndex; +#ifdef IVAS_FLOAT_FIXED + ivas_mcmasa_set_separate_channel_mode_fx( &separateChannelEnabled, &separateChannelIndex, ivas_total_brate ); + ivas_mcmasa_split_brate_fx( separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); +#else ivas_mcmasa_set_separate_channel_mode( &separateChannelEnabled, &separateChannelIndex, ivas_total_brate ); ivas_mcmasa_split_brate( separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); +#endif } else if ( st_ivas->mc_mode == MC_MODE_MCT ) {