From 22a43701068c2512e0643f2075e56848ec960ff5 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 23 Apr 2026 14:00:47 +0300 Subject: [PATCH 1/5] Fix float issue 1578 by adjusting the stereo type detection. --- lib_com/ivas_cnst.h | 5 + lib_com/options.h | 1 + lib_dec/ivas_dirac_dec.c | 4 + lib_rend/ivas_dirac_output_synthesis_dec.c | 7 + lib_rend/ivas_dirac_rend.c | 220 +++++++++++++++++++++ lib_rend/ivas_prot_rend.h | 5 + lib_rend/ivas_stat_rend.h | 6 + lib_rend/lib_rend.c | 4 + 8 files changed, 252 insertions(+) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 47b878bab..c02b1833d 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1216,7 +1216,12 @@ typedef enum { MASA_STEREO_NOT_DEFINED, MASA_STEREO_SPACED_MICS, +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + MASA_STEREO_DOWNMIX, + MASA_DUAL_MONO +#else MASA_STEREO_DOWNMIX +#endif } MASA_TRANSPORT_SIGNAL_TYPE; typedef enum diff --git a/lib_com/options.h b/lib_com/options.h index 1b2eded86..aae502d81 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -178,6 +178,7 @@ #define FIX_FLOAT_1573_POSITION_UPDATE /* Eri: Float issue 1573: For static orientation and listener movement, the PoseUpdated flag is cleared and prevents 5 ms update rate. */ #define FIX_1576_LCLD_CRASH_DIFFERENT_CODEC_ISAR_FRAME_SIZE /* Dolby: float issue 1576: fix for crash in LCLD mode when codec frame size is less than isar frame size */ #define FIX_1452_DEFAULT_REVERB /* Nokia/Philips/FhG: Fix default room presets and their usage in renderer */ +#define FIX_FLOAT_1578_OMASA_REND_SPIKES /* Nokia: Float issue 1578: Fix spikes and collapsed perception in OMASA/MASA rendering to FOA/HOA */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 0b5f02fa0..1ff5b1e76 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -274,7 +274,11 @@ static ivas_error ivas_dirac_rend_config( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect, ivas_total_brate ); +#else ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect ); +#endif } else { diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 1f0f816f5..f25047762 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -1761,6 +1761,13 @@ void ivas_dirac_dec_compute_directional_responses( direct_response[1] = 1.0f; } } +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + else if ( transport_signal_type == MASA_DUAL_MONO ) + { + direct_response[0] = 1.0f; + /* direct_response[1] is not adjusted for dual mono input */ + } +#endif else { set_f( direct_response, 1.0f, hDirACRend->num_protos_ambi ); diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index b56fe1ac0..f32a704e8 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -45,6 +45,15 @@ #endif #include "wmc_auto.h" +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES +/*------------------------------------------------------------------------------------------* + * Local constants + *------------------------------------------------------------------------------------------*/ + +/* Constants for MASA dual mono detection */ +#define MASA_DUAL_MONO_TAU1 0.01562500000000000f /* 2^-6, which is about -18 dB */ +#define MASA_DUAL_MONO_TAU2 0.00000762939453125f /* 2^-17, which is about -51 dB */ +#endif /*------------------------------------------------------------------------- * ivas_dirac_allocate_parameters() @@ -1328,9 +1337,18 @@ void protoSignalComputation2( float interpolatorSpaced = 0.0f; float interpolatorDmx = 1.0f; +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + float interpolatorDualMono = 0.0f; + int16_t max_band_diff_ene; +#endif int16_t dipole_freq_range[2]; +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + float tempSpaced, tempDmx, tempDualMono; + max_band_diff_ene = min( stereo_type_detect->max_band_diff_ene, num_freq_bands ); /* Local version for correct maximum */ +#else float tempSpaced, tempDmx; +#endif if ( isloudspeaker ) { @@ -1381,6 +1399,11 @@ void protoSignalComputation2( right_hi_power = 0.0f; total_hi_power = 0.0f; +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + stereo_type_detect->inst_diff_bb_power = 0.0f; + stereo_type_detect->inst_total_bb_power = 0.0f; + +#endif dipole_freq_range[0] = stereo_type_detect->dipole_freq_range[0]; dipole_freq_range[1] = stereo_type_detect->dipole_freq_range[1]; @@ -1395,11 +1418,26 @@ void protoSignalComputation2( { interpolatorSpaced = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); interpolatorDmx = 1.0f - interpolatorSpaced; +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + interpolatorDualMono = interpolatorDmx; +#endif } +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + else if ( stereo_type_detect->type_change_direction == MASA_DUAL_MONO ) { + interpolatorDualMono = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); + interpolatorDmx = 1.0f - interpolatorDualMono; + interpolatorSpaced = interpolatorDmx; + } + else /* MASA_STEREO_DOWNMIX */ +#else else +#endif { interpolatorDmx = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); interpolatorSpaced = 1.0f - interpolatorDmx; +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + interpolatorDualMono = interpolatorSpaced; +#endif } } @@ -1439,18 +1477,39 @@ void protoSignalComputation2( sum_total_ratio[l] = stereo_type_detect->sum_power[l] / ( stereo_type_detect->total_power[l] + EPSILON ); } +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + if ( l < max_band_diff_ene ) + { + RealSubtract = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + ImagSubtract = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + stereo_type_detect->inst_diff_bb_power += RealSubtract * RealSubtract + ImagSubtract * ImagSubtract; + + if ( l == max_band_diff_ene - 1 ) + { + /* Stores sum of reference power (i.e., sum of transport channels) up to max_band_diff_ene - 1. */ + stereo_type_detect->inst_total_bb_power = total_bb_power; /* Total energy before smoothing */ + } + + if ( l == 0 ) + { + stereo_type_detect->subtract_power_y += RealSubtract * RealSubtract + ImagSubtract * ImagSubtract; + } + } +#else if ( l == 0 ) { RealSubtract = RealBuffer[0][0][l] - RealBuffer[1][0][l]; ImagSubtract = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; stereo_type_detect->subtract_power_y += RealSubtract * RealSubtract + ImagSubtract * ImagSubtract; } +#endif /* Compute protos (and their power) for direct sound rendering */ /* W prototype */ if ( stereo_type_detect->interpolator > 0 ) { +#ifndef FIX_FLOAT_1578_OMASA_REND_SPIKES if ( l < ( dipole_freq_range[1] - 1 ) || l >= MASA_SUM_PROTO_START_BIN ) { Real_aux = interpolatorSpaced * 0.5f * Real_aux + interpolatorDmx * Real_aux; @@ -1467,6 +1526,59 @@ void protoSignalComputation2( p_proto_buffer[2 * l] = interpolatorSpaced * RealBuffer[0][0][l] + interpolatorDmx * Real_aux; p_proto_buffer[2 * l + 1] = interpolatorSpaced * ImagBuffer[0][0][l] + interpolatorDmx * Imag_aux; } +#else + if ( (stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_STEREO_DOWNMIX ) || + ( stereo_type_detect->type_change_direction == MASA_STEREO_DOWNMIX && stereo_type_detect->current_stereo_type == MASA_STEREO_SPACED_MICS ) ) + { + if ( l < ( dipole_freq_range[1] - 1 ) || l >= MASA_SUM_PROTO_START_BIN ) + { + Real_aux = interpolatorSpaced * 0.5f * Real_aux + interpolatorDmx * Real_aux; + Imag_aux = interpolatorSpaced * 0.5f * Imag_aux + interpolatorDmx * Imag_aux; + proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + } + else + { + tempSpaced = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; + tempDmx = Real_aux * Real_aux + Imag_aux * Imag_aux; + proto_power_smooth[l] += interpolatorSpaced * tempSpaced + interpolatorDmx * tempDmx; + p_proto_buffer[2 * l] = interpolatorSpaced * RealBuffer[0][0][l] + interpolatorDmx * Real_aux; + p_proto_buffer[2 * l + 1] = interpolatorSpaced * ImagBuffer[0][0][l] + interpolatorDmx * Imag_aux; + } + } + else if ( ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_DUAL_MONO ) || + ( stereo_type_detect->type_change_direction == MASA_DUAL_MONO && stereo_type_detect->current_stereo_type == MASA_STEREO_SPACED_MICS ) ) + { + if ( l < ( dipole_freq_range[1] - 1 ) || l >= MASA_SUM_PROTO_START_BIN ) + { + Real_aux *= 0.5f; + Imag_aux *= 0.5f; + proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + } + else + { + tempSpaced = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; + Real_aux *= 0.5f; + Imag_aux *= 0.5f; + tempDualMono = Real_aux * Real_aux + Imag_aux * Imag_aux; + proto_power_smooth[l] += interpolatorSpaced * tempSpaced + interpolatorDualMono * tempDualMono; + p_proto_buffer[2 * l] = interpolatorSpaced * RealBuffer[0][0][l] + interpolatorDualMono * Real_aux; + p_proto_buffer[2 * l + 1] = interpolatorSpaced * ImagBuffer[0][0][l] + interpolatorDualMono * Imag_aux; + } + } + else /* MASA_STEREO_DOWNMIX <-> MASA_DUAL_MONO */ + { + /* Both use same proto but dual mono has 0.5 scaling */ + Real_aux = interpolatorDualMono * 0.5f * Real_aux + interpolatorDmx * Real_aux; + Imag_aux = interpolatorDualMono * 0.5f * Imag_aux + interpolatorDmx * Imag_aux; + proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + } +#endif } else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) { @@ -1485,7 +1597,19 @@ void protoSignalComputation2( p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l]; } } +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + else if ( stereo_type_detect->masa_stereo_type == MASA_DUAL_MONO ) + { + Real_aux *= 0.5f; + Imag_aux *= 0.5f; + proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + } + else /* MASA_STEREO_DOWNMIX */ +#else else +#endif { proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; p_proto_buffer[2 * l] = Real_aux; @@ -1495,6 +1619,7 @@ void protoSignalComputation2( /* Y prototype */ if ( stereo_type_detect->interpolator > 0 ) { +#ifndef FIX_FLOAT_1578_OMASA_REND_SPIKES if ( l < ( dipole_freq_range[0] ) ) { p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); @@ -1509,7 +1634,51 @@ void protoSignalComputation2( { p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); +#else + if ( (stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_STEREO_DOWNMIX ) || + ( stereo_type_detect->type_change_direction == MASA_STEREO_DOWNMIX && stereo_type_detect->current_stereo_type == MASA_STEREO_SPACED_MICS ) ) + { + if ( l < ( dipole_freq_range[0] ) ) + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + } + else if ( l < ( dipole_freq_range[1] ) ) + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ) + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * ( -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ) ) + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + } + else + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + } + } + else if ( ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_DUAL_MONO ) || + ( stereo_type_detect->type_change_direction == MASA_DUAL_MONO && stereo_type_detect->current_stereo_type == MASA_STEREO_SPACED_MICS ) ) + { + if ( l < ( dipole_freq_range[0] ) ) + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + } + else if ( l < ( dipole_freq_range[1] ) ) + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ) + interpolatorDualMono * p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * ( -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ) ) + interpolatorDualMono * p_proto_buffer[2 * l + 1]; + } + else + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + } } + else /* MASA_STEREO_DOWNMIX <-> MASA_DUAL_MONO */ + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorDualMono * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorDualMono * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + } +#endif proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; } else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) @@ -1533,7 +1702,18 @@ void protoSignalComputation2( proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; } } +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + else if ( stereo_type_detect->masa_stereo_type == MASA_DUAL_MONO ) + { + /* proto = W */ + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; + } + else /* MASA_STEREO_DOWNMIX */ +#else else +#endif { p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; @@ -1821,7 +2001,12 @@ void computeDirectionAngles( *------------------------------------------------------------------------*/ void ivas_masa_init_stereotype_detection( +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + MASA_STEREO_TYPE_DETECT *stereo_type_detect, + int32_t ivas_total_brate ) +#else MASA_STEREO_TYPE_DETECT *stereo_type_detect ) +#endif { stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; @@ -1853,6 +2038,17 @@ void ivas_masa_init_stereotype_detection( stereo_type_detect->min_sum_total_ratio_db = 0.0f; stereo_type_detect->subtract_target_ratio_db = 0.0f; +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + stereo_type_detect->inst_diff_bb_power = 0.0f; + stereo_type_detect->inst_total_bb_power = 0.0f; + + stereo_type_detect->max_band_diff_ene = IVAS_CLDFB_NO_CHANNELS_MAX; + if ( ivas_total_brate < IVAS_48k ) + { + stereo_type_detect->max_band_diff_ene = 18; + } + +#endif return; } @@ -1879,7 +2075,23 @@ void ivas_masa_stereotype_detection( float min_sum_temp; float lr_total_bb_temp; float lr_total_hi_temp; +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + int16_t change_to_dual_mono_selection; + float diffPerSum; + + /* Determine if broadband energy and ratio between difference broadband energy and broadband energy indicate + * that the signal type is dual mono */ + change_to_dual_mono_selection = 0; + if ( stereo_type_detect->inst_total_bb_power > 1.0f ) + { + diffPerSum = stereo_type_detect->inst_diff_bb_power / stereo_type_detect->inst_total_bb_power; + if ( diffPerSum < ( stereo_type_detect->current_stereo_type == MASA_DUAL_MONO ? MASA_DUAL_MONO_TAU1 : MASA_DUAL_MONO_TAU2 ) ) + { + change_to_dual_mono_selection = 1; + } + } +#endif /* Determine if the determined features match the spaced mic type */ change_to_spaced_selection = 0; if ( subtract_target_ratio_db < -3.0f ) @@ -1933,7 +2145,15 @@ void ivas_masa_stereotype_detection( } else { +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + if ( change_to_dual_mono_selection == 1 ) + { + stereo_type_detect->masa_stereo_type = MASA_DUAL_MONO; + } + else if ( change_to_spaced_selection == 1 ) +#else if ( change_to_spaced_selection == 1 ) +#endif { stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS; } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index a4241eb37..49d889b97 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -341,7 +341,12 @@ void computeDirectionAngles( ); void ivas_masa_init_stereotype_detection( +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + MASA_STEREO_TYPE_DETECT *stereo_type_detect, + int32_t ivas_total_brate +#else MASA_STEREO_TYPE_DETECT *stereo_type_detect +#endif ); void ivas_masa_stereotype_detection( diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 9ed6d300e..3467424c3 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -310,6 +310,12 @@ typedef struct float min_sum_total_ratio_db; float subtract_target_ratio_db; +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + float inst_diff_bb_power; + float inst_total_bb_power; + int16_t max_band_diff_ene; + +#endif int16_t counter; int16_t interpolator; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index f539edb13..f1f8cdb09 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -8820,7 +8820,11 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect, IVAS_512k ); /* Use 512k to get correct path */ +#else ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect ); +#endif } else { -- GitLab From 481ef3d2b91b0ad23cec07f44a4fe15874775e33 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 23 Apr 2026 14:18:56 +0300 Subject: [PATCH 2/5] Clang format --- lib_rend/ivas_dirac_rend.c | 1677 ++++++++++++++++++------------------ 1 file changed, 839 insertions(+), 838 deletions(-) diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index f32a704e8..d61c0a46b 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -1423,7 +1423,8 @@ void protoSignalComputation2( #endif } #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - else if ( stereo_type_detect->type_change_direction == MASA_DUAL_MONO ) { + else if ( stereo_type_detect->type_change_direction == MASA_DUAL_MONO ) + { interpolatorDualMono = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); interpolatorDmx = 1.0f - interpolatorDualMono; interpolatorSpaced = interpolatorDmx; @@ -1527,7 +1528,7 @@ void protoSignalComputation2( p_proto_buffer[2 * l + 1] = interpolatorSpaced * ImagBuffer[0][0][l] + interpolatorDmx * Imag_aux; } #else - if ( (stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_STEREO_DOWNMIX ) || + if ( ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_STEREO_DOWNMIX ) || ( stereo_type_detect->type_change_direction == MASA_STEREO_DOWNMIX && stereo_type_detect->current_stereo_type == MASA_STEREO_SPACED_MICS ) ) { if ( l < ( dipole_freq_range[1] - 1 ) || l >= MASA_SUM_PROTO_START_BIN ) @@ -1635,7 +1636,7 @@ void protoSignalComputation2( p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); #else - if ( (stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_STEREO_DOWNMIX ) || + if ( ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_STEREO_DOWNMIX ) || ( stereo_type_detect->type_change_direction == MASA_STEREO_DOWNMIX && stereo_type_detect->current_stereo_type == MASA_STEREO_SPACED_MICS ) ) { if ( l < ( dipole_freq_range[0] ) ) @@ -1679,1070 +1680,1070 @@ void protoSignalComputation2( p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorDualMono * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); } #endif - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; - } - else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) - { - if ( l < ( dipole_freq_range[0] ) ) /* proto = W */ - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; - proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; } - else if ( l < ( dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */ + else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) { - p_proto_buffer[2 * num_freq_bands + 2 * l] = ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + if ( l < ( dipole_freq_range[0] ) ) /* proto = W */ + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; + } + else if ( l < ( dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */ + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + } + else /* proto = W */ + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; + } } - else /* proto = W */ +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + else if ( stereo_type_detect->masa_stereo_type == MASA_DUAL_MONO ) { + /* proto = W */ p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; } - } -#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - else if ( stereo_type_detect->masa_stereo_type == MASA_DUAL_MONO ) - { - /* proto = W */ - p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; - proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; - } - else /* MASA_STEREO_DOWNMIX */ + else /* MASA_STEREO_DOWNMIX */ #else else #endif - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; - } + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + } - /* Compute protos for decorrelation */ - proto_frame_f[2 * l] = Real_aux; - proto_frame_f[2 * l + 1] = Imag_aux; - proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; - } + /* Compute protos for decorrelation */ + proto_frame_f[2 * l] = Real_aux; + proto_frame_f[2 * l + 1] = Imag_aux; + proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + } - if ( stereo_type_detect->interpolator > 0 ) - { - stereo_type_detect->interpolator++; - if ( stereo_type_detect->interpolator == MASA_STEREO_INTERPOLATION_SLOTS ) + if ( stereo_type_detect->interpolator > 0 ) { - stereo_type_detect->interpolator = 0; - stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction; + stereo_type_detect->interpolator++; + if ( stereo_type_detect->interpolator == MASA_STEREO_INTERPOLATION_SLOTS ) + { + stereo_type_detect->interpolator = 0; + stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction; + } } - } - stereo_type_detect->left_bb_power = a * left_bb_power + b * stereo_type_detect->left_bb_power; - stereo_type_detect->right_bb_power = a * right_bb_power + b * stereo_type_detect->right_bb_power; - stereo_type_detect->total_bb_power = a * total_bb_power + b * stereo_type_detect->total_bb_power; + stereo_type_detect->left_bb_power = a * left_bb_power + b * stereo_type_detect->left_bb_power; + stereo_type_detect->right_bb_power = a * right_bb_power + b * stereo_type_detect->right_bb_power; + stereo_type_detect->total_bb_power = a * total_bb_power + b * stereo_type_detect->total_bb_power; - lr_bb_power = ( stereo_type_detect->left_bb_power < stereo_type_detect->right_bb_power ) ? stereo_type_detect->left_bb_power : stereo_type_detect->right_bb_power; - lr_bb_power *= 2.0f; - lr_total_bb_ratio = 10.0f * log10f( lr_bb_power / ( stereo_type_detect->total_bb_power + EPSILON ) ); + lr_bb_power = ( stereo_type_detect->left_bb_power < stereo_type_detect->right_bb_power ) ? stereo_type_detect->left_bb_power : stereo_type_detect->right_bb_power; + lr_bb_power *= 2.0f; + lr_total_bb_ratio = 10.0f * log10f( lr_bb_power / ( stereo_type_detect->total_bb_power + EPSILON ) ); - stereo_type_detect->left_hi_power = a2 * left_hi_power + b2 * stereo_type_detect->left_hi_power; - stereo_type_detect->right_hi_power = a2 * right_hi_power + b2 * stereo_type_detect->right_hi_power; - stereo_type_detect->total_hi_power = a2 * total_hi_power + b2 * stereo_type_detect->total_hi_power; + stereo_type_detect->left_hi_power = a2 * left_hi_power + b2 * stereo_type_detect->left_hi_power; + stereo_type_detect->right_hi_power = a2 * right_hi_power + b2 * stereo_type_detect->right_hi_power; + stereo_type_detect->total_hi_power = a2 * total_hi_power + b2 * stereo_type_detect->total_hi_power; - lr_hi_power = ( stereo_type_detect->left_hi_power < stereo_type_detect->right_hi_power ) ? stereo_type_detect->left_hi_power : stereo_type_detect->right_hi_power; - lr_hi_power *= 2.0f; - lr_total_hi_ratio = 10.0f * log10f( lr_hi_power / ( stereo_type_detect->total_hi_power + EPSILON ) ); + lr_hi_power = ( stereo_type_detect->left_hi_power < stereo_type_detect->right_hi_power ) ? stereo_type_detect->left_hi_power : stereo_type_detect->right_hi_power; + lr_hi_power *= 2.0f; + lr_total_hi_ratio = 10.0f * log10f( lr_hi_power / ( stereo_type_detect->total_hi_power + EPSILON ) ); - minimum( sum_total_ratio, min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio ); - min_sum_total_ratio_db = 10.0f * log10f( min_sum_total_ratio ); + minimum( sum_total_ratio, min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio ); + min_sum_total_ratio_db = 10.0f * log10f( min_sum_total_ratio ); - stereo_type_detect->lr_total_bb_ratio_db = lr_total_bb_ratio; - stereo_type_detect->lr_total_hi_ratio_db = lr_total_hi_ratio; - stereo_type_detect->min_sum_total_ratio_db = min_sum_total_ratio_db; + stereo_type_detect->lr_total_bb_ratio_db = lr_total_bb_ratio; + stereo_type_detect->lr_total_hi_ratio_db = lr_total_hi_ratio; + stereo_type_detect->min_sum_total_ratio_db = min_sum_total_ratio_db; - ivas_masa_stereotype_detection( stereo_type_detect ); - } - else - { - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2; - - for ( l = 0; l < num_freq_bands; l++ ) + ivas_masa_stereotype_detection( stereo_type_detect ); + } + else { - Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; - Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2; - reference_power[l] = Real_aux * Real_aux + Imag_aux * Imag_aux; - proto_power_smooth[l] += reference_power[l]; - p_proto_buffer[2 * l] = Real_aux; - p_proto_buffer[2 * l + 1] = Imag_aux; + for ( l = 0; l < num_freq_bands; l++ ) + { + Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; + Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + reference_power[l] = Real_aux * Real_aux + Imag_aux * Imag_aux; + proto_power_smooth[l] += reference_power[l]; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; - proto_frame_f[2 * l] = Real_aux; - proto_frame_f[2 * l + 1] = Imag_aux; + p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; - proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + proto_frame_f[2 * l] = Real_aux; + proto_frame_f[2 * l + 1] = Imag_aux; + + proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + } } - } - return; -} + return; + } -/*------------------------------------------------------------------------- - * protoSignalComputation4() - * - * - *-------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------- + * protoSignalComputation4() + * + * + *-------------------------------------------------------------------------*/ -void protoSignalComputation4( - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float *proto_frame_f, - float *proto_direct_buffer_f, - float *reference_power, - float *proto_power_smooth, - const int16_t slot_index, - const int16_t num_outputs_diff, - const int16_t num_freq_bands, - const float *mtx_hoa_decoder, - const int16_t nchan_transport, - const int16_t *sba_map_tc_ind ) -{ - int16_t k, l; - int16_t n; - float sq_tmp; - float *p_proto_buffer; - - set_zero( reference_power, num_freq_bands ); - for ( k = 0; k < 4; k++ ) + void protoSignalComputation4( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_frame_f, + float *proto_direct_buffer_f, + float *reference_power, + float *proto_power_smooth, + const int16_t slot_index, + const int16_t num_outputs_diff, + const int16_t num_freq_bands, + const float *mtx_hoa_decoder, + const int16_t nchan_transport, + const int16_t *sba_map_tc_ind ) { - for ( l = 0; l < num_freq_bands; l++ ) + int16_t k, l; + int16_t n; + float sq_tmp; + float *p_proto_buffer; + + set_zero( reference_power, num_freq_bands ); + for ( k = 0; k < 4; k++ ) { - sq_tmp = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l]; - reference_power[l] += 0.5f * sq_tmp; + for ( l = 0; l < num_freq_bands; l++ ) + { + sq_tmp = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l]; + reference_power[l] += 0.5f * sq_tmp; + } } - } - /*For decorrelated diffuseness*/ - for ( l = 0; l < num_outputs_diff; l++ ) - { - for ( k = 0; k < num_freq_bands; k++ ) + /*For decorrelated diffuseness*/ + for ( l = 0; l < num_outputs_diff; l++ ) { - proto_frame_f[2 * l * num_freq_bands + 2 * k] = 0.f; - proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] = 0.f; - for ( n = 0; n < nchan_transport; n++ ) + for ( k = 0; k < num_freq_bands; k++ ) { - proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; - proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; + proto_frame_f[2 * l * num_freq_bands + 2 * k] = 0.f; + proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] = 0.f; + for ( n = 0; n < nchan_transport; n++ ) + { + proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; + proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; + } } } - } - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff; - for ( k = 0; k < num_outputs_diff; k++ ) - { - for ( l = 0; l < num_freq_bands; l++ ) + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff; + for ( k = 0; k < num_outputs_diff; k++ ) { - sq_tmp = proto_frame_f[k * 2 * num_freq_bands + 2 * l] * proto_frame_f[k * 2 * num_freq_bands + 2 * l] + proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1] * proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; - proto_power_smooth[l + k * num_freq_bands] += sq_tmp; - p_proto_buffer[k * 2 * num_freq_bands + 2 * l] = proto_frame_f[k * 2 * num_freq_bands + 2 * l]; - p_proto_buffer[k * 2 * num_freq_bands + 2 * l + 1] = proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; + for ( l = 0; l < num_freq_bands; l++ ) + { + sq_tmp = proto_frame_f[k * 2 * num_freq_bands + 2 * l] * proto_frame_f[k * 2 * num_freq_bands + 2 * l] + proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1] * proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; + proto_power_smooth[l + k * num_freq_bands] += sq_tmp; + p_proto_buffer[k * 2 * num_freq_bands + 2 * l] = proto_frame_f[k * 2 * num_freq_bands + 2 * l]; + p_proto_buffer[k * 2 * num_freq_bands + 2 * l + 1] = proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; + } } - } - return; -} + return; + } -/*------------------------------------------------------------------------- - * ivas_dirac_dec_compute_diffuse_proto() - * - * Compute diffuse prototype buffer and smooth power, only for decorrelated bands - *------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------- + * ivas_dirac_dec_compute_diffuse_proto() + * + * Compute diffuse prototype buffer and smooth power, only for decorrelated bands + *------------------------------------------------------------------------*/ -void ivas_dirac_dec_compute_diffuse_proto( - DIRAC_REND_HANDLE hDirACRend, - const int16_t num_freq_bands, - const int16_t slot_idx /* i : slot index */ -) -{ - int16_t k, l; - int16_t num_freq_bands_diff; - float *p_diff_buffer, *p_diff_buffer_1; - float *p_proto_diff, *p_power_smooth, *proto_frame_dec_f; - DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; - DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; - int16_t m; - float *p_hoa_enc; - - proto_frame_dec_f = hDirACRend->proto_frame_dec_f; - h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); - h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); - - num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; - if ( num_freq_bands_diff == 0 ) + void ivas_dirac_dec_compute_diffuse_proto( + DIRAC_REND_HANDLE hDirACRend, + const int16_t num_freq_bands, + const int16_t slot_idx /* i : slot index */ + ) { - return; - } + int16_t k, l; + int16_t num_freq_bands_diff; + float *p_diff_buffer, *p_diff_buffer_1; + float *p_proto_diff, *p_power_smooth, *proto_frame_dec_f; + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; + DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; + int16_t m; + float *p_hoa_enc; - p_diff_buffer = h_dirac_output_synthesis_state->proto_diffuse_buffer_f + slot_idx * 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE; - p_diff_buffer_1 = p_diff_buffer + 1; - p_power_smooth = h_dirac_output_synthesis_state->proto_power_diff_smooth; + proto_frame_dec_f = hDirACRend->proto_frame_dec_f; + h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) - { - for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) + num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; + if ( num_freq_bands_diff == 0 ) { - p_proto_diff = proto_frame_dec_f + k * 2 * num_freq_bands; - for ( l = 0; l < num_freq_bands_diff; l++ ) + return; + } + + p_diff_buffer = h_dirac_output_synthesis_state->proto_diffuse_buffer_f + slot_idx * 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE; + p_diff_buffer_1 = p_diff_buffer + 1; + p_power_smooth = h_dirac_output_synthesis_state->proto_power_diff_smooth; + + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) + { + for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) { - *p_diff_buffer = *( p_proto_diff++ ); - *p_diff_buffer_1 = *( p_proto_diff++ ); - *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); - p_diff_buffer += 2; - p_diff_buffer_1 += 2; + p_proto_diff = proto_frame_dec_f + k * 2 * num_freq_bands; + for ( l = 0; l < num_freq_bands_diff; l++ ) + { + *p_diff_buffer = *( p_proto_diff++ ); + *p_diff_buffer_1 = *( p_proto_diff++ ); + *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); + p_diff_buffer += 2; + p_diff_buffer_1 += 2; + } } } - } - else - { - /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/ - for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) + else { - for ( l = 0; l < num_freq_bands_diff; l++ ) + /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/ + for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) { - p_hoa_enc = hDirACRend->hoa_encoder + k; - p_proto_diff = proto_frame_dec_f + 2 * l; + for ( l = 0; l < num_freq_bands_diff; l++ ) + { + p_hoa_enc = hDirACRend->hoa_encoder + k; + p_proto_diff = proto_frame_dec_f + 2 * l; - *p_diff_buffer = 0.f; - *p_diff_buffer_1 = 0.f; + *p_diff_buffer = 0.f; + *p_diff_buffer_1 = 0.f; - /*LS to HOA*/ - for ( m = 0; m < hDirACRend->num_outputs_diff; m++ ) - { - *p_diff_buffer += ( *p_hoa_enc ) * ( *p_proto_diff ); - *p_diff_buffer_1 += ( *p_hoa_enc ) * ( *( p_proto_diff + 1 ) ); - p_hoa_enc += hDirACRend->hOutSetup.nchan_out_woLFE; - p_proto_diff += 2 * num_freq_bands; - } + /*LS to HOA*/ + for ( m = 0; m < hDirACRend->num_outputs_diff; m++ ) + { + *p_diff_buffer += ( *p_hoa_enc ) * ( *p_proto_diff ); + *p_diff_buffer_1 += ( *p_hoa_enc ) * ( *( p_proto_diff + 1 ) ); + p_hoa_enc += hDirACRend->hOutSetup.nchan_out_woLFE; + p_proto_diff += 2 * num_freq_bands; + } - *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); - p_diff_buffer += 2; - p_diff_buffer_1 += 2; + *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); + p_diff_buffer += 2; + p_diff_buffer_1 += 2; + } } } - } - - return; -} + return; + } -/*------------------------------------------------------------------------- - * computeDirectionAngles() - * - *------------------------------------------------------------------------*/ -void computeDirectionAngles( - float *intensity_real_x, - float *intensity_real_y, - float *intensity_real_z, - const int16_t num_frequency_bands, - int16_t *azimuth, - int16_t *elevation ) -{ - int16_t k; - float intensityNorm; - float x, y, z, radius; + /*------------------------------------------------------------------------- + * computeDirectionAngles() + * + *------------------------------------------------------------------------*/ - for ( k = 0; k < num_frequency_bands; ++k ) + void computeDirectionAngles( + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z, + const int16_t num_frequency_bands, + int16_t *azimuth, + int16_t *elevation ) { - intensityNorm = *( intensity_real_x ) * *( intensity_real_x ) + - *( intensity_real_y ) * *( intensity_real_y ) + - *( intensity_real_z ) * *( intensity_real_z ); + int16_t k; + float intensityNorm; + float x, y, z, radius; - if ( intensityNorm <= EPSILON ) - { - intensityNorm = 1.0f; - x = 1.0f; - y = 0.0f; - z = 0.0f; - intensity_real_x++; - intensity_real_y++; - intensity_real_z++; - } - else + for ( k = 0; k < num_frequency_bands; ++k ) { - intensityNorm = sqrtf( 1.f / intensityNorm ); - x = *( intensity_real_x++ ) * intensityNorm; - y = *( intensity_real_y++ ) * intensityNorm; - z = *( intensity_real_z++ ) * intensityNorm; + intensityNorm = *( intensity_real_x ) * *( intensity_real_x ) + + *( intensity_real_y ) * *( intensity_real_y ) + + *( intensity_real_z ) * *( intensity_real_z ); + + if ( intensityNorm <= EPSILON ) + { + intensityNorm = 1.0f; + x = 1.0f; + y = 0.0f; + z = 0.0f; + intensity_real_x++; + intensity_real_y++; + intensity_real_z++; + } + else + { + intensityNorm = sqrtf( 1.f / intensityNorm ); + x = *( intensity_real_x++ ) * intensityNorm; + y = *( intensity_real_y++ ) * intensityNorm; + z = *( intensity_real_z++ ) * intensityNorm; + } + radius = sqrtf( x * x + y * y ); + azimuth[k] = (int16_t) ( max( -180.0f, min( 180.0f, atan2f( y, x ) / EVS_PI * 180.0f ) ) + 0.5f ); + elevation[k] = (int16_t) ( max( -90.0f, min( 180.0f, atan2f( z, radius ) / EVS_PI * 180.0f ) ) + 0.5f ); } - radius = sqrtf( x * x + y * y ); - azimuth[k] = (int16_t) ( max( -180.0f, min( 180.0f, atan2f( y, x ) / EVS_PI * 180.0f ) ) + 0.5f ); - elevation[k] = (int16_t) ( max( -90.0f, min( 180.0f, atan2f( z, radius ) / EVS_PI * 180.0f ) ) + 0.5f ); + + return; } - return; -} + /*------------------------------------------------------------------------- + * ivas_masa_init_stereotype_detection() + * + * Initialize stereo transport signal type detection + *------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------- - * ivas_masa_init_stereotype_detection() - * - * Initialize stereo transport signal type detection - *------------------------------------------------------------------------*/ - -void ivas_masa_init_stereotype_detection( + void ivas_masa_init_stereotype_detection( #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - MASA_STEREO_TYPE_DETECT *stereo_type_detect, - int32_t ivas_total_brate ) + MASA_STEREO_TYPE_DETECT * stereo_type_detect, + int32_t ivas_total_brate ) #else MASA_STEREO_TYPE_DETECT *stereo_type_detect ) #endif -{ - stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; - stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; - stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX; + { + stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; + stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; + stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX; - stereo_type_detect->counter = 0; - stereo_type_detect->interpolator = 0; + stereo_type_detect->counter = 0; + stereo_type_detect->interpolator = 0; - stereo_type_detect->dipole_freq_range[0] = 1; - stereo_type_detect->dipole_freq_range[1] = 3; + stereo_type_detect->dipole_freq_range[0] = 1; + stereo_type_detect->dipole_freq_range[1] = 3; - stereo_type_detect->left_bb_power = 0.0f; /* Broadband estimates */ - stereo_type_detect->right_bb_power = 0.0f; - stereo_type_detect->total_bb_power = 0.0f; + stereo_type_detect->left_bb_power = 0.0f; /* Broadband estimates */ + stereo_type_detect->right_bb_power = 0.0f; + stereo_type_detect->total_bb_power = 0.0f; - stereo_type_detect->left_hi_power = 0.0f; /* High-frequency estimates */ - stereo_type_detect->right_hi_power = 0.0f; - stereo_type_detect->total_hi_power = 0.0f; + stereo_type_detect->left_hi_power = 0.0f; /* High-frequency estimates */ + stereo_type_detect->right_hi_power = 0.0f; + stereo_type_detect->total_hi_power = 0.0f; - set_zero( stereo_type_detect->sum_power, MASA_SUM_FREQ_RANGE_BINS ); - set_zero( stereo_type_detect->total_power, MASA_SUM_FREQ_RANGE_BINS ); + set_zero( stereo_type_detect->sum_power, MASA_SUM_FREQ_RANGE_BINS ); + set_zero( stereo_type_detect->total_power, MASA_SUM_FREQ_RANGE_BINS ); - stereo_type_detect->subtract_power_y = 0.0f; - stereo_type_detect->subtract_power_y_smooth = 0.0f; - stereo_type_detect->target_power_y_smooth = 0.0f; + stereo_type_detect->subtract_power_y = 0.0f; + stereo_type_detect->subtract_power_y_smooth = 0.0f; + stereo_type_detect->target_power_y_smooth = 0.0f; - stereo_type_detect->lr_total_bb_ratio_db = 0.0f; - stereo_type_detect->lr_total_hi_ratio_db = 0.0f; - stereo_type_detect->min_sum_total_ratio_db = 0.0f; - stereo_type_detect->subtract_target_ratio_db = 0.0f; + stereo_type_detect->lr_total_bb_ratio_db = 0.0f; + stereo_type_detect->lr_total_hi_ratio_db = 0.0f; + stereo_type_detect->min_sum_total_ratio_db = 0.0f; + stereo_type_detect->subtract_target_ratio_db = 0.0f; #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - stereo_type_detect->inst_diff_bb_power = 0.0f; - stereo_type_detect->inst_total_bb_power = 0.0f; + stereo_type_detect->inst_diff_bb_power = 0.0f; + stereo_type_detect->inst_total_bb_power = 0.0f; - stereo_type_detect->max_band_diff_ene = IVAS_CLDFB_NO_CHANNELS_MAX; - if ( ivas_total_brate < IVAS_48k ) - { - stereo_type_detect->max_band_diff_ene = 18; - } + stereo_type_detect->max_band_diff_ene = IVAS_CLDFB_NO_CHANNELS_MAX; + if ( ivas_total_brate < IVAS_48k ) + { + stereo_type_detect->max_band_diff_ene = 18; + } #endif - return; -} - + return; + } -/*------------------------------------------------------------------------- - * ivas_masa_stereotype_detection() - * - * Detect the type of the transport audio signals - *------------------------------------------------------------------------*/ -void ivas_masa_stereotype_detection( - MASA_STEREO_TYPE_DETECT *stereo_type_detect ) -{ - float lr_total_bb_ratio_db = stereo_type_detect->lr_total_bb_ratio_db; - float lr_total_hi_ratio_db = stereo_type_detect->lr_total_hi_ratio_db; - float min_sum_total_ratio_db = stereo_type_detect->min_sum_total_ratio_db; - float subtract_target_ratio_db = stereo_type_detect->subtract_target_ratio_db; - float change_to_spaced; - int16_t change_to_spaced_selection; - float change_to_downmix; - float change_to_downmix2; - int16_t change_to_downmix_selection; - float subtract_temp; - float min_sum_temp; - float lr_total_bb_temp; - float lr_total_hi_temp; + /*------------------------------------------------------------------------- + * ivas_masa_stereotype_detection() + * + * Detect the type of the transport audio signals + *------------------------------------------------------------------------*/ + + void ivas_masa_stereotype_detection( + MASA_STEREO_TYPE_DETECT * stereo_type_detect ) + { + float lr_total_bb_ratio_db = stereo_type_detect->lr_total_bb_ratio_db; + float lr_total_hi_ratio_db = stereo_type_detect->lr_total_hi_ratio_db; + float min_sum_total_ratio_db = stereo_type_detect->min_sum_total_ratio_db; + float subtract_target_ratio_db = stereo_type_detect->subtract_target_ratio_db; + float change_to_spaced; + int16_t change_to_spaced_selection; + float change_to_downmix; + float change_to_downmix2; + int16_t change_to_downmix_selection; + float subtract_temp; + float min_sum_temp; + float lr_total_bb_temp; + float lr_total_hi_temp; #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - int16_t change_to_dual_mono_selection; - float diffPerSum; + int16_t change_to_dual_mono_selection; + float diffPerSum; - /* Determine if broadband energy and ratio between difference broadband energy and broadband energy indicate - * that the signal type is dual mono */ - change_to_dual_mono_selection = 0; - if ( stereo_type_detect->inst_total_bb_power > 1.0f ) - { - diffPerSum = stereo_type_detect->inst_diff_bb_power / stereo_type_detect->inst_total_bb_power; - if ( diffPerSum < ( stereo_type_detect->current_stereo_type == MASA_DUAL_MONO ? MASA_DUAL_MONO_TAU1 : MASA_DUAL_MONO_TAU2 ) ) + /* Determine if broadband energy and ratio between difference broadband energy and broadband energy indicate + * that the signal type is dual mono */ + change_to_dual_mono_selection = 0; + if ( stereo_type_detect->inst_total_bb_power > 1.0f ) { - change_to_dual_mono_selection = 1; + diffPerSum = stereo_type_detect->inst_diff_bb_power / stereo_type_detect->inst_total_bb_power; + if ( diffPerSum < ( stereo_type_detect->current_stereo_type == MASA_DUAL_MONO ? MASA_DUAL_MONO_TAU1 : MASA_DUAL_MONO_TAU2 ) ) + { + change_to_dual_mono_selection = 1; + } } - } #endif - /* Determine if the determined features match the spaced mic type */ - change_to_spaced_selection = 0; - if ( subtract_target_ratio_db < -3.0f ) - { - subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; - min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); - lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; + /* Determine if the determined features match the spaced mic type */ + change_to_spaced_selection = 0; + if ( subtract_target_ratio_db < -3.0f ) + { + subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; + min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); + lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; - change_to_spaced = subtract_temp + min_sum_temp + lr_total_bb_temp; + change_to_spaced = subtract_temp + min_sum_temp + lr_total_bb_temp; - if ( change_to_spaced >= 1.0f ) - { - change_to_spaced_selection = 1; + if ( change_to_spaced >= 1.0f ) + { + change_to_spaced_selection = 1; + } } - } - /* Determine if the determined features match the downmix type, according to a metric */ - change_to_downmix_selection = 0; - if ( subtract_target_ratio_db > 0.0f ) - { - subtract_temp = subtract_target_ratio_db / 3.0f; - min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; - lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; + /* Determine if the determined features match the downmix type, according to a metric */ + change_to_downmix_selection = 0; + if ( subtract_target_ratio_db > 0.0f ) + { + subtract_temp = subtract_target_ratio_db / 3.0f; + min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; + lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; - change_to_downmix = subtract_temp + min_sum_temp + lr_total_bb_temp; + change_to_downmix = subtract_temp + min_sum_temp + lr_total_bb_temp; - if ( change_to_downmix >= 1.0f ) - { - change_to_downmix_selection = 1; + if ( change_to_downmix >= 1.0f ) + { + change_to_downmix_selection = 1; + } } - } - /* Determine if the determined features match the downmix type, according to another metric */ - if ( lr_total_hi_ratio_db < -12.0f ) - { - subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; - min_sum_temp = min_sum_total_ratio_db / 6.0f; - lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; + /* Determine if the determined features match the downmix type, according to another metric */ + if ( lr_total_hi_ratio_db < -12.0f ) + { + subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; + min_sum_temp = min_sum_total_ratio_db / 6.0f; + lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; - change_to_downmix2 = subtract_temp + min_sum_temp + lr_total_hi_temp; + change_to_downmix2 = subtract_temp + min_sum_temp + lr_total_hi_temp; - if ( change_to_downmix2 >= 1.0f ) - { - change_to_downmix_selection = 1; + if ( change_to_downmix2 >= 1.0f ) + { + change_to_downmix_selection = 1; + } } - } - if ( stereo_type_detect->counter < 400 ) - { - stereo_type_detect->counter++; - } - else - { -#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - if ( change_to_dual_mono_selection == 1 ) + if ( stereo_type_detect->counter < 400 ) { - stereo_type_detect->masa_stereo_type = MASA_DUAL_MONO; + stereo_type_detect->counter++; } - else if ( change_to_spaced_selection == 1 ) + else + { +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + if ( change_to_dual_mono_selection == 1 ) + { + stereo_type_detect->masa_stereo_type = MASA_DUAL_MONO; + } + else if ( change_to_spaced_selection == 1 ) #else if ( change_to_spaced_selection == 1 ) #endif - { - stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS; - } - else if ( change_to_downmix_selection == 1 ) - { - stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; + { + stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS; + } + else if ( change_to_downmix_selection == 1 ) + { + stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; + } } - } - if ( stereo_type_detect->interpolator == 0 ) - { - if ( stereo_type_detect->current_stereo_type != stereo_type_detect->masa_stereo_type ) + if ( stereo_type_detect->interpolator == 0 ) { - stereo_type_detect->interpolator = 1; - stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type; + if ( stereo_type_detect->current_stereo_type != stereo_type_detect->masa_stereo_type ) + { + stereo_type_detect->interpolator = 1; + stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type; + } } + + return; } - return; -} + /*------------------------------------------------------------------------- + * computeIntensityVector_dec() + * + * + *------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------- - * computeIntensityVector_dec() - * - * - *------------------------------------------------------------------------*/ + void computeIntensityVector_dec( + float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const int16_t num_frequency_bands, + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z ) + { + /* + * W = a + ib; Y = c + id + * real(W*Y') = ac + bd + */ + int16_t i; + float real, img; -void computeIntensityVector_dec( - float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - const int16_t num_frequency_bands, - float *intensity_real_x, - float *intensity_real_y, - float *intensity_real_z ) -{ - /* - * W = a + ib; Y = c + id - * real(W*Y') = ac + bd - */ - int16_t i; - float real, img; + for ( i = 0; i < num_frequency_bands; ++i ) + { + real = Cldfb_RealBuffer[0][0][i]; + img = Cldfb_ImagBuffer[0][0][i]; + intensity_real_x[i] = Cldfb_RealBuffer[3][0][i] * real + Cldfb_ImagBuffer[3][0][i] * img; + intensity_real_y[i] = Cldfb_RealBuffer[1][0][i] * real + Cldfb_ImagBuffer[1][0][i] * img; + intensity_real_z[i] = Cldfb_RealBuffer[2][0][i] * real + Cldfb_ImagBuffer[2][0][i] * img; + } - for ( i = 0; i < num_frequency_bands; ++i ) - { - real = Cldfb_RealBuffer[0][0][i]; - img = Cldfb_ImagBuffer[0][0][i]; - intensity_real_x[i] = Cldfb_RealBuffer[3][0][i] * real + Cldfb_ImagBuffer[3][0][i] * img; - intensity_real_y[i] = Cldfb_RealBuffer[1][0][i] * real + Cldfb_ImagBuffer[1][0][i] * img; - intensity_real_z[i] = Cldfb_RealBuffer[2][0][i] * real + Cldfb_ImagBuffer[2][0][i] * img; + return; } - return; -} + /*------------------------------------------------------------------------- + * ivas_lfe_synth_with_cldfb() + * + * + *------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------- - * ivas_lfe_synth_with_cldfb() - * - * - *------------------------------------------------------------------------*/ + void ivas_lfe_synth_with_cldfb( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float RealBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const int16_t slot_index, + const int16_t subframe_index, + const int16_t nchan_transport ) + { + float lfeGain; + float transportGain; + float protoLfeReal, protoLfeImag; + int16_t i; + float transportEne, protoLfeEne, targetEneLfe, targetEneTrans; -void ivas_lfe_synth_with_cldfb( - MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float RealBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - const int16_t slot_index, - const int16_t subframe_index, - const int16_t nchan_transport ) -{ - float lfeGain; - float transportGain; - float protoLfeReal, protoLfeImag; - int16_t i; - float transportEne, protoLfeEne, targetEneLfe, targetEneTrans; + set_zero( RealBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); + set_zero( ImagBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); - set_zero( RealBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); - set_zero( ImagBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); + protoLfeReal = RealBuffer[0][0][0]; + protoLfeImag = ImagBuffer[0][0][0]; + transportEne = RealBuffer[0][0][0] * RealBuffer[0][0][0] + ImagBuffer[0][0][0] * ImagBuffer[0][0][0]; + for ( i = 1; i < nchan_transport; i++ ) + { + protoLfeReal += RealBuffer[i][0][0]; + protoLfeImag += ImagBuffer[i][0][0]; + transportEne += RealBuffer[i][0][0] * RealBuffer[i][0][0] + ImagBuffer[i][0][0] * ImagBuffer[i][0][0]; + } + protoLfeEne = protoLfeReal * protoLfeReal + protoLfeImag * protoLfeImag; - protoLfeReal = RealBuffer[0][0][0]; - protoLfeImag = ImagBuffer[0][0][0]; - transportEne = RealBuffer[0][0][0] * RealBuffer[0][0][0] + ImagBuffer[0][0][0] * ImagBuffer[0][0][0]; - for ( i = 1; i < nchan_transport; i++ ) - { - protoLfeReal += RealBuffer[i][0][0]; - protoLfeImag += ImagBuffer[i][0][0]; - transportEne += RealBuffer[i][0][0] * RealBuffer[i][0][0] + ImagBuffer[i][0][0] * ImagBuffer[i][0][0]; - } - protoLfeEne = protoLfeReal * protoLfeReal + protoLfeImag * protoLfeImag; + targetEneLfe = transportEne * hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index]; + targetEneTrans = transportEne * max( ( 1.0f - hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index] ), 0.01f ); - targetEneLfe = transportEne * hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index]; - targetEneTrans = transportEne * max( ( 1.0f - hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index] ), 0.01f ); + hMasaLfeSynth->transportEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->protoLfeEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->targetEneLfeSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->targetEneTransSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->transportEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->protoLfeEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->targetEneLfeSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->targetEneTransSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->transportEneSmooth += transportEne; + hMasaLfeSynth->protoLfeEneSmooth += protoLfeEne; + hMasaLfeSynth->targetEneLfeSmooth += targetEneLfe; + hMasaLfeSynth->targetEneTransSmooth += targetEneTrans; - hMasaLfeSynth->transportEneSmooth += transportEne; - hMasaLfeSynth->protoLfeEneSmooth += protoLfeEne; - hMasaLfeSynth->targetEneLfeSmooth += targetEneLfe; - hMasaLfeSynth->targetEneTransSmooth += targetEneTrans; + lfeGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneLfeSmooth / ( EPSILON + hMasaLfeSynth->protoLfeEneSmooth ) ) ); + transportGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneTransSmooth / ( EPSILON + hMasaLfeSynth->transportEneSmooth ) ) ); - lfeGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneLfeSmooth / ( EPSILON + hMasaLfeSynth->protoLfeEneSmooth ) ) ); - transportGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneTransSmooth / ( EPSILON + hMasaLfeSynth->transportEneSmooth ) ) ); + RealBufferLfe[slot_index][0] = protoLfeReal * lfeGain; + ImagBufferLfe[slot_index][0] = protoLfeImag * lfeGain; - RealBufferLfe[slot_index][0] = protoLfeReal * lfeGain; - ImagBufferLfe[slot_index][0] = protoLfeImag * lfeGain; + RealBuffer[0][0][0] *= transportGain; + ImagBuffer[0][0][0] *= transportGain; + for ( i = 1; i < nchan_transport; i++ ) + { + RealBuffer[i][0][0] *= transportGain; + ImagBuffer[i][0][0] *= transportGain; + } - RealBuffer[0][0][0] *= transportGain; - ImagBuffer[0][0][0] *= transportGain; - for ( i = 1; i < nchan_transport; i++ ) - { - RealBuffer[i][0][0] *= transportGain; - ImagBuffer[i][0][0] *= transportGain; + return; } - return; -} + /*------------------------------------------------------------------------- + * rotateAziEle_DirAC() + * + * Apply rotation to DirAC DOAs + *------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------- - * rotateAziEle_DirAC() - * - * Apply rotation to DirAC DOAs - *------------------------------------------------------------------------*/ + void rotateAziEle_DirAC( + int16_t * azi, /* i/o: array of azimuth values */ + int16_t * ele, /* i/o: array of elevation values */ + const int16_t band1, /* i : bands to work on (lower limit) */ + const int16_t band2, /* i : bands to work on (upper bound) */ + const float *p_Rmat /* i : pointer to real-space rotation matrix */ + ) + { + int16_t b; + float dv_0, dv_1, dv_2; + float dv_r_0, dv_r_1, dv_r_2; + float w; -void rotateAziEle_DirAC( - int16_t *azi, /* i/o: array of azimuth values */ - int16_t *ele, /* i/o: array of elevation values */ - const int16_t band1, /* i : bands to work on (lower limit) */ - const int16_t band2, /* i : bands to work on (upper bound) */ - const float *p_Rmat /* i : pointer to real-space rotation matrix */ -) -{ - int16_t b; - float dv_0, dv_1, dv_2; - float dv_r_0, dv_r_1, dv_r_2; - float w; + push_wmops( "rotateAziEle_DirAC" ); - push_wmops( "rotateAziEle_DirAC" ); + for ( b = band1; b < band2; b++ ) + { - for ( b = band1; b < band2; b++ ) - { + /*Conversion spherical to cartesian coordinates*/ + w = cosf( ele[b] * PI_OVER_180 ); + dv_0 = w * cosf( azi[b] * PI_OVER_180 ); + dv_1 = w * sinf( azi[b] * PI_OVER_180 ); + dv_2 = sinf( ele[b] * PI_OVER_180 ); - /*Conversion spherical to cartesian coordinates*/ - w = cosf( ele[b] * PI_OVER_180 ); - dv_0 = w * cosf( azi[b] * PI_OVER_180 ); - dv_1 = w * sinf( azi[b] * PI_OVER_180 ); - dv_2 = sinf( ele[b] * PI_OVER_180 ); + dv_r_0 = p_Rmat[0] * dv_0 + p_Rmat[1] * dv_1 + p_Rmat[2] * dv_2; + dv_r_1 = p_Rmat[3] * dv_0 + p_Rmat[4] * dv_1 + p_Rmat[5] * dv_2; + dv_r_2 = p_Rmat[6] * dv_0 + p_Rmat[7] * dv_1 + p_Rmat[8] * dv_2; + + /*Conversion spherical to cartesian coordinates*/ + azi[b] = (int16_t) ( atan2f( dv_r_1, dv_r_0 ) * _180_OVER_PI ); + ele[b] = (int16_t) ( atan2f( dv_r_2, sqrtf( dv_r_0 * dv_r_0 + dv_r_1 * dv_r_1 ) ) * _180_OVER_PI ); + } - dv_r_0 = p_Rmat[0] * dv_0 + p_Rmat[1] * dv_1 + p_Rmat[2] * dv_2; - dv_r_1 = p_Rmat[3] * dv_0 + p_Rmat[4] * dv_1 + p_Rmat[5] * dv_2; - dv_r_2 = p_Rmat[6] * dv_0 + p_Rmat[7] * dv_1 + p_Rmat[8] * dv_2; + pop_wmops(); - /*Conversion spherical to cartesian coordinates*/ - azi[b] = (int16_t) ( atan2f( dv_r_1, dv_r_0 ) * _180_OVER_PI ); - ele[b] = (int16_t) ( atan2f( dv_r_2, sqrtf( dv_r_0 * dv_r_0 + dv_r_1 * dv_r_1 ) ) * _180_OVER_PI ); + return; } - pop_wmops(); - return; -} + /*------------------------------------------------------------------------- + * ivas_masa_ext_dirac_render_sf() + * + * A reduced rewrite of the corresponding decoder side function + *------------------------------------------------------------------------*/ + static void ivas_masa_ext_dirac_render_sf( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */ + float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ + ) + { + int16_t i, ch, idx_in, idx_lfe; + DIRAC_REND_HANDLE hDirACRend; + float dirEne; + float surCohEner; + float surCohRatio[CLDFB_NO_CHANNELS_MAX]; + int16_t subframe_idx; + int16_t slot_idx, index_slot; + int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx; + int16_t nchan_transport; + int16_t masa_band_mapping[MASA_FREQUENCY_BANDS + 1]; -/*------------------------------------------------------------------------- - * ivas_masa_ext_dirac_render_sf() - * - * A reduced rewrite of the corresponding decoder side function - *------------------------------------------------------------------------*/ - -static void ivas_masa_ext_dirac_render_sf( - MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */ - float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ -) -{ - int16_t i, ch, idx_in, idx_lfe; - DIRAC_REND_HANDLE hDirACRend; - float dirEne; - float surCohEner; - float surCohRatio[CLDFB_NO_CHANNELS_MAX]; - int16_t subframe_idx; - int16_t slot_idx, index_slot; - int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx; - int16_t nchan_transport; - int16_t masa_band_mapping[MASA_FREQUENCY_BANDS + 1]; - - /* CLDFB: last output channels reserved to LFT for CICPx */ - float Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - - /* local copies of azi, ele, diffuseness */ - int16_t azimuth[CLDFB_NO_CHANNELS_MAX]; - int16_t elevation[CLDFB_NO_CHANNELS_MAX]; - float diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; - - DIRAC_DEC_STACK_MEM DirAC_mem; - float *reference_power, *reference_power_smooth; - float *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; - uint16_t coherence_flag; - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + /* CLDFB: last output channels reserved to LFT for CICPx */ + float Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - push_wmops( "ivas_masa_ext_dirac_render_sf" ); + /* local copies of azi, ele, diffuseness */ + int16_t azimuth[CLDFB_NO_CHANNELS_MAX]; + int16_t elevation[CLDFB_NO_CHANNELS_MAX]; + float diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; - /* Initialize aux buffers */ - hDirACRend = hMasaExtRend->hDirACRend; - hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - nchan_transport = hMasaExtRend->nchan_input; + DIRAC_DEC_STACK_MEM DirAC_mem; + float *reference_power, *reference_power_smooth; + float *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; + uint16_t coherence_flag; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - DirAC_mem = hDirACRend->stack_mem; + push_wmops( "ivas_masa_ext_dirac_render_sf" ); - reference_power = DirAC_mem.reference_power; - reference_power_smooth = ( DirAC_mem.reference_power == NULL ) ? NULL : DirAC_mem.reference_power + hSpatParamRendCom->num_freq_bands; - onset_filter = DirAC_mem.onset_filter; - onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands; - coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ + /* Initialize aux buffers */ + hDirACRend = hMasaExtRend->hDirACRend; + hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; + nchan_transport = hMasaExtRend->nchan_input; - /* Construct default MASA band mapping */ - for ( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ ) - { - masa_band_mapping[i] = i; - } + DirAC_mem = hDirACRend->stack_mem; - /* Subframe loop */ - slot_idx_start = hSpatParamRendCom->slots_rendered; - slot_idx_start_cldfb_synth = 0; + reference_power = DirAC_mem.reference_power; + reference_power_smooth = ( DirAC_mem.reference_power == NULL ) ? NULL : DirAC_mem.reference_power + hSpatParamRendCom->num_freq_bands; + onset_filter = DirAC_mem.onset_filter; + onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands; + coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ - subframe_idx = hSpatParamRendCom->subframes_rendered; - md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + /* Construct default MASA band mapping */ + for ( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ ) + { + masa_band_mapping[i] = i; + } - /* copy parameters into local buffers*/ - mvs2s( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); - mvs2s( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); - mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + /* Subframe loop */ + slot_idx_start = hSpatParamRendCom->slots_rendered; + slot_idx_start_cldfb_synth = 0; - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - set_zero( reference_power_smooth, hSpatParamRendCom->num_freq_bands ); - } - else - { - set_zero( onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); - } + subframe_idx = hSpatParamRendCom->subframes_rendered; + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; - /* compute response */ - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_compute_power_factors( hSpatParamRendCom->num_freq_bands, - diffuseness_vector, - hDirACRend->h_output_synthesis_psd_params.max_band_decorr, - hDirACRend->h_output_synthesis_psd_state.direct_power_factor, - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); + /* copy parameters into local buffers*/ + mvs2s( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); + mvs2s( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); + mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); - if ( coherence_flag ) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - dirEne = hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i]; - surCohEner = hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] * hSpatParamRendCom->surroundingCoherence[md_idx][i]; - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] -= surCohEner; - hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] += surCohEner; - - surCohRatio[i] = surCohEner / ( 1e-12f + dirEne + surCohEner ); - } + set_zero( reference_power_smooth, hSpatParamRendCom->num_freq_bands ); } else { - set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); + set_zero( onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); } - } - else - { - ivas_dirac_dec_compute_gain_factors( hSpatParamRendCom->num_freq_bands, - hSpatParamRendCom->diffuseness_vector[md_idx], - hDirACRend->h_output_synthesis_psd_params.max_band_decorr, - hDirACRend->h_output_synthesis_psd_state.direct_power_factor, - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); - if ( coherence_flag ) + /* compute response */ + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + ivas_dirac_dec_compute_power_factors( hSpatParamRendCom->num_freq_bands, + diffuseness_vector, + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); + + if ( coherence_flag ) + { + for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + dirEne = hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i]; + surCohEner = hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] * hSpatParamRendCom->surroundingCoherence[md_idx][i]; + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] -= surCohEner; + hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] += surCohEner; + + surCohRatio[i] = surCohEner / ( 1e-12f + dirEne + surCohEner ); + } + } + else { - surCohRatio[i] = hSpatParamRendCom->surroundingCoherence[md_idx][i]; + set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); } } else { - set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); - } - } + ivas_dirac_dec_compute_gain_factors( hSpatParamRendCom->num_freq_bands, + hSpatParamRendCom->diffuseness_vector[md_idx], + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); - ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, - hDirACRend, - hMasaExtRend->hVBAPdata, - masa_band_mapping, - NULL, - azimuth, - elevation, - md_idx, - surCohRatio, - 0 ); + if ( coherence_flag ) + { + for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + surCohRatio[i] = hSpatParamRendCom->surroundingCoherence[md_idx][i]; + } + } + else + { + set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); + } + } + ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, + hDirACRend, + hMasaExtRend->hVBAPdata, + masa_band_mapping, + NULL, + azimuth, + elevation, + md_idx, + surCohRatio, + 0 ); - for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) - { - index_slot = slot_idx_start + slot_idx; - md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; - /* CLDFB Analysis*/ - for ( ch = 0; ch < nchan_transport; ch++ ) + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - cldfbAnalysis_ts( &( output_f[ch][hSpatParamRendCom->num_freq_bands * index_slot] ), - Cldfb_RealBuffer[ch][0], - Cldfb_ImagBuffer[ch][0], - hSpatParamRendCom->num_freq_bands, - hMasaExtRend->cldfbAnaRend[ch] ); - } + index_slot = slot_idx_start + slot_idx; + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + /* CLDFB Analysis*/ + for ( ch = 0; ch < nchan_transport; ch++ ) + { + cldfbAnalysis_ts( &( output_f[ch][hSpatParamRendCom->num_freq_bands * index_slot] ), + Cldfb_RealBuffer[ch][0], + Cldfb_ImagBuffer[ch][0], + hSpatParamRendCom->num_freq_bands, + hMasaExtRend->cldfbAnaRend[ch] ); + } - if ( nchan_transport == 1 ) - { - /* Need to set second CLDFB channel to zero as further processing assumes CNA content in it */ - set_zero( Cldfb_RealBuffer[1][0], hSpatParamRendCom->num_freq_bands ); - set_zero( Cldfb_ImagBuffer[1][0], hSpatParamRendCom->num_freq_bands ); - } - - /*-----------------------------------------------------------------* - * prototype signal computation - *-----------------------------------------------------------------*/ - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, - reference_power, slot_idx, nchan_transport, - hDirACRend->num_outputs_diff, - hSpatParamRendCom->num_freq_bands, - 0 ); - } - else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) - { - protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirACRend->proto_frame_f, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, - 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect ); - } - else - { - switch ( nchan_transport ) - { - case 2: - protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirACRend->proto_frame_f, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, - hDirACRend->hOutSetup.is_loudspeaker_setup, - slot_idx, - hSpatParamRendCom->num_freq_bands, - hDirACRend->masa_stereo_type_detect ); - break; - case 1: - protoSignalComputation1( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirACRend->proto_frame_f, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, - slot_idx, - hDirACRend->num_protos_diff, - hSpatParamRendCom->num_freq_bands ); - break; - default: - return; + if ( nchan_transport == 1 ) + { + /* Need to set second CLDFB channel to zero as further processing assumes CNA content in it */ + set_zero( Cldfb_RealBuffer[1][0], hSpatParamRendCom->num_freq_bands ); + set_zero( Cldfb_ImagBuffer[1][0], hSpatParamRendCom->num_freq_bands ); } - } - /*-----------------------------------------------------------------* - * frequency domain decorrelation - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * prototype signal computation + *-----------------------------------------------------------------*/ - if ( hDirACRend->proto_signal_decorr_on == 1 ) - { - /* decorrelate prototype frame */ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, - hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, - hDirACRend->synthesisConf, - nchan_transport, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, - hDirACRend->proto_index_diff, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport ), - onset_filter, - hDirACRend->h_freq_domain_decorr_ap_params, - hDirACRend->h_freq_domain_decorr_ap_state ); - - v_multc( onset_filter, 0.25f, onset_filter, hSpatParamRendCom->num_freq_bands ); - v_add( onset_filter, onset_filter_subframe, onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); - p_onset_filter = onset_filter_subframe; + protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, + reference_power, slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + 0 ); + } + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + { + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect ); } else { - ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, - hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, - hDirACRend->synthesisConf, - nchan_transport, - hDirACRend->proto_frame_f, - hDirACRend->num_protos_diff, - hDirACRend->proto_index_diff, - DirAC_mem.frame_dec_f, - onset_filter, - hDirACRend->h_freq_domain_decorr_ap_params, - hDirACRend->h_freq_domain_decorr_ap_state ); - - hDirACRend->proto_frame_dec_f = DirAC_mem.frame_dec_f; - p_onset_filter = onset_filter; + switch ( nchan_transport ) + { + case 2: + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + hDirACRend->hOutSetup.is_loudspeaker_setup, + slot_idx, + hSpatParamRendCom->num_freq_bands, + hDirACRend->masa_stereo_type_detect ); + break; + case 1: + protoSignalComputation1( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + slot_idx, + hDirACRend->num_protos_diff, + hSpatParamRendCom->num_freq_bands ); + break; + default: + return; + } } - } - else - { - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + + /*-----------------------------------------------------------------* + * frequency domain decorrelation + *-----------------------------------------------------------------*/ + + if ( hDirACRend->proto_signal_decorr_on == 1 ) { - set_f( onset_filter_subframe, 1.f, hSpatParamRendCom->num_freq_bands ); - p_onset_filter = onset_filter_subframe; + /* decorrelate prototype frame */ + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + nchan_transport, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->proto_index_diff, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport ), + onset_filter, + hDirACRend->h_freq_domain_decorr_ap_params, + hDirACRend->h_freq_domain_decorr_ap_state ); + + v_multc( onset_filter, 0.25f, onset_filter, hSpatParamRendCom->num_freq_bands ); + v_add( onset_filter, onset_filter_subframe, onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); + p_onset_filter = onset_filter_subframe; + } + else + { + ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + nchan_transport, + hDirACRend->proto_frame_f, + hDirACRend->num_protos_diff, + hDirACRend->proto_index_diff, + DirAC_mem.frame_dec_f, + onset_filter, + hDirACRend->h_freq_domain_decorr_ap_params, + hDirACRend->h_freq_domain_decorr_ap_state ); + + hDirACRend->proto_frame_dec_f = DirAC_mem.frame_dec_f; + p_onset_filter = onset_filter; + } } else { - /* no frequency domain decorrelation: use prototype frame */ - hDirACRend->proto_frame_dec_f = hDirACRend->proto_frame_f; - p_onset_filter = NULL; + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + set_f( onset_filter_subframe, 1.f, hSpatParamRendCom->num_freq_bands ); + p_onset_filter = onset_filter_subframe; + } + else + { + /* no frequency domain decorrelation: use prototype frame */ + hDirACRend->proto_frame_dec_f = hDirACRend->proto_frame_f; + p_onset_filter = NULL; + } } - } - /*-----------------------------------------------------------------* - * output synthesis - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * output synthesis + *-----------------------------------------------------------------*/ - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) - { - /* Compute diffuse prototypes */ - ivas_dirac_dec_compute_diffuse_proto( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); - } + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + { + /* Compute diffuse prototypes */ + ivas_dirac_dec_compute_diffuse_proto( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); + } - ivas_dirac_dec_output_synthesis_process_slot( reference_power, - p_onset_filter, - azimuth, - elevation, - hSpatParamRendCom->diffuseness_vector[md_idx], - hSpatParamRendCom, - hDirACRend, - hMasaExtRend->hVBAPdata, - hDirACRend->hOutSetup, - nchan_transport, - md_idx, - 0, - 0 ); + ivas_dirac_dec_output_synthesis_process_slot( reference_power, + p_onset_filter, + azimuth, + elevation, + hSpatParamRendCom->diffuseness_vector[md_idx], + hSpatParamRendCom, + hDirACRend, + hMasaExtRend->hVBAPdata, + hDirACRend->hOutSetup, + nchan_transport, + md_idx, + 0, + 0 ); - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - v_add( reference_power, reference_power_smooth, reference_power_smooth, hSpatParamRendCom->num_freq_bands ); + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + v_add( reference_power, reference_power_smooth, reference_power_smooth, hSpatParamRendCom->num_freq_bands ); + } } - } - ivas_dirac_dec_output_synthesis_get_interpolator( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + ivas_dirac_dec_output_synthesis_get_interpolator( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hSpatParamRendCom, - hDirACRend, - nchan_transport, - hSpatParamRendCom->subframe_nbslots[subframe_idx], - p_onset_filter, - diffuseness_vector, - 0, - 0 ); - } - else - { - ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hSpatParamRendCom, - hDirACRend, - hSpatParamRendCom->subframe_nbslots[subframe_idx], - diffuseness_vector, - reference_power_smooth, - 1.0f, - 0 ); - } + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( Cldfb_RealBuffer, + Cldfb_ImagBuffer, + hSpatParamRendCom, + hDirACRend, + nchan_transport, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + p_onset_filter, + diffuseness_vector, + 0, + 0 ); + } + else + { + ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( Cldfb_RealBuffer, + Cldfb_ImagBuffer, + hSpatParamRendCom, + hDirACRend, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + diffuseness_vector, + reference_power_smooth, + 1.0f, + 0 ); + } - /*-----------------------------------------------------------------* - * CLDFB synthesis (and binaural rendering) - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * CLDFB synthesis (and binaural rendering) + *-----------------------------------------------------------------*/ - index_slot = slot_idx_start_cldfb_synth; + index_slot = slot_idx_start_cldfb_synth; - { - float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t outchannels; + { + float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t outchannels; - idx_in = 0; - idx_lfe = 0; + idx_in = 0; + idx_lfe = 0; - outchannels = hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; + outchannels = hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; - /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */ + /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */ - for ( ch = 0; ch < outchannels; ch++ ) - { - if ( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( hDirACRend->hOutSetup.index_lfe[idx_lfe] == ch ) ) + for ( ch = 0; ch < outchannels; ch++ ) { - /* No LFE for MASA rendering */ - set_zero( &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); - - if ( idx_lfe < ( hDirACRend->hOutSetup.num_lfe - 1 ) ) + if ( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( hDirACRend->hOutSetup.index_lfe[idx_lfe] == ch ) ) { - idx_lfe++; + /* No LFE for MASA rendering */ + set_zero( &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + + if ( idx_lfe < ( hDirACRend->hOutSetup.num_lfe - 1 ) ) + { + idx_lfe++; + } } - } - else - { - /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + else { - RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; - ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + { + RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; + ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; + } + cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], hMasaExtRend->cldfbSynRend[idx_in] ); + idx_in++; } - cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], hMasaExtRend->cldfbSynRend[idx_in] ); - idx_in++; } } - } - hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx]; - hSpatParamRendCom->subframes_rendered++; + hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx]; + hSpatParamRendCom->subframes_rendered++; - pop_wmops(); + pop_wmops(); - return; -} + return; + } -/*------------------------------------------------------------------------- - * ivas_masa_ext_dirac_render() - * - * MASA external renderer - *------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------- + * ivas_masa_ext_dirac_render() + * + * MASA external renderer + *------------------------------------------------------------------------*/ -void ivas_masa_ext_dirac_render( - MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - float *output_f[], /* i/o: input/output signals in time domain */ - const int16_t num_subframes /* i : number of subframes to render */ -) -{ - int16_t subframe_idx; - float *output_f_local[MAX_OUTPUT_CHANNELS]; - int16_t n, n_samples_sf; - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + void ivas_masa_ext_dirac_render( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ + float *output_f[], /* i/o: input/output signals in time domain */ + const int16_t num_subframes /* i : number of subframes to render */ + ) + { + int16_t subframe_idx; + float *output_f_local[MAX_OUTPUT_CHANNELS]; + int16_t n, n_samples_sf; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; + hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - n_samples_sf = JBM_CLDFB_SLOTS_IN_SUBFRAME * hSpatParamRendCom->slot_size; + n_samples_sf = JBM_CLDFB_SLOTS_IN_SUBFRAME * hSpatParamRendCom->slot_size; - for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) - { - output_f_local[n] = output_f[n]; - } + for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) + { + output_f_local[n] = output_f[n]; + } - hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; + hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; - for ( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) - { - hSpatParamRendCom->slots_rendered = 0; - ivas_masa_ext_dirac_render_sf( hMasaExtRend, output_f_local ); - for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) + for ( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { - output_f_local[n] += n_samples_sf; + hSpatParamRendCom->slots_rendered = 0; + ivas_masa_ext_dirac_render_sf( hMasaExtRend, output_f_local ); + for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) + { + output_f_local[n] += n_samples_sf; + } + + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } - hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + return; } - - return; -} -- GitLab From 6ffe38273e31082dd56b8115ebb3c27759416b4f Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 23 Apr 2026 14:35:41 +0300 Subject: [PATCH 3/5] Fix sanitizer bug. --- lib_rend/ivas_dirac_rend.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index d61c0a46b..56059a53d 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -1345,7 +1345,11 @@ void protoSignalComputation2( int16_t dipole_freq_range[2]; #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES float tempSpaced, tempDmx, tempDualMono; - max_band_diff_ene = min( stereo_type_detect->max_band_diff_ene, num_freq_bands ); /* Local version for correct maximum */ + + if ( stereo_type_detect != NULL ) + { + max_band_diff_ene = min( stereo_type_detect->max_band_diff_ene, num_freq_bands ); /* Local version for correct maximum */ + } #else float tempSpaced, tempDmx; #endif -- GitLab From 2405cab30d2669ea0399f2b99395b6736289a7da Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 23 Apr 2026 14:52:18 +0300 Subject: [PATCH 4/5] Add default init --- lib_rend/ivas_dirac_rend.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 56059a53d..6e8b98cf4 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -1346,6 +1346,7 @@ void protoSignalComputation2( #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES float tempSpaced, tempDmx, tempDualMono; + max_band_diff_ene = IVAS_CLDFB_NO_CHANNELS_MAX; if ( stereo_type_detect != NULL ) { max_band_diff_ene = min( stereo_type_detect->max_band_diff_ene, num_freq_bands ); /* Local version for correct maximum */ -- GitLab From 297805c83f0ee49a1fb92c5d9e00616106867f49 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Mon, 27 Apr 2026 16:59:52 +0300 Subject: [PATCH 5/5] Fix missing curly brace. --- lib_rend/ivas_dirac_rend.c | 1671 ++++++++++++++++++------------------ 1 file changed, 836 insertions(+), 835 deletions(-) diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 6e8b98cf4..bcdfbd960 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -1640,6 +1640,7 @@ void protoSignalComputation2( { p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + } #else if ( ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS && stereo_type_detect->current_stereo_type == MASA_STEREO_DOWNMIX ) || ( stereo_type_detect->type_change_direction == MASA_STEREO_DOWNMIX && stereo_type_detect->current_stereo_type == MASA_STEREO_SPACED_MICS ) ) @@ -1685,1070 +1686,1070 @@ void protoSignalComputation2( p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorDualMono * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); } #endif - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + } + else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) + { + if ( l < ( dipole_freq_range[0] ) ) /* proto = W */ + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; } - else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) + else if ( l < ( dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */ { - if ( l < ( dipole_freq_range[0] ) ) /* proto = W */ - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; - proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; - } - else if ( l < ( dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */ - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; - } - else /* proto = W */ - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; - proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; - } + p_proto_buffer[2 * num_freq_bands + 2 * l] = ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; } -#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - else if ( stereo_type_detect->masa_stereo_type == MASA_DUAL_MONO ) + else /* proto = W */ { - /* proto = W */ p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; } - else /* MASA_STEREO_DOWNMIX */ + } +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + else if ( stereo_type_detect->masa_stereo_type == MASA_DUAL_MONO ) + { + /* proto = W */ + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; + } + else /* MASA_STEREO_DOWNMIX */ #else else #endif - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; - } - - /* Compute protos for decorrelation */ - proto_frame_f[2 * l] = Real_aux; - proto_frame_f[2 * l + 1] = Imag_aux; - proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; } - if ( stereo_type_detect->interpolator > 0 ) + /* Compute protos for decorrelation */ + proto_frame_f[2 * l] = Real_aux; + proto_frame_f[2 * l + 1] = Imag_aux; + proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + } + + if ( stereo_type_detect->interpolator > 0 ) + { + stereo_type_detect->interpolator++; + if ( stereo_type_detect->interpolator == MASA_STEREO_INTERPOLATION_SLOTS ) { - stereo_type_detect->interpolator++; - if ( stereo_type_detect->interpolator == MASA_STEREO_INTERPOLATION_SLOTS ) - { - stereo_type_detect->interpolator = 0; - stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction; - } + stereo_type_detect->interpolator = 0; + stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction; } + } - stereo_type_detect->left_bb_power = a * left_bb_power + b * stereo_type_detect->left_bb_power; - stereo_type_detect->right_bb_power = a * right_bb_power + b * stereo_type_detect->right_bb_power; - stereo_type_detect->total_bb_power = a * total_bb_power + b * stereo_type_detect->total_bb_power; + stereo_type_detect->left_bb_power = a * left_bb_power + b * stereo_type_detect->left_bb_power; + stereo_type_detect->right_bb_power = a * right_bb_power + b * stereo_type_detect->right_bb_power; + stereo_type_detect->total_bb_power = a * total_bb_power + b * stereo_type_detect->total_bb_power; - lr_bb_power = ( stereo_type_detect->left_bb_power < stereo_type_detect->right_bb_power ) ? stereo_type_detect->left_bb_power : stereo_type_detect->right_bb_power; - lr_bb_power *= 2.0f; - lr_total_bb_ratio = 10.0f * log10f( lr_bb_power / ( stereo_type_detect->total_bb_power + EPSILON ) ); + lr_bb_power = ( stereo_type_detect->left_bb_power < stereo_type_detect->right_bb_power ) ? stereo_type_detect->left_bb_power : stereo_type_detect->right_bb_power; + lr_bb_power *= 2.0f; + lr_total_bb_ratio = 10.0f * log10f( lr_bb_power / ( stereo_type_detect->total_bb_power + EPSILON ) ); - stereo_type_detect->left_hi_power = a2 * left_hi_power + b2 * stereo_type_detect->left_hi_power; - stereo_type_detect->right_hi_power = a2 * right_hi_power + b2 * stereo_type_detect->right_hi_power; - stereo_type_detect->total_hi_power = a2 * total_hi_power + b2 * stereo_type_detect->total_hi_power; + stereo_type_detect->left_hi_power = a2 * left_hi_power + b2 * stereo_type_detect->left_hi_power; + stereo_type_detect->right_hi_power = a2 * right_hi_power + b2 * stereo_type_detect->right_hi_power; + stereo_type_detect->total_hi_power = a2 * total_hi_power + b2 * stereo_type_detect->total_hi_power; - lr_hi_power = ( stereo_type_detect->left_hi_power < stereo_type_detect->right_hi_power ) ? stereo_type_detect->left_hi_power : stereo_type_detect->right_hi_power; - lr_hi_power *= 2.0f; - lr_total_hi_ratio = 10.0f * log10f( lr_hi_power / ( stereo_type_detect->total_hi_power + EPSILON ) ); + lr_hi_power = ( stereo_type_detect->left_hi_power < stereo_type_detect->right_hi_power ) ? stereo_type_detect->left_hi_power : stereo_type_detect->right_hi_power; + lr_hi_power *= 2.0f; + lr_total_hi_ratio = 10.0f * log10f( lr_hi_power / ( stereo_type_detect->total_hi_power + EPSILON ) ); - minimum( sum_total_ratio, min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio ); - min_sum_total_ratio_db = 10.0f * log10f( min_sum_total_ratio ); + minimum( sum_total_ratio, min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio ); + min_sum_total_ratio_db = 10.0f * log10f( min_sum_total_ratio ); - stereo_type_detect->lr_total_bb_ratio_db = lr_total_bb_ratio; - stereo_type_detect->lr_total_hi_ratio_db = lr_total_hi_ratio; - stereo_type_detect->min_sum_total_ratio_db = min_sum_total_ratio_db; + stereo_type_detect->lr_total_bb_ratio_db = lr_total_bb_ratio; + stereo_type_detect->lr_total_hi_ratio_db = lr_total_hi_ratio; + stereo_type_detect->min_sum_total_ratio_db = min_sum_total_ratio_db; - ivas_masa_stereotype_detection( stereo_type_detect ); - } - else - { - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2; + ivas_masa_stereotype_detection( stereo_type_detect ); + } + else + { + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2; - for ( l = 0; l < num_freq_bands; l++ ) - { - Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; - Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; + for ( l = 0; l < num_freq_bands; l++ ) + { + Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; + Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; - reference_power[l] = Real_aux * Real_aux + Imag_aux * Imag_aux; - proto_power_smooth[l] += reference_power[l]; - p_proto_buffer[2 * l] = Real_aux; - p_proto_buffer[2 * l + 1] = Imag_aux; + reference_power[l] = Real_aux * Real_aux + Imag_aux * Imag_aux; + proto_power_smooth[l] += reference_power[l]; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; - p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; - proto_frame_f[2 * l] = Real_aux; - proto_frame_f[2 * l + 1] = Imag_aux; + proto_frame_f[2 * l] = Real_aux; + proto_frame_f[2 * l + 1] = Imag_aux; - proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; - } + proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; } - - return; } + return; +} - /*------------------------------------------------------------------------- - * protoSignalComputation4() - * - * - *-------------------------------------------------------------------------*/ - void protoSignalComputation4( - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float *proto_frame_f, - float *proto_direct_buffer_f, - float *reference_power, - float *proto_power_smooth, - const int16_t slot_index, - const int16_t num_outputs_diff, - const int16_t num_freq_bands, - const float *mtx_hoa_decoder, - const int16_t nchan_transport, - const int16_t *sba_map_tc_ind ) - { - int16_t k, l; - int16_t n; - float sq_tmp; - float *p_proto_buffer; +/*------------------------------------------------------------------------- + * protoSignalComputation4() + * + * + *-------------------------------------------------------------------------*/ - set_zero( reference_power, num_freq_bands ); - for ( k = 0; k < 4; k++ ) +void protoSignalComputation4( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_frame_f, + float *proto_direct_buffer_f, + float *reference_power, + float *proto_power_smooth, + const int16_t slot_index, + const int16_t num_outputs_diff, + const int16_t num_freq_bands, + const float *mtx_hoa_decoder, + const int16_t nchan_transport, + const int16_t *sba_map_tc_ind ) +{ + int16_t k, l; + int16_t n; + float sq_tmp; + float *p_proto_buffer; + + set_zero( reference_power, num_freq_bands ); + for ( k = 0; k < 4; k++ ) + { + for ( l = 0; l < num_freq_bands; l++ ) { - for ( l = 0; l < num_freq_bands; l++ ) - { - sq_tmp = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l]; - reference_power[l] += 0.5f * sq_tmp; - } + sq_tmp = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l]; + reference_power[l] += 0.5f * sq_tmp; } + } - /*For decorrelated diffuseness*/ - for ( l = 0; l < num_outputs_diff; l++ ) + /*For decorrelated diffuseness*/ + for ( l = 0; l < num_outputs_diff; l++ ) + { + for ( k = 0; k < num_freq_bands; k++ ) { - for ( k = 0; k < num_freq_bands; k++ ) + proto_frame_f[2 * l * num_freq_bands + 2 * k] = 0.f; + proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] = 0.f; + for ( n = 0; n < nchan_transport; n++ ) { - proto_frame_f[2 * l * num_freq_bands + 2 * k] = 0.f; - proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] = 0.f; - for ( n = 0; n < nchan_transport; n++ ) - { - proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; - proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; - } + proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; + proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; } } + } - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff; - for ( k = 0; k < num_outputs_diff; k++ ) + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff; + for ( k = 0; k < num_outputs_diff; k++ ) + { + for ( l = 0; l < num_freq_bands; l++ ) { - for ( l = 0; l < num_freq_bands; l++ ) - { - sq_tmp = proto_frame_f[k * 2 * num_freq_bands + 2 * l] * proto_frame_f[k * 2 * num_freq_bands + 2 * l] + proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1] * proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; - proto_power_smooth[l + k * num_freq_bands] += sq_tmp; - p_proto_buffer[k * 2 * num_freq_bands + 2 * l] = proto_frame_f[k * 2 * num_freq_bands + 2 * l]; - p_proto_buffer[k * 2 * num_freq_bands + 2 * l + 1] = proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; - } + sq_tmp = proto_frame_f[k * 2 * num_freq_bands + 2 * l] * proto_frame_f[k * 2 * num_freq_bands + 2 * l] + proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1] * proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; + proto_power_smooth[l + k * num_freq_bands] += sq_tmp; + p_proto_buffer[k * 2 * num_freq_bands + 2 * l] = proto_frame_f[k * 2 * num_freq_bands + 2 * l]; + p_proto_buffer[k * 2 * num_freq_bands + 2 * l + 1] = proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; } - - return; } + return; +} - /*------------------------------------------------------------------------- - * ivas_dirac_dec_compute_diffuse_proto() - * - * Compute diffuse prototype buffer and smooth power, only for decorrelated bands - *------------------------------------------------------------------------*/ - - void ivas_dirac_dec_compute_diffuse_proto( - DIRAC_REND_HANDLE hDirACRend, - const int16_t num_freq_bands, - const int16_t slot_idx /* i : slot index */ - ) - { - int16_t k, l; - int16_t num_freq_bands_diff; - float *p_diff_buffer, *p_diff_buffer_1; - float *p_proto_diff, *p_power_smooth, *proto_frame_dec_f; - DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; - DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; - int16_t m; - float *p_hoa_enc; - proto_frame_dec_f = hDirACRend->proto_frame_dec_f; - h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); - h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); +/*------------------------------------------------------------------------- + * ivas_dirac_dec_compute_diffuse_proto() + * + * Compute diffuse prototype buffer and smooth power, only for decorrelated bands + *------------------------------------------------------------------------*/ - num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; - if ( num_freq_bands_diff == 0 ) - { - return; - } +void ivas_dirac_dec_compute_diffuse_proto( + DIRAC_REND_HANDLE hDirACRend, + const int16_t num_freq_bands, + const int16_t slot_idx /* i : slot index */ +) +{ + int16_t k, l; + int16_t num_freq_bands_diff; + float *p_diff_buffer, *p_diff_buffer_1; + float *p_proto_diff, *p_power_smooth, *proto_frame_dec_f; + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; + DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; + int16_t m; + float *p_hoa_enc; + + proto_frame_dec_f = hDirACRend->proto_frame_dec_f; + h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); + + num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; + if ( num_freq_bands_diff == 0 ) + { + return; + } - p_diff_buffer = h_dirac_output_synthesis_state->proto_diffuse_buffer_f + slot_idx * 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE; - p_diff_buffer_1 = p_diff_buffer + 1; - p_power_smooth = h_dirac_output_synthesis_state->proto_power_diff_smooth; + p_diff_buffer = h_dirac_output_synthesis_state->proto_diffuse_buffer_f + slot_idx * 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE; + p_diff_buffer_1 = p_diff_buffer + 1; + p_power_smooth = h_dirac_output_synthesis_state->proto_power_diff_smooth; - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) + { + for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) { - for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) + p_proto_diff = proto_frame_dec_f + k * 2 * num_freq_bands; + for ( l = 0; l < num_freq_bands_diff; l++ ) { - p_proto_diff = proto_frame_dec_f + k * 2 * num_freq_bands; - for ( l = 0; l < num_freq_bands_diff; l++ ) - { - *p_diff_buffer = *( p_proto_diff++ ); - *p_diff_buffer_1 = *( p_proto_diff++ ); - *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); - p_diff_buffer += 2; - p_diff_buffer_1 += 2; - } + *p_diff_buffer = *( p_proto_diff++ ); + *p_diff_buffer_1 = *( p_proto_diff++ ); + *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); + p_diff_buffer += 2; + p_diff_buffer_1 += 2; } } - else + } + else + { + /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/ + for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) { - /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/ - for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) + for ( l = 0; l < num_freq_bands_diff; l++ ) { - for ( l = 0; l < num_freq_bands_diff; l++ ) - { - p_hoa_enc = hDirACRend->hoa_encoder + k; - p_proto_diff = proto_frame_dec_f + 2 * l; + p_hoa_enc = hDirACRend->hoa_encoder + k; + p_proto_diff = proto_frame_dec_f + 2 * l; - *p_diff_buffer = 0.f; - *p_diff_buffer_1 = 0.f; - - /*LS to HOA*/ - for ( m = 0; m < hDirACRend->num_outputs_diff; m++ ) - { - *p_diff_buffer += ( *p_hoa_enc ) * ( *p_proto_diff ); - *p_diff_buffer_1 += ( *p_hoa_enc ) * ( *( p_proto_diff + 1 ) ); - p_hoa_enc += hDirACRend->hOutSetup.nchan_out_woLFE; - p_proto_diff += 2 * num_freq_bands; - } + *p_diff_buffer = 0.f; + *p_diff_buffer_1 = 0.f; - *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); - p_diff_buffer += 2; - p_diff_buffer_1 += 2; + /*LS to HOA*/ + for ( m = 0; m < hDirACRend->num_outputs_diff; m++ ) + { + *p_diff_buffer += ( *p_hoa_enc ) * ( *p_proto_diff ); + *p_diff_buffer_1 += ( *p_hoa_enc ) * ( *( p_proto_diff + 1 ) ); + p_hoa_enc += hDirACRend->hOutSetup.nchan_out_woLFE; + p_proto_diff += 2 * num_freq_bands; } + + *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); + p_diff_buffer += 2; + p_diff_buffer_1 += 2; } } - - return; } + return; +} + - /*------------------------------------------------------------------------- - * computeDirectionAngles() - * - *------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * computeDirectionAngles() + * + *------------------------------------------------------------------------*/ - void computeDirectionAngles( - float *intensity_real_x, - float *intensity_real_y, - float *intensity_real_z, - const int16_t num_frequency_bands, - int16_t *azimuth, - int16_t *elevation ) +void computeDirectionAngles( + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z, + const int16_t num_frequency_bands, + int16_t *azimuth, + int16_t *elevation ) +{ + int16_t k; + float intensityNorm; + float x, y, z, radius; + + for ( k = 0; k < num_frequency_bands; ++k ) { - int16_t k; - float intensityNorm; - float x, y, z, radius; + intensityNorm = *( intensity_real_x ) * *( intensity_real_x ) + + *( intensity_real_y ) * *( intensity_real_y ) + + *( intensity_real_z ) * *( intensity_real_z ); - for ( k = 0; k < num_frequency_bands; ++k ) + if ( intensityNorm <= EPSILON ) { - intensityNorm = *( intensity_real_x ) * *( intensity_real_x ) + - *( intensity_real_y ) * *( intensity_real_y ) + - *( intensity_real_z ) * *( intensity_real_z ); - - if ( intensityNorm <= EPSILON ) - { - intensityNorm = 1.0f; - x = 1.0f; - y = 0.0f; - z = 0.0f; - intensity_real_x++; - intensity_real_y++; - intensity_real_z++; - } - else - { - intensityNorm = sqrtf( 1.f / intensityNorm ); - x = *( intensity_real_x++ ) * intensityNorm; - y = *( intensity_real_y++ ) * intensityNorm; - z = *( intensity_real_z++ ) * intensityNorm; - } - radius = sqrtf( x * x + y * y ); - azimuth[k] = (int16_t) ( max( -180.0f, min( 180.0f, atan2f( y, x ) / EVS_PI * 180.0f ) ) + 0.5f ); - elevation[k] = (int16_t) ( max( -90.0f, min( 180.0f, atan2f( z, radius ) / EVS_PI * 180.0f ) ) + 0.5f ); + intensityNorm = 1.0f; + x = 1.0f; + y = 0.0f; + z = 0.0f; + intensity_real_x++; + intensity_real_y++; + intensity_real_z++; } - - return; + else + { + intensityNorm = sqrtf( 1.f / intensityNorm ); + x = *( intensity_real_x++ ) * intensityNorm; + y = *( intensity_real_y++ ) * intensityNorm; + z = *( intensity_real_z++ ) * intensityNorm; + } + radius = sqrtf( x * x + y * y ); + azimuth[k] = (int16_t) ( max( -180.0f, min( 180.0f, atan2f( y, x ) / EVS_PI * 180.0f ) ) + 0.5f ); + elevation[k] = (int16_t) ( max( -90.0f, min( 180.0f, atan2f( z, radius ) / EVS_PI * 180.0f ) ) + 0.5f ); } + return; +} - /*------------------------------------------------------------------------- - * ivas_masa_init_stereotype_detection() - * - * Initialize stereo transport signal type detection - *------------------------------------------------------------------------*/ - void ivas_masa_init_stereotype_detection( +/*------------------------------------------------------------------------- + * ivas_masa_init_stereotype_detection() + * + * Initialize stereo transport signal type detection + *------------------------------------------------------------------------*/ + +void ivas_masa_init_stereotype_detection( #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - MASA_STEREO_TYPE_DETECT * stereo_type_detect, - int32_t ivas_total_brate ) + MASA_STEREO_TYPE_DETECT *stereo_type_detect, + int32_t ivas_total_brate ) #else MASA_STEREO_TYPE_DETECT *stereo_type_detect ) #endif - { - stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; - stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; - stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX; +{ + stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; + stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; + stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX; - stereo_type_detect->counter = 0; - stereo_type_detect->interpolator = 0; + stereo_type_detect->counter = 0; + stereo_type_detect->interpolator = 0; - stereo_type_detect->dipole_freq_range[0] = 1; - stereo_type_detect->dipole_freq_range[1] = 3; + stereo_type_detect->dipole_freq_range[0] = 1; + stereo_type_detect->dipole_freq_range[1] = 3; - stereo_type_detect->left_bb_power = 0.0f; /* Broadband estimates */ - stereo_type_detect->right_bb_power = 0.0f; - stereo_type_detect->total_bb_power = 0.0f; + stereo_type_detect->left_bb_power = 0.0f; /* Broadband estimates */ + stereo_type_detect->right_bb_power = 0.0f; + stereo_type_detect->total_bb_power = 0.0f; - stereo_type_detect->left_hi_power = 0.0f; /* High-frequency estimates */ - stereo_type_detect->right_hi_power = 0.0f; - stereo_type_detect->total_hi_power = 0.0f; + stereo_type_detect->left_hi_power = 0.0f; /* High-frequency estimates */ + stereo_type_detect->right_hi_power = 0.0f; + stereo_type_detect->total_hi_power = 0.0f; - set_zero( stereo_type_detect->sum_power, MASA_SUM_FREQ_RANGE_BINS ); - set_zero( stereo_type_detect->total_power, MASA_SUM_FREQ_RANGE_BINS ); + set_zero( stereo_type_detect->sum_power, MASA_SUM_FREQ_RANGE_BINS ); + set_zero( stereo_type_detect->total_power, MASA_SUM_FREQ_RANGE_BINS ); - stereo_type_detect->subtract_power_y = 0.0f; - stereo_type_detect->subtract_power_y_smooth = 0.0f; - stereo_type_detect->target_power_y_smooth = 0.0f; + stereo_type_detect->subtract_power_y = 0.0f; + stereo_type_detect->subtract_power_y_smooth = 0.0f; + stereo_type_detect->target_power_y_smooth = 0.0f; - stereo_type_detect->lr_total_bb_ratio_db = 0.0f; - stereo_type_detect->lr_total_hi_ratio_db = 0.0f; - stereo_type_detect->min_sum_total_ratio_db = 0.0f; - stereo_type_detect->subtract_target_ratio_db = 0.0f; + stereo_type_detect->lr_total_bb_ratio_db = 0.0f; + stereo_type_detect->lr_total_hi_ratio_db = 0.0f; + stereo_type_detect->min_sum_total_ratio_db = 0.0f; + stereo_type_detect->subtract_target_ratio_db = 0.0f; #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - stereo_type_detect->inst_diff_bb_power = 0.0f; - stereo_type_detect->inst_total_bb_power = 0.0f; + stereo_type_detect->inst_diff_bb_power = 0.0f; + stereo_type_detect->inst_total_bb_power = 0.0f; - stereo_type_detect->max_band_diff_ene = IVAS_CLDFB_NO_CHANNELS_MAX; - if ( ivas_total_brate < IVAS_48k ) - { - stereo_type_detect->max_band_diff_ene = 18; - } + stereo_type_detect->max_band_diff_ene = IVAS_CLDFB_NO_CHANNELS_MAX; + if ( ivas_total_brate < IVAS_48k ) + { + stereo_type_detect->max_band_diff_ene = 18; + } #endif - return; - } + return; +} - /*------------------------------------------------------------------------- - * ivas_masa_stereotype_detection() - * - * Detect the type of the transport audio signals - *------------------------------------------------------------------------*/ - - void ivas_masa_stereotype_detection( - MASA_STEREO_TYPE_DETECT * stereo_type_detect ) - { - float lr_total_bb_ratio_db = stereo_type_detect->lr_total_bb_ratio_db; - float lr_total_hi_ratio_db = stereo_type_detect->lr_total_hi_ratio_db; - float min_sum_total_ratio_db = stereo_type_detect->min_sum_total_ratio_db; - float subtract_target_ratio_db = stereo_type_detect->subtract_target_ratio_db; - float change_to_spaced; - int16_t change_to_spaced_selection; - float change_to_downmix; - float change_to_downmix2; - int16_t change_to_downmix_selection; - float subtract_temp; - float min_sum_temp; - float lr_total_bb_temp; - float lr_total_hi_temp; +/*------------------------------------------------------------------------- + * ivas_masa_stereotype_detection() + * + * Detect the type of the transport audio signals + *------------------------------------------------------------------------*/ + +void ivas_masa_stereotype_detection( + MASA_STEREO_TYPE_DETECT *stereo_type_detect ) +{ + float lr_total_bb_ratio_db = stereo_type_detect->lr_total_bb_ratio_db; + float lr_total_hi_ratio_db = stereo_type_detect->lr_total_hi_ratio_db; + float min_sum_total_ratio_db = stereo_type_detect->min_sum_total_ratio_db; + float subtract_target_ratio_db = stereo_type_detect->subtract_target_ratio_db; + float change_to_spaced; + int16_t change_to_spaced_selection; + float change_to_downmix; + float change_to_downmix2; + int16_t change_to_downmix_selection; + float subtract_temp; + float min_sum_temp; + float lr_total_bb_temp; + float lr_total_hi_temp; #ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - int16_t change_to_dual_mono_selection; - float diffPerSum; + int16_t change_to_dual_mono_selection; + float diffPerSum; - /* Determine if broadband energy and ratio between difference broadband energy and broadband energy indicate - * that the signal type is dual mono */ - change_to_dual_mono_selection = 0; - if ( stereo_type_detect->inst_total_bb_power > 1.0f ) + /* Determine if broadband energy and ratio between difference broadband energy and broadband energy indicate + * that the signal type is dual mono */ + change_to_dual_mono_selection = 0; + if ( stereo_type_detect->inst_total_bb_power > 1.0f ) + { + diffPerSum = stereo_type_detect->inst_diff_bb_power / stereo_type_detect->inst_total_bb_power; + if ( diffPerSum < ( stereo_type_detect->current_stereo_type == MASA_DUAL_MONO ? MASA_DUAL_MONO_TAU1 : MASA_DUAL_MONO_TAU2 ) ) { - diffPerSum = stereo_type_detect->inst_diff_bb_power / stereo_type_detect->inst_total_bb_power; - if ( diffPerSum < ( stereo_type_detect->current_stereo_type == MASA_DUAL_MONO ? MASA_DUAL_MONO_TAU1 : MASA_DUAL_MONO_TAU2 ) ) - { - change_to_dual_mono_selection = 1; - } + change_to_dual_mono_selection = 1; } + } #endif - /* Determine if the determined features match the spaced mic type */ - change_to_spaced_selection = 0; - if ( subtract_target_ratio_db < -3.0f ) - { - subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; - min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); - lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; + /* Determine if the determined features match the spaced mic type */ + change_to_spaced_selection = 0; + if ( subtract_target_ratio_db < -3.0f ) + { + subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; + min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); + lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; - change_to_spaced = subtract_temp + min_sum_temp + lr_total_bb_temp; + change_to_spaced = subtract_temp + min_sum_temp + lr_total_bb_temp; - if ( change_to_spaced >= 1.0f ) - { - change_to_spaced_selection = 1; - } + if ( change_to_spaced >= 1.0f ) + { + change_to_spaced_selection = 1; } + } - /* Determine if the determined features match the downmix type, according to a metric */ - change_to_downmix_selection = 0; - if ( subtract_target_ratio_db > 0.0f ) - { - subtract_temp = subtract_target_ratio_db / 3.0f; - min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; - lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; + /* Determine if the determined features match the downmix type, according to a metric */ + change_to_downmix_selection = 0; + if ( subtract_target_ratio_db > 0.0f ) + { + subtract_temp = subtract_target_ratio_db / 3.0f; + min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; + lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; - change_to_downmix = subtract_temp + min_sum_temp + lr_total_bb_temp; + change_to_downmix = subtract_temp + min_sum_temp + lr_total_bb_temp; - if ( change_to_downmix >= 1.0f ) - { - change_to_downmix_selection = 1; - } + if ( change_to_downmix >= 1.0f ) + { + change_to_downmix_selection = 1; } + } - /* Determine if the determined features match the downmix type, according to another metric */ - if ( lr_total_hi_ratio_db < -12.0f ) - { - subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; - min_sum_temp = min_sum_total_ratio_db / 6.0f; - lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; + /* Determine if the determined features match the downmix type, according to another metric */ + if ( lr_total_hi_ratio_db < -12.0f ) + { + subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; + min_sum_temp = min_sum_total_ratio_db / 6.0f; + lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; - change_to_downmix2 = subtract_temp + min_sum_temp + lr_total_hi_temp; + change_to_downmix2 = subtract_temp + min_sum_temp + lr_total_hi_temp; - if ( change_to_downmix2 >= 1.0f ) - { - change_to_downmix_selection = 1; - } + if ( change_to_downmix2 >= 1.0f ) + { + change_to_downmix_selection = 1; } + } - if ( stereo_type_detect->counter < 400 ) + if ( stereo_type_detect->counter < 400 ) + { + stereo_type_detect->counter++; + } + else + { +#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES + if ( change_to_dual_mono_selection == 1 ) { - stereo_type_detect->counter++; + stereo_type_detect->masa_stereo_type = MASA_DUAL_MONO; } - else - { -#ifdef FIX_FLOAT_1578_OMASA_REND_SPIKES - if ( change_to_dual_mono_selection == 1 ) - { - stereo_type_detect->masa_stereo_type = MASA_DUAL_MONO; - } - else if ( change_to_spaced_selection == 1 ) + else if ( change_to_spaced_selection == 1 ) #else if ( change_to_spaced_selection == 1 ) #endif - { - stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS; - } - else if ( change_to_downmix_selection == 1 ) - { - stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; - } + { + stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS; } - - if ( stereo_type_detect->interpolator == 0 ) + else if ( change_to_downmix_selection == 1 ) { - if ( stereo_type_detect->current_stereo_type != stereo_type_detect->masa_stereo_type ) - { - stereo_type_detect->interpolator = 1; - stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type; - } + stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; } - - return; } - - /*------------------------------------------------------------------------- - * computeIntensityVector_dec() - * - * - *------------------------------------------------------------------------*/ - - void computeIntensityVector_dec( - float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - const int16_t num_frequency_bands, - float *intensity_real_x, - float *intensity_real_y, - float *intensity_real_z ) + if ( stereo_type_detect->interpolator == 0 ) { - /* - * W = a + ib; Y = c + id - * real(W*Y') = ac + bd - */ - int16_t i; - float real, img; - - for ( i = 0; i < num_frequency_bands; ++i ) + if ( stereo_type_detect->current_stereo_type != stereo_type_detect->masa_stereo_type ) { - real = Cldfb_RealBuffer[0][0][i]; - img = Cldfb_ImagBuffer[0][0][i]; - intensity_real_x[i] = Cldfb_RealBuffer[3][0][i] * real + Cldfb_ImagBuffer[3][0][i] * img; - intensity_real_y[i] = Cldfb_RealBuffer[1][0][i] * real + Cldfb_ImagBuffer[1][0][i] * img; - intensity_real_z[i] = Cldfb_RealBuffer[2][0][i] * real + Cldfb_ImagBuffer[2][0][i] * img; + stereo_type_detect->interpolator = 1; + stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type; } - - return; } + return; +} - /*------------------------------------------------------------------------- - * ivas_lfe_synth_with_cldfb() - * - * - *------------------------------------------------------------------------*/ - void ivas_lfe_synth_with_cldfb( - MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float RealBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - const int16_t slot_index, - const int16_t subframe_index, - const int16_t nchan_transport ) +/*------------------------------------------------------------------------- + * computeIntensityVector_dec() + * + * + *------------------------------------------------------------------------*/ + +void computeIntensityVector_dec( + float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const int16_t num_frequency_bands, + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z ) +{ + /* + * W = a + ib; Y = c + id + * real(W*Y') = ac + bd + */ + int16_t i; + float real, img; + + for ( i = 0; i < num_frequency_bands; ++i ) { - float lfeGain; - float transportGain; - float protoLfeReal, protoLfeImag; - int16_t i; - float transportEne, protoLfeEne, targetEneLfe, targetEneTrans; + real = Cldfb_RealBuffer[0][0][i]; + img = Cldfb_ImagBuffer[0][0][i]; + intensity_real_x[i] = Cldfb_RealBuffer[3][0][i] * real + Cldfb_ImagBuffer[3][0][i] * img; + intensity_real_y[i] = Cldfb_RealBuffer[1][0][i] * real + Cldfb_ImagBuffer[1][0][i] * img; + intensity_real_z[i] = Cldfb_RealBuffer[2][0][i] * real + Cldfb_ImagBuffer[2][0][i] * img; + } - set_zero( RealBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); - set_zero( ImagBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); + return; +} - protoLfeReal = RealBuffer[0][0][0]; - protoLfeImag = ImagBuffer[0][0][0]; - transportEne = RealBuffer[0][0][0] * RealBuffer[0][0][0] + ImagBuffer[0][0][0] * ImagBuffer[0][0][0]; - for ( i = 1; i < nchan_transport; i++ ) - { - protoLfeReal += RealBuffer[i][0][0]; - protoLfeImag += ImagBuffer[i][0][0]; - transportEne += RealBuffer[i][0][0] * RealBuffer[i][0][0] + ImagBuffer[i][0][0] * ImagBuffer[i][0][0]; - } - protoLfeEne = protoLfeReal * protoLfeReal + protoLfeImag * protoLfeImag; - targetEneLfe = transportEne * hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index]; - targetEneTrans = transportEne * max( ( 1.0f - hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index] ), 0.01f ); +/*------------------------------------------------------------------------- + * ivas_lfe_synth_with_cldfb() + * + * + *------------------------------------------------------------------------*/ - hMasaLfeSynth->transportEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->protoLfeEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->targetEneLfeSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->targetEneTransSmooth *= MCMASA_LFE_SYNTH_ALPHA; +void ivas_lfe_synth_with_cldfb( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float RealBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const int16_t slot_index, + const int16_t subframe_index, + const int16_t nchan_transport ) +{ + float lfeGain; + float transportGain; + float protoLfeReal, protoLfeImag; + int16_t i; + float transportEne, protoLfeEne, targetEneLfe, targetEneTrans; - hMasaLfeSynth->transportEneSmooth += transportEne; - hMasaLfeSynth->protoLfeEneSmooth += protoLfeEne; - hMasaLfeSynth->targetEneLfeSmooth += targetEneLfe; - hMasaLfeSynth->targetEneTransSmooth += targetEneTrans; + set_zero( RealBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); + set_zero( ImagBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); - lfeGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneLfeSmooth / ( EPSILON + hMasaLfeSynth->protoLfeEneSmooth ) ) ); - transportGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneTransSmooth / ( EPSILON + hMasaLfeSynth->transportEneSmooth ) ) ); + protoLfeReal = RealBuffer[0][0][0]; + protoLfeImag = ImagBuffer[0][0][0]; + transportEne = RealBuffer[0][0][0] * RealBuffer[0][0][0] + ImagBuffer[0][0][0] * ImagBuffer[0][0][0]; + for ( i = 1; i < nchan_transport; i++ ) + { + protoLfeReal += RealBuffer[i][0][0]; + protoLfeImag += ImagBuffer[i][0][0]; + transportEne += RealBuffer[i][0][0] * RealBuffer[i][0][0] + ImagBuffer[i][0][0] * ImagBuffer[i][0][0]; + } + protoLfeEne = protoLfeReal * protoLfeReal + protoLfeImag * protoLfeImag; - RealBufferLfe[slot_index][0] = protoLfeReal * lfeGain; - ImagBufferLfe[slot_index][0] = protoLfeImag * lfeGain; + targetEneLfe = transportEne * hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index]; + targetEneTrans = transportEne * max( ( 1.0f - hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index] ), 0.01f ); - RealBuffer[0][0][0] *= transportGain; - ImagBuffer[0][0][0] *= transportGain; - for ( i = 1; i < nchan_transport; i++ ) - { - RealBuffer[i][0][0] *= transportGain; - ImagBuffer[i][0][0] *= transportGain; - } + hMasaLfeSynth->transportEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->protoLfeEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->targetEneLfeSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->targetEneTransSmooth *= MCMASA_LFE_SYNTH_ALPHA; - return; - } + hMasaLfeSynth->transportEneSmooth += transportEne; + hMasaLfeSynth->protoLfeEneSmooth += protoLfeEne; + hMasaLfeSynth->targetEneLfeSmooth += targetEneLfe; + hMasaLfeSynth->targetEneTransSmooth += targetEneTrans; + lfeGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneLfeSmooth / ( EPSILON + hMasaLfeSynth->protoLfeEneSmooth ) ) ); + transportGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneTransSmooth / ( EPSILON + hMasaLfeSynth->transportEneSmooth ) ) ); - /*------------------------------------------------------------------------- - * rotateAziEle_DirAC() - * - * Apply rotation to DirAC DOAs - *------------------------------------------------------------------------*/ + RealBufferLfe[slot_index][0] = protoLfeReal * lfeGain; + ImagBufferLfe[slot_index][0] = protoLfeImag * lfeGain; - void rotateAziEle_DirAC( - int16_t * azi, /* i/o: array of azimuth values */ - int16_t * ele, /* i/o: array of elevation values */ - const int16_t band1, /* i : bands to work on (lower limit) */ - const int16_t band2, /* i : bands to work on (upper bound) */ - const float *p_Rmat /* i : pointer to real-space rotation matrix */ - ) + RealBuffer[0][0][0] *= transportGain; + ImagBuffer[0][0][0] *= transportGain; + for ( i = 1; i < nchan_transport; i++ ) { - int16_t b; - float dv_0, dv_1, dv_2; - float dv_r_0, dv_r_1, dv_r_2; - float w; + RealBuffer[i][0][0] *= transportGain; + ImagBuffer[i][0][0] *= transportGain; + } + + return; +} - push_wmops( "rotateAziEle_DirAC" ); - for ( b = band1; b < band2; b++ ) - { +/*------------------------------------------------------------------------- + * rotateAziEle_DirAC() + * + * Apply rotation to DirAC DOAs + *------------------------------------------------------------------------*/ + +void rotateAziEle_DirAC( + int16_t *azi, /* i/o: array of azimuth values */ + int16_t *ele, /* i/o: array of elevation values */ + const int16_t band1, /* i : bands to work on (lower limit) */ + const int16_t band2, /* i : bands to work on (upper bound) */ + const float *p_Rmat /* i : pointer to real-space rotation matrix */ +) +{ + int16_t b; + float dv_0, dv_1, dv_2; + float dv_r_0, dv_r_1, dv_r_2; + float w; - /*Conversion spherical to cartesian coordinates*/ - w = cosf( ele[b] * PI_OVER_180 ); - dv_0 = w * cosf( azi[b] * PI_OVER_180 ); - dv_1 = w * sinf( azi[b] * PI_OVER_180 ); - dv_2 = sinf( ele[b] * PI_OVER_180 ); + push_wmops( "rotateAziEle_DirAC" ); - dv_r_0 = p_Rmat[0] * dv_0 + p_Rmat[1] * dv_1 + p_Rmat[2] * dv_2; - dv_r_1 = p_Rmat[3] * dv_0 + p_Rmat[4] * dv_1 + p_Rmat[5] * dv_2; - dv_r_2 = p_Rmat[6] * dv_0 + p_Rmat[7] * dv_1 + p_Rmat[8] * dv_2; + for ( b = band1; b < band2; b++ ) + { - /*Conversion spherical to cartesian coordinates*/ - azi[b] = (int16_t) ( atan2f( dv_r_1, dv_r_0 ) * _180_OVER_PI ); - ele[b] = (int16_t) ( atan2f( dv_r_2, sqrtf( dv_r_0 * dv_r_0 + dv_r_1 * dv_r_1 ) ) * _180_OVER_PI ); - } + /*Conversion spherical to cartesian coordinates*/ + w = cosf( ele[b] * PI_OVER_180 ); + dv_0 = w * cosf( azi[b] * PI_OVER_180 ); + dv_1 = w * sinf( azi[b] * PI_OVER_180 ); + dv_2 = sinf( ele[b] * PI_OVER_180 ); - pop_wmops(); + dv_r_0 = p_Rmat[0] * dv_0 + p_Rmat[1] * dv_1 + p_Rmat[2] * dv_2; + dv_r_1 = p_Rmat[3] * dv_0 + p_Rmat[4] * dv_1 + p_Rmat[5] * dv_2; + dv_r_2 = p_Rmat[6] * dv_0 + p_Rmat[7] * dv_1 + p_Rmat[8] * dv_2; - return; + /*Conversion spherical to cartesian coordinates*/ + azi[b] = (int16_t) ( atan2f( dv_r_1, dv_r_0 ) * _180_OVER_PI ); + ele[b] = (int16_t) ( atan2f( dv_r_2, sqrtf( dv_r_0 * dv_r_0 + dv_r_1 * dv_r_1 ) ) * _180_OVER_PI ); } + pop_wmops(); - /*------------------------------------------------------------------------- - * ivas_masa_ext_dirac_render_sf() - * - * A reduced rewrite of the corresponding decoder side function - *------------------------------------------------------------------------*/ + return; +} - static void ivas_masa_ext_dirac_render_sf( - MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */ - float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ - ) - { - int16_t i, ch, idx_in, idx_lfe; - DIRAC_REND_HANDLE hDirACRend; - float dirEne; - float surCohEner; - float surCohRatio[CLDFB_NO_CHANNELS_MAX]; - int16_t subframe_idx; - int16_t slot_idx, index_slot; - int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx; - int16_t nchan_transport; - int16_t masa_band_mapping[MASA_FREQUENCY_BANDS + 1]; - /* CLDFB: last output channels reserved to LFT for CICPx */ - float Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; +/*------------------------------------------------------------------------- + * ivas_masa_ext_dirac_render_sf() + * + * A reduced rewrite of the corresponding decoder side function + *------------------------------------------------------------------------*/ + +static void ivas_masa_ext_dirac_render_sf( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */ + float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ +) +{ + int16_t i, ch, idx_in, idx_lfe; + DIRAC_REND_HANDLE hDirACRend; + float dirEne; + float surCohEner; + float surCohRatio[CLDFB_NO_CHANNELS_MAX]; + int16_t subframe_idx; + int16_t slot_idx, index_slot; + int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx; + int16_t nchan_transport; + int16_t masa_band_mapping[MASA_FREQUENCY_BANDS + 1]; + + /* CLDFB: last output channels reserved to LFT for CICPx */ + float Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + + /* local copies of azi, ele, diffuseness */ + int16_t azimuth[CLDFB_NO_CHANNELS_MAX]; + int16_t elevation[CLDFB_NO_CHANNELS_MAX]; + float diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; + + DIRAC_DEC_STACK_MEM DirAC_mem; + float *reference_power, *reference_power_smooth; + float *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; + uint16_t coherence_flag; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - /* local copies of azi, ele, diffuseness */ - int16_t azimuth[CLDFB_NO_CHANNELS_MAX]; - int16_t elevation[CLDFB_NO_CHANNELS_MAX]; - float diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; + push_wmops( "ivas_masa_ext_dirac_render_sf" ); - DIRAC_DEC_STACK_MEM DirAC_mem; - float *reference_power, *reference_power_smooth; - float *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; - uint16_t coherence_flag; - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + /* Initialize aux buffers */ + hDirACRend = hMasaExtRend->hDirACRend; + hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; + nchan_transport = hMasaExtRend->nchan_input; - push_wmops( "ivas_masa_ext_dirac_render_sf" ); + DirAC_mem = hDirACRend->stack_mem; - /* Initialize aux buffers */ - hDirACRend = hMasaExtRend->hDirACRend; - hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - nchan_transport = hMasaExtRend->nchan_input; + reference_power = DirAC_mem.reference_power; + reference_power_smooth = ( DirAC_mem.reference_power == NULL ) ? NULL : DirAC_mem.reference_power + hSpatParamRendCom->num_freq_bands; + onset_filter = DirAC_mem.onset_filter; + onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands; + coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ - DirAC_mem = hDirACRend->stack_mem; + /* Construct default MASA band mapping */ + for ( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ ) + { + masa_band_mapping[i] = i; + } - reference_power = DirAC_mem.reference_power; - reference_power_smooth = ( DirAC_mem.reference_power == NULL ) ? NULL : DirAC_mem.reference_power + hSpatParamRendCom->num_freq_bands; - onset_filter = DirAC_mem.onset_filter; - onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands; - coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ + /* Subframe loop */ + slot_idx_start = hSpatParamRendCom->slots_rendered; + slot_idx_start_cldfb_synth = 0; - /* Construct default MASA band mapping */ - for ( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ ) - { - masa_band_mapping[i] = i; - } + subframe_idx = hSpatParamRendCom->subframes_rendered; + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; - /* Subframe loop */ - slot_idx_start = hSpatParamRendCom->slots_rendered; - slot_idx_start_cldfb_synth = 0; + /* copy parameters into local buffers*/ + mvs2s( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); + mvs2s( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); + mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); - subframe_idx = hSpatParamRendCom->subframes_rendered; - md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + set_zero( reference_power_smooth, hSpatParamRendCom->num_freq_bands ); + } + else + { + set_zero( onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); + } - /* copy parameters into local buffers*/ - mvs2s( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); - mvs2s( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); - mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + /* compute response */ + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_compute_power_factors( hSpatParamRendCom->num_freq_bands, + diffuseness_vector, + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + if ( coherence_flag ) { - set_zero( reference_power_smooth, hSpatParamRendCom->num_freq_bands ); + for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + dirEne = hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i]; + surCohEner = hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] * hSpatParamRendCom->surroundingCoherence[md_idx][i]; + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] -= surCohEner; + hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] += surCohEner; + + surCohRatio[i] = surCohEner / ( 1e-12f + dirEne + surCohEner ); + } } else { - set_zero( onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); + set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); } + } + else + { + ivas_dirac_dec_compute_gain_factors( hSpatParamRendCom->num_freq_bands, + hSpatParamRendCom->diffuseness_vector[md_idx], + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); - /* compute response */ - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + if ( coherence_flag ) { - ivas_dirac_dec_compute_power_factors( hSpatParamRendCom->num_freq_bands, - diffuseness_vector, - hDirACRend->h_output_synthesis_psd_params.max_band_decorr, - hDirACRend->h_output_synthesis_psd_state.direct_power_factor, - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); - - if ( coherence_flag ) - { - for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - dirEne = hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i]; - surCohEner = hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] * hSpatParamRendCom->surroundingCoherence[md_idx][i]; - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] -= surCohEner; - hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] += surCohEner; - - surCohRatio[i] = surCohEner / ( 1e-12f + dirEne + surCohEner ); - } - } - else + for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); + surCohRatio[i] = hSpatParamRendCom->surroundingCoherence[md_idx][i]; } } else { - ivas_dirac_dec_compute_gain_factors( hSpatParamRendCom->num_freq_bands, - hSpatParamRendCom->diffuseness_vector[md_idx], - hDirACRend->h_output_synthesis_psd_params.max_band_decorr, - hDirACRend->h_output_synthesis_psd_state.direct_power_factor, - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); - - if ( coherence_flag ) - { - for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - surCohRatio[i] = hSpatParamRendCom->surroundingCoherence[md_idx][i]; - } - } - else - { - set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); - } + set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); } + } - ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, - hDirACRend, - hMasaExtRend->hVBAPdata, - masa_band_mapping, - NULL, - azimuth, - elevation, - md_idx, - surCohRatio, - 0 ); + ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, + hDirACRend, + hMasaExtRend->hVBAPdata, + masa_band_mapping, + NULL, + azimuth, + elevation, + md_idx, + surCohRatio, + 0 ); - for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + index_slot = slot_idx_start + slot_idx; + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + + /* CLDFB Analysis*/ + for ( ch = 0; ch < nchan_transport; ch++ ) { - index_slot = slot_idx_start + slot_idx; - md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + cldfbAnalysis_ts( &( output_f[ch][hSpatParamRendCom->num_freq_bands * index_slot] ), + Cldfb_RealBuffer[ch][0], + Cldfb_ImagBuffer[ch][0], + hSpatParamRendCom->num_freq_bands, + hMasaExtRend->cldfbAnaRend[ch] ); + } - /* CLDFB Analysis*/ - for ( ch = 0; ch < nchan_transport; ch++ ) - { - cldfbAnalysis_ts( &( output_f[ch][hSpatParamRendCom->num_freq_bands * index_slot] ), - Cldfb_RealBuffer[ch][0], - Cldfb_ImagBuffer[ch][0], - hSpatParamRendCom->num_freq_bands, - hMasaExtRend->cldfbAnaRend[ch] ); - } + if ( nchan_transport == 1 ) + { + /* Need to set second CLDFB channel to zero as further processing assumes CNA content in it */ + set_zero( Cldfb_RealBuffer[1][0], hSpatParamRendCom->num_freq_bands ); + set_zero( Cldfb_ImagBuffer[1][0], hSpatParamRendCom->num_freq_bands ); + } + + /*-----------------------------------------------------------------* + * prototype signal computation + *-----------------------------------------------------------------*/ - if ( nchan_transport == 1 ) - { - /* Need to set second CLDFB channel to zero as further processing assumes CNA content in it */ - set_zero( Cldfb_RealBuffer[1][0], hSpatParamRendCom->num_freq_bands ); - set_zero( Cldfb_ImagBuffer[1][0], hSpatParamRendCom->num_freq_bands ); + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, + reference_power, slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + 0 ); + } + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + { + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect ); + } + else + { + switch ( nchan_transport ) + { + case 2: + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + hDirACRend->hOutSetup.is_loudspeaker_setup, + slot_idx, + hSpatParamRendCom->num_freq_bands, + hDirACRend->masa_stereo_type_detect ); + break; + case 1: + protoSignalComputation1( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + slot_idx, + hDirACRend->num_protos_diff, + hSpatParamRendCom->num_freq_bands ); + break; + default: + return; } + } - /*-----------------------------------------------------------------* - * prototype signal computation - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * frequency domain decorrelation + *-----------------------------------------------------------------*/ + if ( hDirACRend->proto_signal_decorr_on == 1 ) + { + /* decorrelate prototype frame */ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, - reference_power, slot_idx, nchan_transport, - hDirACRend->num_outputs_diff, - hSpatParamRendCom->num_freq_bands, - 0 ); - } - else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) - { - protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirACRend->proto_frame_f, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, - 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect ); + ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + nchan_transport, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->proto_index_diff, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport ), + onset_filter, + hDirACRend->h_freq_domain_decorr_ap_params, + hDirACRend->h_freq_domain_decorr_ap_state ); + + v_multc( onset_filter, 0.25f, onset_filter, hSpatParamRendCom->num_freq_bands ); + v_add( onset_filter, onset_filter_subframe, onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); + p_onset_filter = onset_filter_subframe; } else { - switch ( nchan_transport ) - { - case 2: - protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirACRend->proto_frame_f, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, - hDirACRend->hOutSetup.is_loudspeaker_setup, - slot_idx, - hSpatParamRendCom->num_freq_bands, - hDirACRend->masa_stereo_type_detect ); - break; - case 1: - protoSignalComputation1( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirACRend->proto_frame_f, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, - slot_idx, - hDirACRend->num_protos_diff, - hSpatParamRendCom->num_freq_bands ); - break; - default: - return; - } - } + ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + nchan_transport, + hDirACRend->proto_frame_f, + hDirACRend->num_protos_diff, + hDirACRend->proto_index_diff, + DirAC_mem.frame_dec_f, + onset_filter, + hDirACRend->h_freq_domain_decorr_ap_params, + hDirACRend->h_freq_domain_decorr_ap_state ); - /*-----------------------------------------------------------------* - * frequency domain decorrelation - *-----------------------------------------------------------------*/ - - if ( hDirACRend->proto_signal_decorr_on == 1 ) - { - /* decorrelate prototype frame */ - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, - hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, - hDirACRend->synthesisConf, - nchan_transport, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, - hDirACRend->proto_index_diff, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport ), - onset_filter, - hDirACRend->h_freq_domain_decorr_ap_params, - hDirACRend->h_freq_domain_decorr_ap_state ); - - v_multc( onset_filter, 0.25f, onset_filter, hSpatParamRendCom->num_freq_bands ); - v_add( onset_filter, onset_filter_subframe, onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); - p_onset_filter = onset_filter_subframe; - } - else - { - ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, - hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, - hDirACRend->synthesisConf, - nchan_transport, - hDirACRend->proto_frame_f, - hDirACRend->num_protos_diff, - hDirACRend->proto_index_diff, - DirAC_mem.frame_dec_f, - onset_filter, - hDirACRend->h_freq_domain_decorr_ap_params, - hDirACRend->h_freq_domain_decorr_ap_state ); - - hDirACRend->proto_frame_dec_f = DirAC_mem.frame_dec_f; - p_onset_filter = onset_filter; - } - } - else - { - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - set_f( onset_filter_subframe, 1.f, hSpatParamRendCom->num_freq_bands ); - p_onset_filter = onset_filter_subframe; - } - else - { - /* no frequency domain decorrelation: use prototype frame */ - hDirACRend->proto_frame_dec_f = hDirACRend->proto_frame_f; - p_onset_filter = NULL; - } + hDirACRend->proto_frame_dec_f = DirAC_mem.frame_dec_f; + p_onset_filter = onset_filter; } - - /*-----------------------------------------------------------------* - * output synthesis - *-----------------------------------------------------------------*/ - - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + } + else + { + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - /* Compute diffuse prototypes */ - ivas_dirac_dec_compute_diffuse_proto( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); + set_f( onset_filter_subframe, 1.f, hSpatParamRendCom->num_freq_bands ); + p_onset_filter = onset_filter_subframe; } - - ivas_dirac_dec_output_synthesis_process_slot( reference_power, - p_onset_filter, - azimuth, - elevation, - hSpatParamRendCom->diffuseness_vector[md_idx], - hSpatParamRendCom, - hDirACRend, - hMasaExtRend->hVBAPdata, - hDirACRend->hOutSetup, - nchan_transport, - md_idx, - 0, - 0 ); - - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + else { - v_add( reference_power, reference_power_smooth, reference_power_smooth, hSpatParamRendCom->num_freq_bands ); + /* no frequency domain decorrelation: use prototype frame */ + hDirACRend->proto_frame_dec_f = hDirACRend->proto_frame_f; + p_onset_filter = NULL; } } - ivas_dirac_dec_output_synthesis_get_interpolator( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + /*-----------------------------------------------------------------* + * output synthesis + *-----------------------------------------------------------------*/ - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { - ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hSpatParamRendCom, - hDirACRend, - nchan_transport, - hSpatParamRendCom->subframe_nbslots[subframe_idx], - p_onset_filter, - diffuseness_vector, - 0, - 0 ); + /* Compute diffuse prototypes */ + ivas_dirac_dec_compute_diffuse_proto( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); } - else + + ivas_dirac_dec_output_synthesis_process_slot( reference_power, + p_onset_filter, + azimuth, + elevation, + hSpatParamRendCom->diffuseness_vector[md_idx], + hSpatParamRendCom, + hDirACRend, + hMasaExtRend->hVBAPdata, + hDirACRend->hOutSetup, + nchan_transport, + md_idx, + 0, + 0 ); + + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hSpatParamRendCom, - hDirACRend, - hSpatParamRendCom->subframe_nbslots[subframe_idx], - diffuseness_vector, - reference_power_smooth, - 1.0f, - 0 ); + v_add( reference_power, reference_power_smooth, reference_power_smooth, hSpatParamRendCom->num_freq_bands ); } + } - /*-----------------------------------------------------------------* - * CLDFB synthesis (and binaural rendering) - *-----------------------------------------------------------------*/ + ivas_dirac_dec_output_synthesis_get_interpolator( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); - index_slot = slot_idx_start_cldfb_synth; + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( Cldfb_RealBuffer, + Cldfb_ImagBuffer, + hSpatParamRendCom, + hDirACRend, + nchan_transport, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + p_onset_filter, + diffuseness_vector, + 0, + 0 ); + } + else + { + ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( Cldfb_RealBuffer, + Cldfb_ImagBuffer, + hSpatParamRendCom, + hDirACRend, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + diffuseness_vector, + reference_power_smooth, + 1.0f, + 0 ); + } - { - float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t outchannels; + /*-----------------------------------------------------------------* + * CLDFB synthesis (and binaural rendering) + *-----------------------------------------------------------------*/ + + index_slot = slot_idx_start_cldfb_synth; + + { + float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t outchannels; - idx_in = 0; - idx_lfe = 0; + idx_in = 0; + idx_lfe = 0; - outchannels = hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; + outchannels = hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; - /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */ + /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */ - for ( ch = 0; ch < outchannels; ch++ ) + for ( ch = 0; ch < outchannels; ch++ ) + { + if ( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( hDirACRend->hOutSetup.index_lfe[idx_lfe] == ch ) ) { - if ( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( hDirACRend->hOutSetup.index_lfe[idx_lfe] == ch ) ) - { - /* No LFE for MASA rendering */ - set_zero( &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + /* No LFE for MASA rendering */ + set_zero( &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); - if ( idx_lfe < ( hDirACRend->hOutSetup.num_lfe - 1 ) ) - { - idx_lfe++; - } + if ( idx_lfe < ( hDirACRend->hOutSetup.num_lfe - 1 ) ) + { + idx_lfe++; } - else + } + else + { + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) - { - RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; - ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; - } - cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], hMasaExtRend->cldfbSynRend[idx_in] ); - idx_in++; + RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; + ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; } + cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], hMasaExtRend->cldfbSynRend[idx_in] ); + idx_in++; } } - hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx]; - hSpatParamRendCom->subframes_rendered++; + } + hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx]; + hSpatParamRendCom->subframes_rendered++; - pop_wmops(); + pop_wmops(); - return; - } + return; +} - /*------------------------------------------------------------------------- - * ivas_masa_ext_dirac_render() - * - * MASA external renderer - *------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * ivas_masa_ext_dirac_render() + * + * MASA external renderer + *------------------------------------------------------------------------*/ - void ivas_masa_ext_dirac_render( - MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ - float *output_f[], /* i/o: input/output signals in time domain */ - const int16_t num_subframes /* i : number of subframes to render */ - ) - { - int16_t subframe_idx; - float *output_f_local[MAX_OUTPUT_CHANNELS]; - int16_t n, n_samples_sf; - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; +void ivas_masa_ext_dirac_render( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ + float *output_f[], /* i/o: input/output signals in time domain */ + const int16_t num_subframes /* i : number of subframes to render */ +) +{ + int16_t subframe_idx; + float *output_f_local[MAX_OUTPUT_CHANNELS]; + int16_t n, n_samples_sf; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; + hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - n_samples_sf = JBM_CLDFB_SLOTS_IN_SUBFRAME * hSpatParamRendCom->slot_size; + n_samples_sf = JBM_CLDFB_SLOTS_IN_SUBFRAME * hSpatParamRendCom->slot_size; - for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) - { - output_f_local[n] = output_f[n]; - } + for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) + { + output_f_local[n] = output_f[n]; + } - hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; + hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; - for ( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) + for ( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) + { + hSpatParamRendCom->slots_rendered = 0; + ivas_masa_ext_dirac_render_sf( hMasaExtRend, output_f_local ); + for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) { - hSpatParamRendCom->slots_rendered = 0; - ivas_masa_ext_dirac_render_sf( hMasaExtRend, output_f_local ); - for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) - { - output_f_local[n] += n_samples_sf; - } - - hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + output_f_local[n] += n_samples_sf; } - return; + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } + + return; +} -- GitLab