From 85d0e7904413f2663b9a6a3146d667a2aa0b4caa Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 9 Jan 2024 11:51:52 +0530 Subject: [PATCH] ivas_binRenderer_internal.c float to fix conversion [x] Few of functions and subfunctions in ivas_binRenderer_internal.c converted to fixed. --- lib_com/basop_util.c | 22 +- lib_com/basop_util.h | 3 +- lib_com/ivas_cnst.h | 1 + lib_com/ivas_prot.h | 16 +- lib_com/ivas_rom_com.c | 292 +++++++++++- lib_com/ivas_rom_com.h | 6 +- lib_com/ivas_spar_com.c | 125 ++++- lib_com/ivas_tools.c | 94 ++++ lib_com/prot_fx2.h | 38 +- lib_com/tools.c | 145 +++++- lib_dec/ivas_binRenderer_internal.c | 370 +++++++-------- lib_rend/ivas_allrad_dec.c | 124 ++++- lib_rend/ivas_efap.c | 680 +++++++++++++++++++++++++++- lib_rend/ivas_prot_rend.h | 13 +- lib_rend/ivas_rom_rend.c | 35 +- lib_rend/ivas_rom_rend.h | 12 +- lib_rend/ivas_stat_rend.h | 12 +- 17 files changed, 1775 insertions(+), 213 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 104fa39cb..a3ccaefc7 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -1237,7 +1237,6 @@ Word16 getCosWord16(Word16 theta) return result; } - Word16 getCosWord16R2( Word16 theta ) { @@ -1254,6 +1253,27 @@ Word16 getCosWord16R2( return result; } + +Word16 getSineWord16R2( Word16 theta ) +{ + IF ( theta == 0 ) + { + return 0; + } + Word16 cosine = getCosWord16R2( theta ); + Word16 result = 32767 - ( mult_r( cosine, cosine ) ); + Word16 exp = 0; + Word16 sine = Sqrt16( result, &exp ); + sine = shl( sine, exp ); + + IF ( ( ( theta >= 16384 ) && ( theta <= 32767 ) ) || ( ( theta < 0 ) && ( theta >= -16384 ) ) ) + { + sine = negate( sine ); + } + + return sine; +} + /* * Calculate Integer Square Root of 'val'. This is the equivalent of (int)sqrt(val); * The return value will be truncated to the lowest integer (throwing away the fractionnal part. diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index e77a643f4..3e18edbb1 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -459,7 +459,8 @@ Word32 getCosWord32(Word32 theta); * \param theta Angle normalized to radix 2, theta = (angle in radians)*2.0/pi * \return result with exponent 0. */ -Word16 getCosWord16R2(Word16 theta); +Word16 getCosWord16R2( Word16 theta ); +Word16 getSineWord16R2( Word16 theta ); /****************************************************************************/ /*! \brief Sets Array Word16 arg1 to value Word16 arg2 for Word16 arg3 elements diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index f21f6140a..c660abbbc 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -48,6 +48,7 @@ #define _180_OVER_PI ( 180.0f / EVS_PI ) #define SQRT2 1.414213562373095f +#define SQRT2_FIXED 1518500250 // Q30 #define SQRT2_OVER_2 (SQRT2 / 2.0f) #define INV_SQRT2 7.071067811865475e-1f /* 1/sqrt(2) */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 9fd731d1d..3d72e00d6 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3742,6 +3742,13 @@ void ivas_dirac_dec_get_response( float *response, const int16_t ambisonics_order ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_get_response_fixed( + const Word16 azimuth, + const Word16 elevation, + Word32 *response, + const Word16 ambisonics_order ); +#endif void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, @@ -5295,7 +5302,14 @@ void panning_wrap_angles( float *azi_wrapped, /* o : wrapped azimuth component */ float *ele_wrapped /* o : wrapped elevation component */ ); - +#ifdef IVAS_FLOAT_FIXED +void panning_wrap_angles_fixed( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ + Word32 *azi_wrapped, /* o : wrapped azimuth component */ + Word32 *ele_wrapped /* o : wrapped elevation component */ +); +#endif void v_sort_ind( float *x, /* i/o: Vector to be sorted */ int16_t *idx, /* o : Original index positions */ diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 13fed1dd9..cabd2fb04 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -4240,7 +4240,13 @@ const float dirac_gains_norm_term[9] = { 1.000000e+00f, 7.071068e-01f, 1.000000e+00f, 4.082483e-01f, 2.041242e-01f, 1.000000e+00f, 2.886751e-01f, 9.128709e-02f, 3.726780e-02f }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 dirac_gains_norm_term_int[9] = //Q30 +{ + 1073741824, 759250176, 1073741824, 438353280, 219176688, 1073741824, 309962528, 98018768, + 40015996 +}; +#endif const float dirac_gains_Pnm[91][9] = { {-1.000000e+00f,-0.000000e+00f,1.000000e+00f,-0.000000e+00f,0.000000e+00f,-1.000000e+00f,-0.000000e+00f,0.000000e+00f,-0.000000e+00f}, @@ -4335,7 +4341,102 @@ const float dirac_gains_Pnm[91][9] = {-1.745235e-02f,9.998478e-01f,-4.995431e-01f,-5.234908e-02f,2.999086e+00f,2.616524e-02f,-1.497488e+00f,-2.617055e-01f,1.499315e+01f}, {-4.371139e-08f,1.000000e+00f,-5.000000e-01f,-1.311342e-07f,3.000000e+00f,6.556709e-08f,-1.500000e+00f,-6.556709e-07f,1.500000e+01f} }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 dirac_gains_Pnm_int[91][9] = //Q27 +{ + {-134217728, 0, 134217728, 0, 0, -134217728, 0, 0, 0}, + {-134197288, 2342396, 134156400, -7026119, 122639, -134095104, 14049026, -613106, 10701}, + {-134135976, 4684105, 133972536, -14043751, 490416, -133727536, 28061840, -2450586, 85575}, + {-134033784, 7024438, 133666264, -21044428, 1102895, -133115936, 42002312, -5506921, 288606}, + {-133890784, 9362478, 133238096, -28019012, 1959264, -132262040, 55833192, -9772457, 683351}, + {-133706992, 11697809, 132688440, -34959892, 3058584, -131167848, 69520408, -15234719, 1332861}, + {-133482480, 14029564, 132017976, -41858120, 4399464, -129836328, 83027720, -21876818, 2299344}, + {-133217280, 16357047, 131227600, -48705360, 5980272, -128270864, 96320208, -29678480, 3644062}, + {-132911536, 18679510, 130318176, -55493180, 7799064, -126475552, 109363520, -38615824, 5427104}, + {-132565296, 20996256, 129290928, -62213284, 9853607, -124455056, 122123976, -48661468, 7707213}, + {-132178656, 23306694, 128146968, -68857816, 12141505, -122214432, 134569248, -59785232, 10541761}, + {-131751776, 25609964, 126887800, -75418320, 14659851, -119759704, 146666688, -71952528, 13986158}, + {-131284736, 27905410, 125514928, -81886824, 17405570, -117097048, 158385376, -85126080, 18094094}, + {-130777744, 30192412, 124030024, -88255768, 20375446, -114233392, 169695776, -99266128, 22917396}, + {-130230888, 32470208, 122434848, -94517128, 23565774, -111176104, 180568608, -114328832, 28505376}, + {-129644368, 34738112, 120731408, -100663320, 26972664, -107933048, 190976128, -130267952, 34905200}, + {-129018344, 36995424, 118921736, -106686840, 30591964, -104512608, 200891728, -147034448, 42161440}, + {-128353056, 39241452, 117008088, -112580368, 34419264, -100923608, 210290720, -164576576, 50316080}, + {-127648640, 41475572, 114992728, -118336848, 38449984, -97175216, 219149232, -182840512, 59408524}, + {-126905360, 43697012, 112878208, -123949000, 42679048, -93277184, 227444688, -201769248, 69474696}, + {-126123408, 45905176, 110666976, -129410248, 47101484, -89239304, 235156848, -221304640, 80548296}, + {-125303040, 48099312, 108361848, -134713792, 51711740, -85072152, 242266352, -241385344, 92659128}, + {-124444528, 50278820, 105965584, -139853120, 56504308, -80786280, 248755776, -261949392, 105834368}, + {-123548080, 52443040, 103481048, -144822272, 61473384, -76392608, 254609280, -282932704, 120097808}, + {-122614016, 54591264, 100911328, -149614784, 66612780, -71902504, 259812912, -304269024, 135469312}, + {-121642584, 56722880, 98259536, -154225168, 71916384, -67327280, 264354304, -325891904, 151965872}, + {-120634104, 58837188, 95528944, -158647504, 77377552, -62678672, 268222720, -347732352, 169600480}, + {-119588872, 60933588, 92722800, -162876704, 82989840, -57968464, 271409984, -369722464, 188383040}, + {-118507224, 63011412, 89844624, -166907264, 88746208, -53208660, 273908992, -391791360, 208319200}, + {-117389480, 65070028, 86897888, -170734608, 94639696, -48411356, 275714624, -413868832, 229411120}, + {-116235952, 67108864, 83886096, -174353936, 100663296, -43588484, 276824064, -435884832, 251658240}, + {-115047032, 69127240, 80812992, -177760784, 106809472, -38752388, 277236128, -457767936, 275054816}, + {-113823072, 71124576, 77682296, -180951136, 113070880, -33915128, 276951296, -479447744, 299592224}, + {-112564464, 73100224, 74497888, -183920976, 119439696, -29088994, 275972448, -500852768, 325257600}, + {-111271560, 75053584, 71263600, -186666800, 125908272, -24285974, 274304128, -521913568, 352034976}, + {-109944736, 76984136, 67983320, -189185120, 132468856, -19517968, 271952224, -542560640, 379905024}, + {-108584440, 78891192, 64661120, -191472992, 139113184, -14796968, 268925472, -562724864, 408843424}, + {-107191040, 80774240, 61300996, -193527600, 145833472, -10134552, 265233552, -582338944, 438823936}, + {-105765016, 82632672, 57907084, -195346384, 152621264, -5542341, 260888528, -601335936, 469815200}, + {-104306760, 84465968, 54483472, -196927072, 159468512, -1031517, 255903808, -619651456, 501783968}, + {-102816736, 86273488, 51034412, -198267904, 166366624, 3386773, 250294992, -637221056, 534692032}, + {-101295408, 88054736, 47564080, -199367280, 173307296, 7701825, 244078832, -653983232, 568498944}, + {-99743224, 89809192, 44076620, -200223728, 180282192, 11903295, 237274256, -669879040, 603161856}, + {-98160648, 91536272, 40576356, -200836160, 187282720, 15980983, 229901280, -684849728, 638632640}, + {-96548144, 93235488, 37067500, -201203920, 194300432, 19925212, 221981760, -698840192, 674862144}, + {-94906272, 94906272, 33554432, -201326592, 201326592, 23726568, 213539056, -711796992, 711796992}, + {-93235488, 96548144, 30041364, -201203920, 208352752, 27376188, 204597888, -723670016, 749382016}, + {-91536272, 98160648, 26532496, -200836160, 215370464, 30865648, 195183856, -734411520, 787559936}, + {-89809200, 99743208, 23032272, -200223728, 222370864, 34186800, 185324752, -743976000, 826268864}, + {-88054736, 101295408, 19544786, -199367280, 229345888, 37332284, 175048640, -752322176, 865447872}, + {-86273488, 102816736, 16074439, -198268032, 236286560, 40294912, 164385440, -759410496, 905030144}, + {-84465944, 104306784, 12625336, -196927072, 243184800, 43068320, 153365504, -765205632, 944950528}, + {-82632672, 105765016, 9201773, -195346384, 250031920, 45646496, 142020480, -769675200, 985139200}, + {-80774256, 107191032, 5807891, -193527600, 256819584, 48024044, 130382952, -772789696, 1025526400}, + {-78891192, 108584440, 2447739, -191472992, 263540000, 50196224, 118485736, -774524480, 1066041600}, + {-76984120, 109944720, -874438, -189185120, 270184320, 52158672, 106363224, -774856768, 1106610176}, + {-75053584, 111271544, -4154720, -186666800, 276744864, 53907864, 94049432, -773768704, 1147159552}, + {-73100224, 112564464, -7389016, -183920976, 283213504, 55440728, 81579720, -771245696, 1187614080}, + {-71124568, 113823072, -10573435, -180951136, 289582400, 56754824, 68989160, -767276288, 1227898496}, + {-69127232, 115047064, -13704140, -177760784, 295843776, 57848416, 56313356, -761853888, 1267938048}, + {-67108880, 116235952, -16777203, -174353936, 301989888, 58720256, 43588536, -754974720, 1307654528}, + {-65070028, 117389472, -19788994, -170734608, 308013440, 59369844, 30850226, -746639232, 1346972928}, + {-63011400, 118507224, -22735772, -166907264, 313906944, 59797272, 18134762, -736851968, 1385816832}, + {-60933588, 119588872, -25613950, -162876704, 319663424, 60003204, 5477891, -725620736, 1424110464}, + {-58837172, 120634088, -28420080, -158647504, 325275584, 59989016, -7084927, -712957184, 1461778688}, + {-56722868, 121642576, -31150674, -154225168, 330736768, 59756660, -19517928, -698877184, 1498746240}, + {-54591276, 122613992, -33802452, -149614784, 336040384, 59308680, -31786382, -683399744, 1534940800}, + {-52443040, 123548064, -36372160, -144822272, 341179712, 58648260, -43855684, -666547776, 1570288384}, + {-50278848, 124444520, -38856688, -139853264, 346148864, 57779188, -55691916, -648348160, 1604717952}, + {-48099324, 125303040, -41252988, -134713792, 350941376, 56705796, -67261816, -628830848, 1638160896}, + {-45905160, 126123416, -43558124, -129410240, 355551744, 55433036, -78532848, -608029120, 1670546304}, + {-43697012, 126905360, -45769332, -123949000, 359974080, 53966400, -89473440, -585980480, 1701810944}, + {-41475560, 127648632, -47883864, -118336808, 364203168, 52311936, -100052728, -562724992, 1731889152}, + {-39241464, 128353048, -49899212, -112580408, 368233856, 50476188, -110241232, -538305984, 1760719104}, + {-36995424, 129018360, -51812888, -106686856, 372061216, 48466224, -120010336, -512769824, 1788240512}, + {-34738100, 129644368, -53622532, -100663280, 375680512, 46289628, -129332608, -486166400, 1814398208}, + {-32470208, 130230888, -55325984, -94517088, 379087360, 43954400, -138181984, -458547616, 1839134464}, + {-30192412, 130777744, -56921148, -88255752, 382277728, 41469052, -146533552, -429968768, 1862399872}, + {-27905450, 131284752, -58406064, -81886920, 385247552, 38842476, -154363936, -400487584, 1884144384}, + {-25609950, 131751776, -59778952, -75418272, 387993376, 36083912, -161651424, -370163232, 1904324096}, + {-23306666, 132178656, -61038128, -68857760, 390511712, 33203050, -168375472, -339058272, 1922894464}, + {-20996270, 132565280, -62182040, -62213328, 392799456, 30209874, -174517136, -307236864, 1939817984}, + {-18679498, 132911536, -63209344, -55493124, 394854208, 27114732, -180059392, -274765312, 1955057024}, + {-16357021, 133217280, -64118736, -48705292, 396672992, 23928188, -184986656, -241711232, 1968580864}, + {-14029578, 133482472, -64909128, -41858176, 398253664, 20661142, -189285248, -208144320, 1980359808}, + {-11697849, 133706992, -65579560, -34960012, 399594624, 17324636, -192943088, -174134880, 1990369664}, + {-9362556, 133890784, -66129224, -28019252, 400693888, 13929935, -195949824, -139755008, 1998589184}, + {-7024411, 134033784, -66557432, -21044346, 401550304, 10488515, -198297168, -105077560, 2004999424}, + {-4684126, 134135976, -66863648, -14043818, 402162752, 7011926, -199978640, -70176320, 2009588352}, + {-2342414, 134197304, -67047540, -7026174, 402530496, 3511839, -200989440, -35125516, 2012346496}, + {-5, 134217728, -67108864, -17, 402653184, 8, -201326592, -88, 2013265920} +}; +#endif const float dirac_gains_trg_term[181][2] = { {-1.000000e+00f,8.742278e-08f}, @@ -4520,7 +4621,192 @@ const float dirac_gains_trg_term[181][2] = {9.998477e-01f,-1.745241e-02f}, {1.000000e+00f,0.000000e+00f} }; - +#ifdef IVAS_FLOAT_FIXED +const Word32 dirac_gains_trg_term_int[181][2] = //Q30 +{ + {-1073741824, 93}, + {-1073578304, -18739436}, + {-1073087680, -37473000}, + {-1072270272, -56195404}, + {-1071126272, -74900440}, + {-1069655936, -93582656}, + {-1067859776, -112236624}, + {-1065738240, -130856168}, + {-1063292288, -149436080}, + {-1060522368, -167970160}, + {-1057429248, -186453440}, + {-1054014208, -204879600}, + {-1050278016, -223243376}, + {-1046221952, -241539408}, + {-1041847104, -259761664}, + {-1037154944, -277904896}, + {-1032146880, -295963392}, + {-1026824448, -313931616}, + {-1021189120, -331804480}, + {-1015242880, -349576096}, + {-1008987264, -367241408}, + {-1002424448, -384794592}, + {-995556160, -402230656}, + {-988384640, -419544416}, + {-980912000, -436730112}, + {-973140608, -453782944}, + {-965072832, -470697376}, + {-956710976, -487468704}, + {-948057792, -504091296}, + {-939115840, -520560224}, + {-929887680, -536871040}, + {-920376384, -553017856}, + {-910584576, -568996544}, + {-900515712, -584801664}, + {-890172480, -600428672}, + {-879557888, -615873088}, + {-868675520, -631129536}, + {-857528320, -646194048}, + {-846120128, -661061376}, + {-834454080, -675727744}, + {-822533888, -690187904}, + {-810363392, -704438016}, + {-797945664, -718473536}, + {-785285056, -732290112}, + {-772385152, -745883904}, + {-759250176, -759250176}, + {-745883904, -772385152}, + {-732290112, -785285056}, + {-718473600, -797945664}, + {-704438016, -810363392}, + {-690187904, -822533888}, + {-675727552, -834454144}, + {-661061376, -846120128}, + {-646194048, -857528320}, + {-631129536, -868675392}, + {-615873088, -879557760}, + {-600428672, -890172352}, + {-584801792, -900515712}, + {-568996544, -910584576}, + {-553017856, -920376384}, + {-536871040, -929887680}, + {-520560224, -939115776}, + {-504091296, -948057792}, + {-487468704, -956710976}, + {-470697376, -965072832}, + {-453782944, -973140608}, + {-436730208, -980911936}, + {-419544416, -988384640}, + {-402230784, -995556160}, + {-384794592, -1002424448}, + {-367241280, -1008987264}, + {-349576096, -1015242880}, + {-331804480, -1021189120}, + {-313931712, -1026824384}, + {-295963392, -1032146880}, + {-277904800, -1037154944}, + {-259761664, -1041847104}, + {-241539296, -1046221952}, + {-223243488, -1050278016}, + {-204879600, -1054014208}, + {-186453328, -1057429248}, + {-167970160, -1060522368}, + {-149435984, -1063292288}, + {-130856168, -1065738240}, + {-112236624, -1067859776}, + {-93582792, -1069655936}, + {-74900448, -1071126272}, + {-56195288, -1072270272}, + {-37473008, -1073087680}, + {-18739318, -1073578304}, + {-46, -1073741824}, + {18739350, -1073578304}, + {37473052, -1073087680}, + {56195320, -1072270272}, + {74900480, -1071126272}, + {93582824, -1069655936}, + {112236512, -1067859776}, + {130856168, -1065738240}, + {149435984, -1063292288}, + {167970272, -1060522368}, + {186453328, -1057429248}, + {204879504, -1054014208}, + {223243488, -1050278016}, + {241539296, -1046221952}, + {259761664, -1041847104}, + {277904896, -1037154944}, + {295963392, -1032146880}, + {313931712, -1026824448}, + {331804480, -1021189120}, + {349576096, -1015242880}, + {367241408, -1008987264}, + {384794720, -1002424320}, + {402230784, -995556160}, + {419544320, -988384640}, + {436730112, -980912000}, + {453782848, -973140608}, + {470697504, -965072832}, + {487468576, -956710976}, + {504091296, -948057792}, + {520560352, -939115776}, + {536870912, -929887680}, + {553017920, -920376384}, + {568996544, -910584704}, + {584801664, -900515712}, + {600428800, -890172224}, + {615873088, -879557888}, + {631129536, -868675392}, + {646193920, -857528320}, + {661061504, -846120064}, + {675727616, -834454144}, + {690187904, -822533888}, + {704438016, -810363136}, + {718473536, -797945792}, + {732290176, -785285056}, + {745883776, -772385216}, + {759250176, -759250176}, + {772385216, -745883776}, + {785285056, -732290112}, + {797945664, -718473536}, + {810363264, -704438016}, + {822533888, -690187904}, + {834454144, -675727616}, + {846120128, -661061504}, + {857528320, -646193920}, + {868675392, -631129536}, + {879557888, -615873088}, + {890172352, -600428800}, + {900515712, -584801792}, + {910584704, -568996544}, + {920376384, -553017920}, + {929887680, -536870912}, + {939115776, -520560352}, + {948057792, -504091296}, + {956710976, -487468576}, + {965072832, -470697504}, + {973140608, -453782944}, + {980911936, -436730112}, + {988384640, -419544320}, + {995556160, -402230784}, + {1002424320, -384794592}, + {1008987264, -367241280}, + {1015242880, -349576096}, + {1021189120, -331804480}, + {1026824448, -313931712}, + {1032146880, -295963392}, + {1037154944, -277904800}, + {1041847104, -259761664}, + {1046221952, -241539296}, + {1050278016, -223243488}, + {1054014208, -204879600}, + {1057429248, -186453328}, + {1060522368, -167970272}, + {1063292288, -149435984}, + {1065738240, -130856168}, + {1067859776, -112236624}, + {1069655936, -93582760}, + {1071126272, -74900440}, + {1072270272, -56195308}, + {1073087680, -37473052}, + {1073578304, -18739382}, + {1073741824, 0} +}; +#endif /*----------------------------------------------------------------------------------* * FB ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 90e244bc5..ac1621c09 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -407,7 +407,11 @@ extern const int16_t dirac_gains_P_idx[16]; extern const float dirac_gains_norm_term[9]; extern const float dirac_gains_Pnm[91][9]; extern const float dirac_gains_trg_term[181][2]; - +#ifdef IVAS_FLOAT_FIXED +extern const Word32 dirac_gains_norm_term_int[9]; +extern const Word32 dirac_gains_Pnm_int[91][9]; +extern const Word32 dirac_gains_trg_term_int[181][2]; +#endif /*------------------------------------------------------------------------------------------* * FB ROM tables *------------------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index e80dbf428..816bc98b4 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1382,7 +1382,6 @@ void ivas_compute_spar_params( if ( ndm != num_ch ) { ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); - } } @@ -1813,6 +1812,130 @@ void ivas_dirac_dec_get_response( return; } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_dirac_dec_get_response_fixed() + * + * Block Q of 29 is maintained + * calculate reponse, 1 degree resolution + *------------------------------------------------------------------------*/ + +void ivas_dirac_dec_get_response_fixed( + const Word16 azimuth, + const Word16 elevation, + Word32 *response, + const Word16 ambisonics_order ) +{ + Word16 index_azimuth, index_elevation; + Word16 el, e, az; + Word32 cos_1, cos_2, sin_1, cos_az[3]; + Word32 sin_az[3]; + Word32 f, c; + Word16 l, m; + Word16 b, b1, b_2, b1_2, a; + + index_azimuth = ( azimuth + 180 ) % 360; + index_elevation = elevation + 90; + e = index_elevation > 90 ? -1 : 1; + el = index_elevation > 90 ? 180 - index_elevation : index_elevation; + + az = index_azimuth > 180 ? 360 - index_azimuth : index_azimuth; + f = index_azimuth > 180 ? -( 1 << Q29 ) : ( 1 << Q29 ); + + cos_1 = dirac_gains_trg_term_int[az][0] >> 1; // Q29 + cos_2 = Mpy_32_32( cos_1, cos_1 ); // Q27 + sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] >> 1 ); // Q27 + cos_az[0] = cos_1; // Q29 + cos_az[1] = L_sub( Mpy_32_32( ( 1 << Q30 ), cos_2 ), ( 1 << Q25 ) ) << 4; // Q29 + cos_az[2] = L_sub( Mpy_32_32( Mpy_32_32( ( 1 << Q30 ), cos_1 ), cos_az[1] ) << 4, cos_az[0] ); // Q29 + sin_az[0] = sin_1 << 2; // Q29 + sin_az[1] = Mpy_32_32( Mpy_32_32( sin_1, ( 1 << Q30 ) ), cos_1 ) << 6; // Q29 + sin_az[2] = Mpy_32_32( sin_1, L_sub( Mpy_32_32( ( 1 << Q30 ), cos_2 ) << 5, ( 1 << 29 ) ) ) << 4; + + response[0] = ( 1 << 29 ); + /* Un-optimized code - for reference */ + /* for( l = 1; l<= ambisonics_order; l++ ) */ + /* { */ + /* int16_t b, b1, a; */ + /* float c; */ + /* for( m = 0; m < l; m++ ) */ + /* { */ + /* b = l*l+m; */ + /* a = dirac_gains_P_idx[b]; */ + /* c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ + + /* if( m%2 == 1 ) */ + /* { */ + /* c = c*e; */ + /* } */ + + /* response[b] = c * sin_az[l-m-1]; */ + + /* b1 = l*l+2*l-m; */ + /* response[b1] = c * cos_az[l-m-1]; */ + + /* } */ + + /* b = l*l+l; */ + /* a = dirac_gains_P_idx[b]; */ + /* c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ + /* if( l%2 == 1) */ + /* { */ + /* c = c*e; */ + /* } */ + + /* response[b] = c; */ + /* } */ + + FOR ( l = 1; l <= ambisonics_order; l++ ) + { + b_2 = l * l; + b1_2 = l * l + 2 * l; + FOR ( m = 0; m < l; m += 2 ) + { + b = b_2 + m; + a = dirac_gains_P_idx[b]; + c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 + + response[b] = Mpy_32_32( c, sin_az[l - m - 1] ) << 6; // Q29 + + b1 = b1_2 - m; + response[b1] = Mpy_32_32( c, cos_az[l - m - 1] ) << 6; // Q29 + } + + FOR( m = 1; m < l; m += 2 ) + { + b = b_2 + m; + a = dirac_gains_P_idx[b]; + c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 + IF ( e == -1 ) + { + c = -c; + } + + response[b] = Mpy_32_32( c, sin_az[l - m - 1] ) << 6; //Q29 + + b1 = b1_2 - m; + response[b1] = Mpy_32_32( c, cos_az[l - m - 1] ) << 6; //Q29 + } + + b = b_2 + l; + a = dirac_gains_P_idx[b]; + c = Mpy_32_32( dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a] ); //Q26 + IF ( l % 2 == 1 ) + { + IF( e == -1 ) + { + c = -c; + } + } + + response[b] = c << 3; //Q29 + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_get_bits_to_encode diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 916dd31ae..e1c2e6e76 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -40,6 +40,11 @@ #include "wmc_auto.h" #include "ivas_rom_com.h" + +#define ANGLE_90_DEG_Q22 377487360 +#define ANGLE_180_DEG_Q22 754974720 +#define ANGLE_360_DEG_Q22 1509949440 + /*--------------------------------------------------------------- * sumAbs() * @@ -1141,7 +1146,27 @@ static float wrap_azi( return azi; } +#ifdef IVAS_FLOAT_FIXED +/* helper function for panning_wrap_angles */ +static Word32 wrap_azi_fixed( + const Word32 azi_deg ) +{ + Word32 azi = azi_deg; + + /* Wrap azimuth value */ + WHILE( azi > ANGLE_180_DEG_Q22 ) + { + azi -= ANGLE_360_DEG_Q22; + } + + WHILE( azi <= -ANGLE_180_DEG_Q22 ) + { + azi += ANGLE_360_DEG_Q22; + } + return azi; +} +#endif /*-------------------------------------------------------------------* * panning_wrap_angles() * @@ -1209,7 +1234,76 @@ void panning_wrap_angles( return; } } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * panning_wrap_angles_fixed() + * + * Wrap angles for amplitude panning to the range: + * azimuth = (-180, 180] + * elevation = [-90, 90] + * Considers direction changes from large elevation values + *-------------------------------------------------------------------*/ +void panning_wrap_angles_fixed( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ + Word32 *azi_wrapped, /* o : wrapped azimuth component */ + Word32 *ele_wrapped /* o : wrapped elevation component */ +) +{ + Word32 azi, ele; + + azi = azi_deg; + ele = ele_deg; + + IF( L_abs( ele ) < ANGLE_90_DEG_Q22 ) + { + *ele_wrapped = ele; + *azi_wrapped = wrap_azi_fixed( azi ); + return; + } + ELSE + { + /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ + IF( ( ( ele % ANGLE_90_DEG_Q22 ) == 0 ) && ( ( ele % ANGLE_180_DEG_Q22 ) != 0 ) ) + { + *azi_wrapped = 0; + WHILE( ele > ANGLE_90_DEG_Q22 ) + { + ele -= ANGLE_360_DEG_Q22; + } + WHILE( ele < -ANGLE_90_DEG_Q22 ) + { + ele += ANGLE_360_DEG_Q22; + } + *ele_wrapped = ele; + } + ELSE + { + /* Wrap elevation and adjust azimuth accordingly */ + WHILE( L_abs( ele ) > ANGLE_90_DEG_Q22 ) + { + /* Flip to other hemisphere */ + azi += ANGLE_180_DEG_Q22; + + /* Compensate elevation accordingly */ + IF( ele > ANGLE_90_DEG_Q22 ) + { + ele = ANGLE_180_DEG_Q22 - ele; + } + ELSE IF( ele < -ANGLE_90_DEG_Q22 ) + { + ele = -ANGLE_180_DEG_Q22 - ele; + } + } + *azi_wrapped = wrap_azi_fixed( azi ); + *ele_wrapped = ele; + } + + return; + } +} +#endif /*-------------------------------------------------------------------------* * v_sort_ind() * diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 7bce292b2..38c560f78 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -4941,6 +4941,42 @@ void lsf_dec_fx( #endif ); +/*! r: index of the maximum value in the input vector */ +Word16 maximum_l( + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word32 *max /* o : maximum value in the input vector */ +); + +/*! r: index of the minimum value in the input vector */ +Word16 minimum_l( + const Word32 *vec, /* i : Input vector */ + const Word16 lvec, /* i : Vector length */ + Word32 *min_val /* o : minimum value in the input vector */ +); + +void v_multc_fixed( + const Word32 x[], /* i : Input vector */ + const Word32 c, /* i : Constant */ + Word32 y[], /* o : Output vector that contains c*x */ + const Word16 N /* i : Vector length */ +); + +void v_sub_fixed( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N, /* i : Vector length */ + const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */ +); + +/*! r: dot product of x[] and y[] */ +Word32 dotp_fixed( + const Word32 x[], /* i : vector x[] */ + const Word32 y[], /* i : vector y[] */ + const Word16 n /* i : vector length */ +); + void lsf_end_dec_fx( Decoder_State* st, /* i/o: decoder state structure */ Word16 mode2_flag, @@ -7700,4 +7736,4 @@ void delay_signal_fx( const Word16 delay /* i : delay in samples */ ); #endif -#endif \ No newline at end of file +#endif diff --git a/lib_com/tools.c b/lib_com/tools.c index 8004fcf3c..21e238090 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -38,6 +38,7 @@ #include "options.h" #include #include "prot.h" +#include "prot_fx2.h" #include "wmc_auto.h" /*------------------------------------------------------------------* @@ -563,6 +564,36 @@ int16_t maximum_s( return ind; } +/*! r: index of the maximum value in the input vector */ +Word16 maximum_l( + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word32 *max /* o : maximum value in the input vector */ +) +{ + Word16 i, ind; + Word32 tmp; + + ind = 0; + tmp = vec[0]; + + FOR ( i = 1; i < lvec; i++ ) + { + IF ( vec[i] > tmp ) + { + ind = i; + tmp = vec[i]; + } + } + + IF ( max != NULL ) + { + *max = tmp; + } + + return ind; +} + /*---------------------------------------------------------------------* * maximumAbs() * @@ -582,16 +613,16 @@ int16_t maximumAbs( ind = 0; tmp = (float) fabs( vec[0] ); - for ( j = 1; j < lvec; j++ ) + FOR ( j = 1; j < lvec; j++ ) { - if ( (float) fabs( vec[j] ) > tmp ) + IF ( (float) fabs( vec[j] ) > tmp ) { ind = j; tmp = (float) fabs( vec[j] ); } } - if ( max_val != NULL ) + IF ( max_val != NULL ) { *max_val = tmp; } @@ -670,6 +701,41 @@ int16_t minimum_s( return ind; } +/*-------------------------------------------------------------------* + * minimum_l() + * + * Finds minimum 16-bit signed integer value in the array and returns it. + *-------------------------------------------------------------------*/ + +/*! r: index of the minimum value in the input vector */ +Word16 minimum_l( + const Word32 *vec, /* i : Input vector */ + const Word16 lvec, /* i : Vector length */ + Word32 *min_val /* o : minimum value in the input vector */ +) +{ + Word16 i, ind; + Word32 tmp; + + ind = 0; + tmp = vec[0]; + + for ( i = 1; i < lvec; i++ ) + { + if ( vec[i] < tmp ) + { + ind = i; + tmp = vec[i]; + } + } + + if ( min_val != NULL ) + { + *min_val = tmp; + } + + return ind; +} /*---------------------------------------------------------------------* * emaximum() @@ -750,6 +816,32 @@ float dotp( return suma; } +/*---------------------------------------------------------------------* + * dotp() + * + * Dot product of vector x[] and vector y[] + *---------------------------------------------------------------------*/ + +/*! r: dot product of x[] and y[] */ +Word32 dotp_fixed( + const Word32 x[], /* i : vector x[] */ + const Word32 y[], /* i : vector y[] */ + const Word16 n /* i : vector length */ +) +{ + Word16 i; + Word32 suma; + + suma = Mpy_32_32( x[0], y[0] ); + + FOR ( i = 1; i < n; i++ ) + { + suma += Mpy_32_32( x[i], y[i] ); + } + + return suma; +} + /*---------------------------------------------------------------------* * inv_sqrt() @@ -896,6 +988,30 @@ void v_sub( return; } +/*-------------------------------------------------------------------* + * v_sub() + * + * Subtraction of two vectors sample by sample + *-------------------------------------------------------------------*/ + +void v_sub_fixed( + const Word32 x1[], /* i : Input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */ + const Word16 N, /* i : Vector length */ + const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */ +) +{ + Word16 i; + + FOR ( i = 0; i < N; i++ ) + { + y[i] = L_sub( ( x1[i] >> hdrm ), ( x2[i] >> hdrm ) ); + } + + return; +} + /*-------------------------------------------------------------------* * v_mult() * @@ -942,6 +1058,29 @@ void v_multc( return; } +/*-------------------------------------------------------------------* + * v_multc_fixed() + * + * Multiplication of vector by constant + *-------------------------------------------------------------------*/ + +void v_multc_fixed( + const Word32 x[], /* i : Input vector */ + const Word32 c, /* i : Constant */ + Word32 y[], /* o : Output vector that contains c*x */ + const Word16 N /* i : Vector length */ +) +{ + Word16 i; + + FOR ( i = 0; i < N; i++ ) + { + y[i] = Mpy_32_32( c, x[i] ); + } + + return; +} + /*-------------------------------------------------------------------* * squant() diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 77e01cd30..763de1a17 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -56,11 +56,11 @@ static void ivas_binRenderer_filterModule( float out_Conv_CLDFB_imag[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : imag part of Binaural signals */ float CLDFB_real[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : real part of LS signals */ float CLDFB_imag[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : imag part of LS signals */ - const int16_t numTimeSlots, /* i : number of time slots to process */ + const Word16 numTimeSlots, /* i : number of time slots to process */ BINAURAL_RENDERER_HANDLE hBinRenderer /* i/o: fastconv binaural renderer handle */ ) { - int16_t bandIdx, k, chIdx, tapIdx; + Word16 bandIdx, k, chIdx, tapIdx; float *filterStatesLeftRealPtr, *filterStatesLeftImagPtr; const float *filterTapsLeftRealPtr, *filterTapsLeftImagPtr, *filterTapsRightRealPtr, *filterTapsRightImagPtr; @@ -119,157 +119,162 @@ static void ivas_binRenderer_filterModule( * Open convolution module handle of fastconv binaural renderer *-------------------------------------------------------------------------*/ +#define NUM_TAPS_F0_6 ( Word16 )( 58 ) // (int16_t) ceil( 0.6f * hBinRenConvModule->numTaps ) +#define NUM_TAPS_F0_5 ( Word16 )( 48 ) // (int16_t) ceil( 0.5f * hBinRenConvModule->numTaps ) +#define NUM_TAPS_F0_4 ( Word16 )( 39 ) // (int16_t) ceil( 0.4f * hBinRenConvModule->numTaps ) +#define NUM_TAPS_F0_3 ( Word16 )( 29 ) // (int16_t) ceil( 0.3f * hBinRenConvModule->numTaps ) + static ivas_error ivas_binRenderer_convModuleOpen( BINAURAL_RENDERER_HANDLE hBinRenderer, - const int16_t renderer_type, - const int16_t isLoudspeaker, + const Word16 renderer_type, + const Word16 isLoudspeaker, const AUDIO_CONFIG input_config, const HRTFS_FASTCONV_HANDLE hHrtf ) { - int16_t bandIdx, chIdx; + Word16 bandIdx, chIdx; BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ - if ( ( hBinRenConvModule = (BINRENDERER_CONV_MODULE_HANDLE) malloc( sizeof( BINRENDERER_CONV_MODULE ) ) ) == NULL ) + IF ( ( hBinRenConvModule = (BINRENDERER_CONV_MODULE_HANDLE) malloc( sizeof( BINRENDERER_CONV_MODULE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( !isLoudspeaker ) + IF ( !isLoudspeaker ) { hBinRenderer->nInChannels = audioCfg2channels( input_config ); } - else + ELSE { /* Note: needs to be revisited if multiple LFE support is required */ hBinRenderer->nInChannels = ( audioCfg2channels( input_config ) - isLoudspeaker ); } - if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX; /* Use variable order filtering */ bandIdx = 0; - for ( ; bandIdx < 5; bandIdx++ ) + FOR ( ; bandIdx < 5; bandIdx++ ) { hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; } - for ( ; bandIdx < 10; bandIdx++ ) + FOR ( ; bandIdx < 10; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = (int16_t) ceilf( 0.6f * hBinRenConvModule->numTaps ); + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_6; } - for ( ; bandIdx < 20; bandIdx++ ) + FOR ( ; bandIdx < 20; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = (int16_t) ceilf( 0.5f * hBinRenConvModule->numTaps ); + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_5; } - for ( ; bandIdx < 30; bandIdx++ ) + FOR ( ; bandIdx < 30; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = (int16_t) ceilf( 0.4f * hBinRenConvModule->numTaps ); + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_4; } - for ( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + FOR ( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = (int16_t) ceilf( 0.3f * hBinRenConvModule->numTaps ); + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_3; } } - else + ELSE { - if ( hBinRenderer->ivas_format == SBA_FORMAT ) + IF ( hBinRenderer->ivas_format == SBA_FORMAT ) { hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA; } - else + ELSE { hBinRenConvModule->numTaps = BINAURAL_NTAPS; } /* Use fixed order filtering */ bandIdx = 0; - for ( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + FOR ( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; } } /* allocate memory for filter states */ - if ( ( hBinRenConvModule->filterTapsLeftReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterTapsLeftReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsLeftImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterTapsLeftImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterTapsRightReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterTapsRightImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + FOR ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } } - if ( ( hBinRenConvModule->filterStatesLeftReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterStatesLeftReal = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterStatesLeftImag = (float ***) malloc( hBinRenderer->conv_band * sizeof( float ** ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + FOR ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + FOR ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = (float *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = (float *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] = (float *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) + IF ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] = (float *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } @@ -277,42 +282,42 @@ static ivas_error ivas_binRenderer_convModuleOpen( } /* set memories */ - for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) + FOR ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + FOR ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - int16_t tmp = 0; + Word16 tmp = 0; - if ( isLoudspeaker ) + IF ( isLoudspeaker ) { - if ( input_config == IVAS_AUDIO_CONFIG_5_1 ) + IF ( input_config == IVAS_AUDIO_CONFIG_5_1 ) { tmp = channelIndex_CICP6[chIdx]; } - else if ( input_config == IVAS_AUDIO_CONFIG_7_1 ) + ELSE IF ( input_config == IVAS_AUDIO_CONFIG_7_1 ) { tmp = channelIndex_CICP12[chIdx]; } - else if ( input_config == IVAS_AUDIO_CONFIG_5_1_2 ) + ELSE IF ( input_config == IVAS_AUDIO_CONFIG_5_1_2 ) { tmp = channelIndex_CICP14[chIdx]; } - else if ( input_config == IVAS_AUDIO_CONFIG_5_1_4 ) + ELSE IF ( input_config == IVAS_AUDIO_CONFIG_5_1_4 ) { tmp = channelIndex_CICP16[chIdx]; } - else if ( input_config == IVAS_AUDIO_CONFIG_7_1_4 ) + ELSE IF ( input_config == IVAS_AUDIO_CONFIG_7_1_4 ) { tmp = channelIndex_CICP19[chIdx]; } } - if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { /* set the memories to zero */ set_zero( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx] ); set_zero( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx] ); - if ( isLoudspeaker ) + IF ( isLoudspeaker ) { hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftBRIRReal[bandIdx][tmp]; hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftBRIRImag[bandIdx][tmp]; @@ -320,21 +325,21 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightBRIRImag[bandIdx][tmp]; } } - else + ELSE { /* set the memories to zero */ set_zero( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTaps ); set_zero( hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTaps ); - if ( isLoudspeaker ) + IF ( isLoudspeaker ) { hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal[bandIdx][tmp]; hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag[bandIdx][tmp]; hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal[bandIdx][tmp]; hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag[bandIdx][tmp]; } - else + ELSE { - if ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + IF ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) { /* HOA3 filter coefficients */ hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA3[bandIdx][chIdx]; @@ -342,7 +347,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA3[bandIdx][chIdx]; hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA3[bandIdx][chIdx]; } - else if ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + ELSE IF ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) { /* HOA2 filter coefficients */ hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA2[bandIdx][chIdx]; @@ -350,7 +355,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA2[bandIdx][chIdx]; hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA2[bandIdx][chIdx]; } - else if ( input_config == IVAS_AUDIO_CONFIG_FOA ) + ELSE IF ( input_config == IVAS_AUDIO_CONFIG_FOA ) { /* FOA filter coefficients */ hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_FOA[bandIdx][chIdx]; @@ -358,7 +363,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_FOA[bandIdx][chIdx]; hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_FOA[bandIdx][chIdx]; } - else + ELSE { return IVAS_ERR_INVALID_INPUT_FORMAT; } @@ -384,7 +389,7 @@ void ivas_init_binaural_hrtf( HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */ ) { - int16_t i; + Word16 i; HrtfFastConv->leftHRIRReal_HOA3 = NULL; HrtfFastConv->leftHRIRImag_HOA3 = NULL; @@ -418,7 +423,7 @@ void ivas_init_binaural_hrtf( HrtfFastConv->allocate_init_flag = 0x00; - for ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + FOR ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) { HrtfFastConv->fastconvReverberationEneCorrections[i] = 0x00; HrtfFastConv->fastconvReverberationEneCorrections[i] = 0x00; @@ -436,30 +441,30 @@ void ivas_init_binaural_hrtf( static ivas_error ivas_alloc_pppMem( float ****pppMem, - const int16_t dim1, - const int16_t dim2, - const int16_t dim3, - const int16_t allocate_init_flag ) + const Word16 dim1, + const Word16 dim2, + const Word16 dim3, + const Word16 allocate_init_flag ) { - int16_t i, j; + Word16 i, j; float ***localMem = NULL; - if ( ( localMem = (float ***) malloc( dim1 * sizeof( float ** ) ) ) == NULL ) + IF ( ( localMem = (float ***) malloc( dim1 * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); } - for ( i = 0; i < dim1; i++ ) + FOR ( i = 0; i < dim1; i++ ) { - if ( ( localMem[i] = (float **) malloc( dim2 * sizeof( float * ) ) ) == NULL ) + IF ( ( localMem[i] = (float **) malloc( dim2 * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); } - if ( allocate_init_flag == 0 ) + IF ( allocate_init_flag == 0 ) { - for ( j = 0; j < dim2; j++ ) + FOR ( j = 0; j < dim2; j++ ) { - if ( ( localMem[i][j] = (float *) malloc( dim3 * sizeof( float ) ) ) == NULL ) + IF ( ( localMem[i][j] = (float *) malloc( dim3 * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" ); } @@ -484,139 +489,139 @@ ivas_error ivas_allocate_binaural_hrtf( const AUDIO_CONFIG input_config, /* i : input audio configuration */ const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */ const RENDERER_TYPE renderer_type, /* i : renderer type */ - const int16_t allocate_init_flag /* i : Memory allocation flag */ + const Word16 allocate_init_flag /* i : Memory allocation flag */ ) { - if ( input_config == IVAS_AUDIO_CONFIG_HOA3 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) + IF ( input_config == IVAS_AUDIO_CONFIG_HOA3 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) { - if ( ( HrtfFastConv->leftHRIRReal_HOA3 != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA3 != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA3 != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA3 != NULL ) ) + IF ( ( HrtfFastConv->leftHRIRReal_HOA3 != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA3 != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA3 != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA3 != NULL ) ) { return IVAS_ERR_OK; } - else + ELSE { - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRReal_HOA3, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRReal_HOA3, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA3" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRImag_HOA3, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRImag_HOA3, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA3" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRReal_HOA3, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRReal_HOA3, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA3" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRImag_HOA3, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRImag_HOA3, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA3" ); } } } - if ( input_config == IVAS_AUDIO_CONFIG_HOA2 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) + IF ( input_config == IVAS_AUDIO_CONFIG_HOA2 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) { - if ( ( HrtfFastConv->leftHRIRReal_HOA2 != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA2 != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA2 != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA2 != NULL ) ) + IF ( ( HrtfFastConv->leftHRIRReal_HOA2 != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA2 != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA2 != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA2 != NULL ) ) { return IVAS_ERR_OK; } - else + ELSE { - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRReal_HOA2, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRReal_HOA2, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA2" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRImag_HOA2, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRImag_HOA2, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA2" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRReal_HOA2, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRReal_HOA2, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA2" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRImag_HOA2, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRImag_HOA2, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA2" ); } } } - if ( input_config == IVAS_AUDIO_CONFIG_FOA || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_FOA ) + IF ( input_config == IVAS_AUDIO_CONFIG_FOA || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_FOA ) { - if ( ( HrtfFastConv->leftHRIRReal_FOA != NULL ) && ( HrtfFastConv->leftHRIRImag_FOA != NULL ) && ( HrtfFastConv->rightHRIRReal_FOA != NULL ) && ( HrtfFastConv->rightHRIRImag_FOA != NULL ) ) + IF ( ( HrtfFastConv->leftHRIRReal_FOA != NULL ) && ( HrtfFastConv->leftHRIRImag_FOA != NULL ) && ( HrtfFastConv->rightHRIRReal_FOA != NULL ) && ( HrtfFastConv->rightHRIRImag_FOA != NULL ) ) { return IVAS_ERR_OK; } - else + ELSE { - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRReal_FOA, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRReal_FOA, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_FOA" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRImag_FOA, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRImag_FOA, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_FOA" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRReal_FOA, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRReal_FOA, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_FOA" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRImag_FOA, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRImag_FOA, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_FOA" ); } } } - if ( renderer_type == RENDERER_BINAURAL_FASTCONV || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + IF ( renderer_type == RENDERER_BINAURAL_FASTCONV || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) { - if ( ( HrtfFastConv->leftHRIRReal != NULL ) && ( HrtfFastConv->leftHRIRImag != NULL ) && ( HrtfFastConv->rightHRIRReal != NULL ) && ( HrtfFastConv->rightHRIRImag != NULL ) ) + IF ( ( HrtfFastConv->leftHRIRReal != NULL ) && ( HrtfFastConv->leftHRIRImag != NULL ) && ( HrtfFastConv->rightHRIRReal != NULL ) && ( HrtfFastConv->rightHRIRImag != NULL ) ) { return IVAS_ERR_OK; } - else + ELSE { - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRReal, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRReal, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRImag, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftHRIRImag, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRReal, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRReal, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRImag, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightHRIRImag, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag" ); } } } - if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + IF ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) { - if ( ( HrtfFastConv->leftBRIRReal != NULL ) && ( HrtfFastConv->leftBRIRImag != NULL ) && ( HrtfFastConv->rightBRIRReal != NULL ) && ( HrtfFastConv->rightBRIRImag != NULL ) ) + IF ( ( HrtfFastConv->leftBRIRReal != NULL ) && ( HrtfFastConv->leftBRIRImag != NULL ) && ( HrtfFastConv->rightBRIRReal != NULL ) && ( HrtfFastConv->rightBRIRImag != NULL ) ) { return IVAS_ERR_OK; } - else + ELSE { - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftBRIRReal, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftBRIRReal, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRReal" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftBRIRImag, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftBRIRImag, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRImag" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightBRIRReal, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightBRIRReal, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRReal" ); } - if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightBRIRImag, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightBRIRImag, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRImag" ); } @@ -639,58 +644,58 @@ static ivas_error ivas_binaural_hrtf_open( const RENDERER_TYPE renderer_type /* i : renderer type */ ) { - int16_t i, j; + Word16 i, j; ivas_error error; - if ( hHrtfFastConv != NULL && *hHrtfFastConv != NULL ) + IF ( hHrtfFastConv != NULL && *hHrtfFastConv != NULL ) { /* Tables already loaded from file */ return IVAS_ERR_OK; } - else + ELSE { /* Initialise tables from ROM */ HRTFS_FASTCONV *HrtfFastConv; - if ( ( HrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) ) ) == NULL ) + IF ( ( HrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for FastConv HRTF tables" ); } ivas_init_binaural_hrtf( HrtfFastConv ); - if ( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF ( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV ) { HrtfFastConv->FASTCONV_HRIR_latency_s = FASTCONV_HRIR_latency_s; } - if ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + IF ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) { HrtfFastConv->FASTCONV_HOA2_latency_s = FASTCONV_HOA2_latency_s; } - if ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + IF ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) { HrtfFastConv->FASTCONV_HOA3_latency_s = FASTCONV_HOA3_latency_s; } - if ( input_config == IVAS_AUDIO_CONFIG_FOA ) + IF ( input_config == IVAS_AUDIO_CONFIG_FOA ) { HrtfFastConv->FASTCONV_FOA_latency_s = FASTCONV_FOA_latency_s; } - if ( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF ( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { HrtfFastConv->FASTCONV_BRIR_latency_s = FASTCONV_BRIR_latency_s; } HrtfFastConv->allocate_init_flag = 1; - if ( ( error = ivas_allocate_binaural_hrtf( HrtfFastConv, input_config, BINAURAL_INPUT_AUDIO_CONFIG_INVALID, renderer_type, HrtfFastConv->allocate_init_flag ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_allocate_binaural_hrtf( HrtfFastConv, input_config, BINAURAL_INPUT_AUDIO_CONFIG_INVALID, renderer_type, HrtfFastConv->allocate_init_flag ) ) != IVAS_ERR_OK ) { return error; } - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + FOR ( i = 0; i < BINAURAL_CONVBANDS; i++ ) { - if ( renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF ( renderer_type == RENDERER_BINAURAL_FASTCONV ) { - for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + FOR ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { HrtfFastConv->leftHRIRReal[i][j] = leftHRIRReal[i][j]; HrtfFastConv->leftHRIRImag[i][j] = leftHRIRImag[i][j]; @@ -698,9 +703,9 @@ static ivas_error ivas_binaural_hrtf_open( HrtfFastConv->rightHRIRImag[i][j] = rightHRIRImag[i][j]; } } - else if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + ELSE IF ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { - for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) + FOR ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { HrtfFastConv->leftBRIRReal[i][j] = leftBRIRReal[i][j]; HrtfFastConv->leftBRIRImag[i][j] = leftBRIRImag[i][j]; @@ -708,9 +713,9 @@ static ivas_error ivas_binaural_hrtf_open( HrtfFastConv->rightBRIRImag[i][j] = rightBRIRImag[i][j]; } } - if ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + IF ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) { - for ( j = 0; j < HOA3_CHANNELS; j++ ) + FOR ( j = 0; j < HOA3_CHANNELS; j++ ) { HrtfFastConv->leftHRIRReal_HOA3[i][j] = leftHRIRReal_HOA3[i][j]; HrtfFastConv->leftHRIRImag_HOA3[i][j] = leftHRIRImag_HOA3[i][j]; @@ -718,9 +723,9 @@ static ivas_error ivas_binaural_hrtf_open( HrtfFastConv->rightHRIRImag_HOA3[i][j] = rightHRIRImag_HOA3[i][j]; } } - if ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + IF ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) { - for ( j = 0; j < HOA2_CHANNELS; j++ ) + FOR ( j = 0; j < HOA2_CHANNELS; j++ ) { HrtfFastConv->leftHRIRReal_HOA2[i][j] = leftHRIRReal_HOA2[i][j]; HrtfFastConv->leftHRIRImag_HOA2[i][j] = leftHRIRImag_HOA2[i][j]; @@ -728,9 +733,9 @@ static ivas_error ivas_binaural_hrtf_open( HrtfFastConv->rightHRIRImag_HOA2[i][j] = rightHRIRImag_HOA2[i][j]; } } - if ( input_config == IVAS_AUDIO_CONFIG_FOA ) + IF ( input_config == IVAS_AUDIO_CONFIG_FOA ) { - for ( j = 0; j < FOA_CHANNELS; j++ ) + FOR ( j = 0; j < FOA_CHANNELS; j++ ) { HrtfFastConv->leftHRIRReal_FOA[i][j] = leftHRIRReal_FOA[i][j]; HrtfFastConv->leftHRIRImag_FOA[i][j] = leftHRIRImag_FOA[i][j]; @@ -881,7 +886,7 @@ ivas_error ivas_binRenderer_open( ) { BINAURAL_RENDERER_HANDLE hBinRenderer; - int16_t convBand, chIdx, k; + Word16 convBand, chIdx, k; ivas_error error; error = IVAS_ERR_OK; @@ -890,7 +895,7 @@ ivas_error ivas_binRenderer_open( * prepare library opening *-----------------------------------------------------------------*/ - if ( ( hBinRenderer = (BINAURAL_RENDERER_HANDLE) malloc( sizeof( BINAURAL_RENDERER ) ) ) == NULL ) + IF ( ( hBinRenderer = (BINAURAL_RENDERER_HANDLE) malloc( sizeof( BINAURAL_RENDERER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Renderer\n" ) ); } @@ -899,7 +904,7 @@ ivas_error ivas_binRenderer_open( /* Define of head rotation has to be done in binRendeder in CLDFB*/ hBinRenderer->rotInCldfb = 0; - if ( st_ivas->ivas_format == MC_FORMAT || st_ivas->ivas_format == SBA_FORMAT ) + IF ( st_ivas->ivas_format == MC_FORMAT || st_ivas->ivas_format == SBA_FORMAT ) { hBinRenderer->rotInCldfb = 1; } @@ -907,11 +912,11 @@ ivas_error ivas_binRenderer_open( /* Declare some common variables needed for renderer */ /* Which format used for binaural rendering (needed for late reverb) ? MC or SBA */ - if ( st_ivas->hIntSetup.is_loudspeaker_setup ) + IF ( st_ivas->hIntSetup.is_loudspeaker_setup ) { hBinRenderer->ivas_format = MC_FORMAT; } - else + ELSE { hBinRenderer->ivas_format = SBA_FORMAT; } @@ -920,11 +925,11 @@ ivas_error ivas_binRenderer_open( hBinRenderer->timeSlots = MAX_PARAM_SPATIAL_SUBFRAMES; /* Corresponds to 5 msec sound to motion latency */ - if ( convBand > BINAURAL_CONVBANDS ) + IF ( convBand > BINAURAL_CONVBANDS ) { hBinRenderer->conv_band = BINAURAL_CONVBANDS; } - else + ELSE { hBinRenderer->conv_band = convBand; } @@ -932,32 +937,32 @@ ivas_error ivas_binRenderer_open( /*LFE rendering switched off by default*/ hBinRenderer->render_lfe = 0; - if ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->hIntSetup.is_loudspeaker_setup ) + IF ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->hIntSetup.is_loudspeaker_setup ) { hBinRenderer->render_lfe = 1; } /* Load HRTF tables */ - if ( ( error = ivas_binaural_hrtf_open( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_binaural_hrtf_open( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && ( st_ivas->hIntSetup.is_loudspeaker_setup == 0 ) ) + IF ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && ( st_ivas->hIntSetup.is_loudspeaker_setup == 0 ) ) { IVAS_OUTPUT_SETUP out_setup; /* Allocate memories and buffers needed for convolutional module in CICP19 */ - if ( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, 1, IVAS_AUDIO_CONFIG_7_1_4, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, 1, IVAS_AUDIO_CONFIG_7_1_4, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) { return error; } ivas_output_init( &out_setup, IVAS_AUDIO_CONFIG_7_1_4 ); - if ( st_ivas->hoa_dec_mtx == NULL ) + IF ( st_ivas->hoa_dec_mtx == NULL ) { - if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) { return error; } @@ -966,41 +971,41 @@ ivas_error ivas_binRenderer_open( hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx; st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f ); } - else + ELSE { /* Allocate memories and buffers needed for convolutional module */ - if ( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, st_ivas->hIntSetup.is_loudspeaker_setup, st_ivas->hIntSetup.output_config, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, st_ivas->hIntSetup.is_loudspeaker_setup, st_ivas->hIntSetup.output_config, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) { - if ( hBinRenderer->ivas_format == MC_FORMAT ) + IF ( hBinRenderer->ivas_format == MC_FORMAT ) { st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s * 1000000000.f ); } - else + ELSE { - if ( hBinRenderer->nInChannels == 16 ) + IF ( hBinRenderer->nInChannels == 16 ) { st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s * 1000000000.f ); } - else if ( hBinRenderer->nInChannels == 9 ) + ELSE IF ( hBinRenderer->nInChannels == 9 ) { st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_HOA2_latency_s * 1000000000.f ); } - else if ( hBinRenderer->nInChannels == 4 ) + ELSE IF ( hBinRenderer->nInChannels == 4 ) { st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_FOA_latency_s * 1000000000.f ); } - else + ELSE { return IVAS_ERR_INVALID_INPUT_FORMAT; } } } - else + ELSE { /* same value for MC or HOA both use MC BRIR*/ st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f ); @@ -1008,41 +1013,52 @@ ivas_error ivas_binRenderer_open( } /* Allocate memories needed for reverb module */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - if ( ( error = ivas_binaural_reverb_open_fastconv( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_binaural_reverb_open_fastconv( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) { return error; } /* initialize the dmx matrix */ - for ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) + FOR ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { - for ( k = 0; k < hBinRenderer->nInChannels; k++ ) + FOR ( k = 0; k < hBinRenderer->nInChannels; k++ ) { hBinRenderer->hReverb->dmxmtx[chIdx][k] = dmxmtx_table[chIdx][k]; } } } - else + ELSE { hBinRenderer->hReverb = NULL; } hBinRenderer->hEFAPdata = NULL; - if ( hBinRenderer->hReverb != NULL ) + IF ( hBinRenderer->hReverb != NULL ) { - if ( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 ) + IF ( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 ) { - for ( k = 0; k < 11; k++ ) +#ifdef IVAS_FLOAT_FIXED + Word32 foa_enc_int[FOA_CHANNELS]; +#endif + FOR ( k = 0; k < 11; k++ ) { +#ifndef IVAS_FLOAT_FIXED ivas_dirac_dec_get_response( (int16_t) ls_azimuth_CICP19[k], (int16_t) ls_elevation_CICP19[k], hBinRenderer->hReverb->foa_enc[k], 1 ); +#else + ivas_dirac_dec_get_response_fixed( (int16_t) ls_azimuth_CICP19[k], (int16_t) ls_elevation_CICP19[k], foa_enc_int, 1 ); + FOR( int foa_idx = 0; foa_idx < FOA_CHANNELS; foa_idx++ ) + { + hBinRenderer->hReverb->foa_enc[k][foa_idx] = ( (float) foa_enc_int[foa_idx] ) / ( 1 << Q29 ); + } +#endif } } - else if ( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + ELSE IF ( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { - if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth, st_ivas->hIntSetup.ls_elevation, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth, st_ivas->hIntSetup.ls_elevation, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } @@ -1069,17 +1085,17 @@ static void ivas_binRenderer_convModuleClose( BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: fastconv binaural renderer handle */ ) { - int16_t bandIdx, chIdx; + Word16 bandIdx, chIdx; BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; hBinRenConvModule = ( *hBinRenderer )->hBinRenConvModule; - if ( hBinRenConvModule == NULL ) + IF ( hBinRenConvModule == NULL ) { return; } - for ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) + FOR ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) { free( hBinRenConvModule->filterTapsLeftReal[bandIdx] ); hBinRenConvModule->filterTapsLeftReal[bandIdx] = NULL; @@ -1106,9 +1122,9 @@ static void ivas_binRenderer_convModuleClose( free( hBinRenConvModule->filterTapsRightImag ); hBinRenConvModule->filterTapsRightImag = NULL; - for ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) + FOR ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) { - for ( chIdx = 0; chIdx < ( *hBinRenderer )->nInChannels; chIdx++ ) + FOR ( chIdx = 0; chIdx < ( *hBinRenderer )->nInChannels; chIdx++ ) { free( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] ); hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = NULL; @@ -1147,17 +1163,17 @@ void ivas_binRenderer_close( BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: fastconv binaural renderer handle */ ) { - if ( hBinRenderer == NULL || *hBinRenderer == NULL ) + IF ( hBinRenderer == NULL || *hBinRenderer == NULL ) { return; } - if ( ( *hBinRenderer )->hBinRenConvModule != NULL ) + IF ( ( *hBinRenderer )->hBinRenConvModule != NULL ) { ivas_binRenderer_convModuleClose( hBinRenderer ); } - if ( ( *hBinRenderer )->hReverb != NULL ) + IF ( ( *hBinRenderer )->hReverb != NULL ) { ivas_binaural_reverb_close( &( ( *hBinRenderer )->hReverb ) ); } @@ -1177,18 +1193,18 @@ void ivas_binRenderer_close( static void ivas_free_pppHrtfMem( float ****ppppHRIR, - const int16_t dim, - const int16_t alloc_init ) + const Word16 dim, + const Word16 alloc_init ) { - int16_t i, j; + Word16 i, j; - if ( *ppppHRIR != NULL ) + IF ( *ppppHRIR != NULL ) { - for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + FOR ( i = 0; i < BINAURAL_CONVBANDS; i++ ) { - if ( alloc_init == 0 ) + IF( alloc_init == 0 ) { - for ( j = 0; j < dim; j++ ) + FOR( j = 0; j < dim; j++ ) { free( ( *ppppHRIR )[i][j] ); ( *ppppHRIR )[i][j] = NULL; @@ -1215,9 +1231,9 @@ void ivas_binaural_hrtf_close( HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i : fastconv HRTF handle */ ) { - int16_t allocate_init_flag; + Word16 allocate_init_flag; - if ( hHrtfFastConv == NULL || *hHrtfFastConv == NULL ) + IF ( hHrtfFastConv == NULL || *hHrtfFastConv == NULL ) { return; } diff --git a/lib_rend/ivas_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index abc98d70a..e91b2c306 100644 --- a/lib_rend/ivas_allrad_dec.c +++ b/lib_rend/ivas_allrad_dec.c @@ -41,7 +41,6 @@ #include "wmc_auto.h" - /*-----------------------------------------------------------------------* * Global function definitions *-----------------------------------------------------------------------*/ @@ -51,11 +50,11 @@ * * Computes the ALLRAD decoder matrix for HOA to loudspeakers *-------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_sba_get_hoa_dec_matrix( const IVAS_OUTPUT_SETUP hOutSetup, /* i : target output setup */ float **hoa_dec_mtx, /* o : ALLRAD decoder matrix */ - const int16_t ambisonics_order /* i : Ambisonics order */ + const Word16 ambisonics_order /* i : Ambisonics order */ ) { int16_t i, j, k; @@ -161,3 +160,122 @@ ivas_error ivas_sba_get_hoa_dec_matrix( return error; } +#else +#define TEMP_VAL 30678337 // Q31 (1.f / num_td) +ivas_error ivas_sba_get_hoa_dec_matrix( + const IVAS_OUTPUT_SETUP hOutSetup, /* i : target output setup */ + float **hoa_dec_mtx, /* o : ALLRAD decoder matrix */ + const Word16 ambisonics_order /* i : Ambisonics order */ +) +{ + Word16 i, j, k; + Word16 num_harm, num_td, num_spk; + const Word32 *t_design_azi, *t_design_ele; + Word32 tmp_val; + Word32 G_td_int[MAX_OUTPUT_CHANNELS]; + Word32 Y_td_int[SBA_NHARM_HOA3]; + float *p_dec_mtx; + EFAP_HANDLE hEFAP; + ivas_error error; + + error = IVAS_ERR_OK; + + /* Allocate memory */ + assert( *hoa_dec_mtx == NULL && "hoa_dec_mtx != NULL" ); + IF ( ( *hoa_dec_mtx = (float *) malloc( SBA_NHARM_HOA3 * ( hOutSetup.nchan_out_woLFE ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "ALLRAD: Cannot allocate memory!" ) ); + } + + /* Initialization by zeroing all SH coeff up to 3rd order (IVAS convention) */ + num_spk = hOutSetup.nchan_out_woLFE; + p_dec_mtx = *hoa_dec_mtx; + + FOR ( i = 0; i < num_spk; i++ ) + { + FOR ( j = 0; j < SBA_NHARM_HOA3; j++ ) + { + *( p_dec_mtx++ ) = 0.f; + } + } + + IF ( hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO ) + { + ( *hoa_dec_mtx )[0] = 1.f; + } + ELSE IF ( hOutSetup.output_config == IVAS_AUDIO_CONFIG_STEREO ) + { + ( *hoa_dec_mtx )[0] = 0.5f; + ( *hoa_dec_mtx )[1] = 0.5f; + ( *hoa_dec_mtx )[SBA_NHARM_HOA3] = 0.5f; + ( *hoa_dec_mtx )[SBA_NHARM_HOA3 + 1] = -0.5f; + } + ELSE IF ( hOutSetup.is_loudspeaker_setup ) + { + /* init EFIP */ + IF ( ( error = efap_init_data( &( hEFAP ), hOutSetup.ls_azimuth, hOutSetup.ls_elevation, num_spk, EFAP_MODE_EFIP ) ) != IVAS_ERR_OK ) + { + return error; + } + + num_harm = ivas_sba_get_nchan( ambisonics_order, 0 ); + + /* Get t-design values */ + num_td = SBA_T_DESIGN_11_SIZE; + t_design_azi = t_design_11_azimuth_int; + t_design_ele = t_design_11_elevation_int; + + /* dec_mtx = ( 1 / num_td ) * (G_td * Y_td') * diag(norm_sn3d) */ + FOR ( i = 0; i < num_td; i++ ) + { + /* spherical harmonics response for t-design, corresponding to ambisonic order */ + ivas_dirac_dec_get_response_fixed( + ( (Word16) ( t_design_azi[i] >> 22 ) ) > 0 ? ( (Word16) ( t_design_azi[i] >> 22 ) ) : ( (Word16) ( t_design_azi[i] >> 22 ) ) + 1, + ( (Word16) ( t_design_ele[i] >> 22 ) ) > 0 ? ( (Word16) ( t_design_ele[i] >> 22 ) ) : ( (Word16) ( t_design_ele[i] >> 22 ) ) + 1, + Y_td_int, ambisonics_order ); + FOR ( j = 0; j < num_harm; j++ ) + { + Y_td_int[j] = Mpy_32_32( Y_td_int[j], norm_sn3d_hoa3_int[j] ) << 1; // Q28 + } + + /* t-design to real LS panning gains */ + efap_determine_gains_fixed( hEFAP, G_td_int, t_design_azi[i], t_design_ele[i] , EFAP_MODE_EFIP ); + + p_dec_mtx = *hoa_dec_mtx; + FOR ( j = 0; j < num_spk; j++ ) + { + Word32 dec_mtx_temp = 0; + FOR ( k = 0; k < num_harm; k++ ) + { + dec_mtx_temp = Mpy_32_32( G_td_int[j], Y_td_int[k] ); + *( p_dec_mtx++ ) += ( (float) dec_mtx_temp ) / ( 1 << 25 ); + } + p_dec_mtx += ( SBA_NHARM_HOA3 - num_harm ); + } + } + + tmp_val = TEMP_VAL; + p_dec_mtx = *hoa_dec_mtx; + FOR ( i = 0; i < num_spk; i++ ) + { + Word32 dec_mtx_temp_scale = 0; + FOR ( j = 0; j < num_harm; j++ ) + { + dec_mtx_temp_scale = Mpy_32_32( tmp_val, norm_sn3d_hoa3_int[j] ); + *( p_dec_mtx++ ) *= ((float)dec_mtx_temp_scale) / (1<<29); + } + p_dec_mtx += ( SBA_NHARM_HOA3 - num_harm ); + } + + /* free EFAP handle */ + efap_free_data( &hEFAP ); + } + ELSE + { + assert( 0 && "ALLRAD: output not supported!!!" ); + } + + + return error; +} +#endif \ No newline at end of file diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 9391a5a73..ff1c83741 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -36,6 +36,7 @@ #include #include "options.h" #include "prot.h" +#include "prot_fx2.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_stat_dec.h" @@ -48,7 +49,10 @@ #define EFAP_MAX_SIZE_TMP_BUFF 30 #define EFAP_MAX_GHOST_LS 5 /* Maximum number of ghost Loudspeakers, for memory allocation purpose */ #define POLY_THRESH 1e-4f - +#ifdef IVAS_FLOAT_FIXED +#define Q22_180_DEG 754974720 +#define Q22_360_DEG 1509949440 +#endif /*-----------------------------------------------------------------------* * Local function prototypes @@ -75,12 +79,17 @@ static void remap_ghosts( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, int static void vertex_init( const float *aziSpk, const float *eleSpk, EFAP_VERTEX_DATA *efapVtxData ); static void efap_panning( const float azi, const float ele, const EFAP_POLYSET_DATA *polyData, float *bufferL ); - +#ifdef IVAS_FLOAT_FIXED +static void efap_panning_fixed( const Word32 azi, const Word32 ele, const EFAP_POLYSET_DATA *polyData, float *bufferL ); +#endif static void get_poly_gains( const float azi, const float ele, const float aziPoly[EFAP_MAX_CHAN_NUM], const float elePoly[EFAP_MAX_CHAN_NUM], const int16_t numChan, float *buffer ); - +#ifdef IVAS_FLOAT_FIXED +static void get_poly_gains_fixed( const Word32 azi, const Word32 ele, const Word32 aziPoly[EFAP_MAX_CHAN_NUM], const Word32 elePoly[EFAP_MAX_CHAN_NUM], const Word16 numChan, Word32 *buffer ); +#endif static float get_tri_gain( const float A[2], const float B[2], const float C[2], const float P_minus_A[2] ); - - +#ifdef IVAS_FLOAT_FIXED +static Word32 get_tri_gain_fixed( const Word32 A[2], const Word32 B[2], const Word32 C[2], const Word32 P_minus_A[2] ); +#endif /*-----------------------------------------------------------------------* * EFAP Utils @@ -93,11 +102,17 @@ static void efap_sort_s( int16_t *x, int16_t *idx, const int16_t len ); static float vertex_distance( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE tri, const int16_t vtxIdx ); static float point_plane_distance( const float P1[3], const float P2[3], const float P3[3], const float X[3] ); - +#ifdef IVAS_FLOAT_FIXED +static Word32 point_plane_distance_fixed( const Word32 P1[3], const Word32 P2[3], const Word32 P3[3], const Word32 X[3] ); +#endif static float point_poly_distance( const EFAP_POLYSET poly, const float X[3] ); - +#ifdef IVAS_FLOAT_FIXED +static Word32 point_poly_distance_fixed( const EFAP_POLYSET poly, const Word32 X[3] ); +#endif static void efap_crossp( const float *v1, const float *v2, float *v ); - +#ifdef IVAS_FLOAT_FIXED +static void efap_crossp_fixed( const Word32 *v1, const Word32 *v2, Word32 *v ); +#endif static int16_t find_int_in_tri( const EFAP_LS_TRIANGLE *tri, const int16_t n, const int16_t r, int16_t *pos ); static void remove_vertex( EFAP_VERTEX *vtxArray, const int16_t idx, const int16_t L ); @@ -114,14 +129,24 @@ static void sort_channels_vertex( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRI static float efap_fmodf( const float x, const float y ); -static int16_t get_poly_num( const float P[2], const EFAP_POLYSET_DATA *polyData ); +static Word32 efap_lmodl( const Word32 x, const Word32 y ); +static int16_t get_poly_num( const float P[2], const EFAP_POLYSET_DATA *polyData ); +#ifdef IVAS_FLOAT_FIXED +static int16_t get_poly_num_fixed( const Word32 P[2], const EFAP_POLYSET_DATA *polyData ); +#endif static int16_t in_poly( const float P[2], const EFAP_POLYSET poly ); - +#ifdef IVAS_FLOAT_FIXED +static Word16 in_poly_fixed( const Word32 P[2], const EFAP_POLYSET poly ); +#endif static int16_t in_tri( float A[2], float B[2], float C[2], float P_minus_A[2] ); - +#ifdef IVAS_FLOAT_FIXED +static Word16 in_tri_fixed( Word32 A[2], Word32 B[2], Word32 C[2], Word32 P_minus_A[2] ); +#endif static void sph2cart( const float azi, const float ele, float *pos ); - +#ifdef IVAS_FLOAT_FIXED +static void sph2cart_fixed( const Word32 azi, const Word32 ele, Word32 *pos ); +#endif /*-----------------------------------------------------------------------* * Global function definitions *-----------------------------------------------------------------------*/ @@ -293,8 +318,90 @@ void efap_determine_gains( return; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * efap_determine_gains_fixed() + * + * Obtain amplitude panning gains for all speaker nodes based on the + * given direction + *-------------------------------------------------------------------------*/ + +void efap_determine_gains_fixed( + EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ + Word32 *gains, /* o : gain vector for speaker nodes for given direction */ + const Word32 azi_deg, + /* i : azimuth in degrees for panning direction (positive left) */ // Q22 + const Word32 ele_deg, + /* i : elevation in degrees for panning direction (positive up) */ // Q22 + const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ + +) +{ + Word16 i, j; + Word32 azi_wrap_int, ele_wrap_int; + float normBuffer, gain_temp[MAX_OUTPUT_CHANNELS]; + /* Resetting bufferShort and bufferLong */ + set_zero( hEFAPdata->bufferShort, hEFAPdata->numSpk ); + set_zero( hEFAPdata->bufferLong, hEFAPdata->vtxData.numVtx ); + + /* Wrap angles to correct range */ + panning_wrap_angles_fixed( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); + + /* Panning */ + efap_panning_fixed( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong ); + + IF( efap_mode == EFAP_MODE_EFAP ) + { + normBuffer = 0.f; + FOR( j = 0; j < hEFAPdata->numSpk; ++j ) + { + hEFAPdata->bufferShort[j] = 0.f; + /* Multiplying by the downmixMatrix */ + FOR( i = 0; i < hEFAPdata->vtxData.numVtx; ++i ) + { + hEFAPdata->bufferShort[j] += hEFAPdata->bufferLong[i] * hEFAPdata->dmTranspose[i][j]; + } + normBuffer = normBuffer + hEFAPdata->bufferShort[j] * hEFAPdata->bufferShort[j]; + } + normBuffer = inv_sqrt( normBuffer ); + FOR( j = 0; j < hEFAPdata->numSpk; ++j ) + { + hEFAPdata->bufferShort[j] *= normBuffer; + } + } + ELSE + { + normBuffer = 0.f; + FOR( j = 0; j < hEFAPdata->numSpk; ++j ) + { + hEFAPdata->bufferShort[j] = 0.f; + /* Multiplying by the downmixMatrix */ + FOR( i = 0; i < hEFAPdata->vtxData.numVtx; ++i ) + { + hEFAPdata->bufferShort[j] += hEFAPdata->bufferLong[i] * hEFAPdata->dmTranspose[i][j]; + } + normBuffer = normBuffer + hEFAPdata->bufferShort[j]; + } + normBuffer = 1.f / normBuffer; + + FOR( j = 0; j < hEFAPdata->numSpk; ++j ) + { + hEFAPdata->bufferShort[j] = sqrtf( hEFAPdata->bufferShort[j] * normBuffer ); + } + } + + /* Copy gains to output */ + mvr2r( hEFAPdata->bufferShort, gain_temp, hEFAPdata->numSpk ); + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + { + gains[i] = (Word32) ( gain_temp[i] * ( 1 << Q28 ) ); + } + + return; +} +#endif /*-------------------------------------------------------------------------* * efap_free_data() * @@ -370,7 +477,11 @@ static ivas_error poly_init( int16_t finalLength, lengthTri2PolyPS; int16_t lengthTri2PolySorted[EFAP_MAX_POLY_SET]; int16_t sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM]; +#ifndef IVAS_FLOAT_FIXED float tmpMax, tmpMin; +#else + Word32 tmpMax, tmpMin; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -413,26 +524,45 @@ static ivas_error poly_init( for ( j = 0; j < lengthTri2PolySorted[n]; ++j ) { efap->polyData.polysetArray[m].chan[j] = sortedChan[n][j]; +#ifndef IVAS_FLOAT_FIXED efap->polyData.polysetArray[m].polyAzi[j] = efap->vtxData.vertexArray[sortedChan[n][j]].azi; efap->polyData.polysetArray[m].polyEle[j] = efap->vtxData.vertexArray[sortedChan[n][j]].ele; +#else + efap->polyData.polysetArray[m].polyAzi[j] = (Word32) ( efap->vtxData.vertexArray[sortedChan[n][j]].azi * ( 1 << Q22 ) ); + efap->polyData.polysetArray[m].polyEle[j] = (Word32) ( efap->vtxData.vertexArray[sortedChan[n][j]].ele * ( 1 << Q22 ) ); +#endif efap->polyData.polysetArray[m].isNaN[j] = efap->vtxData.vertexArray[sortedChan[n][j]].isNaN; } efap->polyData.polysetArray[m].numChan = lengthTri2PolySorted[n]; /* In case tmpMax - tmpMin > 180, wrap polygon azimuth */ +#ifndef IVAS_FLOAT_FIXED maximum( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMax ); minimum( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMin ); +#else + maximum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMax ); + minimum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMin ); +#endif +#ifndef IVAS_FLOAT_FIXED if ( ( tmpMax - tmpMin ) > 180 ) +#else + if ( ( tmpMax - tmpMin ) > Q22_180_DEG /*180 in Q22*/ ) +#endif { for ( j = 0; j < lengthTri2PolySorted[n]; ++j ) { assert( ( m + 2 < EFAP_MAX_POLY_SET ) && "EFAP: maximum polygons exceeded!" ); /* add two new polygons with azimuths wrapped to differing bounds */ +#ifndef IVAS_FLOAT_FIXED efap->polyData.polysetArray[m + 1].polyAzi[j] = efap_fmodf( efap->polyData.polysetArray[m].polyAzi[j], 360 ); efap->polyData.polysetArray[m + 2].polyAzi[j] = efap->polyData.polysetArray[m + 1].polyAzi[j] - 360; +#else + efap->polyData.polysetArray[m + 1].polyAzi[j] = efap_lmodl( efap->polyData.polysetArray[m].polyAzi[j], Q22_360_DEG ); + efap->polyData.polysetArray[m + 2].polyAzi[j] = efap->polyData.polysetArray[m + 1].polyAzi[j] - Q22_360_DEG; +#endif /* Copy the rest of the fields */ efap->polyData.polysetArray[m + 1].chan[j] = efap->polyData.polysetArray[m].chan[j]; @@ -1280,14 +1410,22 @@ static void efap_panning( for ( i = 0; i < numChan; ++i ) { chan[i] = polyData->polysetArray[polyIdx].chan[i]; +#ifndef IVAS_FLOAT_FIXED aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; +#else + aziPoly[i] = ( (float) polyData->polysetArray[polyIdx].polyAzi[i] ) / ( 1 << Q22 ); +#endif if ( polyData->polysetArray[polyIdx].isNaN[i] == 1 ) { aziPoly[i] = P[0]; } +#ifndef IVAS_FLOAT_FIXED elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; +#else + elePoly[i] = ( (float) polyData->polysetArray[polyIdx].polyEle[i] ) / ( 1 << Q22 ); +#endif } /* Computing the gain for the polygon */ @@ -1306,7 +1444,71 @@ static void efap_panning( return; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * efap_panning_fixed() + * + * Compute the gain without applying the downmix Matrix and the norm of the array + *-------------------------------------------------------------------------*/ + +static void efap_panning_fixed( + const Word32 azi, /* i : Value of the azimuth */ + const Word32 ele, /* i : Value of the elevation */ + const EFAP_POLYSET_DATA *polyData, /* i : Polygon data */ + float *bufferL /* o : 1D array of length numSpk that will contain the tmp values */ +) +{ + Word16 i; + Word16 polyIdx; + Word16 numChan; + Word16 chan[EFAP_MAX_CHAN_NUM]; + Word32 aziPoly[EFAP_MAX_CHAN_NUM]; + Word32 elePoly[EFAP_MAX_CHAN_NUM]; + Word32 tmpBuff[EFAP_MAX_CHAN_NUM]; + Word32 normTmpBuff; + Word32 P[2]; + + P[0] = azi; + P[1] = ele; + + /* Finding in which polygon the point is */ + polyIdx = get_poly_num_fixed( P, polyData ); + + assert( polyIdx != -1 && "EFAP: polygon not found!" ); + + /* Extracting the chan, the azimuth and the ele of the considered poly */ + numChan = polyData->polysetArray[polyIdx].numChan; + FOR( i = 0; i < numChan; ++i ) + { + chan[i] = polyData->polysetArray[polyIdx].chan[i]; + aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; + + IF( polyData->polysetArray[polyIdx].isNaN[i] == 1 ) + { + aziPoly[i] = P[0]; + } + + elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; + } + + /* Computing the gain for the polygon */ + get_poly_gains_fixed( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); + + /* Computing the norm of the tmp buffer */ + normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); + Word16 exp = 0; + normTmpBuff = ISqrt32( normTmpBuff, &exp ); + + /* Updating the buffer structure */ + FOR( i = 0; i < numChan; ++i ) + { + bufferL[chan[i]] = ( (float) Mpy_32_32( tmpBuff[i], normTmpBuff ) ) / ( 1 << ( Q31 - exp ) ); + } + + return; +} +#endif /*-------------------------------------------------------------------------* * get_poly_gains() @@ -1361,8 +1563,61 @@ static void get_poly_gains( return; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * get_poly_gains_fixed() + * + * Compute the gain for a precise polygon + *-------------------------------------------------------------------------*/ + +static void get_poly_gains_fixed( + const Word32 azi, /* i : Value of the azimuth */ + const Word32 ele, /* i : Value of the elevation */ + const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons */ + const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons */ + const Word16 numChan, /* i : Length of aziPoly & elePoly */ + Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values */ +) +{ + Word16 i, j; + Word16 idx1, idx2; + Word32 P[2]; + Word32 A[2], B[2], C[2]; + Word32 P_minus_A[2]; + + P[0] = azi; + P[1] = ele; + + /* Processing, we search for the triangle in which belong P, then we compute the gain */ + FOR( i = 1; i < numChan + 1; ++i ) + { + A[0] = aziPoly[i - 1]; + A[1] = elePoly[i - 1]; + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + FOR( j = i; j < numChan - 2 + i; ++j ) + { + idx1 = 1 + ( j % numChan ); + idx2 = 1 + ( idx1 % numChan ); + + B[0] = aziPoly[idx1 - 1]; + B[1] = elePoly[idx1 - 1]; + + C[0] = aziPoly[idx2 - 1]; + C[1] = elePoly[idx2 - 1]; + + IF( in_tri_fixed( A, B, C, P_minus_A ) ) + { + buffer[i - 1] = L_shl_sat( get_tri_gain_fixed( A, B, C, P_minus_A ), Q12 ); + break; + } + } + } + + return; +} +#endif /*-------------------------------------------------------------------------* * get_tri_gain() * @@ -1401,8 +1656,50 @@ static float get_tri_gain( } return gain; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * get_tri_gain_fixed() + * + * Compute the value of the gain for a given triangle + *-------------------------------------------------------------------------*/ + +static Word32 get_tri_gain_fixed( + const Word32 A[2], /* i : Coordinate of one apex of the triangle */ + const Word32 B[2], /* i : Coordinate of one apex of the triangle */ + const Word32 C[2], /* i : Coordinate of one apex of the triangle */ + const Word32 P_minus_A[2] /* i : Value of (P - A) */ +) +{ + Word32 N[2], tmpN[2]; + Word32 tmpSub1[2]; + Word32 tmpDot1, tmpDot2; + Word32 gain; + + /* Processing */ + tmpN[0] = B[1] - C[1]; + tmpN[1] = C[0] - B[0]; + + v_sub_fixed( B, A, tmpSub1, 2, 0 ); + tmpDot1 = dotp_fixed( tmpN, tmpSub1, 2 ); // Q13 + Word16 exp = Q13; + Word32 inv_tmpDot2 = L_shl( tmpDot1, norm_l( tmpDot1 ) ); + exp = exp - norm_l( tmpDot1 ); + Word16 inv_tmpDot1 = Inv16( inv_tmpDot2 >> Q16, &exp ); + v_multc_fixed( tmpN, L_shl( inv_tmpDot1, Q16 + exp ), N, 2 ); + + tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // Q18 + + gain = 0x00040000 - tmpDot2; + /* Set gains <= -60dB to 0 to avoid problems in SVD */ + IF( L_abs( gain ) < 1 ) + { + gain = 0; + } + return gain; // Q18 +} +#endif /*-------------------------------------------------------------------------* * add_vertex() * @@ -1536,13 +1833,38 @@ static float point_poly_distance( { float P1[3], P2[3], P3[3]; +#ifndef IVAS_FLOAT_FIXED sph2cart( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); sph2cart( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); sph2cart( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); - +#else + sph2cart( ( (float) poly.polyAzi[0] ) / ( 1 << Q22 ), ( (float) poly.polyEle[0] ) / ( 1 << Q22 ), &P1[0] ); + sph2cart( ( (float) poly.polyAzi[1] ) / ( 1 << Q22 ), ( (float) poly.polyEle[1] ) / ( 1 << Q22 ), &P2[0] ); + sph2cart( ( (float) poly.polyAzi[2] ) / ( 1 << Q22 ), ( (float) poly.polyEle[2] ) / ( 1 << Q22 ), &P3[0] ); +#endif return point_plane_distance( P1, P2, P3, X ); } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * point_poly_distance_fixed() + * + * Compute the signed distance between a point and polygon + *-------------------------------------------------------------------------*/ +static Word32 point_poly_distance_fixed( + const EFAP_POLYSET poly, /* i : The polygon which forms a plane */ + const Word32 X[3] /* i : Cartesian coordinates of the point of interest */ +) +{ + Word32 P1[3], P2[3], P3[3]; + + sph2cart_fixed( poly.polyAzi[0] << 1, poly.polyEle[0] << 1, &P1[0] ); + sph2cart_fixed( poly.polyAzi[1] << 1, poly.polyEle[1] << 1, &P2[0] ); + sph2cart_fixed( poly.polyAzi[2] << 1, poly.polyEle[2] << 1, &P3[0] ); + + return point_plane_distance_fixed( P1, P2, P3, X ); +} +#endif /*-------------------------------------------------------------------------* * point_plane_distance() * @@ -1586,8 +1908,52 @@ static float point_plane_distance( return dist; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * point_plane_distance_fixed() + * + * Compute the signed distance between a point and a given plane + *-------------------------------------------------------------------------*/ +static Word32 point_plane_distance_fixed( + const Word32 P1[3], /* i : First point of the triangle that defines the planes */ + const Word32 P2[3], /* i : Second point of the triangle */ + const Word32 P3[3], /* i : Third point of the triangle */ + const Word32 X[3] /* i : The point of interest */ +) +{ + Word32 tmpCross1[3], tmpCross2[3]; + Word32 resultCross[3]; + Word32 tmpDot1[3], tmpDot2[3]; + Word32 tmpNorm; + Word32 dist; + + /* Check if the point already matches a triangle vertex */ + IF( ( X[0] == P1[0] && X[1] == P1[1] && X[2] == P1[2] ) || + ( X[0] == P2[0] && X[1] == P2[1] && X[2] == P2[2] ) || + ( X[0] == P3[0] && X[1] == P3[1] && X[2] == P3[2] ) ) + { + return 0; + } + + /* Cross Product */ + v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); + v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); + + /* resultCross = cross(P1-P2,P1-P3) */ + efap_crossp_fixed( tmpCross1, tmpCross2, resultCross ); + /* Dot Product */ + tmpNorm = dotp_fixed( resultCross, resultCross, 3 ); + Word16 exp = 31; + tmpNorm = ISqrt32( tmpNorm << 1, &exp ); // Q29 + v_sub_fixed( X, P1, tmpDot1, 3, 1 ); + v_multc_fixed( resultCross, tmpNorm, tmpDot2, 3 ); + dist = L_shl( dotp_fixed( tmpDot1, tmpDot2, 3 ), 12 + exp ); + + return dist; +} +#endif /*-------------------------------------------------------------------------* * efap_crossp() * @@ -1606,7 +1972,26 @@ static void efap_crossp( return; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * efap_crossp_fixed() + * + * Compute the cross product between column vectors of float of size 3x1 + *-------------------------------------------------------------------------*/ + +static void efap_crossp_fixed( + const Word32 *v1, /* i : First float vector */ + const Word32 *v2, /* i : Second float vector */ + Word32 *v /* o : Output vector */ +) +{ + v[0] = L_sub( Mpy_32_32( v1[1], v2[2] ), Mpy_32_32( v1[2], v2[1] ) ); + v[1] = L_sub( Mpy_32_32( v1[2], v2[0] ), Mpy_32_32( v1[0], v2[2] ) ); + v[2] = L_sub( Mpy_32_32( v1[0], v2[1] ), Mpy_32_32( v1[1], v2[0] ) ); + return; +} +#endif /*-------------------------------------------------------------------------* * find_int_in_tri() @@ -2020,6 +2405,20 @@ static float efap_fmodf( return result >= 0 ? result : result + y; } +/*-------------------------------------------------------------------------* + * efap_lmodl() + * + * Modulus operation that will handle negative values the same way as matlab + *-------------------------------------------------------------------------*/ + +static Word32 efap_lmodl( + const Word32 x, /* i : Dividend */ + const Word32 y /* i : Divisor */ +) +{ + Word32 result = x % y; + return result >= 0 ? result : result + y; +} /*-------------------------------------------------------------------------* * get_poly_num() @@ -2082,7 +2481,69 @@ static int16_t get_poly_num( return found_poly; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * get_poly_num() + * + * Returns the index of the polygon in which the coordinate is + *-------------------------------------------------------------------------*/ +static Word16 get_poly_num_fixed( + const Word32 P[2], /* i : Azimuth and elevation of the point */ + const EFAP_POLYSET_DATA *polyData /* i : Polyset struct */ +) +{ + Word16 i; + Word16 num_poly, found_poly; + Word16 poly_tmp[EFAP_MAX_CHAN_NUM]; + Word32 poly_dist[EFAP_MAX_CHAN_NUM]; + + Word32 dist_tmp; + Word32 pos[3]; + + num_poly = 0; + + sph2cart_fixed( P[0] << 1, P[1] << 1, &pos[0] ); + + /* Filter the polygon list with a fast 2d check */ + FOR( i = 0; i < polyData->numPoly; ++i ) + { + IF( in_poly_fixed( P, polyData->polysetArray[i] ) ) + { + /* select only polygons which are visible from the point */ + dist_tmp = point_poly_distance_fixed( polyData->polysetArray[i], pos ); + IF( dist_tmp == 0 ) + { + return i; + } + ELSE IF( dist_tmp > 0 ) + { + poly_tmp[num_poly] = i; + poly_dist[num_poly] = dist_tmp; + num_poly++; + } + } + } + IF( num_poly == 0 ) + { + return -1; + } + + /* select the polygon with the smallest distance */ + found_poly = poly_tmp[0]; + dist_tmp = poly_dist[0]; + FOR( i = 1; i < num_poly; i++ ) + { + IF( poly_dist[i] < dist_tmp ) + { + found_poly = poly_tmp[i]; + dist_tmp = poly_dist[i]; + } + } + + return found_poly; +} +#endif /*-------------------------------------------------------------------------* * in_poly() @@ -2117,9 +2578,17 @@ static int16_t in_poly( } else { +#ifndef IVAS_FLOAT_FIXED A[0] = poly.polyAzi[0]; +#else + A[0] = ( (float) poly.polyAzi[0] ) / ( 1 << Q22 ); +#endif } +#ifndef IVAS_FLOAT_FIXED A[1] = poly.polyEle[0]; +#else + A[1] = ( (float) poly.polyEle[0] ) / ( 1 << Q22 ); +#endif v_sub( P, A, P_minus_A, 2 ); /* Precalculate value of (P-A) */ @@ -2131,9 +2600,17 @@ static int16_t in_poly( } else { +#ifndef IVAS_FLOAT_FIXED B[0] = poly.polyAzi[n]; +#else + B[0] = ( (float) poly.polyAzi[n] ) / ( 1 << Q22 ); +#endif } +#ifndef IVAS_FLOAT_FIXED B[1] = poly.polyEle[n]; +#else + B[1] = ( (float) poly.polyEle[n] ) / ( 1 << Q22 ); +#endif if ( poly.isNaN[n + 1] ) { @@ -2141,9 +2618,17 @@ static int16_t in_poly( } else { +#ifndef IVAS_FLOAT_FIXED C[0] = poly.polyAzi[n + 1]; +#else + C[0] = ( (float) poly.polyAzi[n + 1] ) / ( 1 << Q22 ); +#endif } +#ifndef IVAS_FLOAT_FIXED C[1] = poly.polyEle[n + 1]; +#else + C[1] = ( (float) poly.polyEle[n + 1] ) / ( 1 << Q22 ); +#endif if ( in_tri( A, B, C, P_minus_A ) ) { @@ -2153,8 +2638,77 @@ static int16_t in_poly( return 0; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * in_poly_fixed() + * + * Determines if a given point is within a polygon or not + *-------------------------------------------------------------------------*/ + +static Word16 in_poly_fixed( /* Angles are in Q22 */ + const Word32 P[2], /* i : Azimuth and elevation of the point */ + const EFAP_POLYSET poly /* i : Polyset struct */ +) +{ + Word16 n; + Word16 numVertices = poly.numChan; + Word32 A[2]; + Word32 B[2]; + Word32 C[2]; + Word32 P_minus_A[2]; + /* Safety check */ + IF( numVertices < 3 ) + { + return 0; + } + + /* See if the point is in one of the triangles available in the polygon */ + + IF( poly.isNaN[0] ) + { + A[0] = P[0]; + } + ELSE + { + A[0] = poly.polyAzi[0]; + } + A[1] = poly.polyEle[0]; + + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + + FOR( n = 1; n < numVertices - 1; ++n ) + { + IF( poly.isNaN[n] ) + { + B[0] = P[0]; + } + ELSE + { + B[0] = poly.polyAzi[n]; + } + B[1] = poly.polyEle[n]; + + IF( poly.isNaN[n + 1] ) + { + C[0] = P[0]; + } + ELSE + { + C[0] = poly.polyAzi[n + 1]; + } + C[1] = poly.polyEle[n + 1]; + + IF( in_tri_fixed( A, B, C, P_minus_A ) ) + { + return 1; + } + } + + return 0; +} +#endif /*-------------------------------------------------------------------------* * in_tri() * @@ -2212,7 +2766,67 @@ static int16_t in_tri( return 1; } } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * in_tri_fixed() + * + * Determines if a given point is within a triangle or not + *-------------------------------------------------------------------------*/ + +static Word16 in_tri_fixed( + Word32 A[2], /* i : Coordinate of one apex of the triangle */ + Word32 B[2], /* i : Coordinate of one apex of the triangle */ + Word32 C[2], /* i : Coordinate of one apex of the triangle */ + Word32 P_minus_A[2] /* i : Value of (P - A) */ +) +{ + Word32 tmpDot1[2], tmpDot2[2]; + Word32 matInv[2][2]; + Word32 invFactor; + Word32 S[2]; + Word32 thresh_int = 34; // 1e-6f in Q25 + /* + Not a Valid Triangle : Colinear edges + In the matlab implementation, the rcond() function is used + Since it's very complex to implement this in C + I'll just compute the determinant and if it's equal to 0, that means the two vectors are colinear + */ + + v_sub_fixed( B, A, tmpDot1, 2, 0 ); + v_sub_fixed( C, A, tmpDot2, 2, 0 ); + + /* Verification of the non-colinearity : Q22 * Q22 = Q13 */ + invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); + + IF( invFactor == 0 ) + { + return 0; + } + + invFactor = ( 0x7FFFFFFF / invFactor ) << Q13; + + // Q22 = Q22 * Q31 + matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); + matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); + matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); + matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); + + /* Computing S (Q13) = matInv (Q22) *(P-A) (Q22) */ + S[0] = L_add( Mpy_32_32( matInv[0][0], P_minus_A[0] ), Mpy_32_32( matInv[0][1], P_minus_A[1] ) ); + S[1] = L_add( Mpy_32_32( matInv[1][0], P_minus_A[0] ), Mpy_32_32( matInv[1][1], P_minus_A[1] ) ); + + /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ + IF( ( S[0] << Q12 ) < -thresh_int || ( S[1] << Q12 ) < -thresh_int || ( ( S[0] + S[1] ) << Q12 ) > ( ( 1 << Q25 ) + thresh_int ) ) + { + return 0; + } + ELSE + { + return 1; + } +} +#endif /*-------------------------------------------------------------------------* * sph2cart() * @@ -2231,3 +2845,43 @@ static void sph2cart( return; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------------* + * sph2cart_fixed() + * + * Converts a vertex position to cartesian coordinates + *-------------------------------------------------------------------------*/ + +static void sph2cart_fixed( + const Word32 azi, /* i : Azimuth in degrees (Q23) */ + const Word32 ele, /* i : Elevation in degrees (Q23) */ + Word32 *pos /* o : Cartesian coordinates vector (x, y, z) */ +) +{ + Word16 azi_temp, ele_temp; + IF( azi >= 0 ) + { + azi_temp = div_l( ( azi >> Q7 ), 360 ); + } + ELSE + { + azi_temp = div_l( L_negate( azi >> Q7 ), 360 ); + azi_temp = negate( azi_temp ); + } + IF( ele >= 0 ) + { + ele_temp = div_l( ( ele >> Q7 ), 360 ); + } + ELSE + { + ele_temp = div_l( L_negate( ele >> Q7 ), 360 ); + ele_temp = negate( ele_temp ); + } + + pos[0] = Mpy_32_16( getCosWord16R2( azi_temp ), 0, getCosWord16R2( ele_temp ) ); + pos[1] = Mpy_32_16( getSineWord16R2( azi_temp ), 0, getCosWord16R2( ele_temp ) ); + pos[2] = getSineWord16R2( ele_temp ) << Q16; + + return; +} +#endif \ No newline at end of file diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index f5b81b11e..457b40411 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -193,8 +193,15 @@ void efap_determine_gains( const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ const int16_t efap_mode /* i : indicates whether EFAP or EFIP is used */ ); - - +#ifdef IVAS_FLOAT_FIXED +void efap_determine_gains_fixed( + EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ + Word32 *gains, /* o : gain vector for speaker nodes for given direction */ + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ + const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ +); +#endif /*----------------------------------------------------------------------------------* * Amplitude Panning VBAP prototypes *----------------------------------------------------------------------------------*/ @@ -234,7 +241,7 @@ void ivas_sba_prototype_renderer( ivas_error ivas_sba_get_hoa_dec_matrix( const IVAS_OUTPUT_SETUP hOutSetup, /* i : target output setup */ float **hoa_dec_mtx, /* o : ALLRAD decoder matrix */ - const int16_t ambisonics_order /* i : Ambisonics order */ + const Word16 ambisonics_order /* i : Ambisonics order */ ); void ivas_dirac_dec_binaural_sba_gain( diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 4a5bb177f..caecfd54f 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -587,7 +587,7 @@ const float defaultHRIR_right_avg_power_16kHz[LR_IAC_LENGTH_NR_FC] = { /*----------------------------------------------------------------------------------* * t-design and SN3D normalization table *----------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED /* SN3D norm */ const float norm_sn3d_hoa3[16] = { @@ -621,8 +621,41 @@ const float t_design_11_elevation[70] = 7.684274e+00f, -2.357068e+01f, 2.330745e+01f, 7.065865e+01f, -9.680889e+00f, -7.080268e+01f, -2.669635e+01f, 4.801363e+01f, -7.637348e+00f, 4.466512e+01f, 2.630235e+01f, -4.445764e+01f, 9.523415e+00f, -4.762422e+01f }; +#else + /* SN3D norm (Fixed) */ +const Word32 norm_sn3d_hoa3_int[16] = //Q29 +{ + 536870912, 929887680, 929887680, 929887680, 1200479872, 1200479872, 1200479872, 1200479872, + 1200479872, 1420426880, 1420426880, 1420426880, 1420426880, 1420426880, 1420426880, 1420426880 +}; +/* Order 11 t-design (Fixed) */ +const Word32 t_design_11_azimuth_int[70] = //Q22 +{ + 557537536, -352048704, 35542952, -475385760, -433128576, -139406256, 91672512, -656574272, + -269545888, 695329600, -105708328, -406863424, 116830824, 642626944, -650375488, -49669536, + 337803904, -176396320, -130960136, 162897952, 393260832, -355492512, 32528372, -512866496, + 196298752, -103887160, 418971008, -565325056, -348496416, 252195824, 640238272, 124812712, + 171040864, 462144768, 694795264, -54495164, 334436992, -211915232, 498802976, 198056256, + 721106944, -262205152, -46622500, 553723648, -567722112, 429374688, 472862912, -747865344, + -513046848, 247784176, 636293504, 89658872, -708860416, 499041632, -486913824, 40465300, + 255405088, -654401600, -266171792, 733708736, -735214528, -444394464, -210523984, 550956672, + -571670208, 392437792, -407199840, -709501312, -185104624, 341749952 +}; +const Word32 t_design_11_elevation_int[70] = //Q22 +{ + 32264880, -99531128, 98619664, 295373760, -41510792, -296752576, -110989040, 200389120, + -32381998, 186790640, 110686800, -187308768, 40965912, -200090656, 31260270, -98944136, + 99486584, 295439520, -41252724, -295690368, -110288888, 199710944, -31529360, 185749904, + 111754128, -186937488, 41576956, -201158656, 30604994, -97914352, 99159760, 296471488, + -40187320, -295251520, -110837920, 200282496, -30654222, 185653648, 112046888, -185870448, + 40932200, -201478384, 31204158, -97864056, 98091768, 297048608, -39787016, -296034784, + -111878992, 201317536, -30965548, 186634192, 111159544, -185581968, 39923276, -200605760, + 32230182, -98862600, 97758528, 296363872, -40604592, -296967968, -111972608, 201383760, + -32033360, 187339088, 110320048, -186468864, 39944096, -199750464 +}; +#endif /*----------------------------------------------------------------------* * Reverberator ROM tables *-----------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 9e7d0b889..78da6567b 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -108,15 +108,21 @@ extern const float defaultHRIR_right_avg_power_16kHz[LR_IAC_LENGTH_NR_FC]; /*----------------------------------------------------------------------------------* * t-design and SN3D normalization table *----------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED /* SN3D norm */ extern const float norm_sn3d_hoa3[16]; /* Order 11 t-design */ extern const float t_design_11_azimuth[70]; extern const float t_design_11_elevation[70]; - - +#else +/* SN3D norm (Fixed) */ +extern const Word32 norm_sn3d_hoa3_int[16]; + +/* Order 11 t-design (Fixed) */ +extern const Word32 t_design_11_azimuth_int[70]; +extern const Word32 t_design_11_elevation_int[70]; +#endif /*----------------------------------------------------------------------* * Reverberator ROM tables *-----------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 6ad74bc45..72bf10c34 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -584,7 +584,7 @@ typedef struct EFAP_VERTEX_DATA int16_t *vtxOrder; /* Array that indicates the order of the vertex ranked by increasing azimuth */ } EFAP_VERTEX_DATA; - +#ifndef IVAS_FLOAT_FIXED typedef struct EFAP_POLYSET { int16_t chan[EFAP_MAX_CHAN_NUM]; /* An array indicating the loudspeaker index of the polygon vertices */ @@ -594,7 +594,17 @@ typedef struct EFAP_POLYSET float polyEle[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the elevation of the channels */ } EFAP_POLYSET; +#else +typedef struct EFAP_POLYSET +{ + Word16 chan[EFAP_MAX_CHAN_NUM]; /* An array indicating the loudspeaker index of the polygon vertices */ + Word16 isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ + Word16 numChan; /* An integer between 0 and EFAP_MAX_CHAN_NUM corresponding to the number of vertices of the polygon */ + Word32 polyAzi[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the azimuth of the channels */ + Word32 polyEle[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the elevation of the channels */ +} EFAP_POLYSET; +#endif typedef struct EFAP_LS_TRIANGLE { int16_t LS[3]; /* Array indicating the loudspeaker index of the triangle vertices */ -- GitLab