From 64850a954cee210093bb3851e16c9dbf85130ae3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 24 Jan 2024 14:49:23 +0530 Subject: [PATCH] cleanup of qmetadata related functions [x] Few intermediate float/fixed conversion code cleaned up. --- lib_com/ivas_prot.h | 3 +- lib_dec/ivas_dirac_dec.c | 127 +++++++++++++------------------------ lib_dec/ivas_masa_dec.c | 30 ++++++++- lib_rend/ivas_dirac_rend.c | 78 +++++++++++------------ 4 files changed, 114 insertions(+), 124 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index c16e1fd0b..e4bc8a0c5 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3293,8 +3293,7 @@ void ivas_qmetadata_to_dirac_fx( 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 */ - Word32 q + int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ); #else void ivas_qmetadata_to_dirac( diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 86245537b..365cb006c 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1080,10 +1080,35 @@ void ivas_dirac_dec_read_BS( st->next_bit_pos = next_bit_pos_orig; } - + IF( hDirAC != NULL && hSpatParamRendCom != NULL ) { - ivas_qmetadata_to_dirac_fx( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands, 30 ); + for (i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++) { + for ( j = 0; j < hSpatParamRendCom->num_freq_bands; j++) { + hSpatParamRendCom->diffuseness_vector_fx[i][j] = float_to_fix(hSpatParamRendCom->diffuseness_vector[i][j], 30); + hSpatParamRendCom->energy_ratio1_fx[i][j] = float_to_fix(hSpatParamRendCom->energy_ratio1[i][j], 30); + IF(hodirac_flag) + { + hSpatParamRendCom->energy_ratio2_fx[i][j] = float_to_fix(hSpatParamRendCom->energy_ratio2[i][j], 30); + } + hSpatParamRendCom->surroundingCoherence_fx[i][j] = float_to_fix16(hSpatParamRendCom->surroundingCoherence[i][j], 15); + hSpatParamRendCom->spreadCoherence_fx[i][j] = float_to_fix16(hSpatParamRendCom->spreadCoherence[i][j], 15); + } + } + ivas_qmetadata_to_dirac_fx( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands ); + + for (i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++) { + for ( j = 0; j < hSpatParamRendCom->num_freq_bands; j++) { + hSpatParamRendCom->diffuseness_vector[i][j] = fix_to_float(hSpatParamRendCom->diffuseness_vector_fx[i][j], 30); + hSpatParamRendCom->energy_ratio1[i][j] = fix_to_float(hSpatParamRendCom->energy_ratio1_fx[i][j], 30); + IF(hodirac_flag) + { + hSpatParamRendCom->energy_ratio2[i][j] = fix_to_float(hSpatParamRendCom->energy_ratio2_fx[i][j], 30); + } + hSpatParamRendCom->surroundingCoherence[i][j] = fix_to_float(hSpatParamRendCom->surroundingCoherence_fx[i][j], 15); + hSpatParamRendCom->spreadCoherence[i][j] = fix_to_float(hSpatParamRendCom->spreadCoherence_fx[i][j], 15); + } + } } return; } @@ -1241,8 +1266,7 @@ void ivas_qmetadata_to_dirac_fx( const Word32 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 */ - Word32 q + int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ) { Word16 block, band; @@ -1264,7 +1288,7 @@ void ivas_qmetadata_to_dirac_fx( hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; hSpatParamRendCom->numSimultaneousDirections = add(hSpatParamRendCom->numParametricDirections , hSpatParamRendCom->numIsmDirections); - + IF (hMasa != NULL && ivas_total_brate > IVAS_SID_5k2) { Word16 meta_write_index; @@ -1281,36 +1305,24 @@ void ivas_qmetadata_to_dirac_fx( hSpatParamRendCom->azimuth[meta_write_index][b] = extract_h(L_shr(q_direction->band_data[band].azimuth_fx[block], 6)); hSpatParamRendCom->elevation[meta_write_index][b] = extract_h(L_shr(q_direction->band_data[band].elevation_fx[block], 6)); hSpatParamRendCom->energy_ratio1_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block]; - hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub(1 << q, q_direction->band_data[band].energy_ratio_fx[block]); - - /*TODO : remove float code*/ - hSpatParamRendCom->energy_ratio1[meta_write_index][b] = fix_to_float(q_direction->band_data[band].energy_ratio_fx[block] , q); - hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = fix_to_float(hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] , q); + hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub(ONE_IN_Q30, q_direction->band_data[band].energy_ratio_fx[block]); IF (q_direction->coherence_band_data != NULL) { hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]]; - /*TODO : remove float code*/ - hSpatParamRendCom->spreadCoherence[meta_write_index][b] = fix16_to_float(hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] , 15); } ELSE { hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = 0; - /*TODO : remove float code*/ - hSpatParamRendCom->spreadCoherence[meta_write_index][b] = 0.0f; } IF (hQMetaData->surcoh_band_data != NULL) { hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = ivas_divde_255[hQMetaData->surcoh_band_data[band].surround_coherence[block]];/*q15*/ - /*TODO : remove float code*/ - hSpatParamRendCom->surroundingCoherence[meta_write_index][b] = fix16_to_float(hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] , 15); } ELSE { hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = 0; - /*TODO : remove float code*/ - hSpatParamRendCom->surroundingCoherence[meta_write_index][b] = 0.0f; } } } @@ -1321,7 +1333,7 @@ void ivas_qmetadata_to_dirac_fx( q_direction = &(hQMetaData->q_direction[1]); FOR (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block) { - meta_write_index = (hSpatParamRendCom->dirac_bs_md_write_idx + block) % hSpatParamRendCom->dirac_md_buffer_length; + meta_write_index = (add(hSpatParamRendCom->dirac_bs_md_write_idx , block)) % hSpatParamRendCom->dirac_md_buffer_length; FOR (band = 0; band < hMasa->config.numCodingBands; ++band) { @@ -1331,29 +1343,20 @@ void ivas_qmetadata_to_dirac_fx( hSpatParamRendCom->elevation2[meta_write_index][b] = extract_h(L_shr(q_direction->band_data[band].elevation_fx[block], 6)); hSpatParamRendCom->energy_ratio2_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block]; hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub(hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b], q_direction->band_data[band].energy_ratio_fx[block]); - /*TODO : remove float code*/ - hSpatParamRendCom->energy_ratio2[meta_write_index][b] = fix_to_float(hSpatParamRendCom->energy_ratio2_fx[meta_write_index][b], q); - hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = fix_to_float(hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b], q); /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */ IF(hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] < 0) { hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = 0; - /*TODO : remove float code*/ - hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = 0.0f; } IF (q_direction->coherence_band_data != NULL) { hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]]; - /*TODO : remove float code*/ - hSpatParamRendCom->spreadCoherence2[meta_write_index][b] = fix16_to_float(hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b], 15); } ELSE { hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = 0; - /*TODO : remove float code*/ - hSpatParamRendCom->spreadCoherence2[meta_write_index][b] = 0.0f; } } } @@ -1364,12 +1367,9 @@ void ivas_qmetadata_to_dirac_fx( /* 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); - /*TODO : remove float code*/ - set_zero(hSpatParamRendCom->energy_ratio2[meta_write_index], hSpatParamRendCom->num_freq_bands); - set_zero(hSpatParamRendCom->spreadCoherence2[meta_write_index], hSpatParamRendCom->num_freq_bands); + meta_write_index = add(hSpatParamRendCom->dirac_bs_md_write_idx , block) % hSpatParamRendCom->dirac_md_buffer_length; + set16_fx(hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands); + set16_fx(hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands); set32_fx(hSpatParamRendCom->energy_ratio2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands); set16_fx(hSpatParamRendCom->spreadCoherence2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands); @@ -1434,22 +1434,13 @@ void ivas_qmetadata_to_dirac_fx( hSpatParamRendCom->spreadCoherence_fx[block][b] = 0; hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0; - hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = 0; - hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0; - hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0; + hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0; + hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0; hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0; - - /*TODO : Remove float code*/ - 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; } } @@ -1479,7 +1470,7 @@ void ivas_qmetadata_to_dirac_fx( } diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0]; - diffuseness_fx = L_sub(float_to_fix(1.0f,q) , q_direction->band_data[qBand_idx].energy_ratio_fx[0]); + diffuseness_fx = L_sub(ONE_IN_Q30 , q_direction->band_data[qBand_idx].energy_ratio_fx[0]); FOR (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) { @@ -1491,18 +1482,16 @@ void ivas_qmetadata_to_dirac_fx( IF(q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] < 0) { - q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] = L_add(q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata], float_to_fix(360.0f, 22)); - /*TODO: Remove float code*/ - q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] = fix_to_float(q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] , 22); + q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] = L_add(q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata], 1509949440/*360.0F in Q22*/); } IF (hMasa == NULL && hodirac_flag) { azimuth_fx = q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata]; elevation_fx = q_direction[idx_sec].band_data[qBand_idx].elevation_fx[block_qmetadata]; - diffuseness_fx = L_sub(float_to_fix(1.f, q), q_direction[0].band_data[qBand_idx].energy_ratio_fx[block_qmetadata]); + diffuseness_fx = L_sub(ONE_IN_Q30, q_direction[0].band_data[qBand_idx].energy_ratio_fx[block_qmetadata]); diffuseness_sec_fx = q_direction[1].band_data[qBand_idx].energy_ratio_fx[block_qmetadata]; - assert(diffuseness_sec_fx < float_to_fix(1.0001f,q) && diffuseness_sec_fx > float_to_fix(-0.0001f,q)); + assert(diffuseness_sec_fx < 1073849216/*1.0001f in Q30*/ && diffuseness_sec_fx > -107374/*-0.0001f in Q30*/); } ELSE { @@ -1515,8 +1504,8 @@ void ivas_qmetadata_to_dirac_fx( IF (hodirac_flag) { - azi = extract_h(L_shr((L_add(azimuth_fx, float_to_fix(0.5f, 22))), 6)); - ele = extract_h(L_shr((L_add(elevation_fx, float_to_fix(0.5f, 22))), 6)); + azi = extract_h(L_shr((L_add(azimuth_fx, ONE_IN_Q21)), 6)); + ele = extract_h(L_shr((L_add(elevation_fx, ONE_IN_Q21)), 6)); /*addition of one to compensate precision loss*/ IF (azi < 0) { azi += 1; @@ -1566,37 +1555,25 @@ void ivas_qmetadata_to_dirac_fx( IF (ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL) { hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[q_direction->coherence_band_data[qBand_idx].spread_coherence[block]]; - /*TODO : remove float code*/ - hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = fix16_to_float(hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b], 15); } ELSE { hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0; - /*TODO : remove float code*/ - hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f; } IF (ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL) { hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0]]; - /*TODO : remove float code*/ - hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = fix16_to_float(hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b], 15); } ELSE { hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0; - /*TODO : remove float code*/ - hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; } hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio_fx[0]; hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx; - /*TODO : remove float code*/ - hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = fix_to_float(hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b], q); - hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = fix_to_float(hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b], q); - IF (hodirac_flag) { IF (idx_sec == 0) @@ -1604,17 +1581,13 @@ void ivas_qmetadata_to_dirac_fx( hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele; hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi; hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0; - /*TODO : remove float code*/ - hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0.f; } ELSE { assert(idx_sec == 1); hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele; hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi; - hSpatParamRendCom->energy_ratio2_fx[tmp_write_idx_band][b] = L_sub(float_to_fix(1.f, q) , diffuseness_sec_fx); - /*TODO : remove float code*/ - hSpatParamRendCom->energy_ratio2[tmp_write_idx_band][b] = fix_to_float(hSpatParamRendCom->energy_ratio2_fx[tmp_write_idx_band][b], q); + hSpatParamRendCom->energy_ratio2_fx[tmp_write_idx_band][b] = L_sub(ONE_IN_Q30 , diffuseness_sec_fx); } } ELSE @@ -1636,7 +1609,6 @@ void ivas_qmetadata_to_dirac_fx( FOR (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) { -#ifdef IVAS_FLOAT_FIXED hSpatParamRendCom->spreadCoherence_fx[block][b] = 0; hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0; hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0; @@ -1644,19 +1616,10 @@ void ivas_qmetadata_to_dirac_fx( hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0; hSpatParamRendCom->energy_ratio1_fx[block][b] = 0; hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0; -#endif - /*TODO : remove float code*/ - hSpatParamRendCom->spreadCoherence[block][b] = 0.0f; - hSpatParamRendCom->surroundingCoherence[block][b] = 0.0f; - hSpatParamRendCom->energy_ratio1[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; + tmp_write_idx_band = add(tmp_write_idx_band , 1) % hSpatParamRendCom->dirac_md_buffer_length; } } } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 3a37fc231..f37963740 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -590,7 +590,35 @@ ivas_error ivas_masa_decode( } } - ivas_qmetadata_to_dirac_fx(hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0, 30); + for ( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++) { + for ( int j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++) { + st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j] = float_to_fix(st_ivas->hSpatParamRendCom->diffuseness_vector[i][j], 30); + st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j] = float_to_fix(st_ivas->hSpatParamRendCom->energy_ratio1[i][j], 30); + IF(hQMetaData->no_directions == 2) + { + st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j] = float_to_fix(st_ivas->hSpatParamRendCom->energy_ratio2[i][j], 30); + st_ivas->hSpatParamRendCom->spreadCoherence2_fx[i][j] = float_to_fix16(st_ivas->hSpatParamRendCom->spreadCoherence2[i][j], 15); + } + st_ivas->hSpatParamRendCom->surroundingCoherence_fx[i][j] = float_to_fix16(st_ivas->hSpatParamRendCom->surroundingCoherence[i][j], 15); + st_ivas->hSpatParamRendCom->spreadCoherence_fx[i][j] = float_to_fix16(st_ivas->hSpatParamRendCom->spreadCoherence[i][j], 15); + } + } + + ivas_qmetadata_to_dirac_fx(hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0); + + for ( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++) { + for ( int j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++) { + st_ivas->hSpatParamRendCom->diffuseness_vector[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j], 30); + st_ivas->hSpatParamRendCom->energy_ratio1[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j], 30); + IF(hQMetaData->no_directions == 2) + { + st_ivas->hSpatParamRendCom->energy_ratio2[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j], 30); + st_ivas->hSpatParamRendCom->spreadCoherence2[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->spreadCoherence2_fx[i][j], 15); + } + st_ivas->hSpatParamRendCom->surroundingCoherence[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->surroundingCoherence_fx[i][j], 15); + st_ivas->hSpatParamRendCom->spreadCoherence[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->spreadCoherence_fx[i][j], 15); + } + } #else ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0); #endif diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index ad829aa4d..4dbb8437e 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -183,119 +183,119 @@ ivas_error ivas_dirac_allocate_parameters( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_dirac_allocate_parameters_fx( 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 */ + const Word16 params_flag /* i : set of parameters flag */ ) { - int16_t i; + Word16 i; - if ( params_flag == 1 ) + IF ( params_flag == 1 ) { - if ( ( hSpatParamRendCom->azimuth = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->azimuth = ( Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == 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 ) + IF ( ( hSpatParamRendCom->elevation = ( Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == 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 ) + 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 ) + 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 ) + 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 ) + 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" ) ); } #ifdef IVAS_FLOAT_FIXED - if ( ( hSpatParamRendCom->diffuseness_vector_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->diffuseness_vector_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - if ( ( hSpatParamRendCom->energy_ratio1_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->energy_ratio1_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - if ( ( hSpatParamRendCom->spreadCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->spreadCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - if ( ( hSpatParamRendCom->surroundingCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->surroundingCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } #endif - for ( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) + 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 ) + IF ( ( hSpatParamRendCom->azimuth[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof(Word16) ) ) == 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 ) + IF ( ( hSpatParamRendCom->elevation[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof(Word16) ) ) == 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 ) + 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 ) + 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 ) + 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 ) + 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 ); #ifdef IVAS_FLOAT_FIXED - if ( ( hSpatParamRendCom->diffuseness_vector_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->diffuseness_vector_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hSpatParamRendCom->diffuseness_vector_fx[i], 1, hSpatParamRendCom->num_freq_bands ); + set32_fx( hSpatParamRendCom->diffuseness_vector_fx[i], ONE_IN_Q30, hSpatParamRendCom->num_freq_bands ); - if ( ( hSpatParamRendCom->energy_ratio1_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->energy_ratio1_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hSpatParamRendCom->energy_ratio1_fx[i], 0, hSpatParamRendCom->num_freq_bands ); - if ( ( hSpatParamRendCom->spreadCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->spreadCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set16_fx( hSpatParamRendCom->spreadCoherence_fx[i], 0, hSpatParamRendCom->num_freq_bands ); - if ( ( hSpatParamRendCom->surroundingCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->surroundingCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } @@ -303,72 +303,72 @@ ivas_error ivas_dirac_allocate_parameters_fx( #endif } } - else if ( params_flag == 2 ) + ELSE IF ( params_flag == 2 ) { - if ( ( hSpatParamRendCom->azimuth2 = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->azimuth2 = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof(Word16 * ) ) ) == 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 ) + IF ( ( hSpatParamRendCom->elevation2 = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof(Word16 * ) ) ) == 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 ) + 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 ) + 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" ) ); } #ifdef IVAS_FLOAT_FIXED - if ( ( hSpatParamRendCom->energy_ratio2_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->energy_ratio2_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - if ( ( hSpatParamRendCom->spreadCoherence2_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->spreadCoherence2_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } #endif - for ( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) + 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 ) + IF ( ( hSpatParamRendCom->azimuth2[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof(Word16) ) ) == 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 ) + IF ( ( hSpatParamRendCom->elevation2[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof(Word16) ) ) == 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 ) + 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 ) + 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 ); #ifdef IVAS_FLOAT_FIXED - if ( ( hSpatParamRendCom->energy_ratio2_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->energy_ratio2_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hSpatParamRendCom->energy_ratio2_fx[i], 0, hSpatParamRendCom->num_freq_bands ); - if ( ( hSpatParamRendCom->spreadCoherence2_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) + IF ( ( hSpatParamRendCom->spreadCoherence2_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } -- GitLab