Coverage Report

Created: 2026-08-13 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_drc_freq_dec.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include <string.h>
21
#include <stdio.h>
22
#include <math.h>
23
#include "ixheaac_type_def.h"
24
#include "ixheaacd_sbr_common.h"
25
26
#include "ixheaacd_cnst.h"
27
#include "ixheaac_constants.h"
28
#include "ixheaac_basic_ops32.h"
29
#include "ixheaac_basic_ops16.h"
30
#include "ixheaac_basic_ops40.h"
31
#include "ixheaac_basic_ops.h"
32
#include "ixheaacd_bitbuffer.h"
33
#include "ixheaac_error_standards.h"
34
#include "ixheaac_basic_op.h"
35
#include "ixheaacd_intrinsics.h"
36
#include "ixheaacd_defines.h"
37
38
#include "ixheaacd_aac_rom.h"
39
40
#include "ixheaacd_definitions.h"
41
42
#include "ixheaacd_error_codes.h"
43
44
#include "ixheaacd_pulsedata.h"
45
46
#include "ixheaacd_pns.h"
47
#include "ixheaacd_drc_data_struct.h"
48
49
#include "ixheaacd_lt_predict.h"
50
51
#include "ixheaacd_ec_defines.h"
52
#include "ixheaacd_ec_struct_def.h"
53
#include "ixheaacd_channelinfo.h"
54
#include "ixheaacd_drc_dec.h"
55
#include "ixheaacd_sbrdecoder.h"
56
#include "ixheaacd_block.h"
57
#include "ixheaacd_channel.h"
58
59
#include "ixheaacd_sbr_payload.h"
60
#include "ixheaacd_common_rom.h"
61
#include "ixheaacd_sbrdecsettings.h"
62
#include "ixheaacd_sbr_scale.h"
63
#include "ixheaacd_env_extr_part.h"
64
#include "ixheaacd_sbr_rom.h"
65
#include "ixheaacd_stereo.h"
66
#include "ixheaacd_lpp_tran.h"
67
#include "ixheaacd_hybrid.h"
68
#include "ixheaacd_ps_dec.h"
69
70
#include "ixheaacd_env_extr.h"
71
#include "ixheaacd_adts.h"
72
#include "ixheaacd_audioobjtypes.h"
73
74
#include "ixheaacd_memory_standards.h"
75
76
#include "ixheaacd_latmdemux.h"
77
78
#include "ixheaacd_aacdec.h"
79
#include "ixheaacd_config.h"
80
#include "ixheaacd_mps_polyphase.h"
81
#include "ixheaacd_qmf_dec.h"
82
#include "ixheaacd_mps_macro_def.h"
83
#include "ixheaacd_mps_struct_def.h"
84
#include "ixheaacd_mps_res_rom.h"
85
#include "ixheaacd_mps_aac_struct.h"
86
#include "ixheaacd_mps_dec.h"
87
#include "ixheaacd_struct_def.h"
88
89
1.01G
#define DRC_SBR_ONE_Q25 (1 << 25)
90
91
static PLATFORM_INLINE WORD32 ixheaacd_mult32x16in32_shift29(WORD32 a,
92
597k
                                                             WORD32 b) {
93
597k
  WORD32 result;
94
597k
  WORD64 temp_result;
95
96
597k
  temp_result = (WORD64)a * (WORD64)b;
97
98
597k
  result = (WORD32)(temp_result >> 29);
99
100
597k
  return (result);
101
597k
}
102
103
static PLATFORM_INLINE WORD32 ixheaacd_mult32x16in32_shift25(WORD32 a,
104
244M
                                                             WORD32 b) {
105
244M
  WORD32 result;
106
244M
  WORD64 temp_result;
107
108
244M
  temp_result = (WORD64)a * (WORD64)b;
109
110
244M
  temp_result = temp_result >> 25;
111
112
244M
  if (temp_result >= MAX_32)
113
508k
    result = MAX_32;
114
243M
  else if (temp_result < MIN_32)
115
708
    result = MIN_32;
116
243M
  else
117
243M
    result = (WORD32)temp_result;
118
119
244M
  return (result);
120
244M
}
121
122
static const WORD32 ixheaacd_drc_pow_tbl_2_q29[] = {
123
    536870912,  537242967,  537615991,  537988562,  538361391,  538734479,
124
    539108539,  539482144,  539856009,  540230847,  540605230,  540979873,
125
    541354776,  541730654,  542106077,  542481760,  542858421,  543234626,
126
    543611091,  543987817,  544365523,  544742772,  545120282,  545498775,
127
    545876810,  546255106,  546633664,  547013208,  547392292,  547771638,
128
    548151972,  548531845,  548911981,  549293107,  549673770,  550054698,
129
    550435889,  550818073,  551199794,  551581779,  551964758,  552347273,
130
    552730053,  553113099,  553497142,  553880719,  554264562,  554649404,
131
    555033779,  555418421,  555803330,  556189241,  556574683,  556960393,
132
    557347107,  557733352,  558119865,  558506646,  558894433,  559281751,
133
    559669337,  560057931,  560446055,  560834448,  561223110,  561612784,
134
    562001985,  562391456,  562781941,  563171952,  563562234,  563952786,
135
    564344355,  564735450,  565126815,  565519199,  565911108,  566303288,
136
    566695739,  567089213,  567482209,  567875478,  568269771,  568663586,
137
    569057673,  569452034,  569847421,  570242329,  570637511,  571033721,
138
    571429451,  571825455,  572221734,  572619044,  573015873,  573412977,
139
    573811114,  574208769,  574606699,  575005666,  575404148,  575802907,
140
    576201942,  576602016,  577001605,  577401471,  577802378,  578202799,
141
    578603497,  579004473,  579406493,  579808025,  580209836,  580612693,
142
    581015061,  581417708,  581820634,  582224610,  582628095,  583031860,
143
    583436676,  583841002,  584245607,  584650493,  585056433,  585461881,
144
    585867610,  586274395,  586680687,  587087260,  587494116,  587902030,
145
    588309450,  588717152,  589125916,  589534184,  589942735,  590351569,
146
    590761467,  591170869,  591580554,  591991306,  592401560,  592812098,
147
    593222920,  593634813,  594046205,  594457883,  594870633,  595282882,
148
    595695417,  596108238,  596522133,  596935527,  597349207,  597763964,
149
    598178218,  598592760,  599008380,  599423497,  599838901,  600254594,
150
    600671368,  601087637,  601504195,  601921837,  602338973,  602756397,
151
    603174111,  603592913,  604011207,  604429790,  604849464,  605268628,
152
    605688083,  606107829,  606528668,  606948996,  607369615,  607791330,
153
    608212533,  608634029,  609055816,  609478701,  609901074,  610323739,
154
    610747505,  611170757,  611594302,  612018141,  612443083,  612867510,
155
    613292231,  613718058,  614143369,  614568974,  614994874,  615421883,
156
    615848375,  616275162,  616703060,  617130439,  617558114,  617986086,
157
    618415172,  618843738,  619272600,  619702579,  620132037,  620561793,
158
    620991846,  621423019,  621853669,  622284618,  622716688,  623148235,
159
    623580081,  624012226,  624445496,  624878241,  625311285,  625745457,
160
    626179103,  626613049,  627048125,  627482673,  627917523,  628352674,
161
    628788957,  629224712,  629660769,  630097961,  630534623,  630971588,
162
    631408855,  631847261,  632285135,  632723313,  633162631,  633601417,
163
    634040507,  634479901,  634920439,  635360443,  635800752,  636242207,
164
    636683127,  637124352,  637565884,  638008564,  638450708,  638893159,
165
    639336761,  639779826,  640223197,  640666876,  641111710,  641556004,
166
    642000607,  642446367,  642891586,  643337114,  643782951,  644229948,
167
    644676404,  645123169,  645571097,  646018482,  646466177,  646914182,
168
    647363354,  647811981,  648260918,  648711025,  649160586,  649610458,
169
    650060643,  650511999,  650962808,  651413929,  651866225,  652317973,
170
    652770033,  653223271,  653675959,  654128960,  654582276,  655036772,
171
    655490716,  655944976,  656400417,  656855307,  657310512,  657766033,
172
    658222739,  658678891,  659135360,  659593017,  660050119,  660507538,
173
    660965274,  661424202,  661882573,  662341262,  662801145,  663260471,
174
    663720114,  664180077,  664641237,  665101837,  665562757,  666024877,
175
    666486436,  666948316,  667410515,  667873918,  668336759,  668799921,
176
    669264288,  669728093,  670192218,  670656666,  671122323,  671587415,
177
    672052829,  672519455,  672985516,  673451899,  673918605,  674386527,
178
    674853881,  675321559,  675790455,  676258782,  676727434,  677196410,
179
    677666608,  678136235,  678606188,  679077364,  679547969,  680018900,
180
    680490157,  680962642,  681434553,  681906792,  682380260,  682853154,
181
    683326375,  683800829,  684274707,  684748914,  685223450,  685699220,
182
    686174414,  686649938,  687126699,  687602882,  688079395,  688556239,
183
    689034324,  689511829,  689989665,  690468745,  690947244,  691426075,
184
    691905238,  692385648,  692865476,  693345636,  693827046,  694307873,
185
    694789033,  695270526,  695753273,  696235434,  696717930,  697201682,
186
    697684847,  698168347,  698652182,  699137277,  699621784,  700106626,
187
    700592731,  701078246,  701564098,  702050286,  702537740,  703024604,
188
    703511804,  704000273,  704488150,  704976365,  705464918,  705954743,
189
    706443974,  706933544,  707424389,  707914639,  708405228,  708896158,
190
    709388365,  709879976,  710371927,  710865159,  711357793,  711850769,
191
    712345028,  712838688,  713332689,  713827033,  714322665,  714817695,
192
    715313068,  715809731,  716305792,  716802196,  717298945,  717796987,
193
    718294425,  718792207,  719291286,  719789759,  720288578,  720787743,
194
    721288207,  721788064,  722288268,  722789774,  723290672,  723791917,
195
    724293510,  724796408,  725298697,  725801333,  726305278,  726808613,
196
    727312296,  727816328,  728321672,  728826404,  729331485,  729837881,
197
    730343664,  730849797,  731356280,  731864082,  732371269,  732878807,
198
    733387666,  733895909,  734404503,  734913450,  735423722,  735933376,
199
    736443382,  736954717,  737465431,  737976499,  738487922,  739000676,
200
    739512808,  740025295,  740539116,  741052315,  741565869,  742079779,
201
    742595027,  743109650,  743624629,  744140950,  744656644,  745172696,
202
    745690092,  746206860,  746723986,  747241470,  747760302,  748278505,
203
    748797067,  749316978,  749836260,  750355901,  750875903,  751397258,
204
    751917981,  752439065,  752961506,  753483313,  754005482,  754528012,
205
    755051903,  755575159,  756098778,  756623759,  757148104,  757672813,
206
    758197885,  758724324,  759250125,  759776290,  760303825,  760830721,
207
    761357981,  761885607,  762414607,  762942965,  763471690,  764001790,
208
    764531249,  765061074,  765591266,  766122838,  766653766,  767185062,
209
    767717742,  768249775,  768782177,  769314948,  769849106,  770382616,
210
    770916497,  771451767,  771986388,  772521379,  773057763,  773593497,
211
    774129603,  774666080,  775203953,  775741174,  776278768,  776817761,
212
    777356101,  777894814,  778433900,  778974389,  779514224,  780054432,
213
    780596047,  781137005,  781678338,  782220046,  782763164,  783305624,
214
    783848460,  784392709,  784936298,  785480264,  786024607,  786570367,
215
    787115466,  787660942,  788207838,  788754071,  789300683,  789847673,
216
    790396087,  790943837,  791491966,  792041522,  792590412,  793139683,
217
    793689333,  794240415,  794790829,  795341624,  795893853,  796445413,
218
    796997355,  797549679,  798103441,  798656532,  799210006,  799764921,
219
    800319163,  800873790,  801428800,  801985256,  802541037,  803097203,
220
    803654817,  804211755,  804769079,  805326789,  805885951,  806444435,
221
    807003307,  807563633,  808123280,  808683314,  809243737,  809805619,
222
    810366819,  810928409,  811491460,  812053829,  812616587,  813179736,
223
    813744351,  814308281,  814872602,  815438392,  816003496,  816568991,
224
    817135959,  817702240,  818268913,  818835978,  819404520,  819972373,
225
    820540619,  821110344,  821679379,  822248808,  822818632,  823389939,
226
    823960554,  824531564,  825104060,  825675863,  826248061,  826820657,
227
    827394742,  827968132,  828541920,  829117201,  829691784,  830266766,
228
    830842146,  831419024,  831995203,  832571781,  833149860,  833727238,
229
    834305017,  834883195,  835462879,  836041861,  836621243,  837202134,
230
    837782320,  838362909,  838943900,  839526403,  840108200,  840690401,
231
    841274117,  841857125,  842440538,  843025469,  843609691,  844194318,
232
    844779350,  845365905,  845951749,  846537999,  847125775,  847712839,
233
    848300310,  848888187,  849477595,  850066289,  850655390,  851246025,
234
    851835944,  852426272,  853017009,  853609284,  854200840,  854792807,
235
    855386315,  855979103,  856572302,  857165912,  857761068,  858355502,
236
    858950348,  859546742,  860142413,  860738498,  861334995,  861933045,
237
    862530370,  863128110,  863727405,  864325973,  864924957,  865524355,
238
    866125314,  866725545,  867326191,  867928401,  868529881,  869131778,
239
    869734092,  870337974,  870941124,  871544692,  872149831,  872754236,
240
    873359061,  873964304,  874571123,  875177207,  875783710,  876391792,
241
    876999138,  877606904,  878215091,  878824861,  879433893,  880043346,
242
    880654386,  881264685,  881875407,  882486553,  883099289,  883711283,
243
    884323700,  884937712,  885550980,  886164672,  886778790,  887394507,
244
    888009477,  888624873,  889241872,  889858122,  890474799,  891093082,
245
    891710615,  892328577,  892946966,  893566965,  894186213,  894805890,
246
    895427180,  896047717,  896668684,  897290081,  897913096,  898535355,
247
    899158046,  899782358,  900405913,  901029900,  901654319,  902280365,
248
    902905651,  903531370,  904158719,  904785306,  905412328,  906039785,
249
    906668875,  907297202,  907925965,  908556365,  909186000,  909816072,
250
    910446581,  911078730,  911710114,  912341935,  912975401,  913608099,
251
    914241235,  914874810,  915510034,  916144489,  916779383,  917415930,
252
    918051705,  918687921,  919325793,  919962891,  920600432,  921238414,
253
    921878057,  922516924,  923156234,  923797209,  924437406,  925078047,
254
    925719132,  926361886,  927003861,  927646281,  928290373,  928933684,
255
    929577441,  930221644,  930867524,  931512622,  932158166,  932805391,
256
    933451831,  934098719,  934746055,  935395077,  936043312,  936691996,
257
    937342369,  937991953,  938641988,  939292472,  939944651,  940596039,
258
    941247878,  941901414,  942554158,  943207354,  943861002,  944516353,
259
    945170909,  945825918,  946482633,  947138552,  947794925,  948451753,
260
    949110291,  949768030,  950426226,  951086135,  951745243,  952404809,
261
    953064832,  953726573,  954387511,  955048908,  955712027,  956374341,
262
    957037115,  957700348,  958365307,  959029460,  959694074,  960360418,
263
    961025954,  961691951,  962358410,  963026603,  963693987,  964361833,
264
    965031418,  965700191,  966369428,  967039128,  967710571,  968381201,
265
    969052296,  969725137,  970397163,  971069654,  971743897,  972417321,
266
    973091213,  973765571,  974441685,  975116980,  975792742,  976470264,
267
    977146964,  977824133,  978501771,  979181174,  979859753,  980538802,
268
    981219619,  981899611,  982580073,  983261008,  983943715,  984625594,
269
    985307946,  985992074,  986675373,  987359145,  988043392,  988729419,
270
    989414615,  990100286,  990787742,  991474364,  992161462,  992849036,
271
    993538401,  994226929,  994915935,  995606734,  996296696,  996987136,
272
    997678055,  998370772,  999062649,  999755006,  1000449165, 1001142483,
273
    1001836281, 1002531886, 1003226647, 1003921889, 1004617614, 1005315149,
274
    1006011839, 1006709012, 1007407999, 1008106140, 1008804764, 1009503872,
275
    1010204800, 1010904879, 1011605442, 1012307830, 1013009365, 1013711388,
276
    1014413896, 1015118233, 1015821717, 1016525688, 1017231492, 1017936440,
277
    1018641876, 1019347801, 1020055565, 1020762470, 1021469865, 1022179101,
278
    1022887478, 1023596346, 1024305704, 1025016910, 1025727253, 1026438089,
279
    1027150775, 1027862597, 1028574913, 1029287722, 1030002386, 1030716185,
280
    1031430478, 1032146630, 1032861915, 1033577694, 1034293970, 1035012111,
281
    1035729381, 1036447148, 1037166784, 1037885547, 1038604809, 1039324569,
282
    1040046202, 1040766961, 1041488219, 1042211355, 1042933614, 1043656374,
283
    1044379635, 1045104778, 1045829042, 1046553809, 1047280462, 1048006234,
284
    1048732509, 1049459287, 1050187958, 1050915745, 1051644036, 1052374224,
285
    1053103526, 1053833333, 1054563647, 1055295861, 1056027188, 1056759022,
286
    1057492761, 1058225610, 1058958967, 1059694233, 1060428608, 1061163492,
287
    1061898885, 1062636193, 1063372607, 1064109531, 1064848373, 1065586320,
288
    1066324778, 1067063748, 1067804642, 1068544637, 1069285146, 1070027582,
289
    1070769118, 1071511168, 1072253732, 1072998229};
