From 72748eeb1e77b9f11cadb7cef19732aff8983c95 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 16 Jan 2024 20:40:42 +0530 Subject: [PATCH] FTF changes for ivas_qmetadata_to_dirac_fx and ivas_dirac_dec_set_md_map Added changes for the following funcitons: [x] ivas_qmetadata_to_dirac_fx() [x] ivas_dirac_config_bands_fx() [x] rand_triangular_signed_fx() [x] ivas_dirac_dec_set_md_map() [x] ivas_jbm_dec_get_adapted_subframes() [x] ivas_jbm_dec_get_md_map_even_spacing() [x] ivas_jbm_dec_get_md_map() [x] ivas_get_hodirac_flag_fx() [x] ivas_get_bits_to_encode_fx() [x] ivas_get_spar_table_idx_fx() --- lib_com/ivas_dirac_com.c | 117 +++++- lib_com/ivas_prot.h | 34 +- lib_com/ivas_prot_fx.h | 47 +++ lib_com/ivas_rom_com_fx.c | 77 +++- lib_com/ivas_rom_com_fx.h | 2 + lib_com/ivas_sba_config.c | 110 ++++- lib_com/ivas_spar_com.c | 79 ++++ lib_com/ivas_tools.c | 37 +- lib_dec/ivas_dirac_dec.c | 755 +++++++++++++++++++++++++++++++---- lib_dec/ivas_ism_param_dec.c | 26 +- lib_dec/ivas_jbm_dec.c | 80 ++-- lib_dec/ivas_masa_dec.c | 72 +++- lib_dec/ivas_rom_dec.c | 12 + lib_dec/ivas_rom_dec.h | 4 + lib_dec/ivas_sba_dec.c | 6 +- lib_dec/ivas_spar_decoder.c | 5 + lib_rend/ivas_dirac_rend.c | 502 ++++++++++++++++++++++- lib_rend/ivas_prot_rend.h | 11 + lib_rend/ivas_stat_rend.h | 10 + 19 files changed, 1826 insertions(+), 160 deletions(-) diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 27e3b8393..378e679f4 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -40,7 +40,8 @@ #include "prot.h" #include "cnst.h" #include "wmc_auto.h" - +#include "prot_fx1.h" +#include "prot_fx2.h" /*-----------------------------------------------------------------------* * Local function prototypes @@ -74,7 +75,23 @@ int16_t ivas_get_hodirac_flag( } } +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_get_hodirac_flag_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +) +{ + IF( GT_16( sba_order, 1 ) && GT_32( ivas_total_brate, IVAS_256k ) ) + { + return 1; + } + ELSE + { + return 0; + } +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_sba_config() * @@ -312,6 +329,104 @@ void ivas_dirac_config_bands( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_config_bands_fx( + Word16 *band_grouping, /* o : band grouping */ + const Word16 nbands, /* i : number of bands */ + const Word16 max_band, /* i : maximal band index +1 */ + Word16 *dirac_to_spar_md_bands, + const Word8 useLowerBandRes, + const Word16 enc_param_start_band, + IVAS_FB_MIXER_HANDLE hFbMdft ) +{ + Word16 i; + { + IF( EQ_16( nbands, 5 ) ) + { + Copy( DirAC_band_grouping_5, band_grouping, 5 + 1 ); + } + ELSE IF(EQ_16( nbands, 6 ) ) + { + Copy( DirAC_band_grouping_6, band_grouping, 6 + 1 ); + } + ELSE IF(EQ_16( nbands, 12 ) ) + { + Word16 band; + FOR( band = 0; band < DIRAC_MAX_NBANDS; band++ ) + { + dirac_to_spar_md_bands[band] = band; + } + IF( hFbMdft != NULL ) + { + Word16 sb, idx1, idx2, b; + + idx1 = -1; + sb = 0; + FOR( b = 0; b < max_band; b++ ) + { + idx2 = hFbMdft->pFb->fb_bin_to_band.p_cldfb_map_to_spar_band[b]; + IF( GT_16( idx2, idx1 ) ) + { + band_grouping[sb++] = b; + idx1 = idx2; + } + } + band_grouping[sb] = max_band; + + /* set the remaining bands to max_band to avoid problems for the DirAC parameter estimation with bw < FB */ + FOR( b = sb; b <= nbands; b++ ) + { + band_grouping[b] = max_band; + } + } + ELSE + { + Copy( DirAC_band_grouping_12, band_grouping, 12 + 1 ); + } + + IF( useLowerBandRes ) + { + Word16 step = DIRAC_LOW_BANDRES_STEP; + Word16 reduced_band; + for ( band = enc_param_start_band + 2, reduced_band = enc_param_start_band + 1; band <= DIRAC_MAX_NBANDS; band += step, reduced_band++ ) + { + band_grouping[reduced_band] = band_grouping[band]; + } + FOR( ; reduced_band <= DIRAC_MAX_NBANDS; reduced_band++ ) + { + band_grouping[reduced_band] = max_band; + } + for ( band = enc_param_start_band + ( DIRAC_MAX_NBANDS - enc_param_start_band ) / 2 - 1, reduced_band = DIRAC_MAX_NBANDS - 1; band >= enc_param_start_band; band--, reduced_band -= step ) + { + dirac_to_spar_md_bands[reduced_band] = dirac_to_spar_md_bands[band]; + dirac_to_spar_md_bands[reduced_band - 1] = dirac_to_spar_md_bands[band]; + } + } + ELSE + { + /* always code the last two fb bands together */ + band_grouping[DIRAC_MAX_NBANDS - 1] = max_band; + dirac_to_spar_md_bands[DIRAC_MAX_NBANDS - 1] = DIRAC_MAX_NBANDS - 2; + } + } + ELSE + { + assert( 0 && "nbands must be 5 or 6!" ); + } + } + + /* Limit the band range to band max */ + FOR( i = 0; i < nbands + 1; i++ ) + { + IF( GT_16( band_grouping[i], max_band ) ) + { + band_grouping[i] = max_band; + } + } + + return; +} +#endif /*-------------------------------------------------------------------* * ivas_get_dirac_sba_max_md_bits() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ab01dda53..c276eeda9 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -760,6 +760,11 @@ int16_t get_igf_startline_flt( float rand_triangular_signed( int16_t *seed ); +#ifdef IVAS_FLOAT_FIXED +Word16 rand_triangular_signed_fx( + int16_t *seed, + Word16 *exp_fac); +#endif Word64 var_32_fx( const Word32 *x, /* i : input vector */ const int16_t len, /* i : length of inputvector */ @@ -3269,7 +3274,19 @@ int16_t ivas_qmetadata_dec_sid_decode( int16_t *element_mode, /* o : element mode */ const int16_t ivas_format /* i : IVAS format */ ); - +#ifdef IVAS_FLOAT_FIXED +void ivas_qmetadata_to_dirac_fx( + 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 */ + Word32 q +); +#else void ivas_qmetadata_to_dirac( const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ @@ -3278,9 +3295,9 @@ void ivas_qmetadata_to_dirac( 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 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ); - +#endif ivas_error ivas_qmetadata_open( IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ ); @@ -3709,6 +3726,17 @@ void ivas_dirac_config_bands( IVAS_FB_MIXER_HANDLE hFbMdft ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_config_bands_fx( + Word16 *band_grouping, /* o : band grouping */ + const Word16 nbands, /* i : number of bands */ + const Word16 max_band, /* i : maximal band index +1 */ + Word16 *dirac_to_spar_md_bands, /* o : mapping of DirAC parameter band index to SPAR FB band index */ + const Word8 useLowerBandRes, /* i : flag indicating lower band resolution for DirAC */ + const Word16 enc_param_start_band, /* i : band index of first DirAC parameter band */ + IVAS_FB_MIXER_HANDLE hFbMdft +); +#endif void ivas_get_dirac_sba_max_md_bits( const int32_t sba_total_brate, int16_t *bits_frame_nominal, diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 5ad13d3a4..dffe0656c 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -268,4 +268,51 @@ void stereo_dft_dec_core_switching_fx( Word16 *q, Word16 *q_DFT ); +Word16 ivas_get_hodirac_flag_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + +void ivas_sba_config_fx( + const Word32 sba_total_brate, /* i : SBA total bitrate */ + Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word16 nb_channels, /* i : Number of ambisonic channels */ + Word16 *nchan_transport, /* o : number of transport channels */ + const Word16 sba_planar, /* i : SBA Planar flag */ + Word16 *nSCE, /* o : number of SCEs */ + Word16 *nCPE, /* o : number of CPEs */ + Word16 *element_mode /* o : element mode of the core coder */ +); + +Word16 ivas_get_bits_to_encode_fx( + Word32 val); + +Word16 ivas_get_spar_table_idx_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 bwidth, /* i : audio bandwidth */ + Word16 *bitlen, /* o : number of bits */ + Word16 *ind /* o : indice */ +); + +Word16 ivas_get_sba_num_TCs_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + +Word16 ivas_sba_get_nchan_fx( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 sba_planar /* i : SBA planar flag */ +); + +void ivas_dirac_dec_set_md_map_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ +); + +void ivas_jbm_dec_get_adapted_subframes_fx( + const Word16 nCldfbTs, /* i : number of time slots in the current frame */ + Word16 *subframe_nbslots, /* i/o: subframe grid */ + Word16 *nb_subframes /* i/o: number of subframes in the frame */ +); #endif \ No newline at end of file diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index ab7cf3aec..7a0dcd35f 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -225,26 +225,61 @@ const Word16 dft_trigo_32k_fx[STEREO_DFT_N_32k_ENC / 4 + 1] = const Word16 dft_trigo_48k_fx[STEREO_DFT_N_MAX_ENC / 4 + 1] = { - 0, 107, 214, 321, 428, 536, 643, 750, 857, 964, 1072, 1179, 1286, 1393, 1500, 1607, 1714, 1822, 1929, 2036, 2143, 2250, 2357, 2464, 2570, 2677, 2784, 2891, 2998, - 3105, 3211, 3318, 3425, 3531, 3638, 3744, 3851, 3957, 4064, 4170, 4277, 4383, 4489, 4595, 4701, 4808, 4914, 5020, 5126, 5231, 5337, 5443, 5549, 5654, 5760, 5866, - 5971, 6076, 6182, 6287, 6392, 6497, 6602, 6707, 6812, 6917, 7022, 7127, 7231, 7336, 7440, 7545, 7649, 7753, 7857, 7961, 8065, 8169, 8273, 8377, 8480, 8584, 8687, - 8791, 8894, 8997, 9100, 9203, 9306, 9409, 9512, 9614, 9717, 9819, 9921, 10023, 10125, 10227, 10329, 10431, 10532, 10634, 10735, 10837, 10938, 11039, 11140, 11240, - 11341, 11442, 11542, 11642, 11742, 11843, 11942, 12042, 12142, 12241, 12341, 12440, 12539, 12638, 12737, 12836, 12934, 13033, 13131, 13229, 13327, 13425, 13523, - 13621, 13718, 13815, 13913, 14010, 14106, 14203, 14300, 14396, 14492, 14589, 14684, 14780, 14876, 14971, 15067, 15162, 15257, 15352, 15446, 15541, 15635, 15729, - 15823, 15917, 16011, 16104, 16197, 16291, 16384, 16476, 16569, 16661, 16754, 16846, 16938, 17029, 17121, 17212, 17303, 17394, 17485, 17576, 17666, 17756, 17846, - 17936, 18026, 18115, 18204, 18293, 18382, 18471, 18559, 18648, 18736, 18824, 18911, 18999, 19086, 19173, 19260, 19347, 19433, 19519, 19605, 19691, 19777, 19862, - 19947, 20032, 20117, 20202, 20286, 20370, 20454, 20538, 20621, 20704, 20787, 20870, 20953, 21035, 21117, 21199, 21281, 21362, 21443, 21524, 21605, 21685, 21766, - 21846, 21926, 22005, 22084, 22164, 22242, 22321, 22399, 22478, 22556, 22633, 22711, 22788, 22865, 22941, 23018, 23094, 23170, 23246, 23321, 23396, 23471, 23546, - 23620, 23695, 23769, 23842, 23916, 23989, 24062, 24134, 24207, 24279, 24351, 24422, 24494, 24565, 24636, 24706, 24777, 24847, 24916, 24986, 25055, 25124, 25193, - 25261, 25330, 25397, 25465, 25532, 25599, 25666, 25733, 25799, 25865, 25931, 25996, 26061, 26126, 26191, 26255, 26319, 26383, 26446, 26509, 26572, 26635, 26697, - 26759, 26821, 26882, 26944, 27004, 27065, 27125, 27185, 27245, 27305, 27364, 27423, 27481, 27539, 27597, 27655, 27712, 27769, 27826, 27883, 27939, 27995, 28050, - 28106, 28161, 28215, 28270, 28324, 28377, 28431, 28484, 28537, 28589, 28642, 28694, 28745, 28797, 28848, 28898, 28949, 28999, 29049, 29098, 29147, 29196, 29245, - 29293, 29341, 29388, 29435, 29482, 29529, 29575, 29621, 29667, 29712, 29758, 29802, 29847, 29891, 29935, 29978, 30021, 30064, 30106, 30149, 30190, 30232, 30273, - 30314, 30355, 30395, 30435, 30474, 30514, 30552, 30591, 30629, 30667, 30705, 30742, 30779, 30816, 30852, 30888, 30924, 30959, 30994, 31029, 31063, 31097, 31130, - 31164, 31197, 31229, 31262, 31294, 31325, 31357, 31387, 31418, 31448, 31478, 31508, 31537, 31566, 31595, 31623, 31651, 31679, 31706, 31733, 31759, 31785, 31811, - 31837, 31862, 31887, 31912, 31936, 31960, 31983, 32006, 32029, 32051, 32074, 32095, 32117, 32138, 32159, 32179, 32199, 32219, 32238, 32257, 32276, 32294, 32312, - 32330, 32347, 32364, 32381, 32397, 32413, 32428, 32444, 32458, 32473, 32487, 32501, 32514, 32528, 32540, 32553, 32565, 32577, 32588, 32599, 32610, 32620, 32630, - 32640, 32649, 32658, 32666, 32675, 32683, 32690, 32697, 32704, 32711, 32717, 32723, 32728, 32733, 32738, 32742, 32746, 32750, 32753, 32756, 32759, 32761, 32763, - 32765, 32766, 32767, 32767, 32767 + 0, 107, 214, 321, 428, 536, 643, 750, 857, 964, 1072, 1179, 1286, 1393, 1500, 1607, 1714, 1822, 1929, 2036, 2143, 2250, 2357, 2464, 2570, 2677, 2784, 2891, 2998, + 3105, 3211, 3318, 3425, 3531, 3638, 3744, 3851, 3957, 4064, 4170, 4277, 4383, 4489, 4595, 4701, 4808, 4914, 5020, 5126, 5231, 5337, 5443, 5549, 5654, 5760, 5866, + 5971, 6076, 6182, 6287, 6392, 6497, 6602, 6707, 6812, 6917, 7022, 7127, 7231, 7336, 7440, 7545, 7649, 7753, 7857, 7961, 8065, 8169, 8273, 8377, 8480, 8584, 8687, + 8791, 8894, 8997, 9100, 9203, 9306, 9409, 9512, 9614, 9717, 9819, 9921, 10023, 10125, 10227, 10329, 10431, 10532, 10634, 10735, 10837, 10938, 11039, 11140, 11240, + 11341, 11442, 11542, 11642, 11742, 11843, 11942, 12042, 12142, 12241, 12341, 12440, 12539, 12638, 12737, 12836, 12934, 13033, 13131, 13229, 13327, 13425, 13523, + 13621, 13718, 13815, 13913, 14010, 14106, 14203, 14300, 14396, 14492, 14589, 14684, 14780, 14876, 14971, 15067, 15162, 15257, 15352, 15446, 15541, 15635, 15729, + 15823, 15917, 16011, 16104, 16197, 16291, 16384, 16476, 16569, 16661, 16754, 16846, 16938, 17029, 17121, 17212, 17303, 17394, 17485, 17576, 17666, 17756, 17846, + 17936, 18026, 18115, 18204, 18293, 18382, 18471, 18559, 18648, 18736, 18824, 18911, 18999, 19086, 19173, 19260, 19347, 19433, 19519, 19605, 19691, 19777, 19862, + 19947, 20032, 20117, 20202, 20286, 20370, 20454, 20538, 20621, 20704, 20787, 20870, 20953, 21035, 21117, 21199, 21281, 21362, 21443, 21524, 21605, 21685, 21766, + 21846, 21926, 22005, 22084, 22164, 22242, 22321, 22399, 22478, 22556, 22633, 22711, 22788, 22865, 22941, 23018, 23094, 23170, 23246, 23321, 23396, 23471, 23546, + 23620, 23695, 23769, 23842, 23916, 23989, 24062, 24134, 24207, 24279, 24351, 24422, 24494, 24565, 24636, 24706, 24777, 24847, 24916, 24986, 25055, 25124, 25193, + 25261, 25330, 25397, 25465, 25532, 25599, 25666, 25733, 25799, 25865, 25931, 25996, 26061, 26126, 26191, 26255, 26319, 26383, 26446, 26509, 26572, 26635, 26697, + 26759, 26821, 26882, 26944, 27004, 27065, 27125, 27185, 27245, 27305, 27364, 27423, 27481, 27539, 27597, 27655, 27712, 27769, 27826, 27883, 27939, 27995, 28050, + 28106, 28161, 28215, 28270, 28324, 28377, 28431, 28484, 28537, 28589, 28642, 28694, 28745, 28797, 28848, 28898, 28949, 28999, 29049, 29098, 29147, 29196, 29245, + 29293, 29341, 29388, 29435, 29482, 29529, 29575, 29621, 29667, 29712, 29758, 29802, 29847, 29891, 29935, 29978, 30021, 30064, 30106, 30149, 30190, 30232, 30273, + 30314, 30355, 30395, 30435, 30474, 30514, 30552, 30591, 30629, 30667, 30705, 30742, 30779, 30816, 30852, 30888, 30924, 30959, 30994, 31029, 31063, 31097, 31130, + 31164, 31197, 31229, 31262, 31294, 31325, 31357, 31387, 31418, 31448, 31478, 31508, 31537, 31566, 31595, 31623, 31651, 31679, 31706, 31733, 31759, 31785, 31811, + 31837, 31862, 31887, 31912, 31936, 31960, 31983, 32006, 32029, 32051, 32074, 32095, 32117, 32138, 32159, 32179, 32199, 32219, 32238, 32257, 32276, 32294, 32312, + 32330, 32347, 32364, 32381, 32397, 32413, 32428, 32444, 32458, 32473, 32487, 32501, 32514, 32528, 32540, 32553, 32565, 32577, 32588, 32599, 32610, 32620, 32630, + 32640, 32649, 32658, 32666, 32675, 32683, 32690, 32697, 32704, 32711, 32717, 32723, 32728, 32733, 32738, 32742, 32746, 32750, 32753, 32756, 32759, 32761, 32763, + 32765, 32766, 32767, 32767, 32767 +}; + +const Word16 ivas_divde_255[256] = { + 0, 128, 257, 385, 514, 642, 771, 899, 1028, + 1156, 1285, 1413, 1542, 1670, 1799, 1927, 2056, + 2184, 2313, 2441, 2570, 2698, 2827, 2955, 3084, + 3212, 3341, 3469, 3598, 3726, 3855, 3983, 4112, + 4240, 4369, 4497, 4626, 4754, 4883, 5011, 5140, + 5268, 5397, 5525, 5654, 5782, 5911, 6039, 6168, + 6296, 6425, 6553, 6682, 6810, 6939, 7067, 7196, + 7324, 7453, 7581, 7710, 7838, 7967, 8095, 8224, + 8352, 8481, 8609, 8738, 8866, 8995, 9123, 9252, + 9380, 9509, 9637, 9766, 9894, 10023, 10151, 10280, + 10408, 10537, 10665, 10794, 10922, 11051, 11179, 11308, + 11436, 11565, 11693, 11822, 11950, 12079, 12207, 12336, + 12464, 12593, 12721, 12850, 12978, 13107, 13235, 13364, + 13492, 13621, 13749, 13878, 14006, 14135, 14263, 14392, + 14520, 14649, 14777, 14906, 15034, 15163, 15291, 15420, + 15548, 15677, 15805, 15934, 16062, 16191, 16319, 16448, + 16576, 16705, 16833, 16962, 17090, 17219, 17347, 17476, + 17604, 17733, 17861, 17990, 18118, 18247, 18375, 18504, + 18632, 18761, 18889, 19018, 19146, 19275, 19403, 19532, + 19660, 19789, 19917, 20046, 20174, 20303, 20431, 20560, + 20688, 20817, 20945, 21074, 21202, 21331, 21459, 21588, + 21716, 21845, 21973, 22102, 22230, 22359, 22487, 22616, + 22744, 22873, 23001, 23130, 23258, 23387, 23515, 23644, + 23772, 23901, 24029, 24158, 24286, 24415, 24543, 24672, + 24800, 24929, 25057, 25186, 25314, 25443, 25571, 25700, + 25828, 25957, 26085, 26214, 26342, 26471, 26599, 26728, + 26856, 26985, 27113, 27242, 27370, 27499, 27627, 27756, + 27884, 28013, 28141, 28270, 28398, 28527, 28655, 28784, + 28912, 29041, 29169, 29298, 29426, 29555, 29683, 29812, + 29940, 30069, 30197, 30326, 30454, 30583, 30711, 30840, + 30968, 31097, 31225, 31354, 31482, 31611, 31739, 31868, + 31996, 32125, 32253, 32382, 32510, 32639, 32767 }; /* clang-format on */ diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 1a78371ed..f507d4a70 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -52,4 +52,6 @@ extern const Word16 dft_trigo_12k8_fx[STEREO_DFT_N_12k8_ENC / 4 + 1]; extern const Word16 dft_trigo_32k_fx[STEREO_DFT_N_32k_ENC / 4 + 1]; extern const Word16 dft_trigo_48k_fx[STEREO_DFT_N_MAX_ENC / 4 + 1]; +extern const Word16 ivas_divde_255[256]; + #endif \ No newline at end of file diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index ddf8fc6ad..96f0be387 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -42,7 +42,7 @@ #include "ivas_stat_com.h" #include "ivas_rom_com.h" #include "wmc_auto.h" - +#include "ivas_prot_fx.h" /*-------------------------------------------------------------------* * ivas_sba_config() @@ -114,7 +114,72 @@ void ivas_sba_config( return; } +#ifdef IVAS_FLOAT_FIXED +/*not tested*/ +void ivas_sba_config_fx( + const Word32 sba_total_brate, /* i : SBA total bitrate */ + Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word16 nb_channels, /* i : Number of ambisonic channels */ + Word16 *nchan_transport, /* o : number of transport channels */ + const Word16 sba_planar, /* i : SBA Planar flag */ + Word16 *nSCE, /* o : number of SCEs */ + Word16 *nCPE, /* o : number of CPEs */ + Word16 *element_mode /* o : element mode of the core coder */ +) +{ + IF( ( LT_16( sba_order, 0 ) ) && ( LT_16( nb_channels, 0 ) ) ) + { + assert( 0 && "Either order or number of channels must be positive" ); + } + ELSE IF( LT_16( sba_order, 0 ) ) + { + sba_order = ivas_sba_get_order( nb_channels, sba_planar ); + } + ELSE IF( LT_16( nb_channels, 0 ) ) + { + nb_channels = ivas_sba_get_nchan_fx( sba_order, sba_planar ); + } + ELSE + { + IF( sba_planar ) + { + assert( ( EQ_16( add( shl( sba_order, 1 ), 1 ), nb_channels ) ) && "Order and number of channels do not correspond!" ); + } + ELSE + { + assert( ( EQ_16( mult( add( sba_order, 1 ), add( sba_order, 1 ) ), nb_channels ) ) && "Order and number of channels do not correspond!" ); + } + } + + IF( nchan_transport != NULL ) + { + *nchan_transport = ivas_get_sba_num_TCs_fx( sba_total_brate, sba_order ); + } + + /* Configure core coder number of elements*/ + IF( nchan_transport != NULL && nSCE != NULL && nCPE != NULL ) + { + IF( EQ_16( *nchan_transport, 1 ) ) + { + *nSCE = 1; + *nCPE = 0; + *element_mode = IVAS_SCE; + } + ELSE + { + *nSCE = 0; + *nCPE = shr( *nchan_transport, 2 ); + IF( NE_16( mult( 2, ( *nCPE ) ), *nchan_transport ) ) + { + *nCPE = add( *nCPE, 1 ); + } + *element_mode = IVAS_CPE_MDCT; + } + } + return; +} +#endif /*-------------------------------------------------------------------* * ivas_sba_get_order() * @@ -145,6 +210,30 @@ int16_t ivas_sba_get_order( return ( sba_order ); } +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_sba_get_order_fx( + const Word16 nb_channels, /* i : Number of ambisonic channels */ + const Word16 sba_planar /* i : SBA Planar flag */ +) +{ + Word16 sba_order; + Word16 exp = 0; + IF( sba_planar ) + { + sba_order = shr( sub( nb_channels, 1 ), 1 ); + assert( ( EQ_16( add( shl( sba_order, 1 ), 1 ), nb_channels ) ) && "Number of channels not supported in Planar SBA!" ); + } + ELSE + { + sba_order = sub( Sqrt16( nb_channels, &exp ), ONE_IN_Q15 ); // 15 - exp + assert( ( EQ_16( mult( add( sba_order, 1 ), add( sba_order, 1 ) ), nb_channels ) ) && "Number of channels not supported in SBA!" ); + } + + assert( ( sba_order <= 3 ) && "Error: SBA order must be <= 3!" ); + + return ( sba_order ); +} +#endif /*-------------------------------------------------------------------* * ivas_sba_get_analysis_order() @@ -198,7 +287,26 @@ int16_t ivas_sba_get_nchan( return ( nb_channels ); } +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_sba_get_nchan_fx( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 sba_planar /* i : SBA planar flag */ +) +{ + Word16 nb_channels; + IF (sba_planar) + { + nb_channels = add(mult(2 , sba_order) , 1); + } + ELSE + { + nb_channels = mult(add(sba_order , 1) , (sba_order + 1)); + } + + return (nb_channels); +} +#endif /*-------------------------------------------------------------------* * ivas_sba_get_nchan_metadata() * diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 816bc98b4..14880d9aa 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -234,7 +234,54 @@ int16_t ivas_get_spar_table_idx( return table_idx; } +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_get_spar_table_idx_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 bwidth, /* i : audio bandwidth */ + Word16 *bitlen, /* o : number of bits */ + Word16 *ind /* o : indice */ +) +{ + Word16 table_idx = 0, ind1[IVAS_SPAR_BR_TABLE_LEN]; + Word16 i, j = 0, ind2 = -1; + + FOR (i = 0; i < IVAS_SPAR_BR_TABLE_LEN; i++) + { + ind1[j] = 0; + IF ((EQ_32(ivas_spar_br_table_consts[i].ivas_total_brate , ivas_total_brate)) && + (EQ_16(ivas_spar_br_table_consts[i].sba_order , sba_order))) + { + ind1[j++] = i; + } + } + + FOR (i = 0; i < j; i++) + { + IF (EQ_16(ivas_spar_br_table_consts[ind1[i]].bwidth , bwidth)) + { + ind2 = i; + BREAK; + } + } + assert(j > 0); /* to check if bitrate entry is present */ + assert(ind2 >= 0); /* to check if bw entry is present */ + + table_idx = ind1[ind2]; + + IF (ind != NULL) + { + *ind = ind2; + } + + IF (bitlen != NULL) + { + *bitlen = ivas_get_bits_to_encode(j - 1); + } + return table_idx; +} +#endif /*-------------------------------------------------------------------* * ivas_get_sba_num_TCs() * @@ -256,6 +303,21 @@ int16_t ivas_get_sba_num_TCs( return nchan_transport; } +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_get_sba_num_TCs_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +) +{ + Word16 table_idx, nchan_transport; + + table_idx = ivas_get_spar_table_idx_fx(ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL); + + nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + + return nchan_transport; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_get_pred_coeffs() @@ -1959,6 +2021,23 @@ int16_t ivas_get_bits_to_encode( return bits_req; } +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_get_bits_to_encode_fx( + Word32 val) +{ + Word16 bits_req = 0; + + assert(GE_32(val , 0)); + + WHILE (val) + { + bits_req = add(bits_req, 1); + val = L_shr(val,1); + } + + return bits_req; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_set_bitrate_config() diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index efc9e6440..cb3dea6ff 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -39,7 +39,8 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include "ivas_rom_com.h" - +#include "prot_fx1.h" +#include "prot_fx2.h" #define ANGLE_90_DEG_Q22 377487360 #define ANGLE_180_DEG_Q22 754974720 @@ -1464,7 +1465,6 @@ float rand_triangular_signed( int16_t *seed ) { float rand_val; - rand_val = own_random( seed ) * OUTMAX_INV; if ( rand_val <= 0.0f ) { @@ -1478,7 +1478,40 @@ float rand_triangular_signed( } } +#ifdef IVAS_FLOAT_FIXED +Word16 rand_triangular_signed_fx( + Word16 *seed, + Word16 *exp_fac ) +{ + Word16 rand_val; + rand_val = Random( seed ); // q15 + Word16 tmp1, tmp2; + Word16 exp1, exp = 1; + if ( rand_val <= 0 ) + { + /* rand_val in [-1, 0] */ + /*0.5f * (sqrtf(rand_val + 1.0f) - 1)*/ + tmp1 = Sqrt16( add( shr( rand_val, 1 ), ONE_IN_Q14 ), &exp ); + exp1 = BASOP_Util_Add_MantExp(tmp1, exp, negate(ONE_IN_Q14), 1, &tmp2); + tmp2 = shr(tmp2, 1); + *exp_fac = exp1; + return tmp2; + } + else + { + /* rand_val in (0, 1) */ + /*0.5f * ( 1 - sqrtf(1.0f - rand_val))*/ + Word16 one_minus_rand = sub(MAX16B, rand_val); + exp = 0; + tmp1 = Sqrt16(one_minus_rand, &exp); // q15 - exp + exp1 = BASOP_Util_Add_MantExp(ONE_IN_Q14, 1, negate(tmp1), exp, &tmp2); + tmp2 = shr(tmp2, 1); + *exp_fac = exp1; + return tmp2; + } +} +#endif /*-------------------------------------------------------------------* * ceil_log_2() * diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index d0972853f..ec74f1b1a 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -43,7 +43,12 @@ #include "ivas_rom_dec.h" #include "ivas_rom_rend.h" #include "wmc_auto.h" - +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" +#endif /*-----------------------------------------------------------------------* * Local function prototypes @@ -1075,21 +1080,523 @@ void ivas_dirac_dec_read_BS( st->next_bit_pos = next_bit_pos_orig; } - if ( hDirAC != NULL && hSpatParamRendCom != NULL ) + 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 ); - } +#ifdef IVAS_FLOAT_FIXED + //Word32 q = 15; + + //if (hQMetaData->q_direction[0].band_data != NULL) { + // for (int sf = 0; sf < hQMetaData->q_direction[0].cfg.nblocks; sf++) + // { + // for (j = 0; j < hQMetaData->q_direction[0].cfg.nbands; j++) + // { + // if (fabs(hQMetaData->q_direction[0].band_data[j].energy_ratio[sf]) >= 1) + // { + // q = min(q, norm_l((Word32)hQMetaData->q_direction[0].band_data[j].energy_ratio[sf])); + // } + // } + // } + //} + // + //if (hQMetaData->q_direction[1].band_data != NULL) { + // for (int sf = 0; sf < hQMetaData->q_direction[1].cfg.nblocks; sf++) + // { + // for (j = 0; j < hQMetaData->q_direction[1].cfg.nbands; j++) + // { + // if (fabs(hQMetaData->q_direction[1].band_data[j].energy_ratio[sf]) >= 1) + // { + // q = min(q, norm_l((Word32)hQMetaData->q_direction[1].band_data[j].energy_ratio[sf])); + // } + // } + // } + //} + //q -= 1; // guarded bits + //if (hQMetaData->q_direction[0].band_data != NULL) { + // for (int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++) + // { + // for (j = 0; j < hQMetaData->q_direction[0].cfg.nbands; j++) + // { + // hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[sf] = float_to_fix(hQMetaData->q_direction[0].band_data[j].energy_ratio[sf], q); + // } + // } + //} + + //if (hQMetaData->q_direction[1].band_data != NULL) { + // for (int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++) + // { + // for (j = 0; j < hQMetaData->q_direction[1].cfg.nbands; j++) + // { + // hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[sf] = float_to_fix(hQMetaData->q_direction[1].band_data[j].energy_ratio[sf], q); + // } + // } + //} + + for (int d = 0; d < hQMetaData->no_directions; d++) + { + IVAS_QDIRECTION *q_direction; + q_direction = &hQMetaData->q_direction[d]; + int nbands = q_direction->cfg.nbands; + //int nblocks = q_direction->cfg.nblocks; + FOR( j = 0; j < nbands; j++) + { + FOR(Word16 k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++) + { + q_direction->band_data[j].elevation_fx[k] = (Word32)(q_direction->band_data[j].elevation[k] * (1 << 22)); + q_direction->band_data[j].azimuth_fx[k] = (Word32)(q_direction->band_data[j].azimuth[k] * (1 << 22)); + q_direction->band_data[j].energy_ratio_fx[k] = (Word32)(q_direction->band_data[j].energy_ratio[k] * (1 << 30)); + } + } + } + ivas_qmetadata_to_dirac_fx(hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands, 30); + +#else + ivas_qmetadata_to_dirac(hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands); +#endif + + } return; } - /*-----------------------------------------------------------------------* * ivas_qmetadata_to_dirac() * * Copy qmetedata to DirAC parameters for rendering *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_qmetadata_to_dirac_fx( + 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 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 +) +{ + Word16 block, band; + Word16 *seed_ptr; + Word16 band_start, band_end, diff_idx; + Word16 b, ele, azi; + Word32 azimuth_fx, elevation_fx; + Word32 diffuseness_fx; + IVAS_QDIRECTION *q_direction; + Word16 *band_mapping; + Word16 *band_grouping; + Word16 start_band; + Word16 nbands = 0; + Word16 nblocks = 0; + Word16 qBand_idx; + Word16 idx_sec = 0; + Word16 no_secs = 1; + q_direction = &(hQMetaData->q_direction[0]); + + 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; + band_mapping = hMasa->data.band_mapping; + + FOR (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block) + { + meta_write_index = (hSpatParamRendCom->dirac_bs_md_write_idx + block) % hSpatParamRendCom->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) + { + 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); + + 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; + } + } + } + } + + IF (hQMetaData->no_directions == 2) + { + 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; + + 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] = extract_h(L_shr(q_direction->band_data[band].azimuth_fx[block], 6)); + 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; + } + } + } + } + } + ELSE IF (hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2_fx != NULL && hSpatParamRendCom->spreadCoherence2_fx != NULL) + { + /* 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); + + 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); + } + } + } + ELSE /* SBA mode/SID/Zero frame*/ + { + Word16 tmp_write_idx_param_band; + Word16 tmp_write_idx_band; + + Word32 diffuseness_sec_fx = 0; + + /* 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_fx(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_fx(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 = hSpatParamRendCom->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; + + 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->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; + } + } + } + + /* 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 = hSpatParamRendCom->dirac_bs_md_write_idx; + + IF (ivas_format == SBA_FORMAT) + { + qBand_idx = dirac_to_spar_md_bands[band] - start_band; + } + ELSE + { + qBand_idx = band; + } + 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]); + + FOR (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) + { + Word16 block_qmetadata; + + block_qmetadata = min(block, nblocks - 1); + block_qmetadata = max(block_qmetadata, 0); + + + 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); + } + + 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_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)); + } + ELSE + { + azimuth_fx = q_direction->band_data[qBand_idx].azimuth_fx[block_qmetadata]; + elevation_fx = q_direction->band_data[qBand_idx].elevation_fx[block_qmetadata]; + } + FOR (b = band_start; b < band_end; b++) + { + tmp_write_idx_band = tmp_write_idx_param_band; + + 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)); + /*addition of one to compensate precision loss*/ + IF (azi < 0) { + azi += 1; + } + IF (ele < 0) { + ele += 1; + } + } + ELSE + { + Word16 tmp1, tmp4; + Word16 a, b_tmp; + + Word16 exp_factor = 0; + a = rand_triangular_signed_fx(seed_ptr, &exp_factor);//q = exp_factor + tmp1 = mult(a, dirac_dithering_azi_scale_fx[diff_idx]); // exp_factor + 5 + + Word32 tmp1_32 = L_deposit_h(tmp1); + Word16 final_1_exp; + Word32 final_1_32 = BASOP_Util_Add_Mant32Exp(azimuth_fx, 9, tmp1_32, exp_factor + 5, &final_1_exp); + b_tmp = rand_triangular_signed_fx(seed_ptr, &exp_factor);//q = exp_factor + tmp4 = mult(b_tmp, dirac_dithering_ele_scale_fx[diff_idx]);//exp_factor + 4 + + Word32 tmp4_32 = L_deposit_h(tmp4); + Word16 final_2_exp; + Word32 final_2_32 = BASOP_Util_Add_Mant32Exp(elevation_fx, 9, tmp4_32, exp_factor + 4, &final_2_exp); + + + final_1_32 = BASOP_Util_Add_Mant32Exp(final_1_32, final_1_exp, ONE_IN_Q30, 0, &final_1_exp);/*0.5 in q31*/ + final_2_32 = BASOP_Util_Add_Mant32Exp(final_2_32, final_2_exp, ONE_IN_Q30, 0, &final_2_exp); + + azi = extract_h(L_shr(final_1_32, 31 - final_1_exp - 16)); + ele = extract_h(L_shr(final_2_32, 31 - final_2_exp - 16)); + + /*addition of one to compensate precision loss*/ + IF (azi < 0) { + azi += 1; + } + IF (ele < 0) { + ele += 1; + } + /* 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) + { + 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) + { + 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); + } + } + ELSE + { + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi; + } + } + tmp_write_idx_param_band = (tmp_write_idx_param_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; + + } /* for ( block =...) */ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ + + /* Bands not transmitted -> zeroed*/ + FOR (b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++) + { + tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx; + + 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; + hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0; + 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; + } + } + } + /* 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; +} +#else void ivas_qmetadata_to_dirac( const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ @@ -1117,29 +1624,29 @@ void ivas_qmetadata_to_dirac( int16_t idx_sec = 0; int16_t no_secs = 1; - q_direction = &( hQMetaData->q_direction[0] ); + q_direction = &(hQMetaData->q_direction[0]); hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; hSpatParamRendCom->numSimultaneousDirections = hSpatParamRendCom->numParametricDirections + hSpatParamRendCom->numIsmDirections; - if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 ) + 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 ) + 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 = (hSpatParamRendCom->dirac_bs_md_write_idx + block) % hSpatParamRendCom->dirac_md_buffer_length; - for ( band = 0; band < hMasa->config.numCodingBands; ++band ) + 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 ) + 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->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 ( q_direction->coherence_band_data != NULL ) + if (q_direction->coherence_band_data != NULL) { hSpatParamRendCom->spreadCoherence[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; } @@ -1148,7 +1655,7 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->spreadCoherence[meta_write_index][b] = 0.0f; } - if ( hQMetaData->surcoh_band_data != NULL ) + if (hQMetaData->surcoh_band_data != NULL) { hSpatParamRendCom->surroundingCoherence[meta_write_index][b] = hQMetaData->surcoh_band_data[band].surround_coherence[block] / 255.0f; } @@ -1160,29 +1667,29 @@ void ivas_qmetadata_to_dirac( } } - if ( hQMetaData->no_directions == 2 ) + if (hQMetaData->no_directions == 2) { - q_direction = &( hQMetaData->q_direction[1] ); - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) + 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 = (hSpatParamRendCom->dirac_bs_md_write_idx + block) % hSpatParamRendCom->dirac_md_buffer_length; - for ( band = 0; band < hMasa->config.numCodingBands; ++band ) + 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 ) + 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->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]; /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */ - if ( hSpatParamRendCom->diffuseness_vector[meta_write_index][b] < 0.0f ) + if (hSpatParamRendCom->diffuseness_vector[meta_write_index][b] < 0.0f) { hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = 0.0f; } - if ( q_direction->coherence_band_data != NULL ) + if (q_direction->coherence_band_data != NULL) { hSpatParamRendCom->spreadCoherence2[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; } @@ -1194,16 +1701,16 @@ void ivas_qmetadata_to_dirac( } } } - else if ( hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2 != NULL && hSpatParamRendCom->spreadCoherence2 != NULL ) + else if (hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2 != NULL && hSpatParamRendCom->spreadCoherence2 != NULL) { /* zero out old dir2 data */ - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) + 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 ); + 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); } } } @@ -1219,18 +1726,18 @@ void ivas_qmetadata_to_dirac( nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands]; band_grouping = hDirAC->band_grouping; - if ( ivas_total_brate <= IVAS_SID_5k2 && ivas_format != SBA_FORMAT ) + 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 ); + 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 ) + if (ivas_format == SBA_FORMAT) { hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS; } @@ -1239,10 +1746,10 @@ void ivas_qmetadata_to_dirac( 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 ); + 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 ) + if (hQMetaData->q_direction[0].cfg.nblocks == 0) { /* No transmission -> no copy from qmetadata buffers*/ nbands = start_band; @@ -1250,15 +1757,15 @@ void ivas_qmetadata_to_dirac( } /* Low-Bands with no spatial data transmitted, analysis at decoder side */ - for ( band = 0; band < start_band; band++ ) + for (band = 0; band < start_band; band++) { 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++ ) + for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) { - for ( b = band_start; b < band_end; b++ ) + for (b = band_start; b < band_end; b++) { tmp_write_idx_band = tmp_write_idx_param_band; hSpatParamRendCom->spreadCoherence[block][b] = 0.0f; @@ -1271,26 +1778,26 @@ void ivas_qmetadata_to_dirac( 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 = (tmp_write_idx_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; } } } /* Bands with spatial data transmitted */ - if ( hodirac_flag ) + if (hodirac_flag) { no_secs = DIRAC_HO_NUMSECTORS; } - for ( idx_sec = 0; idx_sec < no_secs; idx_sec++ ) + for (idx_sec = 0; idx_sec < no_secs; idx_sec++) { - for ( band = start_band; band < nbands; band++ ) + for (band = start_band; band < nbands; band++) { band_start = band_grouping[band]; band_end = band_grouping[band + 1]; tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx; - if ( ivas_format == SBA_FORMAT ) + if (ivas_format == SBA_FORMAT) { qBand_idx = dirac_to_spar_md_bands[band] - start_band; } @@ -1301,25 +1808,25 @@ void ivas_qmetadata_to_dirac( diffuseness = 1.0f - q_direction->band_data[qBand_idx].energy_ratio[0]; diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0]; - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + 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 ); + 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 ) + 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 ) + 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 ); + assert(diffuseness_sec < 1.0001f && diffuseness_sec > -0.0001f); } else { @@ -1327,25 +1834,25 @@ void ivas_qmetadata_to_dirac( elevation = q_direction->band_data[qBand_idx].elevation[block_qmetadata]; } - for ( b = band_start; b < band_end; b++ ) + for (b = band_start; b < band_end; b++) { tmp_write_idx_band = tmp_write_idx_param_band; - if ( hodirac_flag ) + if (hodirac_flag) { - azi = (int16_t) ( azimuth + 0.5f ); - ele = (int16_t) ( elevation + 0.5f ); + 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 ); + 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 ); + ele = min(90, ele); + ele = max(-90, ele); } - if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) + 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; } @@ -1354,7 +1861,7 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f; } - if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) + 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; } @@ -1367,9 +1874,9 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness; - if ( hodirac_flag ) + if (hodirac_flag) { - if ( idx_sec == 0 ) + if (idx_sec == 0) { hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele; hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi; @@ -1377,7 +1884,7 @@ void ivas_qmetadata_to_dirac( } else { - assert( idx_sec == 1 ); + 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; @@ -1389,18 +1896,18 @@ void ivas_qmetadata_to_dirac( hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi; } } - tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + tmp_write_idx_param_band = (tmp_write_idx_param_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; } /* for ( block =...) */ } /* for ( band = ...) */ } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ - for ( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) + for (b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++) { tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx; - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) { hSpatParamRendCom->spreadCoherence[block][b] = 0.0f; @@ -1413,18 +1920,18 @@ void ivas_qmetadata_to_dirac( 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 = (tmp_write_idx_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; } } } /* 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; + hSpatParamRendCom->dirac_bs_md_write_idx = (hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES) % hSpatParamRendCom->dirac_md_buffer_length; return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_set_md_map() * @@ -1569,7 +2076,99 @@ void ivas_dirac_dec_set_md_map( } #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_set_md_map_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ +) +{ + Word16 num_slots_in_subfr; + DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + + hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + + /* 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; + + ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes ); + /* copy also to tc buffer */ + /* only for non-combined formats and combinded formats w/o discrete objects */ + IF( ( st_ivas->ivas_format != MASA_ISM_FORMAT || st_ivas->ism_mode != ISM_MASA_MODE_DISC ) && !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) + { + st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes; + Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes ); + } + + /* set mapping according to dirac_read_idx */ + + set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + + IF( st_ivas->ivas_format == MASA_FORMAT ) + { + ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); + } + ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) + { + 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 ); + } + + IF (hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0) + { + Word16 sf_idx, slot_idx, slot_idx_abs; + Word32 tmp_fx; + Word32 num; + Word16 denom, norm_denom, exp_denom, exp_num, norm_num, exp; + Word32 ans, ans_fix_32; + Word16 ans_fix_16, exp_final; + + slot_idx_abs = 0; + FOR (sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++) + { + tmp_fx = 0; + FOR (slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++) + { + tmp_fx = L_add(tmp_fx , L_deposit_h(hSpatParamRendCom->render_to_md_map[slot_idx_abs])); + slot_idx_abs = add(slot_idx_abs , 1); + } + + exp_denom = 15, exp_num = 31; + norm_num = norm_l(tmp_fx); + num = L_shl(tmp_fx, norm_num); + exp_num = exp_num - norm_num; + + norm_denom = norm_s(hSpatParamRendCom->subframe_nbslots[sf_idx]); + denom = shl(hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom); + exp_denom = exp_denom - norm_denom; + + exp = sub(exp_num, exp_denom); + + IF (num > denom) { + num = L_shr(num, 1); + exp = add(exp, 1); + } + + ans = div_l(num, denom); + ans_fix_32 = BASOP_Util_Add_Mant32Exp(ans, exp, L_deposit_h(hSpatParamRendCom->dirac_read_idx), 15/*31 - 16*/, &exp_final); + ans_fix_16 = round_fx(L_shr(ans_fix_32, 31 - exp_final - 16)); + + hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; + } + set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hSpatParamRendCom->nb_subframes ); + } + + return; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_render() * @@ -1865,10 +2464,10 @@ void ivas_dirac_dec_render_sf( for ( ch = 0; ch < nchan_transport; ch++ ) { cldfbAnalysis_ts_ivas( &( st_ivas->hTcBuffer->tc[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ), - Cldfb_RealBuffer_Temp[ch][slot_idx], - Cldfb_ImagBuffer_Temp[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, - st_ivas->cldfbAnaDec[ch] ); + Cldfb_RealBuffer_Temp[ch][slot_idx], + Cldfb_ImagBuffer_Temp[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch] ); } } @@ -1911,10 +2510,10 @@ void ivas_dirac_dec_render_sf( for ( ch = 0; ch < nchan_transport; ch++ ) { cldfbAnalysis_ts_ivas( &( 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] ); + Cldfb_RealBuffer[ch][0], + Cldfb_ImagBuffer[ch][0], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch] ); } } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index dda7ee7f9..cf79d1fe8 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -40,7 +40,9 @@ #include "ivas_rom_com.h" #include "ivas_rom_dec.h" #include "wmc_auto.h" - +#include "ivas_prot_fx.h" +#include "prot_fx1.h" +#include "prot_fx2.h" /*-----------------------------------------------------------------------* * Local function definitions @@ -562,6 +564,17 @@ ivas_error ivas_param_ism_dec_open( if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { +#ifdef IVAS_FLOAT_FIXED + if ((error = ivas_dirac_allocate_parameters_fx(hSpatParamRendCom, 1)) != IVAS_ERR_OK) + { + return error; + } + + if ((error = ivas_dirac_allocate_parameters_fx(hSpatParamRendCom, 2)) != IVAS_ERR_OK) + { + return error; + } +#else if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) { return error; @@ -571,6 +584,7 @@ ivas_error ivas_param_ism_dec_open( { return error; } +#endif } st_ivas->hISMDTX.dtx_flag = 0; @@ -706,8 +720,13 @@ void ivas_param_ism_dec_close( { if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 1); + ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 2); +#else ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 ); ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 ); +#endif } free( *hSpatParamRendCom_out ); @@ -1115,8 +1134,11 @@ void ivas_param_ism_dec_digest_tc( /* general setup */ ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator ); +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots ); +#else ivas_dirac_dec_set_md_map( st_ivas, nCldfbSlots ); - +#endif /* set buffers to zero */ for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ ) { diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 224cf8548..bfb4fba04 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -41,13 +41,13 @@ #include "ivas_rom_com.h" #include #include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED #ifdef DUMPS_ENABLED #include "debug.h" #endif // DUMPS_ENABLED - +#include "prot_fx1.h" +#include "prot_fx2.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * Local function prototypes @@ -125,7 +125,6 @@ ivas_error ivas_jbm_dec_tc( { set_f( p_output[n], 0.0f, output_frame ); } - } else if ( st_ivas->ivas_format == STEREO_FORMAT ) { @@ -717,7 +716,7 @@ ivas_error ivas_jbm_dec_tc( else if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe == 0 ) { /* Delay the separated channel to sync with the DirAC rendering */ - delay_signal_float( p_output[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); + delay_signal_float( p_output[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); } } else @@ -852,8 +851,11 @@ void ivas_jbm_dec_feed_tc_to_renderer( { if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots ); +#else ivas_dirac_dec_set_md_map( st_ivas, n_render_timeslots ); - +#endif ivas_param_ism_params_to_masa_param_mapping( st_ivas ); } else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) @@ -879,16 +881,15 @@ void ivas_jbm_dec_feed_tc_to_renderer( /* delay the objects here for all renderers where it is needed */ if ( - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL - ) + st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || + st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || + st_ivas->renderer_type == RENDERER_OSBA_AMBI || + st_ivas->renderer_type == RENDERER_OSBA_LS || + st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) { for ( n = 0; n < st_ivas->nchan_ism; n++ ) { - delay_signal_float( st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer[n], st_ivas->hSbaIsmData->delayBuffer_size ); + delay_signal_float( st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer[n], st_ivas->hSbaIsmData->delayBuffer_size ); } } @@ -959,7 +960,7 @@ ivas_error ivas_jbm_dec_render( const uint16_t nSamplesAsked, /* i : number of samples wanted */ uint16_t *nSamplesRendered, /* o : number of samples rendered */ uint16_t *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { int16_t n, nchan_out; @@ -1091,10 +1092,10 @@ ivas_error ivas_jbm_dec_render( /* Binaural rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { @@ -1275,11 +1276,11 @@ ivas_error ivas_jbm_dec_render( &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output : p_tc, p_output, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } + { + return error; + } - ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); + ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); } else if ( st_ivas->renderer_type == RENDERER_MC ) { @@ -1292,12 +1293,12 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } - ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); + ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output ); } } else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) @@ -1322,12 +1323,12 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - if ( ( error = ivas_td_binaural_renderer( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_td_binaural_renderer( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } - ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_output, p_output ); + ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_output, p_output ); } } else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) @@ -1441,7 +1442,7 @@ ivas_error ivas_jbm_dec_flush_renderer( const MC_MODE mc_mode_old, /* i : old MC mode */ const ISM_MODE ism_mode_old, /* i : old ISM mode */ uint16_t *nSamplesRendered, /* o : number of samples flushed */ - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ ) { ivas_error error; @@ -1656,8 +1657,8 @@ ivas_error ivas_jbm_dec_flush_renderer( } } - ivas_syn_output( p_output, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, - data ); + ivas_syn_output( p_output, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, + data ); return IVAS_ERR_OK; @@ -1814,12 +1815,12 @@ void ivas_jbm_dec_get_adapted_subframes( return; } #endif - /*--------------------------------------------------------------------------* * ivas_jbm_dec_get_adapted_linear_interpolator() * * Get an meta data map adapted to a time scale modified IVAS frame *--------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_jbm_dec_get_md_map( const Word16 default_len, /* i : default frame length in metadata slots */ @@ -2026,7 +2027,6 @@ void ivas_jbm_dec_get_md_map_even_spacing( } #endif - /*--------------------------------------------------------------------------* * ivas_jbm_dec_get_num_tc_channels() * @@ -2779,9 +2779,9 @@ void ivas_jbm_dec_copy_tc_no_tsm( for ( slot_idx = 0; slot_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; slot_idx++ ) { cldfbAnalysis_ts_ivas( &( tc[ch_idx][num_freq_bands * slot_idx] ), - &cldfb_real_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands], - &cldfb_imag_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands], - num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch] ); + &cldfb_real_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands], + &cldfb_imag_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands], + num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch] ); } } } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index d7cf9cfe1..d4f669746 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -41,6 +41,8 @@ #include "prot.h" #include #include "wmc_auto.h" +#include "prot_fx1.h" +#include "prot_fx2.h" /*-----------------------------------------------------------------------* * Local constants @@ -451,7 +453,75 @@ ivas_error ivas_masa_decode( if ( st_ivas->hDirAC != NULL ) { dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */ - ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0 ); + +#ifdef IVAS_FLOAT_FIXED + //Word32 q = 15; + + //for (int sf = 0; sf < hQMetaData->q_direction[0].cfg.nblocks; sf++) + //{ + // for (int j = 0; j < hQMetaData->q_direction[0].cfg.nbands; j++) + // { + // if (fabs(hQMetaData->q_direction[0].band_data[j].energy_ratio[sf]) >= 1) + // { + // q = min(q, norm_l((Word32)hQMetaData->q_direction[0].band_data[j].energy_ratio[sf])); + // } + // } + //} + //for (int sf = 0; sf < hQMetaData->q_direction[1].cfg.nblocks; sf++) + //{ + // for (int j = 0; j < hQMetaData->q_direction[0].cfg.nbands; j++) + // { + // if (fabs(hQMetaData->q_direction[1].band_data[j].energy_ratio[sf]) >= 1) + // { + // q = min(q, norm_l((Word32)hQMetaData->q_direction[1].band_data[j].energy_ratio[sf])); + // } + // } + //} + //q -= 1; // guarded bits + //for (int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++) + //{ + // for (int j = 0; j < hQMetaData->q_direction[0].cfg.nbands; j++) + // { + // hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[sf] = float_to_fix(hQMetaData->q_direction[0].band_data[j].energy_ratio[sf], q); + // } + //} + //for (int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++) + //{ + // for (int j = 0; j < hQMetaData->q_direction[1].cfg.nbands; j++) + // { + // hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[sf] = float_to_fix(hQMetaData->q_direction[1].band_data[j].energy_ratio[sf], q); + // } + //} + //if (hQMetaData->no_directions == 2 && (hMasa != NULL && ivas_total_brate > IVAS_SID_5k2)) { + // for (int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++) + // { + // for (int j = 0; j < hMasa->config.numCodingBands; j++) + // { + // hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[sf] = float_to_fix(hQMetaData->q_direction[1].band_data[j].energy_ratio[sf], q); + // } + // } + //} + for (int d = 0; d < hQMetaData->no_directions; d++) + { + IVAS_QDIRECTION *q_direction; + q_direction = &hQMetaData->q_direction[d]; + int nbands = hQMetaData->q_direction[0].cfg.nbands; + //int nblocks = hQMetaData->q_direction[0].cfg.nblocks; + FOR(Word16 j = 0; j < nbands; j++) + { + FOR(Word16 k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++) + { + q_direction->band_data[j].elevation_fx[k] = (Word32)(q_direction->band_data[j].elevation[k] * (1 << 22)); + q_direction->band_data[j].azimuth_fx[k] = (Word32)(q_direction->band_data[j].azimuth[k] * (1 << 22)); + q_direction->band_data[j].energy_ratio_fx[k] = (Word32)(q_direction->band_data[j].energy_ratio[k] * (1 << 30)); + } + } + } + + ivas_qmetadata_to_dirac_fx(hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0, 30); +#else + ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0); +#endif } if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) diff --git a/lib_dec/ivas_rom_dec.c b/lib_dec/ivas_rom_dec.c index cb4628948..e0b7e6604 100644 --- a/lib_dec/ivas_rom_dec.c +++ b/lib_dec/ivas_rom_dec.c @@ -482,6 +482,18 @@ const float dirac_dithering_ele_scale[DIRAC_DIFFUSE_LEVELS] = 6.716062e-01f, 1.011804e+00f, 1.796875e+00f, 2.804382e+00f, 4.623130e+00f, 7.802667e+00f, 1.045446e+01f, 1.379538e+01f }; +#ifdef IVAS_FLOAT_FIXED +/*Q10*/ +const Word16 dirac_dithering_azi_scale_fx[DIRAC_DIFFUSE_LEVELS] = +{ + 687 ,1036 ,1842 ,2892 ,4916 ,9426 ,15051 ,26278 +}; +/*Q11*/ +const Word16 dirac_dithering_ele_scale_fx[DIRAC_DIFFUSE_LEVELS] = +{ + 1375 ,2072 ,3680 ,5743 ,9468 ,15979 ,21410 ,28252 +}; +#endif /*----------------------------------------------------------------------------------* * FASTCONV and PARAMETRIC binaural renderer ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_rom_dec.h b/lib_dec/ivas_rom_dec.h index c7fc25788..03c83b711 100644 --- a/lib_dec/ivas_rom_dec.h +++ b/lib_dec/ivas_rom_dec.h @@ -106,6 +106,10 @@ extern const uint16_t *const sym_freq_ECSQ_tab_abs_lsbs[1 + 4]; extern const float dirac_dithering_azi_scale[DIRAC_DIFFUSE_LEVELS]; extern const float dirac_dithering_ele_scale[DIRAC_DIFFUSE_LEVELS]; +#ifdef IVAS_FLOAT_FIXED +extern const Word16 dirac_dithering_azi_scale_fx[DIRAC_DIFFUSE_LEVELS]; +extern const Word16 dirac_dithering_ele_scale_fx[DIRAC_DIFFUSE_LEVELS]; +#endif /*----------------------------------------------------------------------------------* * FASTCONV and PARAMETRIC binaural renderer ROM tables diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 9d528e6b7..af31ff535 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -42,7 +42,7 @@ #include "ivas_rom_dec.h" #include #include "wmc_auto.h" - +#include "ivas_prot_fx.h" /*-------------------------------------------------------------------* * ivas_sba_set_cna_cng_flag() @@ -708,7 +708,11 @@ void ivas_sba_dec_digest_tc( /* set the md map */ if ( st_ivas->hDirAC ) { +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots ); +#else ivas_dirac_dec_set_md_map( st_ivas, nCldfbSlots ); +#endif } if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index c4230ff79..57748c35a 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -52,6 +52,7 @@ #include "debug.h" #endif // DUMPS_ENABLED + /*-------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------*/ @@ -1643,7 +1644,11 @@ void ivas_spar_dec_upmixer( if ( st_ivas->hDirAC != 0 ) { +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_dec_set_md_map_fx( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS ); +#else ivas_dirac_dec_set_md_map( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS ); +#endif } for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index ef756204f..ad829aa4d 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -41,8 +41,8 @@ #include "ivas_cnst.h" #include "ivas_rom_rend.h" #include "wmc_auto.h" - - +#include "prot_fx1.h" +#include "prot_fx2.h" /*------------------------------------------------------------------------- * ivas_dirac_allocate_parameters() * @@ -180,7 +180,207 @@ ivas_error ivas_dirac_allocate_parameters( return IVAS_ERR_OK; } +#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 */ +) +{ + 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" ) ); + } +#ifdef IVAS_FLOAT_FIXED + 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 ) + { + 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 ) + { + 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 ) + { + 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++ ) + { + 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 ); +#ifdef IVAS_FLOAT_FIXED + 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 ); + + 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 ) + { + 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 ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set16_fx( hSpatParamRendCom->surroundingCoherence_fx[i], 0, hSpatParamRendCom->num_freq_bands ); +#endif + } + } + 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" ) ); + } +#ifdef IVAS_FLOAT_FIXED + 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 ) + { + 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++ ) + { + 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 ); +#ifdef IVAS_FLOAT_FIXED + 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 ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set16_fx( hSpatParamRendCom->spreadCoherence2_fx[i], 0, hSpatParamRendCom->num_freq_bands ); +#endif + } + } + + return IVAS_ERR_OK; +} + +#endif /*------------------------------------------------------------------------- * ivas_spat_hSpatParamRendCom_config() * @@ -248,14 +448,25 @@ ivas_error ivas_spat_hSpatParamRendCom_config( { if ( hodirac_flag && hSpatParamRendCom->azimuth2 == NULL ) { +#ifdef IVAS_FLOAT_FIXED + if ((error = ivas_dirac_allocate_parameters_fx(hSpatParamRendCom, 2)) != IVAS_ERR_OK) + { + return error; + } +#else if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) { return error; } +#endif } else if ( !hodirac_flag && hSpatParamRendCom->azimuth2 != NULL ) { +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_deallocate_parameters_fx(hSpatParamRendCom, 2); +#else ivas_dirac_deallocate_parameters( hSpatParamRendCom, 2 ); +#endif } } @@ -299,18 +510,30 @@ ivas_error ivas_spat_hSpatParamRendCom_config( hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr; } } - +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) { return error; } - +#endif if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && hodirac_flag ) ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) { return error; } +#endif } else { @@ -318,6 +541,10 @@ ivas_error ivas_spat_hSpatParamRendCom_config( hSpatParamRendCom->elevation2 = NULL; hSpatParamRendCom->energy_ratio2 = NULL; hSpatParamRendCom->spreadCoherence2 = NULL; +#ifdef IVAS_FLOAT_FIXED + hSpatParamRendCom->energy_ratio2_fx = NULL; + hSpatParamRendCom->spreadCoherence2_fx = NULL; +#endif } } @@ -338,9 +565,13 @@ void ivas_spat_hSpatParamRendCom_close( { return; } - +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 1); + ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 2); +#else ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 ); ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 ); +#endif free( *hSpatParamRendCom_out ); *hSpatParamRendCom_out = NULL; @@ -458,6 +689,258 @@ void ivas_dirac_rend_close( * Deallocate DirAC parameters *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_deallocate_parameters_fx( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ + const Word16 params_flag /* i : set of parameters flag */ +) +{ + Word16 i; + Word16 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->energy_ratio1_fx != NULL) + { + for (i = 0; i < md_buffer_length; i++) + { + if (hSpatParamRendCom->energy_ratio1_fx[i] != NULL) + { + free(hSpatParamRendCom->energy_ratio1_fx[i]); + hSpatParamRendCom->energy_ratio1_fx[i] = NULL; + } + } + free(hSpatParamRendCom->energy_ratio1_fx); + hSpatParamRendCom->energy_ratio1_fx = 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->diffuseness_vector_fx != NULL) + { + for (i = 0; i < md_buffer_length; i++) + { + if (hSpatParamRendCom->diffuseness_vector_fx[i] != NULL) + { + free(hSpatParamRendCom->diffuseness_vector_fx[i]); + hSpatParamRendCom->diffuseness_vector_fx[i] = NULL; + } + } + + free(hSpatParamRendCom->diffuseness_vector_fx); + hSpatParamRendCom->diffuseness_vector_fx = 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->spreadCoherence_fx != NULL) + { + for (i = 0; i < md_buffer_length; i++) + { + if (hSpatParamRendCom->spreadCoherence_fx[i] != NULL) + { + free(hSpatParamRendCom->spreadCoherence_fx[i]); + hSpatParamRendCom->spreadCoherence_fx[i] = NULL; + } + } + free(hSpatParamRendCom->spreadCoherence_fx); + hSpatParamRendCom->spreadCoherence_fx = 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; + } + + if (hSpatParamRendCom->surroundingCoherence_fx != NULL) + { + for (i = 0; i < md_buffer_length; i++) + { + if (hSpatParamRendCom->surroundingCoherence_fx[i] != NULL) + { + free(hSpatParamRendCom->surroundingCoherence_fx[i]); + hSpatParamRendCom->surroundingCoherence_fx[i] = NULL; + } + } + free(hSpatParamRendCom->surroundingCoherence_fx); + hSpatParamRendCom->surroundingCoherence_fx = 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->energy_ratio2_fx != NULL) + { + for (i = 0; i < md_buffer_length; i++) + { + if (hSpatParamRendCom->energy_ratio2_fx[i] != NULL) + { + free(hSpatParamRendCom->energy_ratio2_fx[i]); + hSpatParamRendCom->energy_ratio2_fx[i] = NULL; + } + } + free(hSpatParamRendCom->energy_ratio2_fx); + hSpatParamRendCom->energy_ratio2_fx = 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; + } + + if (hSpatParamRendCom->spreadCoherence2_fx != NULL) + { + for (i = 0; i < md_buffer_length; i++) + { + if (hSpatParamRendCom->spreadCoherence2_fx[i] != NULL) + { + free(hSpatParamRendCom->spreadCoherence2_fx[i]); + hSpatParamRendCom->spreadCoherence2_fx[i] = NULL; + } + } + free(hSpatParamRendCom->spreadCoherence2_fx); + hSpatParamRendCom->spreadCoherence2_fx = NULL; + } + } + + return; +} +#endif 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 */ @@ -1838,7 +2321,6 @@ void ivas_masa_init_stereotype_detection( return; } - /*------------------------------------------------------------------------- * ivas_masa_stereotype_detection() * @@ -2227,10 +2709,10 @@ static void ivas_masa_ext_dirac_render_sf( for ( ch = 0; ch < nchan_transport; ch++ ) { cldfbAnalysis_ts_ivas( &( output_f[ch][hSpatParamRendCom->num_freq_bands * index_slot] ), - Cldfb_RealBuffer[ch][0], - Cldfb_ImagBuffer[ch][0], - hSpatParamRendCom->num_freq_bands, - hMasaExtRend->cldfbAnaRend[ch] ); + Cldfb_RealBuffer[ch][0], + Cldfb_ImagBuffer[ch][0], + hSpatParamRendCom->num_freq_bands, + hMasaExtRend->cldfbAnaRend[ch] ); } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index ba6a4ec47..b8ea58d3d 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -599,6 +599,17 @@ ivas_error ivas_dirac_allocate_parameters( const int16_t params_flag /* i : set of parameters flag */ ); +#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 */ +); + +void ivas_dirac_deallocate_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 */ +); +#endif 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 */ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 5ab433cf8..9740a14a1 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -197,10 +197,20 @@ typedef struct ivas_spatial_parametric_rend_common_data_structure float **diffuseness_vector; float **energy_ratio1; float **energy_ratio2; +#ifdef IVAS_FLOAT_FIXED + Word32 **diffuseness_vector_fx; + Word32 **energy_ratio1_fx; + Word32 **energy_ratio2_fx; +#endif float **spreadCoherence; float **spreadCoherence2; float **surroundingCoherence; +#ifdef IVAS_FLOAT_FIXED + Word16 **spreadCoherence_fx; + Word16 **spreadCoherence2_fx; + Word16 **surroundingCoherence_fx; +#endif /* Metadata access indices and buffer size */ int16_t dirac_bs_md_write_idx; -- GitLab