diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj
index 645828db60765df626ab3d11925c76aaa9b345ae..2851fd82e92daf535338b92b45ea87c42f9e3603 100644
--- a/Workspace_msvc/lib_dec.vcxproj
+++ b/Workspace_msvc/lib_dec.vcxproj
@@ -271,10 +271,7 @@
-
-
-
diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters
index 6284884920f332ea486df52e269e1eb51e5ef8f3..a7eb87f148c3b90ba5ca4e4fdefe4f1f60417709 100644
--- a/Workspace_msvc/lib_dec.vcxproj.filters
+++ b/Workspace_msvc/lib_dec.vcxproj.filters
@@ -16,15 +16,6 @@
dec_ivas_c
-
- dec_ivas_c
-
-
- dec_ivas_c
-
-
- dec_ivas_c
-
dec_ivas_c
diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj
index 6e3943249f2e64991a5cd27b6e6a09aa25ad2f33..3e5f8bee133b3600bbe891fbc67950d48db39c33 100644
--- a/Workspace_msvc/lib_rend.vcxproj
+++ b/Workspace_msvc/lib_rend.vcxproj
@@ -222,6 +222,10 @@
+
+
+
+
diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h
index 9867cda5d9db7203431a12ba170372826e21426b..3b6c1558bef78826779ea1d574e6a54fac50acd1 100644
--- a/lib_com/ivas_prot.h
+++ b/lib_com/ivas_prot.h
@@ -1045,6 +1045,7 @@ ivas_error ivas_param_ism_dec_open(
void ivas_param_ism_dec_close(
DIRAC_DEC_HANDLE *hDirAC, /* i/o: decoder DirAC handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */
const AUDIO_CONFIG output_config /* i : output audio configuration */
);
@@ -3170,8 +3171,9 @@ int16_t ivas_qmetadata_dec_sid_decode(
void ivas_qmetadata_to_dirac(
const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */
- DIRAC_DEC_HANDLE hDirAC, /* o : DirAC decoder structure */
+ DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */
MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
const int32_t ivas_total_brate, /* i : IVAS total bitrate */
const IVAS_FORMAT ivas_format, /* i : IVAS format */
const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
@@ -3573,33 +3575,20 @@ ivas_error ivas_dirac_sba_config(
const int16_t nbands /* i : number of frequency bands */
);
-ivas_error ivas_dirac_dec_open(
- Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
-);
-
-ivas_error ivas_dirac_allocate_parameters(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
- const int16_t params_flag /* i : set of parameters flag */
-);
-
ivas_error ivas_dirac_dec_config(
Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
const DIRAC_CONFIG_FLAG flag_configopen /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
);
void ivas_dirac_dec_close(
- DIRAC_DEC_HANDLE *hDirAC /* i/o: decoder DirAC handle */
-);
-
-void ivas_dirac_deallocate_parameters(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
- const int16_t params_flag /* i : set of parameters flag */
+ DIRAC_DEC_HANDLE *hDirAC_out
);
void ivas_dirac_dec_read_BS(
const int32_t ivas_total_brate, /* i : IVAS total bitrate */
Decoder_State *st, /* i/o: decoder Core state structure */
DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */
IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q metadata */
int16_t *nb_bits, /* o : number of bits read */
const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
@@ -3650,12 +3639,6 @@ ivas_error ivas_td_decorr_reconfig_dec(
uint16_t *useTdDecorr /* i/o: TD decorrelator flag */
);
-/*! r: Configured reqularization factor value */
-float configure_reqularization_factor(
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- const int32_t ivas_total_brate /* i : total IVAS bitrate */
-);
-
void computeDiffuseness_mdft(
float **buffer_intensity[DIRAC_NUM_DIMS],
const float *buffer_energy,
@@ -3682,109 +3665,6 @@ void computeDiffuseness(
float *diffuseness
);
-ivas_error ivas_dirac_dec_onset_detection_open(
- const int16_t num_channels,
- const int16_t num_freq_bands,
- const int16_t max_band_decorr,
- DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params,
- DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state
-);
-
-void ivas_dirac_dec_onset_detection_process(
- const float *input_power_f,
- float *onset_filter,
- const int16_t num_protos_diff,
- DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params,
- DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state
-);
-
-ivas_error ivas_dirac_dec_decorr_open(
- DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params,
- DIRAC_DECORR_STATE **ph_freq_domain_decorr_ap_state,
- const int16_t num_freq_bands,
- int16_t num_outputs_diff,
- const int16_t num_protos_diff,
- const DIRAC_SYNTHESIS_CONFIG synthesisConf,
- float *frequency_axis,
- const int16_t nchan_transport, /* i : number of transport channels */
- const int32_t output_Fs /* i : output sampling rate */
-);
-
-void ivas_dirac_dec_decorr_process(
- const int16_t num_freq_bands,
- int16_t num_channels,
- const int16_t num_protos_diff,
- const DIRAC_SYNTHESIS_CONFIG synthesisConf,
- const int16_t nchan_transport, /* i : number of transport channels */
- const float *input_frame_f,
- const int16_t num_protos_dir,
- const int16_t *proto_index_dir,
- float *frame_dec_f,
- float *onset_filter,
- HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params,
- HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state
-);
-
-void ivas_dirac_dec_decorr_close(
- HANDLE_DIRAC_DECORR_PARAMS *ph_dirac_decorr_params,
- HANDLE_DIRAC_DECORR_STATE *ph_dirac_decorr_state
-);
-
-ivas_error ivas_dirac_dec_output_synthesis_open(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const RENDERER_TYPE renderer_type, /* i : renderer type */
- const int16_t nchan_transport, /* i : number of transport channels */
- const int32_t output_Fs /* i : output sampling rate */
- ,
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
-);
-
-void ivas_dirac_dec_output_synthesis_init(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const int16_t nchan_out_woLFE, /* i : number of output audio channels without LFE */
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
-);
-
-void ivas_dirac_dec_output_synthesis_close(
- DIRAC_DEC_HANDLE hDirAC /* i/o: DirAC handle */
-);
-
-void ivas_dirac_dec_output_synthesis_process_slot(
- const float *reference_power, /* i : Estimated power */
- const float *onset, /* i : onset filter */
- const int16_t *azimuth,
- const int16_t *elevation,
- const float *diffuseness,
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const int16_t sh_rot_max_order,
- const float *p_Rmat, /* i : rotation matrix */
- const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */
- const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */
- const int16_t nchan_transport, /* i : number of transport channels */
- const int16_t ind_slot, /* i : index of the slot to be added to the input covariance */
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
-);
-
-void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
- float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */
- float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const int16_t nchan_transport, /* i : number of transport channels */
- const int16_t nbslots, /* i : number of slots to process */
- const float *onset_filter,
- float *diffuseness,
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
-);
-
-void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls(
- float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */
- float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const int16_t nbslots, /* i : number of slots to process */
- float *diffuseness_vector, /* i : diffuseness (needed for direction smoothing)*/
- float *reference_power_smooth,
- float qualityBasedSmFactor
-);
void ivas_dirac_dec_get_response(
const int16_t azimuth,
@@ -3793,50 +3673,8 @@ void ivas_dirac_dec_get_response(
const int16_t ambisonics_order
);
-void compute_hoa_encoder_mtx(
- const float *azimuth,
- const float *elevation,
- float *response,
- const int16_t num_responses,
- const int16_t ambisonics_order );
-
-void ivas_dirac_dec_compute_gain_factors(
- const int16_t num_freq_bands,
- const float *diffuseness,
- const int16_t max_band_decorr,
- float *direct_gain_factor,
- float *diffuse_gain_factor
-);
-
-void ivas_dirac_dec_compute_power_factors(
- const int16_t num_freq_bands,
- const float *diffuseness,
- const int16_t max_band_decorr,
- float *direct_power_factor,
- float *diffuse_power_factor
-);
-
-void ivas_dirac_dec_compute_directional_responses(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */
- const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
- const int16_t *azimuth,
- const int16_t *elevation,
- const int16_t md_idx,
- const float *surCohRatio,
- const int16_t shd_rot_max_order, /* i : split-order rotation method */
- const float *p_Rmat, /* i : rotation matrix */
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
-);
-
-void ivas_dirac_dec_get_frequency_axis(
- float *frequency_axis, /* o : array of center frequencies of a real filter bank */
- const int32_t output_Fs, /* i : sampling frequency */
- const int16_t num_freq_bands /* i : number of frequency bands */
-);
-
void calculate_hodirac_sector_parameters(
- DIRAC_ENC_HANDLE hDirAC,
+ DIRAC_ENC_HANDLE hDirAC,
float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */
float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector, imaginary part */
const float beta, /* i : forgetting factor for average filtering */
@@ -4907,14 +4745,14 @@ void ivas_spar_arith_coeffs_com_init(
int16_t ivas_arith_encode_cmplx_cell_array(
- ivas_arith_t *pArith_re,
- ivas_arith_t *pArith_re_diff,
- const int16_t *pDo_diff,
- const int16_t nB,
- int16_t *pSymbol_re,
- int16_t *pSymbol_old_re,
- ivas_cell_dim_t *pCell_dims,
- BSTR_ENC_HANDLE hMetaData,
+ ivas_arith_t *pArith_re,
+ ivas_arith_t *pArith_re_diff,
+ const int16_t *pDo_diff,
+ const int16_t nB,
+ int16_t *pSymbol_re,
+ int16_t *pSymbol_old_re,
+ ivas_cell_dim_t *pCell_dims,
+ BSTR_ENC_HANDLE hMetaData,
const int16_t any_diff ,
const int16_t wc_strat_arith
);
diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c
index 85334346ad580e59d22fb24d065876f80c113088..5ca878a00ec58382864b493b2665782dbb4f20a9 100644
--- a/lib_dec/ivas_dec.c
+++ b/lib_dec/ivas_dec.c
@@ -445,7 +445,7 @@ ivas_error ivas_dec(
{
#ifdef FIX_564
/* loudness correction */
- ivas_dirac_dec_binaural_gain( output, nchan_remapped, output_frame );
+ ivas_dirac_dec_binaural_sba_gain( output, nchan_remapped, output_frame );
#else
float gain;
diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c
index 257d1074add8c8b5873d78198f485d2277b6fb46..766f4ff08fe05ea389e53845c393a6b5fda5f734 100644
--- a/lib_dec/ivas_dirac_dec.c
+++ b/lib_dec/ivas_dirac_dec.c
@@ -51,206 +51,69 @@
* Local function prototypes
*-----------------------------------------------------------------------*/
-static ivas_error ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, const RENDERER_TYPE renderer_type, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, const int16_t hodirac_flag );
-
-static void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem );
-
-static void initDiffuseResponses( float *diffuse_response_function, const int16_t num_channels, AUDIO_CONFIG output_config, IVAS_OUTPUT_SETUP hOutSetup, const int16_t ambisonics_order, const IVAS_FORMAT ivas_format, int16_t *num_ele_spk_no_diffuse_rendering, AUDIO_CONFIG transport_config );
-
-static 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 );
-
-static void protoSignalComputation_shd( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float *proto_direct_buffer_f, float *proto_diffuse_buffer_f, float *reference_power, const int16_t slot_index, const int16_t num_inputs, const int16_t num_outputs_diff, const int16_t num_freq_bands, float *p_Rmat );
-
-static void protoSignalComputation1( 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 );
-
-static void protoSignalComputation2( 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 isloudspeaker, const int16_t slot_index, const int16_t num_freq_bands, MASA_STEREO_TYPE_DETECT *stereo_type_detect );
-
-static 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 );
-
-static void ivas_dirac_dec_compute_diffuse_proto( DIRAC_DEC_HANDLE hDirAC, const int16_t slot_idx );
-
-static 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 );
-
-static void ivas_masa_init_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect );
-
-static void ivas_masa_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect );
-
-static 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 );
-
-static void rotateAziEle_DirAC( int16_t *azi, int16_t *ele, const int16_t band1, const int16_t band2, const float *p_Rmat );
-
-
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec_open()
- *
- * Open decoder DirAC handle
- *-------------------------------------------------------------------------*/
-
-ivas_error ivas_dirac_dec_open(
- Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
+static ivas_error ivas_dirac_dec_config_internal(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
)
{
+ DIRAC_DEC_HANDLE hDirAC;
ivas_error error;
+ DIRAC_CONFIG_FLAG flag_config;
+ flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp;
error = IVAS_ERR_OK;
- if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
- {
- return error;
- }
-
- return error;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_dirac_allocate_parameters()
- *
- * Allocate and initialize DirAC parameters
- *-------------------------------------------------------------------------*/
-
-ivas_error ivas_dirac_allocate_parameters(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
- const int16_t params_flag /* i : set of parameters flag */
-)
-{
- int16_t i;
+ hDirAC = NULL;
- if ( params_flag == 1 )
+ if ( flag_config == DIRAC_RECONFIGURE )
{
- if ( ( hDirAC->azimuth = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
-
- if ( ( hDirAC->elevation = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
-
- if ( ( hDirAC->diffuseness_vector = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
-
- if ( ( hDirAC->energy_ratio1 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
-
- if ( ( hDirAC->spreadCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
-
- if ( ( hDirAC->surroundingCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
-
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
- {
- if ( ( hDirAC->azimuth[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_s( hDirAC->azimuth[i], 0, hDirAC->num_freq_bands );
-
- if ( ( hDirAC->elevation[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_s( hDirAC->elevation[i], 0, hDirAC->num_freq_bands );
-
- if ( ( hDirAC->diffuseness_vector[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_f( hDirAC->diffuseness_vector[i], 1.0f, hDirAC->num_freq_bands );
-
- if ( ( hDirAC->energy_ratio1[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_f( hDirAC->energy_ratio1[i], 0.0f, hDirAC->num_freq_bands );
-
- if ( ( hDirAC->spreadCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_f( hDirAC->spreadCoherence[i], 0.0f, hDirAC->num_freq_bands );
-
- if ( ( hDirAC->surroundingCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands );
- }
+ hDirAC = st_ivas->hDirAC;
}
- else if ( params_flag == 2 )
+ else if ( flag_config == DIRAC_OPEN )
{
- if ( ( hDirAC->azimuth2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
+ /*-----------------------------------------------------------------*
+ * prepare library opening
+ *-----------------------------------------------------------------*/
- if ( ( hDirAC->elevation2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL )
+ if ( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
- if ( ( hDirAC->energy_ratio2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
+ if ( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL )
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) );
}
- if ( ( hDirAC->spreadCoherence2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
+ hDirAC->hParamIsm = NULL;
+ hDirAC->hParamIsmRendering = NULL;
+ st_ivas->hDirAC = hDirAC;
+ }
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
- {
- if ( ( hDirAC->azimuth2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_s( hDirAC->azimuth2[i], 0, hDirAC->num_freq_bands );
- if ( ( hDirAC->elevation2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_s( hDirAC->elevation2[i], 0, hDirAC->num_freq_bands );
+ /*-----------------------------------------------------------------*
+ * DirAC main configuration
+ *-----------------------------------------------------------------*/
- if ( ( hDirAC->energy_ratio2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_f( hDirAC->energy_ratio2[i], 0.0f, hDirAC->num_freq_bands );
+ if ( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
- if ( ( hDirAC->spreadCoherence2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
- }
- set_f( hDirAC->spreadCoherence2[i], 0.0f, hDirAC->num_freq_bands );
- }
+ if ( flag_config == DIRAC_OPEN )
+ {
+ hDirAC->spar_to_dirac_write_idx = st_ivas->ivas_format == SBA_FORMAT ? DELAY_DIRAC_PARAM_DEC_SFR : 0;
+ hDirAC->dithering_seed = DIRAC_DITH_SEED;
+ st_ivas->hDirAC = hDirAC;
}
- return IVAS_ERR_OK;
+ return error;
}
-
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec_config()
- *
- * Open or reconfigure decoder DirAC/MASA handle
- *-------------------------------------------------------------------------*/
-
-ivas_error ivas_dirac_dec_config(
- Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
- const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
-)
+static ivas_error ivas_dirac_rend_config(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
+ const int16_t dec_param_estim_old )
{
DIRAC_DEC_HANDLE hDirAC;
int16_t nchan_out_woLFE;
@@ -262,27 +125,30 @@ ivas_error ivas_dirac_dec_config(
float *proto_frame_f_old;
int16_t proto_signal_decorr_on_old;
uint16_t i, j, k;
- int16_t dec_param_estim_old;
float ls_azimuth[MAX_OUTPUT_CHANNELS];
float ls_elevation[MAX_OUTPUT_CHANNELS];
int32_t output_Fs, ivas_total_brate;
ivas_error error;
int16_t nchan_transport_orig;
int16_t hodirac_flag;
- int16_t map_idx;
DIRAC_CONFIG_FLAG flag_config;
+ DIRAC_REND_HANDLE hDirACRend;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp;
error = IVAS_ERR_OK;
- hDirAC = NULL;
+ hDirACRend = NULL;
output_Fs = st_ivas->hDecoderConfig->output_Fs;
ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order );
+ hDirAC = st_ivas->hDirAC;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+
if ( flag_config == DIRAC_RECONFIGURE )
{
- hDirAC = st_ivas->hDirAC;
+ hDirACRend = st_ivas->hDirACRend;
}
else if ( flag_config == DIRAC_OPEN )
{
@@ -290,29 +156,21 @@ ivas_error ivas_dirac_dec_config(
* prepare library opening
*-----------------------------------------------------------------*/
- if ( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL )
+ if ( ( hDirACRend = (DIRAC_REND_HANDLE) malloc( sizeof( DIRAC_REND_DATA ) ) ) == NULL )
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n" ) );
}
- if ( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) );
- }
nchan_transport_old = 0;
- hDirAC->hParamIsm = NULL;
- hDirAC->hParamIsmRendering = NULL;
- st_ivas->hDirAC = hDirAC;
}
- dec_param_estim_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirAC->hConfig->dec_param_estim : FALSE;
nchan_transport_old = 0;
num_outputs_dir_old = 0;
num_outputs_diff_old = 0;
num_protos_diff_old = 0;
nchan_transport_orig = st_ivas->nchan_transport;
- if ( st_ivas->ivas_format == SBA_FORMAT && !( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
+ if ( st_ivas->ivas_format == SBA_FORMAT )
{
st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
}
@@ -329,58 +187,40 @@ ivas_error ivas_dirac_dec_config(
ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 );
}
- /*-----------------------------------------------------------------*
- * DirAC main configuration
- *-----------------------------------------------------------------*/
-
- if ( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ) != IVAS_ERR_OK )
- {
- return error;
- }
-
/*-----------------------------------------------------------------*
* output setup: for parametric binaural renderer, use output setup, otherwise internal setup
*-----------------------------------------------------------------*/
- if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
- {
- hDirAC->hOutSetup = st_ivas->hOutSetup;
-
- hDirAC->hConfig->dec_param_estim = FALSE;
- }
- else
- {
- hDirAC->hOutSetup = st_ivas->hIntSetup;
- }
- nchan_out_woLFE = hDirAC->hOutSetup.nchan_out_woLFE;
+ hDirACRend->hOutSetup = st_ivas->hIntSetup;
+ nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
- if ( hDirAC->hOutSetup.ls_azimuth != NULL && hDirAC->hOutSetup.ls_elevation != NULL )
+ if ( hDirACRend->hOutSetup.ls_azimuth != NULL && hDirACRend->hOutSetup.ls_elevation != NULL )
{
- mvr2r( hDirAC->hOutSetup.ls_azimuth, ls_azimuth, nchan_out_woLFE );
- mvr2r( hDirAC->hOutSetup.ls_elevation, ls_elevation, nchan_out_woLFE );
+ mvr2r( hDirACRend->hOutSetup.ls_azimuth, ls_azimuth, nchan_out_woLFE );
+ mvr2r( hDirACRend->hOutSetup.ls_elevation, ls_elevation, nchan_out_woLFE );
}
- if ( hDirAC->hOutSetup.ambisonics_order == -1 )
+ if ( hDirACRend->hOutSetup.ambisonics_order == -1 )
{
- hDirAC->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */
- if ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_MONO || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_STEREO )
+ hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */
+ if ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_MONO || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_STEREO )
{
- hDirAC->hOutSetup.ambisonics_order = SBA_FOA_ORDER;
+ hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER;
}
}
- else if ( hDirAC->hOutSetup.ambisonics_order >= SBA_FOA_ORDER )
+ else if ( hDirACRend->hOutSetup.ambisonics_order >= SBA_FOA_ORDER )
{
mvr2r( ls_azimuth_4d4, ls_azimuth, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
mvr2r( ls_elevation_4d4, ls_elevation, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
}
- if ( hDirAC->hOutSetup.separateChannelEnabled && ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_4 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 || ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
+ if ( hDirACRend->hOutSetup.separateChannelEnabled && ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1 || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_7_1 || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1_4 || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 || ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
{
/* Remove the channel of the separated signal from the output setup of the spatial synthesis */
- hDirAC->hOutSetup.nchan_out_woLFE--;
- nchan_out_woLFE = hDirAC->hOutSetup.nchan_out_woLFE;
- mvr2r( &ls_azimuth[hDirAC->hOutSetup.separateChannelIndex + 1], &ls_azimuth[hDirAC->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirAC->hOutSetup.separateChannelIndex );
- mvr2r( &ls_elevation[hDirAC->hOutSetup.separateChannelIndex + 1], &ls_elevation[hDirAC->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirAC->hOutSetup.separateChannelIndex );
+ hDirACRend->hOutSetup.nchan_out_woLFE--;
+ nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
+ mvr2r( &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex );
+ mvr2r( &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex );
}
/*-----------------------------------------------------------------*
@@ -389,100 +229,62 @@ ivas_error ivas_dirac_dec_config(
st_ivas->nchan_transport = nchan_transport_orig;
- if ( flag_config == DIRAC_OPEN )
- {
- hDirAC->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
- set_s( hDirAC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
- set_s( hDirAC->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
- hDirAC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
- hDirAC->subframes_rendered = 0;
- hDirAC->slots_rendered = 0;
- hDirAC->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
- }
-
- if ( st_ivas->ivas_format == SBA_FORMAT && flag_config == DIRAC_RECONFIGURE && ( ( ivas_total_brate > IVAS_256k && st_ivas->hDecoderConfig->last_ivas_total_brate <= IVAS_256k ) || ( ivas_total_brate <= IVAS_256k && st_ivas->hDecoderConfig->last_ivas_total_brate > IVAS_256k ) ) )
- {
- if ( st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k && hDirAC->azimuth2 == NULL )
- {
- if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
- else if ( st_ivas->hDecoderConfig->ivas_total_brate <= IVAS_256k && hDirAC->azimuth2 != NULL )
- {
- ivas_dirac_deallocate_parameters( hDirAC, 2 );
- }
- }
-
- /* band config needed only for SPAR with FOA output */
- if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag )
- {
- return IVAS_ERR_OK;
- }
-
- if ( nchan_transport_orig > 2 && hDirAC->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC && !hodirac_flag )
- {
- hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
- hDirAC->panningConf = DIRAC_PANNING_VBAP;
- }
- else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
+ if ( nchan_transport_orig > 2 && hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC && !hodirac_flag )
{
- hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
- hDirAC->panningConf = DIRAC_PANNING_VBAP;
+ hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
+ hDirACRend->panningConf = DIRAC_PANNING_VBAP;
}
- else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->hOutSetup.output_config == AUDIO_CONFIG_MONO )
+ else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_MONO )
{
- hDirAC->synthesisConf = DIRAC_SYNTHESIS_MONO;
- hDirAC->panningConf = DIRAC_PANNING_HOA3;
+ hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO;
+ hDirACRend->panningConf = DIRAC_PANNING_HOA3;
nchan_out_woLFE = 1;
}
- else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->hOutSetup.is_loudspeaker_setup )
+ else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.is_loudspeaker_setup )
{
- hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
- hDirAC->panningConf = DIRAC_PANNING_VBAP;
+ hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
+ hDirACRend->panningConf = DIRAC_PANNING_VBAP;
}
- else if ( st_ivas->ivas_format == MASA_FORMAT && !hDirAC->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 )
+ else if ( st_ivas->ivas_format == MASA_FORMAT && !hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 )
{
- hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD;
- hDirAC->panningConf = DIRAC_PANNING_HOA3;
+ hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD;
+ hDirACRend->panningConf = DIRAC_PANNING_HOA3;
}
else
{
- hDirAC->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD;
- hDirAC->panningConf = DIRAC_PANNING_HOA3;
+ hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD;
+ hDirACRend->panningConf = DIRAC_PANNING_HOA3;
}
if ( flag_config == DIRAC_OPEN )
{
- hDirAC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
- if ( ( hDirAC->frequency_axis = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
+ if ( ( hDirACRend->frequency_axis = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
- set_f( hDirAC->frequency_axis, 0.0f, hDirAC->num_freq_bands );
+ set_f( hDirACRend->frequency_axis, 0.0f, hSpatParamRendCom->num_freq_bands );
- ivas_dirac_dec_get_frequency_axis( hDirAC->frequency_axis, output_Fs, hDirAC->num_freq_bands );
+ ivas_dirac_dec_get_frequency_axis( hDirACRend->frequency_axis, output_Fs, hSpatParamRendCom->num_freq_bands );
}
- if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->panningConf == DIRAC_PANNING_HOA3 && nchan_transport == 2 )
+ if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->panningConf == DIRAC_PANNING_HOA3 && nchan_transport == 2 )
{
- if ( ( flag_config == DIRAC_RECONFIGURE && hDirAC->masa_stereo_type_detect == NULL ) || flag_config == DIRAC_OPEN )
+ if ( ( flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect == NULL ) || flag_config == DIRAC_OPEN )
{
- if ( ( hDirAC->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL )
+ if ( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- ivas_masa_init_stereotype_detection( hDirAC->masa_stereo_type_detect );
+ ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect );
}
else
{
- if ( flag_config == DIRAC_RECONFIGURE && hDirAC->masa_stereo_type_detect != NULL )
+ if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect != NULL )
{
- free( hDirAC->masa_stereo_type_detect );
+ free( hDirACRend->masa_stereo_type_detect );
}
- hDirAC->masa_stereo_type_detect = NULL;
+ hDirACRend->masa_stereo_type_detect = NULL;
}
/*-----------------------------------------------------------------*
@@ -492,45 +294,39 @@ ivas_error ivas_dirac_dec_config(
/* prototype signal computation */
if ( flag_config == DIRAC_RECONFIGURE )
{
- num_outputs_dir_old = hDirAC->num_outputs_dir;
- num_outputs_diff_old = hDirAC->num_outputs_diff;
- num_protos_diff_old = hDirAC->num_protos_diff;
+ num_outputs_dir_old = hDirACRend->num_outputs_dir;
+ num_outputs_diff_old = hDirACRend->num_outputs_diff;
+ num_protos_diff_old = hDirACRend->num_protos_diff;
}
/* allocate output setup related arrays */
- if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
- {
- /* Two channels in parametric binaural rendering */
- hDirAC->num_outputs_diff = 2;
- hDirAC->num_outputs_dir = 2;
- }
- else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS )
{
/* Directional and diffuses components in output LS format */
- hDirAC->num_outputs_diff = nchan_out_woLFE;
- hDirAC->num_outputs_dir = nchan_out_woLFE;
+ hDirACRend->num_outputs_diff = nchan_out_woLFE;
+ hDirACRend->num_outputs_dir = nchan_out_woLFE;
}
- else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
/* Directional and diffuses components in SHD */
/* Diffuseness components up to 1st order */
- hDirAC->num_outputs_diff = ( min( hDirAC->hOutSetup.ambisonics_order, 1 ) + 1 ) * ( min( hDirAC->hOutSetup.ambisonics_order, 1 ) + 1 );
- if ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( ivas_total_brate >= IVAS_96k ) && ( hDirAC->hOutSetup.ambisonics_order > 1 ) && ( nchan_transport < 4 ) )
+ hDirACRend->num_outputs_diff = ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ) * ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 );
+ if ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( ivas_total_brate >= IVAS_96k ) && ( hDirACRend->hOutSetup.ambisonics_order > 1 ) && ( nchan_transport < 4 ) )
{
- hDirAC->num_outputs_diff += 2; /* Add 2nd-order planar components for HRs */
+ hDirACRend->num_outputs_diff += 2; /* Add 2nd-order planar components for HRs */
}
- hDirAC->num_outputs_dir = ivas_sba_get_nchan( hDirAC->hOutSetup.ambisonics_order, 0 );
+ hDirACRend->num_outputs_dir = ivas_sba_get_nchan( hDirACRend->hOutSetup.ambisonics_order, 0 );
}
- else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
+ else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
{
- hDirAC->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS;
- hDirAC->num_outputs_dir = nchan_out_woLFE;
+ hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS;
+ hDirACRend->num_outputs_dir = nchan_out_woLFE;
}
- else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
+ else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO )
{
- hDirAC->num_outputs_diff = 1; /* There is one output channel in mono */
- hDirAC->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */
+ hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */
+ hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */
}
else
{
@@ -539,154 +335,135 @@ ivas_error ivas_dirac_dec_config(
if ( flag_config == DIRAC_OPEN )
{
- num_outputs_dir_old = hDirAC->num_outputs_dir;
- if ( ( hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ) ) == NULL )
+ num_outputs_dir_old = hDirACRend->num_outputs_dir;
+ if ( ( hDirACRend->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_dir ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
- num_outputs_diff_old = hDirAC->num_outputs_diff;
- if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL )
+ num_outputs_diff_old = hDirACRend->num_outputs_diff;
+ if ( ( hDirACRend->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_diff ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- if ( hDirAC->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE )
+ if ( hDirACRend->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE )
{
- free( hDirAC->proto_index_dir );
- if ( ( hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ) ) == NULL )
+ free( hDirACRend->proto_index_dir );
+ if ( ( hDirACRend->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_dir ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- set_s( hDirAC->proto_index_dir, 0, hDirAC->num_outputs_dir );
+ set_s( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir );
- if ( hDirAC->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE )
+ if ( hDirACRend->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE )
{
- free( hDirAC->proto_index_diff );
- if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL )
+ free( hDirACRend->proto_index_diff );
+ if ( ( hDirACRend->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_diff ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- set_s( hDirAC->proto_index_diff, 0, hDirAC->num_outputs_diff );
+ set_s( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff );
- hDirAC->sba_map_tc = sba_map_tc;
+ hDirACRend->sba_map_tc = sba_map_tc;
if ( st_ivas->ivas_format == SBA_FORMAT )
{
if ( st_ivas->sba_order > SBA_FOA_ORDER && ivas_total_brate >= IVAS_512k )
{
- hDirAC->sba_map_tc = sba_map_tc_512;
+ hDirACRend->sba_map_tc = sba_map_tc_512;
}
}
if ( nchan_transport == 1 )
{
- hDirAC->num_protos_ambi = 1;
- hDirAC->num_protos_dir = 1;
- hDirAC->num_protos_diff = 1;
-
- if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
- {
- hDirAC->num_protos_dir = 2;
- hDirAC->num_protos_diff = 2;
- hDirAC->proto_index_dir[0] = 0;
- hDirAC->proto_index_dir[1] = 1;
- hDirAC->proto_index_diff[0] = 0;
- hDirAC->proto_index_diff[1] = 1;
- }
+ hDirACRend->num_protos_ambi = 1;
+ hDirACRend->num_protos_dir = 1;
+ hDirACRend->num_protos_diff = 1;
}
else if ( nchan_transport == 2 )
{
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
- {
- hDirAC->num_protos_ambi = 2;
- hDirAC->num_protos_diff = 1;
- hDirAC->num_protos_dir = 2;
- hDirAC->proto_index_dir[1] = 1;
- }
- else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- hDirAC->num_protos_dir = 2;
- hDirAC->num_protos_diff = 2;
- hDirAC->proto_index_dir[0] = 0;
- hDirAC->proto_index_dir[1] = 1;
- hDirAC->proto_index_diff[0] = 0;
- hDirAC->proto_index_diff[1] = 1;
+ hDirACRend->num_protos_ambi = 2;
+ hDirACRend->num_protos_diff = 1;
+ hDirACRend->num_protos_dir = 2;
+ hDirACRend->proto_index_dir[1] = 1;
}
- else if ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_MONO )
+ else if ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_MONO )
{
/* Following the foa rendering for code compatibility */
- hDirAC->num_protos_ambi = 2;
- hDirAC->num_protos_dir = 2;
- hDirAC->num_protos_diff = 3;
- hDirAC->proto_index_dir[0] = 0;
- hDirAC->proto_index_diff[0] = 0;
+ hDirACRend->num_protos_ambi = 2;
+ hDirACRend->num_protos_dir = 2;
+ hDirACRend->num_protos_diff = 3;
+ hDirACRend->proto_index_dir[0] = 0;
+ hDirACRend->proto_index_diff[0] = 0;
}
else
{
- hDirAC->num_protos_ambi = 2;
- hDirAC->num_protos_diff = 3;
+ hDirACRend->num_protos_ambi = 2;
+ hDirACRend->num_protos_diff = 3;
- for ( k = 0; k < hDirAC->num_outputs_diff; k++ )
+ for ( k = 0; k < hDirACRend->num_outputs_diff; k++ )
{
if ( ls_azimuth[k] > 0.0f )
{
- hDirAC->proto_index_diff[k] = 1;
+ hDirACRend->proto_index_diff[k] = 1;
}
else if ( ls_azimuth[k] < 0.0f )
{
- hDirAC->proto_index_diff[k] = 2;
+ hDirACRend->proto_index_diff[k] = 2;
}
else
{
- hDirAC->proto_index_diff[k] = 0;
+ hDirACRend->proto_index_diff[k] = 0;
}
}
- if ( hDirAC->hOutSetup.is_loudspeaker_setup )
+ if ( hDirACRend->hOutSetup.is_loudspeaker_setup )
{
- hDirAC->num_protos_dir = 3;
- mvs2s( hDirAC->proto_index_diff, hDirAC->proto_index_dir, nchan_out_woLFE );
+ hDirACRend->num_protos_dir = 3;
+ mvs2s( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE );
}
else
{
- hDirAC->num_protos_dir = 2;
- hDirAC->proto_index_dir[1] = 1;
+ hDirACRend->num_protos_dir = 2;
+ hDirACRend->proto_index_dir[1] = 1;
}
}
}
else /* nchan_transport > 2 */
{
- hDirAC->num_protos_ambi = 4;
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS )
+ hDirACRend->num_protos_ambi = 4;
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS )
{
- hDirAC->num_protos_diff = hDirAC->num_outputs_diff;
- for ( k = 0; k < hDirAC->num_outputs_diff; k++ )
+ hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff;
+ for ( k = 0; k < hDirACRend->num_outputs_diff; k++ )
{
- hDirAC->proto_index_diff[k] = k;
+ hDirACRend->proto_index_diff[k] = k;
}
- hDirAC->num_protos_dir = hDirAC->num_outputs_dir;
- for ( k = 0; k < hDirAC->num_outputs_dir; k++ )
+ hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir;
+ for ( k = 0; k < hDirACRend->num_outputs_dir; k++ )
{
- hDirAC->proto_index_dir[k] = k;
+ hDirACRend->proto_index_dir[k] = k;
}
}
else
{
- hDirAC->num_protos_diff = 1;
- hDirAC->num_protos_dir = nchan_transport;
- if ( ( st_ivas->sba_planar ) && ( !( st_ivas->ivas_format == SBA_FORMAT ) ) )
+ hDirACRend->num_protos_diff = 1;
+ hDirACRend->num_protos_dir = nchan_transport;
+ if ( ( st_ivas->sba_planar ) && ( !( st_ivas->ivas_format == SBA_FORMAT ) ) ) // Todo Dolby/FhG refactor: Is this ever true?
{
- hDirAC->num_protos_dir++;
+ hDirACRend->num_protos_dir++;
}
- for ( k = 0; k < min( hDirAC->num_outputs_dir, hDirAC->num_protos_dir ); k++ )
+ for ( k = 0; k < min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ )
{
- if ( hDirAC->sba_map_tc[k] < hDirAC->num_outputs_dir )
+ if ( hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir )
{
- hDirAC->proto_index_dir[hDirAC->sba_map_tc[k]] = k;
+ hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k;
}
}
}
@@ -695,61 +472,61 @@ ivas_error ivas_dirac_dec_config(
/* direct/diffuse responses */
if ( flag_config == DIRAC_OPEN )
{
- if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL )
+ if ( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
/* reallocate static memory */
- else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->num_outputs_dir != num_outputs_dir_old )
+ else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->num_outputs_dir != num_outputs_dir_old )
{
- free( hDirAC->diffuse_response_function );
- hDirAC->diffuse_response_function = NULL;
- if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL )
+ free( hDirACRend->diffuse_response_function );
+ hDirACRend->diffuse_response_function = NULL;
+ if ( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- if ( ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) )
+ if ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) )
{
- initDiffuseResponses( hDirAC->diffuse_response_function, nchan_out_woLFE, hDirAC->hOutSetup.output_config,
- hDirAC->hOutSetup, hDirAC->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirAC->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config );
+ initDiffuseResponses( hDirACRend->diffuse_response_function, nchan_out_woLFE, hDirACRend->hOutSetup.output_config,
+ hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config );
}
else
{
- initDiffuseResponses( hDirAC->diffuse_response_function, hDirAC->num_outputs_dir, AUDIO_CONFIG_FOA,
- hDirAC->hOutSetup, hDirAC->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirAC->num_ele_spk_no_diffuse_rendering, AUDIO_CONFIG_INVALID );
+ initDiffuseResponses( hDirACRend->diffuse_response_function, hDirACRend->num_outputs_dir, AUDIO_CONFIG_FOA,
+ hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, AUDIO_CONFIG_INVALID );
}
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
{
if ( flag_config == DIRAC_OPEN )
{
- if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL )
+ if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->hoa_encoder && ( hDirAC->num_outputs_diff != num_outputs_diff_old ) )
+ else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder && ( hDirACRend->num_outputs_diff != num_outputs_diff_old ) )
{
- free( hDirAC->hoa_encoder );
- hDirAC->hoa_encoder = NULL;
- if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL )
+ free( hDirACRend->hoa_encoder );
+ hDirACRend->hoa_encoder = NULL;
+ if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- set_f( hDirAC->hoa_encoder, 0.0f, nchan_out_woLFE * hDirAC->num_outputs_diff );
- compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirAC->hoa_encoder, hDirAC->num_outputs_diff, hDirAC->hOutSetup.ambisonics_order );
+ set_f( hDirACRend->hoa_encoder, 0.0f, nchan_out_woLFE * hDirACRend->num_outputs_diff );
+ compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirACRend->hoa_encoder, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order );
}
else
{
- if ( flag_config == DIRAC_RECONFIGURE && hDirAC->hoa_encoder )
+ if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder )
{
- free( hDirAC->hoa_encoder );
+ free( hDirACRend->hoa_encoder );
}
- hDirAC->hoa_encoder = NULL;
+ hDirACRend->hoa_encoder = NULL;
}
/* VBAP */
@@ -758,7 +535,7 @@ ivas_error ivas_dirac_dec_config(
st_ivas->hVBAPdata = NULL;
}
- if ( hDirAC->panningConf == DIRAC_PANNING_VBAP )
+ if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP )
{
if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL )
{
@@ -770,13 +547,13 @@ ivas_error ivas_dirac_dec_config(
return error;
}
}
- else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
+ else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO )
{
if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL )
{
vbap_free_data( &( st_ivas->hVBAPdata ) );
}
- hDirAC->hoa_decoder = NULL;
+ hDirACRend->hoa_decoder = NULL;
}
else if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL )
{
@@ -786,67 +563,67 @@ ivas_error ivas_dirac_dec_config(
/* HOA panning/dec */
if ( flag_config == DIRAC_OPEN )
{
- hDirAC->hoa_decoder = NULL;
- if ( ( hDirAC->panningConf == DIRAC_PANNING_HOA3 ) || st_ivas->ivas_format == SBA_FORMAT || ( nchan_transport > 2 ) )
+ hDirACRend->hoa_decoder = NULL;
+ if ( ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) || st_ivas->ivas_format == SBA_FORMAT || ( nchan_transport > 2 ) )
{
- if ( hDirAC->hOutSetup.is_loudspeaker_setup )
+ if ( hDirACRend->hOutSetup.is_loudspeaker_setup )
{
if ( st_ivas->hoa_dec_mtx != NULL )
{
free( st_ivas->hoa_dec_mtx );
st_ivas->hoa_dec_mtx = NULL;
}
- if ( ( error = ivas_sba_get_hoa_dec_matrix( hDirAC->hOutSetup, &st_ivas->hoa_dec_mtx, hDirAC->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_sba_get_hoa_dec_matrix( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK )
{
return error;
}
- hDirAC->hoa_decoder = st_ivas->hoa_dec_mtx;
+ hDirACRend->hoa_decoder = st_ivas->hoa_dec_mtx;
}
}
}
/* decorrelation */
- proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirAC->proto_signal_decorr_on : 0;
- hDirAC->proto_signal_decorr_on = 1;
- if ( ( nchan_transport > 2 ) && ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) )
+ proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirACRend->proto_signal_decorr_on : 0;
+ hDirACRend->proto_signal_decorr_on = 1;
+ if ( ( nchan_transport > 2 ) && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) )
{
/*switch off decorrelation for 4 transport channels*/
- hDirAC->proto_signal_decorr_on = 0;
+ hDirACRend->proto_signal_decorr_on = 0;
}
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO )
{
- hDirAC->proto_signal_decorr_on = 0;
+ hDirACRend->proto_signal_decorr_on = 0;
}
- if ( ( flag_config == DIRAC_OPEN && hDirAC->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) )
+ if ( ( flag_config == DIRAC_OPEN && hDirACRend->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) )
{
- if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ),
- &( hDirAC->h_freq_domain_decorr_ap_state ),
- hDirAC->num_freq_bands,
- hDirAC->num_outputs_diff,
- hDirAC->num_protos_diff,
- hDirAC->synthesisConf,
- hDirAC->frequency_axis,
+ if ( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ),
+ &( hDirACRend->h_freq_domain_decorr_ap_state ),
+ hSpatParamRendCom->num_freq_bands,
+ hDirACRend->num_outputs_diff,
+ hDirACRend->num_protos_diff,
+ hDirACRend->synthesisConf,
+ hDirACRend->frequency_axis,
nchan_transport > 2 ? 4 : nchan_transport,
output_Fs ) ) != IVAS_ERR_OK )
{
return error;
}
}
- else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) )
+ else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) )
{
- ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state );
+ ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
}
- else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old )
+ else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old )
{
- if ( nchan_transport != nchan_transport_old || hDirAC->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE )
+ if ( nchan_transport != nchan_transport_old || hDirACRend->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE )
{
/* close and reopen the decorrelator */
- ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state );
+ ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
- if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), &( hDirAC->h_freq_domain_decorr_ap_state ), hDirAC->num_freq_bands, hDirAC->num_outputs_diff,
- hDirAC->num_protos_diff, hDirAC->synthesisConf, hDirAC->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff,
+ hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK )
{
return error;
}
@@ -856,54 +633,54 @@ ivas_error ivas_dirac_dec_config(
/* output synthesis */
if ( flag_config == DIRAC_OPEN )
{
- if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK )
+ if ( ( ivas_dirac_dec_output_synthesis_open( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK )
{
return error;
}
- hDirAC->h_output_synthesis_psd_params.use_onset_filters = hDirAC->proto_signal_decorr_on;
+ hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
}
- else if ( ( flag_config == DIRAC_RECONFIGURE ) && ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) )
+ else if ( ( flag_config == DIRAC_RECONFIGURE ) && ( ( nchan_transport != nchan_transport_old ) || ( hDirACRend->num_outputs_diff != num_outputs_diff_old ) ) )
{
- ivas_dirac_dec_output_synthesis_close( hDirAC );
+ ivas_dirac_dec_output_synthesis_close( hDirACRend );
- if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK )
+ if ( ( ivas_dirac_dec_output_synthesis_open( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK )
{
return error;
}
- hDirAC->h_output_synthesis_psd_params.use_onset_filters = hDirAC->proto_signal_decorr_on;
+ hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
}
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- hDirAC->h_output_synthesis_psd_params.use_onset_filters = 0;
+ hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0;
}
/*-----------------------------------------------------------------*
* memory allocation
*-----------------------------------------------------------------*/
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_frame_f )
+ if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f )
{
- free( hDirAC->proto_frame_f );
+ free( hDirACRend->proto_frame_f );
}
- hDirAC->proto_frame_f = NULL;
+ hDirACRend->proto_frame_f = NULL;
}
else
{
- if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_frame_f == NULL ) )
+ if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL ) )
{
- if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL )
+ if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- else if ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->num_protos_diff != num_protos_diff_old ) )
+ else if ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->num_protos_diff != num_protos_diff_old ) )
{
- proto_frame_f_old = hDirAC->proto_frame_f;
+ proto_frame_f_old = hDirACRend->proto_frame_f;
free( proto_frame_f_old );
- if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL )
+ if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
@@ -913,31 +690,31 @@ ivas_error ivas_dirac_dec_config(
if ( flag_config == DIRAC_OPEN )
{
- hDirAC->buffer_energy = NULL;
+ hDirACRend->buffer_energy = NULL;
}
if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == TRUE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) )
{
- hDirAC->index_buffer_intensity = 0;
+ hDirACRend->index_buffer_intensity = 0;
for ( i = 0; i < DIRAC_NUM_DIMS; i++ )
{
for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
{
- if ( ( hDirAC->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL )
+ if ( ( hDirACRend->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
- set_f( hDirAC->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX );
+ set_f( hDirACRend->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX );
}
}
- if ( hDirAC->buffer_energy == NULL )
+ if ( hDirACRend->buffer_energy == NULL )
{
- if ( ( hDirAC->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL )
+ if ( ( hDirACRend->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
}
- set_f( hDirAC->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX );
+ set_f( hDirACRend->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX );
}
else if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == FALSE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) )
{
@@ -945,124 +722,228 @@ ivas_error ivas_dirac_dec_config(
{
for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
{
- if ( flag_config == DIRAC_RECONFIGURE && hDirAC->buffer_intensity_real[i][j] )
+ if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->buffer_intensity_real[i][j] )
{
- free( hDirAC->buffer_intensity_real[i][j] );
+ free( hDirACRend->buffer_intensity_real[i][j] );
}
- hDirAC->buffer_intensity_real[i][j] = NULL;
+ hDirACRend->buffer_intensity_real[i][j] = NULL;
}
}
- if ( hDirAC->buffer_energy != NULL )
+ if ( hDirACRend->buffer_energy != NULL )
{
- free( hDirAC->buffer_energy );
- hDirAC->buffer_energy = NULL;
+ free( hDirACRend->buffer_energy );
+ hDirACRend->buffer_energy = NULL;
}
}
/* output synthesis */
- ivas_dirac_dec_output_synthesis_init( hDirAC, nchan_out_woLFE, hodirac_flag );
+ ivas_dirac_dec_output_synthesis_init( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag );
/* Allocate stack memory */
if ( flag_config != DIRAC_OPEN )
{
- ivas_dirac_free_mem( &( hDirAC->stack_mem ) );
+ ivas_dirac_free_mem( &( hDirACRend->stack_mem ) );
}
- if ( ( error = ivas_dirac_alloc_mem( hDirAC, st_ivas->renderer_type, &( hDirAC->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK )
{
return error;
}
- mvs2s( DirAC_block_grouping, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 );
-
if ( flag_config == DIRAC_OPEN )
{
- hDirAC->dirac_md_buffer_length = 0;
- hDirAC->dirac_bs_md_write_idx = 0;
- hDirAC->dirac_read_idx = 0;
- hDirAC->spar_to_dirac_write_idx = 0;
- if ( st_ivas->mc_mode == MC_MODE_MCMASA )
- {
- hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
+ st_ivas->hDirACRend = hDirACRend;
+ }
- set_s( hDirAC->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
- for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ )
- {
- hDirAC->render_to_md_map[map_idx] = map_idx;
- }
- }
- else if ( st_ivas->ivas_format == MASA_FORMAT )
- {
- hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR;
- hDirAC->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR;
+ return error;
+}
- set_s( hDirAC->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
- for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ )
- {
- hDirAC->render_to_md_map[map_idx] = map_idx;
- }
- }
- else
- {
- int16_t num_slots_in_subfr;
- num_slots_in_subfr = hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1;
- hDirAC->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR );
- hDirAC->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR;
- hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR;
- hDirAC->dirac_read_idx = 0;
- hDirAC->dirac_estimator_idx = 0;
-
- set_s( hDirAC->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
- for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ )
- {
- hDirAC->render_to_md_map[map_idx] = hDirAC->dirac_read_idx + map_idx / num_slots_in_subfr;
- }
- }
- if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 1 ) ) != IVAS_ERR_OK )
- {
- return error;
- }
+/*-------------------------------------------------------------------------
+ * ivas_dirac_dec_config()
+ *
+ * Open or reconfigure decoder DirAC/MASA handle
+ *-------------------------------------------------------------------------*/
- if ( st_ivas->ivas_format == MASA_FORMAT || ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k ) )
- {
- if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
- else
- {
- hDirAC->azimuth2 = NULL;
- hDirAC->elevation2 = NULL;
- hDirAC->energy_ratio2 = NULL;
- hDirAC->spreadCoherence2 = NULL;
- }
+ivas_error ivas_dirac_dec_config(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
+)
+{
+ ivas_error error;
+ int32_t output_Fs;
+ int16_t hodirac_flag;
+ int16_t sparfoa_flag;
+ DIRAC_CONFIG_FLAG dec_config_flag;
+ DIRAC_CONFIG_FLAG rend_config_flag;
+ DIRAC_CONFIG_FLAG common_rend_config_flag;
+ int16_t need_dirac_rend;
+ int16_t need_parambin;
+ int16_t dec_param_estim_old;
+ int16_t dec_param_estim_new;
- hDirAC->hDiffuseDist = NULL; /* Memory is allocated from stack during runtime when needed */
+ error = IVAS_ERR_OK;
- hDirAC->dithering_seed = DIRAC_DITH_SEED;
- st_ivas->hDirAC = hDirAC;
+ /* Solve and setup flags for inits */
+ dec_config_flag = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp;
+
+ output_Fs = st_ivas->hDecoderConfig->output_Fs;
+ hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
+ dec_param_estim_old = ( dec_config_flag == DIRAC_RECONFIGURE ) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE;
+
+
+ sparfoa_flag = 0;
+ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag )
+ {
+ sparfoa_flag = 1;
}
- /* allocate transport channels*/
- if ( flag_config == DIRAC_OPEN )
+ if ( ( error = ivas_dirac_dec_config_internal( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ /* This is required for parambin */
+ if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
+ {
+ st_ivas->hDirAC->hConfig->dec_param_estim = FALSE;
+ }
+
+ dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim;
+
+ /* Setup renderers and meta */
+ /* First, free everything if in reconfig and not the active renderer */
+ need_parambin = 0;
+ switch ( st_ivas->renderer_type )
+ {
+ case RENDERER_BINAURAL_PARAMETRIC:
+ case RENDERER_BINAURAL_PARAMETRIC_ROOM:
+ case RENDERER_STEREO_PARAMETRIC:
+ need_parambin = 1;
+ break;
+ default:
+ need_parambin = 0;
+ }
+
+ if ( !need_parambin )
+ {
+ ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin );
+ }
+
+ need_dirac_rend = 0;
+ switch ( st_ivas->renderer_type )
+ {
+ case RENDERER_DIRAC:
+ case RENDERER_BINAURAL_FASTCONV:
+ case RENDERER_BINAURAL_FASTCONV_ROOM:
+ case RENDERER_SBA_LINEAR_ENC:
+ case RENDERER_SBA_LINEAR_DEC:
+ need_dirac_rend = 1;
+ break;
+ default:
+ need_dirac_rend = 0;
+ }
+
+ if ( !need_dirac_rend )
+ {
+ ivas_dirac_rend_close( &st_ivas->hDirACRend );
+ }
+
+ if ( !sparfoa_flag )
+ {
+ common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : flag_config_inp;
+ if ( ( error = ivas_spat_hSpatParamRendCom_config( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new,
+ st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( need_dirac_rend )
+ {
+ rend_config_flag = st_ivas->hDirACRend == NULL ? DIRAC_OPEN : flag_config_inp;
+ if ( ( error = ivas_dirac_rend_config( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ if ( need_parambin )
+ {
+ if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC )
+ {
+ if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ if ( st_ivas->hDiracDecBin == NULL )
+ {
+ if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ else
+ {
+ /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */
+ if ( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) )
+ {
+ ivas_dirac_dec_decorr_close( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state );
+ }
+
+ if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( !st_ivas->hDiracDecBin->useTdDecorr )
+ {
+ if ( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params == NULL )
+ {
+ float frequency_axis[CLDFB_NO_CHANNELS_MAX];
+ ivas_dirac_dec_get_frequency_axis( frequency_axis, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands );
+ if ( ( error = ivas_dirac_dec_decorr_open( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ),
+ &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ),
+ st_ivas->hSpatParamRendCom->num_freq_bands,
+ BINAURAL_CHANNELS,
+ BINAURAL_CHANNELS,
+ DIRAC_SYNTHESIS_PSD_LS,
+ frequency_axis,
+ BINAURAL_CHANNELS,
+ st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ }
+
+ st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
+ }
+ }
+ }
+
+ /* Allocate transport channel buffers for SBA format when in JBM */
+ if ( dec_config_flag == DIRAC_OPEN )
{
if ( st_ivas->hDecoderConfig->voip_active == 1 && st_ivas->hTcBuffer == NULL )
{
if ( st_ivas->ivas_format == SBA_FORMAT )
{
int16_t nchan_to_allocate;
+ int16_t nchan_transport;
+
+ nchan_transport = st_ivas->nchan_transport;
nchan_to_allocate = nchan_transport;
- if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
+ if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
{
nchan_to_allocate++; /* we need a channel for the CNG in this case*/
}
- if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
+ if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
{
nchan_to_allocate = 2 * BINAURAL_CHANNELS;
}
- if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_to_allocate, nchan_to_allocate, hDirAC->slot_size ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_to_allocate, nchan_to_allocate, st_ivas->hSpatParamRendCom->slot_size ) ) != IVAS_ERR_OK )
{
return error;
}
@@ -1081,10 +962,8 @@ ivas_error ivas_dirac_dec_config(
*------------------------------------------------------------------------*/
void ivas_dirac_dec_close(
- DIRAC_DEC_HANDLE *hDirAC_out /* i/o: decoder DirAC handle */
-)
+ DIRAC_DEC_HANDLE *hDirAC_out )
{
- int16_t i, j;
DIRAC_DEC_HANDLE hDirAC;
if ( hDirAC_out == NULL || *hDirAC_out == NULL )
@@ -1101,86 +980,6 @@ void ivas_dirac_dec_close(
hDirAC->hConfig = NULL;
}
- /* close Output synthesis sub-module */
- ivas_dirac_dec_output_synthesis_close( hDirAC );
-
- /* close Decorrelator sub-module */
- if ( hDirAC->proto_signal_decorr_on )
- {
- ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state );
- }
-
- /* Params */
-
- /* free frequency axis buffer */
- if ( hDirAC->frequency_axis != NULL )
- {
- free( hDirAC->frequency_axis );
- hDirAC->frequency_axis = NULL;
- }
-
- if ( hDirAC->diffuse_response_function != NULL )
- {
- free( hDirAC->diffuse_response_function );
- hDirAC->diffuse_response_function = NULL;
- }
-
- if ( hDirAC->hoa_encoder != NULL )
- {
- free( hDirAC->hoa_encoder );
- hDirAC->hoa_encoder = NULL;
- }
-
- /* prototype indexing */
- if ( hDirAC->proto_index_dir != NULL )
- {
- free( hDirAC->proto_index_dir );
- hDirAC->proto_index_dir = NULL;
- }
-
- if ( hDirAC->proto_index_diff != NULL )
- {
- free( hDirAC->proto_index_diff );
- hDirAC->proto_index_dir = NULL;
- }
-
- /* States */
-
- /* free prototype signal buffers */
- if ( hDirAC->proto_frame_f != NULL )
- {
- free( hDirAC->proto_frame_f );
- hDirAC->proto_frame_f = NULL;
- }
-
- for ( i = 0; i < DIRAC_NUM_DIMS; i++ )
- {
- for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
- {
- if ( hDirAC->buffer_intensity_real[i][j] != NULL )
- {
- free( hDirAC->buffer_intensity_real[i][j] );
- hDirAC->buffer_intensity_real[i][j] = NULL;
- }
- }
- }
- if ( hDirAC->buffer_energy != NULL )
- {
- free( hDirAC->buffer_energy );
- hDirAC->buffer_energy = NULL;
- }
-
- ivas_dirac_deallocate_parameters( hDirAC, 1 );
- ivas_dirac_deallocate_parameters( hDirAC, 2 );
-
- if ( hDirAC->masa_stereo_type_detect != NULL )
- {
- free( hDirAC->masa_stereo_type_detect );
- hDirAC->masa_stereo_type_detect = NULL;
- }
-
- ivas_dirac_free_mem( &( hDirAC->stack_mem ) );
-
free( *hDirAC_out );
*hDirAC_out = NULL;
@@ -1189,1993 +988,557 @@ void ivas_dirac_dec_close(
/*-------------------------------------------------------------------------
- * ivas_dirac_deallocate_parameters()
+ * ivas_dirac_dec_read_BS()
*
- * Deallocate DirAC parameters
- *-------------------------------------------------------------------------*/
+ * Read DirAC parameters from the bitstream
+ *------------------------------------------------------------------------*/
-void ivas_dirac_deallocate_parameters(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
- const int16_t params_flag /* i : set of parameters flag */
+void ivas_dirac_dec_read_BS(
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ Decoder_State *st, /* i/o: decoder state structure */
+ DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */
+ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata */
+ int16_t *nb_bits, /* o : number of bits read */
+ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
+ int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */
)
{
- int16_t i;
-
- if ( params_flag == 1 )
+ int16_t i, j, b, dir, orig_dirac_bands;
+ int16_t next_bit_pos_orig;
+ *nb_bits = 0;
+ if ( !st->bfi && ivas_total_brate > IVAS_SID_5k2 )
{
- if ( hDirAC->azimuth != NULL )
- {
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
- {
- if ( hDirAC->azimuth[i] != NULL )
- {
- free( hDirAC->azimuth[i] );
- hDirAC->azimuth[i] = NULL;
- }
- }
+ next_bit_pos_orig = st->next_bit_pos;
+ st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 );
- free( hDirAC->azimuth );
- hDirAC->azimuth = NULL;
- }
+ /* 1 bit flag for signaling metadata to read */
+ b = st->bit_stream[( st->next_bit_pos )--];
+ ( *nb_bits )++;
- if ( hDirAC->elevation != NULL )
+ if ( b == 1 ) /* WB 4TCs condition, no other metadata to read*/
{
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
- {
- if ( hDirAC->elevation[i] != NULL )
- {
- free( hDirAC->elevation[i] );
- hDirAC->elevation[i] = NULL;
- }
- }
+ orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
- free( hDirAC->elevation );
- hDirAC->elevation = NULL;
- }
+ hQMetaData->sba_inactive_mode = 1;
- if ( hDirAC->energy_ratio1 != NULL )
- {
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
+ /* if we start with a SID frame, we need to init the azi/ele arrays.*/
+ if ( st->ini_frame == 0 )
{
- if ( hDirAC->energy_ratio1[i] != NULL )
+ for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ )
{
- free( hDirAC->energy_ratio1[i] );
- hDirAC->energy_ratio1[i] = NULL;
+ set_zero( hQMetaData->q_direction[0].band_data[b].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES );
+ set_zero( hQMetaData->q_direction[0].band_data[b].elevation, MAX_PARAM_SPATIAL_SUBFRAMES );
}
}
- free( hDirAC->energy_ratio1 );
- hDirAC->energy_ratio1 = NULL;
- }
- if ( hDirAC->diffuseness_vector != NULL )
- {
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
+ *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT );
+ for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
+ {
+ hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0];
+ hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0];
+ hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0];
+ }
+ for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
{
- if ( hDirAC->diffuseness_vector[i] != NULL )
+ for ( j = orig_dirac_bands - 2; j >= 0; j-- )
{
- free( hDirAC->diffuseness_vector[i] );
- hDirAC->diffuseness_vector[i] = NULL;
+ hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0];
+ hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0];
+ hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0];
}
}
- free( hDirAC->diffuseness_vector );
- hDirAC->diffuseness_vector = NULL;
+ hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
}
-
- if ( hDirAC->spreadCoherence != NULL )
+ else
{
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
+ hQMetaData->sba_inactive_mode = 0;
+ hQMetaData->is_masa_ivas_format = 0;
+ if ( hQMetaData->useLowerRes )
{
- if ( hDirAC->spreadCoherence[i] != NULL )
- {
- free( hDirAC->spreadCoherence[i] );
- hDirAC->spreadCoherence[i] = NULL;
- }
+ hQMetaData->q_direction[0].cfg.nblocks = 1;
}
- free( hDirAC->spreadCoherence );
- hDirAC->spreadCoherence = NULL;
- }
-
- if ( hDirAC->surroundingCoherence != NULL )
- {
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
+ else
{
- if ( hDirAC->surroundingCoherence[i] != NULL )
- {
- free( hDirAC->surroundingCoherence[i] );
- hDirAC->surroundingCoherence[i] = NULL;
- }
+ hQMetaData->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES;
}
- free( hDirAC->surroundingCoherence );
- hDirAC->surroundingCoherence = NULL;
+
+ *nb_bits += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag );
}
+
+#ifdef DEBUGGING
+ assert( *nb_bits >= 0 );
+#endif
+
+ st->next_bit_pos = next_bit_pos_orig;
}
- else if ( params_flag == 2 )
+ else if ( !st->bfi && ivas_total_brate == IVAS_SID_5k2 )
{
- if ( hDirAC->azimuth2 != NULL )
- {
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
- {
- if ( hDirAC->azimuth2[i] != NULL )
- {
- free( hDirAC->azimuth2[i] );
- hDirAC->azimuth2[i] = NULL;
- }
- }
- free( hDirAC->azimuth2 );
- hDirAC->azimuth2 = NULL;
- }
+ next_bit_pos_orig = st->next_bit_pos;
+
+ /* subtract mode signaling bits, since bitstream was moved after mode reading */
+ st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS );
+#ifndef SBA_MODE_CLEANUP_2
+ /* 1 bit flag for SPAR/DirAC, already read in read format function */
+#else
+ /* 1 bit flag for signaling metadata to read */
+#endif
+ b = st->bit_stream[( st->next_bit_pos )--];
+ ( *nb_bits )++;
+ hQMetaData->sba_inactive_mode = 1;
+ orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
- if ( hDirAC->elevation2 != NULL )
+ /* if we start with a SID frame, we need to init the azi/ele arrays.*/
+ if ( st->ini_frame == 0 )
{
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
+ for ( dir = 0; dir < hQMetaData->no_directions; dir++ )
{
- if ( hDirAC->elevation2[i] != NULL )
+ for ( b = 0; b < hQMetaData->q_direction[dir].cfg.nbands; b++ )
{
- free( hDirAC->elevation2[i] );
- hDirAC->elevation2[i] = NULL;
+ set_zero( hQMetaData->q_direction[dir].band_data[b].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES );
+ set_zero( hQMetaData->q_direction[dir].band_data[b].elevation, MAX_PARAM_SPATIAL_SUBFRAMES );
}
}
- free( hDirAC->elevation2 );
- hDirAC->elevation2 = NULL;
}
- if ( hDirAC->energy_ratio2 != NULL )
+ *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT );
+ for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
{
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
- {
- if ( hDirAC->energy_ratio2[i] != NULL )
- {
- free( hDirAC->energy_ratio2[i] );
- hDirAC->energy_ratio2[i] = NULL;
- }
- }
- free( hDirAC->energy_ratio2 );
- hDirAC->energy_ratio2 = NULL;
+ hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0];
+ hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0];
+ hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0];
}
-
- if ( hDirAC->spreadCoherence2 != NULL )
+ for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
{
- for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
+ for ( j = orig_dirac_bands - 2; j >= 0; j-- )
{
- if ( hDirAC->spreadCoherence2[i] != NULL )
- {
- free( hDirAC->spreadCoherence2[i] );
- hDirAC->spreadCoherence2[i] = NULL;
- }
+ hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0];
+ hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0];
+ hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0];
}
- free( hDirAC->spreadCoherence2 );
- hDirAC->spreadCoherence2 = NULL;
}
+
+ hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
+
+ st->next_bit_pos = next_bit_pos_orig;
+ }
+
+ if ( hDirAC != NULL && hSpatParamRendCom != NULL )
+ {
+ ivas_qmetadata_to_dirac( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands );
}
return;
}
-/*-------------------------------------------------------------------------
- * ivas_dirac_alloc_mem()
+/*-----------------------------------------------------------------------*
+ * ivas_qmetadata_to_dirac()
*
- * Allocate stack memory for DirAC renderer
- *------------------------------------------------------------------------*/
+ * Copy qmetedata to DirAC parameters for rendering
+ *-----------------------------------------------------------------------*/
-static ivas_error ivas_dirac_alloc_mem(
- DIRAC_DEC_HANDLE hDirAC,
- const RENDERER_TYPE renderer_type,
- DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem,
- const int16_t hodirac_flag )
+void ivas_qmetadata_to_dirac(
+ const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */
+ DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */
+ MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ const int32_t ivas_total_brate, /* i : IVAS total bitrate */
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
+ int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */
+)
{
- int16_t num_freq_bands, num_freq_bands_diff, size;
- int16_t size_ho;
- int16_t size_pf;
- int16_t num_outputs_dir, num_outputs_diff;
- int16_t num_protos_dir;
-
- num_protos_dir = hDirAC->num_protos_dir;
-
- num_freq_bands = hDirAC->num_freq_bands;
- num_freq_bands_diff = hDirAC->h_output_synthesis_psd_params.max_band_decorr;
+ int16_t block, band;
+ int16_t *seed_ptr;
+ int16_t band_start, band_end, diff_idx;
+ float diffuseness;
+ int16_t b, ele, azi;
+ float azimuth, elevation;
+ IVAS_QDIRECTION *q_direction;
+ int16_t *band_mapping;
+ int16_t *band_grouping;
+ int16_t start_band;
+ int16_t nbands = 0;
+ int16_t nblocks = 0;
+ int16_t qBand_idx;
+ int16_t idx_sec = 0;
+ int16_t no_secs = 1;
- num_outputs_dir = hDirAC->num_outputs_dir;
- num_outputs_diff = hDirAC->num_outputs_diff;
+ q_direction = &( hQMetaData->q_direction[0] );
+ hSpatParamRendCom->numSimultaneousDirections = hQMetaData->no_directions;
- size = num_freq_bands * num_outputs_dir;
- if ( hodirac_flag )
+ if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 )
{
- size_ho = size * DIRAC_HO_NUMSECTORS;
- size_pf = num_freq_bands * DIRAC_HO_NUMSECTORS;
- }
- else
- {
- size_ho = size;
- size_pf = num_freq_bands;
- }
+ int16_t meta_write_index;
+ band_mapping = hMasa->data.band_mapping;
- /* PSD related buffers */
- hDirAC_mem->cy_auto_dir_smooth = NULL;
- hDirAC_mem->proto_power_smooth = NULL;
- hDirAC_mem->proto_power_diff_smooth = NULL;
- hDirAC_mem->direct_responses_square = NULL;
- hDirAC_mem->frame_dec_f = NULL;
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
- {
- if ( ( hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL )
+ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- set_zero( hDirAC_mem->cy_auto_dir_smooth, size );
+ meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length;
- if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- set_zero( hDirAC_mem->proto_power_smooth, size );
+ for ( band = 0; band < hMasa->config.numCodingBands; ++band )
+ {
+ for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
+ {
+ hSpatParamRendCom->azimuth[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block];
+ hSpatParamRendCom->elevation[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block];
+ hSpatParamRendCom->energy_ratio1[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block];
+ hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = 1.0f - q_direction->band_data[band].energy_ratio[block];
- if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- set_zero( hDirAC_mem->proto_power_diff_smooth, size );
+ if ( q_direction->coherence_band_data != NULL )
+ {
+ hSpatParamRendCom->spreadCoherence[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f;
+ }
+ else
+ {
+ hSpatParamRendCom->spreadCoherence[meta_write_index][b] = 0.0f;
+ }
- if ( ( hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ if ( hQMetaData->surcoh_band_data != NULL )
+ {
+ hSpatParamRendCom->surroundingCoherence[meta_write_index][b] = hQMetaData->surcoh_band_data[band].surround_coherence[block] / 255.0f;
+ }
+ else
+ {
+ hSpatParamRendCom->surroundingCoherence[meta_write_index][b] = 0.0f;
+ }
+ }
+ }
}
- set_zero( hDirAC_mem->direct_responses_square, size );
- if ( hDirAC->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) )
+
+ if ( hQMetaData->no_directions == 2 )
{
- if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL )
+ q_direction = &( hQMetaData->q_direction[1] );
+ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- }
- }
- hDirAC->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth;
- hDirAC->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth;
- hDirAC->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth;
- hDirAC->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square;
+ meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length;
- /* Target and smoothed nrg factors/gains */
- if ( ( hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- set_zero( hDirAC_mem->cy_cross_dir_smooth, size );
+ for ( band = 0; band < hMasa->config.numCodingBands; ++band )
+ {
+ for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
+ {
+ hSpatParamRendCom->azimuth2[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block];
+ hSpatParamRendCom->elevation2[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block];
+ hSpatParamRendCom->energy_ratio2[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block];
+ hSpatParamRendCom->diffuseness_vector[meta_write_index][b] -= q_direction->band_data[band].energy_ratio[block];
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
- {
- if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ if ( q_direction->coherence_band_data != NULL )
+ {
+ hSpatParamRendCom->spreadCoherence2[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f;
+ }
+ else
+ {
+ hSpatParamRendCom->spreadCoherence2[meta_write_index][b] = 0.0f;
+ }
+ }
+ }
+ }
}
- set_zero( hDirAC_mem->cy_auto_diff_smooth, size );
- }
- else
- {
- if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL )
+ else if ( hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2 != NULL && hSpatParamRendCom->spreadCoherence2 != NULL )
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ /* zero out old dir2 data */
+ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
+ {
+ meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length;
+ set_s( hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
+ set_s( hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
+ set_zero( hSpatParamRendCom->energy_ratio2[meta_write_index], hSpatParamRendCom->num_freq_bands );
+ set_zero( hSpatParamRendCom->spreadCoherence2[meta_write_index], hSpatParamRendCom->num_freq_bands );
+ }
}
- set_zero( hDirAC_mem->cy_auto_diff_smooth, num_outputs_diff * num_freq_bands_diff );
}
- hDirAC->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth;
- hDirAC->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth;
-
- /*Responses (gains/factors)*/
- if ( ( hDirAC_mem->direct_responses = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL )
+ else /* SBA mode/SID/Zero frame*/
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- set_zero( hDirAC_mem->direct_responses, size );
-
+ int16_t tmp_write_idx_param_band;
+ int16_t tmp_write_idx_band;
+ float diffuseness_sec = 0.f;
- hDirAC->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses;
+ /* ungroup */
+ seed_ptr = &hDirAC->dithering_seed;
+ nblocks = q_direction->cfg.nblocks;
+ nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands];
+ band_grouping = hDirAC->band_grouping;
- /* Prototypes */
- hDirAC_mem->proto_direct_buffer_f = NULL;
- hDirAC_mem->proto_diffuse_buffer_f = NULL;
- if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
- {
- if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL )
+ if ( ivas_total_brate <= IVAS_SID_5k2 && ivas_format != SBA_FORMAT )
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/
+ start_band = 0;
+ hDirAC->hConfig->nbands = 5;
+ ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL );
+ nbands = 5;
}
-
- if ( hDirAC->proto_signal_decorr_on )
+ else
{
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
+ start_band = hDirAC->hConfig->enc_param_start_band;
+ if ( ivas_format == SBA_FORMAT )
{
- if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
+ hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS;
}
else
{
- if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
+ hDirAC->hConfig->nbands = q_direction->cfg.nbands;
}
- }
- }
- hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f;
- hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f;
- /* Gains/power factors*/
- hDirAC_mem->direct_power_factor = NULL;
- hDirAC_mem->diffuse_power_factor = NULL;
+ ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hDirAC->hConfig->enc_param_start_band, hDirAC->hFbMdft );
- if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
- {
- if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ nbands = hDirAC->hConfig->nbands;
+ if ( hQMetaData->q_direction[0].cfg.nblocks == 0 )
+ {
+ /* No transmission -> no copy from qmetadata buffers*/
+ nbands = start_band;
+ }
}
- }
- hDirAC->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor;
- hDirAC->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor;
-
- hDirAC_mem->reference_power = NULL;
- hDirAC_mem->onset_filter = NULL;
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
- {
- if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
+ /* Low-Bands with no spatial data transmitted, analysis at decoder side */
+ for ( band = 0; band < start_band; band++ )
{
- if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- if ( hDirAC->proto_signal_decorr_on )
+ band_start = band_grouping[band];
+ band_end = band_grouping[band + 1];
+ tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
+
+ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
{
- if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL )
+ for ( b = band_start; b < band_end; b++ )
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ tmp_write_idx_band = tmp_write_idx_param_band;
+ hSpatParamRendCom->spreadCoherence[block][b] = 0.0f;
+ hSpatParamRendCom->surroundingCoherence[block][b] = 0.0f;
+
+ hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
+ hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
+ hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = 0.f;
+
+ hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f;
+ hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f;
+ hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0;
+ tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
}
}
}
- }
- else
- {
- if ( num_protos_dir > 2 )
+
+ /* Bands with spatial data transmitted */
+ if ( hodirac_flag )
{
- if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL )
- {
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
+ no_secs = DIRAC_HO_NUMSECTORS;
}
- if ( hDirAC->proto_signal_decorr_on )
+ for ( idx_sec = 0; idx_sec < no_secs; idx_sec++ )
{
- if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL )
+ for ( band = start_band; band < nbands; band++ )
{
- return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
- }
- }
- }
+ band_start = band_grouping[band];
+ band_end = band_grouping[band + 1];
+ tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
- return IVAS_ERR_OK;
-}
+ if ( ivas_format == SBA_FORMAT )
+ {
+ qBand_idx = dirac_to_spar_md_bands[band] - start_band;
+ }
+ else
+ {
+ qBand_idx = band;
+ }
+ diffuseness = 1.0f - q_direction->band_data[qBand_idx].energy_ratio[0];
+#ifdef DEBUG_MODE_DIRAC
+ dbgwrite( &diffuseness, sizeof( float ), 1, 1, "./res/dirac_dec_diffuseness.dat" );
+#endif
+ diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0];
+ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
+ {
+ int16_t block_qmetadata;
-static void ivas_dirac_free_mem(
- DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem )
-{
- if ( hDirAC_mem->cy_auto_dir_smooth != NULL )
- {
- free( hDirAC_mem->cy_auto_dir_smooth );
- }
- if ( hDirAC_mem->proto_power_smooth != NULL )
- {
- free( hDirAC_mem->proto_power_smooth );
- }
- if ( hDirAC_mem->proto_power_diff_smooth != NULL )
- {
- free( hDirAC_mem->proto_power_diff_smooth );
- }
- if ( hDirAC_mem->direct_responses_square != NULL )
- {
- free( hDirAC_mem->direct_responses_square );
- }
- if ( hDirAC_mem->frame_dec_f != NULL )
- {
- free( hDirAC_mem->frame_dec_f );
- }
- if ( hDirAC_mem->cy_cross_dir_smooth != NULL )
- {
- free( hDirAC_mem->cy_cross_dir_smooth );
- }
- if ( hDirAC_mem->cy_auto_diff_smooth != NULL )
- {
- free( hDirAC_mem->cy_auto_diff_smooth );
- }
- if ( hDirAC_mem->direct_responses != NULL )
- {
- free( hDirAC_mem->direct_responses );
- }
- if ( hDirAC_mem->proto_direct_buffer_f != NULL )
- {
- free( hDirAC_mem->proto_direct_buffer_f );
- }
- if ( hDirAC_mem->proto_diffuse_buffer_f != NULL )
- {
- free( hDirAC_mem->proto_diffuse_buffer_f );
- }
- if ( hDirAC_mem->direct_power_factor != NULL )
- {
- free( hDirAC_mem->direct_power_factor );
- }
- if ( hDirAC_mem->diffuse_power_factor != NULL )
- {
- free( hDirAC_mem->diffuse_power_factor );
- }
- if ( hDirAC_mem->reference_power != NULL )
- {
- free( hDirAC_mem->reference_power );
- }
- if ( hDirAC_mem->onset_filter != NULL )
- {
- free( hDirAC_mem->onset_filter );
- }
+ block_qmetadata = min( block, nblocks - 1 );
+ block_qmetadata = max( block_qmetadata, 0 );
- return;
-}
+ if ( q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] < 0.f )
+ {
+ q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] += 360.f;
+ }
+ if ( hMasa == NULL && hodirac_flag )
+ {
+ azimuth = q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata];
+ elevation = q_direction[idx_sec].band_data[qBand_idx].elevation[block_qmetadata];
+ diffuseness = 1.f - q_direction[0].band_data[qBand_idx].energy_ratio[block_qmetadata];
+ diffuseness_sec = q_direction[1].band_data[qBand_idx].energy_ratio[block_qmetadata];
+ assert( diffuseness_sec < 1.0001f && diffuseness_sec > -0.0001f );
+ }
+ else
+ {
+ azimuth = q_direction->band_data[qBand_idx].azimuth[block_qmetadata];
+ elevation = q_direction->band_data[qBand_idx].elevation[block_qmetadata];
+ }
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec_read_BS()
- *
- * Read DirAC parameters from the bitstream
- *------------------------------------------------------------------------*/
+ for ( b = band_start; b < band_end; b++ )
+ {
+ tmp_write_idx_band = tmp_write_idx_param_band;
-void ivas_dirac_dec_read_BS(
- const int32_t ivas_total_brate, /* i : IVAS total bitrate */
- Decoder_State *st, /* i/o: decoder state structure */
- DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */
- IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata */
- int16_t *nb_bits, /* o : number of bits read */
- const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
- int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */
-)
-{
- int16_t i, j, b, dir, orig_dirac_bands;
- int16_t next_bit_pos_orig;
- *nb_bits = 0;
- if ( !st->bfi && ivas_total_brate > IVAS_SID_5k2 )
- {
- next_bit_pos_orig = st->next_bit_pos;
- st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 );
+ if ( hodirac_flag )
+ {
+ azi = (int16_t) ( azimuth + 0.5f );
+ ele = (int16_t) ( elevation + 0.5f );
+ }
+ else
+ {
+ azi = (int16_t) ( azimuth + rand_triangular_signed( seed_ptr ) * dirac_dithering_azi_scale[diff_idx] + 0.5f );
+ ele = (int16_t) ( elevation + rand_triangular_signed( seed_ptr ) * dirac_dithering_ele_scale[diff_idx] + 0.5f );
+ /* limit the elevation to [-90, 90] */
+ ele = min( 90, ele );
+ ele = max( -90, ele );
+ }
- /* 1 bit flag for signaling metadata to read */
- b = st->bit_stream[( st->next_bit_pos )--];
- ( *nb_bits )++;
+ if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL )
+ {
+ hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = q_direction->coherence_band_data[qBand_idx].spread_coherence[block] / 255.0f;
+ }
+ else
+ {
+ hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f;
+ }
- if ( b == 1 ) /* WB 4TCs condition, no other metadata to read*/
- {
- orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
+ if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL )
+ {
+ hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0] / 255.0f;
+ }
+ else
+ {
+ hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f;
+ }
- hQMetaData->sba_inactive_mode = 1;
+ hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio[0];
- /* if we start with a SID frame, we need to init the azi/ele arrays.*/
- if ( st->ini_frame == 0 )
- {
- for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ )
- {
- set_zero( hQMetaData->q_direction[0].band_data[b].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES );
- set_zero( hQMetaData->q_direction[0].band_data[b].elevation, MAX_PARAM_SPATIAL_SUBFRAMES );
- }
- }
-
- *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT );
- for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
- {
- hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0];
- hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0];
- hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0];
- }
- for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
- {
- for ( j = orig_dirac_bands - 2; j >= 0; j-- )
- {
- hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0];
- hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0];
- hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0];
- }
- }
-
- hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
- }
- else
- {
- hQMetaData->sba_inactive_mode = 0;
- hQMetaData->is_masa_ivas_format = 0;
- if ( hQMetaData->useLowerRes )
- {
- hQMetaData->q_direction[0].cfg.nblocks = 1;
- }
- else
- {
- hQMetaData->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES;
- }
-
- *nb_bits += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag );
- }
-
-#ifdef DEBUGGING
- assert( *nb_bits >= 0 );
-#endif
-
- st->next_bit_pos = next_bit_pos_orig;
- }
- else if ( !st->bfi && ivas_total_brate == IVAS_SID_5k2 )
- {
- next_bit_pos_orig = st->next_bit_pos;
-
- /* subtract mode signaling bits, since bitstream was moved after mode reading */
- st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS );
-#ifndef SBA_MODE_CLEANUP_2
- /* 1 bit flag for SPAR/DirAC, already read in read format function */
-#else
- /* 1 bit flag for signaling metadata to read */
-#endif
- b = st->bit_stream[( st->next_bit_pos )--];
- ( *nb_bits )++;
- hQMetaData->sba_inactive_mode = 1;
- orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
-
- /* if we start with a SID frame, we need to init the azi/ele arrays.*/
- if ( st->ini_frame == 0 )
- {
- for ( dir = 0; dir < hQMetaData->no_directions; dir++ )
- {
- for ( b = 0; b < hQMetaData->q_direction[dir].cfg.nbands; b++ )
- {
- set_zero( hQMetaData->q_direction[dir].band_data[b].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES );
- set_zero( hQMetaData->q_direction[dir].band_data[b].elevation, MAX_PARAM_SPATIAL_SUBFRAMES );
- }
- }
- }
-
- *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT );
- for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
- {
- hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0];
- hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0];
- hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0];
- }
- for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
- {
- for ( j = orig_dirac_bands - 2; j >= 0; j-- )
- {
- hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0];
- hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0];
- hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0];
- }
- }
-
- hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
-
- st->next_bit_pos = next_bit_pos_orig;
- }
-
- if ( hDirAC != NULL )
- {
- ivas_qmetadata_to_dirac( hQMetaData, hDirAC, NULL, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands );
- }
-
- return;
-}
-
-
-/*-----------------------------------------------------------------------*
- * ivas_qmetadata_to_dirac()
- *
- * Copy qmetedata to DirAC parameters for rendering
- *-----------------------------------------------------------------------*/
-
-void ivas_qmetadata_to_dirac(
- const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */
- DIRAC_DEC_HANDLE hDirAC, /* o : DirAC decoder structure */
- MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
- const int32_t ivas_total_brate, /* i : IVAS total bitrate */
- const IVAS_FORMAT ivas_format, /* i : IVAS format */
- const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
- int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */
-)
-{
- int16_t block, band;
- int16_t *seed_ptr;
- int16_t band_start, band_end, diff_idx;
- float diffuseness;
- int16_t b, ele, azi;
- float azimuth, elevation;
- IVAS_QDIRECTION *q_direction;
- int16_t *band_mapping;
- int16_t *band_grouping;
- int16_t start_band;
- int16_t nbands = 0;
- int16_t nblocks = 0;
- int16_t qBand_idx;
- int16_t idx_sec = 0;
- int16_t no_secs = 1;
-
- q_direction = &( hQMetaData->q_direction[0] );
- hDirAC->numSimultaneousDirections = hQMetaData->no_directions;
-
- if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 )
- {
- int16_t meta_write_index;
- band_mapping = hMasa->data.band_mapping;
-
- for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
- {
- meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length;
-
- for ( band = 0; band < hMasa->config.numCodingBands; ++band )
- {
- for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
- {
- hDirAC->azimuth[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block];
- hDirAC->elevation[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block];
- hDirAC->energy_ratio1[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block];
- hDirAC->diffuseness_vector[meta_write_index][b] = 1.0f - q_direction->band_data[band].energy_ratio[block];
-
- if ( q_direction->coherence_band_data != NULL )
- {
- hDirAC->spreadCoherence[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f;
- }
- else
- {
- hDirAC->spreadCoherence[meta_write_index][b] = 0.0f;
- }
-
- if ( hQMetaData->surcoh_band_data != NULL )
- {
- hDirAC->surroundingCoherence[meta_write_index][b] = hQMetaData->surcoh_band_data[band].surround_coherence[block] / 255.0f;
- }
- else
- {
- hDirAC->surroundingCoherence[meta_write_index][b] = 0.0f;
- }
- }
- }
- }
-
- if ( hQMetaData->no_directions == 2 )
- {
- q_direction = &( hQMetaData->q_direction[1] );
- for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
- {
- meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length;
-
- for ( band = 0; band < hMasa->config.numCodingBands; ++band )
- {
- for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
- {
- hDirAC->azimuth2[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block];
- hDirAC->elevation2[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block];
- hDirAC->energy_ratio2[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block];
- hDirAC->diffuseness_vector[meta_write_index][b] -= q_direction->band_data[band].energy_ratio[block];
-
- if ( q_direction->coherence_band_data != NULL )
- {
- hDirAC->spreadCoherence2[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f;
- }
- else
- {
- hDirAC->spreadCoherence2[meta_write_index][b] = 0.0f;
- }
- }
- }
- }
- }
- else if ( hDirAC->azimuth2 != NULL && hDirAC->elevation2 != NULL && hDirAC->energy_ratio2 != NULL && hDirAC->spreadCoherence2 != NULL )
- {
- /* zero out old dir2 data */
- for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
- {
- meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length;
- set_s( hDirAC->azimuth2[meta_write_index], 0, hDirAC->num_freq_bands );
- set_s( hDirAC->elevation2[meta_write_index], 0, hDirAC->num_freq_bands );
- set_zero( hDirAC->energy_ratio2[meta_write_index], hDirAC->num_freq_bands );
- set_zero( hDirAC->spreadCoherence2[meta_write_index], hDirAC->num_freq_bands );
- }
- }
- }
- else /* SBA mode/SID/Zero frame*/
- {
- int16_t tmp_write_idx_param_band;
- int16_t tmp_write_idx_band;
- float diffuseness_sec = 0.f;
-
- /* ungroup */
- seed_ptr = &hDirAC->dithering_seed;
- nblocks = q_direction->cfg.nblocks;
- nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands];
- band_grouping = hDirAC->band_grouping;
-
- if ( ivas_total_brate <= IVAS_SID_5k2 && ivas_format != SBA_FORMAT )
- {
- /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/
- start_band = 0;
- hDirAC->hConfig->nbands = 5;
- ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL );
- nbands = 5;
- }
- else
- {
- start_band = hDirAC->hConfig->enc_param_start_band;
- if ( ivas_format == SBA_FORMAT )
- {
- hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS;
- }
- else
- {
- hDirAC->hConfig->nbands = q_direction->cfg.nbands;
- }
-
- ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hDirAC->hConfig->enc_param_start_band, hDirAC->hFbMdft );
-
- nbands = hDirAC->hConfig->nbands;
- if ( hQMetaData->q_direction[0].cfg.nblocks == 0 )
- {
- /* No transmission -> no copy from qmetadata buffers*/
- nbands = start_band;
- }
- }
-
- /* Low-Bands with no spatial data transmitted, analysis at decoder side */
- for ( band = 0; band < start_band; band++ )
- {
- band_start = band_grouping[band];
- band_end = band_grouping[band + 1];
- tmp_write_idx_param_band = hDirAC->dirac_bs_md_write_idx;
-
- for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
- {
- for ( b = band_start; b < band_end; b++ )
- {
- tmp_write_idx_band = tmp_write_idx_param_band;
- hDirAC->spreadCoherence[block][b] = 0.0f;
- hDirAC->surroundingCoherence[block][b] = 0.0f;
-
- hDirAC->elevation[tmp_write_idx_band][b] = 0;
- hDirAC->azimuth[tmp_write_idx_band][b] = 0;
- hDirAC->diffuseness_vector[tmp_write_idx_band][b] = 0.f;
-
- hDirAC->spreadCoherence[tmp_write_idx_band][b] = 0.0f;
- hDirAC->surroundingCoherence[tmp_write_idx_band][b] = 0.0f;
- hDirAC->energy_ratio1[tmp_write_idx_band][b] = 0;
- tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hDirAC->dirac_md_buffer_length;
- }
- }
- }
-
- /* Bands with spatial data transmitted */
- if ( hodirac_flag )
- {
- no_secs = DIRAC_HO_NUMSECTORS;
- }
-
- for ( idx_sec = 0; idx_sec < no_secs; idx_sec++ )
- {
- for ( band = start_band; band < nbands; band++ )
- {
- band_start = band_grouping[band];
- band_end = band_grouping[band + 1];
- tmp_write_idx_param_band = hDirAC->dirac_bs_md_write_idx;
-
- if ( ivas_format == SBA_FORMAT )
- {
- qBand_idx = dirac_to_spar_md_bands[band] - start_band;
- }
- else
- {
- qBand_idx = band;
- }
- diffuseness = 1.0f - q_direction->band_data[qBand_idx].energy_ratio[0];
-#ifdef DEBUG_MODE_DIRAC
- dbgwrite( &diffuseness, sizeof( float ), 1, 1, "./res/dirac_dec_diffuseness.dat" );
-#endif
- diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0];
-
- for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
- {
- int16_t block_qmetadata;
-
- block_qmetadata = min( block, nblocks - 1 );
- block_qmetadata = max( block_qmetadata, 0 );
-
- if ( q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] < 0.f )
- {
- q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] += 360.f;
- }
-
- if ( hMasa == NULL && hodirac_flag )
- {
- azimuth = q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata];
- elevation = q_direction[idx_sec].band_data[qBand_idx].elevation[block_qmetadata];
- diffuseness = 1.f - q_direction[0].band_data[qBand_idx].energy_ratio[block_qmetadata];
- diffuseness_sec = q_direction[1].band_data[qBand_idx].energy_ratio[block_qmetadata];
- assert( diffuseness_sec < 1.0001f && diffuseness_sec > -0.0001f );
- }
- else
- {
- azimuth = q_direction->band_data[qBand_idx].azimuth[block_qmetadata];
- elevation = q_direction->band_data[qBand_idx].elevation[block_qmetadata];
- }
-
- for ( b = band_start; b < band_end; b++ )
- {
- tmp_write_idx_band = tmp_write_idx_param_band;
-
- if ( hodirac_flag )
- {
- azi = (int16_t) ( azimuth + 0.5f );
- ele = (int16_t) ( elevation + 0.5f );
- }
- else
- {
- azi = (int16_t) ( azimuth + rand_triangular_signed( seed_ptr ) * dirac_dithering_azi_scale[diff_idx] + 0.5f );
- ele = (int16_t) ( elevation + rand_triangular_signed( seed_ptr ) * dirac_dithering_ele_scale[diff_idx] + 0.5f );
- /* limit the elevation to [-90, 90] */
- ele = min( 90, ele );
- ele = max( -90, ele );
- }
-
- if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL )
- {
- hDirAC->spreadCoherence[tmp_write_idx_band][b] = q_direction->coherence_band_data[qBand_idx].spread_coherence[block] / 255.0f;
- }
- else
- {
- hDirAC->spreadCoherence[tmp_write_idx_band][b] = 0.0f;
- }
-
- if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL )
- {
- hDirAC->surroundingCoherence[tmp_write_idx_band][b] = hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0] / 255.0f;
- }
- else
- {
- hDirAC->surroundingCoherence[tmp_write_idx_band][b] = 0.0f;
- }
-
- hDirAC->energy_ratio1[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio[0];
-
- hDirAC->diffuseness_vector[tmp_write_idx_band][b] = diffuseness;
-
- if ( hodirac_flag )
- {
- if ( idx_sec == 0 )
- {
- hDirAC->elevation[tmp_write_idx_band][b] = ele;
- hDirAC->azimuth[tmp_write_idx_band][b] = azi;
- hDirAC->energy_ratio1[tmp_write_idx_band][b] = 0.f; // not in use
- }
- else
- {
- assert( idx_sec == 1 );
- hDirAC->elevation2[tmp_write_idx_band][b] = ele;
- hDirAC->azimuth2[tmp_write_idx_band][b] = azi;
- hDirAC->energy_ratio2[tmp_write_idx_band][b] = 1.f - diffuseness_sec;
- }
- }
- else
- {
- hDirAC->elevation[tmp_write_idx_band][b] = ele;
- hDirAC->azimuth[tmp_write_idx_band][b] = azi;
- }
- }
- tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hDirAC->dirac_md_buffer_length;
-
- } /* for ( block =...) */
- } /* for ( band = ...) */
- } /* for ( idx_sec = ...)*/
-
- /* Bands not transmitted -> zeroed*/
- for ( b = band_grouping[band]; b < hDirAC->num_freq_bands; b++ )
- {
- tmp_write_idx_band = hDirAC->dirac_bs_md_write_idx;
-
- for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
- {
-
- hDirAC->spreadCoherence[block][b] = 0.0f;
- hDirAC->surroundingCoherence[block][b] = 0.0f;
- hDirAC->energy_ratio1[block][b] = 0;
-
- hDirAC->elevation[tmp_write_idx_band][b] = 0;
- hDirAC->azimuth[tmp_write_idx_band][b] = 0;
- hDirAC->diffuseness_vector[tmp_write_idx_band][b] = 0.f;
- hDirAC->spreadCoherence[tmp_write_idx_band][b] = 0.0f;
- hDirAC->surroundingCoherence[tmp_write_idx_band][b] = 0.0f;
- hDirAC->energy_ratio1[tmp_write_idx_band][b] = 0;
- tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hDirAC->dirac_md_buffer_length;
- }
- }
- }
-
- /* update buffer write index */
- hDirAC->dirac_bs_md_write_idx = ( hDirAC->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hDirAC->dirac_md_buffer_length;
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec_set_md_map()
- *
- * Set metadata index mapping for DirAC
- *------------------------------------------------------------------------*/
-
-void ivas_dirac_dec_set_md_map(
- Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
- const int16_t nCldfbTs /* i : number of CLDFB time slots */
-)
-{
- int16_t num_slots_in_subfr;
- DIRAC_DEC_HANDLE hDirAC;
-
- hDirAC = st_ivas->hDirAC;
-#ifdef DEBUGGING
- assert( hDirAC );
-#endif
-
- /* adapt subframes */
- hDirAC->num_slots = nCldfbTs;
- hDirAC->slots_rendered = 0;
- num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
- hDirAC->subframes_rendered = 0;
-
- ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hDirAC->subframe_nbslots, &hDirAC->nb_subframes );
-
- /* set mapping according to dirac_read_idx */
-
- set_s( hDirAC->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
-
-#ifdef FIX_470_MASA_JBM_EXT
- if ( st_ivas->ivas_format == MASA_FORMAT )
- {
- ivas_jbm_dec_get_md_map_even_spacing( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hDirAC->dirac_md_buffer_length, hDirAC->render_to_md_map );
- }
- else if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
-#else
- if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
-#endif
- {
- ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hDirAC->dirac_md_buffer_length, hDirAC->render_to_md_map );
- }
- else
- {
- ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hDirAC->dirac_read_idx, hDirAC->dirac_md_buffer_length, hDirAC->render_to_md_map );
- }
-
- if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
- {
- float tmp;
- int16_t sf_idx, slot_idx, slot_idx_abs;
-
- slot_idx_abs = 0;
- for ( sf_idx = 0; sf_idx < hDirAC->nb_subframes; sf_idx++ )
- {
- tmp = 0.0f;
- for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[sf_idx]; slot_idx++ )
- {
- tmp += (float) hDirAC->render_to_md_map[slot_idx_abs];
- slot_idx_abs++;
- }
- hDirAC->render_to_md_map[sf_idx] = ( (int16_t) roundf( tmp / (float) hDirAC->subframe_nbslots[sf_idx] ) + hDirAC->dirac_read_idx ) % hDirAC->dirac_md_buffer_length;
- }
-
- set_s( &hDirAC->render_to_md_map[hDirAC->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hDirAC->nb_subframes );
- }
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec()
- *
- * DirAC decoding process
- *------------------------------------------------------------------------*/
-
-void ivas_dirac_dec(
- Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
- float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */
- const int16_t nchan_transport /* i : number of transport channels */
-)
-{
- int16_t subframe_idx;
- float *output_f_local[MAX_OUTPUT_CHANNELS];
- float cng_td_buffer[L_FRAME16k];
- int16_t nchan_out, n, n_samples_sf;
- nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
-
- n_samples_sf = JBM_CLDFB_SLOTS_IN_SUBFRAME * st_ivas->hDirAC->slot_size;
-
- for ( n = 0; n < nchan_out; n++ )
- {
- output_f_local[n] = &output_f[n][0];
- }
-
- for ( n = 0; n < nchan_transport; n++ )
- {
- st_ivas->hTcBuffer->tc[n] = output_f[n];
- }
-
- if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT )
- {
- Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
- st_ivas->hTcBuffer->tc[nchan_transport] = &cng_td_buffer[0];
- generate_masking_noise_lb_dirac( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc[1], DEFAULT_JBM_CLDFB_TIMESLOTS, st->cna_dirac_flag && st->flag_cna );
- }
-
- ivas_dirac_dec_set_md_map( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS );
-
- for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ )
- {
- ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL );
- for ( n = 0; n < nchan_out; n++ )
- {
- output_f_local[n] += n_samples_sf;
- }
- }
-
- if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 )
- {
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % st_ivas->hDirAC->dirac_md_buffer_length;
- }
- else
- {
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length;
- }
-
- for ( n = 0; n < nchan_transport; n++ )
- {
- st_ivas->hTcBuffer->tc[n] = NULL;
- }
-
- if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT )
- {
- st_ivas->hTcBuffer->tc[nchan_transport] = NULL;
- }
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec_render()
- *
- * DirAC decoding renderer process
- *------------------------------------------------------------------------*/
-
-void ivas_dirac_dec_render(
- Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
- const int16_t nchan_transport, /* i : number of transport channels */
- const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
- uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
- uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
- float *output_f[] /* o : rendered time signal */
-)
-{
- int16_t slots_to_render, first_sf, last_sf, subframe_idx;
- uint16_t slot_size, n_samples_sf, ch, nchan_intern;
- DIRAC_DEC_HANDLE hDirAC;
- float *output_f_local[MAX_OUTPUT_CHANNELS];
-
- hDirAC = st_ivas->hDirAC;
-
- nchan_intern = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
-#ifdef DEBUGGING
- assert( hDirAC );
-#endif
- for ( ch = 0; ch < nchan_intern; ch++ )
- {
- output_f_local[ch] = output_f[ch];
- }
- slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
-
- /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
- slots_to_render = min( hDirAC->num_slots - hDirAC->slots_rendered, nSamplesAsked / slot_size );
- *nSamplesRendered = slots_to_render * slot_size;
- first_sf = hDirAC->subframes_rendered;
- last_sf = first_sf;
-
- while ( slots_to_render > 0 )
- {
- slots_to_render -= hDirAC->subframe_nbslots[last_sf];
- last_sf++;
- }
-
-#ifdef DEBUGGING
- assert( slots_to_render == 0 );
-#endif
- for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
- {
- ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL );
- n_samples_sf = hDirAC->subframe_nbslots[subframe_idx] * st_ivas->hDirAC->slot_size;
- for ( ch = 0; ch < nchan_intern; ch++ )
- {
- output_f_local[ch] += n_samples_sf;
- }
- }
-
- if ( hDirAC->slots_rendered == hDirAC->num_slots )
- {
- if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 )
- {
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % st_ivas->hDirAC->dirac_md_buffer_length;
- }
- else
- {
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length;
- }
- }
-
- *nSamplesAvailable = ( hDirAC->num_slots - hDirAC->slots_rendered ) * slot_size;
-
- return;
-}
-
-
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec()
- *
- * DirAC decoding process
- *------------------------------------------------------------------------*/
-
-void ivas_dirac_dec_render_sf(
- Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
- float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */
- const int16_t nchan_transport, /* i : number of transport channels */
- float *pppQMfFrame_ts_re[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX],
- float *pppQMfFrame_ts_im[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] )
-{
- int16_t i, ch, idx_in, idx_lfe;
- DIRAC_DEC_HANDLE hDirAC;
- float dirEne;
- float surCohEner;
- float surCohRatio[CLDFB_NO_CHANNELS_MAX];
- int16_t subframe_idx;
- int16_t slot_idx, index_slot;
- int16_t hodirac_flag;
- float *p_Rmat;
- int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
-
- /*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];
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- float Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
- float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
-#else
- float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
- float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
-#endif
-
- int16_t index, num_freq_bands;
-
- /* 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;
-
- push_wmops( "ivas_dirac_dec_render" );
-
- /* Initialize aux buffers */
- hDirAC = st_ivas->hDirAC;
-
- DirAC_mem = st_ivas->hDirAC->stack_mem;
-
- reference_power = DirAC_mem.reference_power;
- reference_power_smooth = DirAC_mem.reference_power + hDirAC->num_freq_bands;
- onset_filter = DirAC_mem.onset_filter;
-#ifdef FIX_614_ADD_TO_NULL_PTR_DIRAC_SETUP
- onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hDirAC->num_freq_bands;
-#else
- onset_filter_subframe = DirAC_mem.onset_filter + hDirAC->num_freq_bands;
-#endif
-
- hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
-
- if ( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT )
- {
- coherence_flag = st_ivas->hQMetaData->coherence_flag;
- }
- else
- {
- coherence_flag = 0;
- }
-
-#ifdef DEBUG_MODE_DIRAC
- {
- int16_t n, tmp[IVAS_SPAR_MAX_CH * L_FRAME48k];
- char file_name[50] = { 0 };
- const int16_t output_frame = st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC;
-
- for ( n = 0; n < nchan_transport; n++ )
- {
- for ( i = 0; i < output_frame; i++ )
- {
- tmp[nchan_transport * i + n] = (int16_t) ( output_f[n][i] + 0.5f );
- }
- }
- sprintf( file_name, "./res/ivas_dirac_dec_DMX%d.%d.pcm", nchan_transport, (int16_t) ( output_frame * 0.05 ) );
- dbgwrite( tmp, sizeof( int16_t ), nchan_transport * output_frame, 1, file_name );
- }
-#endif
-
- /* Subframe loop */
- slot_idx_start = hDirAC->slots_rendered;
- slot_idx_start_cldfb_synth = 0;
-
- subframe_idx = hDirAC->subframes_rendered;
- if ( hDirAC->hConfig->dec_param_estim == FALSE )
- {
- md_idx = hDirAC->render_to_md_map[subframe_idx];
- }
- else
- {
- md_idx = hDirAC->render_to_md_map[slot_idx_start];
- }
- /* ToDo: Another workaround for self test BE */
-
- /* copy parameters into local buffers*/
- if ( hDirAC->hConfig->dec_param_estim == FALSE )
- {
- mvs2s( hDirAC->azimuth[hDirAC->render_to_md_map[subframe_idx]], azimuth, hDirAC->num_freq_bands );
- mvs2s( hDirAC->elevation[hDirAC->render_to_md_map[subframe_idx]], elevation, hDirAC->num_freq_bands );
- mvr2r( hDirAC->diffuseness_vector[hDirAC->render_to_md_map[subframe_idx]], diffuseness_vector, hDirAC->num_freq_bands );
- }
- else
- {
- set_zero( diffuseness_vector, hDirAC->num_freq_bands );
- }
-
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
- {
- set_zero( reference_power_smooth, hDirAC->num_freq_bands );
- }
- else
- {
- set_zero( onset_filter_subframe, hDirAC->num_freq_bands );
- }
-
- if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] )
- {
- p_Rmat = &st_ivas->hCombinedOrientationData->Rmat[subframe_idx][0][0];
-
- if ( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
- {
- num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
- if ( hDirAC->hConfig->dec_param_estim == FALSE )
- {
- rotateAziEle_DirAC( azimuth, elevation, num_freq_bands, hDirAC->num_freq_bands, p_Rmat );
- }
- }
- }
- else
- {
- p_Rmat = 0;
- }
-
- if ( hDirAC->hConfig->dec_param_estim == FALSE )
- {
- /* compute response */
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
- {
- ivas_dirac_dec_compute_power_factors( hDirAC->num_freq_bands,
- diffuseness_vector,
- hDirAC->h_output_synthesis_psd_params.max_band_decorr,
- hDirAC->h_output_synthesis_psd_state.direct_power_factor,
- hDirAC->h_output_synthesis_psd_state.diffuse_power_factor );
-
- if ( coherence_flag )
- {
- for ( i = 0; i < hDirAC->num_freq_bands; i++ )
- {
- dirEne = hDirAC->h_output_synthesis_psd_state.direct_power_factor[i];
- surCohEner = hDirAC->h_output_synthesis_psd_state.diffuse_power_factor[i] * hDirAC->surroundingCoherence[md_idx][i];
- hDirAC->h_output_synthesis_psd_state.diffuse_power_factor[i] -= surCohEner;
- hDirAC->h_output_synthesis_psd_state.direct_power_factor[i] += surCohEner;
-
- surCohRatio[i] = surCohEner / ( 1e-12f + dirEne + surCohEner );
- }
- }
- else
- {
- set_zero( surCohRatio, hDirAC->num_freq_bands );
- }
- }
- else
- {
- ivas_dirac_dec_compute_gain_factors( hDirAC->num_freq_bands,
- hDirAC->diffuseness_vector[md_idx],
- hDirAC->h_output_synthesis_psd_params.max_band_decorr,
- hDirAC->h_output_synthesis_psd_state.direct_power_factor,
- hDirAC->h_output_synthesis_psd_state.diffuse_power_factor );
-
- if ( coherence_flag )
- {
- for ( i = 0; i < hDirAC->num_freq_bands; i++ )
- {
- surCohRatio[i] = hDirAC->surroundingCoherence[md_idx][i];
- }
- }
- else
- {
- set_zero( surCohRatio, hDirAC->num_freq_bands );
- }
- }
- if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 1 )
- {
- ivas_dirac_dec_compute_directional_responses( hDirAC,
- st_ivas->hVBAPdata,
- st_ivas->hMasa,
- azimuth,
- elevation,
- md_idx,
- surCohRatio,
- st_ivas->hCombinedOrientationData->shd_rot_max_order,
- p_Rmat,
- hodirac_flag );
- }
- else
- {
- ivas_dirac_dec_compute_directional_responses( hDirAC,
- st_ivas->hVBAPdata,
- st_ivas->hMasa,
- azimuth,
- elevation,
- md_idx,
- surCohRatio,
- 0,
- NULL,
- hodirac_flag );
- }
- }
-
- for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ )
- {
- index_slot = slot_idx_start + slot_idx;
- if ( hDirAC->hConfig->dec_param_estim == TRUE )
- {
- md_idx = hDirAC->render_to_md_map[index_slot];
- }
- else
- {
- md_idx = hDirAC->render_to_md_map[subframe_idx];
- }
-
- if ( st_ivas->ivas_format == SBA_FORMAT )
- {
- for ( ch = 0; ch < nchan_transport; ch++ )
- {
- mvr2r( pppQMfFrame_ts_re[ch][slot_idx], Cldfb_RealBuffer[ch][0], hDirAC->num_freq_bands );
- mvr2r( pppQMfFrame_ts_im[ch][slot_idx], Cldfb_ImagBuffer[ch][0], hDirAC->num_freq_bands );
- }
- }
- else
- {
- /* CLDFB Analysis*/
- for ( ch = 0; ch < nchan_transport; ch++ )
- {
- cldfbAnalysis_ts( &( st_ivas->hTcBuffer->tc[hDirAC->sba_map_tc[ch]][hDirAC->num_freq_bands * index_slot] ),
- Cldfb_RealBuffer[ch][0],
- Cldfb_ImagBuffer[ch][0],
- hDirAC->num_freq_bands,
- st_ivas->cldfbAnaDec[ch] );
- }
- }
-
- /* CNG in DirAC, extra CLDFB ana for CNA*/
- if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT )
- {
- Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
-
- generate_masking_noise_dirac( st->hFdCngDec->hFdCngCom,
- st_ivas->cldfbAnaDec[1],
- st_ivas->hTcBuffer->tc[1],
- Cldfb_RealBuffer[1][0],
- Cldfb_ImagBuffer[1][0],
- index_slot,
- st->cna_dirac_flag && st->flag_cna,
- ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->cng_type == FD_CNG && st->cng_sba_flag );
- }
-
- /* LFE synthesis */
- if ( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirAC->hOutSetup.separateChannelEnabled && !( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && hDirAC->hOutSetup.num_lfe == 0 ) )
- {
- ivas_lfe_synth_with_cldfb( st_ivas->hMasa->hMasaLfeSynth,
- Cldfb_RealBuffer, Cldfb_ImagBuffer,
- Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1],
- slot_idx,
- md_idx,
- nchan_transport );
- }
-
- /*-----------------------------------------------------------------*
- * protoype signal computation
- *-----------------------------------------------------------------*/
-
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
- {
- if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
- {
- protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer,
- hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f,
- hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f,
- reference_power, slot_idx, nchan_transport,
- hDirAC->num_outputs_diff,
- hDirAC->num_freq_bands,
- p_Rmat );
- }
- else
- {
- protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer,
- hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f,
- hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f,
- reference_power, slot_idx, nchan_transport,
- hDirAC->num_outputs_diff,
- hDirAC->num_freq_bands,
- 0 );
- }
- }
- else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
- {
- protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirAC->proto_frame_f,
- hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f,
- reference_power, hDirAC->h_output_synthesis_psd_state.proto_power_smooth,
- 0, slot_idx, hDirAC->num_freq_bands, hDirAC->masa_stereo_type_detect );
- }
- else
- {
- switch ( nchan_transport )
- {
- case 11:
- case 8:
- case 6:
- case 4:
- protoSignalComputation4( Cldfb_RealBuffer, Cldfb_ImagBuffer,
- hDirAC->proto_frame_f,
- hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f,
- reference_power,
- hDirAC->h_output_synthesis_psd_state.proto_power_smooth,
- slot_idx, hDirAC->num_outputs_diff,
- hDirAC->num_freq_bands,
- hDirAC->hoa_decoder,
- nchan_transport,
- hDirAC->sba_map_tc );
- break;
- case 2:
- protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer,
- hDirAC->proto_frame_f,
- hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f,
- reference_power,
- hDirAC->h_output_synthesis_psd_state.proto_power_smooth,
- hDirAC->hOutSetup.is_loudspeaker_setup,
- slot_idx,
- hDirAC->num_freq_bands,
- hDirAC->masa_stereo_type_detect );
- break;
- case 1:
- protoSignalComputation1( Cldfb_RealBuffer, Cldfb_ImagBuffer,
- hDirAC->proto_frame_f,
- hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f,
- reference_power,
- hDirAC->h_output_synthesis_psd_state.proto_power_smooth,
- slot_idx,
- hDirAC->num_protos_diff,
- hDirAC->num_freq_bands );
- break;
- default:
- return;
- }
- }
-
-
- /*-----------------------------------------------------------------*
- * Compute DirAC parameters at decoder side
- *-----------------------------------------------------------------*/
-
- if ( hDirAC->hConfig->dec_param_estim == TRUE )
- {
- mvs2s( &hDirAC->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], hDirAC->num_freq_bands - hDirAC->hConfig->enc_param_start_band );
- mvs2s( &hDirAC->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], hDirAC->num_freq_bands - hDirAC->hConfig->enc_param_start_band );
- if ( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
- {
- num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
- rotateAziEle_DirAC( azimuth, elevation, num_freq_bands, hDirAC->num_freq_bands, p_Rmat );
- }
-
- hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */
-
- index = hDirAC->index_buffer_intensity;
-
- num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
-
- computeIntensityVector_dec( Cldfb_RealBuffer,
- Cldfb_ImagBuffer,
- num_freq_bands,
- hDirAC->buffer_intensity_real[0][index - 1],
- hDirAC->buffer_intensity_real[1][index - 1],
- hDirAC->buffer_intensity_real[2][index - 1] );
-
- computeDirectionAngles( hDirAC->buffer_intensity_real[0][index - 1],
- hDirAC->buffer_intensity_real[1][index - 1],
- hDirAC->buffer_intensity_real[2][index - 1],
- num_freq_bands,
- azimuth,
- elevation );
-
- mvr2r( reference_power, &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands );
-
- computeDiffuseness( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->diffuseness_vector[md_idx] );
- }
-
-#ifdef DEBUG_MODE_DIRAC
- {
- static FILE *fp_direction_vector = NULL, *fp_diffuseness = NULL, *fp_referencePower = NULL;
-
-
- if ( fp_direction_vector == NULL )
- fp_direction_vector = fopen( "./res/dbg_direction_vector_C_dec.bin", "wb" );
- if ( fp_diffuseness == NULL )
- fp_diffuseness = fopen( "./res/dbg_diffuseness_C_dec.bin", "wb" );
- if ( fp_referencePower == NULL )
- fp_referencePower = fopen( "./res/dbg_reference_power_C_dec.bin", "wb" );
-
-
- for ( i = 0; i < hDirAC->num_freq_bands; i++ )
- {
- float radius_length;
- float dv[3];
-
- if ( hDirAC->hConfig->dec_param_estim == FALSE )
- {
- radius_length = cos( hDirAC->elevation[subframe_idx][i] * PI_OVER_180 );
- dv[0] = radius_length * cos( hDirAC->azimuth[subframe_idx][i] * PI_OVER_180 );
- dv[1] = radius_length * sin( hDirAC->azimuth[subframe_idx][i] * PI_OVER_180 );
- dv[2] = sin( hDirAC->elevation[subframe_idx][i] * PI_OVER_180 );
-
- fwrite( dv, sizeof( float ), 3, fp_direction_vector );
- fwrite( &( hDirAC->diffuseness_vector[0][i] ), sizeof( float ), 1, fp_diffuseness );
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
- {
- reference_power[i] = Cldfb_RealBuffer[0][0][i] * Cldfb_RealBuffer[0][0][i] + Cldfb_ImagBuffer[0][0][i] * Cldfb_ImagBuffer[0][0][i];
- }
- fwrite( &( reference_power[i] ), sizeof( float ), 1, fp_referencePower );
- }
- else
- {
- radius_length = cos( hDirAC->elevation[index_slot][i] * PI_OVER_180 );
- dv[0] = radius_length * cos( hDirAC->azimuth[index_slot][i] * PI_OVER_180 );
- dv[1] = radius_length * sin( hDirAC->azimuth[index_slot][i] * PI_OVER_180 );
- dv[2] = sin( hDirAC->elevation[index_slot][i] * PI_OVER_180 );
-
- fwrite( dv, sizeof( float ), 3, fp_direction_vector );
- fwrite( &( hDirAC->diffuseness_vector[index_slot][i] ), sizeof( float ), 1, fp_diffuseness );
- fwrite( &( reference_power[i] ), sizeof( float ), 1, fp_referencePower );
- }
- }
- }
-#endif
-
- /*-----------------------------------------------------------------*
- * frequency domain decorrelation
- *-----------------------------------------------------------------*/
-
- if ( hDirAC->proto_signal_decorr_on == 1 )
- {
- /* decorrelate prototype frame */
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
- {
- ivas_dirac_dec_decorr_process( hDirAC->num_freq_bands,
- hDirAC->num_outputs_diff,
- hDirAC->num_protos_diff,
- hDirAC->synthesisConf,
- nchan_transport,
- hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hDirAC->num_freq_bands * hDirAC->num_outputs_diff,
- hDirAC->num_protos_diff,
- hDirAC->proto_index_diff,
- hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hDirAC->num_freq_bands * hDirAC->num_outputs_diff + 2 * hDirAC->num_freq_bands * min( 4, nchan_transport ),
- onset_filter,
- hDirAC->h_freq_domain_decorr_ap_params,
- hDirAC->h_freq_domain_decorr_ap_state );
-
- v_multc( onset_filter, 0.25f, onset_filter, hDirAC->num_freq_bands );
- v_add( onset_filter, onset_filter_subframe, onset_filter_subframe, hDirAC->num_freq_bands );
- p_onset_filter = onset_filter_subframe;
- }
- else
- {
- ivas_dirac_dec_decorr_process( hDirAC->num_freq_bands,
- hDirAC->num_outputs_diff,
- hDirAC->num_protos_diff,
- hDirAC->synthesisConf,
- nchan_transport,
- hDirAC->proto_frame_f,
- hDirAC->num_protos_diff,
- hDirAC->proto_index_diff,
- DirAC_mem.frame_dec_f,
- onset_filter,
- hDirAC->h_freq_domain_decorr_ap_params,
- hDirAC->h_freq_domain_decorr_ap_state );
-
- hDirAC->proto_frame_dec_f = DirAC_mem.frame_dec_f;
- p_onset_filter = onset_filter;
- }
- }
- else
- {
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
- {
- set_f( onset_filter_subframe, 1.f, hDirAC->num_freq_bands );
- p_onset_filter = onset_filter_subframe;
- }
- else
- {
- /* no frequency domain decorrelation: use prototype frame */
- hDirAC->proto_frame_dec_f = hDirAC->proto_frame_f;
- p_onset_filter = NULL;
- }
- }
-
- /*-----------------------------------------------------------------*
- * output synthesis
- *-----------------------------------------------------------------*/
-
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
- {
- /*Compute diffuse prototypes*/
- ivas_dirac_dec_compute_diffuse_proto( hDirAC, slot_idx );
- }
-
- /*Compute PSDs*/
- if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order > 0 )
- {
- ivas_dirac_dec_output_synthesis_process_slot( reference_power,
- p_onset_filter,
- azimuth,
- elevation,
- hDirAC->diffuseness_vector[md_idx],
- hDirAC,
- st_ivas->hCombinedOrientationData->shd_rot_max_order,
- p_Rmat,
- st_ivas->hVBAPdata,
- hDirAC->hOutSetup,
- nchan_transport,
- md_idx,
- hodirac_flag );
- }
- else
- {
- ivas_dirac_dec_output_synthesis_process_slot( reference_power,
- p_onset_filter,
- azimuth,
- elevation,
- hDirAC->diffuseness_vector[md_idx],
- hDirAC,
- 0,
- 0,
- st_ivas->hVBAPdata,
- hDirAC->hOutSetup,
- nchan_transport,
- md_idx,
- hodirac_flag );
- }
-
- if ( hDirAC->hConfig->dec_param_estim )
- {
- float fac = 1.0f / (float) hDirAC->subframe_nbslots[subframe_idx];
- v_multc_acc( hDirAC->diffuseness_vector[md_idx], fac, diffuseness_vector, hDirAC->num_freq_bands );
- }
-
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
- {
- v_add( reference_power, reference_power_smooth, reference_power_smooth, hDirAC->num_freq_bands );
- }
- }
-
- ivas_dirac_dec_output_synthesis_get_interpolator( &hDirAC->h_output_synthesis_psd_params, hDirAC->subframe_nbslots[subframe_idx] );
-
-
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
- {
- ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( Cldfb_RealBuffer,
- Cldfb_ImagBuffer,
- hDirAC,
- nchan_transport,
- hDirAC->subframe_nbslots[subframe_idx],
- p_onset_filter,
- diffuseness_vector,
- hodirac_flag );
- }
- else
- {
- /* Determine encoding quality based additional smoothing factor */
- float qualityBasedSmFactor = 1.0f;
-
- if ( st_ivas->hMasa != NULL )
- {
- qualityBasedSmFactor = st_ivas->hMasa->data.dir_decode_quality;
- qualityBasedSmFactor *= qualityBasedSmFactor;
- }
-
-
- ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( Cldfb_RealBuffer,
- Cldfb_ImagBuffer,
- hDirAC,
- hDirAC->subframe_nbslots[subframe_idx],
- diffuseness_vector,
- reference_power_smooth,
- qualityBasedSmFactor );
- }
-
- /*-----------------------------------------------------------------*
- * CLDFB synthesis (and binaural rendering)
- *-----------------------------------------------------------------*/
-
- index_slot = slot_idx_start_cldfb_synth;
-
- if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
- {
- /* Perform binaural rendering */
- ivas_binRenderer( st_ivas->hBinRenderer,
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- &st_ivas->splitBinRend.splitrend.multiBinPoseData,
-#endif
- st_ivas->hCombinedOrientationData,
- subframe_idx,
- hDirAC->subframe_nbslots[subframe_idx],
- Cldfb_RealBuffer_Binaural,
- Cldfb_ImagBuffer_Binaural,
- Cldfb_RealBuffer,
- Cldfb_ImagBuffer );
+ hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness;
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- if ( ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ||
- ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
- {
- int16_t pos_idx;
-#ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG
- for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
-#else
- for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
-#endif
- {
- for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ )
- {
- for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
- {
- mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->splitBinRend.hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hDirAC->num_freq_bands );
- mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->splitBinRend.hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hDirAC->num_freq_bands );
+ if ( hodirac_flag )
+ {
+ if ( idx_sec == 0 )
+ {
+ hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
+ hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
+ hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0.f; // not in use
+ }
+ else
+ {
+ assert( idx_sec == 1 );
+ hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele;
+ hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi;
+ hSpatParamRendCom->energy_ratio2[tmp_write_idx_band][b] = 1.f - diffuseness_sec;
+ }
+ }
+ else
+ {
+ hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
+ hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
+ }
}
- }
- }
- }
-#endif
- /* Inverse CLDFB*/
- for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
- {
- /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
- float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
- float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
-
- for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ )
- {
-#ifdef SPLIT_REND_WITH_HEAD_ROT
- RealBuffer[i] = Cldfb_RealBuffer_Binaural[0][ch][i];
- ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[0][ch][i];
-#else
- RealBuffer[i] = Cldfb_RealBuffer_Binaural[ch][i];
- ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[ch][i];
-#endif
- }
-
- cldfbSynthesis( RealBuffer,
- ImagBuffer,
- &( output_f[ch][index_slot * hDirAC->num_freq_bands] ),
- hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx],
- st_ivas->cldfbSynDec[ch] );
- }
- }
- else if ( st_ivas->ivas_format == SBA_FORMAT )
- {
- for ( ch = 0; ch < hDirAC->hOutSetup.nchan_out_woLFE; ch++ )
- {
- for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ )
- {
- mvr2r( Cldfb_RealBuffer[ch][slot_idx], pppQMfFrame_ts_re[ch][slot_idx], hDirAC->num_freq_bands );
- mvr2r( Cldfb_ImagBuffer[ch][slot_idx], pppQMfFrame_ts_im[ch][slot_idx], hDirAC->num_freq_bands );
- }
- }
- }
- else
- {
- float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
- float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
- int16_t outchannels;
-
- idx_in = 0;
- idx_lfe = 0;
+ tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
- outchannels = hDirAC->hOutSetup.nchan_out_woLFE + hDirAC->hOutSetup.num_lfe;
- if ( hDirAC->hOutSetup.separateChannelEnabled && ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1 ||
- hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1 ||
- hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 ||
- hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_4 ||
- hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 ||
- ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
- {
- outchannels++;
- }
+ } /* for ( block =...) */
+ } /* for ( band = ...) */
+ } /* for ( idx_sec = ...)*/
- if ( hDirAC->hOutSetup.separateChannelEnabled && hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM )
+ /* Bands not transmitted -> zeroed*/
+ for ( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ )
{
- float tmp_separated[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
- float tmp_lfe[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
- const int16_t subframe_start_sample = index_slot * hDirAC->num_freq_bands;
- const int16_t num_samples_subframe = hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx];
-
- /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */
- mvr2r( &( output_f[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated, num_samples_subframe );
- mvr2r( &( output_f[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe, num_samples_subframe );
+ tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx;
- for ( ch = 0; ch < outchannels; ch++ )
+ for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
{
- if ( ( hDirAC->hOutSetup.num_lfe > 0 ) && ( hDirAC->hOutSetup.index_lfe[idx_lfe] == ch ) )
- {
- /* Move the LFE channel to the correct place */
- mvr2r( tmp_lfe, &( output_f[ch][subframe_start_sample] ), num_samples_subframe );
-
- if ( idx_lfe < ( hDirAC->hOutSetup.num_lfe - 1 ) )
- {
- idx_lfe++;
- }
- }
- else if ( ( st_ivas->hLsSetupCustom->separate_ch_found ) && ( hDirAC->hOutSetup.separateChannelIndex == ch ) )
- {
- /* Move the separated channel to the correct place. Thus, the separated channel is
- * combined with the synthesized channels here when there is a matching channel. */
- mvr2r( tmp_separated, &( output_f[ch][subframe_start_sample] ), num_samples_subframe );
- }
- else
- {
- /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
- for ( i = 0; i < hDirAC->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][subframe_start_sample] ), num_samples_subframe, st_ivas->cldfbSynDec[idx_in] );
-
- if ( !st_ivas->hLsSetupCustom->separate_ch_found )
- {
- /* Pan the separated channel and mix with the synthesized channels. Thus, the separated channel
- * is combined with the synthesized channels here when there is no matching channel. */
- v_multc_acc( tmp_separated, st_ivas->hLsSetupCustom->separate_ch_gains[idx_in], &( output_f[ch][subframe_start_sample] ), num_samples_subframe );
- }
- idx_in++;
- }
- }
- }
- else
- {
- for ( ch = 0; ch < outchannels; ch++ )
- {
- if ( ( hDirAC->hOutSetup.num_lfe > 0 ) && ( hDirAC->hOutSetup.index_lfe[idx_lfe] == ch ) )
- {
- if ( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirAC->hOutSetup.separateChannelEnabled )
- {
- for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ )
- {
- RealBuffer[i] = Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1][i];
- ImagBuffer[i] = Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1][i];
- }
- cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hDirAC->num_freq_bands] ), hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[hDirAC->hOutSetup.nchan_out_woLFE + idx_lfe] );
- }
- else if ( st_ivas->mc_mode == MC_MODE_MCMASA && hDirAC->hOutSetup.separateChannelEnabled )
- {
- /* LFE has been synthesized in the time domain, do nothing. */
- }
- else
- {
- set_zero( &( output_f[ch][index_slot * hDirAC->num_freq_bands] ), hDirAC->subframe_nbslots[subframe_idx] * hDirAC->num_freq_bands );
- }
+ hSpatParamRendCom->spreadCoherence[block][b] = 0.0f;
+ hSpatParamRendCom->surroundingCoherence[block][b] = 0.0f;
+ hSpatParamRendCom->energy_ratio1[block][b] = 0;
- if ( idx_lfe < ( hDirAC->hOutSetup.num_lfe - 1 ) )
- {
- idx_lfe++;
- }
- }
- else if ( ( hDirAC->hOutSetup.separateChannelEnabled ) && ( hDirAC->hOutSetup.separateChannelIndex == ch ) )
- {
- /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated
- * channel is combined with the synthesized channels here. */
- }
- else
- {
- /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
- for ( i = 0; i < hDirAC->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 * hDirAC->num_freq_bands] ), hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[idx_in] );
- idx_in++;
- }
+ hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
+ hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
+ hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = 0.f;
+ hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f;
+ hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f;
+ hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0;
+ tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
}
}
}
- hDirAC->slots_rendered += hDirAC->subframe_nbslots[subframe_idx];
- hDirAC->subframes_rendered++;
- pop_wmops();
+ /* update buffer write index */
+ hSpatParamRendCom->dirac_bs_md_write_idx = ( hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length;
return;
}
/*-------------------------------------------------------------------------
- * compute_hoa_encoder_mtx()
- *
+ * ivas_dirac_dec_set_md_map()
*
+ * Set metadata index mapping for DirAC
*------------------------------------------------------------------------*/
-void compute_hoa_encoder_mtx(
- const float *azimuth,
- const float *elevation,
- float *response,
- const int16_t num_responses,
- const int16_t ambisonics_order )
+void ivas_dirac_dec_set_md_map(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nCldfbTs /* i : number of CLDFB time slots */
+)
{
- int16_t k, num_sh;
+ int16_t num_slots_in_subfr;
+ DIRAC_DEC_HANDLE hDirAC;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
- num_sh = ivas_sba_get_nchan( ambisonics_order, 0 );
+ hDirAC = st_ivas->hDirAC;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+#ifdef DEBUGGING
+ assert( hDirAC );
+ assert( hSpatParamRendCom );
+#endif
- for ( k = 0; k < num_responses; k++ )
- {
- ivas_dirac_dec_get_response( (const int16_t) azimuth[k], (const int16_t) elevation[k], &response[k * num_sh], ambisonics_order );
- }
+ /* adapt subframes */
+ hSpatParamRendCom->num_slots = nCldfbTs;
+ hSpatParamRendCom->slots_rendered = 0;
+ num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
+ hSpatParamRendCom->subframes_rendered = 0;
- return;
-}
+ ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes );
+ /* set mapping according to dirac_read_idx */
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec_get_frequency_axis()
- *
- * DirAC decoding initialization
- *------------------------------------------------------------------------*/
+ set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
-void ivas_dirac_dec_get_frequency_axis(
- float *frequency_axis,
- const int32_t output_Fs,
- const int16_t num_freq_bands )
-{
- int16_t k;
- float const_part;
+#ifdef FIX_470_MASA_JBM_EXT
+ if ( st_ivas->ivas_format == MASA_FORMAT )
+ {
+ ivas_jbm_dec_get_md_map_even_spacing( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
+ }
+ else if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
+#else
+ if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
+#endif
+ {
+ ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
+ }
+ else
+ {
+ ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
+ }
- /* calc cldfb frequency axis */
- const_part = (float) output_Fs / ( 2.0f * (float) num_freq_bands );
- for ( k = 0; k < num_freq_bands; ++k )
+ if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
{
- frequency_axis[k] = ( (float) k + 0.5f ) * const_part;
+ float tmp;
+ int16_t sf_idx, slot_idx, slot_idx_abs;
+
+ slot_idx_abs = 0;
+ for ( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
+ {
+ tmp = 0.0f;
+ for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
+ {
+ tmp += (float) hSpatParamRendCom->render_to_md_map[slot_idx_abs];
+ slot_idx_abs++;
+ }
+ hSpatParamRendCom->render_to_md_map[sf_idx] = ( (int16_t) roundf( tmp / (float) hSpatParamRendCom->subframe_nbslots[sf_idx] ) + hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length;
+ }
+
+ set_s( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hSpatParamRendCom->nb_subframes );
}
return;
@@ -3183,1097 +1546,966 @@ void ivas_dirac_dec_get_frequency_axis(
/*-------------------------------------------------------------------------
- * Local functions
- *-------------------------------------------------------------------------*/
+ * ivas_dirac_dec()
+ *
+ * DirAC decoding process
+ *------------------------------------------------------------------------*/
-static void initDiffuseResponses(
- float *diffuse_response_function,
- const int16_t num_channels,
- AUDIO_CONFIG output_config,
- IVAS_OUTPUT_SETUP hOutSetup,
- const int16_t ambisonics_order,
- const IVAS_FORMAT ivas_format,
- int16_t *num_ele_spk_no_diffuse_rendering,
- AUDIO_CONFIG transport_config )
+void ivas_dirac_dec(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */
+ const int16_t nchan_transport /* i : number of transport channels */
+)
{
- int16_t i, l, k, idx, num_horizontal_speakers;
- *num_ele_spk_no_diffuse_rendering = 0;
+ int16_t subframe_idx;
+ float *output_f_local[MAX_OUTPUT_CHANNELS];
+ float cng_td_buffer[L_FRAME16k];
+ int16_t nchan_out, n, n_samples_sf;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
- if ( output_config == AUDIO_CONFIG_MONO )
- {
- diffuse_response_function[0] = 1.0f;
- diffuse_response_function[1] = inv_sqrt( 3.0f );
- }
- else if ( !( output_config == AUDIO_CONFIG_FOA || output_config == AUDIO_CONFIG_HOA2 || output_config == AUDIO_CONFIG_HOA3 ) )
- {
- /* set diffuse response function */
- if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_5_1_4 )
- {
- num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+ nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
- mvr2r( diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers );
- set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS );
- *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS;
- }
- else if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_7_1_4 )
- {
- num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS;
+ n_samples_sf = JBM_CLDFB_SLOTS_IN_SUBFRAME * hSpatParamRendCom->slot_size;
- set_f( diffuse_response_function, sqrtf( 1.f / ( (float) num_horizontal_speakers ) ), num_horizontal_speakers );
- set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS );
- *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS;
- }
- else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 )
- {
- mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels );
- }
- else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 )
- {
- mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels );
- }
- else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) )
- {
- mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels );
- }
- else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) )
- {
- if ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 )
- {
- /* Detect loudspeakers with elevation */
- for ( i = 0, num_horizontal_speakers = 0; i < num_channels; i++ )
- {
- if ( fabsf( hOutSetup.ls_elevation[i] ) <= 5.f )
- {
- num_horizontal_speakers++;
- diffuse_response_function[i] = 1.f;
- }
- else
- {
- *num_ele_spk_no_diffuse_rendering += 1;
- diffuse_response_function[i] = 0.f;
- }
- }
- /* Diffuse only to horizontal plane if enough loudspeakers */
- if ( num_horizontal_speakers > 2 )
- {
- for ( i = 0; i < num_channels; i++ )
- {
- diffuse_response_function[i] *= sqrtf( 1.f / (float) num_horizontal_speakers );
- }
- }
- else
- {
- *num_ele_spk_no_diffuse_rendering = 0;
- set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels );
- }
- }
- else
- {
- set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels );
- }
- }
- else
+ for ( n = 0; n < nchan_out; n++ )
+ {
+ output_f_local[n] = &output_f[n][0];
+ }
+
+ for ( n = 0; n < nchan_transport; n++ )
+ {
+ st_ivas->hTcBuffer->tc[n] = output_f[n];
+ }
+
+ if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT )
+ {
+ Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
+ st_ivas->hTcBuffer->tc[nchan_transport] = &cng_td_buffer[0];
+ generate_masking_noise_lb_dirac( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc[1], DEFAULT_JBM_CLDFB_TIMESLOTS, st->cna_dirac_flag && st->flag_cna );
+ }
+
+ ivas_dirac_dec_set_md_map( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS );
+
+ for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ )
+ {
+ ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL );
+ for ( n = 0; n < nchan_out; n++ )
{
- set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels );
+ output_f_local[n] += n_samples_sf;
}
}
+
+ if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 )
+ {
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length;
+ }
else
{
- idx = 0;
- for ( l = 0; l <= ambisonics_order; l++ )
- {
- for ( k = 0; k < ( 2 * l + 1 ); k++ )
- {
- diffuse_response_function[idx++] = inv_sqrt( 2.0f * l + 1.0f );
- }
- }
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length;
+ }
+
+ for ( n = 0; n < nchan_transport; n++ )
+ {
+ st_ivas->hTcBuffer->tc[n] = NULL;
+ }
+
+ if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT )
+ {
+ st_ivas->hTcBuffer->tc[nchan_transport] = NULL;
}
return;
}
-static void protoSignalComputation_shd(
- float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],
- float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],
- float *proto_direct_buffer_f,
- float *proto_diffuse_buffer_f,
- float *reference_power,
- const int16_t slot_index,
- const int16_t num_inputs,
- const int16_t num_outputs_diff,
- const int16_t num_freq_bands,
- float *p_Rmat )
-{
- int16_t l, k;
- float *p_proto_direct_buffer;
- float *p_proto_diffuse_buffer;
- int16_t Rmat_k[4];
- float W_real, W_imag;
- float Y_real, Y_imag;
- float *p_k[4];
+/*-------------------------------------------------------------------------
+ * ivas_dirac_dec_render()
+ *
+ * DirAC decoding renderer process
+ *------------------------------------------------------------------------*/
- k = 0; /* to avoid compilation warning */
+void ivas_dirac_dec_render(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
+ uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
+ uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
+ float *output_f[] /* o : rendered time signal */
+)
+{
+ int16_t slots_to_render, first_sf, last_sf, subframe_idx;
+ uint16_t slot_size, n_samples_sf, ch, nchan_intern;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
+ float *output_f_local[MAX_OUTPUT_CHANNELS];
- p_proto_direct_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_inputs;
- p_proto_diffuse_buffer = proto_diffuse_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
- if ( num_inputs == 1 )
+ nchan_intern = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
+#ifdef DEBUGGING
+ assert( hSpatParamRendCom );
+#endif
+ for ( ch = 0; ch < nchan_intern; ch++ )
{
- for ( l = 0; l < num_freq_bands; l++ )
- {
- p_proto_direct_buffer[2 * l] = RealBuffer[0][0][l];
- p_proto_direct_buffer[2 * l + 1] = ImagBuffer[0][0][l];
- }
+ output_f_local[ch] = output_f[ch];
}
- else if ( num_inputs == 2 )
- {
- if ( p_Rmat != 0 )
- {
- assert( num_inputs == 4 && "This code block should never be run with num_inputs != 4!" );
+ slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
- for ( l = 0; l < num_freq_bands; l++ )
- {
- W_real = RealBuffer[0][0][l] + RealBuffer[1][0][l];
- W_imag = ImagBuffer[0][0][l] + ImagBuffer[1][0][l];
+ /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
+ slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size );
+ *nSamplesRendered = slots_to_render * slot_size;
+ first_sf = hSpatParamRendCom->subframes_rendered;
+ last_sf = first_sf;
- Y_real = RealBuffer[0][0][l] - RealBuffer[1][0][l];
- Y_imag = ImagBuffer[0][0][l] - ImagBuffer[1][0][l];
+ while ( slots_to_render > 0 )
+ {
+ slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf];
+ last_sf++;
+ }
- p_proto_direct_buffer[2 * l] = W_real;
- p_proto_direct_buffer[2 * l + 1] = W_imag;
- p_proto_direct_buffer[2 * num_freq_bands + 2 * l] = p_Rmat[0] * Y_real;
- p_proto_direct_buffer[2 * num_freq_bands + 2 * l + 1] = p_Rmat[0] * Y_imag;
- }
- }
- else
+#ifdef DEBUGGING
+ assert( slots_to_render == 0 );
+#endif
+ for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
+ {
+ ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL );
+ n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size;
+ for ( ch = 0; ch < nchan_intern; ch++ )
{
- for ( l = 0; l < num_freq_bands; l++ )
- {
- W_real = RealBuffer[0][0][l] + RealBuffer[1][0][l];
- W_imag = ImagBuffer[0][0][l] + ImagBuffer[1][0][l];
-
- p_proto_direct_buffer[2 * l] = W_real;
- p_proto_direct_buffer[2 * l + 1] = W_imag;
- {
- p_proto_direct_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l];
- p_proto_direct_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l];
- }
- }
+ output_f_local[ch] += n_samples_sf;
}
}
- else if ( num_inputs >= 4 )
+
+ if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots )
{
- p_k[0] = p_proto_direct_buffer;
- p_k[1] = p_proto_direct_buffer + 2 * num_freq_bands;
- p_k[2] = p_proto_direct_buffer + 4 * num_freq_bands;
- p_k[3] = p_proto_direct_buffer + 6 * num_freq_bands;
- Rmat_k[0] = 0;
- Rmat_k[1] = 1;
- Rmat_k[2] = 2;
- Rmat_k[3] = 0;
-
- if ( p_Rmat != 0 )
+ if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 )
{
- assert( num_inputs == 4 && "This code block should never be run with num_inputs != 4!" );
-
- for ( l = 0; l < num_freq_bands; l++ )
- {
- *( p_k[0] ) = RealBuffer[0][0][l];
- reference_power[l + num_freq_bands] = *( p_k[0] ) * *( p_k[0] );
- p_k[0]++;
- *( p_k[0] ) = ImagBuffer[0][0][l];
- reference_power[l + num_freq_bands] += *( p_k[0] ) * *( p_k[0] );
- p_k[0]++;
- reference_power[l] = 0.5f * reference_power[l + num_freq_bands];
-
- for ( k = 1; k < 4; k++ )
- {
- *( p_k[k] ) = p_Rmat[3 * Rmat_k[k] + 1] * RealBuffer[1][0][l] + p_Rmat[3 * Rmat_k[k] + 2] * RealBuffer[2][0][l] + p_Rmat[3 * Rmat_k[k] + 0] * RealBuffer[3][0][l];
- reference_power[l + ( k + 1 ) * num_freq_bands] = *( p_k[k] ) * *( p_k[k] );
- p_k[k]++;
- *( p_k[k] ) = p_Rmat[3 * Rmat_k[k] + 1] * ImagBuffer[1][0][l] + p_Rmat[3 * Rmat_k[k] + 2] * ImagBuffer[2][0][l] + p_Rmat[3 * Rmat_k[k] + 0] * ImagBuffer[3][0][l];
- reference_power[l + ( k + 1 ) * num_freq_bands] += *( p_k[k] ) * *( p_k[k] );
- p_k[k]++;
- reference_power[l] += 0.5f * ( reference_power[l + ( k + 1 ) * num_freq_bands] );
- }
-
- for ( k = 1; k < 4; k++ )
- {
- RealBuffer[k][0][l] = p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l];
- ImagBuffer[k][0][l] = p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1];
- }
- }
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length;
}
else
{
- set_zero( reference_power, num_freq_bands );
- for ( k = 0; k < 4; k++ )
- {
- for ( l = 0; l < num_freq_bands; l++ )
- {
- p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l] = RealBuffer[k][0][l];
- p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1] = ImagBuffer[k][0][l];
- reference_power[l + ( k + 1 ) * num_freq_bands] = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l];
- reference_power[l] += 0.5f * ( reference_power[l + ( k + 1 ) * num_freq_bands] );
- }
- }
- }
-
- /* Additional transport channels = planar SBA components of degree higher than 1*/
- for ( ; k < num_inputs; k++ )
- {
- for ( l = 0; l < num_freq_bands; l++ )
- {
- p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l] = RealBuffer[k][0][l];
- p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1] = ImagBuffer[k][0][l];
- }
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length;
}
}
-
- /*Copy direct to diffuse proto*/
- mvr2r( p_proto_direct_buffer, p_proto_diffuse_buffer, 2 * num_freq_bands * min( num_outputs_diff, num_inputs ) );
-
- if ( num_inputs == 1 )
- {
- /* Add comfort noise addition (CNA) to diffuse proto only*/
- for ( l = 0; l < num_freq_bands; l++ )
- {
- p_proto_diffuse_buffer[2 * l] += RealBuffer[1][0][l];
- p_proto_diffuse_buffer[2 * l + 1] += ImagBuffer[1][0][l];
- }
- }
+ *nSamplesAvailable = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size;
return;
}
-static void protoSignalComputation1(
- 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 )
-{
- int16_t l, k;
- float *p_proto_buffer;
-
- p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands;
-
- for ( l = 0; l < num_freq_bands; l++ )
- {
- reference_power[l] = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
- proto_power_smooth[l] += reference_power[l];
- p_proto_buffer[2 * l] = RealBuffer[0][0][l];
- p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l];
+/*-------------------------------------------------------------------------
+ * ivas_dirac_dec()
+ *
+ * DirAC decoding process
+ *------------------------------------------------------------------------*/
- for ( k = 0; k < num_outputs_diff; k++ )
- {
- proto_frame_f[2 * k * num_freq_bands + 2 * l] = RealBuffer[0][0][l];
- proto_frame_f[2 * k * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l];
- }
- }
+void ivas_dirac_dec_render_sf(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ float *pppQMfFrame_ts_re[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX],
+ float *pppQMfFrame_ts_im[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] )
+{
+ int16_t i, ch, idx_in, idx_lfe;
+ DIRAC_DEC_HANDLE hDirAC;
+ 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 hodirac_flag;
+ float *p_Rmat;
+ int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
- return;
-}
+ /*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];
+#ifdef SPLIT_REND_WITH_HEAD_ROT
+ float Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
+ float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
+#else
+ float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
+ float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
+#endif
+ int16_t index, num_freq_bands;
-static void protoSignalComputation2(
- 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 isloudspeaker,
- const int16_t slot_index,
- const int16_t num_freq_bands,
- MASA_STEREO_TYPE_DETECT *stereo_type_detect )
-{
- int16_t l;
- float *p_proto_buffer;
- float Real_aux, Imag_aux;
+ /* 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];
- float left_bb_power, right_bb_power, total_bb_power, lr_bb_power;
- float lr_total_bb_ratio;
- float a, b;
+ 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;
- float left_hi_power, right_hi_power, total_hi_power, lr_hi_power;
- float lr_total_hi_ratio;
- float a2, b2;
+ push_wmops( "ivas_dirac_dec_render" );
- float sum_power;
- float sum_total_ratio[MASA_SUM_FREQ_RANGE_BINS];
- float min_sum_total_ratio;
- float min_sum_total_ratio_db;
+ /* Initialize aux buffers */
+ hDirAC = st_ivas->hDirAC;
+ hDirACRend = st_ivas->hDirACRend;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
- float RealSubtract, ImagSubtract;
+ DirAC_mem = hDirACRend->stack_mem;
- float interpolatorSpaced = 0.0f;
- float interpolatorDmx = 1.0f;
+ reference_power = DirAC_mem.reference_power;
+ reference_power_smooth = DirAC_mem.reference_power + hSpatParamRendCom->num_freq_bands;
+ onset_filter = DirAC_mem.onset_filter;
+#ifdef FIX_614_ADD_TO_NULL_PTR_DIRAC_SETUP
+ onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands;
+#else
+ onset_filter_subframe = DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands;
+#endif
- int16_t dipole_freq_range[2];
- float tempSpaced, tempDmx;
+ hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
- if ( isloudspeaker )
+ if ( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT )
{
- p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 3;
-
- for ( l = 0; l < num_freq_bands; l++ )
- {
- float Left_power;
- float Right_power;
- Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l];
- Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l];
-
- Left_power = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
- Right_power = RealBuffer[1][0][l] * RealBuffer[1][0][l] + ImagBuffer[1][0][l] * ImagBuffer[1][0][l];
-
- reference_power[l] = Left_power + Right_power;
- 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;
- proto_power_smooth[l + num_freq_bands] += RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
- p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l];
- p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l];
-
- proto_power_smooth[l + 2 * num_freq_bands] += RealBuffer[1][0][l] * RealBuffer[1][0][l];
- proto_power_smooth[l + 2 * num_freq_bands] += ImagBuffer[1][0][l] * ImagBuffer[1][0][l];
- p_proto_buffer[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l];
- p_proto_buffer[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];
- }
+ coherence_flag = st_ivas->hQMetaData->coherence_flag;
}
- else if ( stereo_type_detect != NULL )
+ else
{
- p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2;
-
- left_bb_power = 0.0f;
- right_bb_power = 0.0f;
- total_bb_power = 0.0f;
-
- left_hi_power = 0.0f;
- right_hi_power = 0.0f;
- total_hi_power = 0.0f;
-
- dipole_freq_range[0] = stereo_type_detect->dipole_freq_range[0];
- dipole_freq_range[1] = stereo_type_detect->dipole_freq_range[1];
+ coherence_flag = 0;
+ }
- a = 0.01f; /* Temporal smoothing coefficient */
- b = 1.0f - a; /* Temporal smoothing coefficient */
- a2 = 0.1f; /* Temporal smoothing coefficient */
- b2 = 1.0f - a2; /* Temporal smoothing coefficient */
+#ifdef DEBUG_MODE_DIRAC
+ {
+ int16_t n, tmp[IVAS_SPAR_MAX_CH * L_FRAME48k];
+ char file_name[50] = { 0 };
+ const int16_t output_frame = st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC;
- if ( stereo_type_detect->interpolator > 0 )
+ for ( n = 0; n < nchan_transport; n++ )
{
- if ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS )
- {
- interpolatorSpaced = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS );
- interpolatorDmx = 1.0f - interpolatorSpaced;
- }
- else
+ for ( i = 0; i < output_frame; i++ )
{
- interpolatorDmx = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS );
- interpolatorSpaced = 1.0f - interpolatorDmx;
+ tmp[nchan_transport * i + n] = (int16_t) ( output_f[n][i] + 0.5f );
}
}
+ sprintf( file_name, "./res/ivas_dirac_dec_DMX%d.%d.pcm", nchan_transport, (int16_t) ( output_frame * 0.05 ) );
+ dbgwrite( tmp, sizeof( int16_t ), nchan_transport * output_frame, 1, file_name );
+ }
+#endif
- for ( l = 0; l < num_freq_bands; l++ )
- {
- float Left_power;
- float Right_power;
-
- /* Compute sum signal */
- Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l];
- Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l];
-
- /* Compute reference power */
- Left_power = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
- Right_power = RealBuffer[1][0][l] * RealBuffer[1][0][l] + ImagBuffer[1][0][l] * ImagBuffer[1][0][l];
-
- reference_power[l] = Left_power + Right_power;
-
- left_bb_power += Left_power;
- right_bb_power += Right_power;
- total_bb_power += reference_power[l];
+ /* Subframe loop */
+ slot_idx_start = hSpatParamRendCom->slots_rendered;
+ slot_idx_start_cldfb_synth = 0;
- if ( l > MASA_HI_FREQ_START_BIN )
- {
- left_hi_power += Left_power;
- right_hi_power += Right_power;
- total_hi_power += reference_power[l];
- }
+ subframe_idx = hSpatParamRendCom->subframes_rendered;
+ if ( hDirAC->hConfig->dec_param_estim == FALSE )
+ {
+ md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
+ }
+ else
+ {
+ md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start];
+ }
+ /* ToDo: Another workaround for self test BE */
- if ( l < min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) )
- {
- sum_power = Real_aux * Real_aux + Imag_aux * Imag_aux;
+ /* copy parameters into local buffers*/
+ if ( hDirAC->hConfig->dec_param_estim == FALSE )
+ {
+ 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 );
+ }
+ else
+ {
+ set_zero( diffuseness_vector, hSpatParamRendCom->num_freq_bands );
+ }
- stereo_type_detect->sum_power[l] = a * sum_power + b * stereo_type_detect->sum_power[l];
- stereo_type_detect->total_power[l] = a * reference_power[l] + b * stereo_type_detect->total_power[l];
+ 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 );
+ }
- sum_total_ratio[l] = stereo_type_detect->sum_power[l] / ( stereo_type_detect->total_power[l] + EPSILON );
- }
+ if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] )
+ {
+ p_Rmat = &st_ivas->hCombinedOrientationData->Rmat[subframe_idx][0][0];
- if ( l == 0 )
+ if ( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
+ {
+ num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
+ if ( hDirAC->hConfig->dec_param_estim == FALSE )
{
- 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;
+ rotateAziEle_DirAC( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat );
}
+ }
+ }
+ else
+ {
+ p_Rmat = 0;
+ }
- /* Compute protos (and their power) for direct sound rendering */
-
- /* W prototype */
- if ( stereo_type_detect->interpolator > 0 )
- {
- 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->masa_stereo_type == MASA_STEREO_SPACED_MICS )
+ if ( hDirAC->hConfig->dec_param_estim == FALSE )
+ {
+ /* 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 ( coherence_flag )
{
- 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
+ for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
{
- proto_power_smooth[l] += RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
- p_proto_buffer[2 * l] = RealBuffer[0][0][l];
- p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l];
+ 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
{
- 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;
+ 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 );
- /* Y prototype */
- if ( stereo_type_detect->interpolator > 0 )
- {
- 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] );
- }
- 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 ( coherence_flag )
{
- 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 */
+ for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
{
- 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];
+ surCohRatio[i] = hSpatParamRendCom->surroundingCoherence[md_idx][i];
}
}
else
{
- 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];
+ set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands );
}
-
- /* 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 )
+ if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 1 )
{
- 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;
- }
+ ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom,
+ hDirACRend,
+ st_ivas->hVBAPdata,
+ st_ivas->hMasa,
+ azimuth,
+ elevation,
+ md_idx,
+ surCohRatio,
+ st_ivas->hCombinedOrientationData->shd_rot_max_order,
+ p_Rmat,
+ hodirac_flag );
}
-
- 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 ) );
-
- 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 ) );
-
- 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;
-
- 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++ )
+ else
{
- 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;
-
- 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 * 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];
+ ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom,
+ hDirACRend,
+ st_ivas->hVBAPdata,
+ st_ivas->hMasa,
+ azimuth,
+ elevation,
+ md_idx,
+ surCohRatio,
+ 0,
+ NULL,
+ hodirac_flag );
}
}
- return;
-}
-
-
-static 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 ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
{
- for ( l = 0; l < num_freq_bands; l++ )
+ index_slot = slot_idx_start + slot_idx;
+ if ( hDirAC->hConfig->dec_param_estim == TRUE )
{
- 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;
+ md_idx = hSpatParamRendCom->render_to_md_map[index_slot];
+ }
+ else
+ {
+ md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
}
- }
- /*For decorrelated diffuseness*/
- for ( l = 0; l < num_outputs_diff; l++ )
- {
- for ( k = 0; k < num_freq_bands; k++ )
+ if ( st_ivas->ivas_format == SBA_FORMAT )
{
- 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 ( ch = 0; ch < nchan_transport; ch++ )
{
- 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]];
+ mvr2r( pppQMfFrame_ts_re[ch][slot_idx], Cldfb_RealBuffer[ch][0], hSpatParamRendCom->num_freq_bands );
+ mvr2r( pppQMfFrame_ts_im[ch][slot_idx], Cldfb_ImagBuffer[ch][0], hSpatParamRendCom->num_freq_bands );
}
}
- }
-
- 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++ )
+ else
{
- 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];
+ /* CLDFB Analysis*/
+ for ( ch = 0; ch < nchan_transport; ch++ )
+ {
+ cldfbAnalysis_ts( &( st_ivas->hTcBuffer->tc[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ),
+ Cldfb_RealBuffer[ch][0],
+ Cldfb_ImagBuffer[ch][0],
+ hSpatParamRendCom->num_freq_bands,
+ st_ivas->cldfbAnaDec[ch] );
+ }
}
- }
- return;
-}
+ /* CNG in DirAC, extra CLDFB ana for CNA*/
+ if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT )
+ {
+ Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
+ generate_masking_noise_dirac( st->hFdCngDec->hFdCngCom,
+ st_ivas->cldfbAnaDec[1],
+ st_ivas->hTcBuffer->tc[1],
+ Cldfb_RealBuffer[1][0],
+ Cldfb_ImagBuffer[1][0],
+ index_slot,
+ st->cna_dirac_flag && st->flag_cna,
+ ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->cng_type == FD_CNG && st->cng_sba_flag );
+ }
-/*-------------------------------------------------------------------------
- * ivas_dirac_dec_compute_diffuse_proto()
- *
- * Compute diffuse prototype buffer and smooth power, only for decorrelated bands
- *------------------------------------------------------------------------*/
+ /* LFE synthesis */
+ if ( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirACRend->hOutSetup.separateChannelEnabled && !( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && hDirACRend->hOutSetup.num_lfe == 0 ) )
+ {
+ ivas_lfe_synth_with_cldfb( st_ivas->hMasa->hMasaLfeSynth,
+ Cldfb_RealBuffer, Cldfb_ImagBuffer,
+ Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1],
+ slot_idx,
+ md_idx,
+ nchan_transport );
+ }
-static void ivas_dirac_dec_compute_diffuse_proto(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const int16_t slot_idx /* i : slot index */
-)
-{
- int16_t k, l;
- int16_t num_freq_bands, 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 = hDirAC->proto_frame_dec_f;
- h_dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params );
- h_dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state );
-
- num_freq_bands = hDirAC->num_freq_bands;
- num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr;
-
- p_diff_buffer = h_dirac_output_synthesis_state->proto_diffuse_buffer_f + slot_idx * 2 * num_freq_bands_diff * hDirAC->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 ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD )
- {
- for ( k = 0; k < hDirAC->hOutSetup.nchan_out_woLFE; k++ )
+ /*-----------------------------------------------------------------*
+ * protoype signal computation
+ *-----------------------------------------------------------------*/
+
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- p_proto_diff = proto_frame_dec_f + k * 2 * num_freq_bands;
- for ( l = 0; l < num_freq_bands_diff; l++ )
+ if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
+ {
+ 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,
+ p_Rmat );
+ }
+ else
{
- *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;
+ 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
- {
- /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/
- for ( k = 0; k < hDirAC->hOutSetup.nchan_out_woLFE; k++ )
+ 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
{
- for ( l = 0; l < num_freq_bands_diff; l++ )
+ switch ( nchan_transport )
{
- p_hoa_enc = hDirAC->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 < hDirAC->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 += hDirAC->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;
+ case 11:
+ case 8:
+ case 6:
+ case 4:
+ protoSignalComputation4( 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_outputs_diff,
+ hSpatParamRendCom->num_freq_bands,
+ hDirACRend->hoa_decoder,
+ nchan_transport,
+ hDirACRend->sba_map_tc );
+ break;
+ 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;
}
}
- }
-
- return;
-}
-
-/*-------------------------------------------------------------------------
- * computeDirectionAngles()
- *
- *------------------------------------------------------------------------*/
-static 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;
+ /*-----------------------------------------------------------------*
+ * Compute DirAC parameters at decoder side
+ *-----------------------------------------------------------------*/
- for ( k = 0; k < num_frequency_bands; ++k )
+ if ( hDirAC->hConfig->dec_param_estim == TRUE )
+ {
+ mvs2s( &hSpatParamRendCom->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], hSpatParamRendCom->num_freq_bands - hDirAC->hConfig->enc_param_start_band );
+ mvs2s( &hSpatParamRendCom->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], hSpatParamRendCom->num_freq_bands - hDirAC->hConfig->enc_param_start_band );
+ if ( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
+ {
+ num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
+ rotateAziEle_DirAC( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat );
+ }
- {
- intensityNorm = *( intensity_real_x ) * *( intensity_real_x ) +
- *( intensity_real_y ) * *( intensity_real_y ) +
- *( intensity_real_z ) * *( intensity_real_z );
+ hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */
- 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 );
- }
+ index = hDirACRend->index_buffer_intensity;
- return;
-}
+ num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
+ computeIntensityVector_dec( Cldfb_RealBuffer,
+ Cldfb_ImagBuffer,
+ num_freq_bands,
+ hDirACRend->buffer_intensity_real[0][index - 1],
+ hDirACRend->buffer_intensity_real[1][index - 1],
+ hDirACRend->buffer_intensity_real[2][index - 1] );
-/*-------------------------------------------------------------------------
- * ivas_masa_init_stereotype_detection()
- *
- * Initialize stereo transport signal type detection
- *------------------------------------------------------------------------*/
+ computeDirectionAngles( hDirACRend->buffer_intensity_real[0][index - 1],
+ hDirACRend->buffer_intensity_real[1][index - 1],
+ hDirACRend->buffer_intensity_real[2][index - 1],
+ num_freq_bands,
+ azimuth,
+ elevation );
-static void ivas_masa_init_stereotype_detection(
- MASA_STEREO_TYPE_DETECT *stereo_type_detect )
-{
- 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;
+ mvr2r( reference_power, &( hDirACRend->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands );
- stereo_type_detect->counter = 0;
- stereo_type_detect->interpolator = 0;
+ computeDiffuseness( hDirACRend->buffer_intensity_real, hDirACRend->buffer_energy, num_freq_bands, hSpatParamRendCom->diffuseness_vector[md_idx] );
+ }
- stereo_type_detect->dipole_freq_range[0] = 1;
- stereo_type_detect->dipole_freq_range[1] = 3;
+#ifdef DEBUG_MODE_DIRAC
+ {
+ static FILE *fp_direction_vector = NULL, *fp_diffuseness = NULL, *fp_referencePower = NULL;
- 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;
+ if ( fp_direction_vector == NULL )
+ fp_direction_vector = fopen( "./res/dbg_direction_vector_C_dec.bin", "wb" );
+ if ( fp_diffuseness == NULL )
+ fp_diffuseness = fopen( "./res/dbg_diffuseness_C_dec.bin", "wb" );
+ if ( fp_referencePower == NULL )
+ fp_referencePower = fopen( "./res/dbg_reference_power_C_dec.bin", "wb" );
- 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;
+ for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
+ {
+ float radius_length;
+ float dv[3];
- 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;
+ if ( hDirAC->hConfig->dec_param_estim == FALSE )
+ {
+ radius_length = cos( hDirAC->elevation[subframe_idx][i] * PI_OVER_180 );
+ dv[0] = radius_length * cos( hDirAC->azimuth[subframe_idx][i] * PI_OVER_180 );
+ dv[1] = radius_length * sin( hDirAC->azimuth[subframe_idx][i] * PI_OVER_180 );
+ dv[2] = sin( hDirAC->elevation[subframe_idx][i] * PI_OVER_180 );
- return;
-}
+ fwrite( dv, sizeof( float ), 3, fp_direction_vector );
+ fwrite( &( hDirAC->diffuseness_vector[0][i] ), sizeof( float ), 1, fp_diffuseness );
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ {
+ reference_power[i] = Cldfb_RealBuffer[0][0][i] * Cldfb_RealBuffer[0][0][i] + Cldfb_ImagBuffer[0][0][i] * Cldfb_ImagBuffer[0][0][i];
+ }
+ fwrite( &( reference_power[i] ), sizeof( float ), 1, fp_referencePower );
+ }
+ else
+ {
+ radius_length = cos( hDirAC->elevation[index_slot][i] * PI_OVER_180 );
+ dv[0] = radius_length * cos( hDirAC->azimuth[index_slot][i] * PI_OVER_180 );
+ dv[1] = radius_length * sin( hDirAC->azimuth[index_slot][i] * PI_OVER_180 );
+ dv[2] = sin( hDirAC->elevation[index_slot][i] * PI_OVER_180 );
+ fwrite( dv, sizeof( float ), 3, fp_direction_vector );
+ fwrite( &( hDirAC->diffuseness_vector[index_slot][i] ), sizeof( float ), 1, fp_diffuseness );
+ fwrite( &( reference_power[i] ), sizeof( float ), 1, fp_referencePower );
+ }
+ }
+ }
+#endif
-/*-------------------------------------------------------------------------
- * ivas_masa_stereotype_detection()
- *
- * Detect the type of the transport audio signals
- *------------------------------------------------------------------------*/
+ /*-----------------------------------------------------------------*
+ * frequency domain decorrelation
+ *-----------------------------------------------------------------*/
-static 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;
-
- /* 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;
+ 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 );
- change_to_spaced = subtract_temp + min_sum_temp + lr_total_bb_temp;
+ 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 );
- if ( change_to_spaced >= 1.0f )
+ hDirACRend->proto_frame_dec_f = DirAC_mem.frame_dec_f;
+ p_onset_filter = onset_filter;
+ }
+ }
+ else
{
- change_to_spaced_selection = 1;
+ 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;
+ }
}
- }
-
- /* 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;
+ /*-----------------------------------------------------------------*
+ * output synthesis
+ *-----------------------------------------------------------------*/
- if ( change_to_downmix >= 1.0f )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
{
- change_to_downmix_selection = 1;
+ /*Compute diffuse prototypes*/
+ ivas_dirac_dec_compute_diffuse_proto( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx );
}
- }
-
- /* 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;
-
- if ( change_to_downmix2 >= 1.0f )
+ /*Compute PSDs*/
+ if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order > 0 )
{
- change_to_downmix_selection = 1;
+ ivas_dirac_dec_output_synthesis_process_slot( reference_power,
+ p_onset_filter,
+ azimuth,
+ elevation,
+ hSpatParamRendCom->diffuseness_vector[md_idx],
+ hSpatParamRendCom,
+ hDirACRend,
+ st_ivas->hCombinedOrientationData->shd_rot_max_order,
+ p_Rmat,
+ st_ivas->hVBAPdata,
+ hDirACRend->hOutSetup,
+ nchan_transport,
+ md_idx,
+ hodirac_flag,
+ hDirAC->hConfig->dec_param_estim );
}
- }
-
- if ( stereo_type_detect->counter < 400 )
- {
- stereo_type_detect->counter++;
- }
- else
- {
- if ( change_to_spaced_selection == 1 )
+ else
{
- stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS;
+ ivas_dirac_dec_output_synthesis_process_slot( reference_power,
+ p_onset_filter,
+ azimuth,
+ elevation,
+ hSpatParamRendCom->diffuseness_vector[md_idx],
+ hSpatParamRendCom,
+ hDirACRend,
+ 0,
+ 0,
+ st_ivas->hVBAPdata,
+ hDirACRend->hOutSetup,
+ nchan_transport,
+ md_idx,
+ hodirac_flag,
+ hDirAC->hConfig->dec_param_estim );
}
- else if ( change_to_downmix_selection == 1 )
+
+ if ( hDirAC->hConfig->dec_param_estim )
{
- stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX;
+ float fac = 1.0f / (float) hSpatParamRendCom->subframe_nbslots[subframe_idx];
+ v_multc_acc( hSpatParamRendCom->diffuseness_vector[md_idx], fac, diffuseness_vector, hSpatParamRendCom->num_freq_bands );
}
- }
- if ( stereo_type_detect->interpolator == 0 )
- {
- if ( stereo_type_detect->current_stereo_type != stereo_type_detect->masa_stereo_type )
+ if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
{
- stereo_type_detect->interpolator = 1;
- stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type;
+ v_add( reference_power, reference_power_smooth, reference_power_smooth, hSpatParamRendCom->num_freq_bands );
}
}
- return;
-}
+ ivas_dirac_dec_output_synthesis_get_interpolator( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
-/*-------------------------------------------------------------------------
- * computeIntensityVector_dec()
- *
- *
- *------------------------------------------------------------------------*/
-
-static 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 )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- 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;
+ 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,
+ hodirac_flag,
+ hDirAC->hConfig->dec_param_estim );
}
+ else
+ {
+ /* Determine encoding quality based additional smoothing factor */
+ float qualityBasedSmFactor = 1.0f;
- return;
-}
-
+ if ( st_ivas->hMasa != NULL )
+ {
+ qualityBasedSmFactor = st_ivas->hMasa->data.dir_decode_quality;
+ qualityBasedSmFactor *= qualityBasedSmFactor;
+ }
-/*-------------------------------------------------------------------------
- * ivas_lfe_synth_with_cldfb()
- *
- *
- *------------------------------------------------------------------------*/
-static 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 );
-
- 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];
+ 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,
+ qualityBasedSmFactor,
+ hDirAC->hConfig->enc_param_start_band );
}
- protoLfeEne = protoLfeReal * protoLfeReal + protoLfeImag * protoLfeImag;
- targetEneLfe = transportEne * hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index];
- targetEneTrans = transportEne * max( ( 1.0f - hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index] ), 0.01f );
+ /*-----------------------------------------------------------------*
+ * CLDFB synthesis (and binaural rendering)
+ *-----------------------------------------------------------------*/
- hMasaLfeSynth->transportEneSmooth *= MCMASA_LFE_SYNTH_ALPHA;
- hMasaLfeSynth->protoLfeEneSmooth *= MCMASA_LFE_SYNTH_ALPHA;
- hMasaLfeSynth->targetEneLfeSmooth *= MCMASA_LFE_SYNTH_ALPHA;
- hMasaLfeSynth->targetEneTransSmooth *= MCMASA_LFE_SYNTH_ALPHA;
+ index_slot = slot_idx_start_cldfb_synth;
- hMasaLfeSynth->transportEneSmooth += transportEne;
- hMasaLfeSynth->protoLfeEneSmooth += protoLfeEne;
- hMasaLfeSynth->targetEneLfeSmooth += targetEneLfe;
- hMasaLfeSynth->targetEneTransSmooth += targetEneTrans;
+ if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
+ {
+ /* Perform binaural rendering */
+ ivas_binRenderer( st_ivas->hBinRenderer,
+#ifdef SPLIT_REND_WITH_HEAD_ROT
+ &st_ivas->splitBinRend.splitrend.multiBinPoseData,
+#endif
+ st_ivas->hCombinedOrientationData,
+ subframe_idx,
+ hSpatParamRendCom->subframe_nbslots[subframe_idx],
+ Cldfb_RealBuffer_Binaural,
+ Cldfb_ImagBuffer_Binaural,
+ Cldfb_RealBuffer,
+ Cldfb_ImagBuffer );
- lfeGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneLfeSmooth / ( EPSILON + hMasaLfeSynth->protoLfeEneSmooth ) ) );
- transportGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneTransSmooth / ( EPSILON + hMasaLfeSynth->transportEneSmooth ) ) );
+#ifdef SPLIT_REND_WITH_HEAD_ROT
+ if ( ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ||
+ ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
+ {
+ int16_t pos_idx;
+#ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG
+ for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
+#else
+ for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
+#endif
+ {
+ for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
+ {
+ for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
+ {
+ mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->splitBinRend.hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hSpatParamRendCom->num_freq_bands );
+ mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->splitBinRend.hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hSpatParamRendCom->num_freq_bands );
+ }
+ }
+ }
+ }
+#endif
+ /* Inverse CLDFB*/
+ for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
+ {
+ /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
+ float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
+ float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
- RealBufferLfe[slot_index][0] = protoLfeReal * lfeGain;
- ImagBufferLfe[slot_index][0] = protoLfeImag * lfeGain;
+ for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
+ {
+#ifdef SPLIT_REND_WITH_HEAD_ROT
+ RealBuffer[i] = Cldfb_RealBuffer_Binaural[0][ch][i];
+ ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[0][ch][i];
+#else
+ RealBuffer[i] = Cldfb_RealBuffer_Binaural[ch][i];
+ ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[ch][i];
+#endif
+ }
- RealBuffer[0][0][0] *= transportGain;
- ImagBuffer[0][0][0] *= transportGain;
- for ( i = 1; i < nchan_transport; i++ )
+ cldfbSynthesis( RealBuffer,
+ ImagBuffer,
+ &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ),
+ hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx],
+ st_ivas->cldfbSynDec[ch] );
+ }
+ }
+ else if ( st_ivas->ivas_format == SBA_FORMAT )
{
- RealBuffer[i][0][0] *= transportGain;
- ImagBuffer[i][0][0] *= transportGain;
+ for ( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
+ {
+ for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
+ {
+ mvr2r( Cldfb_RealBuffer[ch][slot_idx], pppQMfFrame_ts_re[ch][slot_idx], hSpatParamRendCom->num_freq_bands );
+ mvr2r( Cldfb_ImagBuffer[ch][slot_idx], pppQMfFrame_ts_im[ch][slot_idx], hSpatParamRendCom->num_freq_bands );
+ }
+ }
}
+ else
+ {
+ float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
+ float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
+ int16_t outchannels;
- return;
-}
+ idx_in = 0;
+ idx_lfe = 0;
+ outchannels = hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe;
+ if ( hDirACRend->hOutSetup.separateChannelEnabled && ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1 ||
+ hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_7_1 ||
+ hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 ||
+ hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1_4 ||
+ hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 ||
+ ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
+ {
+ outchannels++;
+ }
-/*-------------------------------------------------------------------------
- * rotateAziEle_DirAC()
- *
- * Apply rotation to DirAC DOAs
- *------------------------------------------------------------------------*/
+ if ( hDirACRend->hOutSetup.separateChannelEnabled && hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM )
+ {
+ float tmp_separated[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
+ float tmp_lfe[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
+ const int16_t subframe_start_sample = index_slot * hSpatParamRendCom->num_freq_bands;
+ const int16_t num_samples_subframe = hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx];
-static 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;
+ /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */
+ mvr2r( &( output_f[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated, num_samples_subframe );
+ mvr2r( &( output_f[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe, num_samples_subframe );
- push_wmops( "rotateAziEle_DirAC" );
+ for ( ch = 0; ch < outchannels; ch++ )
+ {
+ if ( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( hDirACRend->hOutSetup.index_lfe[idx_lfe] == ch ) )
+ {
+ /* Move the LFE channel to the correct place */
+ mvr2r( tmp_lfe, &( output_f[ch][subframe_start_sample] ), num_samples_subframe );
- for ( b = band1; b < band2; b++ )
- {
+ if ( idx_lfe < ( hDirACRend->hOutSetup.num_lfe - 1 ) )
+ {
+ idx_lfe++;
+ }
+ }
+ else if ( ( st_ivas->hLsSetupCustom->separate_ch_found ) && ( hDirACRend->hOutSetup.separateChannelIndex == ch ) )
+ {
+ /* Move the separated channel to the correct place. Thus, the separated channel is
+ * combined with the synthesized channels here when there is a matching channel. */
+ mvr2r( tmp_separated, &( output_f[ch][subframe_start_sample] ), num_samples_subframe );
+ }
+ else
+ {
+ /* 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][subframe_start_sample] ), num_samples_subframe, st_ivas->cldfbSynDec[idx_in] );
- /*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 );
+ if ( !st_ivas->hLsSetupCustom->separate_ch_found )
+ {
+ /* Pan the separated channel and mix with the synthesized channels. Thus, the separated channel
+ * is combined with the synthesized channels here when there is no matching channel. */
+ v_multc_acc( tmp_separated, st_ivas->hLsSetupCustom->separate_ch_gains[idx_in], &( output_f[ch][subframe_start_sample] ), num_samples_subframe );
+ }
- 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;
+ idx_in++;
+ }
+ }
+ }
+ else
+ {
+ for ( ch = 0; ch < outchannels; ch++ )
+ {
+ if ( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( hDirACRend->hOutSetup.index_lfe[idx_lfe] == ch ) )
+ {
+ if ( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirACRend->hOutSetup.separateChannelEnabled )
+ {
+ for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
+ {
+ RealBuffer[i] = Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1][i];
+ ImagBuffer[i] = Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1][i];
+ }
+ cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[hDirACRend->hOutSetup.nchan_out_woLFE + idx_lfe] );
+ }
+ else if ( st_ivas->mc_mode == MC_MODE_MCMASA && hDirACRend->hOutSetup.separateChannelEnabled )
+ {
+ /* LFE has been synthesized in the time domain, do nothing. */
+ }
+ else
+ {
+ set_zero( &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands );
+ }
- /*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 );
+ if ( idx_lfe < ( hDirACRend->hOutSetup.num_lfe - 1 ) )
+ {
+ idx_lfe++;
+ }
+ }
+ else if ( ( hDirACRend->hOutSetup.separateChannelEnabled ) && ( hDirACRend->hOutSetup.separateChannelIndex == ch ) )
+ {
+ /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated
+ * channel is combined with the synthesized channels here. */
+ }
+ else
+ {
+ /* 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], st_ivas->cldfbSynDec[idx_in] );
+ idx_in++;
+ }
+ }
+ }
}
+ hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx];
+ hSpatParamRendCom->subframes_rendered++;
pop_wmops();
diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c
index ee15c79faa26dd36a659b945bcdae2ed26dd57b2..616069f25fbe1000500cd49ff6179189ab351bcd 100644
--- a/lib_dec/ivas_init_dec.c
+++ b/lib_dec/ivas_init_dec.c
@@ -894,77 +894,57 @@ ivas_error ivas_init_decoder(
st_ivas->hSCE[1]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed3 = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2;
}
}
- else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
+ else if ( st_ivas->ivas_format == SBA_FORMAT )
{
-
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
{
return error;
}
- if ( st_ivas->ivas_format == MASA_FORMAT )
+ if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK )
{
- if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK )
- {
- return error;
- }
+ return error;
}
- else if ( st_ivas->ivas_format == SBA_FORMAT )
+
+ if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup )
{
- if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK )
{
return error;
}
+ }
- if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup )
- {
- if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
+ if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
- if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) ) != IVAS_ERR_OK )
+ if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO )
+ {
+ if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
{
return error;
}
- if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO )
- {
- if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK )
- {
- return error;
- }
+ st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
+ }
+ else
+ {
+ int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1];
- st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
- }
- else
+ st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
+ if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) )
{
- int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1];
-
- st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
- if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) )
- {
- st_ivas->hSpar->enc_param_start_band = 0;
-
- set_c( (int8_t *) st_ivas->hQMetaData->twoDirBands, (int8_t) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands );
- st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
- }
+ st_ivas->hSpar->enc_param_start_band = 0;
- ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ),
- st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 );
+ set_c( (int8_t *) st_ivas->hQMetaData->twoDirBands, (int8_t) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands );
+ st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
}
- st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
- }
- if ( st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV && st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV_ROOM &&
- st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && st_ivas->ivas_format != SBA_FORMAT )
- {
- if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK )
- {
- return error;
- }
+ ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ),
+ st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 );
}
+ st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
{
@@ -1012,6 +992,52 @@ ivas_error ivas_init_decoder(
/* set CNA/CNG flags */
ivas_sba_set_cna_cng_flag( st_ivas );
}
+ else if ( st_ivas->ivas_format == MASA_FORMAT )
+ {
+ if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
+ {
+ if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
+ {
+ if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
+ }
+
+ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
+ {
+ if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
+ }
+ }
+
+ /* set CNA/CNG flags */
+ ivas_sba_set_cna_cng_flag( st_ivas );
+ }
else if ( st_ivas->ivas_format == MC_FORMAT )
{
if ( st_ivas->mc_mode == MC_MODE_MCT )
@@ -1146,7 +1172,7 @@ ivas_error ivas_init_decoder(
if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO )
{
- if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
{
return error;
}
@@ -1290,7 +1316,8 @@ ivas_error ivas_init_decoder(
}
#endif
}
- else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
+ /* ParamISM is handled separately from other common config */
+ else if ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) )
{
if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC )
{
@@ -1794,6 +1821,8 @@ void ivas_initialize_handles_dec(
ivas_init_split_rend_handles( &st_ivas->splitBinRend.splitrend );
#endif
st_ivas->hDiracDecBin = NULL;
+ st_ivas->hDirACRend = NULL;
+ st_ivas->hSpatParamRendCom = NULL;
st_ivas->hLsSetUpConversion = NULL;
st_ivas->hEFAPdata = NULL;
st_ivas->hVBAPdata = NULL;
@@ -1904,10 +1933,12 @@ void ivas_destroy_dec(
/* DirAC handle */
if ( st_ivas->ivas_format == ISM_FORMAT )
{
- ivas_param_ism_dec_close( &( st_ivas->hDirAC ), st_ivas->hDecoderConfig->output_config );
+ ivas_param_ism_dec_close( &( st_ivas->hDirAC ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config );
}
else
{
+ ivas_dirac_rend_close( &( st_ivas->hDirACRend ) );
+ ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) );
ivas_dirac_dec_close( &( st_ivas->hDirAC ) );
}
@@ -2111,7 +2142,7 @@ void ivas_init_dec_get_num_cldfb_instances(
{
*numCldfbAnalyses = st_ivas->nchan_transport + 1;
}
- else if ( st_ivas->nchan_transport == 1 && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ else if ( st_ivas->nchan_transport == 1 && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
*numCldfbAnalyses = st_ivas->nchan_transport + 1;
}
diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c
index feef519a954e12fa226c89fa2179a1bba23dfe1b..fa5783d90a3422400c0772e842ce90f1a63111f0 100644
--- a/lib_dec/ivas_ism_dec.c
+++ b/lib_dec/ivas_ism_dec.c
@@ -122,13 +122,13 @@ static ivas_error ivas_ism_bitrate_switching(
if ( st_ivas->hDecoderConfig->voip_active )
{
/* transfer subframe info from DirAC or ParamMC to central tc buffer */
- if ( last_ism_mode == ISM_MODE_PARAM && st_ivas->hDirAC != NULL && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) )
+ if ( last_ism_mode == ISM_MODE_PARAM && st_ivas->hSpatParamRendCom != NULL && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) )
{
- st_ivas->hTcBuffer->nb_subframes = st_ivas->hDirAC->nb_subframes;
- st_ivas->hTcBuffer->subframes_rendered = st_ivas->hDirAC->subframes_rendered;
- st_ivas->hTcBuffer->num_slots = st_ivas->hDirAC->num_slots;
- st_ivas->hTcBuffer->slots_rendered = st_ivas->hDirAC->slots_rendered;
- mvs2s( st_ivas->hDirAC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
+ st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes;
+ st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
+ st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots;
+ st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered;
+ mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
}
/* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv
@@ -169,7 +169,7 @@ static ivas_error ivas_ism_bitrate_switching(
if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM )
{
/* Deallocate the ParamISM struct */
- ivas_param_ism_dec_close( &( st_ivas->hDirAC ), st_ivas->hDecoderConfig->output_config );
+ ivas_param_ism_dec_close( &( st_ivas->hDirAC ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config );
#ifdef FIX_568_ISM_BITRATE_SWITCHING
if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
@@ -369,14 +369,14 @@ static ivas_error ivas_ism_bitrate_switching(
}
/* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */
- if ( st_ivas->hDirAC != NULL )
+ if ( st_ivas->hSpatParamRendCom != NULL )
{
- st_ivas->hDirAC->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
- st_ivas->hDirAC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
- st_ivas->hDirAC->num_slots = st_ivas->hTcBuffer->num_slots;
- st_ivas->hDirAC->slots_rendered = st_ivas->hTcBuffer->slots_rendered;
+ st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
+ st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
+ st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots;
+ st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered;
- mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hDirAC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
+ mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
}
}
diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c
index 2497f5ab988c4a042367ec78e5f33961254d897d..4662304a4afa0335e8f543ece5bbb5e1710a342b 100644
--- a/lib_dec/ivas_ism_param_dec.c
+++ b/lib_dec/ivas_ism_param_dec.c
@@ -287,6 +287,7 @@ static void ivas_param_ism_compute_mixing_matrix(
static void ivas_param_ism_render_slot(
DIRAC_DEC_HANDLE hDirAC,
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom,
float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX],
float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX],
float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
@@ -302,7 +303,7 @@ static void ivas_param_ism_render_slot(
tmp_1 = hDirAC->hParamIsmRendering->interpolator[interpolator_idx];
- for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ )
+ for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
{
/* smooth the mixing matrix */
for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
@@ -324,6 +325,7 @@ static void ivas_param_ism_render_slot(
static void ivas_param_ism_rendering(
DIRAC_DEC_HANDLE hDirAC,
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom,
float Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
float Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][4][CLDFB_NO_CHANNELS_MAX],
@@ -339,7 +341,7 @@ static void ivas_param_ism_rendering(
tmp_1 = hDirAC->hParamIsmRendering->interpolator[slot_idx];
- for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ )
+ for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
{
/* smooth the mixing matrix */
for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
@@ -440,6 +442,7 @@ ivas_error ivas_param_ism_dec_open(
int16_t i;
DIRAC_DEC_HANDLE hDirAC;
IVAS_OUTPUT_SETUP hOutSetup;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
AUDIO_CONFIG output_config;
int32_t output_Fs;
ivas_error error;
@@ -457,6 +460,11 @@ ivas_error ivas_param_ism_dec_open(
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
}
+ if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
/* Assign memory to Param Object handle */
if ( ( hDirAC->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL )
{
@@ -477,15 +485,15 @@ ivas_error ivas_param_ism_dec_open(
* set input parameters
*-----------------------------------------------------------------*/
- hDirAC->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
+ hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
hDirAC->hConfig = NULL;
- set_s( hDirAC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
- set_s( hDirAC->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
- hDirAC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
- hDirAC->subframes_rendered = 0;
- hDirAC->slots_rendered = 0;
- hDirAC->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
- hDirAC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
+ set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
+ set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
+ hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
+ hSpatParamRendCom->subframes_rendered = 0;
+ hSpatParamRendCom->slots_rendered = 0;
+ hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
+ hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
hDirAC->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
@@ -493,9 +501,9 @@ ivas_error ivas_param_ism_dec_open(
{
hDirAC->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i];
- if ( hDirAC->hParamIsm->band_grouping[i] > hDirAC->num_freq_bands )
+ if ( hDirAC->hParamIsm->band_grouping[i] > hSpatParamRendCom->num_freq_bands )
{
- hDirAC->hParamIsm->band_grouping[i] = hDirAC->num_freq_bands;
+ hDirAC->hParamIsm->band_grouping[i] = hSpatParamRendCom->num_freq_bands;
}
}
@@ -546,19 +554,19 @@ ivas_error ivas_param_ism_dec_open(
set_zero( hDirAC->azimuth_values, MAX_NUM_OBJECTS );
set_zero( hDirAC->elevation_values, MAX_NUM_OBJECTS );
- hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
- hDirAC->dirac_bs_md_write_idx = 0;
- hDirAC->dirac_read_idx = 0;
+ hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
+ hSpatParamRendCom->dirac_bs_md_write_idx = 0;
+ hSpatParamRendCom->dirac_read_idx = 0;
hDirAC->spar_to_dirac_write_idx = 0;
if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
{
- if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 1 ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK )
{
return error;
}
- if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK )
{
return error;
}
@@ -567,6 +575,7 @@ ivas_error ivas_param_ism_dec_open(
st_ivas->hISMDTX.dtx_flag = 0;
st_ivas->hDirAC = hDirAC;
+ st_ivas->hSpatParamRendCom = hSpatParamRendCom;
if ( st_ivas->hDecoderConfig->voip_active )
{
@@ -582,17 +591,17 @@ ivas_error ivas_param_ism_dec_open(
}
else
{
- if ( ( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
+ if ( ( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) );
}
- set_zero( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc, MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hDirAC->num_freq_bands );
+ set_zero( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc, MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hSpatParamRendCom->num_freq_bands );
- if ( ( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
+ if ( ( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) );
}
- set_zero( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc, MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hDirAC->num_freq_bands );
+ set_zero( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc, MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hSpatParamRendCom->num_freq_bands );
}
if ( st_ivas->hTcBuffer == NULL )
{
@@ -634,66 +643,70 @@ ivas_error ivas_param_ism_dec_open(
*-------------------------------------------------------------------------*/
void ivas_param_ism_dec_close(
- DIRAC_DEC_HANDLE *hDirAC_out, /* i/o: decoder DirAC handle */
- AUDIO_CONFIG output_config /* i : output audio configuration */
+ DIRAC_DEC_HANDLE *hDirAC_out, /* i/o: decoder DirAC handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */
+ AUDIO_CONFIG output_config /* i : output audio configuration */
)
{
- DIRAC_DEC_HANDLE hDirAC;
-
- if ( hDirAC_out == NULL || *hDirAC_out == NULL )
+ if ( hDirAC_out != NULL && *hDirAC_out != NULL )
{
- return;
- }
-
- hDirAC = *hDirAC_out;
+ DIRAC_DEC_HANDLE hDirAC;
+ hDirAC = *hDirAC_out;
- /* Config & CLDFB */
- if ( hDirAC->hParamIsm != NULL )
- {
- free( hDirAC->hParamIsm );
- hDirAC->hParamIsm = NULL;
- }
+ /* Config & CLDFB */
+ if ( hDirAC->hParamIsm != NULL )
+ {
+ free( hDirAC->hParamIsm );
+ hDirAC->hParamIsm = NULL;
+ }
- if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
- {
- ivas_dirac_deallocate_parameters( hDirAC, 1 );
- ivas_dirac_deallocate_parameters( hDirAC, 2 );
- }
+ if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) )
+ {
+ /* Param ISM Rendering */
+ if ( hDirAC->hParamIsmRendering->interpolator != NULL )
+ {
+ free( hDirAC->hParamIsmRendering->interpolator );
+ hDirAC->hParamIsmRendering->interpolator = NULL;
+ }
+ if ( hDirAC->hParamIsmRendering->proto_matrix != NULL )
+ {
+ free( hDirAC->hParamIsmRendering->proto_matrix );
+ hDirAC->hParamIsmRendering->proto_matrix = NULL;
+ }
+ }
- if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) )
- {
- /* Param ISM Rendering */
- if ( hDirAC->hParamIsmRendering->interpolator != NULL )
+ if ( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL )
{
- free( hDirAC->hParamIsmRendering->interpolator );
- hDirAC->hParamIsmRendering->interpolator = NULL;
+ free( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc );
+ hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
}
- if ( hDirAC->hParamIsmRendering->proto_matrix != NULL )
+ if ( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL )
{
- free( hDirAC->hParamIsmRendering->proto_matrix );
- hDirAC->hParamIsmRendering->proto_matrix = NULL;
+ free( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc );
+ hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
}
- }
- if ( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL )
- {
- free( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc );
- hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
- }
- if ( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL )
- {
- free( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc );
- hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
+ if ( hDirAC->hParamIsmRendering != NULL )
+ {
+ free( hDirAC->hParamIsmRendering );
+ hDirAC->hParamIsmRendering = NULL;
+ }
+
+ free( *hDirAC_out );
+ *hDirAC_out = NULL;
}
- if ( hDirAC->hParamIsmRendering != NULL )
+ if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL )
{
- free( hDirAC->hParamIsmRendering );
- hDirAC->hParamIsmRendering = NULL;
- }
+ if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
+ {
+ ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 );
+ ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 );
+ }
- free( *hDirAC_out );
- *hDirAC_out = NULL;
+ free( *hSpatParamRendCom_out );
+ *hSpatParamRendCom_out = NULL;
+ }
return;
}
@@ -735,12 +748,15 @@ void ivas_param_ism_dec(
float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX];
DIRAC_DEC_HANDLE hDirAC;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
IVAS_OUTPUT_SETUP hSetup;
/* Initialization */
hDirAC = st_ivas->hDirAC;
assert( hDirAC );
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+ assert( hSpatParamRendCom );
#ifdef FIX_549_DMX_GAIN
ene_tc = 0.0f;
ene_sum = 0.0f;
@@ -873,14 +889,14 @@ void ivas_param_ism_dec(
*-----------------------------------------------------------------*/
for ( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ )
{
- cldfbAnalysis_ts( &( output_f[ch][hDirAC->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], hDirAC->num_freq_bands, st_ivas->cldfbAnaDec[ch] );
+ cldfbAnalysis_ts( &( output_f[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch] );
ivas_param_ism_collect_slot( hDirAC, Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], ch, ref_power, cx_diag );
}
}
/* Obtain Mixing Matrix on a frame-level */
- for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ )
+ for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
{
set_f( mixing_matrix[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE );
}
@@ -888,28 +904,28 @@ void ivas_param_ism_dec(
/* Compute mixing matrix */
ivas_param_ism_compute_mixing_matrix( st_ivas->nchan_ism, hDirAC, st_ivas->hISMDTX, direct_response, nchan_transport, nchan_out_woLFE, cx_diag, ref_power, mixing_matrix );
/* subframe loop for synthesis*/
- for ( subframe_idx = 0; subframe_idx < hDirAC->nb_subframes; subframe_idx++ )
+ for ( subframe_idx = 0; subframe_idx < hSpatParamRendCom->nb_subframes; subframe_idx++ )
{
- uint16_t slot_idx_start = subframe_idx * hDirAC->subframe_nbslots[subframe_idx];
+ uint16_t slot_idx_start = subframe_idx * hSpatParamRendCom->subframe_nbslots[subframe_idx];
uint16_t idx_in;
uint16_t idx_lfe;
/* Set some memories to zero */
for ( ch = 0; ch < nchan_out_woLFE; ch++ )
{
- for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ )
+ for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
{
- set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hDirAC->num_freq_bands );
- set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hDirAC->num_freq_bands );
+ set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
+ set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
}
}
- for ( slot_idx = 0; slot_idx < hDirAC->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;
/* Compute bandwise rendering to target LS using covariance rendering */
- ivas_param_ism_rendering( hDirAC, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in,
+ ivas_param_ism_rendering( hDirAC, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in,
Cldfb_RealBuffer, Cldfb_ImagBuffer, mixing_matrix, slot_idx, index_slot,
nchan_out_woLFE, nchan_transport );
}
@@ -922,7 +938,7 @@ void ivas_param_ism_dec(
{
if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) )
{
- set_zero( &( output_f[ch][slot_idx_start * hDirAC->num_freq_bands] ), hDirAC->subframe_nbslots[subframe_idx] * hDirAC->num_freq_bands );
+ set_zero( &( output_f[ch][slot_idx_start * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands );
if ( idx_lfe < ( hSetup.num_lfe - 1 ) )
{
idx_lfe++;
@@ -934,14 +950,14 @@ void ivas_param_ism_dec(
float *ImagBuffer[16];
/* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
- for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ )
+ 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][slot_idx_start * hDirAC->num_freq_bands] ),
- hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] );
+ cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][slot_idx_start * hSpatParamRendCom->num_freq_bands] ),
+ hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] );
idx_in++;
}
@@ -1091,10 +1107,13 @@ void ivas_param_ism_dec_digest_tc(
/* Direct Response/EFAP Gains */
float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
DIRAC_DEC_HANDLE hDirAC;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
/* Initialization */
hDirAC = st_ivas->hDirAC;
assert( hDirAC );
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+ assert( hSpatParamRendCom );
#ifdef FIX_549_DMX_GAIN
ene_tc = 0.0f;
ene_sum = 0.0f;
@@ -1233,16 +1252,16 @@ void ivas_param_ism_dec_digest_tc(
float RealBuffer[CLDFB_NO_CHANNELS_MAX];
float ImagBuffer[CLDFB_NO_CHANNELS_MAX];
- cldfbAnalysis_ts( &( transport_channels_f[ch][hDirAC->num_freq_bands * slot_idx] ), RealBuffer, ImagBuffer, hDirAC->num_freq_bands, st_ivas->cldfbAnaDec[ch] );
- mvr2r( RealBuffer, &hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hDirAC->num_freq_bands * nchan_transport + ch * hDirAC->num_freq_bands], hDirAC->num_freq_bands );
- mvr2r( ImagBuffer, &hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hDirAC->num_freq_bands * nchan_transport + ch * hDirAC->num_freq_bands], hDirAC->num_freq_bands );
+ cldfbAnalysis_ts( &( transport_channels_f[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), RealBuffer, ImagBuffer, hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch] );
+ mvr2r( RealBuffer, &hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands );
+ mvr2r( ImagBuffer, &hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands );
ivas_param_ism_collect_slot( hDirAC, RealBuffer, ImagBuffer, ch, ref_power, cx_diag );
}
}
/* Obtain Mixing Matrix on a frame-level */
- for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ )
+ for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
{
set_f( hDirAC->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE );
}
@@ -1278,6 +1297,7 @@ static void ivas_ism_param_dec_render_sf(
float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX];
float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX];
DIRAC_DEC_HANDLE hDirAC;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
int16_t slot_idx_start;
int16_t idx_in;
@@ -1285,31 +1305,32 @@ static void ivas_ism_param_dec_render_sf(
int16_t subframe_idx;
hDirAC = st_ivas->hDirAC;
- slot_idx_start = hDirAC->slots_rendered;
- subframe_idx = hDirAC->subframes_rendered;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+ slot_idx_start = hSpatParamRendCom->slots_rendered;
+ subframe_idx = hSpatParamRendCom->subframes_rendered;
/* Set some memories to zero */
for ( ch = 0; ch < nchan_out_woLFE; ch++ )
{
- for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ )
+ for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
{
- set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hDirAC->num_freq_bands );
- set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hDirAC->num_freq_bands );
+ set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
+ set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
}
}
- for ( slot_idx = 0; slot_idx < hDirAC->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;
for ( ch = 0; ch < nchan_transport; ch++ )
{
- Cldfb_RealBuffer_in[ch] = &hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hDirAC->num_freq_bands * nchan_transport + ch * hDirAC->num_freq_bands];
- Cldfb_ImagBuffer_in[ch] = &hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc[index_slot * hDirAC->num_freq_bands * nchan_transport + ch * hDirAC->num_freq_bands];
+ Cldfb_RealBuffer_in[ch] = &hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
+ Cldfb_ImagBuffer_in[ch] = &hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
}
/* Compute bandwise rendering to target LS using covariance rendering */
- ivas_param_ism_render_slot( hDirAC, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in,
+ ivas_param_ism_render_slot( hDirAC, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in,
Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirAC->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx,
nchan_out_woLFE, nchan_transport );
}
@@ -1322,7 +1343,7 @@ static void ivas_ism_param_dec_render_sf(
{
if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) )
{
- set_zero( output_f[ch], hDirAC->subframe_nbslots[subframe_idx] * hDirAC->num_freq_bands );
+ set_zero( output_f[ch], hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands );
if ( idx_lfe < ( hSetup.num_lfe - 1 ) )
{
idx_lfe++;
@@ -1334,19 +1355,19 @@ static void ivas_ism_param_dec_render_sf(
float *ImagBuffer[16];
/* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
- for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ )
+ 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],
- hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] );
+ hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] );
idx_in++;
}
}
- hDirAC->slots_rendered += hDirAC->subframe_nbslots[subframe_idx];
- hDirAC->subframes_rendered++;
+ hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx];
+ hSpatParamRendCom->subframes_rendered++;
return;
}
@@ -1369,14 +1390,17 @@ void ivas_param_ism_dec_render(
int16_t ch, slots_to_render, first_sf, last_sf, subframe_idx;
uint16_t slot_size, n_samples_sf;
DIRAC_DEC_HANDLE hDirAC;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
IVAS_OUTPUT_SETUP hSetup;
int16_t nchan_transport, nchan_out, nchan_out_woLFE;
float *output_f_local[MAX_OUTPUT_CHANNELS];
hDirAC = st_ivas->hDirAC;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
hSetup = st_ivas->hIntSetup;
#ifdef DEBUGGING
assert( hDirAC );
+ assert( hSpatParamRendCom );
#endif
nchan_transport = st_ivas->nchan_transport;
if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL )
@@ -1393,14 +1417,14 @@ void ivas_param_ism_dec_render(
slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
/* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
- slots_to_render = min( hDirAC->num_slots - hDirAC->slots_rendered, nSamplesAsked / slot_size );
+ slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size );
*nSamplesRendered = slots_to_render * slot_size;
- first_sf = hDirAC->subframes_rendered;
+ first_sf = hSpatParamRendCom->subframes_rendered;
last_sf = first_sf;
while ( slots_to_render > 0 )
{
- slots_to_render -= hDirAC->subframe_nbslots[last_sf];
+ slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf];
last_sf++;
}
#ifdef DEBUGGING
@@ -1415,14 +1439,14 @@ void ivas_param_ism_dec_render(
for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
{
ivas_ism_param_dec_render_sf( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local );
- n_samples_sf = hDirAC->subframe_nbslots[subframe_idx] * st_ivas->hDirAC->slot_size;
+ n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size;
for ( ch = 0; ch < nchan_out; ch++ )
{
output_f_local[ch] += n_samples_sf;
}
}
- if ( hDirAC->slots_rendered == hDirAC->num_slots )
+ if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots )
{
/* copy the memories */
/* store mixing matrix for next subframe */
@@ -1444,7 +1468,7 @@ void ivas_param_ism_dec_render(
}
}
- *nSamplesAvailable = ( hDirAC->num_slots - hDirAC->slots_rendered ) * slot_size;
+ *nSamplesAvailable = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size;
return;
}
@@ -1461,6 +1485,7 @@ void ivas_param_ism_params_to_masa_param_mapping(
)
{
DIRAC_DEC_HANDLE hDirAC;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
int16_t nBins;
int16_t band_idx, bin_idx, sf_idx;
int16_t brange[2];
@@ -1470,7 +1495,8 @@ void ivas_param_ism_params_to_masa_param_mapping(
int32_t ivas_total_brate;
hDirAC = st_ivas->hDirAC;
- nBins = hDirAC->num_freq_bands;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+ nBins = hSpatParamRendCom->num_freq_bands;
ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
@@ -1492,7 +1518,7 @@ void ivas_param_ism_params_to_masa_param_mapping(
float energy_ratio;
energy_ratio = powf( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence, 2.0f );
- hDirAC->numSimultaneousDirections = 1;
+ hSpatParamRendCom->numSimultaneousDirections = 1;
azimuth[0] = (int16_t) roundf( hDirAC->azimuth_values[0] );
elevation[0] = (int16_t) roundf( hDirAC->elevation_values[0] );
@@ -1500,19 +1526,19 @@ void ivas_param_ism_params_to_masa_param_mapping(
{
for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
{
- hDirAC->azimuth[sf_idx][bin_idx] = azimuth[0];
- hDirAC->elevation[sf_idx][bin_idx] = elevation[0];
+ hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
+ hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
- hDirAC->energy_ratio1[sf_idx][bin_idx] = energy_ratio;
+ hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = energy_ratio;
- hDirAC->spreadCoherence[sf_idx][bin_idx] = 0.0f;
- hDirAC->surroundingCoherence[sf_idx][bin_idx] = 0.0;
+ hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
+ hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
}
}
}
else
{
- hDirAC->numSimultaneousDirections = 2;
+ hSpatParamRendCom->numSimultaneousDirections = 2;
for ( band_idx = 0; band_idx < hDirAC->hParamIsm->nbands; band_idx++ )
{
brange[0] = hDirAC->hParamIsm->band_grouping[band_idx];
@@ -1530,12 +1556,12 @@ void ivas_param_ism_params_to_masa_param_mapping(
{
for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
{
- hDirAC->azimuth[sf_idx][bin_idx] = azimuth[0];
- hDirAC->elevation[sf_idx][bin_idx] = elevation[0];
- hDirAC->energy_ratio1[sf_idx][bin_idx] = power_ratio[0];
- hDirAC->azimuth2[sf_idx][bin_idx] = azimuth[1];
- hDirAC->elevation2[sf_idx][bin_idx] = elevation[1];
- hDirAC->energy_ratio2[sf_idx][bin_idx] = power_ratio[1];
+ hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
+ hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
+ hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = power_ratio[0];
+ hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1];
+ hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1];
+ hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx] = power_ratio[1];
}
}
}
@@ -1544,16 +1570,16 @@ void ivas_param_ism_params_to_masa_param_mapping(
{
for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
{
- hDirAC->spreadCoherence[sf_idx][bin_idx] = 0.0f;
- hDirAC->spreadCoherence2[sf_idx][bin_idx] = 0.0f;
- hDirAC->surroundingCoherence[sf_idx][bin_idx] = 0.0;
+ hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
+ hSpatParamRendCom->spreadCoherence2[sf_idx][bin_idx] = 0.0f;
+ hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
}
}
}
}
else
{
- hDirAC->numSimultaneousDirections = 1;
+ hSpatParamRendCom->numSimultaneousDirections = 1;
azimuth[0] = (int16_t) roundf( hDirAC->azimuth_values[0] );
elevation[0] = (int16_t) roundf( hDirAC->elevation_values[0] );
@@ -1561,11 +1587,11 @@ void ivas_param_ism_params_to_masa_param_mapping(
{
for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
{
- hDirAC->azimuth[sf_idx][bin_idx] = azimuth[0];
- hDirAC->elevation[sf_idx][bin_idx] = elevation[0];
- hDirAC->energy_ratio1[sf_idx][bin_idx] = 1.0f;
- hDirAC->spreadCoherence[sf_idx][bin_idx] = 0.0f;
- hDirAC->surroundingCoherence[sf_idx][bin_idx] = 0.0;
+ hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
+ hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
+ hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = 1.0f;
+ hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
+ hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
}
}
}
diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c
index 98b0672af362fe780fa5aab249eff7b45a88ed11..e1a7a9cbd28640a5357caa7cc844d572d8042af5 100644
--- a/lib_dec/ivas_jbm_dec.c
+++ b/lib_dec/ivas_jbm_dec.c
@@ -320,7 +320,7 @@ ivas_error ivas_jbm_dec_tc(
{
#ifdef FIX_564
/* loudness correction */
- ivas_dirac_dec_binaural_gain( output, nchan_remapped, output_frame );
+ ivas_dirac_dec_binaural_sba_gain( output, nchan_remapped, output_frame );
#else
float gain = 0.8414f; /* Todo: Temporary gain for roughly matching the loudness. To be tuned later together with other outputs. Also, this is not inline with ivas_dec() */
@@ -691,6 +691,7 @@ ivas_error ivas_jbm_dec_render(
ivas_error error;
float *p_output[MAX_OUTPUT_CHANNELS];
float *p_tc[MAX_TRANSPORT_CHANNELS];
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
error = IVAS_ERR_OK;
@@ -700,6 +701,7 @@ ivas_error ivas_jbm_dec_render(
* Initialization of local vars after struct has been set
*----------------------------------------------------------------*/
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
output_Fs = st_ivas->hDecoderConfig->output_Fs;
nchan_out = st_ivas->hDecoderConfig->nchan_out;
nchan_transport = st_ivas->hTcBuffer->nchan_transport_jbm;
@@ -967,7 +969,7 @@ ivas_error ivas_jbm_dec_render(
}
else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
{
- int16_t offset = st_ivas->hDirAC->slots_rendered * st_ivas->hDirAC->slot_size;
+ int16_t offset = hSpatParamRendCom->slots_rendered * hSpatParamRendCom->slot_size;
nchan_remapped = st_ivas->nchan_transport;
if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c
index 78758be56965fc1a8050b6081e2bc9563af8c5d9..4a6053ccd5b44aa3ccf191ecb847ed553d4eea41 100644
--- a/lib_dec/ivas_masa_dec.c
+++ b/lib_dec/ivas_masa_dec.c
@@ -35,6 +35,7 @@
#include
#include "ivas_cnst.h"
#include "ivas_prot.h"
+#include "ivas_prot_rend.h"
#include "ivas_rom_com.h"
#include "ivas_stat_dec.h"
#include "prot.h"
@@ -287,7 +288,7 @@ ivas_error ivas_masa_decode(
}
if ( st_ivas->hDirAC != NULL )
{
- ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, ivas_total_brate, ivas_format, 0, 0 );
+ ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0 );
}
st->next_bit_pos = next_bit_pos_orig;
@@ -981,7 +982,7 @@ ivas_error ivas_masa_dec_reconfigure(
/* renderer might have changed, reselect */
ivas_renderer_select( st_ivas );
- if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->hDirAC == NULL )
+ if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend == NULL ) || ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin == NULL ) )
{
/* init a new DirAC dec */
if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
@@ -989,10 +990,16 @@ ivas_error ivas_masa_dec_reconfigure(
return error;
}
}
- else if ( st_ivas->renderer_type == RENDERER_DISABLE && st_ivas->hDirAC != NULL )
+ else if ( st_ivas->renderer_type == RENDERER_DISABLE )
{
- /* close unnecessary DirAC dec */
- ivas_dirac_dec_close( &( st_ivas->hDirAC ) );
+ if ( st_ivas->hDirAC != NULL )
+ {
+ /* close all unnecessary parametric decoding and rendering */
+ ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin );
+ ivas_dirac_rend_close( &( st_ivas->hDirACRend ) );
+ ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) );
+ ivas_dirac_dec_close( &( st_ivas->hDirAC ) );
+ }
}
/* possible reconfigure is done later */
@@ -1011,6 +1018,14 @@ ivas_error ivas_masa_dec_reconfigure(
sts = st_ivas->hSCE[sce_id]->hCoreCoder;
sts[0]->bit_stream = bit_stream + num_bits;
num_bits += (int16_t) ( st_ivas->hSCE[sce_id]->element_brate / FRAMES_PER_SEC );
+
+ if ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin != NULL )
+ {
+ if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
}
for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
@@ -1031,7 +1046,7 @@ ivas_error ivas_masa_dec_reconfigure(
{
st_ivas->hCPE[cpe_id]->nchan_out = 1;
- if ( st_ivas->hDirAC != NULL )
+ if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend != NULL ) || ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin != NULL ) )
{
if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK )
{
@@ -1043,7 +1058,7 @@ ivas_error ivas_masa_dec_reconfigure(
{
st_ivas->hCPE[cpe_id]->nchan_out = CPE_CHANNELS;
- if ( st_ivas->hDirAC != NULL )
+ if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend != NULL ) || ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin != NULL ) )
{
if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK )
{
@@ -1052,22 +1067,12 @@ ivas_error ivas_masa_dec_reconfigure(
}
}
}
+
if ( st_ivas->hDiracDecBin != NULL )
{
/* regularization factor is bitrate-dependent */
st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
}
- /*-----------------------------------------------------------------*
- * TD Decorrelator
- *-----------------------------------------------------------------*/
-
- if ( st_ivas->hDiracDecBin != NULL )
- {
- if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
/*-----------------------------------------------------------------*
* CLDFB instances
@@ -1138,15 +1143,17 @@ void ivas_spar_param_to_masa_param_mapping(
int16_t slot_idx, slot_idx_start, sf;
SPAR_DEC_HANDLE hSpar;
float slot_fac;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
/* Set values */
hDirAC = st_ivas->hDirAC;
- hDirAC->numSimultaneousDirections = 1;
- hDiffuseDist = st_ivas->hDirAC->hDiffuseDist;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+ hSpatParamRendCom->numSimultaneousDirections = 1;
+ hDiffuseDist = st_ivas->hDiracDecBin->hDiffuseDist;
nchan_transport = st_ivas->nchan_transport;
band_grouping = hDirAC->band_grouping;
hSpar = st_ivas->hSpar;
- dirac_write_idx = hDirAC->render_to_md_map[subframe];
+ dirac_write_idx = hSpatParamRendCom->render_to_md_map[subframe];
/* Init arrays */
for ( i = 0; i < FOA_CHANNELS; i++ )
@@ -1231,7 +1238,7 @@ void ivas_spar_param_to_masa_param_mapping(
set_zero( transportSignalEnergies[1], nBins );
set_zero( transportSignalCrossCorrelation, nBins );
- for ( slot = 0; slot < hDirAC->subframe_nbslots[subframe]; slot++ )
+ for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ )
{
for ( bin = 0; bin < nBins; bin++ )
{
@@ -1291,13 +1298,13 @@ void ivas_spar_param_to_masa_param_mapping(
ratio = I / fmaxf( 1e-12f, E ); /* Energy ratio */
ratio = fmaxf( 0.0f, fminf( 1.0f, ratio ) );
- hDirAC->azimuth[dirac_write_idx][bin] = (int16_t) roundf( azi / PI_OVER_180 );
- hDirAC->elevation[dirac_write_idx][bin] = (int16_t) roundf( ele / PI_OVER_180 );
- hDirAC->energy_ratio1[dirac_write_idx][bin] = ratio;
- hDirAC->diffuseness_vector[dirac_write_idx][bin] = 1.0f - ratio;
+ hSpatParamRendCom->azimuth[dirac_write_idx][bin] = (int16_t) roundf( azi / PI_OVER_180 );
+ hSpatParamRendCom->elevation[dirac_write_idx][bin] = (int16_t) roundf( ele / PI_OVER_180 );
+ hSpatParamRendCom->energy_ratio1[dirac_write_idx][bin] = ratio;
+ hSpatParamRendCom->diffuseness_vector[dirac_write_idx][bin] = 1.0f - ratio;
- hDirAC->spreadCoherence[dirac_write_idx][bin] = 0.0f;
- hDirAC->surroundingCoherence[dirac_write_idx][bin] = 0.0f;
+ hSpatParamRendCom->spreadCoherence[dirac_write_idx][bin] = 0.0f;
+ hSpatParamRendCom->surroundingCoherence[dirac_write_idx][bin] = 0.0f;
/* Determine directional distribution of the indirect audio based on the SPAR mixing matrices (and the transport audio signals when 2 TC) */
if ( hDiffuseDist != NULL )
diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c
index 99b3ff68744b0daf4e3460cd3c9ab3b764ad6bc3..efdb0a8122809153902ba3c5a4acbee1488f9c62 100755
--- a/lib_dec/ivas_mcmasa_dec.c
+++ b/lib_dec/ivas_mcmasa_dec.c
@@ -82,7 +82,7 @@ ivas_error ivas_mcmasa_dec_reconfig(
{
if ( st_ivas->hDirAC == NULL )
{
- if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK )
{
return error;
}
@@ -96,51 +96,5 @@ ivas_error ivas_mcmasa_dec_reconfig(
}
}
- /*-------------------------------------------------------------------*
- * Close binaural rendering handles and re-allocate proper ones
- * in McMASA renderer_type can be only RENDERER_BINAURAL_PARAMETRIC, RENDERER_BINAURAL_PARAMETRIC_ROOM
- *--------------------------------------------------------------------*/
-
- if ( st_ivas->hBinRenderer != NULL )
- {
- ivas_binRenderer_close( &st_ivas->hBinRenderer );
- }
-
- if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
- {
- /* open parametric binaural renderer */
- if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC )
- {
- if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
-
- if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
- else if ( st_ivas->hDiracDecBin != NULL )
- {
- if ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM )
- {
- /* close unneeded renderer */
- ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin );
- }
- else
- {
- /* if necessary, close/open td-decorrs */
- if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK )
- {
- return error;
- }
-
- /* regularization factor is bitrate-dependent */
- st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
- }
- }
-
return error;
}
diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c
index 1350b9656c354f01ba4eaf22c5705c1f0a945589..e99cf63fa64376f9ab08878e7d95380cc2f284d8 100755
--- a/lib_dec/ivas_mct_dec.c
+++ b/lib_dec/ivas_mct_dec.c
@@ -737,13 +737,13 @@ static ivas_error ivas_mc_dec_reconfig(
st_ivas->hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered;
mvs2s( st_ivas->hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
}
- else if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->hDirAC != NULL )
+ else if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->hSpatParamRendCom != NULL )
{
- st_ivas->hTcBuffer->nb_subframes = st_ivas->hDirAC->nb_subframes;
- st_ivas->hTcBuffer->subframes_rendered = st_ivas->hDirAC->subframes_rendered;
- st_ivas->hTcBuffer->num_slots = st_ivas->hDirAC->num_slots;
- st_ivas->hTcBuffer->slots_rendered = st_ivas->hDirAC->slots_rendered;
- mvs2s( st_ivas->hDirAC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
+ st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes;
+ st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
+ st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots;
+ st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered;
+ mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
}
/* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv
@@ -800,7 +800,9 @@ static ivas_error ivas_mc_dec_reconfig(
if ( st_ivas->hDirAC != NULL )
{
- ivas_dirac_dec_close( &st_ivas->hDirAC );
+ ivas_dirac_rend_close( &( st_ivas->hDirACRend ) );
+ ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) );
+ ivas_dirac_dec_close( &( st_ivas->hDirAC ) );
vbap_free_data( &( st_ivas->hVBAPdata ) );
}
@@ -884,7 +886,9 @@ static ivas_error ivas_mc_dec_reconfig(
if ( st_ivas->hDirAC != NULL )
{
- ivas_dirac_dec_close( &st_ivas->hDirAC );
+ ivas_dirac_rend_close( &( st_ivas->hDirACRend ) );
+ ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) );
+ ivas_dirac_dec_close( &( st_ivas->hDirAC ) );
vbap_free_data( &( st_ivas->hVBAPdata ) );
}
@@ -1115,6 +1119,8 @@ static ivas_error ivas_mc_dec_reconfig(
}
else if ( st_ivas->renderer_type == RENDERER_DISABLE && st_ivas->hDirAC != NULL )
{
+ ivas_dirac_rend_close( &( st_ivas->hDirACRend ) );
+ ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) );
ivas_dirac_dec_close( &( st_ivas->hDirAC ) );
vbap_free_data( &( st_ivas->hVBAPdata ) );
@@ -1161,16 +1167,6 @@ static ivas_error ivas_mc_dec_reconfig(
{
ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin );
}
- else
- {
- /* useTdDecorr may change => close and re-open */
- ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin );
-
- if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
}
/* init necessary new renderers */
@@ -1181,21 +1177,6 @@ static ivas_error ivas_mc_dec_reconfig(
return error;
}
}
- else if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) )
- {
- if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC )
- {
- if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
-
- if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
else if ( st_ivas->hBinRendererTd == NULL && st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
{
if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK )
@@ -1267,18 +1248,6 @@ static ivas_error ivas_mc_dec_reconfig(
#endif
}
- /*-----------------------------------------------------------------*
- * TD Decorrelator
- *-----------------------------------------------------------------*/
-
- if ( st_ivas->hDiracDecBin != NULL )
- {
- if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
-
/*-----------------------------------------------------------------*
* CLDFB instances
*-----------------------------------------------------------------*/
@@ -1324,13 +1293,13 @@ static ivas_error ivas_mc_dec_reconfig(
}
/* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */
- if ( st_ivas->hDirAC != NULL )
+ if ( st_ivas->hSpatParamRendCom != NULL )
{
- st_ivas->hDirAC->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
- st_ivas->hDirAC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
- st_ivas->hDirAC->num_slots = st_ivas->hTcBuffer->num_slots;
- st_ivas->hDirAC->slots_rendered = st_ivas->hTcBuffer->slots_rendered;
- mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hDirAC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
+ st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
+ st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
+ st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots;
+ st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered;
+ mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
}
else if ( st_ivas->hParamMC != NULL )
{
diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c
index fb97faf0de1c23cd02e987813e119e1f4868534b..763a1b222fde2f2c596e3f0239a9ea812788475c 100755
--- a/lib_dec/ivas_sba_dec.c
+++ b/lib_dec/ivas_sba_dec.c
@@ -65,7 +65,7 @@ void ivas_sba_set_cna_cng_flag(
/* st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; */
/* st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; */
}
- else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) )
+ else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) )
{
st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1;
@@ -114,8 +114,6 @@ ivas_error ivas_sba_dec_reconfigure(
int16_t num_channels, num_md_sub_frames;
#endif
- RENDERER_TYPE old_renderer_type;
-
DECODER_CONFIG_HANDLE hDecoderConfig;
ivas_error error;
error = IVAS_ERR_OK;
@@ -147,13 +145,13 @@ ivas_error ivas_sba_dec_reconfigure(
st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered;
mvs2s( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
}
- else if ( st_ivas->hDirAC != NULL )
+ else if ( st_ivas->hSpatParamRendCom != NULL )
{
- st_ivas->hTcBuffer->num_slots = st_ivas->hDirAC->num_slots;
- st_ivas->hTcBuffer->nb_subframes = st_ivas->hDirAC->nb_subframes;
- st_ivas->hTcBuffer->slots_rendered = st_ivas->hDirAC->slots_rendered;
- st_ivas->hTcBuffer->subframes_rendered = st_ivas->hDirAC->subframes_rendered;
- mvs2s( st_ivas->hDirAC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
+ st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots;
+ st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes;
+ st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered;
+ st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
+ mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
}
/*-----------------------------------------------------------------*
@@ -240,7 +238,6 @@ ivas_error ivas_sba_dec_reconfigure(
/* renderer might have changed */
intern_config_old = st_ivas->intern_config;
- old_renderer_type = st_ivas->renderer_type;
ivas_renderer_select( st_ivas );
/* side effect of the renderer selection can be a changed internal config */
@@ -293,29 +290,6 @@ ivas_error ivas_sba_dec_reconfigure(
#endif
}
- if ( st_ivas->renderer_type != old_renderer_type )
- {
- if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
- {
- if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC )
- {
- if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
-
- if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
- {
- return error;
- }
- }
- }
- else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) )
- {
- ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin );
- }
-
if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO ) ) || ( last_ivas_total_brate > IVAS_256k && ivas_total_brate <= IVAS_256k ) || ( last_ivas_total_brate <= IVAS_256k && ivas_total_brate > IVAS_256k ) )
{
DIRAC_CONFIG_FLAG flag_config;
@@ -332,11 +306,14 @@ ivas_error ivas_sba_dec_reconfigure(
}
/* synchronize subframe info */
- st_ivas->hDirAC->num_slots = st_ivas->hTcBuffer->num_slots;
- st_ivas->hDirAC->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
- st_ivas->hDirAC->slots_rendered = st_ivas->hTcBuffer->slots_rendered;
- st_ivas->hDirAC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
- mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hDirAC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
+ if ( st_ivas->hSpatParamRendCom != NULL )
+ {
+ st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots;
+ st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
+ st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered;
+ st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
+ mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
+ }
}
if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) ) != IVAS_ERR_OK )
@@ -346,6 +323,8 @@ ivas_error ivas_sba_dec_reconfigure(
if ( st_ivas->renderer_type == RENDERER_DISABLE )
{
+ ivas_dirac_rend_close( &( st_ivas->hDirACRend ) );
+ ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) );
ivas_dirac_dec_close( &( st_ivas->hDirAC ) );
vbap_free_data( &( st_ivas->hVBAPdata ) );
@@ -424,7 +403,7 @@ ivas_error ivas_sba_dec_reconfigure(
}
else
{
- if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
+ if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
{
tc_nchan_to_allocate++; /* we need a channel for the CNG in this case*/
}
@@ -531,9 +510,11 @@ void ivas_sba_dec_render(
uint16_t slot_size, ch;
uint16_t nchan_internal, nchan_out;
SPAR_DEC_HANDLE hSpar;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
float *output_f_local[MAX_OUTPUT_CHANNELS];
hSpar = st_ivas->hSpar;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
@@ -582,11 +563,11 @@ void ivas_sba_dec_render(
{
if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 )
{
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % st_ivas->hDirAC->dirac_md_buffer_length;
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length;
}
else
{
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length;
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length;
}
}
diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c
index 79ed6c7cf3d67400f11897d8c13f8fd491553a0c..dd8fbdc851ea2918f06c6beb4ad5ae6668076e65 100644
--- a/lib_dec/ivas_spar_decoder.c
+++ b/lib_dec/ivas_spar_decoder.c
@@ -325,7 +325,7 @@ ivas_error ivas_spar_dec(
/* read DirAC bitstream */
if ( st_ivas->hQMetaData != NULL )
{
- ivas_dirac_dec_read_BS( hDecoderConfig->ivas_total_brate, st0, st_ivas->hDirAC, st_ivas->hQMetaData, nb_bits_read,
+ ivas_dirac_dec_read_BS( hDecoderConfig->ivas_total_brate, st0, st_ivas->hDirAC, st_ivas->hSpatParamRendCom, st_ivas->hQMetaData, nb_bits_read,
ivas_get_hodirac_flag( hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ), st_ivas->hSpar->dirac_to_spar_md_bands );
}
@@ -1313,6 +1313,7 @@ void ivas_spar_dec_upmixer(
)
{
SPAR_DEC_HANDLE hSpar;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
int16_t nchan_transport, nchan_out;
int16_t subframe_idx, n, i;
int16_t n_samples_sf;
@@ -1392,15 +1393,16 @@ void ivas_spar_dec_upmixer(
st_ivas->hTcBuffer->tc[n] = NULL;
}
- if ( st_ivas->hDirAC != 0 )
+ if ( st_ivas->hDirAC != NULL && st_ivas->hSpatParamRendCom != NULL )
{
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 )
{
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % st_ivas->hDirAC->dirac_md_buffer_length;
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length;
}
else
{
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length;
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length;
}
}
@@ -1689,7 +1691,7 @@ void ivas_spar_dec_upmixer_sf(
if ( ( st_ivas->hOutSetup.num_lfe > 0 ) && ( st_ivas->hOutSetup.index_lfe[idx_lfe] == ch ) )
{
set_zero( output[ch], hSpar->subframe_nbslots[hSpar->subframes_rendered] * num_cldfb_bands );
- if ( idx_lfe < ( st_ivas->hDirAC->hOutSetup.num_lfe - 1 ) )
+ if ( idx_lfe < ( st_ivas->hDirACRend->hOutSetup.num_lfe - 1 ) )
{
idx_lfe++;
}
diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c
index a1d3e9839276bac93dc0eab7d026314f0697d885..c61effd67359f2e1873e7230e1ddda0e154b4b38 100644
--- a/lib_dec/ivas_spar_md_dec.c
+++ b/lib_dec/ivas_spar_md_dec.c
@@ -3051,6 +3051,9 @@ void ivas_spar_to_dirac(
end_band = min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ) / bw;
hDirAC = st_ivas->hDirAC;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+
dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands;
enc_param_start_band = st_ivas->hSpar->enc_param_start_band / bw;
active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0;
@@ -3145,46 +3148,46 @@ void ivas_spar_to_dirac(
{
int16_t ts_start, ts_end, ts;
- ts_start = hDirAC->block_grouping[block];
- ts_end = hDirAC->block_grouping[block + 1];
+ ts_start = DirAC_block_grouping[block];
+ ts_end = DirAC_block_grouping[block + 1];
for ( b = qmf_band_start; b < qmf_band_end; b++ )
{
azi_dith = azi[band];
ele_dith = ele[band];
- hDirAC->energy_ratio1[block][b] = en_ratio;
+ hSpatParamRendCom->energy_ratio1[block][b] = en_ratio;
tmp_write_idx_band = tmp_write_idx_param_band;
if ( hDirAC->hConfig->dec_param_estim == FALSE )
{
- hDirAC->elevation[tmp_write_idx_band][b] = ele_dith;
- hDirAC->azimuth[tmp_write_idx_band][b] = azi_dith;
- hDirAC->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band];
+ hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith;
+ hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith;
+ hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band];
}
else
{
for ( ts = ts_start; ts < ts_end; ts++ )
{
- hDirAC->elevation[tmp_write_idx_band][b] = ele_dith;
- hDirAC->azimuth[tmp_write_idx_band][b] = azi_dith;
- hDirAC->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band];
- tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hDirAC->dirac_md_buffer_length;
+ hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith;
+ hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith;
+ hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band];
+ tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
}
}
}
- tmp_write_idx_param_band = ( tmp_write_idx_param_band + num_slots_in_subfr ) % hDirAC->dirac_md_buffer_length;
+ tmp_write_idx_param_band = ( tmp_write_idx_param_band + num_slots_in_subfr ) % hSpatParamRendCom->dirac_md_buffer_length;
}
}
/* update buffer write index */
if ( hDirAC->hConfig->dec_param_estim == FALSE )
{
- hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hDirAC->dirac_md_buffer_length;
+ hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length;
}
else
{
- hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + CLDFB_NO_COL_MAX ) % hDirAC->dirac_md_buffer_length;
+ hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length;
}
}
else
diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h
index 94953f63a45ec374f7b54b7dddd0fd16edbfb485..5c70409ac2892ff9da3cd11cb968662475c17784 100644
--- a/lib_dec/ivas_stat_dec.h
+++ b/lib_dec/ivas_stat_dec.h
@@ -396,40 +396,9 @@ typedef struct
} ISM_DTX_DATA_DEC;
/*----------------------------------------------------------------------------------*
- * DirAC decoder structure
+ * DirAC decoder structures
*----------------------------------------------------------------------------------*/
-typedef struct dirac_dec_stack_mem
-{
- /*Decorrelator*/
- float *frame_dec_f;
-
- /*Prototypes*/
- float *proto_direct_buffer_f;
- float *proto_diffuse_buffer_f;
-
- /*Prototype NRGs*/
- float *proto_power_smooth;
- float *proto_power_diff_smooth;
-
- /*Gain or power factors for directional and diffuse streams*/
- float *direct_power_factor;
- float *diffuse_power_factor;
-
- /*Directional responses (gains & Nrg)*/
- float *direct_responses;
- float *direct_responses_square;
-
- /* Target co-variance mtx */
- float *cy_auto_dir_smooth;
- float *cy_cross_dir_smooth;
- float *cy_auto_diff_smooth;
-
- float *reference_power;
- float *onset_filter;
-
-} DIRAC_DEC_STACK_MEM, *DIRAC_DEC_STACK_MEM_HANDLE;
-
typedef struct param_ism_rendering
{
float *proto_matrix;
@@ -442,115 +411,32 @@ typedef struct param_ism_rendering
} PARAM_ISM_RENDERING_DATA, *PARAM_ISM_RENDERING_HANDLE;
-/*Onset detector*/
-typedef struct dirac_onset_detection_params_structure
-{
- int16_t num_freq_bands;
- int16_t max_band_decorr;
-
-} DIRAC_ONSET_DETECTION_PARAMS;
-
-typedef struct dirac_onset_detection_state_structure
-{
- float *onset_detector_1;
- float *onset_detector_2;
-
-} DIRAC_ONSET_DETECTION_STATE;
-
-/*Decorrelator*/
-typedef struct dirac_decorr_params_structure
-{
- int16_t max_band_decorr;
- int16_t max_frequency;
-
- int16_t *pre_delay;
- int16_t *filter_length;
- float *filter_coeff_num_real;
- float *filter_coeff_den_real;
- float *phase_coeff_real;
- float *phase_coeff_imag;
- int16_t *split_frequency_bands;
- int16_t num_split_frequency_bands;
-
- int16_t use_ducker;
- int16_t add_back_onsets_on;
-
- DIRAC_ONSET_DETECTION_PARAMS h_onset_detection_power_params;
-
-} DIRAC_DECORR_PARAMS, *HANDLE_DIRAC_DECORR_PARAMS;
-
-typedef struct dirac_decorr_state_structure
-{
- float *decorr_buffer;
- float *direct_energy_smooth;
- float *reverb_energy_smooth;
-
- DIRAC_ONSET_DETECTION_STATE h_onset_detection_power_state;
-
-} DIRAC_DECORR_STATE, *HANDLE_DIRAC_DECORR_STATE;
-
-/*Output synthesis*/
-typedef struct dirac_output_synthesis_params_structure
-{
- int16_t max_band_decorr;
-
- int16_t use_onset_filters;
-
- float *interpolator;
- float *alpha_synthesis;
- float *alpha_synthesis_fast;
- int16_t numAlphas;
- int16_t numAlphasFast;
-
- float *proto_matrix;
-
- float diffuse_compensation_factor;
- float diffuse_compensation_factor_decorr;
-
-} DIRAC_OUTPUT_SYNTHESIS_PARAMS;
-
-typedef struct dirac_output_synthesis_state_structure
+/* ===== DirAC main structure ===== */
+typedef struct ivas_dirac_dec_data_structure
{
- /* only pointer to local buffers */
- float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */
- float *direct_responses_square;
- float *diffuse_responses_square; /* squared diffuse responses. Size: num_channels. */
-
- /* only pointer to local buffers */
- float *direct_power_factor;
- float *diffuse_power_factor;
-
- float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */
- float *proto_power_smooth_prev; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */
-
- float *proto_power_diff_smooth;
- float *proto_power_diff_smooth_prev;
+ DIRAC_CONFIG_DATA_HANDLE hConfig;
- /* only pointer to local buffers */
- float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */
- float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */
+ /*Parameter decoding*/
+ float azimuth_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS];
+ float elevation_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS];
+ int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1];
- /* Output gain memories */
- float *gains_dir_prev; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */
- float *gains_diff_prev; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */
+ int16_t dithering_seed;
+ int16_t spar_to_dirac_write_idx;
- /* only pointer to local buffers */
- float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */
- float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */
- float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */
+ /*sub-modules*/
+ PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM handle */
+ float power_ratios[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE];
+ PARAM_ISM_RENDERING_HANDLE hParamIsmRendering;
- /* PSD memories */
- float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */
- float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */
- float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */
+ IVAS_FB_MIXER_HANDLE hFbMdft;
- const float *onset_filter;
+} DIRAC_DEC_DATA, *DIRAC_DEC_HANDLE;
- /* Temporal smoothing memories */
- float *reference_power_smooth_prev;
- float *direction_smoothness_prev;
-} DIRAC_OUTPUT_SYNTHESIS_STATE;
+/*----------------------------------------------------------------------------------*
+ * ParamMC structures
+ *----------------------------------------------------------------------------------*/
typedef struct dirac_output_synthesis_cov_state_structure
{
@@ -579,154 +465,6 @@ typedef struct dirac_output_synthesis_cov_state_structure
} DIRAC_OUTPUT_SYNTHESIS_COV_STATE;
-/* MASA stereo transport signal type detection structure */
-typedef struct
-{
- MASA_TRANSPORT_SIGNAL_TYPE masa_stereo_type;
- MASA_TRANSPORT_SIGNAL_TYPE current_stereo_type;
- MASA_TRANSPORT_SIGNAL_TYPE type_change_direction;
-
- int16_t dipole_freq_range[2];
-
- float left_bb_power;
- float right_bb_power;
- float total_bb_power;
-
- float left_hi_power;
- float right_hi_power;
- float total_hi_power;
-
- float sum_power[MASA_SUM_FREQ_RANGE_BINS];
- float total_power[MASA_SUM_FREQ_RANGE_BINS];
-
- float subtract_power_y;
- float subtract_power_y_smooth;
- float target_power_y_smooth;
-
- float lr_total_bb_ratio_db;
- float lr_total_hi_ratio_db;
- float min_sum_total_ratio_db;
- float subtract_target_ratio_db;
-
- int16_t counter;
- int16_t interpolator;
-
-} MASA_STEREO_TYPE_DETECT;
-
-/* Diffuse sound directional distribution data structure */
-typedef struct ivas_diffuse_distribution_data_structure
-{
- float diffuseRatioX[CLDFB_NO_CHANNELS_MAX];
- float diffuseRatioY[CLDFB_NO_CHANNELS_MAX];
- float diffuseRatioZ[CLDFB_NO_CHANNELS_MAX];
-
-} DIFFUSE_DISTRIBUTION_DATA, *DIFFUSE_DISTRIBUTION_HANDLE;
-
-
-/* ===== DirAC main structure ===== */
-typedef struct ivas_dirac_dec_data_structure
-{
- DIRAC_CONFIG_DATA_HANDLE hConfig;
- IVAS_OUTPUT_SETUP hOutSetup;
-
- int16_t slot_size;
- int16_t subframe_nbslots[MAX_JBM_SUBFRAMES_5MS];
- int16_t subframes_rendered;
- int16_t slots_rendered;
- int16_t num_slots;
- int16_t render_to_md_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME];
- int16_t nb_subframes;
- int16_t num_freq_bands;
-
- /*Parameter decoding*/
- float azimuth_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS];
- float elevation_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS];
- int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1];
-
- int16_t block_grouping[5];
- /* decoded, ungrouped and rounded values, we have 1 degree resolution anyway */
- int16_t **azimuth;
- int16_t **elevation;
- int16_t **azimuth2;
- int16_t **elevation2;
-
- float **diffuseness_vector;
- float **energy_ratio1;
- float **energy_ratio2;
-
- float **spreadCoherence;
- float **spreadCoherence2;
- float **surroundingCoherence;
-
- int16_t dithering_seed;
- int16_t dirac_bs_md_write_idx;
- int16_t dirac_read_idx;
- int16_t dirac_estimator_idx;
- int16_t spar_to_dirac_write_idx;
- int16_t dirac_md_buffer_length;
-
- int16_t numSimultaneousDirections; /* 1 or 2 */
- DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist;
-
- /*Parameter estimation*/
- int16_t index_buffer_intensity;
- float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF];
- float *buffer_energy;
-
- /*Decoder parameters */
- /*Prototypes*/
- int16_t num_outputs_dir;
- int16_t num_outputs_diff;
- int16_t num_protos_dir;
- int16_t num_protos_diff;
- int16_t num_protos_ambi;
- DIRAC_SYNTHESIS_CONFIG synthesisConf;
- DIRAC_PANNING_CONFIG panningConf;
-
- float *frequency_axis;
- float *diffuse_response_function;
- float *hoa_encoder;
- const float *hoa_decoder;
-
- /*Options*/
- /* Decorrelator options */
- int16_t max_band_decorr;
-
- /* prototype computing */
- int16_t *proto_index_dir;
- int16_t *proto_index_diff;
-
- int16_t proto_signal_decorr_on;
-
- /*Decoder states=memories*/
- float *proto_frame_f;
- float *proto_frame_dec_f;
-
- DIRAC_DEC_STACK_MEM stack_mem;
- MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect;
-
- int16_t num_ele_spk_no_diffuse_rendering;
-
- /*sub-modules*/
- HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params;
- HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state;
-
- DIRAC_OUTPUT_SYNTHESIS_PARAMS h_output_synthesis_psd_params;
- DIRAC_OUTPUT_SYNTHESIS_STATE h_output_synthesis_psd_state;
-
- PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM handle */
- float power_ratios[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE];
- PARAM_ISM_RENDERING_HANDLE hParamIsmRendering;
- IVAS_FB_MIXER_HANDLE hFbMdft;
- const int16_t *sba_map_tc;
-
-} DIRAC_DEC_DATA, *DIRAC_DEC_HANDLE;
-
-
-/*----------------------------------------------------------------------------------*
- * ParamMC structures
- *----------------------------------------------------------------------------------*/
-
typedef struct ivas_param_mc_diff_proto_info_structure
{
int16_t num_protos_diff;
@@ -1027,48 +765,6 @@ typedef struct ivas_lfe_dec_data_structure
} LFE_DEC_DATA, *LFE_DEC_HANDLE;
-// Note: the following structures are used only in lib_dec but this would likely change in the future
-/*----------------------------------------------------------------------------------*
- * VBAP structures
- *----------------------------------------------------------------------------------*/
-
-/* Defines a single virtual surface triplet of loudspeakers
- * with a precalculated inverse matrix */
-typedef struct vbap_vs_triplet_structure
-{
- uint8_t speaker_node[3];
- float inverse_matrix[3][3];
-
-} VBAP_VS_TRIPLET;
-
-
-/* Storage structure for fast runtime triplet search */
-typedef struct triplet_search_structure
-{
- VBAP_VS_TRIPLET *triplets;
- int16_t num_triplets;
- int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS];
-
-} VBAP_SEARCH_STRUCT;
-
-
-/* VBAP data structure. Contains the formed virtual surface arrangement * and supporting data. */
-typedef struct vbap_data_structure
-{
- VBAP_SEARCH_STRUCT search_struct[2]; /* Default to max two groups in this implementation */
- int16_t num_search_structs;
- int16_t num_speaker_nodes;
- int16_t num_speaker_nodes_internal;
- int16_t top_virtual_speaker_node_index; /* These indices can be negative */
- int16_t bottom_virtual_speaker_node_index;
- int16_t back_virtual_speaker_node_index;
- float *bottom_virtual_speaker_node_division_gains;
- float *top_virtual_speaker_node_division_gains;
- float *back_virtual_speaker_node_division_gains;
-
-} VBAP_DATA, *VBAP_HANDLE;
-
-
/*----------------------------------------------------------------------------------*
* renderer structures
*----------------------------------------------------------------------------------*/
@@ -1113,39 +809,6 @@ typedef struct ivas_binaural_rendering_struct
* MASA decoder structures
*----------------------------------------------------------------------------------*/
-/* McMASA LFE synthesis structure */
-typedef struct ivas_mcmasa_lfe_synth_struct
-{
- float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES];
- int16_t lfeGainPrevIndex;
- float transportEneSmooth;
- float protoLfeEneSmooth;
- float targetEneLfeSmooth;
- float targetEneTransSmooth;
-
- float *lfeSynthRingBuffer;
- int16_t ringBufferLoPointer;
- int16_t ringBufferHiPointer;
- float lowpassSum;
- int16_t ringBufferSize;
-
- float *lfeSynthRingBuffer2;
- int16_t ringBufferLoPointer2;
- float lowpassSum2;
- int16_t ringBufferSize2;
-
- float *delayBuffer_syncLp;
- int16_t delayBuffer_syncLp_size;
-
- float *delayBuffer_syncDirAC;
- int16_t delayBuffer_syncDirAC_size;
-
- float lfeGainPrev;
- float transportGainPrev;
- float interpolator[CLDFB_NO_CHANNELS_MAX];
-
-} MCMASA_LFE_SYNTH_DATA, *MCMASA_LFE_SYNTH_DATA_HANDLE;
-
typedef struct ivas_masa_decoder_ext_out_meta_struct
{
MASA_DECRIPTIVE_META descriptiveMeta;
@@ -1351,6 +1014,8 @@ typedef struct Decoder_Struct
int32_t binaural_latency_ns; /* Binauralization latency in ns */
EXTERNAL_ORIENTATION_HANDLE hExtOrientationData; /* External orientation data structure */
COMBINED_ORIENTATION_HANDLE hCombinedOrientationData; /* Combined external and head orientation data structure */
+ DIRAC_REND_HANDLE hDirACRend; /* DirAC renderer handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; /* Spatial parametric (DirAC rend, ParamBin, ParamISM) rendering common data handle. */
/* JBM module */
DECODER_TC_BUFFER_HANDLE hTcBuffer; /* JBM structure */
diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c
index 4616993f79b1219ae3da63bb3ac564d7d97341e1..8a3f33b80b1949416653dfb99e889414c3e22b6d 100644
--- a/lib_rend/ivas_dirac_dec_binaural_functions.c
+++ b/lib_rend/ivas_dirac_dec_binaural_functions.c
@@ -74,6 +74,18 @@ typedef struct hrtfGainCache
float shVec[HRTF_SH_CHANNELS];
} PARAMBIN_HRTF_GAIN_CACHE;
+typedef struct parambin_rend_config_data
+{
+ int16_t separateCenterChannelRendering;
+ IVAS_FORMAT ivas_format;
+ MC_MODE mc_mode;
+ int32_t ivas_total_brate;
+ int16_t nchan_transport;
+ float qualityBasedSmFactor;
+ int16_t processReverb;
+
+} PARAMBIN_REND_CONFIG, *PARAMBIN_REND_CONFIG_HANDLE;
+
/*-------------------------------------------------------------------------
* Local function prototypes
@@ -81,13 +93,13 @@ typedef struct hrtfGainCache
static void ivas_dirac_dec_binaural_internal( Decoder_Struct *st_ivas, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, float *output_f[], const int16_t nchan_transport, const int16_t subframe );
-static void ivas_dirac_dec_decorrelate_slot( DIRAC_DEC_HANDLE hDirAC, const int16_t slot, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float decRe[][CLDFB_NO_CHANNELS_MAX], float decIm[][CLDFB_NO_CHANNELS_MAX] );
+static void ivas_dirac_dec_decorrelate_slot( DIRAC_DEC_BIN_HANDLE hDiracDecBin, const int16_t num_freq_bands, const int16_t slot, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float decRe[][CLDFB_NO_CHANNELS_MAX], float decIm[][CLDFB_NO_CHANNELS_MAX] );
-static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked );
+static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked );
-static void ivas_dirac_dec_binaural_determine_processing_matrices( Decoder_Struct *st_ivas, const int16_t max_band_decorr, float Rmat[3][3], const int16_t isHeadtracked );
+static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t isHeadtracked );
-static void ivas_dirac_dec_binaural_process_output( Decoder_Struct *st_ivas, float *output_f[], float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t max_band_decorr, const int16_t numInChannels, const int16_t subframe );
+static void ivas_dirac_dec_binaural_process_output( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], float *output_f[], float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t max_band_decorr, const int16_t numInChannels, const int16_t processReverb, const int16_t subframe );
static void adaptTransportSignalsHeadtracked( COMBINED_ORIENTATION_HANDLE hHeadTrackData, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nBins, const int16_t nSlots, float Rmat[3][3] );
@@ -104,63 +116,69 @@ static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Ai
static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] );
+// Todo Tapani refactor: Create separate init & render functions for MASA external renderer. The decoder versions would become too complex if generalized.
+
/*-------------------------------------------------------------------------
* ivas_dirac_dec_init_binaural_data()
*
* Initialize parametric binaural renderer
*------------------------------------------------------------------------*/
+// Todo Tapani refactor: To be moved to lib_dec
ivas_error ivas_dirac_dec_init_binaural_data(
Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */
)
{
- DIRAC_DEC_BIN_HANDLE hBinaural;
+ DIRAC_DEC_BIN_HANDLE hDiracDecBin;
int16_t nBins;
int32_t output_Fs;
RENDERER_TYPE renderer_type;
int16_t j, k, bin;
float binCenterFreq, tmpFloat;
ivas_error error;
+ float frequency_axis[CLDFB_NO_CHANNELS_MAX];
- hBinaural = st_ivas->hDiracDecBin;
+ hDiracDecBin = st_ivas->hDiracDecBin;
- if ( hBinaural == NULL )
+ if ( hDiracDecBin == NULL )
{
- if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL )
+ if ( ( hDiracDecBin = (DIRAC_DEC_BIN_HANDLE) malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL )
{
return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " );
}
- hBinaural->hTdDecorr = NULL;
- hBinaural->hReverb = NULL;
+ hDiracDecBin->hTdDecorr = NULL;
+ hDiracDecBin->hReverb = NULL;
+ hDiracDecBin->h_freq_domain_decorr_ap_params = NULL;
+ hDiracDecBin->h_freq_domain_decorr_ap_state = NULL;
}
- nBins = st_ivas->hDirAC->num_freq_bands;
output_Fs = st_ivas->hDecoderConfig->output_Fs;
+ nBins = st_ivas->hSpatParamRendCom->num_freq_bands;
renderer_type = st_ivas->renderer_type;
for ( j = 0; j < BINAURAL_CHANNELS; j++ )
{
for ( k = 0; k < BINAURAL_CHANNELS + 1; k++ )
{
- set_zero( hBinaural->processMtxRe[j][k], nBins );
- set_zero( hBinaural->processMtxIm[j][k], nBins );
+ set_zero( hDiracDecBin->processMtxRe[j][k], nBins );
+ set_zero( hDiracDecBin->processMtxIm[j][k], nBins );
}
for ( k = 0; k < BINAURAL_CHANNELS; k++ )
{
- set_zero( hBinaural->processMtxDecRe[j][k], nBins );
- set_zero( hBinaural->processMtxDecIm[j][k], nBins );
+ set_zero( hDiracDecBin->processMtxDecRe[j][k], nBins );
+ set_zero( hDiracDecBin->processMtxDecIm[j][k], nBins );
}
- set_zero( hBinaural->ChEnePrev[j], nBins );
- set_zero( hBinaural->ChEneOutPrev[j], nBins );
+ set_zero( hDiracDecBin->ChEnePrev[j], nBins );
+ set_zero( hDiracDecBin->ChEneOutPrev[j], nBins );
}
- set_zero( hBinaural->ChCrossRePrev, nBins );
- set_zero( hBinaural->ChCrossImPrev, nBins );
- set_zero( hBinaural->ChCrossReOutPrev, nBins );
- set_zero( hBinaural->ChCrossImOutPrev, nBins );
- hBinaural->renderStereoOutputInsteadOfBinaural = 0;
+ set_zero( hDiracDecBin->ChCrossRePrev, nBins );
+ set_zero( hDiracDecBin->ChCrossImPrev, nBins );
+ set_zero( hDiracDecBin->ChCrossReOutPrev, nBins );
+ set_zero( hDiracDecBin->ChCrossImOutPrev, nBins );
+ hDiracDecBin->renderStereoOutputInsteadOfBinaural = 0;
for ( bin = 0; bin < nBins; bin++ )
@@ -168,35 +186,35 @@ ivas_error ivas_dirac_dec_init_binaural_data(
binCenterFreq = ( (float) bin + CLDFB_HALF_BIN_FREQUENCY_OFFSET ) / (float) nBins * ( (float) output_Fs / 2.0f );
/* These formulas and values are from Christian Borss's publication for binaural diffuse field coherence */
tmpFloat = max( 0.0f, 1.0f - binCenterFreq / 2700.0f );
- hBinaural->diffuseFieldCoherence[bin] = tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f );
+ hDiracDecBin->diffuseFieldCoherence[bin] = tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f );
}
for ( bin = 0; bin < BINAURAL_COHERENCE_DIFFERENCE_BINS; bin++ )
{
- hBinaural->diffuseFieldCoherenceX[bin] = hBinaural->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceX[bin];
- hBinaural->diffuseFieldCoherenceY[bin] = hBinaural->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceY[bin];
- hBinaural->diffuseFieldCoherenceZ[bin] = hBinaural->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceZ[bin];
+ hDiracDecBin->diffuseFieldCoherenceX[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceX[bin];
+ hDiracDecBin->diffuseFieldCoherenceY[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceY[bin];
+ hDiracDecBin->diffuseFieldCoherenceZ[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceZ[bin];
}
if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC ) /* Indication of binaural rendering without room effect */
{
- set_f( hBinaural->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX );
- hBinaural->hReverb = NULL;
+ set_f( hDiracDecBin->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX );
+ hDiracDecBin->hReverb = NULL;
}
else if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Indication of binaural rendering with room effect */
{
- mvr2r( hHrtfParambin->parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins );
+ mvr2r( hHrtfParambin->parametricEarlyPartEneCorrection, hDiracDecBin->earlyPartEneCorrection, nBins );
/* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */
- if ( hBinaural->hReverb != NULL && ( ( hBinaural->hReverb->numBins != nBins ) ||
- ( hBinaural->hReverb->blockSize != CLDFB_SLOTS_PER_SUBFRAME ) ) )
+ if ( hDiracDecBin->hReverb != NULL && ( ( hDiracDecBin->hReverb->numBins != nBins ) ||
+ ( hDiracDecBin->hReverb->blockSize != CLDFB_SLOTS_PER_SUBFRAME ) ) )
{
- ivas_binaural_reverb_close( &( hBinaural->hReverb ) );
+ ivas_binaural_reverb_close( &( hDiracDecBin->hReverb ) );
}
- if ( hBinaural->hReverb == NULL )
+ if ( hDiracDecBin->hReverb == NULL )
{
- if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb,
+ if ( ( error = ivas_binaural_reverb_open( &hDiracDecBin->hReverb,
nBins,
CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL,
st_ivas->hIntSetup.output_config,
@@ -211,28 +229,52 @@ ivas_error ivas_dirac_dec_init_binaural_data(
}
else if ( renderer_type == RENDERER_STEREO_PARAMETRIC )
{
- set_f( hBinaural->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX );
- hBinaural->hReverb = NULL;
- hBinaural->renderStereoOutputInsteadOfBinaural = 1;
+ set_f( hDiracDecBin->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX );
+ hDiracDecBin->hReverb = NULL;
+ hDiracDecBin->renderStereoOutputInsteadOfBinaural = 1;
}
else /* Not valid renderer type for this renderer */
{
assert( false );
}
- if ( hBinaural->hTdDecorr == NULL )
+ hDiracDecBin->hDiffuseDist = NULL; /* Memory is allocated from stack during runtime when needed */
+
+ if ( hDiracDecBin->hTdDecorr == NULL )
+ {
+ hDiracDecBin->useTdDecorr = 0;
+ }
+
+ if ( hDiracDecBin->h_freq_domain_decorr_ap_params != NULL )
{
- hBinaural->useTdDecorr = 0;
+ ivas_dirac_dec_decorr_close( &hDiracDecBin->h_freq_domain_decorr_ap_params, &hDiracDecBin->h_freq_domain_decorr_ap_state );
}
- if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hBinaural->hTdDecorr ), &( hBinaural->useTdDecorr ) ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hDiracDecBin->hTdDecorr ), &( hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK )
{
return error;
}
- hBinaural->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
+ if ( !hDiracDecBin->useTdDecorr && !( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) )
+ {
+ ivas_dirac_dec_get_frequency_axis( frequency_axis, output_Fs, nBins );
+ if ( ( error = ivas_dirac_dec_decorr_open( &( hDiracDecBin->h_freq_domain_decorr_ap_params ),
+ &( hDiracDecBin->h_freq_domain_decorr_ap_state ),
+ nBins,
+ BINAURAL_CHANNELS,
+ BINAURAL_CHANNELS,
+ DIRAC_SYNTHESIS_PSD_LS,
+ frequency_axis,
+ BINAURAL_CHANNELS,
+ output_Fs ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
- st_ivas->hDiracDecBin = hBinaural;
+ st_ivas->hDiracDecBin = hDiracDecBin;
/* allocate transport channels*/
if ( st_ivas->hDecoderConfig->voip_active == 1 && st_ivas->hTcBuffer == NULL )
@@ -271,6 +313,10 @@ void ivas_dirac_dec_close_binaural_data(
}
ivas_td_decorr_dec_close( &( ( *hBinaural )->hTdDecorr ) );
+ if ( ( *hBinaural )->h_freq_domain_decorr_ap_params != NULL )
+ {
+ ivas_dirac_dec_decorr_close( &( *hBinaural )->h_freq_domain_decorr_ap_params, &( *hBinaural )->h_freq_domain_decorr_ap_state );
+ }
free( *hBinaural );
*hBinaural = NULL;
@@ -331,6 +377,7 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs(
*
*------------------------------------------------------------------------*/
+// Todo Tapani refactor: To be moved to lib_dec
void ivas_dirac_dec_binaural_render(
Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
@@ -343,13 +390,13 @@ void ivas_dirac_dec_binaural_render(
int16_t slots_to_render, first_sf, last_sf, subframe_idx;
uint16_t slot_size, ch;
uint16_t nchan_out;
- DIRAC_DEC_HANDLE hDirAC;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
float *output_f_local[MAX_OUTPUT_CHANNELS];
- hDirAC = st_ivas->hDirAC;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
nchan_out = BINAURAL_CHANNELS;
#ifdef DEBUGGING
- assert( hDirAC );
+ assert( hSpatParamRendCom );
#endif
for ( ch = 0; ch < nchan_out; ch++ )
{
@@ -358,14 +405,14 @@ void ivas_dirac_dec_binaural_render(
slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
/* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
- slots_to_render = min( hDirAC->num_slots - hDirAC->slots_rendered, nSamplesAsked / slot_size );
+ slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size );
*nSamplesRendered = slots_to_render * slot_size;
- first_sf = hDirAC->subframes_rendered;
+ first_sf = hSpatParamRendCom->subframes_rendered;
last_sf = first_sf;
while ( slots_to_render > 0 )
{
- slots_to_render -= hDirAC->subframe_nbslots[last_sf];
+ slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf];
last_sf++;
}
@@ -374,7 +421,7 @@ void ivas_dirac_dec_binaural_render(
#endif
for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
{
- int16_t n_samples_sf = slot_size * hDirAC->subframe_nbslots[subframe_idx];
+ int16_t n_samples_sf = slot_size * hSpatParamRendCom->subframe_nbslots[subframe_idx];
ivas_dirac_dec_binaural_internal( st_ivas, st_ivas->hCombinedOrientationData, output_f_local, nchan_transport, subframe_idx );
for ( ch = 0; ch < nchan_out; ch++ )
{
@@ -382,12 +429,12 @@ void ivas_dirac_dec_binaural_render(
}
}
- if ( hDirAC->slots_rendered == hDirAC->num_slots )
+ if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots )
{
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length;
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length;
}
- *nSamplesAvailable = ( hDirAC->num_slots - hDirAC->slots_rendered ) * slot_size;
+ *nSamplesAvailable = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size;
return;
}
@@ -395,12 +442,13 @@ void ivas_dirac_dec_binaural_render(
#ifdef FIX_564
/*-------------------------------------------------------------------------
- * ivas_dirac_dec_binaural_gain()
+ * ivas_dirac_dec_binaural_sba_gain()
*
* loudness correction for parametric binaural renderer
*------------------------------------------------------------------------*/
-void ivas_dirac_dec_binaural_gain(
+// Todo Tapani refactor: To be moved to lib_dec
+void ivas_dirac_dec_binaural_sba_gain(
float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */
const int16_t nchan_remapped, /* i : num channels after remapping of TCs */
const int16_t output_frame /* i : output frame length */
@@ -434,6 +482,7 @@ void ivas_dirac_dec_binaural_gain(
* Parametric binaural renderer main function
*------------------------------------------------------------------------*/
+// Todo Tapani refactor: To be moved to lib_dec
void ivas_dirac_dec_binaural(
Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */
@@ -442,11 +491,13 @@ void ivas_dirac_dec_binaural(
)
{
int16_t subframe;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
float cng_td_buffer[L_FRAME16k];
float *p_output[MAX_OUTPUT_CHANNELS];
int16_t ch;
int16_t slot_size;
int16_t numInChannels;
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
for ( ch = 0; ch < 2 * BINAURAL_CHANNELS; ch++ )
@@ -493,7 +544,7 @@ void ivas_dirac_dec_binaural(
for ( subframe = 0; subframe < MAX_PARAM_SPATIAL_SUBFRAMES; subframe++ )
{
- int16_t n_samples_sf = slot_size * st_ivas->hDirAC->subframe_nbslots[subframe];
+ int16_t n_samples_sf = slot_size * hSpatParamRendCom->subframe_nbslots[subframe];
ivas_dirac_dec_binaural_internal( st_ivas, hCombinedOrientationData, p_output, nchan_transport, subframe );
@@ -501,7 +552,7 @@ void ivas_dirac_dec_binaural(
{
p_output[ch] += n_samples_sf;
}
- st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + 1 ) % st_ivas->hDirAC->dirac_md_buffer_length;
+ hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
}
for ( ch = 0; ch < 2 * BINAURAL_CHANNELS; ch++ )
@@ -517,7 +568,7 @@ void ivas_dirac_dec_binaural(
* Local functions
*------------------------------------------------------------------------*/
-
+// Todo refactor: To be moved to lib_dec
static void ivas_dirac_dec_binaural_internal(
Decoder_Struct *st_ivas,
COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,
@@ -525,7 +576,9 @@ static void ivas_dirac_dec_binaural_internal(
const int16_t nchan_transport,
const int16_t subframe )
{
- DIRAC_DEC_HANDLE hDirAC;
+ DIRAC_DEC_BIN_HANDLE hDiracDecBin;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
+ PARAMBIN_REND_CONFIG config_data;
int16_t slot, ch, numInChannels;
float Cldfb_RealBuffer_in[4][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
float Cldfb_ImagBuffer_in[4][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
@@ -535,13 +588,24 @@ static void ivas_dirac_dec_binaural_internal(
int16_t nBins, offsetSamples;
int16_t i, j;
- hDirAC = st_ivas->hDirAC;
- nBins = hDirAC->num_freq_bands;
- offsetSamples = hDirAC->slots_rendered * nBins;
+ hDiracDecBin = st_ivas->hDiracDecBin;
+ assert( hDiracDecBin );
+ hSpatParamRendCom = st_ivas->hSpatParamRendCom;
+ nBins = hSpatParamRendCom->num_freq_bands;
+ offsetSamples = hSpatParamRendCom->slots_rendered * nBins;
+
+ /* Setuo internal config */
+ config_data.separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled;
+ config_data.ivas_format = st_ivas->ivas_format;
+ config_data.mc_mode = st_ivas->mc_mode;
+ config_data.ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
+ config_data.nchan_transport = st_ivas->nchan_transport;
+ config_data.qualityBasedSmFactor = st_ivas->hMasa != NULL ? st_ivas->hMasa->data.dir_decode_quality : 1.0f;
+ config_data.processReverb = st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ? 1 : 0;
/* The input channel number at this processing function (not nchan_transport) */
numInChannels = BINAURAL_CHANNELS;
- if ( st_ivas->hOutSetup.separateChannelEnabled )
+ if ( config_data.separateCenterChannelRendering )
{
numInChannels++;
}
@@ -559,7 +623,7 @@ static void ivas_dirac_dec_binaural_internal(
Rmat[2][2] = 1.0f;
/* CLDFB Analysis of input */
- for ( slot = 0; slot < hDirAC->subframe_nbslots[subframe]; slot++ )
+ for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ )
{
for ( ch = 0; ch < numInChannels; ch++ )
{
@@ -571,7 +635,7 @@ static void ivas_dirac_dec_binaural_internal(
Cldfb_ImagBuffer_in[ch][slot],
nBins, st_ivas->cldfbAnaDec[ch] );
}
- else if ( st_ivas->nchan_transport == 2 ) /* Stereo signal transmitted as mono with DFT stereo */
+ else if ( config_data.nchan_transport == 2 ) /* Stereo signal transmitted as mono with DFT stereo */
{
/* At mono input duplicate the channel to dual-mono */
mvr2r( Cldfb_RealBuffer_in[0][slot], Cldfb_RealBuffer_in[1][slot], nBins );
@@ -586,7 +650,7 @@ static void ivas_dirac_dec_binaural_internal(
int16_t slotInFrame;
numCoreBands = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->numCoreBands;
- slotInFrame = hDirAC->slots_rendered + slot;
+ slotInFrame = hSpatParamRendCom->slots_rendered + slot;
generate_masking_noise_dirac( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom,
st_ivas->cldfbAnaDec[1],
@@ -638,7 +702,7 @@ static void ivas_dirac_dec_binaural_internal(
}
}
- if ( st_ivas->hDiracDecBin->useTdDecorr )
+ if ( hDiracDecBin->useTdDecorr )
{
for ( ch = BINAURAL_CHANNELS; ch < ( 2 * BINAURAL_CHANNELS ); ch++ )
{
@@ -648,7 +712,7 @@ static void ivas_dirac_dec_binaural_internal(
Cldfb_ImagBuffer_in[ch][slot],
nBins, st_ivas->cldfbAnaDec[ch] );
- if ( st_ivas->nchan_transport == 1 && st_ivas->ivas_format == SBA_FORMAT )
+ if ( config_data.nchan_transport == 1 && config_data.ivas_format == SBA_FORMAT )
{
v_multc( Cldfb_RealBuffer_in[ch][slot], INV_SQRT_2, Cldfb_RealBuffer_in[ch][slot], nBins );
v_multc( Cldfb_ImagBuffer_in[ch][slot], INV_SQRT_2, Cldfb_ImagBuffer_in[ch][slot], nBins );
@@ -657,9 +721,9 @@ static void ivas_dirac_dec_binaural_internal(
}
}
- if ( st_ivas->ivas_format == SBA_FORMAT )
+ if ( config_data.ivas_format == SBA_FORMAT )
{
- st_ivas->hDirAC->hDiffuseDist = &diffuseDistData;
+ hDiracDecBin->hDiffuseDist = &diffuseDistData;
ivas_spar_param_to_masa_param_mapping( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, subframe );
@@ -678,44 +742,45 @@ static void ivas_dirac_dec_binaural_internal(
if ( nchan_transport == 2 )
{
- adaptTransportSignalsHeadtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hDirAC->subframe_nbslots[subframe], Rmat );
+ adaptTransportSignalsHeadtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat );
- ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hDirAC->subframe_nbslots[subframe], Rmat );
+ ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat );
}
}
- ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, Rmat, subframe,
+ ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, Rmat, subframe,
hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0 );
- if ( st_ivas->ivas_format == ISM_FORMAT )
+ if ( config_data.ivas_format == ISM_FORMAT )
{
max_band_decorr = 0;
}
- else if ( st_ivas->hDiracDecBin->useTdDecorr )
+ else if ( hDiracDecBin->useTdDecorr )
{
max_band_decorr = CLDFB_NO_CHANNELS_MAX;
}
else
{
- max_band_decorr = st_ivas->hDirAC->h_freq_domain_decorr_ap_params->max_band_decorr;
+ max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr;
}
- ivas_dirac_dec_binaural_determine_processing_matrices( st_ivas, max_band_decorr, Rmat,
+ ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat,
hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0 );
- ivas_dirac_dec_binaural_process_output( st_ivas, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, subframe );
+ ivas_dirac_dec_binaural_process_output( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, config_data.processReverb, subframe );
- st_ivas->hDirAC->hDiffuseDist = NULL;
+ hDiracDecBin->hDiffuseDist = NULL;
- hDirAC->slots_rendered += hDirAC->subframe_nbslots[subframe];
- hDirAC->subframes_rendered++;
+ hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe];
+ hSpatParamRendCom->subframes_rendered++;
return;
}
static void ivas_dirac_dec_decorrelate_slot(
- DIRAC_DEC_HANDLE hDirAC,
+ DIRAC_DEC_BIN_HANDLE hDiracDecBin,
+ const int16_t num_freq_bands,
const int16_t slot,
float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
@@ -725,37 +790,39 @@ static void ivas_dirac_dec_decorrelate_slot(
int16_t offset, ch, bin;
float onset_filter[BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, 60 bins */
float decorrelatedFrameInterleaved[2 * BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, real + imag, 60 bins */
+ float protoFrameF[2 * BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, real + imag, 60 bins */
+ const int16_t protoIndexDir[BINAURAL_CHANNELS] = { 0, 1 };
/* Decorrelation needs interleaved data. Copy left and right signals to proto_frame_f */
for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
{
- offset = hDirAC->num_freq_bands * BINAURAL_CHANNELS * ch;
- for ( bin = 0; bin < hDirAC->num_freq_bands; bin++ )
+ offset = num_freq_bands * BINAURAL_CHANNELS * ch;
+ for ( bin = 0; bin < num_freq_bands; bin++ )
{
- hDirAC->proto_frame_f[( bin * BINAURAL_CHANNELS ) + offset] = inRe[ch][slot][bin];
- hDirAC->proto_frame_f[( bin * BINAURAL_CHANNELS ) + offset + 1] = inIm[ch][slot][bin];
+ protoFrameF[( bin * BINAURAL_CHANNELS ) + offset] = inRe[ch][slot][bin];
+ protoFrameF[( bin * BINAURAL_CHANNELS ) + offset + 1] = inIm[ch][slot][bin];
}
}
/* Decorrelate proto signal to decorrelatedFrameInterleaved */
- ivas_dirac_dec_decorr_process( hDirAC->num_freq_bands,
- hDirAC->num_outputs_diff,
- hDirAC->num_protos_diff,
- hDirAC->synthesisConf,
+ ivas_dirac_dec_decorr_process( num_freq_bands,
BINAURAL_CHANNELS,
- hDirAC->proto_frame_f,
- hDirAC->num_protos_diff,
- hDirAC->proto_index_diff,
+ BINAURAL_CHANNELS,
+ DIRAC_SYNTHESIS_PSD_LS,
+ BINAURAL_CHANNELS,
+ protoFrameF,
+ BINAURAL_CHANNELS,
+ protoIndexDir,
decorrelatedFrameInterleaved,
onset_filter,
- hDirAC->h_freq_domain_decorr_ap_params,
- hDirAC->h_freq_domain_decorr_ap_state );
+ hDiracDecBin->h_freq_domain_decorr_ap_params,
+ hDiracDecBin->h_freq_domain_decorr_ap_state );
/* De-interleave decorrelated signals*/
for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
{
- offset = hDirAC->num_freq_bands * BINAURAL_CHANNELS * ch;
- for ( bin = 0; bin < hDirAC->num_freq_bands; bin++ )
+ offset = num_freq_bands * BINAURAL_CHANNELS * ch;
+ for ( bin = 0; bin < num_freq_bands; bin++ )
{
decRe[ch][bin] = decorrelatedFrameInterleaved[( bin * BINAURAL_CHANNELS ) + offset];
decIm[ch][bin] = decorrelatedFrameInterleaved[( bin * BINAURAL_CHANNELS ) + offset + 1];
@@ -767,7 +834,9 @@ static void ivas_dirac_dec_decorrelate_slot(
static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices(
- Decoder_Struct *st_ivas,
+ DIRAC_DEC_BIN_HANDLE hDiracDecBin,
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom,
+ PARAMBIN_REND_CONFIG_HANDLE hConfig,
float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
float Rmat[3][3],
@@ -775,11 +844,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
const int16_t isHeadtracked )
{
int16_t ch, slot, bin;
- uint8_t separateCenterChannelRendering;
+ int16_t separateCenterChannelRendering;
int16_t nBins, idx;
float frameMeanDiffusenessEneWeight[CLDFB_NO_CHANNELS_MAX];
- DIRAC_DEC_HANDLE hDirAC;
- DIRAC_DEC_BIN_HANDLE h;
float IIReneLimiterFactor;
float qualityBasedSmFactor;
float lowBitRateEQ[CLDFB_NO_CHANNELS_MAX];
@@ -787,22 +854,30 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
int16_t dirac_read_idx;
float subFrameTotalEne[CLDFB_NO_CHANNELS_MAX];
PARAMBIN_HRTF_GAIN_CACHE gainCache[MAX_GAIN_CACHE_SIZE];
-
- hDirAC = st_ivas->hDirAC;
- h = st_ivas->hDiracDecBin;
- separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled;
- nBins = hDirAC->num_freq_bands; /* Actually bins */
-
- set_zero( h->ChCrossRe, nBins );
- set_zero( h->ChCrossIm, nBins );
- set_zero( h->ChCrossReOut, nBins );
- set_zero( h->ChCrossImOut, nBins );
+ IVAS_FORMAT ivas_format;
+ MC_MODE mc_mode;
+ int32_t ivas_total_brate;
+ int16_t nchan_transport;
+
+ separateCenterChannelRendering = hConfig->separateCenterChannelRendering;
+ ivas_format = hConfig->ivas_format;
+ mc_mode = hConfig->mc_mode;
+ ivas_total_brate = hConfig->ivas_total_brate;
+ nchan_transport = hConfig->nchan_transport;
+ qualityBasedSmFactor = hConfig->qualityBasedSmFactor;
+ qualityBasedSmFactor *= qualityBasedSmFactor;
+ nBins = hSpatParamRendCom->num_freq_bands; /* Actually bins */
+
+ set_zero( hDiracDecBin->ChCrossRe, nBins );
+ set_zero( hDiracDecBin->ChCrossIm, nBins );
+ set_zero( hDiracDecBin->ChCrossReOut, nBins );
+ set_zero( hDiracDecBin->ChCrossImOut, nBins );
for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
{
- set_zero( h->ChEne[ch], nBins );
- set_zero( h->ChEneOut[ch], nBins );
+ set_zero( hDiracDecBin->ChEne[ch], nBins );
+ set_zero( hDiracDecBin->ChEneOut[ch], nBins );
}
- set_zero( h->frameMeanDiffuseness, nBins );
+ set_zero( hDiracDecBin->frameMeanDiffuseness, nBins );
set_zero( frameMeanDiffusenessEneWeight, CLDFB_NO_CHANNELS_MAX );
@@ -813,10 +888,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
/* Determine EQ for low bit rates (13.2 and 16.4 kbps) */
applyLowBitRateEQ = 0;
- if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MC_FORMAT ) && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE )
+ if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ivas_total_brate < MASA_STEREO_MIN_BITRATE )
{
applyLowBitRateEQ = 1;
- if ( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_16k4 )
+ if ( ivas_total_brate == IVAS_16k4 )
{
for ( bin = 0; bin < LOW_BIT_RATE_BINAURAL_EQ_BINS; bin++ )
{
@@ -834,10 +909,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
/* Formulate input and target covariance matrices for this subframe */
set_zero( subFrameTotalEne, CLDFB_NO_CHANNELS_MAX );
- dirac_read_idx = hDirAC->render_to_md_map[subframe];
+ dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe];
/* Calculate input covariance matrix */
- for ( slot = 0; slot < hDirAC->subframe_nbslots[subframe]; slot++ )
+ for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ )
{
for ( bin = 0; bin < nBins; bin++ )
{
@@ -847,13 +922,13 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
instEne = ( inRe[ch][slot][bin] * inRe[ch][slot][bin] );
instEne += ( inIm[ch][slot][bin] * inIm[ch][slot][bin] );
- h->ChEne[ch][bin] += instEne;
+ hDiracDecBin->ChEne[ch][bin] += instEne;
subFrameTotalEne[bin] += instEne;
}
- h->ChCrossRe[bin] += inRe[0][slot][bin] * inRe[1][slot][bin];
- h->ChCrossRe[bin] += inIm[0][slot][bin] * inIm[1][slot][bin];
- h->ChCrossIm[bin] += inRe[0][slot][bin] * inIm[1][slot][bin];
- h->ChCrossIm[bin] -= inIm[0][slot][bin] * inRe[1][slot][bin];
+ hDiracDecBin->ChCrossRe[bin] += inRe[0][slot][bin] * inRe[1][slot][bin];
+ hDiracDecBin->ChCrossRe[bin] += inIm[0][slot][bin] * inIm[1][slot][bin];
+ hDiracDecBin->ChCrossIm[bin] += inRe[0][slot][bin] * inIm[1][slot][bin];
+ hDiracDecBin->ChCrossIm[bin] -= inIm[0][slot][bin] * inRe[1][slot][bin];
}
}
@@ -872,13 +947,13 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
}
}
- if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport == 2 )
+ if ( ivas_format == SBA_FORMAT && nchan_transport == 2 )
{
float tempRe, tempIm;
set_zero( subFrameTotalEne, CLDFB_NO_CHANNELS_MAX );
- for ( slot = 0; slot < hDirAC->subframe_nbslots[subframe]; slot++ )
+ for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ )
{
for ( bin = 0; bin < nBins; bin++ )
{
@@ -902,10 +977,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
* HRTF data set and a BRIR-based data set. The HRTF data set is spectrally corrected to match
* the early spectrum of the BRIR data, using the spectral correction data in
* hBinaural->earlyPartEneCorrection[bin], based on the BRIR set. */
- meanEnePerCh = h->earlyPartEneCorrection[bin] * subFrameTotalEne[bin] / 2.0f;
+ meanEnePerCh = hDiracDecBin->earlyPartEneCorrection[bin] * subFrameTotalEne[bin] / 2.0f;
/* Determine direct part target covariance matrix (for 1 or 2 directions) */
- for ( dirIndex = 0; dirIndex < hDirAC->numSimultaneousDirections; dirIndex++ )
+ for ( dirIndex = 0; dirIndex < hSpatParamRendCom->numSimultaneousDirections; dirIndex++ )
{
int16_t aziDeg, eleDeg;
float lRealp, lImagp, rRealp, rImagp;
@@ -914,14 +989,14 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
if ( dirIndex == 0 ) /* For first of the two simultaneous directions */
{
- aziDeg = hDirAC->azimuth[dirac_read_idx][bin];
- eleDeg = hDirAC->elevation[dirac_read_idx][bin];
- ratio = hDirAC->energy_ratio1[dirac_read_idx][bin];
- spreadCoh = hDirAC->spreadCoherence[dirac_read_idx][bin];
+ aziDeg = hSpatParamRendCom->azimuth[dirac_read_idx][bin];
+ eleDeg = hSpatParamRendCom->elevation[dirac_read_idx][bin];
+ ratio = hSpatParamRendCom->energy_ratio1[dirac_read_idx][bin];
+ spreadCoh = hSpatParamRendCom->spreadCoherence[dirac_read_idx][bin];
}
else /* For second of the two simultaneous directions */
{
- if ( ( ratio = hDirAC->energy_ratio2[dirac_read_idx][bin] ) < 0.001 )
+ if ( ( ratio = hSpatParamRendCom->energy_ratio2[dirac_read_idx][bin] ) < 0.001 )
{
/* This touches only MASA path where second direction always has smaller ratio and
* for non-2dir it is zero. As the whole direction contribution is multiplied with
@@ -929,9 +1004,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
* it is better to save complexity. */
continue;
}
- aziDeg = hDirAC->azimuth2[dirac_read_idx][bin];
- eleDeg = hDirAC->elevation2[dirac_read_idx][bin];
- spreadCoh = hDirAC->spreadCoherence2[dirac_read_idx][bin];
+ aziDeg = hSpatParamRendCom->azimuth2[dirac_read_idx][bin];
+ eleDeg = hSpatParamRendCom->elevation2[dirac_read_idx][bin];
+ spreadCoh = hSpatParamRendCom->spreadCoherence2[dirac_read_idx][bin];
}
diffuseness -= ratio; /* diffuseness = 1 - ratio1 - ratio2 */
@@ -949,9 +1024,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
spreadCoh = max( spreadCoh, altSpreadCoh );
}
- getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 )], isHeadtracked );
+ getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 )], isHeadtracked );
- if ( h->renderStereoOutputInsteadOfBinaural )
+ if ( hDiracDecBin->renderStereoOutputInsteadOfBinaural )
{
/* Synthesizing spread coherence is not needed for stereo loudspeaker output,
* as directional sound is reproduced with two loudspeakers in any case */
@@ -992,7 +1067,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
rImagp *= centerMul;
/* Apply the gain for the left source of the three coherent sources */
- getDirectPartGains( bin, aziDeg + 30, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 1 )], isHeadtracked );
+ getDirectPartGains( bin, aziDeg + 30, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 1 )], isHeadtracked );
hrtfEneSides = ( lRealpTmp * lRealpTmp ) + ( lImagpTmp * lImagpTmp ) + ( rRealpTmp * rRealpTmp ) + ( rImagpTmp * rImagpTmp );
lRealp += sidesMul * lRealpTmp;
@@ -1002,7 +1077,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
/* Apply the gain for the right source of the three coherent sources.
* -30 degrees to 330 wrapping due to internal functions. */
- getDirectPartGains( bin, aziDeg + 330, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 2 )], isHeadtracked );
+ getDirectPartGains( bin, aziDeg + 330, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 2 )], isHeadtracked );
hrtfEneSides += ( lRealpTmp * lRealpTmp ) + ( lImagpTmp * lImagpTmp ) + ( rRealpTmp * rRealpTmp ) + ( rImagpTmp * rImagpTmp );
lRealp += sidesMul * lRealpTmp;
@@ -1030,7 +1105,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
w3 = 2.0f * spreadCoh - 1.0f;
}
- if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) )
+ if ( ( ivas_format == MC_FORMAT && mc_mode == MC_MODE_MCMASA ) )
{
idx = min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 );
@@ -1060,68 +1135,60 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
/* Add direct part (1 or 2) covariance matrix */
dirEne = ratio * meanEnePerCh;
- h->ChEneOut[0][bin] += dirEne * hrtfEne[0]; /* Dir ene part*/
- h->ChEneOut[1][bin] += dirEne * hrtfEne[1];
- h->ChCrossReOut[bin] += dirEne * hrtfCrossRe; /* Dir cross re */
- h->ChCrossImOut[bin] += dirEne * hrtfCrossIm; /* Dir cross im */
+ hDiracDecBin->ChEneOut[0][bin] += dirEne * hrtfEne[0]; /* Dir ene part*/
+ hDiracDecBin->ChEneOut[1][bin] += dirEne * hrtfEne[1];
+ hDiracDecBin->ChCrossReOut[bin] += dirEne * hrtfCrossRe; /* Dir cross re */
+ hDiracDecBin->ChCrossImOut[bin] += dirEne * hrtfCrossIm; /* Dir cross im */
}
/* Add diffuse / ambient part covariance matrix */
diffuseness = max( 0.0f, diffuseness );
diffEne = diffuseness * meanEnePerCh;
- surCoh = hDirAC->surroundingCoherence[dirac_read_idx][bin];
- if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) )
+ surCoh = hSpatParamRendCom->surroundingCoherence[dirac_read_idx][bin];
+ if ( ( ivas_format == MC_FORMAT && mc_mode == MC_MODE_MCMASA ) )
{
- if ( !h->renderStereoOutputInsteadOfBinaural )
+ if ( !hDiracDecBin->renderStereoOutputInsteadOfBinaural )
{
idx = min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 );
/* Apply target spectrum that emphasizes low frequencies when the sound is surround coherent */
diffEne *= ( 1.0f - surCoh ) + surCoh * surCohEne[idx];
}
}
- h->ChEneOut[0][bin] += diffEne; /* Diff ene part*/
- h->ChEneOut[1][bin] += diffEne;
+ hDiracDecBin->ChEneOut[0][bin] += diffEne; /* Diff ene part*/
+ hDiracDecBin->ChEneOut[1][bin] += diffEne;
- if ( h->renderStereoOutputInsteadOfBinaural )
+ if ( hDiracDecBin->renderStereoOutputInsteadOfBinaural )
{
/* When rendering stereo, ambience (except for surround coherent sound) has zero ICC. */
- h->ChCrossReOut[bin] += surCoh * diffEne;
+ hDiracDecBin->ChCrossReOut[bin] += surCoh * diffEne;
}
else /* When rendering binaural, ambience has frequency dependent ICC. */
{
- if ( st_ivas->ivas_format == SBA_FORMAT && bin < BINAURAL_COHERENCE_DIFFERENCE_BINS )
+ if ( ivas_format == SBA_FORMAT && bin < BINAURAL_COHERENCE_DIFFERENCE_BINS )
{
float diffuseFieldCoherence;
- diffuseFieldCoherence = hDirAC->hDiffuseDist->diffuseRatioX[bin] * h->diffuseFieldCoherenceX[bin] + hDirAC->hDiffuseDist->diffuseRatioY[bin] * h->diffuseFieldCoherenceY[bin] + hDirAC->hDiffuseDist->diffuseRatioZ[bin] * h->diffuseFieldCoherenceZ[bin];
- h->ChCrossReOut[bin] += ( ( 1.0f - surCoh ) * diffuseFieldCoherence + surCoh ) * diffEne;
+ diffuseFieldCoherence = hDiracDecBin->hDiffuseDist->diffuseRatioX[bin] * hDiracDecBin->diffuseFieldCoherenceX[bin] + hDiracDecBin->hDiffuseDist->diffuseRatioY[bin] * hDiracDecBin->diffuseFieldCoherenceY[bin] + hDiracDecBin->hDiffuseDist->diffuseRatioZ[bin] * hDiracDecBin->diffuseFieldCoherenceZ[bin];
+ hDiracDecBin->ChCrossReOut[bin] += ( ( 1.0f - surCoh ) * diffuseFieldCoherence + surCoh ) * diffEne;
}
else
{
- h->ChCrossReOut[bin] += ( ( 1.0f - surCoh ) * h->diffuseFieldCoherence[bin] + surCoh ) * diffEne;
+ hDiracDecBin->ChCrossReOut[bin] += ( ( 1.0f - surCoh ) * hDiracDecBin->diffuseFieldCoherence[bin] + surCoh ) * diffEne;
}
}
/* Store parameters for formulating average diffuseness over frame */
- h->frameMeanDiffuseness[bin] += diffEne;
+ hDiracDecBin->frameMeanDiffuseness[bin] += diffEne;
frameMeanDiffusenessEneWeight[bin] += meanEnePerCh;
}
/* Formulate average diffuseness over frame */
for ( bin = 0; bin < nBins; bin++ )
{
- h->frameMeanDiffuseness[bin] /= fmaxf( 1e-12f, frameMeanDiffusenessEneWeight[bin] );
- }
-
- /* Determine encoding quality based additional smoothing factor */
- qualityBasedSmFactor = 1.0f;
- if ( st_ivas->hMasa != NULL )
- {
- qualityBasedSmFactor = st_ivas->hMasa->data.dir_decode_quality;
- qualityBasedSmFactor *= qualityBasedSmFactor;
+ hDiracDecBin->frameMeanDiffuseness[bin] /= fmaxf( 1e-12f, frameMeanDiffusenessEneWeight[bin] );
}
- /* Temporal IIR-type smoothing of covariance matrices */
- if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE )
+ /* Temporal IIR-type smoothing of covariance matrices. Also apply encoding quality based smoothing factor. */
+ if ( ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE )
{
IIReneLimiterFactor = 16.0f + ( 1.0f - qualityBasedSmFactor );
}
@@ -1136,41 +1203,41 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
/* Temporally smooth cov mtx estimates for resulting mixing matrix stability. The design principle is that
* the energy history (IIR) must not be more than double of the current frame energy. This provides more
* robust performance at energy offsets when compared to typical IIR averaging. */
- eneRatio = ( h->ChEne[0][bin] + h->ChEne[1][bin] ) / fmaxf( 1e-12f, ( h->ChEnePrev[0][bin] + h->ChEnePrev[1][bin] ) );
+ eneRatio = ( hDiracDecBin->ChEne[0][bin] + hDiracDecBin->ChEne[1][bin] ) / fmaxf( 1e-12f, ( hDiracDecBin->ChEnePrev[0][bin] + hDiracDecBin->ChEnePrev[1][bin] ) );
IIReneLimiter = fminf( 1.0f, eneRatio * IIReneLimiterFactor );
- h->ChCrossRe[bin] *= qualityBasedSmFactor;
- h->ChCrossIm[bin] *= qualityBasedSmFactor;
- h->ChCrossReOut[bin] *= qualityBasedSmFactor;
- h->ChCrossImOut[bin] *= qualityBasedSmFactor;
+ hDiracDecBin->ChCrossRe[bin] *= qualityBasedSmFactor;
+ hDiracDecBin->ChCrossIm[bin] *= qualityBasedSmFactor;
+ hDiracDecBin->ChCrossReOut[bin] *= qualityBasedSmFactor;
+ hDiracDecBin->ChCrossImOut[bin] *= qualityBasedSmFactor;
for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
{
- h->ChEne[ch][bin] *= qualityBasedSmFactor;
- h->ChEneOut[ch][bin] *= qualityBasedSmFactor;
+ hDiracDecBin->ChEne[ch][bin] *= qualityBasedSmFactor;
+ hDiracDecBin->ChEneOut[ch][bin] *= qualityBasedSmFactor;
}
- h->ChCrossRe[bin] += IIReneLimiter * h->ChCrossRePrev[bin];
- h->ChCrossIm[bin] += IIReneLimiter * h->ChCrossImPrev[bin];
- h->ChCrossReOut[bin] += IIReneLimiter * h->ChCrossReOutPrev[bin];
- h->ChCrossImOut[bin] += IIReneLimiter * h->ChCrossImOutPrev[bin];
+ hDiracDecBin->ChCrossRe[bin] += IIReneLimiter * hDiracDecBin->ChCrossRePrev[bin];
+ hDiracDecBin->ChCrossIm[bin] += IIReneLimiter * hDiracDecBin->ChCrossImPrev[bin];
+ hDiracDecBin->ChCrossReOut[bin] += IIReneLimiter * hDiracDecBin->ChCrossReOutPrev[bin];
+ hDiracDecBin->ChCrossImOut[bin] += IIReneLimiter * hDiracDecBin->ChCrossImOutPrev[bin];
for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
{
- h->ChEne[ch][bin] += IIReneLimiter * h->ChEnePrev[ch][bin];
- h->ChEneOut[ch][bin] += IIReneLimiter * h->ChEneOutPrev[ch][bin];
+ hDiracDecBin->ChEne[ch][bin] += IIReneLimiter * hDiracDecBin->ChEnePrev[ch][bin];
+ hDiracDecBin->ChEneOut[ch][bin] += IIReneLimiter * hDiracDecBin->ChEneOutPrev[ch][bin];
}
/* Store energy values and coefficients for next round */
- h->ChCrossRePrev[bin] = h->ChCrossRe[bin];
- h->ChCrossImPrev[bin] = h->ChCrossIm[bin];
- h->ChCrossReOutPrev[bin] = h->ChCrossReOut[bin];
- h->ChCrossImOutPrev[bin] = h->ChCrossImOut[bin];
+ hDiracDecBin->ChCrossRePrev[bin] = hDiracDecBin->ChCrossRe[bin];
+ hDiracDecBin->ChCrossImPrev[bin] = hDiracDecBin->ChCrossIm[bin];
+ hDiracDecBin->ChCrossReOutPrev[bin] = hDiracDecBin->ChCrossReOut[bin];
+ hDiracDecBin->ChCrossImOutPrev[bin] = hDiracDecBin->ChCrossImOut[bin];
for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
{
- h->ChEnePrev[ch][bin] = h->ChEne[ch][bin];
- h->ChEneOutPrev[ch][bin] = h->ChEneOut[ch][bin];
+ hDiracDecBin->ChEnePrev[ch][bin] = hDiracDecBin->ChEne[ch][bin];
+ hDiracDecBin->ChEneOutPrev[ch][bin] = hDiracDecBin->ChEneOut[ch][bin];
}
}
@@ -1179,20 +1246,28 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
static void ivas_dirac_dec_binaural_determine_processing_matrices(
- Decoder_Struct *st_ivas,
+ DIRAC_DEC_BIN_HANDLE hDiracDecBin,
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom,
+ PARAMBIN_REND_CONFIG_HANDLE hConfig,
const int16_t max_band_decorr,
float Rmat[3][3],
const int16_t isHeadtracked )
{
int16_t chA, chB, bin;
- uint8_t separateCenterChannelRendering;
+ int16_t separateCenterChannelRendering;
int16_t nBins;
- DIRAC_DEC_BIN_HANDLE h;
PARAMBIN_HRTF_GAIN_CACHE gainCache;
-
- h = st_ivas->hDiracDecBin;
- separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled;
- nBins = st_ivas->hDirAC->num_freq_bands; /* Actually bins */
+ IVAS_FORMAT ivas_format;
+ MC_MODE mc_mode;
+ int32_t ivas_total_brate;
+ int16_t nchan_transport;
+
+ separateCenterChannelRendering = hConfig->separateCenterChannelRendering;
+ ivas_format = hConfig->ivas_format;
+ mc_mode = hConfig->mc_mode;
+ ivas_total_brate = hConfig->ivas_total_brate;
+ nchan_transport = hConfig->nchan_transport;
+ nBins = hSpatParamRendCom->num_freq_bands; /* Actually bins */
gainCache.azi = -1000; /* Use -1000 as value for uninitialized cache. */
@@ -1210,21 +1285,21 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices(
CrEneR = 0.0f;
/* Formulate main processing matrix M */
- formulate2x2MixingMatrix( h->ChEne[0][bin], h->ChEne[1][bin],
- h->ChCrossRe[bin], h->ChCrossIm[bin],
- h->ChEneOut[0][bin], h->ChEneOut[1][bin],
- h->ChCrossReOut[bin], h->ChCrossImOut[bin],
- prototypeMtx, Mre, Mim, h->reqularizationFactor );
+ formulate2x2MixingMatrix( hDiracDecBin->ChEne[0][bin], hDiracDecBin->ChEne[1][bin],
+ hDiracDecBin->ChCrossRe[bin], hDiracDecBin->ChCrossIm[bin],
+ hDiracDecBin->ChEneOut[0][bin], hDiracDecBin->ChEneOut[1][bin],
+ hDiracDecBin->ChCrossReOut[bin], hDiracDecBin->ChCrossImOut[bin],
+ prototypeMtx, Mre, Mim, hDiracDecBin->reqularizationFactor );
/* Load estimated covariance matrix to the [2][2] matrix form */
- CxRe[0][0] = h->ChEne[0][bin];
- CxRe[1][1] = h->ChEne[1][bin];
- CxRe[1][0] = h->ChCrossRe[bin];
- CxRe[0][1] = h->ChCrossRe[bin];
+ CxRe[0][0] = hDiracDecBin->ChEne[0][bin];
+ CxRe[1][1] = hDiracDecBin->ChEne[1][bin];
+ CxRe[1][0] = hDiracDecBin->ChCrossRe[bin];
+ CxRe[0][1] = hDiracDecBin->ChCrossRe[bin];
CxIm[0][0] = 0.0f;
CxIm[1][1] = 0.0f;
- CxIm[1][0] = h->ChCrossIm[bin];
- CxIm[0][1] = -h->ChCrossIm[bin];
+ CxIm[1][0] = hDiracDecBin->ChCrossIm[bin];
+ CxIm[0][1] = -hDiracDecBin->ChCrossIm[bin];
/* Make matrix multiplication M*Cx*M' to determine resulting covariance matrix of processing input with M */
matrixMul( Mre, Mim, CxRe, CxIm, tmpMtxRe, tmpMtxIm );
@@ -1240,30 +1315,30 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices(
/* Subtract the resulting covariance matrix from the target covariance matrix to determine
* what signal component is missing. The result is the target covariance matrix for the residual signal, i.e.,
* a residual covariance matrix. */
- CrEneL = max( 0.0f, h->ChEneOut[0][bin] - resultMtxRe[0][0] );
- CrEneR = max( 0.0f, h->ChEneOut[1][bin] - resultMtxRe[1][1] );
- CrCrossRe = h->ChCrossReOut[bin] - resultMtxRe[1][0];
- CrCrossIm = h->ChCrossImOut[bin] - resultMtxIm[1][0];
+ CrEneL = max( 0.0f, hDiracDecBin->ChEneOut[0][bin] - resultMtxRe[0][0] );
+ CrEneR = max( 0.0f, hDiracDecBin->ChEneOut[1][bin] - resultMtxRe[1][1] );
+ CrCrossRe = hDiracDecBin->ChCrossReOut[bin] - resultMtxRe[1][0];
+ CrCrossIm = hDiracDecBin->ChCrossImOut[bin] - resultMtxIm[1][0];
/* The amount of the decorrelated sound is further controlled based on the spatial metadata,
* by determining an energy-suppressed residual covariance matrix that is a control parameter
* that guides the processing of the decorrelated sound to a residual signal.
* The procedure improves quality in e.g. double-talk 2-direction rendering situations.*/
- if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE )
+ if ( ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE )
{
decorrelationReductionFactor = 1.0f;
}
- else if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nchan_transport == 1 ) )
+ else if ( ( ivas_format == MC_FORMAT && mc_mode == MC_MODE_MCMASA ) || ( ivas_format == MASA_FORMAT && nchan_transport == 1 ) )
{
- decorrelationReductionFactor = sqrtf( fmaxf( 0.0f, h->frameMeanDiffuseness[bin] ) );
+ decorrelationReductionFactor = sqrtf( fmaxf( 0.0f, hDiracDecBin->frameMeanDiffuseness[bin] ) );
}
- else if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport == 1 )
+ else if ( ivas_format == SBA_FORMAT && nchan_transport == 1 )
{
decorrelationReductionFactor = 1.0f;
}
else
{
- decorrelationReductionFactor = fmaxf( 0.0f, h->frameMeanDiffuseness[bin] );
+ decorrelationReductionFactor = fmaxf( 0.0f, hDiracDecBin->frameMeanDiffuseness[bin] );
}
CrEneL *= decorrelationReductionFactor;
CrEneR *= decorrelationReductionFactor;
@@ -1272,7 +1347,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices(
/* Determine a residual mixing matrix Mdec for processing the decorrelated signal to obtain
* the residual signal (that has the residual covariance matrix) */
- formulate2x2MixingMatrix( h->ChEne[0][bin], h->ChEne[1][bin],
+ formulate2x2MixingMatrix( hDiracDecBin->ChEne[0][bin], hDiracDecBin->ChEne[1][bin],
0.0f, 0.0f, /* Decorrelated signal has ideally no cross-terms */
CrEneL, CrEneR,
CrCrossRe, CrCrossIm,
@@ -1289,7 +1364,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices(
/* The regularizations at determining mixing matrices cause signal energy to be lost to some degree, which is compensated for here */
realizedOutputEne = CrEneL + CrEneR + resultMtxRe[0][0] + resultMtxRe[1][1];
- targetOutputEne = h->ChEneOut[0][bin] + h->ChEneOut[1][bin];
+ targetOutputEne = hDiracDecBin->ChEneOut[0][bin] + hDiracDecBin->ChEneOut[1][bin];
missingOutputEne = fmaxf( 0.0f, targetOutputEne - realizedOutputEne );
gain = sqrtf( ( resultMtxRe[0][0] + resultMtxRe[1][1] + missingOutputEne ) /
@@ -1310,15 +1385,15 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices(
{
for ( chB = 0; chB < BINAURAL_CHANNELS; chB++ )
{
- h->processMtxRePrev[chA][chB][bin] = h->processMtxRe[chA][chB][bin];
- h->processMtxImPrev[chA][chB][bin] = h->processMtxIm[chA][chB][bin];
- h->processMtxDecRePrev[chA][chB][bin] = h->processMtxDecRe[chA][chB][bin];
- h->processMtxDecImPrev[chA][chB][bin] = h->processMtxDecIm[chA][chB][bin];
-
- h->processMtxRe[chA][chB][bin] = Mre[chA][chB];
- h->processMtxIm[chA][chB][bin] = Mim[chA][chB];
- h->processMtxDecRe[chA][chB][bin] = MdecRe[chA][chB];
- h->processMtxDecIm[chA][chB][bin] = MdecIm[chA][chB];
+ hDiracDecBin->processMtxRePrev[chA][chB][bin] = hDiracDecBin->processMtxRe[chA][chB][bin];
+ hDiracDecBin->processMtxImPrev[chA][chB][bin] = hDiracDecBin->processMtxIm[chA][chB][bin];
+ hDiracDecBin->processMtxDecRePrev[chA][chB][bin] = hDiracDecBin->processMtxDecRe[chA][chB][bin];
+ hDiracDecBin->processMtxDecImPrev[chA][chB][bin] = hDiracDecBin->processMtxDecIm[chA][chB][bin];
+
+ hDiracDecBin->processMtxRe[chA][chB][bin] = Mre[chA][chB];
+ hDiracDecBin->processMtxIm[chA][chB][bin] = Mim[chA][chB];
+ hDiracDecBin->processMtxDecRe[chA][chB][bin] = MdecRe[chA][chB];
+ hDiracDecBin->processMtxDecIm[chA][chB][bin] = MdecIm[chA][chB];
}
}
@@ -1331,19 +1406,19 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices(
int16_t aziDeg = 0;
int16_t eleDeg = 0;
- gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] );
+ gainFactor = 0.8414f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] );
for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ )
{
- h->processMtxRePrev[chA][2][bin] = h->processMtxRe[chA][2][bin];
- h->processMtxImPrev[chA][2][bin] = h->processMtxIm[chA][2][bin];
+ hDiracDecBin->processMtxRePrev[chA][2][bin] = hDiracDecBin->processMtxRe[chA][2][bin];
+ hDiracDecBin->processMtxImPrev[chA][2][bin] = hDiracDecBin->processMtxIm[chA][2][bin];
}
- getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache, isHeadtracked );
+ getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache, isHeadtracked );
- h->processMtxRe[0][2][bin] = lRealp * gainFactor;
- h->processMtxIm[0][2][bin] = lImagp * gainFactor;
- h->processMtxRe[1][2][bin] = rRealp * gainFactor;
- h->processMtxIm[1][2][bin] = rImagp * gainFactor;
+ hDiracDecBin->processMtxRe[0][2][bin] = lRealp * gainFactor;
+ hDiracDecBin->processMtxIm[0][2][bin] = lImagp * gainFactor;
+ hDiracDecBin->processMtxRe[1][2][bin] = rRealp * gainFactor;
+ hDiracDecBin->processMtxIm[1][2][bin] = rImagp * gainFactor;
}
}
@@ -1352,12 +1427,15 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices(
static void ivas_dirac_dec_binaural_process_output(
- Decoder_Struct *st_ivas,
+ DIRAC_DEC_BIN_HANDLE hDiracDecBin,
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom,
+ HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS],
float *output_f[],
float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
const int16_t max_band_decorr,
const int16_t numInChannels,
+ const int16_t processReverb,
const int16_t subframe )
{
int16_t slot, bin, chA, chB;
@@ -1366,31 +1444,29 @@ static void ivas_dirac_dec_binaural_process_output(
float decSlotRe[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX], decSlotIm[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX];
float reverbRe[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
float reverbIm[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
- DIRAC_DEC_BIN_HANDLE h;
float interpVal;
float *decSlotRePointer;
float *decSlotImPointer;
int16_t offsetSamples;
int16_t nSlots;
- h = st_ivas->hDiracDecBin;
- nBins = st_ivas->hDirAC->num_freq_bands;
+ nBins = hSpatParamRendCom->num_freq_bands;
offsetSamples = 0;
- nSlots = st_ivas->hDirAC->subframe_nbslots[subframe];
+ nSlots = hSpatParamRendCom->subframe_nbslots[subframe];
- if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
+ if ( processReverb )
{
/* Process second / room effect part of binaural output when needed */
- ivas_binaural_reverb_processSubframe( st_ivas->hDiracDecBin->hReverb, numInChannels, nSlots, inRe, inIm, reverbRe, reverbIm );
+ ivas_binaural_reverb_processSubframe( hDiracDecBin->hReverb, numInChannels, nSlots, inRe, inIm, reverbRe, reverbIm );
}
interpVal = 0.0f;
for ( slot = 0; slot < nSlots; slot++ )
{
interpVal += 1.0f / (float) nSlots;
- if ( !st_ivas->hDiracDecBin->useTdDecorr && max_band_decorr > 0 )
+ if ( !hDiracDecBin->useTdDecorr && max_band_decorr > 0 )
{
- ivas_dirac_dec_decorrelate_slot( st_ivas->hDirAC, slot, inRe, inIm, decSlotRe, decSlotIm );
+ ivas_dirac_dec_decorrelate_slot( hDiracDecBin, nBins, slot, inRe, inIm, decSlotRe, decSlotIm );
}
for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ )
@@ -1403,7 +1479,7 @@ static void ivas_dirac_dec_binaural_process_output(
/* Processing of the first / HRTF part of the binaural output. */
for ( chB = 0; chB < numInChannels; chB++ )
{
- if ( st_ivas->hDiracDecBin->useTdDecorr )
+ if ( hDiracDecBin->useTdDecorr )
{
decSlotRePointer = inRe[chB + 2][slot];
decSlotImPointer = inIm[chB + 2][slot];
@@ -1419,33 +1495,33 @@ static void ivas_dirac_dec_binaural_process_output(
float gain;
/* Mixing using the formulated processing matrix M */
- gain = ( 1.0f - interpVal ) * h->processMtxRePrev[chA][chB][bin] +
- interpVal * h->processMtxRe[chA][chB][bin];
+ gain = ( 1.0f - interpVal ) * hDiracDecBin->processMtxRePrev[chA][chB][bin] +
+ interpVal * hDiracDecBin->processMtxRe[chA][chB][bin];
outSlotRe[bin] += gain * inRe[chB][slot][bin];
outSlotIm[bin] += gain * inIm[chB][slot][bin];
- gain = ( 1.0f - interpVal ) * h->processMtxImPrev[chA][chB][bin] +
- interpVal * h->processMtxIm[chA][chB][bin];
+ gain = ( 1.0f - interpVal ) * hDiracDecBin->processMtxImPrev[chA][chB][bin] +
+ interpVal * hDiracDecBin->processMtxIm[chA][chB][bin];
outSlotRe[bin] -= gain * inIm[chB][slot][bin];
outSlotIm[bin] += gain * inRe[chB][slot][bin];
/* Mixing decorrelated signals using the formulated residual processing matrix Mdec */
if ( bin < max_band_decorr && chB < 2 )
{
- gain = ( 1.0f - interpVal ) * h->processMtxDecRePrev[chA][chB][bin] +
- interpVal * h->processMtxDecRe[chA][chB][bin];
+ gain = ( 1.0f - interpVal ) * hDiracDecBin->processMtxDecRePrev[chA][chB][bin] +
+ interpVal * hDiracDecBin->processMtxDecRe[chA][chB][bin];
outSlotRe[bin] += gain * decSlotRePointer[bin];
outSlotIm[bin] += gain * decSlotImPointer[bin];
- gain = ( 1.0f - interpVal ) * h->processMtxDecImPrev[chA][chB][bin] +
- interpVal * h->processMtxDecIm[chA][chB][bin];
+ gain = ( 1.0f - interpVal ) * hDiracDecBin->processMtxDecImPrev[chA][chB][bin] +
+ interpVal * hDiracDecBin->processMtxDecIm[chA][chB][bin];
outSlotRe[bin] -= gain * decSlotImPointer[bin];
outSlotIm[bin] += gain * decSlotRePointer[bin];
}
}
}
- if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
+ if ( processReverb )
{
/* Combine second (reverb) part with the first (HRTF) part to obtain binaural output signal with room effect */
v_add( outSlotRe, reverbRe[chA][slot], outSlotRe, CLDFB_NO_CHANNELS_MAX );
@@ -1456,7 +1532,7 @@ static void ivas_dirac_dec_binaural_process_output(
outSlotImPr = &( outSlotIm[0] );
/* Inverse filter bank */
- cldfbSynthesis( &outSlotRePr, &outSlotImPr, &( output_f[chA][nBins * slot + offsetSamples] ), nBins, st_ivas->cldfbSynDec[chA] );
+ cldfbSynthesis( &outSlotRePr, &outSlotImPr, &( output_f[chA][nBins * slot + offsetSamples] ), nBins, cldfbSynDec[chA] );
}
}
diff --git a/lib_dec/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c
similarity index 99%
rename from lib_dec/ivas_dirac_decorr_dec.c
rename to lib_rend/ivas_dirac_decorr_dec.c
index 3687ed53b186321928374b7f55b33e8f6d99a998..e8311888819097d56c1a30837fe588d2cd501046 100644
--- a/lib_dec/ivas_dirac_decorr_dec.c
+++ b/lib_rend/ivas_dirac_decorr_dec.c
@@ -37,9 +37,9 @@
#include "cnst.h"
#include "prot.h"
#include "ivas_prot.h"
+#include "ivas_prot_rend.h"
#include "ivas_stat_dec.h"
#include "ivas_cnst.h"
-#include "ivas_rom_com.h"
#include "ivas_rom_dec.h"
#ifdef DEBUGGING
#include "debug.h"
diff --git a/lib_dec/ivas_dirac_onsets_dec.c b/lib_rend/ivas_dirac_onsets_dec.c
similarity index 99%
rename from lib_dec/ivas_dirac_onsets_dec.c
rename to lib_rend/ivas_dirac_onsets_dec.c
index c094b45ff68aa32a7770f677b3c61e70b763f127..8a03dc2c50da814c0788b1c81325e87633e0ec46 100644
--- a/lib_dec/ivas_dirac_onsets_dec.c
+++ b/lib_rend/ivas_dirac_onsets_dec.c
@@ -36,6 +36,7 @@
#include "cnst.h"
#include "prot.h"
#include "ivas_prot.h"
+#include "ivas_prot_rend.h"
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include "ivas_rom_dec.h"
diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c
old mode 100755
new mode 100644
similarity index 85%
rename from lib_dec/ivas_dirac_output_synthesis_dec.c
rename to lib_rend/ivas_dirac_output_synthesis_dec.c
index 4f25d5a465f606d87e22439f962df2a2a1fd1fb3..2788c7f0e17eed921e6e0bcc575dcc2bd36bd42f
--- a/lib_dec/ivas_dirac_output_synthesis_dec.c
+++ b/lib_rend/ivas_dirac_output_synthesis_dec.c
@@ -37,6 +37,7 @@
#include "cnst.h"
#include "prot.h"
#include "ivas_prot.h"
+#include "ivas_prot_rend.h"
#include "ivas_stat_dec.h"
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
@@ -87,11 +88,12 @@ static void normalizePanningGains( float *direct_response, const int16_t num_cha
*------------------------------------------------------------------------*/
ivas_error ivas_dirac_dec_output_synthesis_open(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- RENDERER_TYPE renderer_type, /* i : renderer type */
- const int16_t nchan_transport, /* i : number of transport channels */
- const int32_t output_Fs, /* i : output sampling rate */
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ RENDERER_TYPE renderer_type, /* i : renderer type */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
)
{
int16_t idx, ch_idx;
@@ -101,20 +103,20 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
float temp_alpha_synthesis[CLDFB_NO_CHANNELS_MAX];
/* pointers to structs for allocation */
- DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params );
- DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state );
+ DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
+ DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
/* check / set input parameters */
- assert( hDirAC->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!" );
- assert( hDirAC->hOutSetup.nchan_out_woLFE > 0 && "Error: Number of output channels > 0!" );
- assert( hDirAC->num_outputs_diff > 0 );
- assert( hDirAC->slot_size > 0 );
- assert( hDirAC->hOutSetup.is_loudspeaker_setup == 0 || hDirAC->hOutSetup.is_loudspeaker_setup == 1 );
- assert( hDirAC->diffuse_response_function != NULL );
+ assert( hSpatParamRendCom->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!" );
+ assert( hDirACRend->hOutSetup.nchan_out_woLFE > 0 && "Error: Number of output channels > 0!" );
+ assert( hDirACRend->num_outputs_diff > 0 );
+ assert( hSpatParamRendCom->slot_size > 0 );
+ assert( hDirACRend->hOutSetup.is_loudspeaker_setup == 0 || hDirACRend->hOutSetup.is_loudspeaker_setup == 1 );
+ assert( hDirACRend->diffuse_response_function != NULL );
- if ( hDirAC->proto_signal_decorr_on )
+ if ( hDirACRend->proto_signal_decorr_on )
{
- dirac_output_synthesis_params->max_band_decorr = hDirAC->h_freq_domain_decorr_ap_params->max_band_decorr;
+ dirac_output_synthesis_params->max_band_decorr = hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr;
}
else
{
@@ -126,16 +128,16 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
*-----------------------------------------------------------------*/
dirac_output_synthesis_state->diffuse_responses_square = NULL;
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO )
{
if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( 2 * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
}
- else if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
+ else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
{
- if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( hDirAC->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
@@ -143,16 +145,16 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
/* prototype power buffers */
dirac_output_synthesis_state->proto_power_smooth_prev = NULL;
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
{
- if ( ( dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_protos_dir * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
}
- if ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) )
+ if ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) )
{
- if ( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
@@ -171,42 +173,42 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
/* target PSD buffers */
if ( hodirac_flag )
{
- size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS;
+ size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS;
}
else
{
- size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir;
+ size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir;
}
if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL;
- if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
}
else
{
- if ( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
{
- if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
}
else
{
- if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
@@ -219,23 +221,23 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
}
- else if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirAC->synthesisConf != DIRAC_SYNTHESIS_MONO )
+ else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO )
{
- if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
}
else
{
- if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
@@ -246,32 +248,32 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
*-----------------------------------------------------------------*/
/* compute alpha */
- if ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) )
+ if ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) )
{
- computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hDirAC->slot_size, hDirAC->num_freq_bands, hDirAC->frequency_axis, output_Fs );
+ computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs );
if ( ( dirac_output_synthesis_params->alpha_synthesis = (float *) malloc( dirac_output_synthesis_params->numAlphas * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis, dirac_output_synthesis_params->numAlphas );
- computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hDirAC->slot_size, hDirAC->num_freq_bands, hDirAC->frequency_axis, output_Fs );
+ computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs );
if ( ( dirac_output_synthesis_params->alpha_synthesis_fast = (float *) malloc( dirac_output_synthesis_params->numAlphasFast * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis_fast, dirac_output_synthesis_params->numAlphasFast );
- if ( ( dirac_output_synthesis_state->reference_power_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->reference_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
- if ( ( dirac_output_synthesis_state->direction_smoothness_prev = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL )
+ if ( ( dirac_output_synthesis_state->direction_smoothness_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
}
- set_zero( dirac_output_synthesis_state->reference_power_smooth_prev, hDirAC->num_freq_bands );
- set_zero( dirac_output_synthesis_state->direction_smoothness_prev, hDirAC->num_freq_bands );
+ set_zero( dirac_output_synthesis_state->reference_power_smooth_prev, hSpatParamRendCom->num_freq_bands );
+ set_zero( dirac_output_synthesis_state->direction_smoothness_prev, hSpatParamRendCom->num_freq_bands );
}
else
{
@@ -288,13 +290,13 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
}
/* prepare diffuse response function */
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO )
{
num_diffuse_responses = 2;
}
else
{
- num_diffuse_responses = hDirAC->hOutSetup.nchan_out_woLFE;
+ num_diffuse_responses = hDirACRend->hOutSetup.nchan_out_woLFE;
}
if ( dirac_output_synthesis_state->diffuse_responses_square != NULL )
@@ -302,34 +304,34 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
for ( ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx )
{
/*dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = pow(dirac_output_synthesis_params->diffuse_response_function[ch_idx]/max_response, 2.0f);*/
- tmp = hDirAC->diffuse_response_function[ch_idx];
+ tmp = hDirACRend->diffuse_response_function[ch_idx];
dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = tmp * tmp;
}
}
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
int16_t diff_compensation_order;
float diff_nrg_total, diff_nrg, diff_nrg_trans, diff_nrg_decorr;
diff_compensation_order = nchan_transport >= 3 ? 3 : 2; /* compensate missing diffuseness modelling up order 2, except for HR*/
- diff_compensation_order = min( diff_compensation_order, hDirAC->hOutSetup.ambisonics_order );
+ diff_compensation_order = min( diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order );
diff_nrg_total = 0;
diff_nrg_trans = 0;
diff_nrg_decorr = 0;
for ( ch_idx = 0; ch_idx < ( diff_compensation_order + 1 ) * ( diff_compensation_order + 1 ); ch_idx++ )
{
- diff_nrg = hDirAC->diffuse_response_function[ch_idx] * hDirAC->diffuse_response_function[ch_idx];
+ diff_nrg = hDirACRend->diffuse_response_function[ch_idx] * hDirACRend->diffuse_response_function[ch_idx];
diff_nrg_total += diff_nrg;
/* is it a transport channel?*/
- if ( ch_idx == 0 || hDirAC->proto_index_dir[ch_idx] != 0 )
+ if ( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 )
{
diff_nrg_trans += diff_nrg;
}
/* is it a decorrelated or transport channel?*/
- if ( ch_idx < hDirAC->num_outputs_diff )
+ if ( ch_idx < hDirACRend->num_outputs_diff )
{
diff_nrg_decorr += diff_nrg;
}
@@ -354,9 +356,10 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
*------------------------------------------------------------------------*/
void ivas_dirac_dec_output_synthesis_init(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const int16_t nchan_out_woLFE, /* i : number of output audio channels without LFE */
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ const int16_t nchan_out_woLFE, /* i : number of output audio channels without LFE */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
)
{
int16_t size;
@@ -364,8 +367,8 @@ void ivas_dirac_dec_output_synthesis_init(
DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
- h_dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params );
- h_dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state );
+ h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
+ h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
/*-----------------------------------------------------------------*
* init outputSynthesisPSD_Init
@@ -374,45 +377,45 @@ void ivas_dirac_dec_output_synthesis_init(
/* initialize buffers */
if ( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev != NULL )
{
- set_zero( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir );
+ set_zero( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir );
}
if ( hodirac_flag )
{
- size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS;
+ size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS;
}
else
{
- size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir;
+ size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir;
}
set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size );
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff );
+ set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff );
}
- else if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD )
+ else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD )
{
- set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_diff );
+ set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff );
}
else
{
- set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir );
+ set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir );
}
if ( h_dirac_output_synthesis_state->proto_power_smooth_prev != NULL )
{
- set_zero( h_dirac_output_synthesis_state->proto_power_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_protos_dir );
+ set_zero( h_dirac_output_synthesis_state->proto_power_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir );
}
set_zero( h_dirac_output_synthesis_state->gains_dir_prev, size );
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- set_zero( h_dirac_output_synthesis_state->gains_diff_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff );
+ set_zero( h_dirac_output_synthesis_state->gains_diff_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff );
}
else
{
- set_zero( h_dirac_output_synthesis_state->gains_diff_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir );
+ set_zero( h_dirac_output_synthesis_state->gains_diff_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir );
}
if ( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev != NULL )
@@ -431,12 +434,12 @@ void ivas_dirac_dec_output_synthesis_init(
*------------------------------------------------------------------------*/
void ivas_dirac_dec_output_synthesis_close(
- DIRAC_DEC_HANDLE hDirAC /* i/o: DirAC handle */
+ DIRAC_REND_HANDLE hDirACRend /* i/o: DirAC handle */
)
{
/* pointers to structs for allocation */
- DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params );
- DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state );
+ DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
+ DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
/*-----------------------------------------------------------------*
* memory deallocation
@@ -537,15 +540,16 @@ void ivas_dirac_dec_output_synthesis_process_slot(
const int16_t *azimuth,
const int16_t *elevation,
const float *diffuseness,
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
const int16_t sh_rot_max_order,
const float *p_Rmat, /* i : rotation matrix */
const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */
const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */
const int16_t nchan_transport, /* i : number of transport channels*/
const int16_t md_idx,
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
-)
+ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
+ const int16_t dec_param_estim )
{
int16_t num_freq_bands, num_channels_dir;
int16_t num_freq_bands_diff, num_channels_diff;
@@ -555,8 +559,8 @@ void ivas_dirac_dec_output_synthesis_process_slot(
DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
- h_dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params );
- h_dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state );
+ h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
+ h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
h_dirac_output_synthesis_state->onset_filter = onset;
@@ -565,19 +569,20 @@ void ivas_dirac_dec_output_synthesis_process_slot(
*-----------------------------------------------------------------*/
/* collect some often used parameters */
- num_freq_bands = hDirAC->num_freq_bands;
- num_channels_dir = hDirAC->num_outputs_dir;
- num_channels_diff = hDirAC->num_outputs_diff;
+ num_freq_bands = hSpatParamRendCom->num_freq_bands;
+ num_channels_dir = hDirACRend->num_outputs_dir;
+ num_channels_diff = hDirACRend->num_outputs_diff;
num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr;
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS )
{
num_channels_dir = hOutSetup.nchan_out_woLFE;
}
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD && hodirac_flag )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD && hodirac_flag )
{
- ivas_dirac_dec_compute_directional_responses( hDirAC,
+ ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom,
+ hDirACRend,
hVBAPdata,
NULL,
azimuth,
@@ -589,43 +594,44 @@ void ivas_dirac_dec_output_synthesis_process_slot(
hodirac_flag );
}
- if ( hDirAC->hConfig->dec_param_estim == FALSE && hodirac_flag )
+ if ( dec_param_estim == FALSE && hodirac_flag )
{
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- v_multc( hDirAC->energy_ratio1[md_idx], -1.f, aux_buf, num_freq_bands );
+ v_multc( hSpatParamRendCom->energy_ratio1[md_idx], -1.f, aux_buf, num_freq_bands );
v_addc( aux_buf, 1.f, aux_buf, num_freq_bands );
- mvr2r( hDirAC->energy_ratio1[md_idx],
+ mvr2r( hSpatParamRendCom->energy_ratio1[md_idx],
h_dirac_output_synthesis_state->direct_power_factor,
num_freq_bands );
mvr2r( aux_buf,
h_dirac_output_synthesis_state->diffuse_power_factor,
num_freq_bands );
- v_multc( hDirAC->energy_ratio2[md_idx], -1.f, aux_buf, num_freq_bands );
+ v_multc( hSpatParamRendCom->energy_ratio2[md_idx], -1.f, aux_buf, num_freq_bands );
v_addc( aux_buf, 1.f, aux_buf, num_freq_bands );
- mvr2r( hDirAC->energy_ratio2[md_idx],
- &h_dirac_output_synthesis_state->direct_power_factor[hDirAC->num_freq_bands],
+ mvr2r( hSpatParamRendCom->energy_ratio2[md_idx],
+ &h_dirac_output_synthesis_state->direct_power_factor[hSpatParamRendCom->num_freq_bands],
num_freq_bands );
mvr2r( aux_buf,
- &h_dirac_output_synthesis_state->diffuse_power_factor[hDirAC->num_freq_bands],
+ &h_dirac_output_synthesis_state->diffuse_power_factor[hSpatParamRendCom->num_freq_bands],
num_freq_bands );
}
else
{
ivas_dirac_dec_compute_gain_factors( num_freq_bands,
- hDirAC->diffuseness_vector[md_idx],
+ hSpatParamRendCom->diffuseness_vector[md_idx],
h_dirac_output_synthesis_params->max_band_decorr,
h_dirac_output_synthesis_state->direct_power_factor,
h_dirac_output_synthesis_state->diffuse_power_factor );
}
}
- else // ( hDirAC->hConfig->dec_param_estim == TRUE )
- if ( hDirAC->hConfig->dec_param_estim == TRUE )
+ else // ( dec_param_estim == TRUE )
+ if ( dec_param_estim == TRUE )
{
/* compute direct responses */
- ivas_dirac_dec_compute_directional_responses( hDirAC,
+ ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom,
+ hDirACRend,
hVBAPdata,
NULL,
azimuth,
@@ -636,7 +642,7 @@ void ivas_dirac_dec_output_synthesis_process_slot(
p_Rmat,
hodirac_flag );
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
ivas_dirac_dec_compute_gain_factors( num_freq_bands,
diffuseness,
@@ -710,7 +716,7 @@ void ivas_dirac_dec_output_synthesis_process_slot(
for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ )
{
v_multc( h_dirac_output_synthesis_state->diffuse_power_factor,
- hDirAC->diffuse_response_function[ch_idx],
+ hDirACRend->diffuse_response_function[ch_idx],
aux_buf,
num_freq_bands_diff );
@@ -738,7 +744,7 @@ void ivas_dirac_dec_output_synthesis_process_slot(
{
computeTargetPSDs_diffuse_with_onsets( num_channels_dir,
num_freq_bands, h_dirac_output_synthesis_params->max_band_decorr,
- hDirAC->proto_index_diff,
+ hDirACRend->proto_index_diff,
h_dirac_output_synthesis_state->diffuse_power_factor,
reference_power,
h_dirac_output_synthesis_state->diffuse_responses_square,
@@ -749,7 +755,7 @@ void ivas_dirac_dec_output_synthesis_process_slot(
}
/* process other PSDs only slot wise for 4 transport channels */
- if ( hDirAC->hConfig->dec_param_estim == TRUE )
+ if ( dec_param_estim == TRUE )
{
computeTargetPSDs_direct( num_channels_dir, num_freq_bands, h_dirac_output_synthesis_state->direct_power_factor, reference_power, h_dirac_output_synthesis_state->direct_responses, h_dirac_output_synthesis_state->direct_responses_square, h_dirac_output_synthesis_state->cy_auto_dir_smooth, h_dirac_output_synthesis_state->cy_cross_dir_smooth );
@@ -769,13 +775,14 @@ void ivas_dirac_dec_output_synthesis_process_slot(
void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */
float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
const int16_t nchan_transport, /* i : number of transport channels */
const int16_t nbslots, /* i : number of slots to process */
const float *onset_filter,
float *diffuseness,
- const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
-)
+ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
+ const int16_t dec_param_estim )
{
int16_t buf_idx, ch_idx, i, l;
int16_t num_freq_bands, num_freq_bands_diff;
@@ -798,15 +805,15 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
float ratio[DIRAC_HO_NUMSECTORS * CLDFB_NO_CHANNELS_MAX];
/* collect some often used parameters */
- h_dirac_output_synthesis_params = hDirAC->h_output_synthesis_psd_params;
- h_dirac_output_synthesis_state = hDirAC->h_output_synthesis_psd_state;
- proto_direct_index = hDirAC->proto_index_dir;
+ h_dirac_output_synthesis_params = hDirACRend->h_output_synthesis_psd_params;
+ h_dirac_output_synthesis_state = hDirACRend->h_output_synthesis_psd_state;
+ proto_direct_index = hDirACRend->proto_index_dir;
- num_protos_dir = hDirAC->num_protos_dir;
- num_freq_bands = hDirAC->num_freq_bands;
+ num_protos_dir = hDirACRend->num_protos_dir;
+ num_freq_bands = hSpatParamRendCom->num_freq_bands;
num_freq_bands_diff = h_dirac_output_synthesis_params.max_band_decorr;
- num_channels_dir = hDirAC->num_outputs_dir;
- num_channels_diff = hDirAC->num_outputs_diff;
+ num_channels_dir = hDirACRend->num_outputs_dir;
+ num_channels_diff = hDirACRend->num_outputs_diff;
nchan_transport_foa = min( 4, nchan_transport );
@@ -816,7 +823,6 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
if ( hodirac_flag )
{
- assert( hDirAC->hConfig->dec_param_estim == FALSE );
/*Direct gain*/
for ( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ )
{
@@ -841,7 +847,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
for ( l = 0; l < num_freq_bands; l++ )
{
aux_buf[l] = 1.f - diffuseness[l];
- ratio[l] = 1.f - h_dirac_output_synthesis_state.direct_power_factor[hDirAC->num_freq_bands + l];
+ ratio[l] = 1.f - h_dirac_output_synthesis_state.direct_power_factor[hSpatParamRendCom->num_freq_bands + l];
ratio[l + num_freq_bands] = 1.f - ratio[l];
}
@@ -862,12 +868,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
for ( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ )
{
v_multc( h_dirac_output_synthesis_state.diffuse_power_factor,
- hDirAC->diffuse_response_function[ch_idx],
+ hDirACRend->diffuse_response_function[ch_idx],
&h_dirac_output_synthesis_state.cy_auto_diff_smooth[ch_idx * num_freq_bands_diff],
num_freq_bands_diff );
}
}
- else if ( hDirAC->hConfig->dec_param_estim == FALSE )
+ else if ( dec_param_estim == FALSE )
{
/*Direct gain*/
for ( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ )
@@ -902,7 +908,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
/*Diffuse gain*/
for ( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ )
{
- v_multc( h_dirac_output_synthesis_state.diffuse_power_factor, hDirAC->diffuse_response_function[ch_idx], &h_dirac_output_synthesis_state.cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], num_freq_bands_diff );
+ v_multc( h_dirac_output_synthesis_state.diffuse_power_factor, hDirACRend->diffuse_response_function[ch_idx], &h_dirac_output_synthesis_state.cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], num_freq_bands_diff );
}
}
@@ -1116,8 +1122,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
for ( l = 0; l < num_freq_bands_diff; l++ )
{
g = g1 * ( *( p_gains_diff++ ) ) + g2 * ( *( p_gains_diff_prev++ ) );
- output_real[l * num_channels_dir + hDirAC->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) ); /* maps ch_idx 5 to 8 */
- output_imag[l * num_channels_dir + hDirAC->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) );
+ output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) ); /* maps ch_idx 5 to 8 */
+ output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) );
}
}
else
@@ -1134,14 +1140,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
* Copy output or HOA decoder
*-----------------------------------------------------------------*/
- if ( hDirAC->hOutSetup.is_loudspeaker_setup && hDirAC->hoa_decoder != NULL )
+ if ( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL )
{
float *p_real, *p_imag;
const float *hoa_decoder;
- hoa_decoder = hDirAC->hoa_decoder;
+ hoa_decoder = hDirACRend->hoa_decoder;
- for ( ch_idx = 0; ch_idx < hDirAC->hOutSetup.nchan_out_woLFE; ch_idx++ )
+ for ( ch_idx = 0; ch_idx < hDirACRend->hOutSetup.nchan_out_woLFE; ch_idx++ )
{
p_real = RealBuffer[ch_idx][buf_idx];
p_imag = ImagBuffer[ch_idx][buf_idx];
@@ -1215,11 +1221,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls(
float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */
float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
const int16_t nbslots, /* i : number of slots to process */
float *diffuseness_vector,
float *reference_power_smooth,
- float qualityBasedSmFactor )
+ float qualityBasedSmFactor,
+ const int16_t enc_param_start_band )
{
int16_t buf_idx, num_freq_bands;
int16_t diff_start_band;
@@ -1252,24 +1260,24 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls(
push_wmops( "dirac_out_synth_sfr" );
- h_dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params );
- h_dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state );
- proto_direct_index = hDirAC->proto_index_dir;
- num_protos_dir = hDirAC->num_protos_dir;
- nchan_out_woLFE = hDirAC->hOutSetup.nchan_out_woLFE;
+ h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
+ h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
+ proto_direct_index = hDirACRend->proto_index_dir;
+ num_protos_dir = hDirACRend->num_protos_dir;
+ nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
/* collect some often used parameters */
- num_freq_bands = hDirAC->num_freq_bands;
+ num_freq_bands = hSpatParamRendCom->num_freq_bands;
/*-----------------------------------------------------------------*
* compute target PSDs
*-----------------------------------------------------------------*/
- if ( hDirAC->hConfig->enc_param_start_band == 0 )
+ if ( enc_param_start_band == 0 )
{
diff_start_band = h_dirac_output_synthesis_params->use_onset_filters == 1 ? h_dirac_output_synthesis_params->max_band_decorr : 0;
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO )
{
nchan_target_psds = 2;
}
@@ -1297,11 +1305,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls(
* compute variables for stereo transport signal type detection
*-----------------------------------------------------------------*/
- if ( hDirAC->masa_stereo_type_detect != NULL )
+ if ( hDirACRend->masa_stereo_type_detect != NULL )
{
+ MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect = hDirACRend->masa_stereo_type_detect;
+
p_cy_auto_dir_smooth = h_dirac_output_synthesis_state->cy_auto_dir_smooth;
p_cy_auto_diff_smooth = h_dirac_output_synthesis_state->cy_auto_diff_smooth;
- if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO )
{
target_power_y = p_cy_auto_dir_smooth[num_freq_bands] / ( sqrtf( h_dirac_output_synthesis_state->direct_power_factor[0] ) + EPSILON );
target_power_y += p_cy_auto_diff_smooth[num_freq_bands] / ( sqrtf( h_dirac_output_synthesis_state->diffuse_power_factor[0] ) + EPSILON );
@@ -1310,19 +1320,19 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls(
{
target_power_y = p_cy_auto_dir_smooth[num_freq_bands] + p_cy_auto_diff_smooth[num_freq_bands];
}
- subtract_power_y = hDirAC->masa_stereo_type_detect->subtract_power_y;
+ subtract_power_y = masa_stereo_type_detect->subtract_power_y;
a = 0.0004f; /* Temporal smoothing coefficient */
b = 1.0f - a; /* Temporal smoothing coefficient */
- hDirAC->masa_stereo_type_detect->target_power_y_smooth = a * target_power_y + b * hDirAC->masa_stereo_type_detect->target_power_y_smooth;
- hDirAC->masa_stereo_type_detect->subtract_power_y_smooth = a * subtract_power_y + b * hDirAC->masa_stereo_type_detect->subtract_power_y_smooth;
+ masa_stereo_type_detect->target_power_y_smooth = a * target_power_y + b * masa_stereo_type_detect->target_power_y_smooth;
+ masa_stereo_type_detect->subtract_power_y_smooth = a * subtract_power_y + b * masa_stereo_type_detect->subtract_power_y_smooth;
- subtract_target_ratio = hDirAC->masa_stereo_type_detect->subtract_power_y_smooth / ( hDirAC->masa_stereo_type_detect->target_power_y_smooth + EPSILON );
+ subtract_target_ratio = masa_stereo_type_detect->subtract_power_y_smooth / ( masa_stereo_type_detect->target_power_y_smooth + EPSILON );
subtract_target_ratio_db = 10.0f * log10f( subtract_target_ratio );
- hDirAC->masa_stereo_type_detect->subtract_target_ratio_db = subtract_target_ratio_db;
+ masa_stereo_type_detect->subtract_target_ratio_db = subtract_target_ratio_db;
- hDirAC->masa_stereo_type_detect->subtract_power_y = 0.0f;
+ masa_stereo_type_detect->subtract_power_y = 0.0f;
}
/*-----------------------------------------------------------------*
@@ -1731,9 +1741,10 @@ static void ivas_dirac_dec_get_response_split_order(
*------------------------------------------------------------------------*/
void ivas_dirac_dec_compute_directional_responses(
- DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */
- const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */
- const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */
+ const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
const int16_t *azimuth,
const int16_t *elevation,
const int16_t md_idx,
@@ -1761,24 +1772,24 @@ void ivas_dirac_dec_compute_directional_responses(
elevation2 = NULL;
transport_signal_type = MASA_STEREO_NOT_DEFINED;
- if ( hDirAC->masa_stereo_type_detect != NULL )
+ if ( hDirACRend->masa_stereo_type_detect != NULL )
{
- dipole_freq_range[0] = hDirAC->masa_stereo_type_detect->dipole_freq_range[0];
- dipole_freq_range[1] = hDirAC->masa_stereo_type_detect->dipole_freq_range[1];
- transport_signal_type = hDirAC->masa_stereo_type_detect->masa_stereo_type;
+ dipole_freq_range[0] = hDirACRend->masa_stereo_type_detect->dipole_freq_range[0];
+ dipole_freq_range[1] = hDirACRend->masa_stereo_type_detect->dipole_freq_range[1];
+ transport_signal_type = hDirACRend->masa_stereo_type_detect->masa_stereo_type;
}
- num_channels_dir = hDirAC->num_outputs_dir;
- if ( hDirAC->numSimultaneousDirections == 2 )
+ num_channels_dir = hDirACRend->num_outputs_dir;
+ if ( hSpatParamRendCom->numSimultaneousDirections == 2 )
{
- azimuth2 = hDirAC->azimuth2[md_idx];
- elevation2 = hDirAC->elevation2[md_idx];
+ azimuth2 = hSpatParamRendCom->azimuth2[md_idx];
+ elevation2 = hSpatParamRendCom->elevation2[md_idx];
}
codingBand = -1;
assert( num_channels_dir <= MAX_OUTPUT_CHANNELS && "Number of channels is too high" );
- for ( k = 0; k < hDirAC->num_freq_bands; ++k )
+ for ( k = 0; k < hSpatParamRendCom->num_freq_bands; ++k )
{
if ( hMasa != NULL && k == MASA_band_grouping_24[hMasa->data.band_mapping[codingBand + 1]] )
{
@@ -1787,24 +1798,24 @@ void ivas_dirac_dec_compute_directional_responses(
if ( hMasa != NULL && k > MASA_band_grouping_24[hMasa->data.band_mapping[codingBand]] &&
k < MASA_band_grouping_24[hMasa->data.band_mapping[codingBand + 1]] &&
- k != hDirAC->h_output_synthesis_psd_params.max_band_decorr )
+ k != hDirACRend->h_output_synthesis_psd_params.max_band_decorr )
{
/* Panning gains have to be computed only for the first bin of the coding band in MASA, for other bins the previous values can be used */
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
{
- mvr2r_inc( &hDirAC->h_output_synthesis_psd_state.direct_responses_square[k - 1],
- hDirAC->num_freq_bands, &hDirAC->h_output_synthesis_psd_state.direct_responses_square[k],
- hDirAC->num_freq_bands, num_channels_dir );
+ mvr2r_inc( &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k - 1],
+ hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k],
+ hSpatParamRendCom->num_freq_bands, num_channels_dir );
}
- mvr2r_inc( &hDirAC->h_output_synthesis_psd_state.direct_responses[k - 1],
- hDirAC->num_freq_bands,
- &hDirAC->h_output_synthesis_psd_state.direct_responses[k],
- hDirAC->num_freq_bands, num_channels_dir );
+ mvr2r_inc( &hDirACRend->h_output_synthesis_psd_state.direct_responses[k - 1],
+ hSpatParamRendCom->num_freq_bands,
+ &hDirACRend->h_output_synthesis_psd_state.direct_responses[k],
+ hSpatParamRendCom->num_freq_bands, num_channels_dir );
}
else
{
/* HOA3 PANNING */
- if ( hDirAC->panningConf == DIRAC_PANNING_HOA3 )
+ if ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 )
{
set_f( direct_response_hoa, 1.0f, MAX_OUTPUT_CHANNELS );
set_f( direct_response_dir2, 1.0f, MAX_OUTPUT_CHANNELS );
@@ -1820,36 +1831,36 @@ void ivas_dirac_dec_compute_directional_responses(
}
else
{
- ivas_dirac_dec_get_response( azimuth[k], elevation[k], direct_response_hoa, hDirAC->hOutSetup.ambisonics_order );
+ ivas_dirac_dec_get_response( azimuth[k], elevation[k], direct_response_hoa, hDirACRend->hOutSetup.ambisonics_order );
if ( hodirac_flag )
{
- ivas_dirac_dec_get_response( azimuth2[k], elevation2[k], direct_response_dir2, hDirAC->hOutSetup.ambisonics_order );
+ ivas_dirac_dec_get_response( azimuth2[k], elevation2[k], direct_response_dir2, hDirACRend->hOutSetup.ambisonics_order );
}
}
- if ( hMasa == NULL && hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hMasa == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD )
{
- mvr2r_inc( direct_response_hoa, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k], hDirAC->num_freq_bands, num_channels_dir );
+ mvr2r_inc( direct_response_hoa, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir );
if ( hodirac_flag )
{
- mvr2r_inc( direct_response_dir2, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k + hDirAC->num_freq_bands * num_channels_dir], hDirAC->num_freq_bands, num_channels_dir );
+ mvr2r_inc( direct_response_dir2, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k + hSpatParamRendCom->num_freq_bands * num_channels_dir], hSpatParamRendCom->num_freq_bands, num_channels_dir );
}
}
- else if ( ( ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( hMasa != NULL ) ) ||
- hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO )
+ else if ( ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( hMasa != NULL ) ) ||
+ hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO )
{
/* Synthesize the first direction */
- spreadCoherencePanningHoa( azimuth[k], elevation[k], hDirAC->spreadCoherence[md_idx][k], direct_response_hoa, num_channels_dir, hDirAC->hOutSetup.ambisonics_order );
+ spreadCoherencePanningHoa( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], direct_response_hoa, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order );
/* Synthesize the second direction and combine the gains */
- if ( hDirAC->numSimultaneousDirections == 2 )
+ if ( hSpatParamRendCom->numSimultaneousDirections == 2 )
{
- spreadCoherencePanningHoa( azimuth2[k], elevation2[k], hDirAC->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hDirAC->hOutSetup.ambisonics_order );
+ spreadCoherencePanningHoa( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order );
/* Combine gains from the two directions */
- totalDirect = hDirAC->energy_ratio1[md_idx][k] + hDirAC->energy_ratio2[md_idx][k] + EPSILON;
- directRatio[0] = hDirAC->energy_ratio1[md_idx][k] / totalDirect;
- directRatio[1] = hDirAC->energy_ratio2[md_idx][k] / totalDirect;
+ totalDirect = hSpatParamRendCom->energy_ratio1[md_idx][k] + hSpatParamRendCom->energy_ratio2[md_idx][k] + EPSILON;
+ directRatio[0] = hSpatParamRendCom->energy_ratio1[md_idx][k] / totalDirect;
+ directRatio[1] = hSpatParamRendCom->energy_ratio2[md_idx][k] / totalDirect;
for ( l = 0; l < num_channels_dir; l++ )
{
direct_response_hoa[l] *= directRatio[0];
@@ -1868,10 +1879,10 @@ void ivas_dirac_dec_compute_directional_responses(
/* Set computed gains */
direct_response = direct_response_hoa;
- if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
+ if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
{
v_mult( direct_response, direct_response, direct_response_square, num_channels_dir );
- mvr2r_inc( direct_response_square, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses_square[k], hDirAC->num_freq_bands, num_channels_dir );
+ mvr2r_inc( direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir );
if ( transport_signal_type == MASA_STEREO_SPACED_MICS )
{
@@ -1883,33 +1894,33 @@ void ivas_dirac_dec_compute_directional_responses(
}
else
{
- set_f( direct_response, 1.0f, hDirAC->num_protos_ambi );
+ set_f( direct_response, 1.0f, hDirACRend->num_protos_ambi );
}
}
- mvr2r_inc( direct_response, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k], hDirAC->num_freq_bands, num_channels_dir );
+ mvr2r_inc( direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir );
}
else
{
assert( 0 && "Not supported synthesis method!" );
}
}
- else if ( hDirAC->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/
+ else if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/
{
/* Synthesize the first direction */
- spreadCoherencePanningVbap( azimuth[k], elevation[k], hDirAC->spreadCoherence[md_idx][k], direct_response_ls, num_channels_dir, hVBAPdata );
+ spreadCoherencePanningVbap( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], direct_response_ls, num_channels_dir, hVBAPdata );
normalizePanningGains( direct_response_ls, num_channels_dir );
/* Synthesize the second direction and combine the gains */
- if ( hDirAC->numSimultaneousDirections == 2 )
+ if ( hSpatParamRendCom->numSimultaneousDirections == 2 )
{
- spreadCoherencePanningVbap( azimuth2[k], elevation2[k], hDirAC->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hVBAPdata );
+ spreadCoherencePanningVbap( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hVBAPdata );
normalizePanningGains( direct_response_dir2, num_channels_dir );
/* Combine gains from the two directions */
- totalDirect = hDirAC->energy_ratio1[md_idx][k] + hDirAC->energy_ratio2[md_idx][k] + EPSILON;
- directRatio[0] = hDirAC->energy_ratio1[md_idx][k] / totalDirect;
- directRatio[1] = hDirAC->energy_ratio2[md_idx][k] / totalDirect;
+ totalDirect = hSpatParamRendCom->energy_ratio1[md_idx][k] + hSpatParamRendCom->energy_ratio2[md_idx][k] + EPSILON;
+ directRatio[0] = hSpatParamRendCom->energy_ratio1[md_idx][k] / totalDirect;
+ directRatio[1] = hSpatParamRendCom->energy_ratio2[md_idx][k] / totalDirect;
for ( l = 0; l < num_channels_dir; l++ )
{
direct_response_ls[l] *= directRatio[0];
@@ -1924,12 +1935,12 @@ void ivas_dirac_dec_compute_directional_responses(
int16_t num_channels_surrCoh;
num_channels_surrCoh = num_channels_dir;
- num_channels_surrCoh -= hDirAC->num_ele_spk_no_diffuse_rendering;
+ num_channels_surrCoh -= hDirACRend->num_ele_spk_no_diffuse_rendering;
for ( l = 0; l < num_channels_dir; l++ )
{
direct_response_ls[l] *= sqrtf( 1.0f - surCohRatio[k] );
- if ( hDirAC->diffuse_response_function[l] > 0.f )
+ if ( hDirACRend->diffuse_response_function[l] > 0.f )
{
direct_response_ls[l] += sqrtf( surCohRatio[k] / (float) num_channels_surrCoh );
}
@@ -1940,8 +1951,8 @@ void ivas_dirac_dec_compute_directional_responses(
/* Set computed gains */
direct_response = direct_response_ls;
v_mult( direct_response, direct_response, direct_response_square, num_channels_dir );
- mvr2r_inc( direct_response_square, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses_square[k], hDirAC->num_freq_bands, num_channels_dir );
- mvr2r_inc( direct_response, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k], hDirAC->num_freq_bands, num_channels_dir );
+ mvr2r_inc( direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir );
+ mvr2r_inc( direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir );
}
else
{
diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c
new file mode 100644
index 0000000000000000000000000000000000000000..84ce30d1bce60f83798b233d2c0286ef559c9e73
--- /dev/null
+++ b/lib_rend/ivas_dirac_rend.c
@@ -0,0 +1,2030 @@
+/******************************************************************************************************
+
+(C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+contributors to this repository. All Rights Reserved.
+
+This software is protected by copyright law and by international treaties.
+The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
+Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+contributors to this repository retain full ownership rights in their respective contributions in
+the software. This notice grants no license of any kind, including but not limited to patent
+license, nor is any license granted by implication, estoppel or otherwise.
+
+Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
+contributions.
+
+This software is provided "AS IS", without any express or implied warranties. The software is in the
+development stage. It is intended exclusively for experts who have experience with such software and
+solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
+and fitness for a particular purpose are hereby disclaimed and excluded.
+
+Any dispute, controversy or claim arising under or in relation to providing this software shall be
+submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
+accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
+the United Nations Convention on Contracts on the International Sales of Goods.
+
+*******************************************************************************************************/
+
+#include
+#include
+#include "options.h"
+#include
+#include "cnst.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "ivas_prot_rend.h"
+#include "ivas_cnst.h"
+#include "ivas_rom_dec.h"
+#ifdef DEBUGGING
+#include "debug.h"
+#endif
+#include "wmc_auto.h"
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_allocate_parameters()
+ *
+ * Allocate and initialize DirAC parameters
+ *-------------------------------------------------------------------------*/
+
+ivas_error ivas_dirac_allocate_parameters(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */
+ const int16_t params_flag /* i : set of parameters flag */
+)
+{
+ int16_t i;
+
+ if ( params_flag == 1 )
+ {
+ if ( ( hSpatParamRendCom->azimuth = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ if ( ( hSpatParamRendCom->elevation = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ if ( ( hSpatParamRendCom->diffuseness_vector = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ if ( ( hSpatParamRendCom->energy_ratio1 = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ if ( ( hSpatParamRendCom->spreadCoherence = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ if ( ( hSpatParamRendCom->surroundingCoherence = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ for ( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ )
+ {
+ if ( ( hSpatParamRendCom->azimuth[i] = (int16_t *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( int16_t ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_s( hSpatParamRendCom->azimuth[i], 0, hSpatParamRendCom->num_freq_bands );
+
+ if ( ( hSpatParamRendCom->elevation[i] = (int16_t *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( int16_t ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_s( hSpatParamRendCom->elevation[i], 0, hSpatParamRendCom->num_freq_bands );
+
+ if ( ( hSpatParamRendCom->diffuseness_vector[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_f( hSpatParamRendCom->diffuseness_vector[i], 1.0f, hSpatParamRendCom->num_freq_bands );
+
+ if ( ( hSpatParamRendCom->energy_ratio1[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_f( hSpatParamRendCom->energy_ratio1[i], 0.0f, hSpatParamRendCom->num_freq_bands );
+
+ if ( ( hSpatParamRendCom->spreadCoherence[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_f( hSpatParamRendCom->spreadCoherence[i], 0.0f, hSpatParamRendCom->num_freq_bands );
+
+ if ( ( hSpatParamRendCom->surroundingCoherence[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_f( hSpatParamRendCom->surroundingCoherence[i], 0.0f, hSpatParamRendCom->num_freq_bands );
+ }
+ }
+ else if ( params_flag == 2 )
+ {
+ if ( ( hSpatParamRendCom->azimuth2 = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ if ( ( hSpatParamRendCom->elevation2 = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ if ( ( hSpatParamRendCom->energy_ratio2 = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ if ( ( hSpatParamRendCom->spreadCoherence2 = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+
+ for ( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ )
+ {
+ if ( ( hSpatParamRendCom->azimuth2[i] = (int16_t *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( int16_t ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_s( hSpatParamRendCom->azimuth2[i], 0, hSpatParamRendCom->num_freq_bands );
+
+ if ( ( hSpatParamRendCom->elevation2[i] = (int16_t *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( int16_t ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_s( hSpatParamRendCom->elevation2[i], 0, hSpatParamRendCom->num_freq_bands );
+
+ if ( ( hSpatParamRendCom->energy_ratio2[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_f( hSpatParamRendCom->energy_ratio2[i], 0.0f, hSpatParamRendCom->num_freq_bands );
+
+ if ( ( hSpatParamRendCom->spreadCoherence2[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
+ }
+ set_f( hSpatParamRendCom->spreadCoherence2[i], 0.0f, hSpatParamRendCom->num_freq_bands );
+ }
+ }
+
+ return IVAS_ERR_OK;
+}
+
+
+ivas_error ivas_spat_hSpatParamRendCom_config(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: IVAS decoder structure */
+ const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
+ const int16_t dec_param_estim_flag,
+ const IVAS_FORMAT ivas_format,
+ const MC_MODE mc_mode,
+ const int32_t output_Fs,
+ const int16_t hodirac_flag )
+{
+ ivas_error error;
+ int16_t map_idx;
+ DIRAC_CONFIG_FLAG flag_config;
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
+
+ flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp;
+ error = IVAS_ERR_OK;
+
+ hSpatParamRendCom = NULL;
+
+ if ( flag_config == DIRAC_RECONFIGURE )
+ {
+ hSpatParamRendCom = *hSpatParamRendCom_out;
+ }
+ else if ( flag_config == DIRAC_OPEN )
+ {
+ /*-----------------------------------------------------------------*
+ * prepare library opening
+ *-----------------------------------------------------------------*/
+
+ if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC meta\n" ) );
+ }
+
+ *hSpatParamRendCom_out = hSpatParamRendCom;
+ }
+
+
+ if ( flag_config == DIRAC_OPEN )
+ {
+ hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
+ set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
+ set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
+ hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
+ hSpatParamRendCom->subframes_rendered = 0;
+ hSpatParamRendCom->slots_rendered = 0;
+ hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
+ hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
+ }
+
+ /*-----------------------------------------------------------------*
+ * set input parameters
+ *-----------------------------------------------------------------*/
+
+ if ( ivas_format == SBA_FORMAT && flag_config == DIRAC_RECONFIGURE )
+ {
+ if ( hodirac_flag && hSpatParamRendCom->azimuth2 == NULL )
+ {
+ if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ else if ( !hodirac_flag && hSpatParamRendCom->azimuth2 != NULL )
+ {
+ ivas_dirac_deallocate_parameters( hSpatParamRendCom, 2 );
+ }
+ }
+
+ if ( flag_config == DIRAC_OPEN )
+ {
+ hSpatParamRendCom->dirac_md_buffer_length = 0;
+ hSpatParamRendCom->dirac_bs_md_write_idx = 0;
+ hSpatParamRendCom->dirac_read_idx = 0;
+ if ( mc_mode == MC_MODE_MCMASA )
+ {
+ hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
+
+ set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
+ for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ )
+ {
+ hSpatParamRendCom->render_to_md_map[map_idx] = map_idx;
+ }
+ }
+ else if ( ivas_format == MASA_FORMAT )
+ {
+ hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR;
+ hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR;
+
+ set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
+ for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ )
+ {
+ hSpatParamRendCom->render_to_md_map[map_idx] = map_idx;
+ }
+ }
+ else
+ {
+ int16_t num_slots_in_subfr;
+ num_slots_in_subfr = dec_param_estim_flag ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1;
+ hSpatParamRendCom->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR );
+ hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR;
+ hSpatParamRendCom->dirac_read_idx = 0;
+
+ set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
+ for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ )
+ {
+ hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr;
+ }
+ }
+
+ if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( ivas_format == MASA_FORMAT || ( ivas_format == SBA_FORMAT && hodirac_flag ) )
+ {
+ if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ else
+ {
+ hSpatParamRendCom->azimuth2 = NULL;
+ hSpatParamRendCom->elevation2 = NULL;
+ hSpatParamRendCom->energy_ratio2 = NULL;
+ hSpatParamRendCom->spreadCoherence2 = NULL;
+ }
+ }
+
+ return error;
+}
+
+
+void ivas_spat_hSpatParamRendCom_close(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out )
+{
+ if ( hSpatParamRendCom_out == NULL || *hSpatParamRendCom_out == NULL )
+ {
+ return;
+ }
+
+ ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 );
+ ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 );
+
+ free( *hSpatParamRendCom_out );
+ *hSpatParamRendCom_out = NULL;
+
+ return;
+}
+
+void ivas_dirac_rend_close(
+ DIRAC_REND_HANDLE *hDirACRend_out )
+{
+ int16_t i, j;
+ DIRAC_REND_HANDLE hDirACRend;
+
+ if ( hDirACRend_out == NULL || *hDirACRend_out == NULL )
+ {
+ return;
+ }
+
+ hDirACRend = *hDirACRend_out;
+
+ /* close Output synthesis sub-module */
+ ivas_dirac_dec_output_synthesis_close( hDirACRend );
+
+ /* close Decorrelator sub-module */
+ if ( hDirACRend->proto_signal_decorr_on )
+ {
+ ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
+ }
+
+ /* Params */
+
+ /* free frequency axis buffer */
+ if ( hDirACRend->frequency_axis != NULL )
+ {
+ free( hDirACRend->frequency_axis );
+ hDirACRend->frequency_axis = NULL;
+ }
+
+ if ( hDirACRend->diffuse_response_function != NULL )
+ {
+ free( hDirACRend->diffuse_response_function );
+ hDirACRend->diffuse_response_function = NULL;
+ }
+
+ if ( hDirACRend->hoa_encoder != NULL )
+ {
+ free( hDirACRend->hoa_encoder );
+ hDirACRend->hoa_encoder = NULL;
+ }
+
+ /* prototype indexing */
+ if ( hDirACRend->proto_index_dir != NULL )
+ {
+ free( hDirACRend->proto_index_dir );
+ hDirACRend->proto_index_dir = NULL;
+ }
+
+ if ( hDirACRend->proto_index_diff != NULL )
+ {
+ free( hDirACRend->proto_index_diff );
+ hDirACRend->proto_index_dir = NULL;
+ }
+
+ /* States */
+
+ /* free prototype signal buffers */
+ if ( hDirACRend->proto_frame_f != NULL )
+ {
+ free( hDirACRend->proto_frame_f );
+ hDirACRend->proto_frame_f = NULL;
+ }
+
+ for ( i = 0; i < DIRAC_NUM_DIMS; i++ )
+ {
+ for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
+ {
+ if ( hDirACRend->buffer_intensity_real[i][j] != NULL )
+ {
+ free( hDirACRend->buffer_intensity_real[i][j] );
+ hDirACRend->buffer_intensity_real[i][j] = NULL;
+ }
+ }
+ }
+ if ( hDirACRend->buffer_energy != NULL )
+ {
+ free( hDirACRend->buffer_energy );
+ hDirACRend->buffer_energy = NULL;
+ }
+
+ if ( hDirACRend->masa_stereo_type_detect != NULL )
+ {
+ free( hDirACRend->masa_stereo_type_detect );
+ hDirACRend->masa_stereo_type_detect = NULL;
+ }
+
+ ivas_dirac_free_mem( &( hDirACRend->stack_mem ) );
+
+ free( *hDirACRend_out );
+ *hDirACRend_out = NULL;
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_deallocate_parameters()
+ *
+ * Deallocate DirAC parameters
+ *-------------------------------------------------------------------------*/
+
+void ivas_dirac_deallocate_parameters(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */
+ const int16_t params_flag /* i : set of parameters flag */
+)
+{
+ int16_t i;
+ int16_t md_buffer_length;
+
+ if ( hSpatParamRendCom == NULL )
+ {
+ return;
+ }
+
+ md_buffer_length = hSpatParamRendCom->dirac_md_buffer_length;
+
+ if ( params_flag == 1 )
+ {
+ if ( hSpatParamRendCom->azimuth != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->azimuth[i] != NULL )
+ {
+ free( hSpatParamRendCom->azimuth[i] );
+ hSpatParamRendCom->azimuth[i] = NULL;
+ }
+ }
+
+ free( hSpatParamRendCom->azimuth );
+ hSpatParamRendCom->azimuth = NULL;
+ }
+
+ if ( hSpatParamRendCom->elevation != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->elevation[i] != NULL )
+ {
+ free( hSpatParamRendCom->elevation[i] );
+ hSpatParamRendCom->elevation[i] = NULL;
+ }
+ }
+
+ free( hSpatParamRendCom->elevation );
+ hSpatParamRendCom->elevation = NULL;
+ }
+
+ if ( hSpatParamRendCom->energy_ratio1 != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->energy_ratio1[i] != NULL )
+ {
+ free( hSpatParamRendCom->energy_ratio1[i] );
+ hSpatParamRendCom->energy_ratio1[i] = NULL;
+ }
+ }
+ free( hSpatParamRendCom->energy_ratio1 );
+ hSpatParamRendCom->energy_ratio1 = NULL;
+ }
+
+ if ( hSpatParamRendCom->diffuseness_vector != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->diffuseness_vector[i] != NULL )
+ {
+ free( hSpatParamRendCom->diffuseness_vector[i] );
+ hSpatParamRendCom->diffuseness_vector[i] = NULL;
+ }
+ }
+
+ free( hSpatParamRendCom->diffuseness_vector );
+ hSpatParamRendCom->diffuseness_vector = NULL;
+ }
+
+ if ( hSpatParamRendCom->spreadCoherence != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->spreadCoherence[i] != NULL )
+ {
+ free( hSpatParamRendCom->spreadCoherence[i] );
+ hSpatParamRendCom->spreadCoherence[i] = NULL;
+ }
+ }
+ free( hSpatParamRendCom->spreadCoherence );
+ hSpatParamRendCom->spreadCoherence = NULL;
+ }
+
+ if ( hSpatParamRendCom->surroundingCoherence != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->surroundingCoherence[i] != NULL )
+ {
+ free( hSpatParamRendCom->surroundingCoherence[i] );
+ hSpatParamRendCom->surroundingCoherence[i] = NULL;
+ }
+ }
+ free( hSpatParamRendCom->surroundingCoherence );
+ hSpatParamRendCom->surroundingCoherence = NULL;
+ }
+ }
+ else if ( params_flag == 2 )
+ {
+ if ( hSpatParamRendCom->azimuth2 != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->azimuth2[i] != NULL )
+ {
+ free( hSpatParamRendCom->azimuth2[i] );
+ hSpatParamRendCom->azimuth2[i] = NULL;
+ }
+ }
+ free( hSpatParamRendCom->azimuth2 );
+ hSpatParamRendCom->azimuth2 = NULL;
+ }
+
+ if ( hSpatParamRendCom->elevation2 != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->elevation2[i] != NULL )
+ {
+ free( hSpatParamRendCom->elevation2[i] );
+ hSpatParamRendCom->elevation2[i] = NULL;
+ }
+ }
+ free( hSpatParamRendCom->elevation2 );
+ hSpatParamRendCom->elevation2 = NULL;
+ }
+
+ if ( hSpatParamRendCom->energy_ratio2 != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->energy_ratio2[i] != NULL )
+ {
+ free( hSpatParamRendCom->energy_ratio2[i] );
+ hSpatParamRendCom->energy_ratio2[i] = NULL;
+ }
+ }
+ free( hSpatParamRendCom->energy_ratio2 );
+ hSpatParamRendCom->energy_ratio2 = NULL;
+ }
+
+ if ( hSpatParamRendCom->spreadCoherence2 != NULL )
+ {
+ for ( i = 0; i < md_buffer_length; i++ )
+ {
+ if ( hSpatParamRendCom->spreadCoherence2[i] != NULL )
+ {
+ free( hSpatParamRendCom->spreadCoherence2[i] );
+ hSpatParamRendCom->spreadCoherence2[i] = NULL;
+ }
+ }
+ free( hSpatParamRendCom->spreadCoherence2 );
+ hSpatParamRendCom->spreadCoherence2 = NULL;
+ }
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_alloc_mem()
+ *
+ * Allocate stack memory for DirAC renderer
+ *------------------------------------------------------------------------*/
+
+ivas_error ivas_dirac_alloc_mem(
+ DIRAC_REND_HANDLE hDirACRend,
+ const RENDERER_TYPE renderer_type,
+ const int16_t num_freq_bands,
+ DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem,
+ const int16_t hodirac_flag )
+{
+ int16_t num_freq_bands_diff, size;
+ int16_t size_ho;
+ int16_t size_pf;
+ int16_t num_outputs_dir, num_outputs_diff;
+ int16_t num_protos_dir;
+
+ num_protos_dir = hDirACRend->num_protos_dir;
+
+ num_freq_bands_diff = hDirACRend->h_output_synthesis_psd_params.max_band_decorr;
+
+ num_outputs_dir = hDirACRend->num_outputs_dir;
+ num_outputs_diff = hDirACRend->num_outputs_diff;
+
+ size = num_freq_bands * num_outputs_dir;
+ if ( hodirac_flag )
+ {
+ size_ho = size * DIRAC_HO_NUMSECTORS;
+ size_pf = num_freq_bands * DIRAC_HO_NUMSECTORS;
+ }
+ else
+ {
+ size_ho = size;
+ size_pf = num_freq_bands;
+ }
+
+ /* PSD related buffers */
+ hDirAC_mem->cy_auto_dir_smooth = NULL;
+ hDirAC_mem->proto_power_smooth = NULL;
+ hDirAC_mem->proto_power_diff_smooth = NULL;
+ hDirAC_mem->direct_responses_square = NULL;
+ hDirAC_mem->frame_dec_f = NULL;
+ if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
+ {
+ if ( ( hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ set_zero( hDirAC_mem->cy_auto_dir_smooth, size );
+
+ if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ set_zero( hDirAC_mem->proto_power_smooth, size );
+
+ if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ set_zero( hDirAC_mem->proto_power_diff_smooth, size );
+
+ if ( ( hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ set_zero( hDirAC_mem->direct_responses_square, size );
+ if ( hDirACRend->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) )
+ {
+ if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ }
+ }
+ hDirACRend->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth;
+ hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth;
+ hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth;
+ hDirACRend->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square;
+
+ /* Target and smoothed nrg factors/gains */
+ if ( ( hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ set_zero( hDirAC_mem->cy_cross_dir_smooth, size );
+
+ if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
+ {
+ if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ set_zero( hDirAC_mem->cy_auto_diff_smooth, size );
+ }
+ else
+ {
+ if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ set_zero( hDirAC_mem->cy_auto_diff_smooth, num_outputs_diff * num_freq_bands_diff );
+ }
+ hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth;
+ hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth;
+
+ /*Responses (gains/factors)*/
+ if ( ( hDirAC_mem->direct_responses = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ set_zero( hDirAC_mem->direct_responses, size );
+
+
+ hDirACRend->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses;
+
+ /* Prototypes */
+ hDirAC_mem->proto_direct_buffer_f = NULL;
+ hDirAC_mem->proto_diffuse_buffer_f = NULL;
+ if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
+ {
+ if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+
+ if ( hDirACRend->proto_signal_decorr_on )
+ {
+ if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
+ {
+ if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ }
+ else
+ {
+ if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ }
+ }
+ }
+ hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f;
+ hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f;
+
+ /* Gains/power factors*/
+ hDirAC_mem->direct_power_factor = NULL;
+ hDirAC_mem->diffuse_power_factor = NULL;
+
+ if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
+ {
+ if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ }
+
+ hDirACRend->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor;
+ hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor;
+
+ hDirAC_mem->reference_power = NULL;
+ hDirAC_mem->onset_filter = NULL;
+ if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
+ {
+ if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
+ {
+ if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ if ( hDirACRend->proto_signal_decorr_on )
+ {
+ if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ }
+ }
+ }
+ else
+ {
+ if ( num_protos_dir > 2 )
+ {
+ if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ }
+
+ if ( hDirACRend->proto_signal_decorr_on )
+ {
+ if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
+ }
+ }
+ }
+
+ return IVAS_ERR_OK;
+}
+
+
+void ivas_dirac_free_mem(
+ DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem )
+{
+ if ( hDirAC_mem->cy_auto_dir_smooth != NULL )
+ {
+ free( hDirAC_mem->cy_auto_dir_smooth );
+ }
+ if ( hDirAC_mem->proto_power_smooth != NULL )
+ {
+ free( hDirAC_mem->proto_power_smooth );
+ }
+ if ( hDirAC_mem->proto_power_diff_smooth != NULL )
+ {
+ free( hDirAC_mem->proto_power_diff_smooth );
+ }
+ if ( hDirAC_mem->direct_responses_square != NULL )
+ {
+ free( hDirAC_mem->direct_responses_square );
+ }
+ if ( hDirAC_mem->frame_dec_f != NULL )
+ {
+ free( hDirAC_mem->frame_dec_f );
+ }
+ if ( hDirAC_mem->cy_cross_dir_smooth != NULL )
+ {
+ free( hDirAC_mem->cy_cross_dir_smooth );
+ }
+ if ( hDirAC_mem->cy_auto_diff_smooth != NULL )
+ {
+ free( hDirAC_mem->cy_auto_diff_smooth );
+ }
+ if ( hDirAC_mem->direct_responses != NULL )
+ {
+ free( hDirAC_mem->direct_responses );
+ }
+ if ( hDirAC_mem->proto_direct_buffer_f != NULL )
+ {
+ free( hDirAC_mem->proto_direct_buffer_f );
+ }
+ if ( hDirAC_mem->proto_diffuse_buffer_f != NULL )
+ {
+ free( hDirAC_mem->proto_diffuse_buffer_f );
+ }
+ if ( hDirAC_mem->direct_power_factor != NULL )
+ {
+ free( hDirAC_mem->direct_power_factor );
+ }
+ if ( hDirAC_mem->diffuse_power_factor != NULL )
+ {
+ free( hDirAC_mem->diffuse_power_factor );
+ }
+ if ( hDirAC_mem->reference_power != NULL )
+ {
+ free( hDirAC_mem->reference_power );
+ }
+ if ( hDirAC_mem->onset_filter != NULL )
+ {
+ free( hDirAC_mem->onset_filter );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * compute_hoa_encoder_mtx()
+ *
+ *
+ *------------------------------------------------------------------------*/
+
+void compute_hoa_encoder_mtx(
+ const float *azimuth,
+ const float *elevation,
+ float *response,
+ const int16_t num_responses,
+ const int16_t ambisonics_order )
+{
+ int16_t k, num_sh;
+
+ num_sh = ivas_sba_get_nchan( ambisonics_order, 0 );
+
+ for ( k = 0; k < num_responses; k++ )
+ {
+ ivas_dirac_dec_get_response( (const int16_t) azimuth[k], (const int16_t) elevation[k], &response[k * num_sh], ambisonics_order );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_dirac_dec_get_frequency_axis()
+ *
+ * DirAC decoding initialization
+ *------------------------------------------------------------------------*/
+
+void ivas_dirac_dec_get_frequency_axis(
+ float *frequency_axis,
+ const int32_t output_Fs,
+ const int16_t num_freq_bands )
+{
+ int16_t k;
+ float const_part;
+
+ /* calc cldfb frequency axis */
+ const_part = (float) output_Fs / ( 2.0f * (float) num_freq_bands );
+ for ( k = 0; k < num_freq_bands; ++k )
+ {
+ frequency_axis[k] = ( (float) k + 0.5f ) * const_part;
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Local functions
+ *-------------------------------------------------------------------------*/
+
+void initDiffuseResponses(
+ float *diffuse_response_function,
+ const int16_t num_channels,
+ AUDIO_CONFIG output_config,
+ IVAS_OUTPUT_SETUP hOutSetup,
+ const int16_t ambisonics_order,
+ const IVAS_FORMAT ivas_format,
+ int16_t *num_ele_spk_no_diffuse_rendering,
+ AUDIO_CONFIG transport_config )
+{
+ int16_t i, l, k, idx, num_horizontal_speakers;
+ *num_ele_spk_no_diffuse_rendering = 0;
+
+ if ( output_config == AUDIO_CONFIG_MONO )
+ {
+ diffuse_response_function[0] = 1.0f;
+ diffuse_response_function[1] = inv_sqrt( 3.0f );
+ }
+ else if ( !( output_config == AUDIO_CONFIG_FOA || output_config == AUDIO_CONFIG_HOA2 || output_config == AUDIO_CONFIG_HOA3 ) )
+ {
+ /* set diffuse response function */
+ if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_5_1_4 )
+ {
+ num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS;
+
+ mvr2r( diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers );
+ set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS );
+ *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS;
+ }
+ else if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_7_1_4 )
+ {
+ num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS;
+
+ set_f( diffuse_response_function, sqrtf( 1.f / ( (float) num_horizontal_speakers ) ), num_horizontal_speakers );
+ set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS );
+ *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS;
+ }
+ else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 )
+ {
+ mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels );
+ }
+ else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 )
+ {
+ mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels );
+ }
+ else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) )
+ {
+ mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels );
+ }
+ else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) )
+ {
+ if ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 )
+ {
+ /* Detect loudspeakers with elevation */
+ for ( i = 0, num_horizontal_speakers = 0; i < num_channels; i++ )
+ {
+ if ( fabsf( hOutSetup.ls_elevation[i] ) <= 5.f )
+ {
+ num_horizontal_speakers++;
+ diffuse_response_function[i] = 1.f;
+ }
+ else
+ {
+ *num_ele_spk_no_diffuse_rendering += 1;
+ diffuse_response_function[i] = 0.f;
+ }
+ }
+ /* Diffuse only to horizontal plane if enough loudspeakers */
+ if ( num_horizontal_speakers > 2 )
+ {
+ for ( i = 0; i < num_channels; i++ )
+ {
+ diffuse_response_function[i] *= sqrtf( 1.f / (float) num_horizontal_speakers );
+ }
+ }
+ else
+ {
+ *num_ele_spk_no_diffuse_rendering = 0;
+ set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels );
+ }
+ }
+ else
+ {
+ set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels );
+ }
+ }
+ else
+ {
+ set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels );
+ }
+ }
+ else
+ {
+ idx = 0;
+ for ( l = 0; l <= ambisonics_order; l++ )
+ {
+ for ( k = 0; k < ( 2 * l + 1 ); k++ )
+ {
+ diffuse_response_function[idx++] = inv_sqrt( 2.0f * l + 1.0f );
+ }
+ }
+ }
+
+ return;
+}
+
+
+void protoSignalComputation_shd(
+ float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],
+ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],
+ float *proto_direct_buffer_f,
+ float *proto_diffuse_buffer_f,
+ float *reference_power,
+ const int16_t slot_index,
+ const int16_t num_inputs,
+ const int16_t num_outputs_diff,
+ const int16_t num_freq_bands,
+ float *p_Rmat )
+{
+ int16_t l, k;
+ float *p_proto_direct_buffer;
+ float *p_proto_diffuse_buffer;
+ int16_t Rmat_k[4];
+ float W_real, W_imag;
+ float Y_real, Y_imag;
+ float *p_k[4];
+
+ k = 0; /* to avoid compilation warning */
+
+ p_proto_direct_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_inputs;
+ p_proto_diffuse_buffer = proto_diffuse_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff;
+
+ if ( num_inputs == 1 )
+ {
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ p_proto_direct_buffer[2 * l] = RealBuffer[0][0][l];
+ p_proto_direct_buffer[2 * l + 1] = ImagBuffer[0][0][l];
+ }
+ }
+ else if ( num_inputs == 2 )
+ {
+ if ( p_Rmat != 0 )
+ {
+ assert( num_inputs == 4 && "This code block should never be run with num_inputs != 4!" );
+
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ W_real = RealBuffer[0][0][l] + RealBuffer[1][0][l];
+ W_imag = ImagBuffer[0][0][l] + ImagBuffer[1][0][l];
+
+ Y_real = RealBuffer[0][0][l] - RealBuffer[1][0][l];
+ Y_imag = ImagBuffer[0][0][l] - ImagBuffer[1][0][l];
+
+ p_proto_direct_buffer[2 * l] = W_real;
+ p_proto_direct_buffer[2 * l + 1] = W_imag;
+ p_proto_direct_buffer[2 * num_freq_bands + 2 * l] = p_Rmat[0] * Y_real;
+ p_proto_direct_buffer[2 * num_freq_bands + 2 * l + 1] = p_Rmat[0] * Y_imag;
+ }
+ }
+ else
+ {
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ W_real = RealBuffer[0][0][l] + RealBuffer[1][0][l];
+ W_imag = ImagBuffer[0][0][l] + ImagBuffer[1][0][l];
+
+ p_proto_direct_buffer[2 * l] = W_real;
+ p_proto_direct_buffer[2 * l + 1] = W_imag;
+ {
+ p_proto_direct_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l];
+ p_proto_direct_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l];
+ }
+ }
+ }
+ }
+ else if ( num_inputs >= 4 )
+ {
+ p_k[0] = p_proto_direct_buffer;
+ p_k[1] = p_proto_direct_buffer + 2 * num_freq_bands;
+ p_k[2] = p_proto_direct_buffer + 4 * num_freq_bands;
+ p_k[3] = p_proto_direct_buffer + 6 * num_freq_bands;
+ Rmat_k[0] = 0;
+ Rmat_k[1] = 1;
+ Rmat_k[2] = 2;
+ Rmat_k[3] = 0;
+
+ if ( p_Rmat != 0 )
+ {
+ assert( num_inputs == 4 && "This code block should never be run with num_inputs != 4!" );
+
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ *( p_k[0] ) = RealBuffer[0][0][l];
+ reference_power[l + num_freq_bands] = *( p_k[0] ) * *( p_k[0] );
+ p_k[0]++;
+ *( p_k[0] ) = ImagBuffer[0][0][l];
+ reference_power[l + num_freq_bands] += *( p_k[0] ) * *( p_k[0] );
+ p_k[0]++;
+ reference_power[l] = 0.5f * reference_power[l + num_freq_bands];
+
+ for ( k = 1; k < 4; k++ )
+ {
+ *( p_k[k] ) = p_Rmat[3 * Rmat_k[k] + 1] * RealBuffer[1][0][l] + p_Rmat[3 * Rmat_k[k] + 2] * RealBuffer[2][0][l] + p_Rmat[3 * Rmat_k[k] + 0] * RealBuffer[3][0][l];
+ reference_power[l + ( k + 1 ) * num_freq_bands] = *( p_k[k] ) * *( p_k[k] );
+ p_k[k]++;
+ *( p_k[k] ) = p_Rmat[3 * Rmat_k[k] + 1] * ImagBuffer[1][0][l] + p_Rmat[3 * Rmat_k[k] + 2] * ImagBuffer[2][0][l] + p_Rmat[3 * Rmat_k[k] + 0] * ImagBuffer[3][0][l];
+ reference_power[l + ( k + 1 ) * num_freq_bands] += *( p_k[k] ) * *( p_k[k] );
+ p_k[k]++;
+ reference_power[l] += 0.5f * ( reference_power[l + ( k + 1 ) * num_freq_bands] );
+ }
+
+ for ( k = 1; k < 4; k++ )
+ {
+ RealBuffer[k][0][l] = p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l];
+ ImagBuffer[k][0][l] = p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1];
+ }
+ }
+ }
+ else
+ {
+ set_zero( reference_power, num_freq_bands );
+ for ( k = 0; k < 4; k++ )
+ {
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l] = RealBuffer[k][0][l];
+ p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1] = ImagBuffer[k][0][l];
+ reference_power[l + ( k + 1 ) * num_freq_bands] = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l];
+ reference_power[l] += 0.5f * ( reference_power[l + ( k + 1 ) * num_freq_bands] );
+ }
+ }
+ }
+
+ /* Additional transport channels = planar SBA components of degree higher than 1*/
+ for ( ; k < num_inputs; k++ )
+ {
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l] = RealBuffer[k][0][l];
+ p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1] = ImagBuffer[k][0][l];
+ }
+ }
+ }
+
+
+ /*Copy direct to diffuse proto*/
+ mvr2r( p_proto_direct_buffer, p_proto_diffuse_buffer, 2 * num_freq_bands * min( num_outputs_diff, num_inputs ) );
+
+ if ( num_inputs == 1 )
+ {
+ /* Add comfort noise addition (CNA) to diffuse proto only*/
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ p_proto_diffuse_buffer[2 * l] += RealBuffer[1][0][l];
+ p_proto_diffuse_buffer[2 * l + 1] += ImagBuffer[1][0][l];
+ }
+ }
+
+ return;
+}
+
+
+void protoSignalComputation1(
+ 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 )
+{
+ int16_t l, k;
+ float *p_proto_buffer;
+
+ p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands;
+
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ reference_power[l] = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
+ proto_power_smooth[l] += reference_power[l];
+ p_proto_buffer[2 * l] = RealBuffer[0][0][l];
+ p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l];
+
+ for ( k = 0; k < num_outputs_diff; k++ )
+ {
+ proto_frame_f[2 * k * num_freq_bands + 2 * l] = RealBuffer[0][0][l];
+ proto_frame_f[2 * k * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l];
+ }
+ }
+
+ return;
+}
+
+
+void protoSignalComputation2(
+ 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 isloudspeaker,
+ const int16_t slot_index,
+ const int16_t num_freq_bands,
+ MASA_STEREO_TYPE_DETECT *stereo_type_detect )
+{
+ int16_t l;
+ float *p_proto_buffer;
+ float Real_aux, Imag_aux;
+
+ float left_bb_power, right_bb_power, total_bb_power, lr_bb_power;
+ float lr_total_bb_ratio;
+ float a, b;
+
+ float left_hi_power, right_hi_power, total_hi_power, lr_hi_power;
+ float lr_total_hi_ratio;
+ float a2, b2;
+
+ float sum_power;
+ float sum_total_ratio[MASA_SUM_FREQ_RANGE_BINS];
+ float min_sum_total_ratio;
+ float min_sum_total_ratio_db;
+
+ float RealSubtract, ImagSubtract;
+
+ float interpolatorSpaced = 0.0f;
+ float interpolatorDmx = 1.0f;
+
+ int16_t dipole_freq_range[2];
+ float tempSpaced, tempDmx;
+
+ if ( isloudspeaker )
+ {
+ p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 3;
+
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ float Left_power;
+ float Right_power;
+ Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l];
+ Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l];
+
+ Left_power = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
+ Right_power = RealBuffer[1][0][l] * RealBuffer[1][0][l] + ImagBuffer[1][0][l] * ImagBuffer[1][0][l];
+
+ reference_power[l] = Left_power + Right_power;
+ 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;
+ proto_power_smooth[l + num_freq_bands] += RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
+ p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l];
+ p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l];
+
+ proto_power_smooth[l + 2 * num_freq_bands] += RealBuffer[1][0][l] * RealBuffer[1][0][l];
+ proto_power_smooth[l + 2 * num_freq_bands] += ImagBuffer[1][0][l] * ImagBuffer[1][0][l];
+ p_proto_buffer[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l];
+ p_proto_buffer[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];
+ }
+ }
+ else if ( stereo_type_detect != NULL )
+ {
+ p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2;
+
+ left_bb_power = 0.0f;
+ right_bb_power = 0.0f;
+ total_bb_power = 0.0f;
+
+ left_hi_power = 0.0f;
+ right_hi_power = 0.0f;
+ total_hi_power = 0.0f;
+
+ dipole_freq_range[0] = stereo_type_detect->dipole_freq_range[0];
+ dipole_freq_range[1] = stereo_type_detect->dipole_freq_range[1];
+
+ a = 0.01f; /* Temporal smoothing coefficient */
+ b = 1.0f - a; /* Temporal smoothing coefficient */
+ a2 = 0.1f; /* Temporal smoothing coefficient */
+ b2 = 1.0f - a2; /* Temporal smoothing coefficient */
+
+ if ( stereo_type_detect->interpolator > 0 )
+ {
+ if ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS )
+ {
+ interpolatorSpaced = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS );
+ interpolatorDmx = 1.0f - interpolatorSpaced;
+ }
+ else
+ {
+ interpolatorDmx = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS );
+ interpolatorSpaced = 1.0f - interpolatorDmx;
+ }
+ }
+
+ for ( l = 0; l < num_freq_bands; l++ )
+ {
+ float Left_power;
+ float Right_power;
+
+ /* Compute sum signal */
+ Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l];
+ Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l];
+
+ /* Compute reference power */
+ Left_power = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
+ Right_power = RealBuffer[1][0][l] * RealBuffer[1][0][l] + ImagBuffer[1][0][l] * ImagBuffer[1][0][l];
+
+ reference_power[l] = Left_power + Right_power;
+
+ left_bb_power += Left_power;
+ right_bb_power += Right_power;
+ total_bb_power += reference_power[l];
+
+ if ( l > MASA_HI_FREQ_START_BIN )
+ {
+ left_hi_power += Left_power;
+ right_hi_power += Right_power;
+ total_hi_power += reference_power[l];
+ }
+
+ if ( l < min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) )
+ {
+ sum_power = Real_aux * Real_aux + Imag_aux * Imag_aux;
+
+ stereo_type_detect->sum_power[l] = a * sum_power + b * stereo_type_detect->sum_power[l];
+ stereo_type_detect->total_power[l] = a * reference_power[l] + b * stereo_type_detect->total_power[l];
+
+ sum_total_ratio[l] = stereo_type_detect->sum_power[l] / ( stereo_type_detect->total_power[l] + EPSILON );
+ }
+
+ 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;
+ }
+
+ /* Compute protos (and their power) for direct sound rendering */
+
+ /* W prototype */
+ if ( stereo_type_detect->interpolator > 0 )
+ {
+ 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->masa_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
+ {
+ proto_power_smooth[l] += RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l];
+ p_proto_buffer[2 * l] = RealBuffer[0][0][l];
+ p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l];
+ }
+ }
+ else
+ {
+ 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;
+ }
+
+ /* Y prototype */
+ if ( stereo_type_detect->interpolator > 0 )
+ {
+ 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] );
+ }
+ 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 ( 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
+ {
+ 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];
+ }
+
+ if ( stereo_type_detect->interpolator > 0 )
+ {
+ 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;
+
+ 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;
+
+ 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 );
+
+ 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++ )
+ {
+ 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;
+
+ 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 * 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;
+}
+
+
+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++ )
+ {
+ 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++ )
+ {
+ 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++ )
+ {
+ 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;
+}
+
+
+/*-------------------------------------------------------------------------
+ * 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;
+
+ 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_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++ )
+ {
+ 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;
+
+ /*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;
+}
+
+
+/*-------------------------------------------------------------------------
+ * 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;
+
+ for ( k = 0; k < num_frequency_bands; ++k )
+
+ {
+ 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 );
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------------
+ * ivas_masa_init_stereotype_detection()
+ *
+ * Initialize stereo transport signal type detection
+ *------------------------------------------------------------------------*/
+
+void ivas_masa_init_stereotype_detection(
+ MASA_STEREO_TYPE_DETECT *stereo_type_detect )
+{
+ 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->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_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 );
+
+ 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;
+
+ 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;
+
+ /* 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;
+
+ 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;
+
+ change_to_downmix = subtract_temp + min_sum_temp + lr_total_bb_temp;
+
+ 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;
+
+ change_to_downmix2 = subtract_temp + min_sum_temp + lr_total_hi_temp;
+
+ if ( change_to_downmix2 >= 1.0f )
+ {
+ change_to_downmix_selection = 1;
+ }
+ }
+
+ if ( stereo_type_detect->counter < 400 )
+ {
+ stereo_type_detect->counter++;
+ }
+ else
+ {
+ if ( change_to_spaced_selection == 1 )
+ {
+ 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 )
+ {
+ stereo_type_detect->interpolator = 1;
+ stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type;
+ }
+ }
+
+ 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 )
+{
+ /*
+ * 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;
+ }
+
+ 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 )
+{
+ 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 );
+
+ 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 );
+
+ 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;
+
+ 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;
+
+ 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;
+}
+
+
+/*-------------------------------------------------------------------------
+ * 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;
+
+ push_wmops( "rotateAziEle_DirAC" );
+
+ 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 );
+
+ 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 );
+ }
+
+ pop_wmops();
+
+ return;
+}
diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h
index e64fdce77a4a23d07f8d2961a3b5e02ce997966d..2b2915d1941d192d3042e448df98735daca9f6d7 100644
--- a/lib_rend/ivas_prot_rend.h
+++ b/lib_rend/ivas_prot_rend.h
@@ -37,6 +37,7 @@
#include "options.h"
#include "ivas_error.h"
#include "lib_rend.h"
+#include "ivas_stat_rend.h"
#include "ivas_stat_dec.h" // Note: needed until #156 is resolved
/* clang-format off */
@@ -133,7 +134,7 @@ void efap_determine_gains(
/*----------------------------------------------------------------------------------*
- * SBA rendering
+ * DirAC/MASA rendering
*----------------------------------------------------------------------------------*/
void ivas_sba_prototype_renderer(
@@ -151,7 +152,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix(
#ifdef FIX_564
-void ivas_dirac_dec_binaural_gain(
+void ivas_dirac_dec_binaural_sba_gain(
float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */
const int16_t nchan_remapped, /* i : num channels after remapping of TCs */
const int16_t output_frame /* i : output frame length */
@@ -187,6 +188,323 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs(
HRTFS_PARAMBIN_HANDLE *hHrtfParambin /* i/o: HRTF structure for rendering */
);
+/*! r: Configured reqularization factor value */
+float configure_reqularization_factor(
+ const IVAS_FORMAT ivas_format, /* i : IVAS format */
+ const int32_t ivas_total_brate /* i : total IVAS bitrate */
+);
+
+ivas_error ivas_dirac_alloc_mem(
+ DIRAC_REND_HANDLE hDirACRend,
+ const RENDERER_TYPE renderer_type,
+ const int16_t num_freq_bands,
+ DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem,
+ const int16_t hodirac_flag
+);
+
+void ivas_dirac_free_mem(
+ DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem
+);
+
+void initDiffuseResponses(
+ float *diffuse_response_function,
+ const int16_t num_channels,
+ AUDIO_CONFIG output_config,
+ IVAS_OUTPUT_SETUP hOutSetup,
+ const int16_t ambisonics_order,
+ const IVAS_FORMAT ivas_format,
+ int16_t *num_ele_spk_no_diffuse_rendering,
+ AUDIO_CONFIG transport_config
+);
+
+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
+);
+
+void protoSignalComputation_shd(
+ float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],
+ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],
+ float *proto_direct_buffer_f,
+ float *proto_diffuse_buffer_f,
+ float *reference_power,
+ const int16_t slot_index,
+ const int16_t num_inputs,
+ const int16_t num_outputs_diff,
+ const int16_t num_freq_bands,
+ float *p_Rmat
+);
+
+void protoSignalComputation1(
+ 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
+);
+
+void protoSignalComputation2(
+ 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 isloudspeaker,
+ const int16_t slot_index,
+ const int16_t num_freq_bands,
+ MASA_STEREO_TYPE_DETECT *stereo_type_detect
+);
+
+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
+);
+
+void ivas_dirac_dec_compute_diffuse_proto(
+ DIRAC_REND_HANDLE hDirACRend,
+ const int16_t num_freq_bands,
+ const int16_t slot_idx
+);
+
+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 ivas_masa_init_stereotype_detection(
+ MASA_STEREO_TYPE_DETECT *stereo_type_detect
+);
+
+void ivas_masa_stereotype_detection(
+ MASA_STEREO_TYPE_DETECT *stereo_type_detect
+);
+
+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
+);
+
+void rotateAziEle_DirAC(
+ int16_t *azi,
+ int16_t *ele,
+ const int16_t band1,
+ const int16_t band2,
+ const float *p_Rmat
+);
+
+ivas_error ivas_dirac_dec_onset_detection_open(
+ const int16_t num_channels,
+ const int16_t num_freq_bands,
+ const int16_t max_band_decorr,
+ DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params,
+ DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state
+);
+
+void ivas_dirac_dec_onset_detection_process(
+ const float *input_power_f,
+ float *onset_filter,
+ const int16_t num_protos_diff,
+ DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params,
+ DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state
+);
+
+ivas_error ivas_dirac_dec_decorr_open(
+ DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params,
+ DIRAC_DECORR_STATE **ph_freq_domain_decorr_ap_state,
+ const int16_t num_freq_bands,
+ int16_t num_outputs_diff,
+ const int16_t num_protos_diff,
+ const DIRAC_SYNTHESIS_CONFIG synthesisConf,
+ float *frequency_axis,
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int32_t output_Fs /* i : output sampling rate */
+);
+
+void ivas_dirac_dec_decorr_process(
+ const int16_t num_freq_bands,
+ int16_t num_channels,
+ const int16_t num_protos_diff,
+ const DIRAC_SYNTHESIS_CONFIG synthesisConf,
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const float *input_frame_f,
+ const int16_t num_protos_dir,
+ const int16_t *proto_index_dir,
+ float *frame_dec_f,
+ float *onset_filter,
+ HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params,
+ HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state
+);
+
+void ivas_dirac_dec_decorr_close(
+ HANDLE_DIRAC_DECORR_PARAMS *ph_dirac_decorr_params,
+ HANDLE_DIRAC_DECORR_STATE *ph_dirac_decorr_state
+);
+
+ivas_error ivas_dirac_dec_output_synthesis_open(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ const RENDERER_TYPE renderer_type, /* i : renderer type */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int32_t output_Fs, /* i : output sampling rate */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+);
+
+void ivas_dirac_dec_output_synthesis_init(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ const int16_t nchan_out_woLFE, /* i : number of output audio channels without LFE */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+);
+
+void ivas_dirac_dec_output_synthesis_close(
+ DIRAC_REND_HANDLE hDirACRend /* i/o: DirAC handle */
+);
+
+void ivas_dirac_dec_output_synthesis_process_slot(
+ const float *reference_power, /* i : Estimated power */
+ const float *onset, /* i : onset filter */
+ const int16_t *azimuth,
+ const int16_t *elevation,
+ const float *diffuseness,
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ const int16_t sh_rot_max_order,
+ const float *p_Rmat, /* i : rotation matrix */
+ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */
+ const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t ind_slot, /* i : index of the slot to be added to the input covariance */
+ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
+ const int16_t dec_param_estim /* i : flag to indicate parameter estimation mode */
+);
+
+void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd(
+ float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */
+ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ const int16_t nchan_transport, /* i : number of transport channels */
+ const int16_t nbslots, /* i : number of slots to process */
+ const float *onset_filter,
+ float *diffuseness,
+ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */
+ const int16_t dec_param_estim /* i : flag to indicate parameter estimation mode */
+);
+
+void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls(
+ float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */
+ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ const int16_t nbslots, /* i : number of slots to process */
+ float *diffuseness_vector, /* i : diffuseness (needed for direction smoothing)*/
+ float *reference_power_smooth,
+ float qualityBasedSmFactor,
+ const int16_t enc_param_start_band
+);
+
+void compute_hoa_encoder_mtx(
+ const float *azimuth,
+ const float *elevation,
+ float *response,
+ const int16_t num_responses,
+ const int16_t ambisonics_order );
+
+void ivas_dirac_dec_compute_gain_factors(
+ const int16_t num_freq_bands,
+ const float *diffuseness,
+ const int16_t max_band_decorr,
+ float *direct_gain_factor,
+ float *diffuse_gain_factor
+);
+
+void ivas_dirac_dec_compute_power_factors(
+ const int16_t num_freq_bands,
+ const float *diffuseness,
+ const int16_t max_band_decorr,
+ float *direct_power_factor,
+ float *diffuse_power_factor
+);
+
+void ivas_dirac_dec_compute_directional_responses(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */
+ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */
+ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */
+ const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */
+ const int16_t *azimuth,
+ const int16_t *elevation,
+ const int16_t md_idx,
+ const float *surCohRatio,
+ const int16_t shd_rot_max_order, /* i : split-order rotation method */
+ const float *p_Rmat, /* i : rotation matrix */
+ const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */
+);
+
+void ivas_dirac_dec_get_frequency_axis(
+ float *frequency_axis, /* o : array of center frequencies of a real filter bank */
+ const int32_t output_Fs, /* i : sampling frequency */
+ const int16_t num_freq_bands /* i : number of frequency bands */
+);
+
+ivas_error ivas_spat_hSpatParamRendCom_config(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: IVAS decoder structure */
+ const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
+ const int16_t dec_param_estim_flag,
+ const IVAS_FORMAT ivas_format,
+ const MC_MODE mc_mode,
+ const int32_t output_Fs,
+ const int16_t hodirac_flag
+);
+
+void ivas_spat_hSpatParamRendCom_close(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out
+);
+
+void ivas_dirac_rend_close(
+ DIRAC_REND_HANDLE *hDirACRend_out
+);
+
+ivas_error ivas_dirac_allocate_parameters(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */
+ const int16_t params_flag /* i : set of parameters flag */
+);
+
+void ivas_dirac_deallocate_parameters(
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */
+ const int16_t params_flag /* i : set of parameters flag */
+);
+
+
/*----------------------------------------------------------------------------------*
* HRTF
diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h
index 04cfd144ed78fd432c346a4090b6665cf10a5959..36c4a1783654583e146ceeaa66ccc38ad58840d6 100644
--- a/lib_rend/ivas_stat_rend.h
+++ b/lib_rend/ivas_stat_rend.h
@@ -47,6 +47,7 @@
#include "ivas_lc3plus_dec.h"
#endif
+//#include "ivas_stat_dec.h"
/*----------------------------------------------------------------------------------*
* Output configuration for renderer (e.g. DirAC, MASA, Binaural Renderer...)
@@ -72,6 +73,348 @@ typedef struct ivas_output_setup_structure
} IVAS_OUTPUT_SETUP, *IVAS_OUTPUT_SETUP_HANDLE;
+/*----------------------------------------------------------------------------------*
+ * Spatial parametric rendering common structures
+ *----------------------------------------------------------------------------------*/
+
+/*Onset detector*/
+typedef struct dirac_onset_detection_params_structure
+{
+ int16_t num_freq_bands;
+ int16_t max_band_decorr;
+
+} DIRAC_ONSET_DETECTION_PARAMS;
+
+typedef struct dirac_onset_detection_state_structure
+{
+ float *onset_detector_1;
+ float *onset_detector_2;
+
+} DIRAC_ONSET_DETECTION_STATE;
+
+/*Decorrelator*/
+typedef struct dirac_decorr_params_structure
+{
+ int16_t max_band_decorr;
+ int16_t max_frequency;
+
+ int16_t *pre_delay;
+ int16_t *filter_length;
+ float *filter_coeff_num_real;
+ float *filter_coeff_den_real;
+ float *phase_coeff_real;
+ float *phase_coeff_imag;
+ int16_t *split_frequency_bands;
+ int16_t num_split_frequency_bands;
+
+ int16_t use_ducker;
+ int16_t add_back_onsets_on;
+
+ DIRAC_ONSET_DETECTION_PARAMS h_onset_detection_power_params;
+
+} DIRAC_DECORR_PARAMS, *HANDLE_DIRAC_DECORR_PARAMS;
+
+typedef struct dirac_decorr_state_structure
+{
+ float *decorr_buffer;
+ float *direct_energy_smooth;
+ float *reverb_energy_smooth;
+
+ DIRAC_ONSET_DETECTION_STATE h_onset_detection_power_state;
+
+} DIRAC_DECORR_STATE, *HANDLE_DIRAC_DECORR_STATE;
+
+typedef struct ivas_spatial_parametric_rend_common_data_structure
+{
+ int16_t slot_size;
+ int16_t subframe_nbslots[MAX_JBM_SUBFRAMES_5MS];
+ int16_t subframes_rendered;
+ int16_t slots_rendered;
+ int16_t num_slots;
+ int16_t render_to_md_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME];
+ int16_t nb_subframes;
+
+ int16_t num_freq_bands;
+ int16_t numSimultaneousDirections; /* 1 or 2 */
+
+ int16_t **azimuth;
+ int16_t **elevation;
+ int16_t **azimuth2;
+ int16_t **elevation2;
+
+ float **diffuseness_vector;
+ float **energy_ratio1;
+ float **energy_ratio2;
+
+ float **spreadCoherence;
+ float **spreadCoherence2;
+ float **surroundingCoherence;
+
+ /* Metadata access indices and buffer size */
+ int16_t dirac_bs_md_write_idx;
+ int16_t dirac_read_idx;
+ int16_t dirac_md_buffer_length;
+
+} SPAT_PARAM_REND_COMMON_DATA, *SPAT_PARAM_REND_COMMON_DATA_HANDLE;
+
+
+/*----------------------------------------------------------------------------------*
+ * DirAC rendering structures
+ *----------------------------------------------------------------------------------*/
+
+typedef struct dirac_dec_stack_mem
+{
+ /*Decorrelator*/
+ float *frame_dec_f;
+
+ /*Prototypes*/
+ float *proto_direct_buffer_f;
+ float *proto_diffuse_buffer_f;
+
+ /*Prototype NRGs*/
+ float *proto_power_smooth;
+ float *proto_power_diff_smooth;
+
+ /*Gain or power factors for directional and diffuse streams*/
+ float *direct_power_factor;
+ float *diffuse_power_factor;
+
+ /*Directional responses (gains & Nrg)*/
+ float *direct_responses;
+ float *direct_responses_square;
+
+ /* Target co-variance mtx */
+ float *cy_auto_dir_smooth;
+ float *cy_cross_dir_smooth;
+ float *cy_auto_diff_smooth;
+
+ float *reference_power;
+ float *onset_filter;
+
+} DIRAC_DEC_STACK_MEM, *DIRAC_DEC_STACK_MEM_HANDLE;
+
+/*Output synthesis*/
+typedef struct dirac_output_synthesis_params_structure
+{
+ int16_t max_band_decorr;
+
+ int16_t use_onset_filters;
+
+ float *interpolator;
+ float *alpha_synthesis;
+ float *alpha_synthesis_fast;
+ int16_t numAlphas;
+ int16_t numAlphasFast;
+
+ float *proto_matrix;
+
+ float diffuse_compensation_factor;
+ float diffuse_compensation_factor_decorr;
+
+} DIRAC_OUTPUT_SYNTHESIS_PARAMS;
+
+typedef struct dirac_output_synthesis_state_structure
+{
+ /* only pointer to local buffers */
+ float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */
+ float *direct_responses_square;
+ float *diffuse_responses_square; /* squared diffuse responses. Size: num_channels. */
+
+ /* only pointer to local buffers */
+ float *direct_power_factor;
+ float *diffuse_power_factor;
+
+ float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */
+ float *proto_power_smooth_prev; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */
+
+ float *proto_power_diff_smooth;
+ float *proto_power_diff_smooth_prev;
+
+ /* only pointer to local buffers */
+ float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */
+ float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */
+
+ /* Output gain memories */
+ float *gains_dir_prev; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */
+ float *gains_diff_prev; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */
+
+ /* only pointer to local buffers */
+ float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */
+ float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */
+ float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */
+
+ /* PSD memories */
+ float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */
+ float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */
+ float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */
+
+ const float *onset_filter;
+
+ /* Temporal smoothing memories */
+ float *reference_power_smooth_prev;
+ float *direction_smoothness_prev;
+
+} DIRAC_OUTPUT_SYNTHESIS_STATE;
+
+/* MASA stereo transport signal type detection structure */
+typedef struct
+{
+ MASA_TRANSPORT_SIGNAL_TYPE masa_stereo_type;
+ MASA_TRANSPORT_SIGNAL_TYPE current_stereo_type;
+ MASA_TRANSPORT_SIGNAL_TYPE type_change_direction;
+
+ int16_t dipole_freq_range[2];
+
+ float left_bb_power;
+ float right_bb_power;
+ float total_bb_power;
+
+ float left_hi_power;
+ float right_hi_power;
+ float total_hi_power;
+
+ float sum_power[MASA_SUM_FREQ_RANGE_BINS];
+ float total_power[MASA_SUM_FREQ_RANGE_BINS];
+
+ float subtract_power_y;
+ float subtract_power_y_smooth;
+ float target_power_y_smooth;
+
+ float lr_total_bb_ratio_db;
+ float lr_total_hi_ratio_db;
+ float min_sum_total_ratio_db;
+ float subtract_target_ratio_db;
+
+ int16_t counter;
+ int16_t interpolator;
+
+} MASA_STEREO_TYPE_DETECT;
+
+/* McMASA LFE synthesis structure */
+typedef struct ivas_mcmasa_lfe_synth_struct
+{
+ float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES];
+ int16_t lfeGainPrevIndex;
+ float transportEneSmooth;
+ float protoLfeEneSmooth;
+ float targetEneLfeSmooth;
+ float targetEneTransSmooth;
+
+ float *lfeSynthRingBuffer;
+ int16_t ringBufferLoPointer;
+ int16_t ringBufferHiPointer;
+ float lowpassSum;
+ int16_t ringBufferSize;
+
+ float *lfeSynthRingBuffer2;
+ int16_t ringBufferLoPointer2;
+ float lowpassSum2;
+ int16_t ringBufferSize2;
+
+ float *delayBuffer_syncLp;
+ int16_t delayBuffer_syncLp_size;
+
+ float *delayBuffer_syncDirAC;
+ int16_t delayBuffer_syncDirAC_size;
+
+ float lfeGainPrev;
+ float transportGainPrev;
+ float interpolator[CLDFB_NO_CHANNELS_MAX];
+
+} MCMASA_LFE_SYNTH_DATA, *MCMASA_LFE_SYNTH_DATA_HANDLE;
+
+/* DirAC renderer main structure */
+typedef struct ivas_dirac_rend_data_structure
+{
+ IVAS_OUTPUT_SETUP hOutSetup;
+
+ /*Parameter estimation*/
+ int16_t index_buffer_intensity;
+ float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF];
+ float *buffer_energy;
+
+ float *frequency_axis;
+ float *diffuse_response_function;
+ float *hoa_encoder;
+ const float *hoa_decoder;
+
+ /*Decoder parameters */
+ /*Prototypes*/
+ int16_t num_outputs_dir;
+ int16_t num_outputs_diff;
+ int16_t num_protos_dir;
+ int16_t num_protos_diff;
+ int16_t num_protos_ambi;
+ DIRAC_SYNTHESIS_CONFIG synthesisConf;
+ DIRAC_PANNING_CONFIG panningConf;
+
+ /* prototype computing */
+ int16_t *proto_index_dir;
+ int16_t *proto_index_diff;
+
+ int16_t proto_signal_decorr_on;
+
+ /*Decoder states=memories*/
+ float *proto_frame_f;
+ float *proto_frame_dec_f;
+
+ DIRAC_DEC_STACK_MEM stack_mem;
+ MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect;
+
+ int16_t num_ele_spk_no_diffuse_rendering;
+
+ const int16_t *sba_map_tc;
+
+ DIRAC_OUTPUT_SYNTHESIS_PARAMS h_output_synthesis_psd_params;
+ DIRAC_OUTPUT_SYNTHESIS_STATE h_output_synthesis_psd_state;
+
+ HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params;
+ HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state;
+
+} DIRAC_REND_DATA, *DIRAC_REND_HANDLE;
+
+
+/*----------------------------------------------------------------------------------*
+ * VBAP structures
+ *----------------------------------------------------------------------------------*/
+
+/* Defines a single virtual surface triplet of loudspeakers
+ * with a precalculated inverse matrix */
+typedef struct vbap_vs_triplet_structure
+{
+ uint8_t speaker_node[3];
+ float inverse_matrix[3][3];
+
+} VBAP_VS_TRIPLET;
+
+
+/* Storage structure for fast runtime triplet search */
+typedef struct triplet_search_structure
+{
+ VBAP_VS_TRIPLET *triplets;
+ int16_t num_triplets;
+ int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS];
+
+} VBAP_SEARCH_STRUCT;
+
+
+/* VBAP data structure. Contains the formed virtual surface arrangement * and supporting data. */
+typedef struct vbap_data_structure
+{
+ VBAP_SEARCH_STRUCT search_struct[2]; /* Default to max two groups in this implementation */
+ int16_t num_search_structs;
+ int16_t num_speaker_nodes;
+ int16_t num_speaker_nodes_internal;
+ int16_t top_virtual_speaker_node_index; /* These indices can be negative */
+ int16_t bottom_virtual_speaker_node_index;
+ int16_t back_virtual_speaker_node_index;
+ float *bottom_virtual_speaker_node_division_gains;
+ float *top_virtual_speaker_node_division_gains;
+ float *back_virtual_speaker_node_division_gains;
+
+} VBAP_DATA, *VBAP_HANDLE;
+
+
/*----------------------------------------------------------------------------------*
* Binaural FastConv Rendering structure
*----------------------------------------------------------------------------------*/
@@ -114,6 +457,17 @@ typedef struct ivas_binaural_reverb_struct
} REVERB_STRUCT, *REVERB_STRUCT_HANDLE;
+
+/* Diffuse sound directional distribution data structure */
+typedef struct ivas_diffuse_distribution_data_structure
+{
+ float diffuseRatioX[CLDFB_NO_CHANNELS_MAX];
+ float diffuseRatioY[CLDFB_NO_CHANNELS_MAX];
+ float diffuseRatioZ[CLDFB_NO_CHANNELS_MAX];
+
+} DIFFUSE_DISTRIBUTION_DATA, *DIFFUSE_DISTRIBUTION_HANDLE;
+
+
/* Parametric binaural data structure */
typedef struct ivas_dirac_dec_binaural_data_structure
{
@@ -145,11 +499,15 @@ typedef struct ivas_dirac_dec_binaural_data_structure
float processMtxImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX];
float processMtxDecRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX];
float processMtxDecImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX];
- uint16_t useSubframeMode; /* 0 = process in 20 ms frames, 1 = process in 5 ms subframes */
uint16_t useTdDecorr;
ivas_td_decorr_state_t *hTdDecorr;
float reqularizationFactor;
+ DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist;
+
+ HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params;
+ HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state;
+
} DIRAC_DEC_BIN_DATA, *DIRAC_DEC_BIN_HANDLE;
typedef struct ivas_binaural_rendering_conv_module_struct
diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c
index e60268e8a86d6f286932b8cf148dd6f144ff5a4a..c8c4cabc3baa8a9d9631d2bf3e41083994d6a1f7 100644
--- a/lib_rend/lib_rend.c
+++ b/lib_rend/lib_rend.c
@@ -2994,11 +2994,11 @@ static ivas_error initMasaDummyDecForMcOut(
}
decDummy->hQMetaData->coherence_flag = 1;
- if ( ( error = ivas_dirac_dec_open( decDummy ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_dec_config( decDummy, DIRAC_OPEN ) ) != IVAS_ERR_OK )
{
return error;
}
- decDummy->hDirAC->dirac_bs_md_write_idx = 0;
+ decDummy->hSpatParamRendCom->dirac_bs_md_write_idx = 0;
if ( decDummy->renderer_type == RENDERER_STEREO_PARAMETRIC )
{
@@ -3072,11 +3072,11 @@ static ivas_error initMasaDummyDecForSbaOut(
}
decDummy->hQMetaData->coherence_flag = 1;
- if ( ( error = ivas_dirac_dec_open( decDummy ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_dec_config( decDummy, DIRAC_OPEN ) ) != IVAS_ERR_OK )
{
return error;
}
- decDummy->hDirAC->dirac_bs_md_write_idx = 0;
+ decDummy->hSpatParamRendCom->dirac_bs_md_write_idx = 0;
numCldfbAnalyses = decDummy->nchan_transport;
numCldfbSyntheses = decDummy->hDecoderConfig->nchan_out;
@@ -3146,11 +3146,11 @@ static ivas_error initMasaDummyDecForBinauralOut(
decDummy->ivas_format = MASA_FORMAT;
decDummy->transport_config = AUDIO_CONFIG_INVALID;
- if ( ( error = ivas_dirac_dec_open( decDummy ) ) != IVAS_ERR_OK )
+ if ( ( error = ivas_dirac_dec_config( decDummy, DIRAC_OPEN ) ) != IVAS_ERR_OK )
{
return error;
}
- decDummy->hDirAC->dirac_bs_md_write_idx = 0;
+ decDummy->hSpatParamRendCom->dirac_bs_md_write_idx = 0;
if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &decDummy->hHrtfParambin ) ) != IVAS_ERR_OK )
{
@@ -3245,6 +3245,8 @@ static DecoderDummy *initDecoderDummy(
decDummy->hVBAPdata = NULL; // note: not used at the moment
decDummy->hMasa = NULL;
decDummy->hDiracDecBin = NULL;
+ decDummy->hDirACRend = NULL;
+ decDummy->hSpatParamRendCom = NULL;
decDummy->hQMetaData = NULL;
decDummy->hHrtfParambin = NULL;
decDummy->hHeadTrackData = NULL;
@@ -3432,6 +3434,8 @@ static void freeDecoderDummy(
}
/* DirAC handle */
+ ivas_dirac_rend_close( &( pDecDummy->hDirACRend ) );
+ ivas_spat_hSpatParamRendCom_close( &( pDecDummy->hSpatParamRendCom ) );
ivas_dirac_dec_close( &( pDecDummy->hDirAC ) );
/* Qmetadata handle */
@@ -3447,6 +3451,9 @@ static void freeDecoderDummy(
pDecDummy->hoa_dec_mtx = NULL;
}
+ /* Parametric binaural renderer HRTF structure */
+ free( pDecDummy->hHrtfParambin );
+
/* Parametric binaural renderer handle */
ivas_dirac_dec_close_binaural_data( &pDecDummy->hDiracDecBin );
@@ -7822,41 +7829,41 @@ static ivas_error renderActiveInputsSba(
static void copyMasaMetadataToDiracRenderer(
MASA_METADATA_FRAME *meta,
- DIRAC_DEC_HANDLE hDirAC )
+ SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom )
{
int16_t band, sf, bin;
int16_t meta_write_index;
- hDirAC->numSimultaneousDirections = meta->descriptive_meta.numberOfDirections + 1;
+ hSpatParamRendCom->numSimultaneousDirections = meta->descriptive_meta.numberOfDirections + 1;
for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
{
- meta_write_index = ( hDirAC->dirac_bs_md_write_idx + sf ) % hDirAC->dirac_md_buffer_length;
+ meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + sf ) % hSpatParamRendCom->dirac_md_buffer_length;
for ( band = 0; band < MASA_MAXIMUM_CODING_SUBBANDS; band++ )
{
for ( bin = MASA_band_grouping_24[band]; bin < MASA_band_grouping_24[band + 1]; bin++ )
{
- hDirAC->azimuth[meta_write_index][bin] = (int16_t) meta->directional_meta[0].azimuth[sf][band];
- hDirAC->elevation[meta_write_index][bin] = (int16_t) meta->directional_meta[0].elevation[sf][band];
- hDirAC->energy_ratio1[meta_write_index][bin] = meta->directional_meta[0].energy_ratio[sf][band];
- hDirAC->diffuseness_vector[meta_write_index][bin] = 1.0f - meta->directional_meta[0].energy_ratio[sf][band];
- hDirAC->spreadCoherence[meta_write_index][bin] = meta->directional_meta[0].spread_coherence[sf][band];
- hDirAC->surroundingCoherence[meta_write_index][bin] = meta->common_meta.surround_coherence[sf][band];
-
- if ( hDirAC->numSimultaneousDirections == 2 )
+ hSpatParamRendCom->azimuth[meta_write_index][bin] = (int16_t) meta->directional_meta[0].azimuth[sf][band];
+ hSpatParamRendCom->elevation[meta_write_index][bin] = (int16_t) meta->directional_meta[0].elevation[sf][band];
+ hSpatParamRendCom->energy_ratio1[meta_write_index][bin] = meta->directional_meta[0].energy_ratio[sf][band];
+ hSpatParamRendCom->diffuseness_vector[meta_write_index][bin] = 1.0f - meta->directional_meta[0].energy_ratio[sf][band];
+ hSpatParamRendCom->spreadCoherence[meta_write_index][bin] = meta->directional_meta[0].spread_coherence[sf][band];
+ hSpatParamRendCom->surroundingCoherence[meta_write_index][bin] = meta->common_meta.surround_coherence[sf][band];
+
+ if ( hSpatParamRendCom->numSimultaneousDirections == 2 )
{
- hDirAC->azimuth2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].azimuth[sf][band];
- hDirAC->elevation2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].elevation[sf][band];
- hDirAC->energy_ratio2[meta_write_index][bin] = meta->directional_meta[1].energy_ratio[sf][band];
- hDirAC->diffuseness_vector[meta_write_index][bin] -= meta->directional_meta[1].energy_ratio[sf][band];
- hDirAC->spreadCoherence2[meta_write_index][bin] = meta->directional_meta[1].spread_coherence[sf][band];
+ hSpatParamRendCom->azimuth2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].azimuth[sf][band];
+ hSpatParamRendCom->elevation2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].elevation[sf][band];
+ hSpatParamRendCom->energy_ratio2[meta_write_index][bin] = meta->directional_meta[1].energy_ratio[sf][band];
+ hSpatParamRendCom->diffuseness_vector[meta_write_index][bin] -= meta->directional_meta[1].energy_ratio[sf][band];
+ hSpatParamRendCom->spreadCoherence2[meta_write_index][bin] = meta->directional_meta[1].spread_coherence[sf][band];
}
}
}
}
- hDirAC->dirac_bs_md_write_idx = ( hDirAC->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hDirAC->dirac_md_buffer_length;
+ hSpatParamRendCom->dirac_bs_md_write_idx = ( hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length;
return;
}
@@ -7868,7 +7875,7 @@ static void renderMasaToMc(
float tmpBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
copyBufferTo2dArray( masaInput->base.inputBuffer, tmpBuffer );
- copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hDirAC );
+ copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hSpatParamRendCom );
if ( masaInput->decDummy->renderer_type == RENDERER_STEREO_PARAMETRIC )
{
@@ -7891,7 +7898,7 @@ static void renderMasaToSba(
float tmpBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
copyBufferTo2dArray( masaInput->base.inputBuffer, tmpBuffer );
- copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hDirAC );
+ copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hSpatParamRendCom );
ivas_dirac_dec( masaInput->decDummy, tmpBuffer, masaInput->base.inputBuffer.config.numChannels );
@@ -7907,7 +7914,7 @@ static void renderMasaToBinaural(
float tmpBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
copyBufferTo2dArray( masaInput->base.inputBuffer, tmpBuffer );
- copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hDirAC );
+ copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hSpatParamRendCom );
ivas_dirac_dec_binaural( masaInput->decDummy, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer, masaInput->base.inputBuffer.config.numChannels );
diff --git a/scripts/config/self_test.prm b/scripts/config/self_test.prm
index a4e3fd041f833e25084ed69b4973f0742ed42d72..f0b30c28cf9395f3df439267b6f33d4d69905baa 100644
--- a/scripts/config/self_test.prm
+++ b/scripts/config/self_test.prm
@@ -754,6 +754,22 @@
../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit
../IVAS_dec HOA3 48 bit testv/stv3OA48c.wav_sw_48-48_HOA3.tst
+// SBA 3OA bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, MONO out
+../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit
+../IVAS_dec MONO 48 bit testv/stv3OA48c.wav_sw_48-48_MONO.tst
+
+// SBA 3OA bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, STEREO out
+../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit
+../IVAS_dec STEREO 48 bit testv/stv3OA48c.wav_sw_48-48_STEREO.tst
+
+// SBA 3OA bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out
+../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit
+../IVAS_dec BINAURAL 48 bit testv/stv3OA48c.wav_sw_48-48_BINAURAL.tst
+
+// SBA 3OA bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, FOA out
+../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit
+../IVAS_dec FOA 48 bit testv/stv3OA48c.wav_sw_48-48_FOA.tst
+
// SBA planar 3OA bitrate switching from 24.4 kbps to 256 kbps, 48kHz in, 48kHz out, 7_1_4 out
../IVAS_cod -sba -3 ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv3OA48c.wav bit
../IVAS_dec 7_1_4 48 bit testv/stv3OA48c.wav_sw_48-48_7_1_4.tst
@@ -928,10 +944,43 @@
../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit
../IVAS_dec 5_1 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_5_1.tst
+// MASA 1dir 1TC bitrate switching from 13.2 kbps to 128 kbps, 48kHz in, 48kHz out, STEREO out
+../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit
+../IVAS_dec STEREO 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_STEREO.tst
+
+// MASA 1dir 1TC bitrate switching from 13.2 kbps to 128 kbps, 48kHz in, 48kHz out, BINAURAL out
+../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit
+../IVAS_dec BINAURAL 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_BINAURAL.tst
+
+// MASA 1dir 1TC bitrate switching from 13.2 kbps to 128 kbps, 48kHz in, 48kHz out, FOA out
+../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit
+../IVAS_dec FOA 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_FOA.tst
+
// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out
../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit
../IVAS_dec BINAURAL 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_BINAURAL.tst
+// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, MONO out
+../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit
+../IVAS_dec MONO 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_MONO.tst
+
+// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, 7_1 out
+../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit
+../IVAS_dec 7_1 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_7_1.tst
+
+// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, MONO out
+../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit
+../IVAS_dec MONO 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_MONO.tst
+
+// MASA 2dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, 7_1 out
+../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv2MASA2TC48c.wav bit
+../IVAS_dec 7_1 48 bit testv/stv2MASA2TC48c.wav_sw_48-48_7_1.tst
+
+// MASA 2dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out
+../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv2MASA2TC48c.wav bit
+../IVAS_dec BINAURAL 48 bit testv/stv2MASA2TC48c.wav_sw_48-48_BINAURAL.tst
+
+
// Multi-channel 5_1 at 13.2 kbps, 48kHz in, 48kHz out
@@ -1138,6 +1187,10 @@
../IVAS_cod -mc 7_1_4 ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv714MC48c.wav bit
../IVAS_dec -FEC 5 STEREO 32 bit testv/stv714MC48c.wav_sw_48-32_stereo.tst
+// Multi-channel 7_1_4 bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out
+../IVAS_cod -mc 7_1_4 ../scripts/switchPaths/sw_mctech_5fr.bin 48 testv/stv714MC48c.wav bit
+../IVAS_dec BINAURAL 48 bit testv/stv51MC48c.wav_sw_48-48_BINAURAL.tst
+
// Multi-channel 5_1_4 at 512 kbps, 48kHz in, 16kHz out, BINAURAL_ROOM out (Model from file)
../IVAS_cod -mc 5_1_4 512000 48 testv/stv514MC48c.wav bit