290
291
static const WORD32 ixheaacd_drc_pow_tbl_1_2_q29[] = {
292
    536870912, 536499115, 536126866, 535755584, 535384559, 535013791, 534642573,
293
    534272319, 533902321, 533531874, 533162389, 532793160, 532424187, 532054765,
294
    531686303, 531318096, 530949443, 530581746, 530214304, 529847117, 529479484,
295
    529112805, 528746380, 528379511, 528013594, 527647931, 527282520, 526916667,
296
    526551763, 526187112, 525822018, 525457872, 525093979, 524729644, 524366255,
297
    524003117, 523640231, 523276904, 522914521, 522552389, 522189817, 521828187,
298
    521466807, 521105678, 520744110, 520383480, 520023101, 519662284, 519302404,
299
    518942774, 518583392, 518223574, 517864691, 517506056, 517146985, 516788847,
300
    516430957, 516073315, 515715239, 515358092, 515001193, 514643861, 514287456,
301
    513931299, 513575388, 513219044, 512863627, 512508455, 512152852, 511798173,
302
    511443739, 511089551, 510734932, 510381235, 510027782, 509673901, 509320938,
303
    508968220, 508615746, 508262844, 507910858, 507559117, 507206948, 506855694,
304
    506504683, 506153915, 505802721, 505452439, 505102400, 504751936, 504402382,
305
    504053070, 503704000, 503354506, 503005920, 502657575, 502308807, 501960945,
306
    501613323, 501265280, 500918141, 500571242, 500224583, 499877503, 499531325,
307
    499185386, 498839027, 498493568, 498148348, 497803367, 497457967, 497113465,
308
    496769200, 496424518, 496080731, 495737182, 495393871, 495050143, 494707308,
309
    494364710, 494021696, 493679573, 493337687, 492996037, 492653973, 492312797,
310
    491971857, 491630504, 491290037, 490949805, 490609809, 490269401, 489929876,
311
    489590587, 489250886, 488912067, 488573482, 488235132, 487896371, 487558490,
312
    487220843, 486882786, 486545606, 486208661, 485871948, 485534827, 485198581,
313
    484862569, 484526148, 484190601, 483855286, 483520203, 483184714, 482850096,
314
    482515709, 482180917, 481846994, 481513302, 481179205, 480845976, 480512977,
315
    480180209, 479847037, 479514730, 479182654, 478850174, 478518557, 478187171,
316
    477856013, 477524454, 477193756, 476863286, 476532416, 476202404, 475872622,
317
    475543067, 475213113, 474884015, 474555145, 474225876, 473897462, 473569276,
318
    473241317, 472912959, 472585454, 472258176, 471930501, 471603677, 471277079,
319
    470950707, 470623939, 470298019, 469972325, 469646236, 469320994, 468995977,
320
    468671184, 468345998, 468021656, 467697539, 467373028, 467049359, 466725915,
321
    466402695, 466079083, 465756311, 465433762, 465110822, 464788720, 464466842,
322
    464145186, 463823140, 463501930, 463180943, 462859566, 462539024, 462218703,
323
    461898604, 461578117, 461258462, 460939028, 460619207, 460300216, 459981446,
324
    459662289, 459343960, 459025852, 458707965, 458389691, 458072244, 457755017,
325
    457437405, 457120617, 456804049, 456487700, 456170967, 455855057, 455539365,
326
    455223290, 454908036, 454593000, 454278182, 453962983, 453648601, 453334438,
327
    453019893, 452706164, 452392653, 452079359, 451765685, 451452825, 451140182,
328
    450827160, 450514950, 450202956, 449891179, 449579023, 449267678, 448956548,
329
    448645040, 448334342, 448023858, 447713590, 447402945, 447093107, 446783483,
330
    446473483, 446164288, 445855308, 445546541, 445237400, 444929061, 444620936,
331
    444312437, 444004738, 443697253, 443389981, 443082336, 442775490, 442468856,
332
    442161850, 441855641, 441549645, 441243276, 440937704, 440632343, 440327193,
333
    440021673, 439716946, 439412431, 439107545, 438803452, 438499569, 438195896,
334
    437891855, 437588603, 437285562, 436982152, 436679530, 436377118, 436074915,
335
    435772346, 435470562, 435168987, 434867046, 434565889, 434264941, 433964201,
336
    433663096, 433362772, 433062657, 432762178, 432462478, 432162987, 431863702,
337
    431564055, 431265185, 430966523, 430667498, 430369249, 430071207, 429773371,
338
    429475174, 429177751, 428880534, 428582956, 428286151, 427989552, 427693157,
339
    427396403, 427100420, 426804642, 426508504, 426213136, 425917972, 425623013,
340
    425327695, 425033144, 424738798, 424444094, 424150155, 423856420, 423562888,
341
    423269000, 422975875, 422682953, 422389675, 422097159, 421804845, 421512177,
342
    421220269, 420928563, 420637058, 420345200, 420054100, 419763202, 419471950,
343
    419181454, 418891160, 418601067, 418310622, 418020930, 417731440, 417441598,
344
    417152508, 416863619, 416574930, 416285891, 415997602, 415709512, 415421073,
345
    415133383, 414845892, 414558600, 414270960, 413984066, 413697371, 413410328,
346
    413124031, 412837931, 412552030, 412265782, 411980277, 411694970, 411409316,
347
    411124404, 410839690, 410555172, 410270309, 409986186, 409702260, 409417989,
348
    409134456, 408851120, 408567980, 408284496, 408001748, 407719196, 407436301,
349
    407154140, 406872175, 406590406, 406308294, 406026914, 405745730, 405464204,
350
    405183410, 404902809, 404621868, 404341657, 404061640, 403781816, 403501653,
351
    403222218, 402942976, 402663395, 402384540, 402105878, 401827409, 401548602,
352
    401270518, 400992628, 400714400, 400436895, 400159582, 399882461, 399605003,
353
    399328266, 399051721, 398774839, 398498677, 398222706, 397946927, 397670812,
354
    397395415, 397120208, 396844667, 396569841, 396295206, 396020761, 395745983,
355
    395471919, 395198044, 394923836, 394650341, 394377035, 394103919, 393830471,
356
    393557733, 393285184, 393012304, 392740132, 392468149, 392196355, 391924230,
357
    391652812, 391381582, 391110023, 390839169, 390568502, 390298023, 390027216,
358
    389757112, 389487195, 389216950, 388947407, 388678050, 388408881, 388139384,
359
    387870587, 387601977, 387333040, 387064801, 386796749, 386528371, 386260690,
360
    385993194, 385725883, 385458248, 385191308, 384924553, 384657474, 384391089,
361
    384124887, 383858871, 383592531, 383326883, 383061419, 382795633, 382530537,
362
    382265624, 382000895, 381735845, 381471483, 381207303, 380942804, 380678991,
363
    380415360, 380151913, 379888145, 379625062, 379362162, 379098943, 378836406,
364
    378574052, 378311880, 378049389, 377787580, 377525952, 377264006, 377002741,
365
    376741656, 376480753, 376219533, 375958991, 375698629, 375437951, 375177951,
366
    374918130, 374658489, 374398533, 374139252, 373880151, 373620735, 373361993,
367
    373103430, 372844553, 372586348, 372328322, 372070475, 371812315, 371554825,
368
    371297513, 371039889, 370782934, 370526157, 370269558, 370012648, 369756404,
369
    369500338, 369243961, 368988250, 368732715, 368477358, 368221691, 367966688,
370
    367711861, 367456725, 367202252, 366947954, 366693833, 366439403, 366185634,
371
    365932041, 365678140, 365424898, 365171832, 364918941, 364665743, 364413202,
372
    364160836, 363908164, 363656148, 363404306, 363152639, 362900667, 362649348,
373
    362398204, 362146755, 361895959, 361645336, 361394887, 361144134, 360894032,
374
    360644103, 360393871, 360144289, 359894880, 359645643, 359396104, 359147212,
375
    358898493, 358649472, 358401098, 358152896, 357904865, 357656534, 357408847,
376
    357161332, 356913517, 356666345, 356419344, 356172514, 355925384, 355678897,
377
    355432580, 355185964, 354939988, 354694182, 354448547, 354202614, 353957319,
378
    353712195, 353466772, 353221987, 352977371, 352732459, 352488182, 352244075,
379
    352000137, 351755902, 351512302, 351268870, 351025143, 350782049, 350539123,
380
    350296365, 350053313, 349810892, 349568639, 349326091, 349084174, 348842424,
381
    348600841, 348358965, 348117717, 347876636, 347635263, 347394516, 347153937,
382
    346913523, 346672818, 346432738, 346192824, 345952619, 345713038, 345473622,
383
    345234373, 344994832, 344755914, 344517162, 344278119, 344039698, 343801441,
384
    343563349, 343324969, 343087207, 342849610, 342611725, 342374457, 342137354,
385
    341899962, 341663188, 341426577, 341190130, 340953396, 340717277, 340481321,
386
    340245079, 340009450, 339773984, 339538682, 339303094, 339068117, 338833304,
387
    338598205, 338363717, 338129391, 337895227, 337660780, 337426941, 337193263,
388
    336959303, 336725949, 336492758, 336259728, 336026415, 335793707, 335561161,
389
    335328333, 335096109, 334864046, 334632144, 334399960, 334168380, 333936959,
390
    333705258, 333474158, 333243218, 333012438, 332781379, 332550919, 332320618,
391
    332090038, 331860057, 331630235, 331400573, 331170631, 330941287, 330712101,
392
    330482637, 330253769, 330025060, 329796509, 329567680, 329339446, 329111369,
393
    328883016, 328655256, 328427654, 328200209, 327972488, 327745358, 327518386,
394
    327291138, 327064480, 326837979, 326611635, 326385017, 326158986, 325933113,
395
    325706965, 325481404, 325255999, 325030751, 324805229, 324580293, 324355513,
396
    324130459, 323905990, 323681677, 323457091, 323233088, 323009241, 322785548,
397
    322561584, 322338202, 322114974, 321891476, 321668557, 321445793, 321223183,
398
    321000303, 320778002, 320555855, 320333438, 320111599, 319889913, 319668381,
399
    319446579, 319225354, 319004282, 318782942, 318562176, 318341563, 318121103,
400
    317900376, 317680221, 317460219, 317239950, 317020253, 316800708, 316581315,
401
    316361656, 316142567, 315923630, 315704427, 315485794, 315267311, 315048981,
402
    314830385, 314612356, 314394479, 314176337, 313958761, 313741337, 313523648,
403
    313306525, 313089551, 312872729, 312655643, 312439120, 312222748, 312006113,
404
    311790040, 311574117, 311358344, 311142309, 310926835, 310711510, 310495923,
405
    310280896, 310066019, 309851290, 309636300, 309421869, 309207586, 308993043,
406
    308779057, 308565219, 308351530, 308137581, 307924187, 307710942, 307497437,
407
    307284487, 307071684, 306859029, 306646116, 306433755, 306221542, 306009071,
408
    305797151, 305585378, 305373753, 305161870, 304950537, 304739351, 304527908,
409
    304317014, 304106267, 303895665, 303684808, 303474498, 303264334, 303053915,
410
    302844042, 302634314, 302424732, 302214895, 302005603, 301796456, 301587056,
411
    301378199, 301169486, 300960918, 300752097, 300543819, 300335684, 300127297,
412
    299919451, 299711748, 299504190, 299296380, 299089109, 298881982, 298674603,
413
    298467763, 298261067, 298054513, 297847708, 297641441, 297435316, 297228942,
414
    297023103, 296817406, 296611460, 296406049, 296200780, 295995653, 295790277,
415
    295585435, 295380734, 295175785, 294971367, 294767092, 294562958, 294358576,
416
    294154725, 293951015, 293747058, 293543630, 293340343, 293137197, 292933805,
417
    292730940, 292528217, 292325247, 292122804, 291920501, 291718338, 291515930,
418
    291314047, 291112305, 290910317, 290708854, 290507530, 290306346, 290104918,
419
    289904013, 289703246, 289502236, 289301748, 289101399, 288901189, 288700736,
420
    288500803, 288301008, 288100971, 287901454, 287702074, 287502453, 287303350,
421
    287104385, 286905557, 286706488, 286507937, 286309522, 286110867, 285912728,
422
    285714725, 285516860, 285318755, 285121164, 284923710, 284726017, 284528837,
423
    284331793, 284134885, 283937739, 283741105, 283544606, 283347870, 283151644,
424
    282955554, 282759600, 282563407, 282367725, 282172178, 281976393, 281781117,
425
    281585976, 281390970, 281195728, 281000992, 280806392, 280611555, 280417224,
426
    280223028, 280028966, 279834668, 279640875, 279447217, 279253323, 279059933,
427
    278866676, 278673554, 278480197, 278287342, 278094620, 277901665, 277709211,
428
    277516890, 277324702, 277132281, 276940359, 276748571, 276556549, 276365027,
429
    276173637, 275982379, 275790889, 275599897, 275409037, 275217945, 275027349,
430
    274836885, 274646553, 274455990, 274265922, 274075986, 273885819, 273696146,
431
    273506604, 273317193, 273127553, 272938405, 272749388, 272560141, 272371386,
432
    272182762, 271993908, 271805545, 271617313, 271429211, 271240880, 271053039,
433
    270865327, 270677388, 270489937, 270302615, 270115423, 269928004, 269741072,
434
    269554269, 269367240, 269180696, 268994281, 268807995, 268621484};
