From 55ffa15cf022ffdfd0da34c848bb6c25b56e355b Mon Sep 17 00:00:00 2001 From: rtyag Date: Fri, 19 Aug 2022 16:57:27 +1000 Subject: [PATCH] changes for issue 80, harmonize SBA SPAR normalization --- lib_com/cnst.h | 3 +-- lib_com/ivas_prot.h | 2 ++ lib_com/options.h | 1 + lib_dec/ivas_dec.c | 6 +++++- lib_dec/ivas_sba_rendering.c | 13 ++++++++++++- lib_dec/ivas_spar_decoder.c | 14 +++++++++++++- lib_enc/ivas_agc_enc.c | 20 ++++++++++++++++++++ lib_enc/ivas_spar_encoder.c | 27 ++++++++++++++++++++++----- 8 files changed, 76 insertions(+), 10 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 8e4c7c9908..40a4710579 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -67,8 +67,7 @@ #define MAX16B_FLT 32767.0f #define MIN16B_FLT ( -32768.0f ) #define PCM16_TO_FLT_FAC 32768.0f - - +#define MDFT_NORM_SCALING ( 1.0f / PCM16_TO_FLT_FAC ) #define MAX_FRAME_COUNTER 200 #define MAX_BITS_PER_FRAME 10240 /* Bits per frame for max. bitrate 512kbps */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 1abe8462cc..9f8192da26 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3702,7 +3702,9 @@ void ivas_spar_config( void ivas_sba_upmixer_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ float output[][L_FRAME48k], /* i/o: transport/output audio channels */ +#ifndef SPAR_SCALING_HARMONIZATION const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ +#endif const int16_t output_frame /* i : output frame length */ ); diff --git a/lib_com/options.h b/lib_com/options.h index 2ea2901adf..ad0aa3d961 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,6 +152,7 @@ #define LFE_NO_ENTROPY_CODING /* issue 65: changes to add no entropy coding in LFE */ #define FIX_79_MASA2TC_BITRATE_SWITCHING /* Nokia: Fix issue 79 on MASA 2TC bitrate switching crash in decoder. */ +#define SPAR_SCALING_HARMONIZATION /* issue 80: Changes to harmonize scaling in spar */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index a103c9f45f..b9923a87e7 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -345,7 +345,11 @@ ivas_error ivas_dec( } else /* SBA_MODE_SPAR */ { - ivas_sba_upmixer_renderer( st_ivas, output, nchan_remapped, output_frame ); /* Note: ivas_sba_linear_renderer() or ivas_dirac_dec() are called internally */ + ivas_sba_upmixer_renderer( st_ivas, output, +#ifndef SPAR_SCALING_HARMONIZATION + nchan_remapped, +#endif + output_frame ); /* Note: ivas_sba_linear_renderer() or ivas_dirac_dec() are called internally */ } } else if ( st_ivas->ivas_format == MC_FORMAT ) diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 41c46bccbe..17b564bf25 100755 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -205,19 +205,27 @@ static void ivas_sba_mtx_mult( void ivas_sba_upmixer_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ float output[][L_FRAME48k], /* i/o: transport/output audio channels */ +#ifndef SPAR_SCALING_HARMONIZATION const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ +#endif const int16_t output_frame /* i : output frame length */ ) { +#ifdef SPAR_SCALING_HARMONIZATION + int16_t i; +#else int16_t i, ch, nchan_out; +#endif float temp; int16_t nchan_internal; wmops_sub_start( "ivas_sba_upmixer_renderer" ); nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_order ); +#ifndef SPAR_SCALING_HARMONIZATION nchan_out = st_ivas->hDecoderConfig->nchan_out; - +#endif +#ifndef SPAR_SCALING_HARMONIZATION for ( ch = 0; ch < nchan_remapped; ch++ ) { for ( i = 0; i < output_frame; i++ ) @@ -237,6 +245,7 @@ void ivas_sba_upmixer_renderer( output[ch][i] = temp; } } +#endif if ( st_ivas->nchan_transport >= 3 ) { @@ -257,6 +266,7 @@ void ivas_sba_upmixer_renderer( ivas_sba_linear_renderer( output, output_frame, st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup, st_ivas->hoa_dec_mtx ); } +#ifndef SPAR_SCALING_HARMONIZATION for ( ch = 0; ch < nchan_out; ch++ ) { for ( i = 0; i < output_frame; i++ ) @@ -264,6 +274,7 @@ void ivas_sba_upmixer_renderer( output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC; } } +#endif wmops_sub_end(); diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 9842097187..85a912363c 100755 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -965,20 +965,32 @@ void ivas_spar_dec_upmixer( /*---------------------------------------------------------------------* * PCA decoder *---------------------------------------------------------------------*/ - #ifdef DEBUG_SBA_AUDIO_DUMP pState->pca_ingest_channels = num_in_ingest; #endif if ( hSpar->hPCA != NULL ) { +#ifdef SPAR_SCALING_HARMONIZATION + for ( out_ch = 0; out_ch < num_in_ingest; out_ch++ ) + { + v_multc( output[out_ch], MDFT_NORM_SCALING, output[out_ch], output_frame ); + } +#endif ivas_pca_dec( hSpar->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); #ifdef DEBUG_SBA_AUDIO_DUMP /* Dump audio signal after ivas_pca_dec */ ivas_spar_dump_signal_wav( output_frame, NULL, output, num_in_ingest, spar_foa_dec_wav[2], "ivas_pca_dec()" ); +#endif +#ifdef SPAR_SCALING_HARMONIZATION + for ( out_ch = 0; out_ch < num_in_ingest; out_ch++ ) + { + v_multc( output[out_ch], PCM16_TO_FLT_FAC, output[out_ch], output_frame ); + } #endif } + /*---------------------------------------------------------------------* * TD decorrelation *---------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 493d1ac071..c3c68efc72 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -242,7 +242,11 @@ void ivas_agc_enc_process( if ( !isClipped ) { +#ifdef SPAR_SCALING_HARMONIZATION + if ( ( ppPcm_out[i][j] > ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC ) || ( ppPcm_out[i][j] < MIN16B_FLT ) ) +#else if ( ( ppPcm_out[i][j] > ( 1.f - pState->minDelta ) ) || ( ppPcm_out[i][j] < -1.f ) ) +#endif { if ( j < offset ) { @@ -278,7 +282,11 @@ void ivas_agc_enc_process( maxGain = max( smoothedMaxAbsVal, MaxAbsVal ) * pState->gain_state[i].lastGain * 2.f; +#ifdef SPAR_SCALING_HARMONIZATION + if ( maxGain < ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC ) +#else if ( maxGain < 1.f - pState->minDelta ) +#endif { pState->gain_state[i].gainExpVal = -1; } @@ -313,7 +321,11 @@ void ivas_agc_enc_process( { int16_t isCompensated = FALSE; pState->gain_data[i].gainException = FALSE; +#ifdef SPAR_SCALING_HARMONIZATION + pState->gain_state[i].gainExpVal = (int16_t) ceilf( -logf( actualMaxAbsVal * MDFT_NORM_SCALING ) / logf( pState->agc_com.winFunc[MaxAbsValIdx] ) ); +#else pState->gain_state[i].gainExpVal = (int16_t) ceilf( -logf( actualMaxAbsVal ) / logf( pState->agc_com.winFunc[MaxAbsValIdx] ) ); +#endif while ( !isCompensated ) { @@ -324,7 +336,11 @@ void ivas_agc_enc_process( { tmpSignal = ppPcm_out[i][idx] * powf( pState->agc_com.winFunc[idx], (float) pState->gain_state[i].gainExpVal ); +#ifdef SPAR_SCALING_HARMONIZATION + if ( ( tmpSignal > ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC ) || ( tmpSignal < MIN16B_FLT ) ) +#else if ( ( tmpSignal > ( 1.f - pState->minDelta ) ) || ( tmpSignal < -1.f ) ) +#endif { isCompensated = FALSE; break; @@ -374,7 +390,11 @@ void ivas_agc_enc_process( } else { +#ifdef SPAR_SCALING_HARMONIZATION + pState->gain_state[i].gainExpVal = (int16_t) ( -floorf( -logf( ( actualMaxAbsVal + pState->minDelta ) * MDFT_NORM_SCALING ) * INV_LOG_2 ) ); +#else pState->gain_state[i].gainExpVal = (int16_t) ( -floorf( -logf( actualMaxAbsVal + pState->minDelta ) * INV_LOG_2 ) ); +#endif pState->gain_state[i].gainExpVal = min( gainExpValMaxRange, pState->gain_state[i].gainExpVal ); gain = powf( 2.0f, -1.0f * pState->gain_state[i].gainExpVal ); diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index ae9328404d..337d602011 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -279,7 +279,9 @@ ivas_error ivas_spar_enc( ) { ENCODER_CONFIG_HANDLE hEncoderConfig; - int16_t i, ch; +#ifndef SPAR_SCALING_HARMONIZATION + int16_t ch; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -291,14 +293,13 @@ ivas_error ivas_spar_enc( return error; } +#ifndef SPAR_SCALING_HARMONIZATION /* normalize input channels */ for ( ch = 0; ch < hEncoderConfig->nchan_inp; ch++ ) { - for ( i = 0; i < input_frame; i++ ) - { - data_f[ch][i] *= ( 1.0 / PCM16_TO_FLT_FAC ); - } + v_multc( data_f[ch], MDFT_NORM_SCALING, data_f[ch], input_frame ); } +#endif if ( hEncoderConfig->sba_planar ) { @@ -790,7 +791,19 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hPCA != NULL ) { +#ifdef SPAR_SCALING_HARMONIZATION + for ( int out_ch = 0; out_ch < FOA_CHANNELS; out_ch++ ) + { + v_multc( p_pcm_tmp[out_ch], MDFT_NORM_SCALING, p_pcm_tmp[out_ch], input_frame ); + } +#endif ivas_pca_enc( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp, input_frame, FOA_CHANNELS ); +#ifdef SPAR_SCALING_HARMONIZATION + for ( int out_ch = 0; out_ch < FOA_CHANNELS; out_ch++ ) + { + v_multc( p_pcm_tmp[out_ch], PCM16_TO_FLT_FAC, p_pcm_tmp[out_ch], input_frame ); + } +#endif } else { @@ -885,7 +898,11 @@ static ivas_error ivas_spar_enc_process( { for ( j = 0; j < nchan_transport; j++ ) { +#ifndef SPAR_SCALING_HARMONIZATION data_f[order[j]][i] = p_pcm_tmp[j][i] * PCM16_TO_FLT_FAC; +#else + data_f[order[j]][i] = p_pcm_tmp[j][i]; +#endif } for ( ; j < IVAS_SPAR_MAX_DMX_CHS; j++ ) { -- GitLab