| 1 | /* |
| 2 | * psymodel.c |
| 3 | * |
| 4 | * Copyright (c) 1999-2000 Mark Taylor |
| 5 | * Copyright (c) 2001-2002 Naoki Shibata |
| 6 | * Copyright (c) 2000-2003 Takehiro Tominaga |
| 7 | * Copyright (c) 2000-2012 Robert Hegemann |
| 8 | * Copyright (c) 2000-2005 Gabriel Bouvigne |
| 9 | * Copyright (c) 2000-2005 Alexander Leidinger |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Library General Public |
| 13 | * License as published by the Free Software Foundation; either |
| 14 | * version 2 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Library General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Library General Public |
| 22 | * License along with this library; if not, write to the |
| 23 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 24 | * Boston, MA 02111-1307, USA. |
| 25 | */ |
| 26 | |
| 27 | /* $Id: psymodel.c,v 1.216 2017/09/06 19:38:23 aleidinger Exp $ */ |
| 28 | |
| 29 | |
| 30 | /* |
| 31 | PSYCHO ACOUSTICS |
| 32 | |
| 33 | |
| 34 | This routine computes the psycho acoustics, delayed by one granule. |
| 35 | |
| 36 | Input: buffer of PCM data (1024 samples). |
| 37 | |
| 38 | This window should be centered over the 576 sample granule window. |
| 39 | The routine will compute the psycho acoustics for |
| 40 | this granule, but return the psycho acoustics computed |
| 41 | for the *previous* granule. This is because the block |
| 42 | type of the previous granule can only be determined |
| 43 | after we have computed the psycho acoustics for the following |
| 44 | granule. |
| 45 | |
| 46 | Output: maskings and energies for each scalefactor band. |
| 47 | block type, PE, and some correlation measures. |
| 48 | The PE is used by CBR modes to determine if extra bits |
| 49 | from the bit reservoir should be used. The correlation |
| 50 | measures are used to determine mid/side or regular stereo. |
| 51 | */ |
| 52 | /* |
| 53 | Notation: |
| 54 | |
| 55 | barks: a non-linear frequency scale. Mapping from frequency to |
| 56 | barks is given by freq2bark() |
| 57 | |
| 58 | scalefactor bands: The spectrum (frequencies) are broken into |
| 59 | SBMAX "scalefactor bands". Thes bands |
| 60 | are determined by the MPEG ISO spec. In |
| 61 | the noise shaping/quantization code, we allocate |
| 62 | bits among the partition bands to achieve the |
| 63 | best possible quality |
| 64 | |
| 65 | partition bands: The spectrum is also broken into about |
| 66 | 64 "partition bands". Each partition |
| 67 | band is about .34 barks wide. There are about 2-5 |
| 68 | partition bands for each scalefactor band. |
| 69 | |
| 70 | LAME computes all psycho acoustic information for each partition |
| 71 | band. Then at the end of the computations, this information |
| 72 | is mapped to scalefactor bands. The energy in each scalefactor |
| 73 | band is taken as the sum of the energy in all partition bands |
| 74 | which overlap the scalefactor band. The maskings can be computed |
| 75 | in the same way (and thus represent the average masking in that band) |
| 76 | or by taking the minmum value multiplied by the number of |
| 77 | partition bands used (which represents a minimum masking in that band). |
| 78 | */ |
| 79 | /* |
| 80 | The general outline is as follows: |
| 81 | |
| 82 | 1. compute the energy in each partition band |
| 83 | 2. compute the tonality in each partition band |
| 84 | 3. compute the strength of each partion band "masker" |
| 85 | 4. compute the masking (via the spreading function applied to each masker) |
| 86 | 5. Modifications for mid/side masking. |
| 87 | |
| 88 | Each partition band is considiered a "masker". The strength |
| 89 | of the i'th masker in band j is given by: |
| 90 | |
| 91 | s3(bark(i)-bark(j))*strength(i) |
| 92 | |
| 93 | The strength of the masker is a function of the energy and tonality. |
| 94 | The more tonal, the less masking. LAME uses a simple linear formula |
| 95 | (controlled by NMT and TMN) which says the strength is given by the |
| 96 | energy divided by a linear function of the tonality. |
| 97 | */ |
| 98 | /* |
| 99 | s3() is the "spreading function". It is given by a formula |
| 100 | determined via listening tests. |
| 101 | |
| 102 | The total masking in the j'th partition band is the sum over |
| 103 | all maskings i. It is thus given by the convolution of |
| 104 | the strength with s3(), the "spreading function." |
| 105 | |
| 106 | masking(j) = sum_over_i s3(i-j)*strength(i) = s3 o strength |
| 107 | |
| 108 | where "o" = convolution operator. s3 is given by a formula determined |
| 109 | via listening tests. It is normalized so that s3 o 1 = 1. |
| 110 | |
| 111 | Note: instead of a simple convolution, LAME also has the |
| 112 | option of using "additive masking" |
| 113 | |
| 114 | The most critical part is step 2, computing the tonality of each |
| 115 | partition band. LAME has two tonality estimators. The first |
| 116 | is based on the ISO spec, and measures how predictiable the |
| 117 | signal is over time. The more predictable, the more tonal. |
| 118 | The second measure is based on looking at the spectrum of |
| 119 | a single granule. The more peaky the spectrum, the more |
| 120 | tonal. By most indications, the latter approach is better. |
| 121 | |
| 122 | Finally, in step 5, the maskings for the mid and side |
| 123 | channel are possibly increased. Under certain circumstances, |
| 124 | noise in the mid & side channels is assumed to also |
| 125 | be masked by strong maskers in the L or R channels. |
| 126 | |
| 127 | |
| 128 | Other data computed by the psy-model: |
| 129 | |
| 130 | ms_ratio side-channel / mid-channel masking ratio (for previous granule) |
| 131 | ms_ratio_next side-channel / mid-channel masking ratio for this granule |
| 132 | |
| 133 | percep_entropy[2] L and R values (prev granule) of PE - A measure of how |
| 134 | much pre-echo is in the previous granule |
| 135 | percep_entropy_MS[2] mid and side channel values (prev granule) of percep_entropy |
| 136 | energy[4] L,R,M,S energy in each channel, prev granule |
| 137 | blocktype_d[2] block type to use for previous granule |
| 138 | */ |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | //#ifdef HAVE_CONFIG_H |
| 144 | #include "lame__config.h"cxx . . $ `<file>/external/lame/lame__config.h`/ |
| 145 | //#endif |
| 146 | |
| 147 | #include <float.h> |
| 148 | |
| 149 | #include "lame.h"cxx . . $ `<file>/external/lame/lame.h`/ |
| 150 | #include "machine.h"cxx . . $ `<file>/external/lame/machine.h`/ |
| 151 | #include "encoder.h"cxx . . $ `<file>/external/lame/encoder.h`/ |
| 152 | #include "util.h"cxx . . $ `<file>/external/lame/util.h`/ |
| 153 | #include "psymodel.h"cxx . . $ `<file>/external/lame/psymodel.h`/ |
| 154 | #include "lame_global_flags.h"cxx . . $ `<file>/external/lame/lame_global_flags.h`/ |
| 155 | #include "fft.h"cxx . . $ `<file>/external/lame/fft.h`/ |
| 156 | #include "lame-analysis.h"cxx . . $ `<file>/external/lame/lame-analysis.h`/ |
| 157 | |
| 158 | |
| 159 | #define NSFIRLENcxx . . $ `external/lame/psymodel.c:159:9`! 21 |
| 160 | |
| 161 | #ifdef M_LN10cxx . . $ `<external>/11263917310783833665/math.h:1120:10`! |
| 162 | #define LN_TO_LOG10cxx . . $ `external/lame/psymodel.c:162:10`! (M_LN10cxx . . $ `<external>/11263917310783833665/math.h:1120:10`!/10) |
| 163 | #else |
| 164 | #define LN_TO_LOG10 0.2302585093 |
| 165 | #endif |
| 166 | |
| 167 | |
| 168 | /* |
| 169 | L3psycho_anal. Compute psycho acoustics. |
| 170 | |
| 171 | Data returned to the calling program must be delayed by one |
| 172 | granule. |
| 173 | |
| 174 | This is done in two places. |
| 175 | If we do not need to know the blocktype, the copying |
| 176 | can be done here at the top of the program: we copy the data for |
| 177 | the last granule (computed during the last call) before it is |
| 178 | overwritten with the new data. It looks like this: |
| 179 | |
| 180 | 0. static psymodel_data |
| 181 | 1. calling_program_data = psymodel_data |
| 182 | 2. compute psymodel_data |
| 183 | |
| 184 | For data which needs to know the blocktype, the copying must be |
| 185 | done at the end of this loop, and the old values must be saved: |
| 186 | |
| 187 | 0. static psymodel_data_old |
| 188 | 1. compute psymodel_data |
| 189 | 2. compute possible block type of this granule |
| 190 | 3. compute final block type of previous granule based on #2. |
| 191 | 4. calling_program_data = psymodel_data_old |
| 192 | 5. psymodel_data_old = psymodel_data |
| 193 | */ |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | /* psycho_loudness_approx |
| 200 | jd - 2001 mar 12 |
| 201 | in: energy - BLKSIZE/2 elements of frequency magnitudes ^ 2 |
| 202 | gfp - uses out_samplerate, ATHtype (also needed for ATHformula) |
| 203 | returns: loudness^2 approximation, a positive value roughly tuned for a value |
| 204 | of 1.0 for signals near clipping. |
| 205 | notes: When calibrated, feeding this function binary white noise at sample |
| 206 | values +32767 or -32768 should return values that approach 3. |
| 207 | ATHformula is used to approximate an equal loudness curve. |
| 208 | future: Data indicates that the shape of the equal loudness curve varies |
| 209 | with intensity. This function might be improved by using an equal |
| 210 | loudness curve shaped for typical playback levels (instead of the |
| 211 | ATH, that is shaped for the threshold). A flexible realization might |
| 212 | simply bend the existing ATH curve to achieve the desired shape. |
| 213 | However, the potential gain may not be enough to justify an effort. |
| 214 | */ |
| 215 | static FLOATcxx . . $ FLOAT# |
| 216 | psycho_loudness_approxcxx . . $ psycho_loudness_approx(743b053a586f501d).(FLOATcxx . . $ FLOAT# const *energy, FLOATcxx . . $ FLOAT# const *eql_w) |
| 217 | { |
| 218 | int i; |
| 219 | FLOATcxx . . $ FLOAT# loudness_power; |
| 220 | |
| 221 | loudness_power = 0.0; |
| 222 | /* apply weights to power in freq. bands */ |
| 223 | for (i = 0; i < BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`! / 2; ++i) |
| 224 | loudness_power += energy[i] * eql_w[i]; |
| 225 | loudness_power *= VO_SCALEcxx . . $ `external/lame/psymodel.h:52:9`!; |
| 226 | |
| 227 | return loudness_power; |
| 228 | } |
| 229 | |
| 230 | /* mask_add optimization */ |
| 231 | /* init the limit values used to avoid computing log in mask_add when it is not necessary */ |
| 232 | |
| 233 | /* For example, with i = 10*log10(m2/m1)/10*16 (= log10(m2/m1)*16) |
| 234 | * |
| 235 | * abs(i)>8 is equivalent (as i is an integer) to |
| 236 | * abs(i)>=9 |
| 237 | * i>=9 || i<=-9 |
| 238 | * equivalent to (as i is the biggest integer smaller than log10(m2/m1)*16 |
| 239 | * or the smallest integer bigger than log10(m2/m1)*16 depending on the sign of log10(m2/m1)*16) |
| 240 | * log10(m2/m1)>=9/16 || log10(m2/m1)<=-9/16 |
| 241 | * exp10 is strictly increasing thus this is equivalent to |
| 242 | * m2/m1 >= 10^(9/16) || m2/m1<=10^(-9/16) which are comparisons to constants |
| 243 | */ |
| 244 | |
| 245 | |
| 246 | #define I1LIMITcxx . . $ `external/lame/psymodel.c:246:9`! 8 /* as in if(i>8) */ |
| 247 | #define I2LIMITcxx . . $ `external/lame/psymodel.c:247:9`! 23 /* as in if(i>24) -> changed 23 */ |
| 248 | #define MLIMITcxx . . $ `external/lame/psymodel.c:248:9`! 15 /* as in if(m<15) */ |
| 249 | |
| 250 | /* pow(10, (I1LIMIT + 1) / 16.0); */ |
| 251 | static const FLOATcxx . . $ FLOAT# ma_max_i1cxx . . $ ma_max_i1. = 3.6517412725483771; |
| 252 | /* pow(10, (I2LIMIT + 1) / 16.0); */ |
| 253 | static const FLOATcxx . . $ FLOAT# ma_max_i2cxx . . $ ma_max_i2. = 31.622776601683793; |
| 254 | /* pow(10, (MLIMIT) / 10.0); */ |
| 255 | static const FLOATcxx . . $ FLOAT# ma_max_mcxx . . $ ma_max_m. = 31.622776601683793; |
| 256 | |
| 257 | /*This is the masking table: |
| 258 | According to tonality, values are going from 0dB (TMN) |
| 259 | to 9.3dB (NMT). |
| 260 | After additive masking computation, 8dB are added, so |
| 261 | final values are going from 8dB to 17.3dB |
| 262 | */ |
| 263 | static const FLOATcxx . . $ FLOAT# tabcxx . . $ tab.[] = { |
| 264 | 1.0 /*pow(10, -0) */ , |
| 265 | 0.79433 /*pow(10, -0.1) */ , |
| 266 | 0.63096 /*pow(10, -0.2) */ , |
| 267 | 0.63096 /*pow(10, -0.2) */ , |
| 268 | 0.63096 /*pow(10, -0.2) */ , |
| 269 | 0.63096 /*pow(10, -0.2) */ , |
| 270 | 0.63096 /*pow(10, -0.2) */ , |
| 271 | 0.25119 /*pow(10, -0.6) */ , |
| 272 | 0.11749 /*pow(10, -0.93) */ |
| 273 | }; |
| 274 | |
| 275 | static const int tab_mask_add_deltacxx . . $ tab_mask_add_delta.[] = { 2, 2, 2, 1, 1, 1, 0, 0, -1 }; |
| 276 | #define STATIC_ASSERT_EQUAL_DIMENSIONcxx . . $ `external/lame/psymodel.c:276:9`!(A,B) enum{static_assert_##A=1/((dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(A) == dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(B))?1:0)} |
| 277 | |
| 278 | inlinecxx . . $ `external/lame/machine.h:107:10`! static int |
| 279 | mask_add_deltacxx . . $ mask_add_delta(7864480464b09eea).(int i) |
| 280 | { |
| 281 | STATIC_ASSERT_EQUAL_DIMENSIONcxx . . $ `external/lame/psymodel.c:276:9`!(tab_mask_add_delta,tab); |
| 282 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(i < (int)dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(tab)); |
| 283 | return tab_mask_add_deltacxx . . $ tab_mask_add_delta.[i]; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | static void |
| 288 | init_mask_add_max_valuescxx . . $ init_mask_add_max_values(49f6e7a06ebc5aa8).(void) |
| 289 | { |
| 290 | #ifndef NDEBUG |
| 291 | FLOATcxx . . $ FLOAT# const _ma_max_i1 = pow(10, (I1LIMITcxx . . $ `external/lame/psymodel.c:246:9`! + 1) / 16.0); |
| 292 | FLOATcxx . . $ FLOAT# const _ma_max_i2 = pow(10, (I2LIMITcxx . . $ `external/lame/psymodel.c:247:9`! + 1) / 16.0); |
| 293 | FLOATcxx . . $ FLOAT# const _ma_max_m = pow(10, (MLIMITcxx . . $ `external/lame/psymodel.c:248:9`!) / 10.0); |
| 294 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(fabs(ma_max_i1 - _ma_max_i1) <= FLT_EPSILONcxx . . $ `<external>/18143172452841944454/float.h:113:9`!); |
| 295 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(fabs(ma_max_i2 - _ma_max_i2) <= FLT_EPSILONcxx . . $ `<external>/18143172452841944454/float.h:113:9`!); |
| 296 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(fabs(ma_max_m - _ma_max_m ) <= FLT_EPSILONcxx . . $ `<external>/18143172452841944454/float.h:113:9`!); |
| 297 | #endif |
| 298 | } |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | /* addition of simultaneous masking Naoki Shibata 2000/7 */ |
| 304 | inlinecxx . . $ `external/lame/machine.h:107:10`! static FLOATcxx . . $ FLOAT# |
| 305 | vbrpsy_mask_addcxx . . $ vbrpsy_mask_add(68b9a276dda9e283).(FLOATcxx . . $ FLOAT# m1, FLOATcxx . . $ FLOAT# m2, int b, int delta) |
| 306 | { |
| 307 | static const FLOATcxx . . $ FLOAT# table2[] = { |
| 308 | 1.33352 * 1.33352, 1.35879 * 1.35879, 1.38454 * 1.38454, 1.39497 * 1.39497, |
| 309 | 1.40548 * 1.40548, 1.3537 * 1.3537, 1.30382 * 1.30382, 1.22321 * 1.22321, |
| 310 | 1.14758 * 1.14758, |
| 311 | 1 |
| 312 | }; |
| 313 | |
| 314 | FLOATcxx . . $ FLOAT# ratio; |
| 315 | |
| 316 | if (m1 < 0) { |
| 317 | m1 = 0; |
| 318 | } |
| 319 | if (m2 < 0) { |
| 320 | m2 = 0; |
| 321 | } |
| 322 | if (m1 <= 0) { |
| 323 | return m2; |
| 324 | } |
| 325 | if (m2 <= 0) { |
| 326 | return m1; |
| 327 | } |
| 328 | if (m2 > m1) { |
| 329 | ratio = m2 / m1; |
| 330 | } |
| 331 | else { |
| 332 | ratio = m1 / m2; |
| 333 | } |
| 334 | if (abscxx . . $ abs(7864480464b09eea).(b) <= delta) { /* approximately, 1 bark = 3 partitions */ |
| 335 | /* originally 'if(i > 8)' */ |
| 336 | if (ratio >= ma_max_i1cxx . . $ ma_max_i1.) { |
| 337 | return m1 + m2; |
| 338 | } |
| 339 | else { |
| 340 | int i = (int) (FAST_LOG10_Xcxx . . $ `external/lame/util.h:98:17`!(ratio, 16.0f)); |
| 341 | return (m1 + m2) * table2[i]; |
| 342 | } |
| 343 | } |
| 344 | if (ratio < ma_max_i2cxx . . $ ma_max_i2.) { |
| 345 | return m1 + m2; |
| 346 | } |
| 347 | if (m1 < m2) { |
| 348 | m1 = m2; |
| 349 | } |
| 350 | return m1; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | /* short block threshold calculation (part 2) |
| 355 | |
| 356 | partition band bo_s[sfb] is at the transition from scalefactor |
| 357 | band sfb to the next one sfb+1; enn and thmm have to be split |
| 358 | between them |
| 359 | */ |
| 360 | static void |
| 361 | convert_partition2scalefaccxx . . $ convert_partition2scalefac(45fcd573c82dddf9).(PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gd, FLOATcxx . . $ FLOAT# const *eb, FLOATcxx . . $ FLOAT# const *thr, |
| 362 | FLOATcxx . . $ FLOAT# enn_out[], FLOATcxx . . $ FLOAT# thm_out[]) |
| 363 | { |
| 364 | FLOATcxx . . $ FLOAT# enn, thmm; |
| 365 | int sb, b, n = gd->n_sbcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#n_sb.; |
| 366 | enn = thmm = 0.0f; |
| 367 | for (sb = b = 0; sb < n; ++b, ++sb) { |
| 368 | int const bo_sb = gd->bocxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#bo.[sb]; |
| 369 | int const npart = gd->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; |
| 370 | int const b_lim = bo_sb < npart ? bo_sb : npart; |
| 371 | while (b < b_lim) { |
| 372 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(eb[b] >= 0); /* iff failed, it may indicate some index error elsewhere */ |
| 373 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(thr[b] >= 0); |
| 374 | enn += eb[b]; |
| 375 | thmm += thr[b]; |
| 376 | b++; |
| 377 | } |
| 378 | if (b >= npart) { |
| 379 | enn_out[sb] = enn; |
| 380 | thm_out[sb] = thmm; |
| 381 | ++sb; |
| 382 | break; |
| 383 | } |
| 384 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(eb[b] >= 0); /* iff failed, it may indicate some index error elsewhere */ |
| 385 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(thr[b] >= 0); |
| 386 | { |
| 387 | /* at transition sfb -> sfb+1 */ |
| 388 | FLOATcxx . . $ FLOAT# const w_curr = gd->bo_weightcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#bo_weight.[sb]; |
| 389 | FLOATcxx . . $ FLOAT# const w_next = 1.0f - w_curr; |
| 390 | enn += w_curr * eb[b]; |
| 391 | thmm += w_curr * thr[b]; |
| 392 | enn_out[sb] = enn; |
| 393 | thm_out[sb] = thmm; |
| 394 | enn = w_next * eb[b]; |
| 395 | thmm = w_next * thr[b]; |
| 396 | } |
| 397 | } |
| 398 | /* zero initialize the rest */ |
| 399 | for (; sb < n; ++sb) { |
| 400 | enn_out[sb] = 0; |
| 401 | thm_out[sb] = 0; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | static void |
| 406 | convert_partition2scalefac_scxx . . $ convert_partition2scalefac_s(d9c6c06ac48ef3c3).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, FLOATcxx . . $ FLOAT# const *eb, FLOATcxx . . $ FLOAT# const *thr, int chn, |
| 407 | int sblock) |
| 408 | { |
| 409 | PsyStateVar_tcxx . . $ PsyStateVar_t# *const psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 410 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gds = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s.; |
| 411 | FLOATcxx . . $ FLOAT# enn[SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!], thm[SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!]; |
| 412 | int sb; |
| 413 | convert_partition2scalefaccxx . . $ convert_partition2scalefac(45fcd573c82dddf9).(gds, eb, thr, enn, thm); |
| 414 | for (sb = 0; sb < SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; ++sb) { |
| 415 | psv->encxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#en.[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][sblock] = enn[sb]; |
| 416 | psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][sblock] = thm[sb]; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /* longblock threshold calculation (part 2) */ |
| 421 | static void |
| 422 | convert_partition2scalefac_lcxx . . $ convert_partition2scalefac_l(f119d38c4c2d963d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, FLOATcxx . . $ FLOAT# const *eb, FLOATcxx . . $ FLOAT# const *thr, int chn) |
| 423 | { |
| 424 | PsyStateVar_tcxx . . $ PsyStateVar_t# *const psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 425 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gdl = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l.; |
| 426 | FLOATcxx . . $ FLOAT# *enn = &psv->encxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#en.[chn].lcxx . . $ $anonymous_type_fdda207d22d8fb07_1#l.[0]; |
| 427 | FLOATcxx . . $ FLOAT# *thm = &psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[chn].lcxx . . $ $anonymous_type_fdda207d22d8fb07_1#l.[0]; |
| 428 | convert_partition2scalefaccxx . . $ convert_partition2scalefac(45fcd573c82dddf9).(gdl, eb, thr, enn, thm); |
| 429 | } |
| 430 | |
| 431 | static void |
| 432 | convert_partition2scalefac_l_to_scxx . . $ convert_partition2scalefac_l_to_s(f119d38c4c2d963d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, FLOATcxx . . $ FLOAT# const *eb, FLOATcxx . . $ FLOAT# const *thr, |
| 433 | int chn) |
| 434 | { |
| 435 | PsyStateVar_tcxx . . $ PsyStateVar_t# *const psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 436 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gds = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->l_to_scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l_to_s.; |
| 437 | FLOATcxx . . $ FLOAT# enn[SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!], thm[SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!]; |
| 438 | int sb, sblock; |
| 439 | convert_partition2scalefaccxx . . $ convert_partition2scalefac(45fcd573c82dddf9).(gds, eb, thr, enn, thm); |
| 440 | for (sb = 0; sb < SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; ++sb) { |
| 441 | FLOATcxx . . $ FLOAT# const scale = 1. / 64.f; |
| 442 | FLOATcxx . . $ FLOAT# const tmp_enn = enn[sb]; |
| 443 | FLOATcxx . . $ FLOAT# const tmp_thm = thm[sb] * scale; |
| 444 | for (sblock = 0; sblock < 3; ++sblock) { |
| 445 | psv->encxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#en.[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][sblock] = tmp_enn; |
| 446 | psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][sblock] = tmp_thm; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | |
| 452 | |
| 453 | static inlinecxx . . $ `external/lame/machine.h:107:10`! FLOATcxx . . $ FLOAT# |
| 454 | NS_INTERPcxx . . $ NS_INTERP(7f54a427cb2e2c3).(FLOATcxx . . $ FLOAT# x, FLOATcxx . . $ FLOAT# y, FLOATcxx . . $ FLOAT# r) |
| 455 | { |
| 456 | /* was pow((x),(r))*pow((y),1-(r)) */ |
| 457 | if (r >= 1.0f) |
| 458 | return x; /* 99.7% of the time */ |
| 459 | if (r <= 0.0f) |
| 460 | return y; |
| 461 | if (y > 0.0f) |
| 462 | return powf(x / y, r) * y; /* rest of the time */ |
| 463 | return 0.0f; /* never happens */ |
| 464 | } |
| 465 | |
| 466 | |
| 467 | |
| 468 | static FLOATcxx . . $ FLOAT# |
| 469 | pecalc_scxx . . $ pecalc_s(5ad1b010e5cdab1).(III_psy_ratiocxx . . $ III_psy_ratio# const *mr, FLOATcxx . . $ FLOAT# masking_lower) |
| 470 | { |
| 471 | FLOATcxx . . $ FLOAT# pe_s; |
| 472 | static const FLOATcxx . . $ FLOAT# regcoef_s[] = { |
| 473 | 11.8, /* these values are tuned only for 44.1kHz... */ |
| 474 | 13.6, |
| 475 | 17.2, |
| 476 | 32, |
| 477 | 46.5, |
| 478 | 51.3, |
| 479 | 57.5, |
| 480 | 67.1, |
| 481 | 71.5, |
| 482 | 84.6, |
| 483 | 97.6, |
| 484 | 130, |
| 485 | /* 255.8 */ |
| 486 | }; |
| 487 | unsigned int sb, sblock; |
| 488 | |
| 489 | pe_s = 1236.28f / 4; |
| 490 | for (sb = 0; sb < SBMAX_scxx . . $ `external/lame/encoder.h:104:9`! - 1; sb++) { |
| 491 | for (sblock = 0; sblock < 3; sblock++) { |
| 492 | FLOATcxx . . $ FLOAT# const thm = mr->thmcxx . . $ $anonymous_type_fdda207d22d8fb07_2#thm..scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][sblock]; |
| 493 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sb < dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(regcoef_s)); |
| 494 | if (thm > 0.0f) { |
| 495 | FLOATcxx . . $ FLOAT# const x = thm * masking_lower; |
| 496 | FLOATcxx . . $ FLOAT# const en = mr->encxx . . $ $anonymous_type_fdda207d22d8fb07_2#en..scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][sblock]; |
| 497 | if (en > x) { |
| 498 | if (en > x * 1e10f) { |
| 499 | pe_s += regcoef_s[sb] * (10.0f * LOG10cxx . . $ `external/lame/util.h:70:17`!); |
| 500 | } |
| 501 | else { |
| 502 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(x > 0); |
| 503 | pe_s += regcoef_s[sb] * FAST_LOG10cxx . . $ `external/lame/util.h:96:17`!(en / x); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | return pe_s; |
| 511 | } |
| 512 | |
| 513 | static FLOATcxx . . $ FLOAT# |
| 514 | pecalc_lcxx . . $ pecalc_l(5ad1b010e5cdab1).(III_psy_ratiocxx . . $ III_psy_ratio# const *mr, FLOATcxx . . $ FLOAT# masking_lower) |
| 515 | { |
| 516 | FLOATcxx . . $ FLOAT# pe_l; |
| 517 | static const FLOATcxx . . $ FLOAT# regcoef_l[] = { |
| 518 | 6.8, /* these values are tuned only for 44.1kHz... */ |
| 519 | 5.8, |
| 520 | 5.8, |
| 521 | 6.4, |
| 522 | 6.5, |
| 523 | 9.9, |
| 524 | 12.1, |
| 525 | 14.4, |
| 526 | 15, |
| 527 | 18.9, |
| 528 | 21.6, |
| 529 | 26.9, |
| 530 | 34.2, |
| 531 | 40.2, |
| 532 | 46.8, |
| 533 | 56.5, |
| 534 | 60.7, |
| 535 | 73.9, |
| 536 | 85.7, |
| 537 | 93.4, |
| 538 | 126.1, |
| 539 | /* 241.3 */ |
| 540 | }; |
| 541 | unsigned int sb; |
| 542 | |
| 543 | pe_l = 1124.23f / 4; |
| 544 | for (sb = 0; sb < SBMAX_lcxx . . $ `external/lame/encoder.h:103:9`! - 1; sb++) { |
| 545 | FLOATcxx . . $ FLOAT# const thm = mr->thmcxx . . $ $anonymous_type_fdda207d22d8fb07_2#thm..lcxx . . $ $anonymous_type_fdda207d22d8fb07_1#l.[sb]; |
| 546 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sb < dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(regcoef_l)); |
| 547 | if (thm > 0.0f) { |
| 548 | FLOATcxx . . $ FLOAT# const x = thm * masking_lower; |
| 549 | FLOATcxx . . $ FLOAT# const en = mr->encxx . . $ $anonymous_type_fdda207d22d8fb07_2#en..lcxx . . $ $anonymous_type_fdda207d22d8fb07_1#l.[sb]; |
| 550 | if (en > x) { |
| 551 | if (en > x * 1e10f) { |
| 552 | pe_l += regcoef_l[sb] * (10.0f * LOG10cxx . . $ `external/lame/util.h:70:17`!); |
| 553 | } |
| 554 | else { |
| 555 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(x > 0); |
| 556 | pe_l += regcoef_l[sb] * FAST_LOG10cxx . . $ `external/lame/util.h:96:17`!(en / x); |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | return pe_l; |
| 563 | } |
| 564 | |
| 565 | |
| 566 | static void |
| 567 | calc_energycxx . . $ calc_energy(d94a6a32123da09d).(PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *l, FLOATcxx . . $ FLOAT# const *fftenergy, FLOATcxx . . $ FLOAT# * eb, FLOATcxx . . $ FLOAT# * max, FLOATcxx . . $ FLOAT# * avg) |
| 568 | { |
| 569 | int b, j; |
| 570 | |
| 571 | for (b = j = 0; b < l->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; ++b) { |
| 572 | FLOATcxx . . $ FLOAT# ebb = 0, m = 0; |
| 573 | int i; |
| 574 | for (i = 0; i < l->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b]; ++i, ++j) { |
| 575 | FLOATcxx . . $ FLOAT# const el = fftenergy[j]; |
| 576 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(el >= 0); |
| 577 | ebb += el; |
| 578 | if (m < el) |
| 579 | m = el; |
| 580 | } |
| 581 | eb[b] = ebb; |
| 582 | max[b] = m; |
| 583 | avg[b] = ebb * l->rnumlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#rnumlines.[b]; |
| 584 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(l->rnumlines[b] >= 0); |
| 585 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(ebb >= 0); |
| 586 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(eb[b] >= 0); |
| 587 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(max[b] >= 0); |
| 588 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(avg[b] >= 0); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | |
| 593 | static void |
| 594 | calc_mask_index_lcxx . . $ calc_mask_index_l(54c422903ca43f93).(lame_internal_flagscxx . . $ lame_internal_flags# const *gfc, FLOATcxx . . $ FLOAT# const *max, |
| 595 | FLOATcxx . . $ FLOAT# const *avg, unsigned char *mask_idx) |
| 596 | { |
| 597 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gdl = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l.; |
| 598 | FLOATcxx . . $ FLOAT# m, a; |
| 599 | int b, k; |
| 600 | int const last_tab_entry = sizeof(tabcxx . . $ tab.) / sizeof(tabcxx . . $ tab.[0]) - 1; |
| 601 | b = 0; |
| 602 | a = avg[b] + avg[b + 1]; |
| 603 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(a >= 0); |
| 604 | if (a > 0.0f) { |
| 605 | m = max[b]; |
| 606 | if (m < max[b + 1]) |
| 607 | m = max[b + 1]; |
| 608 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((gdl->numlines[b] + gdl->numlines[b + 1] - 1) > 0); |
| 609 | a = 20.0f * (m * 2.0f - a) |
| 610 | / (a * (gdl->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b] + gdl->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b + 1] - 1)); |
| 611 | k = (int) a; |
| 612 | if (k > last_tab_entry) |
| 613 | k = last_tab_entry; |
| 614 | mask_idx[b] = k; |
| 615 | } |
| 616 | else { |
| 617 | mask_idx[b] = 0; |
| 618 | } |
| 619 | |
| 620 | for (b = 1; b < gdl->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart. - 1; b++) { |
| 621 | a = avg[b - 1] + avg[b] + avg[b + 1]; |
| 622 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(a >= 0); |
| 623 | if (a > 0.0f) { |
| 624 | m = max[b - 1]; |
| 625 | if (m < max[b]) |
| 626 | m = max[b]; |
| 627 | if (m < max[b + 1]) |
| 628 | m = max[b + 1]; |
| 629 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((gdl->numlines[b - 1] + gdl->numlines[b] + gdl->numlines[b + 1] - 1) > 0); |
| 630 | a = 20.0f * (m * 3.0f - a) |
| 631 | / (a * (gdl->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b - 1] + gdl->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b] + gdl->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b + 1] - 1)); |
| 632 | k = (int) a; |
| 633 | if (k > last_tab_entry) |
| 634 | k = last_tab_entry; |
| 635 | mask_idx[b] = k; |
| 636 | } |
| 637 | else { |
| 638 | mask_idx[b] = 0; |
| 639 | } |
| 640 | } |
| 641 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(b > 0); |
| 642 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(b == gdl->npart - 1); |
| 643 | |
| 644 | a = avg[b - 1] + avg[b]; |
| 645 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(a >= 0); |
| 646 | if (a > 0.0f) { |
| 647 | m = max[b - 1]; |
| 648 | if (m < max[b]) |
| 649 | m = max[b]; |
| 650 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((gdl->numlines[b - 1] + gdl->numlines[b] - 1) > 0); |
| 651 | a = 20.0f * (m * 2.0f - a) |
| 652 | / (a * (gdl->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b - 1] + gdl->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b] - 1)); |
| 653 | k = (int) a; |
| 654 | if (k > last_tab_entry) |
| 655 | k = last_tab_entry; |
| 656 | mask_idx[b] = k; |
| 657 | } |
| 658 | else { |
| 659 | mask_idx[b] = 0; |
| 660 | } |
| 661 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(b == (gdl->npart - 1)); |
| 662 | } |
| 663 | |
| 664 | |
| 665 | static void |
| 666 | vbrpsy_compute_fft_lcxx . . $ vbrpsy_compute_fft_l(6756ddc9682fbc26).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, const sample_tcxx . . $ sample_t# * const buffer[2], int chn, |
| 667 | int gr_out, FLOATcxx . . $ FLOAT# fftenergy[HBLKSIZEcxx . . $ `external/lame/encoder.h:112:9`!], FLOATcxx . . $ FLOAT#(*wsamp_l)[BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`!]) |
| 668 | { |
| 669 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 670 | PsyStateVar_tcxx . . $ PsyStateVar_t# *psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 671 | plotting_datacxx . . $ plotting_data# *plt = cfg->analysiscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#analysis. ? gfc->pinfocxx . . $ lame_internal_flags#pinfo. : 0; |
| 672 | int j; |
| 673 | |
| 674 | if (chn < 2) { |
| 675 | fft_longcxx . . $ fft_long(4693ac94a2571fd).(gfc, *wsamp_l, chn, buffer); |
| 676 | } |
| 677 | else if (chn == 2) { |
| 678 | FLOATcxx . . $ FLOAT# const sqrt2_half = SQRT2cxx . . $ `external/lame/util.h:77:17`! * 0.5f; |
| 679 | /* FFT data for mid and side channel is derived from L & R */ |
| 680 | for (j = BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`! - 1; j >= 0; --j) { |
| 681 | FLOATcxx . . $ FLOAT# const l = wsamp_l[0][j]; |
| 682 | FLOATcxx . . $ FLOAT# const r = wsamp_l[1][j]; |
| 683 | wsamp_l[0][j] = (l + r) * sqrt2_half; |
| 684 | wsamp_l[1][j] = (l - r) * sqrt2_half; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | /********************************************************************* |
| 689 | * compute energies |
| 690 | *********************************************************************/ |
| 691 | fftenergy[0] = wsamp_l[0][0]; |
| 692 | fftenergy[0] *= fftenergy[0]; |
| 693 | |
| 694 | for (j = BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`! / 2 - 1; j >= 0; --j) { |
| 695 | FLOATcxx . . $ FLOAT# const re = (*wsamp_l)[BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`! / 2 - j]; |
| 696 | FLOATcxx . . $ FLOAT# const im = (*wsamp_l)[BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`! / 2 + j]; |
| 697 | fftenergy[BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`! / 2 - j] = (re * re + im * im) * 0.5f; |
| 698 | } |
| 699 | /* total energy */ |
| 700 | { |
| 701 | FLOATcxx . . $ FLOAT# totalenergy = 0.0f; |
| 702 | for (j = 11; j < HBLKSIZEcxx . . $ `external/lame/encoder.h:112:9`!; j++) |
| 703 | totalenergy += fftenergy[j]; |
| 704 | |
| 705 | psv->tot_enercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#tot_ener.[chn] = totalenergy; |
| 706 | } |
| 707 | |
| 708 | if (plt) { |
| 709 | for (j = 0; j < HBLKSIZEcxx . . $ `external/lame/encoder.h:112:9`!; j++) { |
| 710 | plt->energycxx . . $ plotting_data#energy.[gr_out][chn][j] = plt->energy_savecxx . . $ plotting_data#energy_save.[chn][j]; |
| 711 | plt->energy_savecxx . . $ plotting_data#energy_save.[chn][j] = fftenergy[j]; |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | |
| 717 | static void |
| 718 | vbrpsy_compute_fft_scxx . . $ vbrpsy_compute_fft_s(993871e49f4eb56e).(lame_internal_flagscxx . . $ lame_internal_flags# const *gfc, const sample_tcxx . . $ sample_t# * const buffer[2], int chn, |
| 719 | int sblock, FLOATcxx . . $ FLOAT#(*fftenergy_s)[HBLKSIZE_scxx . . $ `external/lame/encoder.h:114:9`!], FLOATcxx . . $ FLOAT#(*wsamp_s)[3][BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`!]) |
| 720 | { |
| 721 | int j; |
| 722 | |
| 723 | if (sblock == 0 && chn < 2) { |
| 724 | fft_shortcxx . . $ fft_short(d5ad062948e36d13).(gfc, *wsamp_s, chn, buffer); |
| 725 | } |
| 726 | if (chn == 2) { |
| 727 | FLOATcxx . . $ FLOAT# const sqrt2_half = SQRT2cxx . . $ `external/lame/util.h:77:17`! * 0.5f; |
| 728 | /* FFT data for mid and side channel is derived from L & R */ |
| 729 | for (j = BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`! - 1; j >= 0; --j) { |
| 730 | FLOATcxx . . $ FLOAT# const l = wsamp_s[0][sblock][j]; |
| 731 | FLOATcxx . . $ FLOAT# const r = wsamp_s[1][sblock][j]; |
| 732 | wsamp_s[0][sblock][j] = (l + r) * sqrt2_half; |
| 733 | wsamp_s[1][sblock][j] = (l - r) * sqrt2_half; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | /********************************************************************* |
| 738 | * compute energies |
| 739 | *********************************************************************/ |
| 740 | fftenergy_s[sblock][0] = (*wsamp_s)[sblock][0]; |
| 741 | fftenergy_s[sblock][0] *= fftenergy_s[sblock][0]; |
| 742 | for (j = BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`! / 2 - 1; j >= 0; --j) { |
| 743 | FLOATcxx . . $ FLOAT# const re = (*wsamp_s)[sblock][BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`! / 2 - j]; |
| 744 | FLOATcxx . . $ FLOAT# const im = (*wsamp_s)[sblock][BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`! / 2 + j]; |
| 745 | fftenergy_s[sblock][BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`! / 2 - j] = (re * re + im * im) * 0.5f; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | |
| 750 | /********************************************************************* |
| 751 | * compute loudness approximation (used for ATH auto-level adjustment) |
| 752 | *********************************************************************/ |
| 753 | static void |
| 754 | vbrpsy_compute_loudness_approximation_lcxx . . $ vbrpsy_compute_loudness_approximation_l(1b40bd2dfd421059).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int gr_out, int chn, |
| 755 | const FLOATcxx . . $ FLOAT# fftenergy[HBLKSIZEcxx . . $ `external/lame/encoder.h:112:9`!]) |
| 756 | { |
| 757 | PsyStateVar_tcxx . . $ PsyStateVar_t# *psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 758 | if (chn < 2) { /*no loudness for mid/side ch */ |
| 759 | gfc->ov_psycxx . . $ lame_internal_flags#ov_psy..loudness_sqcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_6#loudness_sq.[gr_out][chn] = psv->loudness_sq_savecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#loudness_sq_save.[chn]; |
| 760 | psv->loudness_sq_savecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#loudness_sq_save.[chn] = psycho_loudness_approxcxx . . $ psycho_loudness_approx(743b053a586f501d).(fftenergy, gfc->ATHcxx . . $ lame_internal_flags#ATH.->eql_wcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#eql_w.); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | |
| 765 | /********************************************************************** |
| 766 | * Apply HPF of fs/4 to the input signal. |
| 767 | * This is used for attack detection / handling. |
| 768 | **********************************************************************/ |
| 769 | static void |
| 770 | vbrpsy_attack_detectioncxx . . $ vbrpsy_attack_detection(691465ad53fd7228).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, const sample_tcxx . . $ sample_t# * const buffer[2], int gr_out, |
| 771 | III_psy_ratiocxx . . $ III_psy_ratio# masking_ratio[2][2], III_psy_ratiocxx . . $ III_psy_ratio# masking_MS_ratio[2][2], |
| 772 | FLOATcxx . . $ FLOAT# energy[4], FLOATcxx . . $ FLOAT# sub_short_factor[4][3], int ns_attacks[4][4], |
| 773 | int uselongblock[2]) |
| 774 | { |
| 775 | FLOATcxx . . $ FLOAT# ns_hpfsmpl[2][576]; |
| 776 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 777 | PsyStateVar_tcxx . . $ PsyStateVar_t# *const psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 778 | plotting_datacxx . . $ plotting_data# *plt = cfg->analysiscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#analysis. ? gfc->pinfocxx . . $ lame_internal_flags#pinfo. : 0; |
| 779 | int const n_chn_out = cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; |
| 780 | /* chn=2 and 3 = Mid and Side channels */ |
| 781 | int const n_chn_psy = (cfg->modecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode. == JOINT_STEREOcxx . . $ JOINT_STEREO.) ? 4 : n_chn_out; |
| 782 | int chn, i, j; |
| 783 | |
| 784 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&ns_hpfsmpl[0][0], 0, sizeof(ns_hpfsmpl)); |
| 785 | /* Don't copy the input buffer into a temporary buffer */ |
| 786 | /* unroll the loop 2 times */ |
| 787 | for (chn = 0; chn < n_chn_out; chn++) { |
| 788 | static const FLOATcxx . . $ FLOAT# fircoef[] = { |
| 789 | -8.65163e-18 * 2, -0.00851586 * 2, -6.74764e-18 * 2, 0.0209036 * 2, |
| 790 | -3.36639e-17 * 2, -0.0438162 * 2, -1.54175e-17 * 2, 0.0931738 * 2, |
| 791 | -5.52212e-17 * 2, -0.313819 * 2 |
| 792 | }; |
| 793 | /* apply high pass filter of fs/4 */ |
| 794 | const sample_tcxx . . $ sample_t# *const firbuf = &buffer[chn][576 - 350 - NSFIRLENcxx . . $ `external/lame/psymodel.c:159:9`! + 192]; |
| 795 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(fircoef) == ((NSFIRLENcxx . . $ `external/lame/psymodel.c:159:9`! - 1) / 2)); |
| 796 | for (i = 0; i < 576; i++) { |
| 797 | FLOATcxx . . $ FLOAT# sum1, sum2; |
| 798 | sum1 = firbuf[i + 10]; |
| 799 | sum2 = 0.0; |
| 800 | for (j = 0; j < ((NSFIRLENcxx . . $ `external/lame/psymodel.c:159:9`! - 1) / 2) - 1; j += 2) { |
| 801 | sum1 += fircoef[j] * (firbuf[i + j] + firbuf[i + NSFIRLENcxx . . $ `external/lame/psymodel.c:159:9`! - j]); |
| 802 | sum2 += fircoef[j + 1] * (firbuf[i + j + 1] + firbuf[i + NSFIRLENcxx . . $ `external/lame/psymodel.c:159:9`! - j - 1]); |
| 803 | } |
| 804 | ns_hpfsmpl[chn][i] = sum1 + sum2; |
| 805 | } |
| 806 | masking_ratio[gr_out][chn].encxx . . $ $anonymous_type_fdda207d22d8fb07_2#en. = psv->encxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#en.[chn]; |
| 807 | masking_ratio[gr_out][chn].thmcxx . . $ $anonymous_type_fdda207d22d8fb07_2#thm. = psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[chn]; |
| 808 | if (n_chn_psy > 2) { |
| 809 | /* MS maskings */ |
| 810 | /*percep_MS_entropy [chn-2] = gfc -> pe [chn]; */ |
| 811 | masking_MS_ratio[gr_out][chn].encxx . . $ $anonymous_type_fdda207d22d8fb07_2#en. = psv->encxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#en.[chn + 2]; |
| 812 | masking_MS_ratio[gr_out][chn].thmcxx . . $ $anonymous_type_fdda207d22d8fb07_2#thm. = psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[chn + 2]; |
| 813 | } |
| 814 | } |
| 815 | for (chn = 0; chn < n_chn_psy; chn++) { |
| 816 | FLOATcxx . . $ FLOAT# attack_intensity[12]; |
| 817 | FLOATcxx . . $ FLOAT# en_subshort[12]; |
| 818 | FLOATcxx . . $ FLOAT# en_short[4] = { 0, 0, 0, 0 }; |
| 819 | FLOATcxx . . $ FLOAT# const *pf = ns_hpfsmpl[chn & 1]; |
| 820 | int ns_uselongblock = 1; |
| 821 | |
| 822 | if (chn == 2) { |
| 823 | for (i = 0, j = 576; j > 0; ++i, --j) { |
| 824 | FLOATcxx . . $ FLOAT# const l = ns_hpfsmpl[0][i]; |
| 825 | FLOATcxx . . $ FLOAT# const r = ns_hpfsmpl[1][i]; |
| 826 | ns_hpfsmpl[0][i] = l + r; |
| 827 | ns_hpfsmpl[1][i] = l - r; |
| 828 | } |
| 829 | } |
| 830 | /*************************************************************** |
| 831 | * determine the block type (window type) |
| 832 | ***************************************************************/ |
| 833 | /* calculate energies of each sub-shortblocks */ |
| 834 | for (i = 0; i < 3; i++) { |
| 835 | en_subshort[i] = psv->last_en_subshortcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_en_subshort.[chn][i + 6]; |
| 836 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(psv->last_en_subshort[chn][i + 4] > 0); |
| 837 | attack_intensity[i] = en_subshort[i] / psv->last_en_subshortcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_en_subshort.[chn][i + 4]; |
| 838 | en_short[0] += en_subshort[i]; |
| 839 | } |
| 840 | |
| 841 | for (i = 0; i < 9; i++) { |
| 842 | FLOATcxx . . $ FLOAT# const *const pfe = pf + 576 / 9; |
| 843 | FLOATcxx . . $ FLOAT# p = 1.; |
| 844 | for (; pf < pfe; pf++) |
| 845 | if (p < fabs(*pf)) |
| 846 | p = fabs(*pf); |
| 847 | psv->last_en_subshortcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_en_subshort.[chn][i] = en_subshort[i + 3] = p; |
| 848 | en_short[1 + i / 3] += p; |
| 849 | if (p > en_subshort[i + 3 - 2]) { |
| 850 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(en_subshort[i + 3 - 2] > 0); |
| 851 | p = p / en_subshort[i + 3 - 2]; |
| 852 | } |
| 853 | else if (en_subshort[i + 3 - 2] > p * 10.0f) { |
| 854 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(p > 0); |
| 855 | p = en_subshort[i + 3 - 2] / (p * 10.0f); |
| 856 | } |
| 857 | else { |
| 858 | p = 0.0; |
| 859 | } |
| 860 | attack_intensity[i + 3] = p; |
| 861 | } |
| 862 | |
| 863 | /* pulse like signal detection for fatboy.wav and so on */ |
| 864 | for (i = 0; i < 3; ++i) { |
| 865 | FLOATcxx . . $ FLOAT# const enn = |
| 866 | en_subshort[i * 3 + 3] + en_subshort[i * 3 + 4] + en_subshort[i * 3 + 5]; |
| 867 | FLOATcxx . . $ FLOAT# factor = 1.f; |
| 868 | if (en_subshort[i * 3 + 5] * 6 < enn) { |
| 869 | factor *= 0.5f; |
| 870 | if (en_subshort[i * 3 + 4] * 6 < enn) { |
| 871 | factor *= 0.5f; |
| 872 | } |
| 873 | } |
| 874 | sub_short_factor[chn][i] = factor; |
| 875 | } |
| 876 | |
| 877 | if (plt) { |
| 878 | FLOATcxx . . $ FLOAT# x = attack_intensity[0]; |
| 879 | for (i = 1; i < 12; i++) { |
| 880 | if (x < attack_intensity[i]) { |
| 881 | x = attack_intensity[i]; |
| 882 | } |
| 883 | } |
| 884 | plt->erscxx . . $ plotting_data#ers.[gr_out][chn] = plt->ers_savecxx . . $ plotting_data#ers_save.[chn]; |
| 885 | plt->ers_savecxx . . $ plotting_data#ers_save.[chn] = x; |
| 886 | } |
| 887 | |
| 888 | /* compare energies between sub-shortblocks */ |
| 889 | { |
| 890 | FLOATcxx . . $ FLOAT# x = gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->attack_thresholdcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#attack_threshold.[chn]; |
| 891 | for (i = 0; i < 12; i++) { |
| 892 | if (ns_attacks[chn][i / 3] == 0) { |
| 893 | if (attack_intensity[i] > x) { |
| 894 | ns_attacks[chn][i / 3] = (i % 3) + 1; |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | /* should have energy change between short blocks, in order to avoid periodic signals */ |
| 900 | /* Good samples to show the effect are Trumpet test songs */ |
| 901 | /* GB: tuned (1) to avoid too many short blocks for test sample TRUMPET */ |
| 902 | /* RH: tuned (2) to let enough short blocks through for test sample FSOL and SNAPS */ |
| 903 | for (i = 1; i < 4; i++) { |
| 904 | FLOATcxx . . $ FLOAT# const u = en_short[i - 1]; |
| 905 | FLOATcxx . . $ FLOAT# const v = en_short[i]; |
| 906 | FLOATcxx . . $ FLOAT# const m = Maxcxx . . $ `external/lame/util.h:92:17`!(u, v); |
| 907 | if (m < 40000) { /* (2) */ |
| 908 | if (u < 1.7f * v && v < 1.7f * u) { /* (1) */ |
| 909 | if (i == 1 && ns_attacks[chn][0] <= ns_attacks[chn][i]) { |
| 910 | ns_attacks[chn][0] = 0; |
| 911 | } |
| 912 | ns_attacks[chn][i] = 0; |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | if (ns_attacks[chn][0] <= psv->last_attackscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_attacks.[chn]) { |
| 918 | ns_attacks[chn][0] = 0; |
| 919 | } |
| 920 | |
| 921 | if (psv->last_attackscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_attacks.[chn] == 3 || |
| 922 | ns_attacks[chn][0] + ns_attacks[chn][1] + ns_attacks[chn][2] + ns_attacks[chn][3]) { |
| 923 | ns_uselongblock = 0; |
| 924 | |
| 925 | if (ns_attacks[chn][1] && ns_attacks[chn][0]) { |
| 926 | ns_attacks[chn][1] = 0; |
| 927 | } |
| 928 | if (ns_attacks[chn][2] && ns_attacks[chn][1]) { |
| 929 | ns_attacks[chn][2] = 0; |
| 930 | } |
| 931 | if (ns_attacks[chn][3] && ns_attacks[chn][2]) { |
| 932 | ns_attacks[chn][3] = 0; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | if (chn < 2) { |
| 937 | uselongblock[chn] = ns_uselongblock; |
| 938 | } |
| 939 | else { |
| 940 | if (ns_uselongblock == 0) { |
| 941 | uselongblock[0] = uselongblock[1] = 0; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | /* there is a one granule delay. Copy maskings computed last call |
| 946 | * into masking_ratio to return to calling program. |
| 947 | */ |
| 948 | energy[chn] = psv->tot_enercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#tot_ener.[chn]; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | |
| 953 | static void |
| 954 | vbrpsy_skip_masking_scxx . . $ vbrpsy_skip_masking_s(b6022c2330fef37d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int chn, int sblock) |
| 955 | { |
| 956 | if (sblock == 0) { |
| 957 | FLOATcxx . . $ FLOAT# *nbs2 = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy..nb_s2cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_s2.[chn][0]; |
| 958 | FLOATcxx . . $ FLOAT# *nbs1 = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy..nb_s1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_s1.[chn][0]; |
| 959 | int const n = gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; |
| 960 | int b; |
| 961 | for (b = 0; b < n; b++) { |
| 962 | nbs2[b] = nbs1[b]; |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | |
| 968 | static void |
| 969 | vbrpsy_calc_mask_index_scxx . . $ vbrpsy_calc_mask_index_s(54c422903ca43f93).(lame_internal_flagscxx . . $ lame_internal_flags# const *gfc, FLOATcxx . . $ FLOAT# const *max, |
| 970 | FLOATcxx . . $ FLOAT# const *avg, unsigned char *mask_idx) |
| 971 | { |
| 972 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gds = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s.; |
| 973 | FLOATcxx . . $ FLOAT# m, a; |
| 974 | int b, k; |
| 975 | int const last_tab_entry = dimension_ofcxx . . $ `external/lame/machine.h:158:9`!(tab) - 1; |
| 976 | b = 0; |
| 977 | a = avg[b] + avg[b + 1]; |
| 978 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(a >= 0); |
| 979 | if (a > 0.0f) { |
| 980 | m = max[b]; |
| 981 | if (m < max[b + 1]) |
| 982 | m = max[b + 1]; |
| 983 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((gds->numlines[b] + gds->numlines[b + 1] - 1) > 0); |
| 984 | a = 20.0f * (m * 2.0f - a) |
| 985 | / (a * (gds->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b] + gds->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b + 1] - 1)); |
| 986 | k = (int) a; |
| 987 | if (k > last_tab_entry) |
| 988 | k = last_tab_entry; |
| 989 | mask_idx[b] = k; |
| 990 | } |
| 991 | else { |
| 992 | mask_idx[b] = 0; |
| 993 | } |
| 994 | |
| 995 | for (b = 1; b < gds->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart. - 1; b++) { |
| 996 | a = avg[b - 1] + avg[b] + avg[b + 1]; |
| 997 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(b + 1 < gds->npart); |
| 998 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(a >= 0); |
| 999 | if (a > 0.0) { |
| 1000 | m = max[b - 1]; |
| 1001 | if (m < max[b]) |
| 1002 | m = max[b]; |
| 1003 | if (m < max[b + 1]) |
| 1004 | m = max[b + 1]; |
| 1005 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((gds->numlines[b - 1] + gds->numlines[b] + gds->numlines[b + 1] - 1) > 0); |
| 1006 | a = 20.0f * (m * 3.0f - a) |
| 1007 | / (a * (gds->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b - 1] + gds->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b] + gds->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b + 1] - 1)); |
| 1008 | k = (int) a; |
| 1009 | if (k > last_tab_entry) |
| 1010 | k = last_tab_entry; |
| 1011 | mask_idx[b] = k; |
| 1012 | } |
| 1013 | else { |
| 1014 | mask_idx[b] = 0; |
| 1015 | } |
| 1016 | } |
| 1017 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(b > 0); |
| 1018 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(b == gds->npart - 1); |
| 1019 | |
| 1020 | a = avg[b - 1] + avg[b]; |
| 1021 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(a >= 0); |
| 1022 | if (a > 0.0f) { |
| 1023 | m = max[b - 1]; |
| 1024 | if (m < max[b]) |
| 1025 | m = max[b]; |
| 1026 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((gds->numlines[b - 1] + gds->numlines[b] - 1) > 0); |
| 1027 | a = 20.0f * (m * 2.0f - a) |
| 1028 | / (a * (gds->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b - 1] + gds->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b] - 1)); |
| 1029 | k = (int) a; |
| 1030 | if (k > last_tab_entry) |
| 1031 | k = last_tab_entry; |
| 1032 | mask_idx[b] = k; |
| 1033 | } |
| 1034 | else { |
| 1035 | mask_idx[b] = 0; |
| 1036 | } |
| 1037 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(b == (gds->npart - 1)); |
| 1038 | } |
| 1039 | |
| 1040 | |
| 1041 | static void |
| 1042 | vbrpsy_compute_masking_scxx . . $ vbrpsy_compute_masking_s(d238b3830fc1f8ed).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, const FLOATcxx . . $ FLOAT#(*fftenergy_s)[HBLKSIZE_scxx . . $ `external/lame/encoder.h:114:9`!], |
| 1043 | FLOATcxx . . $ FLOAT# * eb, FLOATcxx . . $ FLOAT# * thr, int chn, int sblock) |
| 1044 | { |
| 1045 | PsyStateVar_tcxx . . $ PsyStateVar_t# *const psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 1046 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gds = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s.; |
| 1047 | FLOATcxx . . $ FLOAT# max[CBANDScxx . . $ `external/lame/encoder.h:96:9`!], avg[CBANDScxx . . $ `external/lame/encoder.h:96:9`!]; |
| 1048 | int i, j, b; |
| 1049 | unsigned char mask_idx_s[CBANDScxx . . $ `external/lame/encoder.h:96:9`!]; |
| 1050 | |
| 1051 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(max, 0, sizeof(max)); |
| 1052 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(avg, 0, sizeof(avg)); |
| 1053 | |
| 1054 | for (b = j = 0; b < gds->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; ++b) { |
| 1055 | FLOATcxx . . $ FLOAT# ebb = 0, m = 0; |
| 1056 | int const n = gds->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b]; |
| 1057 | for (i = 0; i < n; ++i, ++j) { |
| 1058 | FLOATcxx . . $ FLOAT# const el = fftenergy_s[sblock][j]; |
| 1059 | ebb += el; |
| 1060 | if (m < el) |
| 1061 | m = el; |
| 1062 | } |
| 1063 | eb[b] = ebb; |
| 1064 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(ebb >= 0); |
| 1065 | max[b] = m; |
| 1066 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(n > 0); |
| 1067 | avg[b] = ebb * gds->rnumlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#rnumlines.[b]; |
| 1068 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(avg[b] >= 0); |
| 1069 | } |
| 1070 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(b == gds->npart); |
| 1071 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j == 129); |
| 1072 | vbrpsy_calc_mask_index_scxx . . $ vbrpsy_calc_mask_index_s(54c422903ca43f93).(gfc, max, avg, mask_idx_s); |
| 1073 | for (j = b = 0; b < gds->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; b++) { |
| 1074 | int kk = gds->s3indcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3ind.[b][0]; |
| 1075 | int const last = gds->s3indcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3ind.[b][1]; |
| 1076 | int const delta = mask_add_deltacxx . . $ mask_add_delta(7864480464b09eea).(mask_idx_s[b]); |
| 1077 | int dd, dd_n; |
| 1078 | FLOATcxx . . $ FLOAT# x, ecb, avg_mask; |
| 1079 | FLOATcxx . . $ FLOAT# const masking_lower = gds->masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#masking_lower.[b] * gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#masking_lower.; |
| 1080 | |
| 1081 | dd = mask_idx_s[kk]; |
| 1082 | dd_n = 1; |
| 1083 | ecb = gds->s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3.[j] * eb[kk] * tabcxx . . $ tab.[mask_idx_s[kk]]; |
| 1084 | ++j, ++kk; |
| 1085 | while (kk <= last) { |
| 1086 | dd += mask_idx_s[kk]; |
| 1087 | dd_n += 1; |
| 1088 | x = gds->s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3.[j] * eb[kk] * tabcxx . . $ tab.[mask_idx_s[kk]]; |
| 1089 | ecb = vbrpsy_mask_addcxx . . $ vbrpsy_mask_add(68b9a276dda9e283).(ecb, x, kk - b, delta); |
| 1090 | ++j, ++kk; |
| 1091 | } |
| 1092 | dd = (1 + 2 * dd) / (2 * dd_n); |
| 1093 | avg_mask = tabcxx . . $ tab.[dd] * 0.5f; |
| 1094 | ecb *= avg_mask; |
| 1095 | #if 0 /* we can do PRE ECHO control now here, or do it later */ |
| 1096 | if (psv->blocktype_old[chn & 0x01] == SHORT_TYPE) { |
| 1097 | /* limit calculated threshold by even older granule */ |
| 1098 | FLOAT const t1 = rpelev_s * psv->nb_s1[chn][b]; |
| 1099 | FLOAT const t2 = rpelev2_s * psv->nb_s2[chn][b]; |
| 1100 | FLOAT const tm = (t2 > 0) ? Min(ecb, t2) : ecb; |
| 1101 | thr[b] = (t1 > 0) ? NS_INTERP(Min(tm, t1), ecb, 0.6) : ecb; |
| 1102 | } |
| 1103 | else { |
| 1104 | /* limit calculated threshold by older granule */ |
| 1105 | FLOAT const t1 = rpelev_s * psv->nb_s1[chn][b]; |
| 1106 | thr[b] = (t1 > 0) ? NS_INTERP(Min(ecb, t1), ecb, 0.6) : ecb; |
| 1107 | } |
| 1108 | #else /* we do it later */ |
| 1109 | thr[b] = ecb; |
| 1110 | #endif |
| 1111 | psv->nb_s2cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_s2.[chn][b] = psv->nb_s1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_s1.[chn][b]; |
| 1112 | psv->nb_s1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_s1.[chn][b] = ecb; |
| 1113 | { |
| 1114 | /* if THR exceeds EB, the quantization routines will take the difference |
| 1115 | * from other bands. in case of strong tonal samples (tonaltest.wav) |
| 1116 | * this leads to heavy distortions. that's why we limit THR here. |
| 1117 | */ |
| 1118 | x = max[b]; |
| 1119 | x *= gds->minvalcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#minval.[b]; |
| 1120 | x *= avg_mask; |
| 1121 | if (thr[b] > x) { |
| 1122 | thr[b] = x; |
| 1123 | } |
| 1124 | } |
| 1125 | if (masking_lower > 1) { |
| 1126 | thr[b] *= masking_lower; |
| 1127 | } |
| 1128 | if (thr[b] > eb[b]) { |
| 1129 | thr[b] = eb[b]; |
| 1130 | } |
| 1131 | if (masking_lower < 1) { |
| 1132 | thr[b] *= masking_lower; |
| 1133 | } |
| 1134 | |
| 1135 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(thr[b] >= 0); |
| 1136 | } |
| 1137 | for (; b < CBANDScxx . . $ `external/lame/encoder.h:96:9`!; ++b) { |
| 1138 | eb[b] = 0; |
| 1139 | thr[b] = 0; |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | static void |
| 1145 | vbrpsy_compute_masking_lcxx . . $ vbrpsy_compute_masking_l(6e79c2abe2ce163f).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, const FLOATcxx . . $ FLOAT# fftenergy[HBLKSIZEcxx . . $ `external/lame/encoder.h:112:9`!], |
| 1146 | FLOATcxx . . $ FLOAT# eb_l[CBANDScxx . . $ `external/lame/encoder.h:96:9`!], FLOATcxx . . $ FLOAT# thr[CBANDScxx . . $ `external/lame/encoder.h:96:9`!], int chn) |
| 1147 | { |
| 1148 | PsyStateVar_tcxx . . $ PsyStateVar_t# *const psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 1149 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gdl = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l.; |
| 1150 | FLOATcxx . . $ FLOAT# max[CBANDScxx . . $ `external/lame/encoder.h:96:9`!], avg[CBANDScxx . . $ `external/lame/encoder.h:96:9`!]; |
| 1151 | unsigned char mask_idx_l[CBANDScxx . . $ `external/lame/encoder.h:96:9`! + 2]; |
| 1152 | int k, b; |
| 1153 | |
| 1154 | /********************************************************************* |
| 1155 | * Calculate the energy and the tonality of each partition. |
| 1156 | *********************************************************************/ |
| 1157 | calc_energycxx . . $ calc_energy(d94a6a32123da09d).(gdl, fftenergy, eb_l, max, avg); |
| 1158 | calc_mask_index_lcxx . . $ calc_mask_index_l(54c422903ca43f93).(gfc, max, avg, mask_idx_l); |
| 1159 | |
| 1160 | /********************************************************************* |
| 1161 | * convolve the partitioned energy and unpredictability |
| 1162 | * with the spreading function, s3_l[b][k] |
| 1163 | ********************************************************************/ |
| 1164 | k = 0; |
| 1165 | for (b = 0; b < gdl->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; b++) { |
| 1166 | FLOATcxx . . $ FLOAT# x, ecb, avg_mask, t; |
| 1167 | FLOATcxx . . $ FLOAT# const masking_lower = gdl->masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#masking_lower.[b] * gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#masking_lower.; |
| 1168 | /* convolve the partitioned energy with the spreading function */ |
| 1169 | int kk = gdl->s3indcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3ind.[b][0]; |
| 1170 | int const last = gdl->s3indcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3ind.[b][1]; |
| 1171 | int const delta = mask_add_deltacxx . . $ mask_add_delta(7864480464b09eea).(mask_idx_l[b]); |
| 1172 | int dd = 0, dd_n = 0; |
| 1173 | |
| 1174 | dd = mask_idx_l[kk]; |
| 1175 | dd_n += 1; |
| 1176 | ecb = gdl->s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3.[k] * eb_l[kk] * tabcxx . . $ tab.[mask_idx_l[kk]]; |
| 1177 | ++k, ++kk; |
| 1178 | while (kk <= last) { |
| 1179 | dd += mask_idx_l[kk]; |
| 1180 | dd_n += 1; |
| 1181 | x = gdl->s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3.[k] * eb_l[kk] * tabcxx . . $ tab.[mask_idx_l[kk]]; |
| 1182 | t = vbrpsy_mask_addcxx . . $ vbrpsy_mask_add(68b9a276dda9e283).(ecb, x, kk - b, delta); |
| 1183 | #if 0 |
| 1184 | ecb += eb_l[kk]; |
| 1185 | if (ecb > t) { |
| 1186 | ecb = t; |
| 1187 | } |
| 1188 | #else |
| 1189 | ecb = t; |
| 1190 | #endif |
| 1191 | ++k, ++kk; |
| 1192 | } |
| 1193 | dd = (1 + 2 * dd) / (2 * dd_n); |
| 1194 | avg_mask = tabcxx . . $ tab.[dd] * 0.5f; |
| 1195 | ecb *= avg_mask; |
| 1196 | |
| 1197 | /**** long block pre-echo control ****/ |
| 1198 | /* dont use long block pre-echo control if previous granule was |
| 1199 | * a short block. This is to avoid the situation: |
| 1200 | * frame0: quiet (very low masking) |
| 1201 | * frame1: surge (triggers short blocks) |
| 1202 | * frame2: regular frame. looks like pre-echo when compared to |
| 1203 | * frame0, but all pre-echo was in frame1. |
| 1204 | */ |
| 1205 | /* chn=0,1 L and R channels |
| 1206 | chn=2,3 S and M channels. |
| 1207 | */ |
| 1208 | if (psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn & 0x01] == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { |
| 1209 | FLOATcxx . . $ FLOAT# const ecb_limit = rpelevcxx . . $ `external/lame/psymodel.h:42:9`! * psv->nb_l1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_l1.[chn][b]; |
| 1210 | if (ecb_limit > 0) { |
| 1211 | thr[b] = Mincxx . . $ `external/lame/util.h:91:17`!(ecb, ecb_limit); |
| 1212 | } |
| 1213 | else { |
| 1214 | /* Robert 071209: |
| 1215 | Because we don't calculate long block psy when we know a granule |
| 1216 | should be of short blocks, we don't have any clue how the granule |
| 1217 | before would have looked like as a long block. So we have to guess |
| 1218 | a little bit for this END_TYPE block. |
| 1219 | Most of the time we get away with this sloppyness. (fingers crossed :) |
| 1220 | The speed increase is worth it. |
| 1221 | */ |
| 1222 | thr[b] = Mincxx . . $ `external/lame/util.h:91:17`!(ecb, eb_l[b] * NS_PREECHO_ATT2cxx . . $ `external/lame/psymodel.h:58:9`!); |
| 1223 | } |
| 1224 | } |
| 1225 | else { |
| 1226 | FLOATcxx . . $ FLOAT# ecb_limit_2 = rpelev2cxx . . $ `external/lame/psymodel.h:43:9`! * psv->nb_l2cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_l2.[chn][b]; |
| 1227 | FLOATcxx . . $ FLOAT# ecb_limit_1 = rpelevcxx . . $ `external/lame/psymodel.h:42:9`! * psv->nb_l1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_l1.[chn][b]; |
| 1228 | FLOATcxx . . $ FLOAT# ecb_limit; |
| 1229 | if (ecb_limit_2 <= 0) { |
| 1230 | ecb_limit_2 = ecb; |
| 1231 | } |
| 1232 | if (ecb_limit_1 <= 0) { |
| 1233 | ecb_limit_1 = ecb; |
| 1234 | } |
| 1235 | if (psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn & 0x01] == NORM_TYPEcxx . . $ `external/lame/encoder.h:118:9`!) { |
| 1236 | ecb_limit = Mincxx . . $ `external/lame/util.h:91:17`!(ecb_limit_1, ecb_limit_2); |
| 1237 | } |
| 1238 | else { |
| 1239 | ecb_limit = ecb_limit_1; |
| 1240 | } |
| 1241 | thr[b] = Mincxx . . $ `external/lame/util.h:91:17`!(ecb, ecb_limit); |
| 1242 | } |
| 1243 | psv->nb_l2cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_l2.[chn][b] = psv->nb_l1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_l1.[chn][b]; |
| 1244 | psv->nb_l1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_l1.[chn][b] = ecb; |
| 1245 | { |
| 1246 | /* if THR exceeds EB, the quantization routines will take the difference |
| 1247 | * from other bands. in case of strong tonal samples (tonaltest.wav) |
| 1248 | * this leads to heavy distortions. that's why we limit THR here. |
| 1249 | */ |
| 1250 | x = max[b]; |
| 1251 | x *= gdl->minvalcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#minval.[b]; |
| 1252 | x *= avg_mask; |
| 1253 | if (thr[b] > x) { |
| 1254 | thr[b] = x; |
| 1255 | } |
| 1256 | } |
| 1257 | if (masking_lower > 1) { |
| 1258 | thr[b] *= masking_lower; |
| 1259 | } |
| 1260 | if (thr[b] > eb_l[b]) { |
| 1261 | thr[b] = eb_l[b]; |
| 1262 | } |
| 1263 | if (masking_lower < 1) { |
| 1264 | thr[b] *= masking_lower; |
| 1265 | } |
| 1266 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(thr[b] >= 0); |
| 1267 | } |
| 1268 | for (; b < CBANDScxx . . $ `external/lame/encoder.h:96:9`!; ++b) { |
| 1269 | eb_l[b] = 0; |
| 1270 | thr[b] = 0; |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | |
| 1275 | static void |
| 1276 | vbrpsy_compute_block_typecxx . . $ vbrpsy_compute_block_type(c1dc22a9e8db10ba).(SessionConfig_tcxx . . $ SessionConfig_t# const *cfg, int *uselongblock) |
| 1277 | { |
| 1278 | int chn; |
| 1279 | |
| 1280 | if (cfg->short_blockscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#short_blocks. == short_block_coupledcxx . . $ short_block_coupled. |
| 1281 | /* force both channels to use the same block type */ |
| 1282 | /* this is necessary if the frame is to be encoded in ms_stereo. */ |
| 1283 | /* But even without ms_stereo, FhG does this */ |
| 1284 | && !(uselongblock[0] && uselongblock[1])) |
| 1285 | uselongblock[0] = uselongblock[1] = 0; |
| 1286 | |
| 1287 | for (chn = 0; chn < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; chn++) { |
| 1288 | /* disable short blocks */ |
| 1289 | if (cfg->short_blockscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#short_blocks. == short_block_dispensedcxx . . $ short_block_dispensed.) { |
| 1290 | uselongblock[chn] = 1; |
| 1291 | } |
| 1292 | if (cfg->short_blockscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#short_blocks. == short_block_forcedcxx . . $ short_block_forced.) { |
| 1293 | uselongblock[chn] = 0; |
| 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | static void |
| 1300 | vbrpsy_apply_block_typecxx . . $ vbrpsy_apply_block_type(567919236745bc71).(PsyStateVar_tcxx . . $ PsyStateVar_t# * psv, int nch, int const *uselongblock, int *blocktype_d) |
| 1301 | { |
| 1302 | int chn; |
| 1303 | |
| 1304 | /* update the blocktype of the previous granule, since it depends on what |
| 1305 | * happend in this granule */ |
| 1306 | for (chn = 0; chn < nch; chn++) { |
| 1307 | int blocktype = NORM_TYPEcxx . . $ `external/lame/encoder.h:118:9`!; |
| 1308 | /* disable short blocks */ |
| 1309 | |
| 1310 | if (uselongblock[chn]) { |
| 1311 | /* no attack : use long blocks */ |
| 1312 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(psv->blocktype_old[chn] != START_TYPEcxx . . $ `external/lame/encoder.h:119:9`!); |
| 1313 | if (psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn] == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) |
| 1314 | blocktype = STOP_TYPEcxx . . $ `external/lame/encoder.h:121:9`!; |
| 1315 | } |
| 1316 | else { |
| 1317 | /* attack : use short blocks */ |
| 1318 | blocktype = SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!; |
| 1319 | if (psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn] == NORM_TYPEcxx . . $ `external/lame/encoder.h:118:9`!) { |
| 1320 | psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn] = START_TYPEcxx . . $ `external/lame/encoder.h:119:9`!; |
| 1321 | } |
| 1322 | if (psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn] == STOP_TYPEcxx . . $ `external/lame/encoder.h:121:9`!) |
| 1323 | psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn] = SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!; |
| 1324 | } |
| 1325 | |
| 1326 | blocktype_d[chn] = psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn]; /* value returned to calling program */ |
| 1327 | psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[chn] = blocktype; /* save for next call to l3psy_anal */ |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | |
| 1332 | /*************************************************************** |
| 1333 | * compute M/S thresholds from Johnston & Ferreira 1992 ICASSP paper |
| 1334 | ***************************************************************/ |
| 1335 | |
| 1336 | static void |
| 1337 | vbrpsy_compute_MS_thresholdscxx . . $ vbrpsy_compute_MS_thresholds(49bd6ec1b516b7bf).(const FLOATcxx . . $ FLOAT# eb[4][CBANDScxx . . $ `external/lame/encoder.h:96:9`!], FLOATcxx . . $ FLOAT# thr[4][CBANDScxx . . $ `external/lame/encoder.h:96:9`!], |
| 1338 | const FLOATcxx . . $ FLOAT# cb_mld[CBANDScxx . . $ `external/lame/encoder.h:96:9`!], const FLOATcxx . . $ FLOAT# ath_cb[CBANDScxx . . $ `external/lame/encoder.h:96:9`!], FLOATcxx . . $ FLOAT# athlower, |
| 1339 | FLOATcxx . . $ FLOAT# msfix, int n) |
| 1340 | { |
| 1341 | FLOATcxx . . $ FLOAT# const msfix2 = msfix * 2.f; |
| 1342 | FLOATcxx . . $ FLOAT# rside, rmid; |
| 1343 | int b; |
| 1344 | for (b = 0; b < n; ++b) { |
| 1345 | FLOATcxx . . $ FLOAT# const ebM = eb[2][b]; |
| 1346 | FLOATcxx . . $ FLOAT# const ebS = eb[3][b]; |
| 1347 | FLOATcxx . . $ FLOAT# const thmL = thr[0][b]; |
| 1348 | FLOATcxx . . $ FLOAT# const thmR = thr[1][b]; |
| 1349 | FLOATcxx . . $ FLOAT# thmM = thr[2][b]; |
| 1350 | FLOATcxx . . $ FLOAT# thmS = thr[3][b]; |
| 1351 | |
| 1352 | /* use this fix if L & R masking differs by 2db or less */ |
| 1353 | /* if db = 10*log10(x2/x1) < 2 */ |
| 1354 | /* if (x2 < 1.58*x1) { */ |
| 1355 | if (thmL <= 1.58f * thmR && thmR <= 1.58f * thmL) { |
| 1356 | FLOATcxx . . $ FLOAT# const mld_m = cb_mld[b] * ebS; |
| 1357 | FLOATcxx . . $ FLOAT# const mld_s = cb_mld[b] * ebM; |
| 1358 | FLOATcxx . . $ FLOAT# const tmp_m = Mincxx . . $ `external/lame/util.h:91:17`!(thmS, mld_m); |
| 1359 | FLOATcxx . . $ FLOAT# const tmp_s = Mincxx . . $ `external/lame/util.h:91:17`!(thmM, mld_s); |
| 1360 | rmid = Maxcxx . . $ `external/lame/util.h:92:17`!(thmM, tmp_m); |
| 1361 | rside = Maxcxx . . $ `external/lame/util.h:92:17`!(thmS, tmp_s); |
| 1362 | } |
| 1363 | else { |
| 1364 | rmid = thmM; |
| 1365 | rside = thmS; |
| 1366 | } |
| 1367 | if (msfix > 0.f) { |
| 1368 | /***************************************************************/ |
| 1369 | /* Adjust M/S maskings if user set "msfix" */ |
| 1370 | /***************************************************************/ |
| 1371 | /* Naoki Shibata 2000 */ |
| 1372 | FLOATcxx . . $ FLOAT# thmLR, thmMS; |
| 1373 | FLOATcxx . . $ FLOAT# const ath = ath_cb[b] * athlower; |
| 1374 | FLOATcxx . . $ FLOAT# const tmp_l = Maxcxx . . $ `external/lame/util.h:92:17`!(thmL, ath); |
| 1375 | FLOATcxx . . $ FLOAT# const tmp_r = Maxcxx . . $ `external/lame/util.h:92:17`!(thmR, ath); |
| 1376 | thmLR = Mincxx . . $ `external/lame/util.h:91:17`!(tmp_l, tmp_r); |
| 1377 | thmM = Maxcxx . . $ `external/lame/util.h:92:17`!(rmid, ath); |
| 1378 | thmS = Maxcxx . . $ `external/lame/util.h:92:17`!(rside, ath); |
| 1379 | thmMS = thmM + thmS; |
| 1380 | if (thmMS > 0.f && (thmLR * msfix2) < thmMS) { |
| 1381 | FLOATcxx . . $ FLOAT# const f = thmLR * msfix2 / thmMS; |
| 1382 | thmM *= f; |
| 1383 | thmS *= f; |
| 1384 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(thmMS > 0.f); |
| 1385 | } |
| 1386 | rmid = Mincxx . . $ `external/lame/util.h:91:17`!(thmM, rmid); |
| 1387 | rside = Mincxx . . $ `external/lame/util.h:91:17`!(thmS, rside); |
| 1388 | } |
| 1389 | if (rmid > ebM) { |
| 1390 | rmid = ebM; |
| 1391 | } |
| 1392 | if (rside > ebS) { |
| 1393 | rside = ebS; |
| 1394 | } |
| 1395 | thr[2][b] = rmid; |
| 1396 | thr[3][b] = rside; |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | |
| 1401 | /* |
| 1402 | * NOTE: the bitrate reduction from the inter-channel masking effect is low |
| 1403 | * compared to the chance of getting annyoing artefacts. L3psycho_anal_vbr does |
| 1404 | * not use this feature. (Robert 071216) |
| 1405 | */ |
| 1406 | |
| 1407 | int |
| 1408 | L3psycho_anal_vbrcxx . . $ L3psycho_anal_vbr(e5d24a8137134426).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, |
| 1409 | const sample_tcxx . . $ sample_t# * const buffer[2], int gr_out, |
| 1410 | III_psy_ratiocxx . . $ III_psy_ratio# masking_ratio[2][2], |
| 1411 | III_psy_ratiocxx . . $ III_psy_ratio# masking_MS_ratio[2][2], |
| 1412 | FLOATcxx . . $ FLOAT# percep_entropy[2], FLOATcxx . . $ FLOAT# percep_MS_entropy[2], |
| 1413 | FLOATcxx . . $ FLOAT# energy[4], int blocktype_d[2]) |
| 1414 | { |
| 1415 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1416 | PsyStateVar_tcxx . . $ PsyStateVar_t# *const psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 1417 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gdl = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l.; |
| 1418 | PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *const gds = &gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s.; |
| 1419 | plotting_datacxx . . $ plotting_data# *plt = cfg->analysiscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#analysis. ? gfc->pinfocxx . . $ lame_internal_flags#pinfo. : 0; |
| 1420 | |
| 1421 | III_psy_xmincxx . . $ III_psy_xmin# last_thm[4]; |
| 1422 | |
| 1423 | /* fft and energy calculation */ |
| 1424 | FLOATcxx . . $ FLOAT#(*wsamp_l)[BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`!]; |
| 1425 | FLOATcxx . . $ FLOAT#(*wsamp_s)[3][BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`!]; |
| 1426 | FLOATcxx . . $ FLOAT# fftenergy[HBLKSIZEcxx . . $ `external/lame/encoder.h:112:9`!]; |
| 1427 | FLOATcxx . . $ FLOAT# fftenergy_s[3][HBLKSIZE_scxx . . $ `external/lame/encoder.h:114:9`!]; |
| 1428 | FLOATcxx . . $ FLOAT# wsamp_L[2][BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`!]; |
| 1429 | FLOATcxx . . $ FLOAT# wsamp_S[2][3][BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`!]; |
| 1430 | FLOATcxx . . $ FLOAT# eb[4][CBANDScxx . . $ `external/lame/encoder.h:96:9`!], thr[4][CBANDScxx . . $ `external/lame/encoder.h:96:9`!]; |
| 1431 | |
| 1432 | FLOATcxx . . $ FLOAT# sub_short_factor[4][3]; |
| 1433 | FLOATcxx . . $ FLOAT# thmm; |
| 1434 | FLOATcxx . . $ FLOAT# const pcfact = 0.6f; |
| 1435 | FLOATcxx . . $ FLOAT# const ath_factor = |
| 1436 | (cfg->msfixcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#msfix. > 0.f) ? (cfg->ATH_offset_factorcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#ATH_offset_factor. * gfc->ATHcxx . . $ lame_internal_flags#ATH.->adjust_factorcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#adjust_factor.) : 1.f; |
| 1437 | |
| 1438 | const FLOATcxx . . $ FLOAT#(*const_eb)[CBANDScxx . . $ `external/lame/encoder.h:96:9`!] = (const FLOATcxx . . $ FLOAT#(*)[CBANDScxx . . $ `external/lame/encoder.h:96:9`!]) eb; |
| 1439 | const FLOATcxx . . $ FLOAT#(*const_fftenergy_s)[HBLKSIZE_scxx . . $ `external/lame/encoder.h:114:9`!] = (const FLOATcxx . . $ FLOAT#(*)[HBLKSIZE_scxx . . $ `external/lame/encoder.h:114:9`!]) fftenergy_s; |
| 1440 | |
| 1441 | /* block type */ |
| 1442 | int ns_attacks[4][4] = { {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0} }; |
| 1443 | int uselongblock[2]; |
| 1444 | |
| 1445 | /* usual variables like loop indices, etc.. */ |
| 1446 | int chn, sb, sblock; |
| 1447 | |
| 1448 | /* chn=2 and 3 = Mid and Side channels */ |
| 1449 | int const n_chn_psy = (cfg->modecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode. == JOINT_STEREOcxx . . $ JOINT_STEREO.) ? 4 : cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; |
| 1450 | |
| 1451 | memcpycxx . . $ memcpy(cc817cb175f282d).(&last_thm[0], &psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[0], sizeof(last_thm)); |
| 1452 | |
| 1453 | vbrpsy_attack_detectioncxx . . $ vbrpsy_attack_detection(691465ad53fd7228).(gfc, buffer, gr_out, masking_ratio, masking_MS_ratio, energy, |
| 1454 | sub_short_factor, ns_attacks, uselongblock); |
| 1455 | |
| 1456 | vbrpsy_compute_block_typecxx . . $ vbrpsy_compute_block_type(c1dc22a9e8db10ba).(cfg, uselongblock); |
| 1457 | |
| 1458 | /* LONG BLOCK CASE */ |
| 1459 | { |
| 1460 | for (chn = 0; chn < n_chn_psy; chn++) { |
| 1461 | int const ch01 = chn & 0x01; |
| 1462 | |
| 1463 | wsamp_l = wsamp_L + ch01; |
| 1464 | vbrpsy_compute_fft_lcxx . . $ vbrpsy_compute_fft_l(6756ddc9682fbc26).(gfc, buffer, chn, gr_out, fftenergy, wsamp_l); |
| 1465 | vbrpsy_compute_loudness_approximation_lcxx . . $ vbrpsy_compute_loudness_approximation_l(1b40bd2dfd421059).(gfc, gr_out, chn, fftenergy); |
| 1466 | vbrpsy_compute_masking_lcxx . . $ vbrpsy_compute_masking_l(6e79c2abe2ce163f).(gfc, fftenergy, eb[chn], thr[chn], chn); |
| 1467 | } |
| 1468 | if (cfg->modecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode. == JOINT_STEREOcxx . . $ JOINT_STEREO.) { |
| 1469 | if ((uselongblock[0] + uselongblock[1]) == 2) { |
| 1470 | vbrpsy_compute_MS_thresholdscxx . . $ vbrpsy_compute_MS_thresholds(49bd6ec1b516b7bf).(const_eb, thr, gdl->mld_cbcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#mld_cb., gfc->ATHcxx . . $ lame_internal_flags#ATH.->cb_lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#cb_l., |
| 1471 | ath_factor, cfg->msfixcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#msfix., gdl->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.); |
| 1472 | } |
| 1473 | } |
| 1474 | /* TODO: apply adaptive ATH masking here ?? */ |
| 1475 | for (chn = 0; chn < n_chn_psy; chn++) { |
| 1476 | convert_partition2scalefac_lcxx . . $ convert_partition2scalefac_l(f119d38c4c2d963d).(gfc, eb[chn], thr[chn], chn); |
| 1477 | convert_partition2scalefac_l_to_scxx . . $ convert_partition2scalefac_l_to_s(f119d38c4c2d963d).(gfc, eb[chn], thr[chn], chn); |
| 1478 | } |
| 1479 | } |
| 1480 | /* SHORT BLOCKS CASE */ |
| 1481 | { |
| 1482 | int const force_short_block_calc = gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->force_short_block_calccxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#force_short_block_calc.; |
| 1483 | for (sblock = 0; sblock < 3; sblock++) { |
| 1484 | for (chn = 0; chn < n_chn_psy; ++chn) { |
| 1485 | int const ch01 = chn & 0x01; |
| 1486 | if (uselongblock[ch01] && !force_short_block_calc) { |
| 1487 | vbrpsy_skip_masking_scxx . . $ vbrpsy_skip_masking_s(b6022c2330fef37d).(gfc, chn, sblock); |
| 1488 | } |
| 1489 | else { |
| 1490 | /* compute masking thresholds for short blocks */ |
| 1491 | wsamp_s = wsamp_S + ch01; |
| 1492 | vbrpsy_compute_fft_scxx . . $ vbrpsy_compute_fft_s(993871e49f4eb56e).(gfc, buffer, chn, sblock, fftenergy_s, wsamp_s); |
| 1493 | vbrpsy_compute_masking_scxx . . $ vbrpsy_compute_masking_s(d238b3830fc1f8ed).(gfc, const_fftenergy_s, eb[chn], thr[chn], chn, |
| 1494 | sblock); |
| 1495 | } |
| 1496 | } |
| 1497 | if (cfg->modecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode. == JOINT_STEREOcxx . . $ JOINT_STEREO.) { |
| 1498 | if ((uselongblock[0] + uselongblock[1]) == 0) { |
| 1499 | vbrpsy_compute_MS_thresholdscxx . . $ vbrpsy_compute_MS_thresholds(49bd6ec1b516b7bf).(const_eb, thr, gds->mld_cbcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#mld_cb., gfc->ATHcxx . . $ lame_internal_flags#ATH.->cb_scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#cb_s., |
| 1500 | ath_factor, cfg->msfixcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#msfix., gds->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.); |
| 1501 | } |
| 1502 | } |
| 1503 | /* TODO: apply adaptive ATH masking here ?? */ |
| 1504 | for (chn = 0; chn < n_chn_psy; ++chn) { |
| 1505 | int const ch01 = chn & 0x01; |
| 1506 | if (!uselongblock[ch01] || force_short_block_calc) { |
| 1507 | convert_partition2scalefac_scxx . . $ convert_partition2scalefac_s(d9c6c06ac48ef3c3).(gfc, eb[chn], thr[chn], chn, sblock); |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | /**** short block pre-echo control ****/ |
| 1513 | for (chn = 0; chn < n_chn_psy; chn++) { |
| 1514 | for (sb = 0; sb < SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; sb++) { |
| 1515 | FLOATcxx . . $ FLOAT# new_thmm[3], prev_thm, t1, t2; |
| 1516 | for (sblock = 0; sblock < 3; sblock++) { |
| 1517 | thmm = psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][sblock]; |
| 1518 | thmm *= NS_PREECHO_ATT0cxx . . $ `external/lame/psymodel.h:56:9`!; |
| 1519 | |
| 1520 | t1 = t2 = thmm; |
| 1521 | |
| 1522 | if (sblock > 0) { |
| 1523 | prev_thm = new_thmm[sblock - 1]; |
| 1524 | } |
| 1525 | else { |
| 1526 | prev_thm = last_thm[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][2]; |
| 1527 | } |
| 1528 | if (ns_attacks[chn][sblock] >= 2 || ns_attacks[chn][sblock + 1] == 1) { |
| 1529 | t1 = NS_INTERPcxx . . $ NS_INTERP(7f54a427cb2e2c3).(prev_thm, thmm, NS_PREECHO_ATT1cxx . . $ `external/lame/psymodel.h:57:9`! * pcfact); |
| 1530 | } |
| 1531 | thmm = Mincxx . . $ `external/lame/util.h:91:17`!(t1, thmm); |
| 1532 | if (ns_attacks[chn][sblock] == 1) { |
| 1533 | t2 = NS_INTERPcxx . . $ NS_INTERP(7f54a427cb2e2c3).(prev_thm, thmm, NS_PREECHO_ATT2cxx . . $ `external/lame/psymodel.h:58:9`! * pcfact); |
| 1534 | } |
| 1535 | else if ((sblock == 0 && psv->last_attackscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_attacks.[chn] == 3) |
| 1536 | || (sblock > 0 && ns_attacks[chn][sblock - 1] == 3)) { /* 2nd preceeding block */ |
| 1537 | switch (sblock) { |
| 1538 | case 0: |
| 1539 | prev_thm = last_thm[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][1]; |
| 1540 | break; |
| 1541 | case 1: |
| 1542 | prev_thm = last_thm[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][2]; |
| 1543 | break; |
| 1544 | case 2: |
| 1545 | prev_thm = new_thmm[0]; |
| 1546 | break; |
| 1547 | } |
| 1548 | t2 = NS_INTERPcxx . . $ NS_INTERP(7f54a427cb2e2c3).(prev_thm, thmm, NS_PREECHO_ATT2cxx . . $ `external/lame/psymodel.h:58:9`! * pcfact); |
| 1549 | } |
| 1550 | |
| 1551 | thmm = Mincxx . . $ `external/lame/util.h:91:17`!(t1, thmm); |
| 1552 | thmm = Mincxx . . $ `external/lame/util.h:91:17`!(t2, thmm); |
| 1553 | |
| 1554 | /* pulse like signal detection for fatboy.wav and so on */ |
| 1555 | thmm *= sub_short_factor[chn][sblock]; |
| 1556 | |
| 1557 | new_thmm[sblock] = thmm; |
| 1558 | } |
| 1559 | for (sblock = 0; sblock < 3; sblock++) { |
| 1560 | psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[chn].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][sblock] = new_thmm[sblock]; |
| 1561 | } |
| 1562 | } |
| 1563 | } |
| 1564 | } |
| 1565 | for (chn = 0; chn < n_chn_psy; chn++) { |
| 1566 | psv->last_attackscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_attacks.[chn] = ns_attacks[chn][2]; |
| 1567 | } |
| 1568 | |
| 1569 | |
| 1570 | /*************************************************************** |
| 1571 | * determine final block type |
| 1572 | ***************************************************************/ |
| 1573 | vbrpsy_apply_block_typecxx . . $ vbrpsy_apply_block_type(567919236745bc71).(psv, cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out., uselongblock, blocktype_d); |
| 1574 | |
| 1575 | /********************************************************************* |
| 1576 | * compute the value of PE to return ... no delay and advance |
| 1577 | *********************************************************************/ |
| 1578 | for (chn = 0; chn < n_chn_psy; chn++) { |
| 1579 | FLOATcxx . . $ FLOAT# *ppe; |
| 1580 | int type; |
| 1581 | III_psy_ratiocxx . . $ III_psy_ratio# const *mr; |
| 1582 | |
| 1583 | if (chn > 1) { |
| 1584 | ppe = percep_MS_entropy - 2; |
| 1585 | type = NORM_TYPEcxx . . $ `external/lame/encoder.h:118:9`!; |
| 1586 | if (blocktype_d[0] == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`! || blocktype_d[1] == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) |
| 1587 | type = SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!; |
| 1588 | mr = &masking_MS_ratio[gr_out][chn - 2]; |
| 1589 | } |
| 1590 | else { |
| 1591 | ppe = percep_entropy; |
| 1592 | type = blocktype_d[chn]; |
| 1593 | mr = &masking_ratio[gr_out][chn]; |
| 1594 | } |
| 1595 | if (type == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { |
| 1596 | ppe[chn] = pecalc_scxx . . $ pecalc_s(5ad1b010e5cdab1).(mr, gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#masking_lower.); |
| 1597 | } |
| 1598 | else { |
| 1599 | ppe[chn] = pecalc_lcxx . . $ pecalc_l(5ad1b010e5cdab1).(mr, gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#masking_lower.); |
| 1600 | } |
| 1601 | |
| 1602 | if (plt) { |
| 1603 | plt->pecxx . . $ plotting_data#pe.[gr_out][chn] = ppe[chn]; |
| 1604 | } |
| 1605 | } |
| 1606 | return 0; |
| 1607 | } |
| 1608 | |
| 1609 | |
| 1610 | |
| 1611 | |
| 1612 | /* |
| 1613 | * The spreading function. Values returned in units of energy |
| 1614 | */ |
| 1615 | static FLOATcxx . . $ FLOAT# |
| 1616 | s3_funccxx . . $ s3_func(fbcf3211dfe1bfd1).(FLOATcxx . . $ FLOAT# bark) |
| 1617 | { |
| 1618 | FLOATcxx . . $ FLOAT# tempx, x, tempy, temp; |
| 1619 | tempx = bark; |
| 1620 | if (tempx >= 0) |
| 1621 | tempx *= 3; |
| 1622 | else |
| 1623 | tempx *= 1.5; |
| 1624 | |
| 1625 | if (tempx >= 0.5 && tempx <= 2.5) { |
| 1626 | temp = tempx - 0.5; |
| 1627 | x = 8.0 * (temp * temp - 2.0 * temp); |
| 1628 | } |
| 1629 | else |
| 1630 | x = 0.0; |
| 1631 | tempx += 0.474; |
| 1632 | tempy = 15.811389 + 7.5 * tempx - 17.5 * sqrt(1.0 + tempx * tempx); |
| 1633 | |
| 1634 | if (tempy <= -60.0) |
| 1635 | return 0.0; |
| 1636 | |
| 1637 | tempx = exp((x + tempy) * LN_TO_LOG10cxx . . $ `external/lame/psymodel.c:162:10`!); |
| 1638 | |
| 1639 | /* Normalization. The spreading function should be normalized so that: |
| 1640 | +inf |
| 1641 | / |
| 1642 | | s3 [ bark ] d(bark) = 1 |
| 1643 | / |
| 1644 | -inf |
| 1645 | */ |
| 1646 | tempx /= .6609193; |
| 1647 | return tempx; |
| 1648 | } |
| 1649 | |
| 1650 | #if 0 |
| 1651 | static FLOAT |
| 1652 | norm_s3_func(void) |
| 1653 | { |
| 1654 | double lim_a = 0, lim_b = 0; |
| 1655 | double x = 0, l, h; |
| 1656 | for (x = 0; s3_func(x) > 1e-20; x -= 1); |
| 1657 | l = x; |
| 1658 | h = 0; |
| 1659 | while (fabs(h - l) > 1e-12) { |
| 1660 | x = (h + l) / 2; |
| 1661 | if (s3_func(x) > 0) { |
| 1662 | h = x; |
| 1663 | } |
| 1664 | else { |
| 1665 | l = x; |
| 1666 | } |
| 1667 | } |
| 1668 | lim_a = l; |
| 1669 | for (x = 0; s3_func(x) > 1e-20; x += 1); |
| 1670 | l = 0; |
| 1671 | h = x; |
| 1672 | while (fabs(h - l) > 1e-12) { |
| 1673 | x = (h + l) / 2; |
| 1674 | if (s3_func(x) > 0) { |
| 1675 | l = x; |
| 1676 | } |
| 1677 | else { |
| 1678 | h = x; |
| 1679 | } |
| 1680 | } |
| 1681 | lim_b = h; |
| 1682 | { |
| 1683 | double sum = 0; |
| 1684 | int const m = 1000; |
| 1685 | int i; |
| 1686 | for (i = 0; i <= m; ++i) { |
| 1687 | double x = lim_a + i * (lim_b - lim_a) / m; |
| 1688 | double y = s3_func(x); |
| 1689 | sum += y; |
| 1690 | } |
| 1691 | { |
| 1692 | double norm = (m + 1) / (sum * (lim_b - lim_a)); |
| 1693 | /*printf( "norm = %lf\n",norm); */ |
| 1694 | return norm; |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | #endif |
| 1699 | |
| 1700 | static FLOATcxx . . $ FLOAT# |
| 1701 | stereo_demaskcxx . . $ stereo_demask(2f2c9d02d22c701f).(double f) |
| 1702 | { |
| 1703 | /* setup stereo demasking thresholds */ |
| 1704 | /* formula reverse enginerred from plot in paper */ |
| 1705 | double arg = freq2barkcxx . . $ freq2bark(fbcf3211dfe1bfd1).(f); |
| 1706 | arg = (Mincxx . . $ `external/lame/util.h:91:17`!(arg, 15.5) / 15.5); |
| 1707 | |
| 1708 | return pow(10.0, 1.25 * (1 - cos(PIcxx . . $ `external/lame/util.h:56:17`! * arg)) - 2.5); |
| 1709 | } |
| 1710 | |
| 1711 | static void |
| 1712 | init_numlinecxx . . $ init_numline(ea5a4f46fbd94ce4).(PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# * gd, FLOATcxx . . $ FLOAT# sfreq, int fft_size, |
| 1713 | int mdct_size, int sbmax, int const *scalepos) |
| 1714 | { |
| 1715 | FLOATcxx . . $ FLOAT# b_frq[CBANDScxx . . $ `external/lame/encoder.h:96:9`! + 1]; |
| 1716 | FLOATcxx . . $ FLOAT# const mdct_freq_frac = sfreq / (2.0f * mdct_size); |
| 1717 | FLOATcxx . . $ FLOAT# const deltafreq = fft_size / (2.0f * mdct_size); |
| 1718 | int partition[HBLKSIZEcxx . . $ `external/lame/encoder.h:112:9`!] = { 0 }; |
| 1719 | int i, j, ni; |
| 1720 | int sfb; |
| 1721 | sfreq /= fft_size; |
| 1722 | j = 0; |
| 1723 | ni = 0; |
| 1724 | /* compute numlines, the number of spectral lines in each partition band */ |
| 1725 | /* each partition band should be about DELBARK wide. */ |
| 1726 | for (i = 0; i < CBANDScxx . . $ `external/lame/encoder.h:96:9`!; i++) { |
| 1727 | FLOATcxx . . $ FLOAT# bark1; |
| 1728 | int j2, nl; |
| 1729 | bark1 = freq2barkcxx . . $ freq2bark(fbcf3211dfe1bfd1).(sfreq * j); |
| 1730 | |
| 1731 | b_frq[i] = sfreq * j; |
| 1732 | |
| 1733 | for (j2 = j; freq2barkcxx . . $ freq2bark(fbcf3211dfe1bfd1).(sfreq * j2) - bark1 < DELBARKcxx . . $ `external/lame/psymodel.h:48:9`! && j2 <= fft_size / 2; j2++); |
| 1734 | |
| 1735 | nl = j2 - j; |
| 1736 | gd->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[i] = nl; |
| 1737 | gd->rnumlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#rnumlines.[i] = (nl > 0) ? (1.0f / nl) : 0; |
| 1738 | |
| 1739 | ni = i + 1; |
| 1740 | |
| 1741 | while (j < j2) { |
| 1742 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j < HBLKSIZEcxx . . $ `external/lame/encoder.h:112:9`!); |
| 1743 | partition[j++] = i; |
| 1744 | } |
| 1745 | if (j > fft_size / 2) { |
| 1746 | j = fft_size / 2; |
| 1747 | ++i; |
| 1748 | break; |
| 1749 | } |
| 1750 | } |
| 1751 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(i < CBANDScxx . . $ `external/lame/encoder.h:96:9`!); |
| 1752 | b_frq[i] = sfreq * j; |
| 1753 | |
| 1754 | gd->n_sbcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#n_sb. = sbmax; |
| 1755 | gd->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart. = ni; |
| 1756 | |
| 1757 | { |
| 1758 | j = 0; |
| 1759 | for (i = 0; i < gd->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; i++) { |
| 1760 | int const nl = gd->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[i]; |
| 1761 | FLOATcxx . . $ FLOAT# const freq = sfreq * (j + nl / 2); |
| 1762 | gd->mld_cbcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#mld_cb.[i] = stereo_demaskcxx . . $ stereo_demask(2f2c9d02d22c701f).(freq); |
| 1763 | j += nl; |
| 1764 | } |
| 1765 | for (; i < CBANDScxx . . $ `external/lame/encoder.h:96:9`!; ++i) { |
| 1766 | gd->mld_cbcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#mld_cb.[i] = 1; |
| 1767 | } |
| 1768 | } |
| 1769 | for (sfb = 0; sfb < sbmax; sfb++) { |
| 1770 | int i1, i2, bo; |
| 1771 | int start = scalepos[sfb]; |
| 1772 | int end = scalepos[sfb + 1]; |
| 1773 | |
| 1774 | i1 = floor(.5 + deltafreq * (start - .5)); |
| 1775 | if (i1 < 0) |
| 1776 | i1 = 0; |
| 1777 | i2 = floor(.5 + deltafreq * (end - .5)); |
| 1778 | |
| 1779 | if (i2 > fft_size / 2) |
| 1780 | i2 = fft_size / 2; |
| 1781 | |
| 1782 | bo = partition[i2]; |
| 1783 | gd->bmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#bm.[sfb] = (partition[i1] + partition[i2]) / 2; |
| 1784 | gd->bocxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#bo.[sfb] = bo; |
| 1785 | |
| 1786 | /* calculate how much of this band belongs to current scalefactor band */ |
| 1787 | { |
| 1788 | FLOATcxx . . $ FLOAT# const f_tmp = mdct_freq_frac * end; |
| 1789 | FLOATcxx . . $ FLOAT# bo_w = (f_tmp - b_frq[bo]) / (b_frq[bo + 1] - b_frq[bo]); |
| 1790 | if (bo_w < 0) { |
| 1791 | bo_w = 0; |
| 1792 | } |
| 1793 | else { |
| 1794 | if (bo_w > 1) { |
| 1795 | bo_w = 1; |
| 1796 | } |
| 1797 | } |
| 1798 | gd->bo_weightcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#bo_weight.[sfb] = bo_w; |
| 1799 | } |
| 1800 | gd->mldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#mld.[sfb] = stereo_demaskcxx . . $ stereo_demask(2f2c9d02d22c701f).(mdct_freq_frac * start); |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | static void |
| 1805 | compute_bark_valuescxx . . $ compute_bark_values(f0f9469dd12fecd4).(PsyConst_CB2SB_tcxx . . $ PsyConst_CB2SB_t# const *gd, FLOATcxx . . $ FLOAT# sfreq, int fft_size, |
| 1806 | FLOATcxx . . $ FLOAT# * bval, FLOATcxx . . $ FLOAT# * bval_width) |
| 1807 | { |
| 1808 | /* compute bark values of each critical band */ |
| 1809 | int k, j = 0, ni = gd->npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; |
| 1810 | sfreq /= fft_size; |
| 1811 | for (k = 0; k < ni; k++) { |
| 1812 | int const w = gd->numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[k]; |
| 1813 | FLOATcxx . . $ FLOAT# bark1, bark2; |
| 1814 | |
| 1815 | bark1 = freq2barkcxx . . $ freq2bark(fbcf3211dfe1bfd1).(sfreq * (j)); |
| 1816 | bark2 = freq2barkcxx . . $ freq2bark(fbcf3211dfe1bfd1).(sfreq * (j + w - 1)); |
| 1817 | bval[k] = .5 * (bark1 + bark2); |
| 1818 | |
| 1819 | bark1 = freq2barkcxx . . $ freq2bark(fbcf3211dfe1bfd1).(sfreq * (j - .5)); |
| 1820 | bark2 = freq2barkcxx . . $ freq2bark(fbcf3211dfe1bfd1).(sfreq * (j + w - .5)); |
| 1821 | bval_width[k] = bark2 - bark1; |
| 1822 | j += w; |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | static int |
| 1827 | init_s3_valuescxx . . $ init_s3_values(e389932dc27b8629).(FLOATcxx . . $ FLOAT# ** p, int (*s3ind)[2], int npart, |
| 1828 | FLOATcxx . . $ FLOAT# const *bval, FLOATcxx . . $ FLOAT# const *bval_width, FLOATcxx . . $ FLOAT# const *norm) |
| 1829 | { |
| 1830 | FLOATcxx . . $ FLOAT# s3[CBANDScxx . . $ `external/lame/encoder.h:96:9`!][CBANDScxx . . $ `external/lame/encoder.h:96:9`!]; |
| 1831 | /* The s3 array is not linear in the bark scale. |
| 1832 | * bval[x] should be used to get the bark value. |
| 1833 | */ |
| 1834 | int i, j, k; |
| 1835 | int numberOfNoneZero = 0; |
| 1836 | |
| 1837 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&s3[0][0], 0, sizeof(s3)); |
| 1838 | |
| 1839 | /* s[i][j], the value of the spreading function, |
| 1840 | * centered at band j (masker), for band i (maskee) |
| 1841 | * |
| 1842 | * i.e.: sum over j to spread into signal barkval=i |
| 1843 | * NOTE: i and j are used opposite as in the ISO docs |
| 1844 | */ |
| 1845 | for (i = 0; i < npart; i++) { |
| 1846 | for (j = 0; j < npart; j++) { |
| 1847 | FLOATcxx . . $ FLOAT# v = s3_funccxx . . $ s3_func(fbcf3211dfe1bfd1).(bval[i] - bval[j]) * bval_width[j]; |
| 1848 | s3[i][j] = v * norm[i]; |
| 1849 | } |
| 1850 | } |
| 1851 | for (i = 0; i < npart; i++) { |
| 1852 | for (j = 0; j < npart; j++) { |
| 1853 | if (s3[i][j] > 0.0f) |
| 1854 | break; |
| 1855 | } |
| 1856 | s3ind[i][0] = j; |
| 1857 | |
| 1858 | for (j = npart - 1; j > 0; j--) { |
| 1859 | if (s3[i][j] > 0.0f) |
| 1860 | break; |
| 1861 | } |
| 1862 | s3ind[i][1] = j; |
| 1863 | numberOfNoneZero += (s3ind[i][1] - s3ind[i][0] + 1); |
| 1864 | } |
| 1865 | *p = lame_calloccxx . . $ `external/lame/machine.h:161:9`!(FLOAT, numberOfNoneZero); |
| 1866 | if (!*p) |
| 1867 | return -1; |
| 1868 | |
| 1869 | k = 0; |
| 1870 | for (i = 0; i < npart; i++) |
| 1871 | for (j = s3ind[i][0]; j <= s3ind[i][1]; j++) |
| 1872 | (*p)[k++] = s3[i][j]; |
| 1873 | |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
| 1877 | int |
| 1878 | psymodel_initcxx . . $ psymodel_init(a5abb0ff158568ac).(lame_global_flagscxx . . $ lame_global_flags# const *gfp) |
| 1879 | { |
| 1880 | lame_internal_flagscxx . . $ lame_internal_flags# *const gfc = gfp->internal_flagscxx . . $ lame_global_struct#internal_flags.; |
| 1881 | SessionConfig_tcxx . . $ SessionConfig_t# *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1882 | PsyStateVar_tcxx . . $ PsyStateVar_t# *const psv = &gfc->sv_psycxx . . $ lame_internal_flags#sv_psy.; |
| 1883 | PsyConst_tcxx . . $ PsyConst_t# *gd; |
| 1884 | int i, j, b, sb, k; |
| 1885 | FLOATcxx . . $ FLOAT# bvl_a = 13, bvl_b = 24; |
| 1886 | FLOATcxx . . $ FLOAT# snr_l_a = 0, snr_l_b = 0; |
| 1887 | FLOATcxx . . $ FLOAT# snr_s_a = -8.25, snr_s_b = -4.5; |
| 1888 | |
| 1889 | FLOATcxx . . $ FLOAT# bval[CBANDScxx . . $ `external/lame/encoder.h:96:9`!]; |
| 1890 | FLOATcxx . . $ FLOAT# bval_width[CBANDScxx . . $ `external/lame/encoder.h:96:9`!]; |
| 1891 | FLOATcxx . . $ FLOAT# norm[CBANDScxx . . $ `external/lame/encoder.h:96:9`!]; |
| 1892 | FLOATcxx . . $ FLOAT# const sfreq = cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out.; |
| 1893 | |
| 1894 | FLOATcxx . . $ FLOAT# xav = 10, xbv = 12; |
| 1895 | FLOATcxx . . $ FLOAT# const minval_low = (0.f - cfg->minvalcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#minval.); |
| 1896 | |
| 1897 | if (gfc->cd_psycxx . . $ lame_internal_flags#cd_psy. != 0) { |
| 1898 | return 0; |
| 1899 | } |
| 1900 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(norm, 0, sizeof(norm)); |
| 1901 | |
| 1902 | gd = lame_calloccxx . . $ `external/lame/machine.h:161:9`!(PsyConst_t, 1); |
| 1903 | gfc->cd_psycxx . . $ lame_internal_flags#cd_psy. = gd; |
| 1904 | |
| 1905 | gd->force_short_block_calccxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#force_short_block_calc. = gfp->experimentalZcxx . . $ lame_global_struct#experimentalZ.; |
| 1906 | |
| 1907 | psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[0] = psv->blocktype_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#blocktype_old.[1] = NORM_TYPEcxx . . $ `external/lame/encoder.h:118:9`!; /* the vbr header is long blocks */ |
| 1908 | |
| 1909 | for (i = 0; i < 4; ++i) { |
| 1910 | for (j = 0; j < CBANDScxx . . $ `external/lame/encoder.h:96:9`!; ++j) { |
| 1911 | psv->nb_l1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_l1.[i][j] = 1e20; |
| 1912 | psv->nb_l2cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_l2.[i][j] = 1e20; |
| 1913 | psv->nb_s1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_s1.[i][j] = psv->nb_s2cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#nb_s2.[i][j] = 1.0; |
| 1914 | } |
| 1915 | for (sb = 0; sb < SBMAX_lcxx . . $ `external/lame/encoder.h:103:9`!; sb++) { |
| 1916 | psv->encxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#en.[i].lcxx . . $ $anonymous_type_fdda207d22d8fb07_1#l.[sb] = 1e20; |
| 1917 | psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[i].lcxx . . $ $anonymous_type_fdda207d22d8fb07_1#l.[sb] = 1e20; |
| 1918 | } |
| 1919 | for (j = 0; j < 3; ++j) { |
| 1920 | for (sb = 0; sb < SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; sb++) { |
| 1921 | psv->encxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#en.[i].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][j] = 1e20; |
| 1922 | psv->thmcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#thm.[i].scxx . . $ $anonymous_type_fdda207d22d8fb07_1#s.[sb][j] = 1e20; |
| 1923 | } |
| 1924 | psv->last_attackscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_attacks.[i] = 0; |
| 1925 | } |
| 1926 | for (j = 0; j < 9; j++) |
| 1927 | psv->last_en_subshortcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#last_en_subshort.[i][j] = 10.; |
| 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | /* init. for loudness approx. -jd 2001 mar 27 */ |
| 1932 | psv->loudness_sq_savecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#loudness_sq_save.[0] = psv->loudness_sq_savecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_5#loudness_sq_save.[1] = 0.0; |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | /************************************************************************* |
| 1937 | * now compute the psychoacoustic model specific constants |
| 1938 | ************************************************************************/ |
| 1939 | /* compute numlines, bo, bm, bval, bval_width, mld */ |
| 1940 | init_numlinecxx . . $ init_numline(ea5a4f46fbd94ce4).(&gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l., sfreq, BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`!, 576, SBMAX_lcxx . . $ `external/lame/encoder.h:103:9`!, gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..lcxx . . $ $anonymous_type_fdda207d22d8fb07_0#l.); |
| 1941 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gd->l.npart < CBANDScxx . . $ `external/lame/encoder.h:96:9`!); |
| 1942 | compute_bark_valuescxx . . $ compute_bark_values(f0f9469dd12fecd4).(&gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l., sfreq, BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`!, bval, bval_width); |
| 1943 | |
| 1944 | /* compute the spreading function */ |
| 1945 | for (i = 0; i < gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; i++) { |
| 1946 | double snr = snr_l_a; |
| 1947 | if (bval[i] >= bvl_a) { |
| 1948 | snr = snr_l_b * (bval[i] - bvl_a) / (bvl_b - bvl_a) |
| 1949 | + snr_l_a * (bvl_b - bval[i]) / (bvl_b - bvl_a); |
| 1950 | } |
| 1951 | norm[i] = pow(10.0, snr / 10.0); |
| 1952 | } |
| 1953 | i = init_s3_valuescxx . . $ init_s3_values(e389932dc27b8629).(&gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3., gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..s3indcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3ind., gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart., bval, bval_width, norm); |
| 1954 | if (i) |
| 1955 | return i; |
| 1956 | |
| 1957 | /* compute long block specific values, ATH and MINVAL */ |
| 1958 | j = 0; |
| 1959 | for (i = 0; i < gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; i++) { |
| 1960 | double x; |
| 1961 | |
| 1962 | /* ATH */ |
| 1963 | x = FLOAT_MAXcxx . . $ `external/lame/machine.h:133:12`!; |
| 1964 | for (k = 0; k < gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[i]; k++, j++) { |
| 1965 | FLOATcxx . . $ FLOAT# const freq = sfreq * j / (1000.0 * BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`!); |
| 1966 | FLOATcxx . . $ FLOAT# level; |
| 1967 | /* freq = Min(.1,freq); *//* ATH below 100 Hz constant, not further climbing */ |
| 1968 | level = ATHformulacxx . . $ ATHformula(e110220ec0e8c77a).(cfg, freq * 1000) - 20; /* scale to FFT units; returned value is in dB */ |
| 1969 | level = pow(10., 0.1 * level); /* convert from dB -> energy */ |
| 1970 | level *= gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[i]; |
| 1971 | if (x > level) |
| 1972 | x = level; |
| 1973 | } |
| 1974 | gfc->ATHcxx . . $ lame_internal_flags#ATH.->cb_lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#cb_l.[i] = x; |
| 1975 | |
| 1976 | /* MINVAL. |
| 1977 | For low freq, the strength of the masking is limited by minval |
| 1978 | this is an ISO MPEG1 thing, dont know if it is really needed */ |
| 1979 | /* FIXME: it does work to reduce low-freq problems in S53-Wind-Sax |
| 1980 | and lead-voice samples, but introduces some 3 kbps bit bloat too. |
| 1981 | TODO: Further refinement of the shape of this hack. |
| 1982 | */ |
| 1983 | x = 20.0 * (bval[i] / xav - 1.0); |
| 1984 | if (x > 6) { |
| 1985 | x = 30; |
| 1986 | } |
| 1987 | if (x < minval_low) { |
| 1988 | x = minval_low; |
| 1989 | } |
| 1990 | if (cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. < 44000) { |
| 1991 | x = 30; |
| 1992 | } |
| 1993 | x -= 8.; |
| 1994 | gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..minvalcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#minval.[i] = pow(10.0, x / 10.) * gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[i]; |
| 1995 | } |
| 1996 | |
| 1997 | /************************************************************************ |
| 1998 | * do the same things for short blocks |
| 1999 | ************************************************************************/ |
| 2000 | init_numlinecxx . . $ init_numline(ea5a4f46fbd94ce4).(&gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s., sfreq, BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`!, 192, SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!, gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.); |
| 2001 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gd->s.npart < CBANDScxx . . $ `external/lame/encoder.h:96:9`!); |
| 2002 | compute_bark_valuescxx . . $ compute_bark_values(f0f9469dd12fecd4).(&gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s., sfreq, BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`!, bval, bval_width); |
| 2003 | |
| 2004 | /* SNR formula. short block is normalized by SNR. is it still right ? */ |
| 2005 | j = 0; |
| 2006 | for (i = 0; i < gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; i++) { |
| 2007 | double x; |
| 2008 | double snr = snr_s_a; |
| 2009 | if (bval[i] >= bvl_a) { |
| 2010 | snr = snr_s_b * (bval[i] - bvl_a) / (bvl_b - bvl_a) |
| 2011 | + snr_s_a * (bvl_b - bval[i]) / (bvl_b - bvl_a); |
| 2012 | } |
| 2013 | norm[i] = pow(10.0, snr / 10.0); |
| 2014 | |
| 2015 | /* ATH */ |
| 2016 | x = FLOAT_MAXcxx . . $ `external/lame/machine.h:133:12`!; |
| 2017 | for (k = 0; k < gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[i]; k++, j++) { |
| 2018 | FLOATcxx . . $ FLOAT# const freq = sfreq * j / (1000.0 * BLKSIZE_scxx . . $ `external/lame/encoder.h:113:9`!); |
| 2019 | FLOATcxx . . $ FLOAT# level; |
| 2020 | /* freq = Min(.1,freq); *//* ATH below 100 Hz constant, not further climbing */ |
| 2021 | level = ATHformulacxx . . $ ATHformula(e110220ec0e8c77a).(cfg, freq * 1000) - 20; /* scale to FFT units; returned value is in dB */ |
| 2022 | level = pow(10., 0.1 * level); /* convert from dB -> energy */ |
| 2023 | level *= gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[i]; |
| 2024 | if (x > level) |
| 2025 | x = level; |
| 2026 | } |
| 2027 | gfc->ATHcxx . . $ lame_internal_flags#ATH.->cb_scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#cb_s.[i] = x; |
| 2028 | |
| 2029 | /* MINVAL. |
| 2030 | For low freq, the strength of the masking is limited by minval |
| 2031 | this is an ISO MPEG1 thing, dont know if it is really needed */ |
| 2032 | x = 7.0 * (bval[i] / xbv - 1.0); |
| 2033 | if (bval[i] > xbv) { |
| 2034 | x *= 1 + log(1 + x) * 3.1; |
| 2035 | } |
| 2036 | if (bval[i] < xbv) { |
| 2037 | x *= 1 + log(1 - x) * 2.3; |
| 2038 | } |
| 2039 | if (x > 6) { |
| 2040 | x = 30; |
| 2041 | } |
| 2042 | if (x < minval_low) { |
| 2043 | x = minval_low; |
| 2044 | } |
| 2045 | if (cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. < 44000) { |
| 2046 | x = 30; |
| 2047 | } |
| 2048 | x -= 8; |
| 2049 | gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..minvalcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#minval.[i] = pow(10.0, x / 10) * gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[i]; |
| 2050 | } |
| 2051 | |
| 2052 | i = init_s3_valuescxx . . $ init_s3_values(e389932dc27b8629).(&gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3., gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..s3indcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3ind., gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart., bval, bval_width, norm); |
| 2053 | if (i) |
| 2054 | return i; |
| 2055 | |
| 2056 | |
| 2057 | init_mask_add_max_valuescxx . . $ init_mask_add_max_values(49f6e7a06ebc5aa8).(); |
| 2058 | init_fftcxx . . $ init_fft(4f558d83b2842a93).(gfc); |
| 2059 | |
| 2060 | /* setup temporal masking */ |
| 2061 | gd->decaycxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#decay. = exp(-1.0 * LOG10cxx . . $ `external/lame/util.h:70:17`! / (temporalmask_sustain_seccxx . . $ `external/lame/psymodel.h:54:9`! * sfreq / 192.0)); |
| 2062 | |
| 2063 | { |
| 2064 | FLOATcxx . . $ FLOAT# msfix; |
| 2065 | msfix = NS_MSFIXcxx . . $ `external/lame/psymodel.h:60:9`!; |
| 2066 | if (cfg->use_safe_joint_stereocxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#use_safe_joint_stereo.) |
| 2067 | msfix = 1.0; |
| 2068 | if (fabs(cfg->msfixcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#msfix.) > 0.0) |
| 2069 | msfix = cfg->msfixcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#msfix.; |
| 2070 | cfg->msfixcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#msfix. = msfix; |
| 2071 | |
| 2072 | /* spread only from npart_l bands. Normally, we use the spreading |
| 2073 | * function to convolve from npart_l down to npart_l bands |
| 2074 | */ |
| 2075 | for (b = 0; b < gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; b++) |
| 2076 | if (gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..s3indcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3ind.[b][1] > gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart. - 1) |
| 2077 | gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..s3indcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3ind.[b][1] = gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart. - 1; |
| 2078 | } |
| 2079 | |
| 2080 | /* prepare for ATH auto adjustment: |
| 2081 | * we want to decrease the ATH by 12 dB per second |
| 2082 | */ |
| 2083 | #define frame_durationcxx . . $ `external/lame/psymodel.c:2083:10`! (576. * cfg->mode_gr / sfreq) |
| 2084 | gfc->ATHcxx . . $ lame_internal_flags#ATH.->decaycxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#decay. = pow(10., -12. / 10. * frame_durationcxx . . $ `external/lame/psymodel.c:2083:10`!); |
| 2085 | gfc->ATHcxx . . $ lame_internal_flags#ATH.->adjust_factorcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#adjust_factor. = 0.01; /* minimum, for leading low loudness */ |
| 2086 | gfc->ATHcxx . . $ lame_internal_flags#ATH.->adjust_limitcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#adjust_limit. = 1.0; /* on lead, allow adjust up to maximum */ |
| 2087 | #undef frame_durationcxx . . $ `external/lame/psymodel.c:2083:10`! |
| 2088 | |
| 2089 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gd->l.bo[SBMAX_lcxx . . $ `external/lame/encoder.h:103:9`! - 1] <= gd->l.npart); |
| 2090 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(gd->s.bo[SBMAX_scxx . . $ `external/lame/encoder.h:104:9`! - 1] <= gd->s.npart); |
| 2091 | |
| 2092 | if (cfg->ATHtypecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#ATHtype. != -1) { |
| 2093 | /* compute equal loudness weights (eql_w) */ |
| 2094 | FLOATcxx . . $ FLOAT# freq; |
| 2095 | FLOATcxx . . $ FLOAT# const freq_inc = (FLOATcxx . . $ FLOAT#) cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. / (FLOATcxx . . $ FLOAT#) (BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`!); |
| 2096 | FLOATcxx . . $ FLOAT# eql_balance = 0.0; |
| 2097 | freq = 0.0; |
| 2098 | for (i = 0; i < BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`! / 2; ++i) { |
| 2099 | /* convert ATH dB to relative power (not dB) */ |
| 2100 | /* to determine eql_w */ |
| 2101 | freq += freq_inc; |
| 2102 | gfc->ATHcxx . . $ lame_internal_flags#ATH.->eql_wcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#eql_w.[i] = 1. / pow(10, ATHformulacxx . . $ ATHformula(e110220ec0e8c77a).(cfg, freq) / 10); |
| 2103 | eql_balance += gfc->ATHcxx . . $ lame_internal_flags#ATH.->eql_wcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#eql_w.[i]; |
| 2104 | } |
| 2105 | eql_balance = 1.0 / eql_balance; |
| 2106 | for (i = BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`! / 2; --i >= 0;) { /* scale weights */ |
| 2107 | gfc->ATHcxx . . $ lame_internal_flags#ATH.->eql_wcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#eql_w.[i] *= eql_balance; |
| 2108 | } |
| 2109 | } |
| 2110 | { |
| 2111 | for (b = j = 0; b < gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; ++b) { |
| 2112 | for (i = 0; i < gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b]; ++i) { |
| 2113 | ++j; |
| 2114 | } |
| 2115 | } |
| 2116 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j == 129); |
| 2117 | for (b = j = 0; b < gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; ++b) { |
| 2118 | for (i = 0; i < gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..numlinescxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#numlines.[b]; ++i) { |
| 2119 | ++j; |
| 2120 | } |
| 2121 | } |
| 2122 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j == 513); |
| 2123 | } |
| 2124 | /* short block attack threshold */ |
| 2125 | { |
| 2126 | float x = gfp->attackthrecxx . . $ lame_global_struct#attackthre.; |
| 2127 | float y = gfp->attackthre_scxx . . $ lame_global_struct#attackthre_s.; |
| 2128 | if (x < 0) { |
| 2129 | x = NSATTACKTHREcxx . . $ `external/lame/psymodel.h:61:9`!; |
| 2130 | } |
| 2131 | if (y < 0) { |
| 2132 | y = NSATTACKTHRE_Scxx . . $ `external/lame/psymodel.h:62:9`!; |
| 2133 | } |
| 2134 | gd->attack_thresholdcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#attack_threshold.[0] = gd->attack_thresholdcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#attack_threshold.[1] = gd->attack_thresholdcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#attack_threshold.[2] = x; |
| 2135 | gd->attack_thresholdcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#attack_threshold.[3] = y; |
| 2136 | } |
| 2137 | { |
| 2138 | float sk_s = -10.f, sk_l = -4.7f; |
| 2139 | static float const sk[] = |
| 2140 | { -7.4, -7.4, -7.4, -9.5, -7.4, -6.1, -5.5, -4.7, -4.7, -4.7, -4.7 }; |
| 2141 | if (gfp->VBR_qcxx . . $ lame_global_struct#VBR_q. < 4) { |
| 2142 | sk_l = sk_s = sk[0]; |
| 2143 | } |
| 2144 | else { |
| 2145 | sk_l = sk_s = sk[gfp->VBR_qcxx . . $ lame_global_struct#VBR_q.] + gfp->VBR_q_fraccxx . . $ lame_global_struct#VBR_q_frac. * (sk[gfp->VBR_qcxx . . $ lame_global_struct#VBR_q.] - sk[gfp->VBR_qcxx . . $ lame_global_struct#VBR_q. + 1]); |
| 2146 | } |
| 2147 | b = 0; |
| 2148 | for (; b < gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; b++) { |
| 2149 | float m = (float) (gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart. - b) / gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; |
| 2150 | gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#masking_lower.[b] = powf(10.f, sk_s * m * 0.1f); |
| 2151 | } |
| 2152 | for (; b < CBANDScxx . . $ `external/lame/encoder.h:96:9`!; ++b) { |
| 2153 | gd->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#masking_lower.[b] = 1.f; |
| 2154 | } |
| 2155 | b = 0; |
| 2156 | for (; b < gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; b++) { |
| 2157 | float m = (float) (gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart. - b) / gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..npartcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#npart.; |
| 2158 | gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#masking_lower.[b] = powf(10.f, sk_l * m * 0.1f); |
| 2159 | } |
| 2160 | for (; b < CBANDScxx . . $ `external/lame/encoder.h:96:9`!; ++b) { |
| 2161 | gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#masking_lower.[b] = 1.f; |
| 2162 | } |
| 2163 | } |
| 2164 | memcpycxx . . $ memcpy(cc817cb175f282d).(&gd->l_to_scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l_to_s., &gd->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l., sizeof(gd->l_to_scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l_to_s.)); |
| 2165 | init_numlinecxx . . $ init_numline(ea5a4f46fbd94ce4).(&gd->l_to_scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l_to_s., sfreq, BLKSIZEcxx . . $ `external/lame/encoder.h:111:9`!, 192, SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!, gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.); |
| 2166 | return 0; |
| 2167 | } |