435
436
4.66k
#define MUL_DRC_BAND 4
437
438
20.5M
static PLATFORM_INLINE WORD32 ixheaacd_div_by_30(WORD32 op) {
439
20.5M
  WORD32 ret;
440
20.5M
  WORD64 temp;
441
442
20.5M
  temp = (WORD64)op * 35791394;
443
444
20.5M
  ret = (WORD32)((temp + 17895697) >> 30);
445
446
20.5M
  return ret;
447
20.5M
}
448
449
10.5M
static PLATFORM_INLINE WORD32 ixheaacd_div_by_15(WORD64 op) {
450
10.5M
  WORD32 ret;
451
10.5M
  WORD64 temp;
452
453
10.5M
  temp = (WORD64)op * 71582788;
454
455
10.5M
  ret = (WORD32)((temp + 134217728) >> 30);
456
457
10.5M
  return ret;
458
10.5M
}
459
460
static VOID ixheaacd_copy_drc_data(ixheaac_drc_data_struct *ch_data,
461
                                   ixheaac_drc_bs_data_struct *ptr_bs_data,
462
646
                                   WORD32 frame_size) {
463
646
  WORD32 band_num;
464
465
646
  ch_data->n_drc_bands = ptr_bs_data->drc_num_bands;
466
467
646
  if (ch_data->n_drc_bands == 1) {
468
188
    ch_data->n_mdct_bands[0] = frame_size;
469
188
    ch_data->drc_fac[0] = ptr_bs_data->dyn_rng_dlbl[0];
470
188
    ch_data->drc_fac_dvb[0] = ptr_bs_data->dyn_rng_dlbl_dvb[0];
471
472
458
  } else {
473
5.12k
    for (band_num = 0; band_num < ptr_bs_data->drc_num_bands; band_num++) {
474
4.66k
      ch_data->n_mdct_bands[band_num] =
475
4.66k
          (ptr_bs_data->drc_band_top[band_num] + 1) * MUL_DRC_BAND;
476
4.66k
      ch_data->drc_fac[band_num] = ptr_bs_data->dyn_rng_dlbl[band_num];
477
4.66k
      ch_data->drc_fac_dvb[band_num] = ptr_bs_data->dyn_rng_dlbl_dvb[band_num];
478
4.66k
    }
479
458
  }
480
481
646
  ch_data->drc_interp_scheme = ptr_bs_data->drc_interpolation_scheme;
482
646
}
483
484
WORD32 ixheaacd_drc_map_channels(ia_drc_dec_struct *pstr_drc_dec,
485
260k
                                 WORD32 num_channels, WORD32 frame_size) {
486
260k
  WORD32 i, element;
487
260k
  WORD32 num_drc_elements;
488
260k
  ixheaac_drc_bs_data_struct *ptr_bs_data;
489
490
260k
  num_drc_elements = pstr_drc_dec->num_drc_elements;
491
492
260k
  if (num_drc_elements == 0) {
493
259k
    return IA_NO_ERROR;
494
259k
  }
495
496
737
  if (num_drc_elements == 1) {
497
579
  }
498
499
737
  if (num_drc_elements > 1) {
500
320
    for (i = 0; i < num_channels; i++) {
501
164
      WORD32 drc_on = 0;
502
503
731
      for (element = 0; element < num_drc_elements; element++) {
504
567
        ptr_bs_data = &pstr_drc_dec->str_drc_bs_data[element];
505
567
        if (ptr_bs_data->b_channel_on[i]) drc_on++;
506
567
      }
507
508
164
      if (drc_on > 1) {
509
2
        return IA_XHEAAC_DEC_EXE_FATAL_INVALID_DRC_DATA;
510
2
      }
511
164
    }
512
158
  }
513
514
1.84k
  for (element = 0; element < num_drc_elements; element++) {
515
1.10k
    ptr_bs_data = &pstr_drc_dec->str_drc_bs_data[element];
516
1.10k
    if (ptr_bs_data->prog_ref_level_present)
517
320
      pstr_drc_dec->prog_ref_level = ptr_bs_data->prog_ref_level;
518
519
2.26k
    for (i = 0; i < num_channels; i++) {
520
1.15k
      if (!ptr_bs_data->b_channel_on[i]) continue;
521
522
646
      ixheaacd_copy_drc_data(&pstr_drc_dec->str_drc_channel_data[i],
523
646
                             &pstr_drc_dec->str_drc_bs_data[element],
524
646
                             frame_size);
525
646
    }
526
1.10k
  }
527
735
  return IA_NO_ERROR;
528
737
}
529
530
VOID ixheaacd_drc_dec_create(ia_drc_dec_struct *pstr_drc_dec,
531
12.3k
                             WORD16 drc_ref_level, WORD16 drc_def_level) {
532
12.3k
  WORD32 j, k;
533
12.3k
  WORD32 ch;
534
535
12.3k
  pstr_drc_dec->sbr_allowed = 1;
536
12.3k
  pstr_drc_dec->sbr_found = 0;
537
538
12.3k
  pstr_drc_dec->drc_element_found = 0;
539
540
12.3k
  pstr_drc_dec->max_audio_channels = MAX_BS_ELEMENT;
541
12.3k
  pstr_drc_dec->drc_ref_level = drc_ref_level;
542
12.3k
  pstr_drc_dec->drc_def_level = drc_def_level;
543
544
12.3k
  pstr_drc_dec->num_drc_elements = 0;
545
12.3k
  pstr_drc_dec->target_ref_level = 108;
546
12.3k
  pstr_drc_dec->prog_ref_level = 108;
547
12.3k
  pstr_drc_dec->cut_factor = 0;
548
12.3k
  pstr_drc_dec->boost_factor = 0;
549
12.3k
  pstr_drc_dec->drc_on = 0;
550
12.3k
  pstr_drc_dec->drc_dig_norm = 1;
551
12.3k
  pstr_drc_dec->pres_mode = -1;
552
553
12.3k
  pstr_drc_dec->length_history = 2;
554
12.3k
  if (pstr_drc_dec->sbr_allowed) pstr_drc_dec->length_history++;
555
556
136k
  for (ch = 0; ch < MAX_BS_ELEMENT; ch++) {
557
123k
    ixheaac_drc_data_struct *pstr_drc_data =
558
123k
        (ixheaac_drc_data_struct *)&pstr_drc_dec->str_drc_channel_data[ch];
559
123k
    pstr_drc_dec->drc_channel_next_index[ch] = 0;
560
123k
    pstr_drc_dec->state = 0;
561
562
8.05M
    for (j = 0; j < 64; j++) {
563
515M
      for (k = 0; k < 64; k++) {
564
507M
        pstr_drc_data->drc_factors_sbr[j][k] = DRC_SBR_ONE_Q25;
565
507M
        pstr_drc_data->drc_factors_sbr_lat[j][k] = DRC_SBR_ONE_Q25;
566
507M
      }
567
7.92M
    }
568
2.10M
    for (j = 0; j < MAX_DRC_BANDS; j++) pstr_drc_data->drc_fac[j] = 0;
569
570
123k
    pstr_drc_data->n_mdct_bands[0] = FRAME_SIZE;
571
123k
    pstr_drc_data->drc_exp = 1;
572
123k
    pstr_drc_data->short_block = 0;
573
123k
    pstr_drc_data->drc_interp_scheme = 0;
574
123k
    pstr_drc_data->n_drc_bands = 1;
575
123k
    pstr_drc_data->new_prog_ref_level = 0;
576
123k
    pstr_drc_data->new_drc_fac = 0;
577
123k
  }
578
12.3k
}
579
580
static WORD32 ixheaacd_drc_excluded_channels(ia_bit_buf_struct *it_bit_buf,
581
287
                                             WORD32 nch, UWORD8 *b_channel_on) {
582
287
  WORD32 ich, nbyte = 0;
583
287
  WORD32 num_excl_chan;
584
287
  UWORD8 exclude_mask;
585
586
287
  num_excl_chan = 7;
587
2.29k
  for (ich = 0; ich < 7; ich++) {
588
2.00k
    exclude_mask = ixheaacd_read_bits_buf(it_bit_buf, 1);
589
2.00k
    if (ich < nch) {
590
2.00k
      b_channel_on[ich] = !exclude_mask;
591
2.00k
    }
592
2.00k
  }
593
287
  nbyte++;
594
595
1.07k
  while (ixheaacd_read_bits_buf(it_bit_buf, 1)) {
596
6.27k
    for (ich = num_excl_chan; ich < num_excl_chan + 7; ich++) {
597
5.48k
      exclude_mask = ixheaacd_read_bits_buf(it_bit_buf, 1);
598
5.48k
      if (ich < nch) {
599
173
        b_channel_on[ich] = !exclude_mask;
600
173
      }
601
5.48k
    }
602
786
    nbyte++;
603
786
    num_excl_chan += 7;
604
786
  }
605
606
287
  return nbyte;
607
287
}
608
609
static WORD32 ixheaacd_drc_element_read(
610
520
    ia_bit_buf_struct *it_bit_buf, ixheaac_drc_bs_data_struct *pstr_bs_data) {
611
520
  WORD32 ich, idrc, nbyte = 1;
612
520
  WORD32 pce_tag_present, drc_bands_present;
613
520
  WORD32 excluded_chns_present;
614
520
  UWORD8 drc_band_incr;
615
520
  WORD8 max_dyn_rng_dlbl = -128;
616
617
520
  pstr_bs_data->drc_num_bands = 1;
618
619
520
  pce_tag_present = ixheaacd_read_bits_buf(it_bit_buf, 1);
620
520
  if (pce_tag_present) {
621
258
    ixheaacd_read_bits_buf(it_bit_buf, 4);/*pce_instance_tag*/
622
258
    ixheaacd_read_bits_buf(it_bit_buf, 4);/*drc_tag_reserved_bits*/
623
258
    nbyte++;
624
258
  }
625
626
4.65k
  for (ich = 0; ich < MAX_AUDIO_CHANNELS; ich++) {
627
4.13k
    pstr_bs_data->b_channel_on[ich] = 1;
628
4.13k
  }
629
630
520
  excluded_chns_present = ixheaacd_read_bits_buf(it_bit_buf, 1);
631
520
  if (excluded_chns_present) {
632
287
    nbyte += ixheaacd_drc_excluded_channels(it_bit_buf, MAX_AUDIO_CHANNELS,
633
287
                                            pstr_bs_data->b_channel_on);
634
287
  }
635
636
520
  drc_bands_present = ixheaacd_read_bits_buf(it_bit_buf, 1);
637
520
  if (drc_bands_present) {
638
275
    drc_band_incr = ixheaacd_read_bits_buf(it_bit_buf, 4);
639
275
    pstr_bs_data->drc_interpolation_scheme = ixheaacd_read_bits_buf(it_bit_buf, 4);
640
275
    nbyte++;
641
642
275
    pstr_bs_data->drc_num_bands += drc_band_incr;
643
3.07k
    for (idrc = 0; idrc < pstr_bs_data->drc_num_bands; idrc++) {
644
2.79k
      pstr_bs_data->drc_band_top[idrc] = ixheaacd_read_bits_buf(it_bit_buf, 8);
645
2.79k
      nbyte++;
646
2.79k
    }
647
275
  } else {
648
245
    pstr_bs_data->drc_band_top[0] = FRAME_SIZE / 4 - 1;
649
245
    pstr_bs_data->drc_interpolation_scheme = 0;
650
245
  }
651
652
520
  pstr_bs_data->prog_ref_level_present = ixheaacd_read_bits_buf(it_bit_buf, 1);
653
520
  if (pstr_bs_data->prog_ref_level_present) {
654
202
    pstr_bs_data->prog_ref_level = ixheaacd_read_bits_buf(it_bit_buf, 7);
655
656
202
    ixheaacd_read_bits_buf(it_bit_buf, 1);/*prog_ref_level_reserved_bits*/
657
202
    nbyte++;
658
202
  }
659
660
3.54k
  for (idrc = 0; idrc < pstr_bs_data->drc_num_bands; idrc++) {
661
3.02k
    WORD32 sign = ixheaacd_read_bits_buf(it_bit_buf, 1);
662
3.02k
    pstr_bs_data->dyn_rng_dlbl[idrc] = ixheaacd_read_bits_buf(it_bit_buf, 7);
663
3.02k
    if (sign)
664
1.85k
      pstr_bs_data->dyn_rng_dlbl[idrc] = -pstr_bs_data->dyn_rng_dlbl[idrc];
665
3.02k
    max_dyn_rng_dlbl = max(max_dyn_rng_dlbl, pstr_bs_data->dyn_rng_dlbl[idrc]);
666
667
3.02k
    nbyte++;
668
3.02k
  }
669
520
  pstr_bs_data->max_dyn_rng_dlbl = max_dyn_rng_dlbl;
670
671
520
  return nbyte;
672
520
}
673
674
static WORD32 ixheaacd_drc_read_compression(ia_bit_buf_struct *it_bit_buf,
675
                                         ia_drc_dec_struct *pstr_drc_dec,
676
75
                                         WORD32 bs_pos) {
677
75
  WORD32 bit_count = 0;
678
75
  WORD32 dmx_lvl_present, ext_present, compression_present;
679
75
  WORD32 coarse_gain_present, fine_grain_present;
680
75
  ia_bit_buf_struct local_bs = {0};
681
75
  WORD32 bytes = 0, bits = 0;
682
683
75
  memcpy(&local_bs, it_bit_buf, sizeof(ia_bit_buf_struct));
684
685
75
  if (local_bs.size < bs_pos) {
686
1
    longjmp(*(local_bs.xaac_jmp_buf),
687
1
            IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
688
1
  }
689
74
  bytes = (local_bs.size - bs_pos) >> 3;
690
74
  bits = (local_bs.size - bs_pos) % 8;
691
692
74
  local_bs.cnt_bits = bs_pos;
693
74
  local_bs.ptr_read_next = local_bs.ptr_bit_buf_base;
694
74
  local_bs.ptr_read_next += bytes;
695
74
  local_bs.bit_pos = 7 - bits;
696
697
74
  if (ixheaacd_read_bits_buf(&local_bs, 8) != DVB_ANC_DATA_SYNC_BYTE) {
698
0
    return 0;
699
0
  }
700
701
74
  if (ixheaacd_read_bits_buf(&local_bs, 2) != 3) return 0;
702
703
70
  ixheaacd_read_bits_buf(&local_bs, 2);
704
70
  pstr_drc_dec->pres_mode = ixheaacd_read_bits_buf(&local_bs, 2);
705
70
  ixheaacd_read_bits_buf(&local_bs, 1);
706
70
  if (ixheaacd_read_bits_buf(&local_bs, 1) != 0) return 0;
707
708
49
  if (ixheaacd_read_bits_buf(&local_bs, 3) != 0) return 0;
709
710
41
  dmx_lvl_present = ixheaacd_read_bits_buf(&local_bs, 1);
711
41
  ext_present = ixheaacd_read_bits_buf(&local_bs, 1);
712
41
  compression_present = ixheaacd_read_bits_buf(&local_bs, 1);
713
41
  coarse_gain_present = ixheaacd_read_bits_buf(&local_bs, 1);
714
41
  fine_grain_present = ixheaacd_read_bits_buf(&local_bs, 1);
715
41
  bit_count += 24;
716
717
41
  if (dmx_lvl_present) {
718
37
    ixheaacd_read_bits_buf(&local_bs, 8);
719
37
    bit_count += 8;
720
37
  }
721
722
41
  if (compression_present) {
723
20
    UWORD8 compression_on, compression_val;
724
725
20
    if (ixheaacd_read_bits_buf(&local_bs, 7) != 0) return 0;
726
727
17
    compression_on = (UWORD8)ixheaacd_read_bits_buf(&local_bs, 1);
728
17
    compression_val = (UWORD8)ixheaacd_read_bits_buf(&local_bs, 8);
729
17
    bit_count += 16;
730
731
17
    if (compression_on) {
732
4
      pstr_drc_dec->str_drc_bs_data[0].drc_num_bands = 1;
733
4
      pstr_drc_dec->str_drc_bs_data[0].dyn_rng_dlbl_dvb[0] = compression_val;
734
4
      pstr_drc_dec->str_drc_bs_data[0].drc_band_top[0] = (1024 >> 2) - 1;
735
4
      pstr_drc_dec->drc_ref_level = -1;
736
4
      pstr_drc_dec->str_drc_bs_data[0].drc_data_type = DVB_DRC_ANC_DATA;
737
13
    } else {
738
13
      pstr_drc_dec->str_drc_bs_data[0].drc_num_bands = 1;
739
13
      pstr_drc_dec->str_drc_bs_data[0].dyn_rng_dlbl_dvb[0] = (WORD8)0x80;
740
13
      pstr_drc_dec->str_drc_bs_data[0].drc_band_top[0] = (1024 >> 2) - 1;
741
13
      pstr_drc_dec->str_drc_bs_data[0].drc_data_type = DVB_DRC_ANC_DATA;
742
743
13
      if (compression_val != 0) return 0;
744
13
    }
745
17
  }
746
747
31
  if (coarse_gain_present) {
748
17
    ixheaacd_read_bits_buf(&local_bs, 16);
749
17
    bit_count += 16;
750
17
  }
751
31
  if (fine_grain_present) {
752
21
    ixheaacd_read_bits_buf(&local_bs, 16);
753
21
    bit_count += 16;
754
21
  }
755
756
31
  if (ext_present) {
757
17
    WORD32 ext_bits = 8;
758
759
17
    ixheaacd_read_bits_buf(&local_bs, 1);
760
17
    if (ixheaacd_read_bits_buf(&local_bs, 1)) ext_bits += 8;
761
17
    if (ixheaacd_read_bits_buf(&local_bs, 1)) ext_bits += 16;
762
17
    if (ixheaacd_read_bits_buf(&local_bs, 1)) ext_bits += 8;
763
764
17
    ixheaacd_read_bits_buf(&local_bs, ext_bits - 4);
765
17
    bit_count += ext_bits;
766
17
  }
767
768
31
  return (bit_count);
769
41
}
770
771
WORD32 ixheaacd_dec_drc_read_element(ia_drc_dec_struct *pstr_drc_dec,
772
                                     ia_drc_dec_struct *drc_dummy,
773
520
                                     ia_bit_buf_struct *it_bit_buf) {
774
520
  WORD32 bits_read = 0;
775
520
  if (pstr_drc_dec->num_drc_elements < pstr_drc_dec->max_audio_channels) {
776
520
    bits_read = ixheaacd_drc_element_read(
777
520
        it_bit_buf, &pstr_drc_dec->str_drc_bs_data[pstr_drc_dec->num_drc_elements]);
778
779
520
    if (pstr_drc_dec->dvb_anc_data_present) {
780
75
      ixheaacd_drc_read_compression(
781
75
          it_bit_buf, pstr_drc_dec, pstr_drc_dec->dvb_anc_data_pos);
782
75
    }
783
520
    pstr_drc_dec->num_drc_elements++;
784
785
520
  } else {
786
0
    ixheaac_drc_bs_data_struct drc_ele_dummy;
787
788
0
    bits_read = ixheaacd_drc_element_read(it_bit_buf, &drc_ele_dummy);
789
0
    if (pstr_drc_dec->dvb_anc_data_present) {
790
0
      ixheaacd_drc_read_compression(
791
0
          it_bit_buf, drc_dummy, pstr_drc_dec->dvb_anc_data_pos);
792
0
    }
793
0
  }
794
795
520
  pstr_drc_dec->dvb_anc_data_present = 0;
796
797
520
  return bits_read;
798
520
}
799
800
static const WORD32 ixheaacd_drc_offset[2][16] = {
801
    {0, 4, 8, 12, 16, 20, 24, 28, 0, 0, 0, 0, 0, 0, 0, 0},
802
803
    {0, 4, 8, 12, 16, 19, 22, 26, 0, 0, 0, 0, 0, 0, 0, 0}};
804
805
886k
WORD32 ixheaacd_get_div_value_24(WORD32 value) {
806
886k
  WORD32 ret;
807
886k
  WORD64 temp;
808
809
886k
  temp = (WORD64)value * 44739243;
810
811
886k
  ret = (WORD32)((temp + 22369621) >> 30);
812
813
886k
  return ret;
814
886k
}
815
816
307k
WORD32 ixheaacd_get_div_value_2400(WORD32 value) {
817
307k
  WORD32 ret;
818
307k
  WORD64 temp;
819
820
307k
  temp = (WORD64)value * 447392;
821
822
307k
  ret = (WORD32)((temp + 223696) >> 30);
823
824
307k
  return ret;
825
307k
}
826
827
978
static WORD32 ixheaacd_drc_div_120_floor(WORD32 value) {
828
978
  WORD32 ret_val;
829
978
  WORD64 temp;
830
831
978
  temp = (WORD64)value * 8947849;
832
833
978
  ret_val = (WORD32)(temp >> 30);
834
835
978
  return ret_val;
836
978
}
837
838
1.41k
static WORD32 ixheaacd_drc_floor(WORD32 bottom, WORD32 frame_size) {
839
1.41k
  WORD32 ret_val;
840
1.41k
  if (960 == frame_size) {
841
326
    ret_val = ixheaacd_drc_div_120_floor(bottom);
842
326
    ret_val *= 30;
843
326
    ret_val = ret_val >> 3;
844
1.09k
  } else {
845
1.09k
    ret_val = bottom >> 7;
846
1.09k
    ret_val = ret_val << 2;
847
1.09k
  }
848
1.41k
  return ret_val;
849
1.41k
}
850
851
1.41k
static WORD32 ixheaacd_drc_ceil(WORD32 top, WORD32 frame_size) {
852
1.41k
  WORD32 ret_val;
853
1.41k
  if (960 == frame_size) {
854
326
    top += 119;
855
326
    ret_val = ixheaacd_drc_div_120_floor(top);
856
326
    ret_val *= 30;
857
326
    ret_val = ret_val >> 3;
858
1.09k
  } else {
859
1.09k
    top += 127;
860
1.09k
    ret_val = top >> 7;
861
1.09k
    ret_val = ret_val << 2;
862
1.09k
  }
863
1.41k
  return ret_val;
864
1.41k
}
865
866
1.41k
static WORD32 ixheaacd_drc_get_bottom_qmf(WORD32 bottom, WORD32 frame_size) {
867
1.41k
  WORD32 ret_val;
868
1.41k
  if (960 == frame_size) {
869
326
    ret_val = bottom % 120;
870
326
    ret_val = ret_val << 5;
871
326
    ret_val = ixheaacd_drc_div_120_floor(ret_val);
872
1.09k
  } else {
873
1.09k
    ret_val = bottom & 0x7F;
874
1.09k
    ret_val = ret_val >> 2;
875
1.09k
  }
876
1.41k
  return ret_val;
877
1.41k
};
878
879
VOID ixheaacd_drc_apply(ia_drc_dec_struct *pstr_drc_dec,
880
                        WORD32 *ptr_spectral_coef, WORD32 win_seq, WORD32 channel,
881
289k
                        WORD32 frame_size, WORD32 esbr_flag, WORD32 audio_object_type) {
882
289k
  WORD32 drc_band, spec_pos, start_pos, end_pos;
883
289k
  WORD32 low_hi, drc_norm, drc_freq_fac;
884
289k
  WORD32 drc_fac, div_val, mod_val, ret_val, offset_value;
885
289k
  const WORD32 *table;
886
289k
  ixheaac_drc_data_struct *pstr_drc_data;
887
289k
  WORD32 num_qmf_sub_sample = (frame_size >> 5);
888
289k
  WORD32 num_qmf_sub_sample_by_2 = (frame_size >> 6);
889
289k
  WORD32 diff_ref_level;
890
891
289k
  WORD32 *drc_sbr_factors[64];
892
289k
  WORD32 qmf_start_pos, qmf_stop_pos, qmf_start, i, j;
893
289k
  WORD32 prev_frame_drc_sbr_factors[64];
894
289k
  WORD32 *ptr_drc_fac;
895
896
289k
  if ((audio_object_type != AOT_ER_AAC_ELD) && (audio_object_type != AOT_ER_AAC_LD)
897
131k
      && esbr_flag)
898
131k
  {
899
8.52M
    for (i = 0; i < SBR_QMF_SUB_SAMPLES; i++)
900
8.39M
    {
901
545M
      for (j = 0; j < SBR_QMF_SUB_BANDS; j++)
902
537M
      {
903
537M
        pstr_drc_dec->str_drc_channel_data[channel].drc_factors_sbr[i][j] =
904
537M
          pstr_drc_dec->str_drc_channel_data[channel].drc_factors_sbr_lat[i][j];
905
537M
      }
906
8.39M
    }
907
4.33M
    for (j = 0; j < 32; j++)
908
4.19M
    {
909
4.19M
      memcpy(pstr_drc_dec->str_drc_channel_data[channel].drc_factors_sbr_lat[j],
910
4.19M
             pstr_drc_dec->str_drc_channel_data[channel].drc_factors_sbr_lat[j + 32],
911
4.19M
             SBR_QMF_SUB_BANDS * sizeof(WORD32));
912
4.19M
    }
913
131k
    ptr_drc_fac =
914
131k
      &pstr_drc_dec->str_drc_channel_data[channel].drc_factors_sbr_lat[0][0];
915
158k
  } else {
916
158k
    ptr_drc_fac =
917
158k
      &pstr_drc_dec->str_drc_channel_data[channel].drc_factors_sbr[0][0];
918
158k
  }
919
18.8M
  for (i = 0; i < 64; i++) {
920
18.5M
    drc_sbr_factors[i] = ptr_drc_fac;
921
18.5M
    ptr_drc_fac += 64;
922
18.5M
  }
923
924
289k
  memcpy(prev_frame_drc_sbr_factors,
925
289k
         drc_sbr_factors[2 * num_qmf_sub_sample - 1], 64 * sizeof(WORD32));
926
927
289k
  pstr_drc_data = &pstr_drc_dec->str_drc_channel_data[channel];
928
289k
  if (!pstr_drc_dec->drc_on) return;
929
930
289k
  if (pstr_drc_dec->drc_dig_norm) {
931
289k
    diff_ref_level =
932
289k
        pstr_drc_dec->target_ref_level - pstr_drc_dec->prog_ref_level;
933
934
289k
    if (diff_ref_level < 0) {
935
1.32k
      diff_ref_level = -diff_ref_level;
936
1.32k
      table = ixheaacd_drc_pow_tbl_2_q29;
937
1.32k
      div_val = ixheaacd_get_div_value_24(diff_ref_level);
938
1.32k
      drc_norm = 1 << (25 + div_val);
939
1.32k
      mod_val = diff_ref_level - (div_val * 24);
940
1.32k
      diff_ref_level = mod_val * 1000;
941
942
288k
    } else {
943
288k
      table = ixheaacd_drc_pow_tbl_1_2_q29;
944
288k
      div_val = ixheaacd_get_div_value_24(diff_ref_level);
945
288k
      drc_norm = 1 << (25 - div_val);
946
288k
      mod_val = diff_ref_level - (div_val * 24);
947
288k
      diff_ref_level = mod_val * 1000;
948
288k
    }
949
289k
    ret_val = ixheaacd_get_div_value_24(diff_ref_level);
950
289k
    drc_norm = ixheaacd_mult32x16in32_shift29(drc_norm, table[ret_val]);
951
952
289k
  } else {
953
0
    drc_norm = (1 << 25);
954
0
  }
955
956
289k
  start_pos = 0;
957
597k
  for (drc_band = 0; drc_band < pstr_drc_data->n_drc_bands; drc_band++) {
958
307k
    if ((pstr_drc_dec->str_drc_bs_data[0].drc_data_type == DVB_DRC_ANC_DATA) &&
959
48
        (pstr_drc_dec->heavy_mode)) {
960
21
      WORD32 val_x, val_y;
961
21
      float compression_factor;
962
21
      float temp;
963
21
      val_x = ((UWORD8)pstr_drc_data->drc_fac_dvb[drc_band]) >> 4;
964
21
      val_y = ((UWORD8)pstr_drc_data->drc_fac_dvb[drc_band]) & 0x0F;
965
966
21
      compression_factor = (FLOAT32)(48.164 - 6.0206 * val_x - 0.4014 * val_y);
967
968
21
      temp = (FLOAT32)(pow(10, (float)compression_factor / 20.0));
969
21
      drc_freq_fac = (WORD32)(temp * 33554431.0f);
970
971
307k
    } else {
972
307k
      if (pstr_drc_data->drc_fac[drc_band] < 0) {
973
17.3k
        low_hi = pstr_drc_dec->cut_factor;
974
290k
      } else {
975
290k
        low_hi = pstr_drc_dec->boost_factor;
976
290k
      }
977
978
307k
      {
979
307k
        drc_fac =
980
307k
            pstr_drc_dec->str_drc_channel_data[channel].drc_fac[drc_band] *
981
307k
            low_hi;
982
307k
        if (drc_fac < 0) {
983
0
          drc_fac *= -1;
984
0
          table = ixheaacd_drc_pow_tbl_1_2_q29;
985
986
0
          div_val = ixheaacd_get_div_value_2400(drc_fac);
987
0
          drc_freq_fac = 1 << (25 - div_val);
988
989
0
          mod_val = drc_fac - (div_val * 2400);
990
0
          drc_fac = mod_val * 10;
991
307k
        } else {
992
307k
          table = ixheaacd_drc_pow_tbl_2_q29;
993
994
307k
          div_val = ixheaacd_get_div_value_2400(drc_fac);
995
307k
          drc_freq_fac = 1 << (25 + div_val);
996
997
307k
          mod_val = drc_fac - (div_val * 2400);
998
307k
          drc_fac = mod_val * 10;
999
307k
        }
1000
1001
307k
        ret_val = ixheaacd_get_div_value_24(drc_fac);
1002
1003
307k
        drc_freq_fac =
1004
307k
            ixheaacd_mult32x16in32_shift29(drc_freq_fac, table[ret_val]);
1005
1006
307k
        drc_freq_fac = ixheaacd_mult32x16in32_shift25(drc_freq_fac, drc_norm);
1007
307k
      }
1008
307k
    }
1009
1010
307k
    end_pos = pstr_drc_data->n_mdct_bands[drc_band];
1011
1012
307k
    if (!pstr_drc_dec->sbr_found) {
1013
244M
      for (spec_pos = start_pos; spec_pos < end_pos; spec_pos++) {
1014
244M
        ptr_spectral_coef[spec_pos] = ixheaacd_mult32x16in32_shift25(
1015
244M
            ptr_spectral_coef[spec_pos], drc_freq_fac);
1016
244M
      }
1017
250k
    }
1018
1019
307k
    if (pstr_drc_dec->sbr_found) {
1020
57.6k
      if (win_seq != EIGHT_SHORT_SEQUENCE) {
1021
56.2k
        if (960 == frame_size) {
1022
14.5k
          qmf_start = ixheaacd_div_by_30(start_pos);
1023
14.5k
          offset_value = 1;
1024
41.6k
        } else {
1025
41.6k
          qmf_start = start_pos >> 5;
1026
41.6k
          offset_value = 0;
1027
41.6k
        }
1028
1029
2.24M
        for (j = -num_qmf_sub_sample_by_2; j < num_qmf_sub_sample; j++) {
1030
2.19M
          WORD32 alpha_val = 0;
1031
1032
2.19M
          if (j + num_qmf_sub_sample_by_2 < num_qmf_sub_sample) {
1033
1.46M
            if (pstr_drc_data->drc_interp_scheme == 0) {
1034
1.34M
              alpha_val = (j + num_qmf_sub_sample_by_2);
1035
87.0M
              for (i = qmf_start; i < 64; i++) {
1036
85.7M
                WORD64 temp_drc = (WORD64)alpha_val * drc_freq_fac +
1037
85.7M
                                  (num_qmf_sub_sample - alpha_val) *
1038
85.7M
                                      (WORD64)prev_frame_drc_sbr_factors[i];
1039
1040
85.7M
                if (frame_size == 512) {
1041
7.61M
                  drc_sbr_factors[num_qmf_sub_sample + j][i] =
1042
7.61M
                      (WORD32)(temp_drc >> 4);
1043
78.1M
                } else if (frame_size == 480) {
1044
10.5M
                  drc_sbr_factors[num_qmf_sub_sample + j][i] =
1045
10.5M
                      ixheaacd_div_by_15(temp_drc);
1046
67.6M
                } else {
1047
67.6M
                  drc_sbr_factors[num_qmf_sub_sample + j][i] =
1048
67.6M
                      (WORD32)(temp_drc >> 5);
1049
67.6M
                }
1050
1051
85.7M
                if (960 == frame_size) {
1052
20.5M
                  drc_sbr_factors[num_qmf_sub_sample + j][i] =
1053
20.5M
                      ixheaacd_div_by_30(
1054
20.5M
                          drc_sbr_factors[num_qmf_sub_sample + j][i]);
1055
20.5M
                }
1056
85.7M
              }
1057
1058
1.34M
            } else {
1059
124k
              if (j + num_qmf_sub_sample_by_2 >=
1060
124k
                  ixheaacd_drc_offset[offset_value]
1061
124k
                                     [pstr_drc_data->drc_interp_scheme - 1]) {
1062
119k
                alpha_val = 1;
1063
6.26M
                for (i = qmf_start; i < 64; i++) {
1064
6.14M
                  drc_sbr_factors[num_qmf_sub_sample + j][i] = drc_freq_fac;
1065
6.14M
                }
1066
119k
              } else {
1067
5.03k
                alpha_val = 0;
1068
295k
                for (i = qmf_start; i < 64; i++) {
1069
290k
                  drc_sbr_factors[num_qmf_sub_sample + j][i] =
1070
290k
                      prev_frame_drc_sbr_factors[i];
1071
290k
                }
1072
5.03k
              }
1073
124k
            }
1074
1.46M
          } else {
1075
727k
            alpha_val = 1;
1076
46.4M
            for (i = qmf_start; i < 64; i++) {
1077
45.7M
              drc_sbr_factors[num_qmf_sub_sample + j][i] = drc_freq_fac;
1078
45.7M
            }
1079
727k
          }
1080
2.19M
        }
1081
56.2k
      } else {
1082
1.41k
        qmf_start_pos = ixheaacd_drc_floor(start_pos, frame_size);
1083
1084
1.41k
        qmf_stop_pos = ixheaacd_drc_ceil(end_pos, frame_size);
1085
1086
1.41k
        qmf_start = ixheaacd_drc_get_bottom_qmf(start_pos, frame_size);
1087
24.0k
        for (j = qmf_start_pos; j < qmf_stop_pos; j++) {
1088
22.5k
          if (j > qmf_start_pos && ((j & 0x03) == 0)) {
1089
4.65k
            qmf_start = 0;
1090
4.65k
          }
1091
1.44M
          for (i = qmf_start; i < 64; i++) {
1092
1.42M
            drc_sbr_factors[num_qmf_sub_sample + j][i] = drc_freq_fac;
1093
1.42M
          }
1094
22.5k
        }
1095
1.41k
      }
1096
57.6k
    }
1097
1098
307k
    start_pos = end_pos;
1099
307k
  }
1100
1101
289k
  if (win_seq != EIGHT_SHORT_SEQUENCE) {
1102
235k
    pstr_drc_data->prev_interp_scheme = pstr_drc_data->drc_interp_scheme;
1103
235k
  } else {
1104
54.2k
    pstr_drc_data->prev_interp_scheme = 8;
1105
54.2k
  }
1106
289k
}