| 1 | /* |
| 2 | * MP3 quantization |
| 3 | * |
| 4 | * Copyright (c) 1999-2000 Mark Taylor |
| 5 | * Copyright (c) 1999-2003 Takehiro Tominaga |
| 6 | * Copyright (c) 2000-2011 Robert Hegemann |
| 7 | * Copyright (c) 2001-2005 Gabriel Bouvigne |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU Library General Public |
| 11 | * License as published by the Free Software Foundation; either |
| 12 | * version 2 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * Library General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Library General Public |
| 20 | * License along with this library; if not, write to the |
| 21 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 22 | * Boston, MA 02111-1307, USA. |
| 23 | */ |
| 24 | |
| 25 | /* $Id: quantize.c,v 1.219 2017/08/02 19:48:05 robert Exp $ */ |
| 26 | |
| 27 | //#ifdef HAVE_CONFIG_H |
| 28 | #include "lame__config.h"cxx . . $ `<file>/external/lame/lame__config.h`/ |
| 29 | //#endif |
| 30 | |
| 31 | #include "lame.h"cxx . . $ `<file>/external/lame/lame.h`/ |
| 32 | #include "machine.h"cxx . . $ `<file>/external/lame/machine.h`/ |
| 33 | #include "encoder.h"cxx . . $ `<file>/external/lame/encoder.h`/ |
| 34 | #include "util.h"cxx . . $ `<file>/external/lame/util.h`/ |
| 35 | #include "quantize_pvt.h"cxx . . $ `<file>/external/lame/quantize_pvt.h`/ |
| 36 | #include "reservoir.h"cxx . . $ `<file>/external/lame/reservoir.h`/ |
| 37 | #include "bitstream.h"cxx . . $ `<file>/external/lame/bitstream.h`/ |
| 38 | #include "vbrquantize.h"cxx . . $ `<file>/external/lame/vbrquantize.h`/ |
| 39 | #include "quantize.h"cxx . . $ `<file>/external/lame/quantize.h`/ |
| 40 | #ifdef HAVE_XMMINTRIN_H |
| 41 | #include "vector_lame_intrin.h" |
| 42 | #endif |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | /* convert from L/R <-> Mid/Side */ |
| 48 | static void |
| 49 | ms_convertcxx . . $ ms_convert(1076bfecde684d99).(III_side_info_tcxx . . $ III_side_info_t# * l3_side, int gr) |
| 50 | { |
| 51 | int i; |
| 52 | for (i = 0; i < 576; ++i) { |
| 53 | FLOATcxx . . $ FLOAT# l, r; |
| 54 | l = l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][0].xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[i]; |
| 55 | r = l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][1].xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[i]; |
| 56 | l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][0].xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[i] = (l + r) * (FLOATcxx . . $ FLOAT#) (SQRT2cxx . . $ `external/lame/util.h:77:17`! * 0.5); |
| 57 | l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][1].xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[i] = (l - r) * (FLOATcxx . . $ FLOAT#) (SQRT2cxx . . $ `external/lame/util.h:77:17`! * 0.5); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /************************************************************************ |
| 62 | * |
| 63 | * init_outer_loop() |
| 64 | * mt 6/99 |
| 65 | * |
| 66 | * initializes cod_info, scalefac and xrpow |
| 67 | * |
| 68 | * returns 0 if all energies in xr are zero, else 1 |
| 69 | * |
| 70 | ************************************************************************/ |
| 71 | |
| 72 | static void |
| 73 | init_xrpow_core_ccxx . . $ init_xrpow_core_c(858263cd1c0e9d81).(gr_infocxx . . $ gr_info# * const cod_info, FLOATcxx . . $ FLOAT# xrpow[576], int upper, FLOATcxx . . $ FLOAT# * sum) |
| 74 | { |
| 75 | int i; |
| 76 | FLOATcxx . . $ FLOAT# tmp; |
| 77 | *sum = 0; |
| 78 | for (i = 0; i <= upper; ++i) { |
| 79 | tmp = fabscxx . . $ fabs(447c67c6676f75c3).(cod_info->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[i]); |
| 80 | *sum += tmp; |
| 81 | xrpow[i] = sqrtcxx . . $ sqrt(447c67c6676f75c3).(tmp * sqrtcxx . . $ sqrt(447c67c6676f75c3).(tmp)); |
| 82 | |
| 83 | if (xrpow[i] > cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max.) |
| 84 | cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max. = xrpow[i]; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | void |
| 93 | init_xrpow_core_initcxx . . $ init_xrpow_core_init(4f558d83b2842a93).(lame_internal_flagscxx . . $ lame_internal_flags# * const gfc) |
| 94 | { |
| 95 | gfc->init_xrpow_corecxx . . $ lame_internal_flags#init_xrpow_core. = init_xrpow_core_ccxx . . $ init_xrpow_core_c(858263cd1c0e9d81).; |
| 96 | |
| 97 | #if defined(HAVE_XMMINTRIN_H) |
| 98 | if (gfc->CPU_features.SSE) |
| 99 | gfc->init_xrpow_core = init_xrpow_core_sse; |
| 100 | #endif |
| 101 | #ifndef HAVE_NASM |
| 102 | #ifdef MIN_ARCH_SSE |
| 103 | gfc->init_xrpow_core = init_xrpow_core_sse; |
| 104 | #endif |
| 105 | #endif |
| 106 | } |
| 107 | |
| 108 | |
| 109 | |
| 110 | static int |
| 111 | init_xrpowcxx . . $ init_xrpow(37cc32f6f6d0f0d7).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, gr_infocxx . . $ gr_info# * const cod_info, FLOATcxx . . $ FLOAT# xrpow[576]) |
| 112 | { |
| 113 | FLOATcxx . . $ FLOAT# sum = 0; |
| 114 | int i; |
| 115 | int const upper = cod_info->max_nonzero_coeffcxx . . $ $anonymous_type_fdda207d22d8fb07_3#max_nonzero_coeff.; |
| 116 | |
| 117 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(xrpow != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 118 | cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max. = 0; |
| 119 | |
| 120 | /* check if there is some energy we have to quantize |
| 121 | * and calculate xrpow matching our fresh scalefactors |
| 122 | */ |
| 123 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(0 <= upper && upper <= 575); |
| 124 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&(xrpow[upper]), 0, (576 - upper) * sizeof(xrpow[0])); |
| 125 | |
| 126 | |
| 127 | gfc->init_xrpow_corecxx . . $ lame_internal_flags#init_xrpow_core.(cod_info, xrpow, upper, &sum); |
| 128 | |
| 129 | /* return 1 if we have something to quantize, else 0 |
| 130 | */ |
| 131 | if (sum > (FLOATcxx . . $ FLOAT#) 1E-20) { |
| 132 | int j = 0; |
| 133 | if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..substep_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#substep_shaping. & 2) |
| 134 | j = 1; |
| 135 | |
| 136 | for (i = 0; i < cod_info->psymaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psymax.; i++) |
| 137 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..pseudohalfcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#pseudohalf.[i] = j; |
| 138 | |
| 139 | return 1; |
| 140 | } |
| 141 | |
| 142 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&cod_info->l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc.[0], 0, sizeof(int) * 576); |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | /* |
| 151 | Gabriel Bouvigne feb/apr 2003 |
| 152 | Analog silence detection in partitionned sfb21 |
| 153 | or sfb12 for short blocks |
| 154 | |
| 155 | From top to bottom of sfb, changes to 0 |
| 156 | coeffs which are below ath. It stops on the first |
| 157 | coeff higher than ath. |
| 158 | */ |
| 159 | static void |
| 160 | psfb21_analogsilencecxx . . $ psfb21_analogsilence(1f82e55fbceb2106).(lame_internal_flagscxx . . $ lame_internal_flags# const *gfc, gr_infocxx . . $ gr_info# * const cod_info) |
| 161 | { |
| 162 | ATH_tcxx . . $ ATH_t# const *const ATH = gfc->ATHcxx . . $ lame_internal_flags#ATH.; |
| 163 | FLOATcxx . . $ FLOAT# *const xr = cod_info->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.; |
| 164 | |
| 165 | if (cod_info->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. != SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { /* NORM, START or STOP type, but not SHORT blocks */ |
| 166 | int gsfb; |
| 167 | int stop = 0; |
| 168 | for (gsfb = PSFB21cxx . . $ `external/lame/encoder.h:105:9`! - 1; gsfb >= 0 && !stop; gsfb--) { |
| 169 | int const start = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..psfb21cxx . . $ $anonymous_type_fdda207d22d8fb07_0#psfb21.[gsfb]; |
| 170 | int const end = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..psfb21cxx . . $ $anonymous_type_fdda207d22d8fb07_0#psfb21.[gsfb + 1]; |
| 171 | int j; |
| 172 | FLOATcxx . . $ FLOAT# ath21; |
| 173 | ath21 = athAdjustcxx . . $ athAdjust(95d5df56d1097f86).(ATH->adjust_factorcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#adjust_factor., ATH->psfb21cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#psfb21.[gsfb], ATH->floorcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#floor., 0); |
| 174 | |
| 175 | if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..longfactcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#longfact.[21] > 1e-12f) |
| 176 | ath21 *= gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..longfactcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#longfact.[21]; |
| 177 | |
| 178 | for (j = end - 1; j >= start; j--) { |
| 179 | if (fabscxx . . $ fabs(447c67c6676f75c3).(xr[j]) < ath21) |
| 180 | xr[j] = 0; |
| 181 | else { |
| 182 | stop = 1; |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | else { |
| 189 | /*note: short blocks coeffs are reordered */ |
| 190 | int block; |
| 191 | for (block = 0; block < 3; block++) { |
| 192 | |
| 193 | int gsfb; |
| 194 | int stop = 0; |
| 195 | for (gsfb = PSFB12cxx . . $ `external/lame/encoder.h:106:9`! - 1; gsfb >= 0 && !stop; gsfb--) { |
| 196 | int const start = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.[12] * 3 + |
| 197 | (gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.[13] - gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.[12]) * block + |
| 198 | (gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..psfb12cxx . . $ $anonymous_type_fdda207d22d8fb07_0#psfb12.[gsfb] - gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..psfb12cxx . . $ $anonymous_type_fdda207d22d8fb07_0#psfb12.[0]); |
| 199 | int const end = |
| 200 | start + (gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..psfb12cxx . . $ $anonymous_type_fdda207d22d8fb07_0#psfb12.[gsfb + 1] - gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..psfb12cxx . . $ $anonymous_type_fdda207d22d8fb07_0#psfb12.[gsfb]); |
| 201 | int j; |
| 202 | FLOATcxx . . $ FLOAT# ath12; |
| 203 | ath12 = athAdjustcxx . . $ athAdjust(95d5df56d1097f86).(ATH->adjust_factorcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#adjust_factor., ATH->psfb12cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#psfb12.[gsfb], ATH->floorcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_2#floor., 0); |
| 204 | |
| 205 | if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..shortfactcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#shortfact.[12] > 1e-12f) |
| 206 | ath12 *= gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..shortfactcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#shortfact.[12]; |
| 207 | |
| 208 | for (j = end - 1; j >= start; j--) { |
| 209 | if (fabscxx . . $ fabs(447c67c6676f75c3).(xr[j]) < ath12) |
| 210 | xr[j] = 0; |
| 211 | else { |
| 212 | stop = 1; |
| 213 | break; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | } |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | static void |
| 227 | init_outer_loopcxx . . $ init_outer_loop(1f82e55fbceb2106).(lame_internal_flagscxx . . $ lame_internal_flags# const *gfc, gr_infocxx . . $ gr_info# * const cod_info) |
| 228 | { |
| 229 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 230 | int sfb, j; |
| 231 | /* initialize fresh cod_info |
| 232 | */ |
| 233 | cod_info->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length. = 0; |
| 234 | cod_info->big_valuescxx . . $ $anonymous_type_fdda207d22d8fb07_3#big_values. = 0; |
| 235 | cod_info->count1cxx . . $ $anonymous_type_fdda207d22d8fb07_3#count1. = 0; |
| 236 | cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. = 210; |
| 237 | cod_info->scalefac_compresscxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_compress. = 0; |
| 238 | /* mixed_block_flag, block_type was set in psymodel.c */ |
| 239 | cod_info->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[0] = 0; |
| 240 | cod_info->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[1] = 0; |
| 241 | cod_info->table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#table_select.[2] = 0; |
| 242 | cod_info->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[0] = 0; |
| 243 | cod_info->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[1] = 0; |
| 244 | cod_info->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[2] = 0; |
| 245 | cod_info->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[3] = 0; /* this one is always 0 */ |
| 246 | cod_info->region0_countcxx . . $ $anonymous_type_fdda207d22d8fb07_3#region0_count. = 0; |
| 247 | cod_info->region1_countcxx . . $ $anonymous_type_fdda207d22d8fb07_3#region1_count. = 0; |
| 248 | cod_info->preflagcxx . . $ $anonymous_type_fdda207d22d8fb07_3#preflag. = 0; |
| 249 | cod_info->scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale. = 0; |
| 250 | cod_info->count1table_selectcxx . . $ $anonymous_type_fdda207d22d8fb07_3#count1table_select. = 0; |
| 251 | cod_info->part2_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_length. = 0; |
| 252 | if (cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. <= 8000) { |
| 253 | cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. = 17; |
| 254 | cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin. = 9; |
| 255 | cod_info->psy_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psy_lmax. = 17; |
| 256 | } |
| 257 | else { |
| 258 | cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. = SBPSY_lcxx . . $ `external/lame/encoder.h:99:9`!; |
| 259 | cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin. = SBPSY_scxx . . $ `external/lame/encoder.h:100:9`!; |
| 260 | cod_info->psy_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psy_lmax. = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..sfb21_extracxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#sfb21_extra. ? SBMAX_lcxx . . $ `external/lame/encoder.h:103:9`! : SBPSY_lcxx . . $ `external/lame/encoder.h:99:9`!; |
| 261 | } |
| 262 | cod_info->psymaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psymax. = cod_info->psy_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psy_lmax.; |
| 263 | cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax. = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax.; |
| 264 | cod_info->sfbdividecxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbdivide. = 11; |
| 265 | for (sfb = 0; sfb < SBMAX_lcxx . . $ `external/lame/encoder.h:103:9`!; sfb++) { |
| 266 | cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[sfb] |
| 267 | = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..lcxx . . $ $anonymous_type_fdda207d22d8fb07_0#l.[sfb + 1] - gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..lcxx . . $ $anonymous_type_fdda207d22d8fb07_0#l.[sfb]; |
| 268 | cod_info->windowcxx . . $ $anonymous_type_fdda207d22d8fb07_3#window.[sfb] = 3; /* which is always 0. */ |
| 269 | } |
| 270 | if (cod_info->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { |
| 271 | FLOATcxx . . $ FLOAT# ixwork[576]; |
| 272 | FLOATcxx . . $ FLOAT# *ix; |
| 273 | |
| 274 | cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin. = 0; |
| 275 | cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. = 0; |
| 276 | if (cod_info->mixed_block_flagcxx . . $ $anonymous_type_fdda207d22d8fb07_3#mixed_block_flag.) { |
| 277 | /* |
| 278 | * MPEG-1: sfbs 0-7 long block, 3-12 short blocks |
| 279 | * MPEG-2(.5): sfbs 0-5 long block, 3-12 short blocks |
| 280 | */ |
| 281 | cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin. = 3; |
| 282 | cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. = cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr. * 2 + 4; |
| 283 | } |
| 284 | if (cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. <= 8000) { |
| 285 | cod_info->psymaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psymax. |
| 286 | = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. |
| 287 | + 3 * (9 - cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin.); |
| 288 | cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax. = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. + 3 * (9 - cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin.); |
| 289 | } |
| 290 | else { |
| 291 | cod_info->psymaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psymax. |
| 292 | = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. |
| 293 | + 3 * ((gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..sfb21_extracxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#sfb21_extra. ? SBMAX_scxx . . $ `external/lame/encoder.h:104:9`! : SBPSY_scxx . . $ `external/lame/encoder.h:100:9`!) - cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin.); |
| 294 | cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax. = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. + 3 * (SBPSY_scxx . . $ `external/lame/encoder.h:100:9`! - cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin.); |
| 295 | } |
| 296 | cod_info->sfbdividecxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbdivide. = cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax. - 18; |
| 297 | cod_info->psy_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psy_lmax. = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax.; |
| 298 | /* re-order the short blocks, for more efficient encoding below */ |
| 299 | /* By Takehiro TOMINAGA */ |
| 300 | /* |
| 301 | Within each scalefactor band, data is given for successive |
| 302 | time windows, beginning with window 0 and ending with window 2. |
| 303 | Within each window, the quantized values are then arranged in |
| 304 | order of increasing frequency... |
| 305 | */ |
| 306 | ix = &cod_info->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..lcxx . . $ $anonymous_type_fdda207d22d8fb07_0#l.[cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax.]]; |
| 307 | memcpycxx . . $ memcpy(cc817cb175f282d).(ixwork, cod_info->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr., 576 * sizeof(FLOATcxx . . $ FLOAT#)); |
| 308 | for (sfb = cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin.; sfb < SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; sfb++) { |
| 309 | int const start = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.[sfb]; |
| 310 | int const end = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.[sfb + 1]; |
| 311 | int window, l; |
| 312 | for (window = 0; window < 3; window++) { |
| 313 | for (l = start; l < end; l++) { |
| 314 | *ix++ = ixwork[3 * l + window]; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | j = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax.; |
| 320 | for (sfb = cod_info->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin.; sfb < SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; sfb++) { |
| 321 | cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[j] = cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[j + 1] = cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[j + 2] |
| 322 | = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.[sfb + 1] - gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..scxx . . $ $anonymous_type_fdda207d22d8fb07_0#s.[sfb]; |
| 323 | cod_info->windowcxx . . $ $anonymous_type_fdda207d22d8fb07_3#window.[j] = 0; |
| 324 | cod_info->windowcxx . . $ $anonymous_type_fdda207d22d8fb07_3#window.[j + 1] = 1; |
| 325 | cod_info->windowcxx . . $ $anonymous_type_fdda207d22d8fb07_3#window.[j + 2] = 2; |
| 326 | j += 3; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | cod_info->count1bitscxx . . $ $anonymous_type_fdda207d22d8fb07_3#count1bits. = 0; |
| 331 | cod_info->sfb_partition_tablecxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_partition_table. = nr_of_sfb_blockcxx . . $ nr_of_sfb_block.[0][0]; |
| 332 | cod_info->slencxx . . $ $anonymous_type_fdda207d22d8fb07_3#slen.[0] = 0; |
| 333 | cod_info->slencxx . . $ $anonymous_type_fdda207d22d8fb07_3#slen.[1] = 0; |
| 334 | cod_info->slencxx . . $ $anonymous_type_fdda207d22d8fb07_3#slen.[2] = 0; |
| 335 | cod_info->slencxx . . $ $anonymous_type_fdda207d22d8fb07_3#slen.[3] = 0; |
| 336 | |
| 337 | cod_info->max_nonzero_coeffcxx . . $ $anonymous_type_fdda207d22d8fb07_3#max_nonzero_coeff. = 575; |
| 338 | |
| 339 | /* fresh scalefactors are all zero |
| 340 | */ |
| 341 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(cod_info->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac., 0, sizeof(cod_info->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.)); |
| 342 | |
| 343 | if (cfg->vbrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr. != vbr_mtcxx . . $ vbr_mt. && cfg->vbrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr. != vbr_mtrhcxx . . $ vbr_mtrh. && cfg->vbrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr. != vbr_abrcxx . . $ vbr_abr. && cfg->vbrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr. != vbr_offcxx . . $ vbr_off.) { |
| 344 | psfb21_analogsilencecxx . . $ psfb21_analogsilence(1f82e55fbceb2106).(gfc, cod_info); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | /************************************************************************ |
| 351 | * |
| 352 | * bin_search_StepSize() |
| 353 | * |
| 354 | * author/date?? |
| 355 | * |
| 356 | * binary step size search |
| 357 | * used by outer_loop to get a quantizer step size to start with |
| 358 | * |
| 359 | ************************************************************************/ |
| 360 | |
| 361 | typedef enumcxx . . $ $anonymous_type_15c59b7239fc017a_0# { |
| 362 | BINSEARCH_NONEcxx . . $ BINSEARCH_NONE., |
| 363 | BINSEARCH_UPcxx . . $ BINSEARCH_UP., |
| 364 | BINSEARCH_DOWNcxx . . $ BINSEARCH_DOWN. |
| 365 | } binsearchDirection_tcxx . . $ binsearchDirection_t#; |
| 366 | |
| 367 | static int |
| 368 | bin_search_StepSizecxx . . $ bin_search_StepSize(3db1ccb649315c03).(lame_internal_flagscxx . . $ lame_internal_flags# * const gfc, gr_infocxx . . $ gr_info# * const cod_info, |
| 369 | int desired_rate, const int ch, const FLOATcxx . . $ FLOAT# xrpow[576]) |
| 370 | { |
| 371 | int nBits; |
| 372 | int CurrentStep = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..CurrentStepcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#CurrentStep.[ch]; |
| 373 | int flag_GoneOver = 0; |
| 374 | int const start = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..OldValuecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#OldValue.[ch]; |
| 375 | binsearchDirection_tcxx . . $ binsearchDirection_t# Direction = BINSEARCH_NONEcxx . . $ BINSEARCH_NONE.; |
| 376 | cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. = start; |
| 377 | desired_rate -= cod_info->part2_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_length.; |
| 378 | |
| 379 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(CurrentStep); |
| 380 | for (;;) { |
| 381 | int step; |
| 382 | nBits = count_bitscxx . . $ count_bits(a840df18a627c36c).(gfc, xrpow, cod_info, 0); |
| 383 | |
| 384 | if (CurrentStep == 1 || nBits == desired_rate) |
| 385 | break; /* nothing to adjust anymore */ |
| 386 | |
| 387 | if (nBits > desired_rate) { |
| 388 | /* increase Quantize_StepSize */ |
| 389 | if (Direction == BINSEARCH_DOWNcxx . . $ BINSEARCH_DOWN.) |
| 390 | flag_GoneOver = 1; |
| 391 | |
| 392 | if (flag_GoneOver) |
| 393 | CurrentStep /= 2; |
| 394 | Direction = BINSEARCH_UPcxx . . $ BINSEARCH_UP.; |
| 395 | step = CurrentStep; |
| 396 | } |
| 397 | else { |
| 398 | /* decrease Quantize_StepSize */ |
| 399 | if (Direction == BINSEARCH_UPcxx . . $ BINSEARCH_UP.) |
| 400 | flag_GoneOver = 1; |
| 401 | |
| 402 | if (flag_GoneOver) |
| 403 | CurrentStep /= 2; |
| 404 | Direction = BINSEARCH_DOWNcxx . . $ BINSEARCH_DOWN.; |
| 405 | step = -CurrentStep; |
| 406 | } |
| 407 | cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. += step; |
| 408 | if (cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. < 0) { |
| 409 | cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. = 0; |
| 410 | flag_GoneOver = 1; |
| 411 | } |
| 412 | if (cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. > 255) { |
| 413 | cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. = 255; |
| 414 | flag_GoneOver = 1; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cod_info->global_gain >= 0); |
| 419 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cod_info->global_gain < 256); |
| 420 | |
| 421 | while (nBits > desired_rate && cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. < 255) { |
| 422 | cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain.++; |
| 423 | nBits = count_bitscxx . . $ count_bits(a840df18a627c36c).(gfc, xrpow, cod_info, 0); |
| 424 | } |
| 425 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..CurrentStepcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#CurrentStep.[ch] = (start - cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. >= 4) ? 4 : 2; |
| 426 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..OldValuecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#OldValue.[ch] = cod_info->global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain.; |
| 427 | cod_info->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length. = nBits; |
| 428 | return nBits; |
| 429 | } |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | /************************************************************************ |
| 435 | * |
| 436 | * trancate_smallspectrums() |
| 437 | * |
| 438 | * Takehiro TOMINAGA 2002-07-21 |
| 439 | * |
| 440 | * trancate smaller nubmers into 0 as long as the noise threshold is allowed. |
| 441 | * |
| 442 | ************************************************************************/ |
| 443 | static int |
| 444 | floatcomparecxx . . $ floatcompare(9148c8c3ff42c9d8).(const void *v1, const void *v2) |
| 445 | { |
| 446 | const FLOATcxx . . $ FLOAT# *const a = v1, *const b = v2; |
| 447 | if (*a > *b) |
| 448 | return 1; |
| 449 | if (*a < *b) |
| 450 | return -1; |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static void |
| 455 | trancate_smallspectrumscxx . . $ trancate_smallspectrums(93637adad86d83b8).(lame_internal_flagscxx . . $ lame_internal_flags# const *gfc, |
| 456 | gr_infocxx . . $ gr_info# * const gi, const FLOATcxx . . $ FLOAT# * const l3_xmin, FLOATcxx . . $ FLOAT# * const work) |
| 457 | { |
| 458 | int sfb, j, width; |
| 459 | FLOATcxx . . $ FLOAT# distort[SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!]; |
| 460 | calc_noise_resultcxx . . $ calc_noise_result# dummy; |
| 461 | |
| 462 | if ((!(gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..substep_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#substep_shaping. & 4) && gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) |
| 463 | || gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..substep_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#substep_shaping. & 0x80) |
| 464 | return; |
| 465 | (void) calc_noisecxx . . $ calc_noise(b07b625c5fdf63be).(gi, l3_xmin, distort, &dummy, 0); |
| 466 | for (j = 0; j < 576; j++) { |
| 467 | FLOATcxx . . $ FLOAT# xr = 0.0; |
| 468 | if (gi->l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc.[j] != 0) |
| 469 | xr = fabscxx . . $ fabs(447c67c6676f75c3).(gi->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[j]); |
| 470 | work[j] = xr; |
| 471 | } |
| 472 | |
| 473 | j = 0; |
| 474 | sfb = 8; |
| 475 | if (gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) |
| 476 | sfb = 6; |
| 477 | do { |
| 478 | FLOATcxx . . $ FLOAT# allowedNoise, trancateThreshold; |
| 479 | int nsame, start; |
| 480 | |
| 481 | width = gi->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[sfb]; |
| 482 | j += width; |
| 483 | if (distort[sfb] >= 1.0) |
| 484 | continue; |
| 485 | |
| 486 | qsortcxx . . $ qsort(ebb60b13a65e77d7).(&work[j - width], width, sizeof(FLOATcxx . . $ FLOAT#), floatcomparecxx . . $ floatcompare(9148c8c3ff42c9d8).); |
| 487 | if (EQcxx . . $ `external/lame/machine.h:169:9`!(work[j - 1], 0.0)) |
| 488 | continue; /* all zero sfb */ |
| 489 | |
| 490 | allowedNoise = (1.0 - distort[sfb]) * l3_xmin[sfb]; |
| 491 | trancateThreshold = 0.0; |
| 492 | start = 0; |
| 493 | do { |
| 494 | FLOATcxx . . $ FLOAT# noise; |
| 495 | for (nsame = 1; start + nsame < width; nsame++) |
| 496 | if (NEQcxx . . $ `external/lame/machine.h:177:9`!(work[start + j - width], work[start + j + nsame - width])) |
| 497 | break; |
| 498 | |
| 499 | noise = work[start + j - width] * work[start + j - width] * nsame; |
| 500 | if (allowedNoise < noise) { |
| 501 | if (start != 0) |
| 502 | trancateThreshold = work[start + j - width - 1]; |
| 503 | break; |
| 504 | } |
| 505 | allowedNoise -= noise; |
| 506 | start += nsame; |
| 507 | } while (start < width); |
| 508 | if (EQcxx . . $ `external/lame/machine.h:169:9`!(trancateThreshold, 0.0)) |
| 509 | continue; |
| 510 | |
| 511 | /* printf("%e %e %e\n", */ |
| 512 | /* trancateThreshold/l3_xmin[sfb], */ |
| 513 | /* trancateThreshold/(l3_xmin[sfb]*start), */ |
| 514 | /* trancateThreshold/(l3_xmin[sfb]*(start+width)) */ |
| 515 | /* ); */ |
| 516 | /* if (trancateThreshold > 1000*l3_xmin[sfb]*start) */ |
| 517 | /* trancateThreshold = 1000*l3_xmin[sfb]*start; */ |
| 518 | |
| 519 | do { |
| 520 | if (fabscxx . . $ fabs(447c67c6676f75c3).(gi->xrcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xr.[j - width]) <= trancateThreshold) |
| 521 | gi->l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc.[j - width] = 0; |
| 522 | } while (--width > 0); |
| 523 | } while (++sfb < gi->psymaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psymax.); |
| 524 | |
| 525 | gi->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length. = noquant_count_bitscxx . . $ noquant_count_bits(66826c97a8bb1d80).(gfc, gi, 0); |
| 526 | } |
| 527 | |
| 528 | |
| 529 | /************************************************************************* |
| 530 | * |
| 531 | * loop_break() |
| 532 | * |
| 533 | * author/date?? |
| 534 | * |
| 535 | * Function: Returns zero if there is a scalefac which has not been |
| 536 | * amplified. Otherwise it returns one. |
| 537 | * |
| 538 | *************************************************************************/ |
| 539 | |
| 540 | inlinecxx . . $ `external/lame/machine.h:107:10`! static int |
| 541 | loop_breakcxx . . $ loop_break(ba1ccb050e73ef9f).(const gr_infocxx . . $ gr_info# * const cod_info) |
| 542 | { |
| 543 | int sfb; |
| 544 | |
| 545 | for (sfb = 0; sfb < cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax.; sfb++) |
| 546 | if (cod_info->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.[sfb] |
| 547 | + cod_info->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[cod_info->windowcxx . . $ $anonymous_type_fdda207d22d8fb07_3#window.[sfb]] == 0) |
| 548 | return 0; |
| 549 | |
| 550 | return 1; |
| 551 | } |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | /* mt 5/99: Function: Improved calc_noise for a single channel */ |
| 557 | |
| 558 | /************************************************************************* |
| 559 | * |
| 560 | * quant_compare() |
| 561 | * |
| 562 | * author/date?? |
| 563 | * |
| 564 | * several different codes to decide which quantization is better |
| 565 | * |
| 566 | *************************************************************************/ |
| 567 | |
| 568 | static double |
| 569 | penaltiescxx . . $ penalties(447c67c6676f75c3).(double noise) |
| 570 | { |
| 571 | return FAST_LOG10cxx . . $ `external/lame/util.h:96:17`!(0.368 + 0.632 * noise * noise * noise); |
| 572 | } |
| 573 | |
| 574 | static double |
| 575 | get_klemm_noisecxx . . $ get_klemm_noise(f2299877dcba95c5).(const FLOATcxx . . $ FLOAT# * distort, const gr_infocxx . . $ gr_info# * const gi) |
| 576 | { |
| 577 | int sfb; |
| 578 | double klemm_noise = 1E-37; |
| 579 | for (sfb = 0; sfb < gi->psymaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psymax.; sfb++) |
| 580 | klemm_noise += penaltiescxx . . $ penalties(447c67c6676f75c3).(distort[sfb]); |
| 581 | |
| 582 | return Maxcxx . . $ `external/lame/util.h:92:17`!(1e-20, klemm_noise); |
| 583 | } |
| 584 | |
| 585 | inlinecxx . . $ `external/lame/machine.h:107:10`! static int |
| 586 | quant_comparecxx . . $ quant_compare(b7b6e97eaa8dcf84).(const int quant_comp, |
| 587 | const calc_noise_resultcxx . . $ calc_noise_result# * const best, |
| 588 | calc_noise_resultcxx . . $ calc_noise_result# * const calc, const gr_infocxx . . $ gr_info# * const gi, const FLOATcxx . . $ FLOAT# * distort) |
| 589 | { |
| 590 | /* |
| 591 | noise is given in decibels (dB) relative to masking thesholds. |
| 592 | |
| 593 | over_noise: ??? (the previous comment is fully wrong) |
| 594 | tot_noise: ??? (the previous comment is fully wrong) |
| 595 | max_noise: max quantization noise |
| 596 | |
| 597 | */ |
| 598 | int better; |
| 599 | |
| 600 | switch (quant_comp) { |
| 601 | default: |
| 602 | case 9:{ |
| 603 | if (best->over_countcxx . . $ calc_noise_result_t#over_count. > 0) { |
| 604 | /* there are distorted sfb */ |
| 605 | better = calc->over_SSDcxx . . $ calc_noise_result_t#over_SSD. <= best->over_SSDcxx . . $ calc_noise_result_t#over_SSD.; |
| 606 | if (calc->over_SSDcxx . . $ calc_noise_result_t#over_SSD. == best->over_SSDcxx . . $ calc_noise_result_t#over_SSD.) |
| 607 | better = calc->bitscxx . . $ calc_noise_result_t#bits. < best->bitscxx . . $ calc_noise_result_t#bits.; |
| 608 | } |
| 609 | else { |
| 610 | /* no distorted sfb */ |
| 611 | better = ((calc->max_noisecxx . . $ calc_noise_result_t#max_noise. < 0) && |
| 612 | ((calc->max_noisecxx . . $ calc_noise_result_t#max_noise. * 10 + calc->bitscxx . . $ calc_noise_result_t#bits.) <= |
| 613 | (best->max_noisecxx . . $ calc_noise_result_t#max_noise. * 10 + best->bitscxx . . $ calc_noise_result_t#bits.))); |
| 614 | } |
| 615 | break; |
| 616 | } |
| 617 | |
| 618 | case 0: |
| 619 | better = calc->over_countcxx . . $ calc_noise_result_t#over_count. < best->over_countcxx . . $ calc_noise_result_t#over_count. |
| 620 | || (calc->over_countcxx . . $ calc_noise_result_t#over_count. == best->over_countcxx . . $ calc_noise_result_t#over_count. && calc->over_noisecxx . . $ calc_noise_result_t#over_noise. < best->over_noisecxx . . $ calc_noise_result_t#over_noise.) |
| 621 | || (calc->over_countcxx . . $ calc_noise_result_t#over_count. == best->over_countcxx . . $ calc_noise_result_t#over_count. && |
| 622 | EQcxx . . $ `external/lame/machine.h:169:9`!(calc->over_noise, best->over_noise) && calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. < best->tot_noisecxx . . $ calc_noise_result_t#tot_noise.); |
| 623 | break; |
| 624 | |
| 625 | case 8: |
| 626 | calc->max_noisecxx . . $ calc_noise_result_t#max_noise. = get_klemm_noisecxx . . $ get_klemm_noise(f2299877dcba95c5).(distort, gi); |
| 627 | /*lint --fallthrough */ |
| 628 | case 1: |
| 629 | better = calc->max_noisecxx . . $ calc_noise_result_t#max_noise. < best->max_noisecxx . . $ calc_noise_result_t#max_noise.; |
| 630 | break; |
| 631 | case 2: |
| 632 | better = calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. < best->tot_noisecxx . . $ calc_noise_result_t#tot_noise.; |
| 633 | break; |
| 634 | case 3: |
| 635 | better = (calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. < best->tot_noisecxx . . $ calc_noise_result_t#tot_noise.) |
| 636 | && (calc->max_noisecxx . . $ calc_noise_result_t#max_noise. < best->max_noisecxx . . $ calc_noise_result_t#max_noise.); |
| 637 | break; |
| 638 | case 4: |
| 639 | better = (calc->max_noisecxx . . $ calc_noise_result_t#max_noise. <= 0.0 && best->max_noisecxx . . $ calc_noise_result_t#max_noise. > 0.2) |
| 640 | || (calc->max_noisecxx . . $ calc_noise_result_t#max_noise. <= 0.0 && |
| 641 | best->max_noisecxx . . $ calc_noise_result_t#max_noise. < 0.0 && |
| 642 | best->max_noisecxx . . $ calc_noise_result_t#max_noise. > calc->max_noisecxx . . $ calc_noise_result_t#max_noise. - 0.2 && calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. < best->tot_noisecxx . . $ calc_noise_result_t#tot_noise.) |
| 643 | || (calc->max_noisecxx . . $ calc_noise_result_t#max_noise. <= 0.0 && |
| 644 | best->max_noisecxx . . $ calc_noise_result_t#max_noise. > 0.0 && |
| 645 | best->max_noisecxx . . $ calc_noise_result_t#max_noise. > calc->max_noisecxx . . $ calc_noise_result_t#max_noise. - 0.2 && |
| 646 | calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. < best->tot_noisecxx . . $ calc_noise_result_t#tot_noise. + best->over_noisecxx . . $ calc_noise_result_t#over_noise.) |
| 647 | || (calc->max_noisecxx . . $ calc_noise_result_t#max_noise. > 0.0 && |
| 648 | best->max_noisecxx . . $ calc_noise_result_t#max_noise. > -0.05 && |
| 649 | best->max_noisecxx . . $ calc_noise_result_t#max_noise. > calc->max_noisecxx . . $ calc_noise_result_t#max_noise. - 0.1 && |
| 650 | calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. + calc->over_noisecxx . . $ calc_noise_result_t#over_noise. < best->tot_noisecxx . . $ calc_noise_result_t#tot_noise. + best->over_noisecxx . . $ calc_noise_result_t#over_noise.) |
| 651 | || (calc->max_noisecxx . . $ calc_noise_result_t#max_noise. > 0.0 && |
| 652 | best->max_noisecxx . . $ calc_noise_result_t#max_noise. > -0.1 && |
| 653 | best->max_noisecxx . . $ calc_noise_result_t#max_noise. > calc->max_noisecxx . . $ calc_noise_result_t#max_noise. - 0.15 && |
| 654 | calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. + calc->over_noisecxx . . $ calc_noise_result_t#over_noise. + calc->over_noisecxx . . $ calc_noise_result_t#over_noise. < |
| 655 | best->tot_noisecxx . . $ calc_noise_result_t#tot_noise. + best->over_noisecxx . . $ calc_noise_result_t#over_noise. + best->over_noisecxx . . $ calc_noise_result_t#over_noise.); |
| 656 | break; |
| 657 | case 5: |
| 658 | better = calc->over_noisecxx . . $ calc_noise_result_t#over_noise. < best->over_noisecxx . . $ calc_noise_result_t#over_noise. |
| 659 | || (EQcxx . . $ `external/lame/machine.h:169:9`!(calc->over_noise, best->over_noise) && calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. < best->tot_noisecxx . . $ calc_noise_result_t#tot_noise.); |
| 660 | break; |
| 661 | case 6: |
| 662 | better = calc->over_noisecxx . . $ calc_noise_result_t#over_noise. < best->over_noisecxx . . $ calc_noise_result_t#over_noise. |
| 663 | || (EQcxx . . $ `external/lame/machine.h:169:9`!(calc->over_noise, best->over_noise) && |
| 664 | (calc->max_noisecxx . . $ calc_noise_result_t#max_noise. < best->max_noisecxx . . $ calc_noise_result_t#max_noise. |
| 665 | || (EQcxx . . $ `external/lame/machine.h:169:9`!(calc->max_noise, best->max_noise) && calc->tot_noisecxx . . $ calc_noise_result_t#tot_noise. <= best->tot_noisecxx . . $ calc_noise_result_t#tot_noise.) |
| 666 | )); |
| 667 | break; |
| 668 | case 7: |
| 669 | better = calc->over_countcxx . . $ calc_noise_result_t#over_count. < best->over_countcxx . . $ calc_noise_result_t#over_count. || calc->over_noisecxx . . $ calc_noise_result_t#over_noise. < best->over_noisecxx . . $ calc_noise_result_t#over_noise.; |
| 670 | break; |
| 671 | } |
| 672 | |
| 673 | |
| 674 | if (best->over_countcxx . . $ calc_noise_result_t#over_count. == 0) { |
| 675 | /* |
| 676 | If no distorted bands, only use this quantization |
| 677 | if it is better, and if it uses less bits. |
| 678 | Unfortunately, part2_3_length is sometimes a poor |
| 679 | estimator of the final size at low bitrates. |
| 680 | */ |
| 681 | better = better && calc->bitscxx . . $ calc_noise_result_t#bits. < best->bitscxx . . $ calc_noise_result_t#bits.; |
| 682 | } |
| 683 | |
| 684 | |
| 685 | return better; |
| 686 | } |
| 687 | |
| 688 | |
| 689 | |
| 690 | /************************************************************************* |
| 691 | * |
| 692 | * amp_scalefac_bands() |
| 693 | * |
| 694 | * author/date?? |
| 695 | * |
| 696 | * Amplify the scalefactor bands that violate the masking threshold. |
| 697 | * See ISO 11172-3 Section C.1.5.4.3.5 |
| 698 | * |
| 699 | * distort[] = noise/masking |
| 700 | * distort[] > 1 ==> noise is not masked |
| 701 | * distort[] < 1 ==> noise is masked |
| 702 | * max_dist = maximum value of distort[] |
| 703 | * |
| 704 | * Three algorithms: |
| 705 | * noise_shaping_amp |
| 706 | * 0 Amplify all bands with distort[]>1. |
| 707 | * |
| 708 | * 1 Amplify all bands with distort[] >= max_dist^(.5); |
| 709 | * ( 50% in the db scale) |
| 710 | * |
| 711 | * 2 Amplify first band with distort[] >= max_dist; |
| 712 | * |
| 713 | * |
| 714 | * For algorithms 0 and 1, if max_dist < 1, then amplify all bands |
| 715 | * with distort[] >= .95*max_dist. This is to make sure we always |
| 716 | * amplify at least one band. |
| 717 | * |
| 718 | * |
| 719 | *************************************************************************/ |
| 720 | static void |
| 721 | amp_scalefac_bandscxx . . $ amp_scalefac_bands(40cc8ef038fb26bc).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, |
| 722 | gr_infocxx . . $ gr_info# * const cod_info, FLOATcxx . . $ FLOAT# const *distort, FLOATcxx . . $ FLOAT# xrpow[576], int bRefine) |
| 723 | { |
| 724 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 725 | int j, sfb; |
| 726 | FLOATcxx . . $ FLOAT# ifqstep34, trigger; |
| 727 | int noise_shaping_amp; |
| 728 | |
| 729 | if (cod_info->scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale. == 0) { |
| 730 | ifqstep34 = 1.29683955465100964055; /* 2**(.75*.5) */ |
| 731 | } |
| 732 | else { |
| 733 | ifqstep34 = 1.68179283050742922612; /* 2**(.75*1) */ |
| 734 | } |
| 735 | |
| 736 | /* compute maximum value of distort[] */ |
| 737 | trigger = 0; |
| 738 | for (sfb = 0; sfb < cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax.; sfb++) { |
| 739 | if (trigger < distort[sfb]) |
| 740 | trigger = distort[sfb]; |
| 741 | } |
| 742 | |
| 743 | noise_shaping_amp = cfg->noise_shaping_ampcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#noise_shaping_amp.; |
| 744 | if (noise_shaping_amp == 3) { |
| 745 | if (bRefine == 1) |
| 746 | noise_shaping_amp = 2; |
| 747 | else |
| 748 | noise_shaping_amp = 1; |
| 749 | } |
| 750 | switch (noise_shaping_amp) { |
| 751 | case 2: |
| 752 | /* amplify exactly 1 band */ |
| 753 | break; |
| 754 | |
| 755 | case 1: |
| 756 | /* amplify bands within 50% of max (on db scale) */ |
| 757 | if (trigger > 1.0) |
| 758 | trigger = powcxx . . $ pow(d8e7e0733fa41c87).(trigger, .5); |
| 759 | else |
| 760 | trigger *= .95; |
| 761 | break; |
| 762 | |
| 763 | case 0: |
| 764 | default: |
| 765 | /* ISO algorithm. amplify all bands with distort>1 */ |
| 766 | if (trigger > 1.0) |
| 767 | trigger = 1.0; |
| 768 | else |
| 769 | trigger *= .95; |
| 770 | break; |
| 771 | } |
| 772 | |
| 773 | j = 0; |
| 774 | for (sfb = 0; sfb < cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax.; sfb++) { |
| 775 | int const width = cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[sfb]; |
| 776 | int l; |
| 777 | j += width; |
| 778 | if (distort[sfb] < trigger) |
| 779 | continue; |
| 780 | |
| 781 | if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..substep_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#substep_shaping. & 2) { |
| 782 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..pseudohalfcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#pseudohalf.[sfb] = !gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..pseudohalfcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#pseudohalf.[sfb]; |
| 783 | if (!gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..pseudohalfcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#pseudohalf.[sfb] && cfg->noise_shaping_ampcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#noise_shaping_amp. == 2) |
| 784 | return; |
| 785 | } |
| 786 | cod_info->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.[sfb]++; |
| 787 | for (l = -width; l < 0; l++) { |
| 788 | xrpow[j + l] *= ifqstep34; |
| 789 | if (xrpow[j + l] > cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max.) |
| 790 | cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max. = xrpow[j + l]; |
| 791 | } |
| 792 | |
| 793 | if (cfg->noise_shaping_ampcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#noise_shaping_amp. == 2) |
| 794 | return; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /************************************************************************* |
| 799 | * |
| 800 | * inc_scalefac_scale() |
| 801 | * |
| 802 | * Takehiro Tominaga 2000-xx-xx |
| 803 | * |
| 804 | * turns on scalefac scale and adjusts scalefactors |
| 805 | * |
| 806 | *************************************************************************/ |
| 807 | |
| 808 | static void |
| 809 | inc_scalefac_scalecxx . . $ inc_scalefac_scale(1c2c1932bd2cc093).(gr_infocxx . . $ gr_info# * const cod_info, FLOATcxx . . $ FLOAT# xrpow[576]) |
| 810 | { |
| 811 | int l, j, sfb; |
| 812 | const FLOATcxx . . $ FLOAT# ifqstep34 = 1.29683955465100964055; |
| 813 | |
| 814 | j = 0; |
| 815 | for (sfb = 0; sfb < cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax.; sfb++) { |
| 816 | int const width = cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[sfb]; |
| 817 | int s = cod_info->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.[sfb]; |
| 818 | if (cod_info->preflagcxx . . $ $anonymous_type_fdda207d22d8fb07_3#preflag.) |
| 819 | s += pretabcxx . . $ pretab.[sfb]; |
| 820 | j += width; |
| 821 | if (s & 1) { |
| 822 | s++; |
| 823 | for (l = -width; l < 0; l++) { |
| 824 | xrpow[j + l] *= ifqstep34; |
| 825 | if (xrpow[j + l] > cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max.) |
| 826 | cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max. = xrpow[j + l]; |
| 827 | } |
| 828 | } |
| 829 | cod_info->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.[sfb] = s >> 1; |
| 830 | } |
| 831 | cod_info->preflagcxx . . $ $anonymous_type_fdda207d22d8fb07_3#preflag. = 0; |
| 832 | cod_info->scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale. = 1; |
| 833 | } |
| 834 | |
| 835 | |
| 836 | |
| 837 | /************************************************************************* |
| 838 | * |
| 839 | * inc_subblock_gain() |
| 840 | * |
| 841 | * Takehiro Tominaga 2000-xx-xx |
| 842 | * |
| 843 | * increases the subblock gain and adjusts scalefactors |
| 844 | * |
| 845 | *************************************************************************/ |
| 846 | |
| 847 | static int |
| 848 | inc_subblock_gaincxx . . $ inc_subblock_gain(d763f8f1cb2f1cb7).(const lame_internal_flagscxx . . $ lame_internal_flags# * const gfc, gr_infocxx . . $ gr_info# * const cod_info, FLOATcxx . . $ FLOAT# xrpow[576]) |
| 849 | { |
| 850 | int sfb, window; |
| 851 | int *const scalefac = cod_info->scalefaccxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac.; |
| 852 | |
| 853 | /* subbloc_gain can't do anything in the long block region */ |
| 854 | for (sfb = 0; sfb < cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax.; sfb++) { |
| 855 | if (scalefac[sfb] >= 16) |
| 856 | return 1; |
| 857 | } |
| 858 | |
| 859 | for (window = 0; window < 3; window++) { |
| 860 | int s1, s2, l, j; |
| 861 | s1 = s2 = 0; |
| 862 | |
| 863 | for (sfb = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. + window; sfb < cod_info->sfbdividecxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbdivide.; sfb += 3) { |
| 864 | if (s1 < scalefac[sfb]) |
| 865 | s1 = scalefac[sfb]; |
| 866 | } |
| 867 | for (; sfb < cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax.; sfb += 3) { |
| 868 | if (s2 < scalefac[sfb]) |
| 869 | s2 = scalefac[sfb]; |
| 870 | } |
| 871 | |
| 872 | if (s1 < 16 && s2 < 8) |
| 873 | continue; |
| 874 | |
| 875 | if (cod_info->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[window] >= 7) |
| 876 | return 1; |
| 877 | |
| 878 | /* even though there is no scalefactor for sfb12 |
| 879 | * subblock gain affects upper frequencies too, that's why |
| 880 | * we have to go up to SBMAX_s |
| 881 | */ |
| 882 | cod_info->subblock_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#subblock_gain.[window]++; |
| 883 | j = gfc->scalefac_bandcxx . . $ lame_internal_flags#scalefac_band..lcxx . . $ $anonymous_type_fdda207d22d8fb07_0#l.[cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax.]; |
| 884 | for (sfb = cod_info->sfb_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_lmax. + window; sfb < cod_info->sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax.; sfb += 3) { |
| 885 | FLOATcxx . . $ FLOAT# amp; |
| 886 | int const width = cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[sfb]; |
| 887 | int s = scalefac[sfb]; |
| 888 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(s >= 0); |
| 889 | s = s - (4 >> cod_info->scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale.); |
| 890 | if (s >= 0) { |
| 891 | scalefac[sfb] = s; |
| 892 | j += width * 3; |
| 893 | continue; |
| 894 | } |
| 895 | |
| 896 | scalefac[sfb] = 0; |
| 897 | { |
| 898 | int const gain = 210 + (s << (cod_info->scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale. + 1)); |
| 899 | amp = IPOW20cxx . . $ `external/lame/machine.h:92:9`!(gain); |
| 900 | } |
| 901 | j += width * (window + 1); |
| 902 | for (l = -width; l < 0; l++) { |
| 903 | xrpow[j + l] *= amp; |
| 904 | if (xrpow[j + l] > cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max.) |
| 905 | cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max. = xrpow[j + l]; |
| 906 | } |
| 907 | j += width * (3 - window - 1); |
| 908 | } |
| 909 | |
| 910 | { |
| 911 | FLOATcxx . . $ FLOAT# const amp = IPOW20cxx . . $ `external/lame/machine.h:92:9`!(202); |
| 912 | j += cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[sfb] * (window + 1); |
| 913 | for (l = -cod_info->widthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#width.[sfb]; l < 0; l++) { |
| 914 | xrpow[j + l] *= amp; |
| 915 | if (xrpow[j + l] > cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max.) |
| 916 | cod_info->xrpow_maxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#xrpow_max. = xrpow[j + l]; |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | |
| 924 | |
| 925 | /******************************************************************** |
| 926 | * |
| 927 | * balance_noise() |
| 928 | * |
| 929 | * Takehiro Tominaga /date?? |
| 930 | * Robert Hegemann 2000-09-06: made a function of it |
| 931 | * |
| 932 | * amplifies scalefactor bands, |
| 933 | * - if all are already amplified returns 0 |
| 934 | * - if some bands are amplified too much: |
| 935 | * * try to increase scalefac_scale |
| 936 | * * if already scalefac_scale was set |
| 937 | * try on short blocks to increase subblock gain |
| 938 | * |
| 939 | ********************************************************************/ |
| 940 | inlinecxx . . $ `external/lame/machine.h:107:10`! static int |
| 941 | balance_noisecxx . . $ balance_noise(72e30158389f37d3).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, |
| 942 | gr_infocxx . . $ gr_info# * const cod_info, FLOATcxx . . $ FLOAT# const *distort, FLOATcxx . . $ FLOAT# xrpow[576], int bRefine) |
| 943 | { |
| 944 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 945 | int status; |
| 946 | |
| 947 | amp_scalefac_bandscxx . . $ amp_scalefac_bands(40cc8ef038fb26bc).(gfc, cod_info, distort, xrpow, bRefine); |
| 948 | |
| 949 | /* check to make sure we have not amplified too much |
| 950 | * loop_break returns 0 if there is an unamplified scalefac |
| 951 | * scale_bitcount returns 0 if no scalefactors are too large |
| 952 | */ |
| 953 | |
| 954 | status = loop_breakcxx . . $ loop_break(ba1ccb050e73ef9f).(cod_info); |
| 955 | |
| 956 | if (status) |
| 957 | return 0; /* all bands amplified */ |
| 958 | |
| 959 | /* not all scalefactors have been amplified. so these |
| 960 | * scalefacs are possibly valid. encode them: |
| 961 | */ |
| 962 | status = scale_bitcountcxx . . $ scale_bitcount(693b474959d9bacf).(gfc, cod_info); |
| 963 | |
| 964 | if (!status) |
| 965 | return 1; /* amplified some bands not exceeding limits */ |
| 966 | |
| 967 | /* some scalefactors are too large. |
| 968 | * lets try setting scalefac_scale=1 |
| 969 | */ |
| 970 | if (cfg->noise_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#noise_shaping. > 1) { |
| 971 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..pseudohalfcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#pseudohalf.[0], 0, sizeof(gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..pseudohalfcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#pseudohalf.)); |
| 972 | if (!cod_info->scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale.) { |
| 973 | inc_scalefac_scalecxx . . $ inc_scalefac_scale(1c2c1932bd2cc093).(cod_info, xrpow); |
| 974 | status = 0; |
| 975 | } |
| 976 | else { |
| 977 | if (cod_info->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`! && cfg->subblock_gaincxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#subblock_gain. > 0) { |
| 978 | status = inc_subblock_gaincxx . . $ inc_subblock_gain(d763f8f1cb2f1cb7).(gfc, cod_info, xrpow) |
| 979 | || loop_breakcxx . . $ loop_break(ba1ccb050e73ef9f).(cod_info); |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | if (!status) { |
| 985 | status = scale_bitcountcxx . . $ scale_bitcount(693b474959d9bacf).(gfc, cod_info); |
| 986 | } |
| 987 | return !status; |
| 988 | } |
| 989 | |
| 990 | |
| 991 | |
| 992 | /************************************************************************ |
| 993 | * |
| 994 | * outer_loop () |
| 995 | * |
| 996 | * Function: The outer iteration loop controls the masking conditions |
| 997 | * of all scalefactorbands. It computes the best scalefac and |
| 998 | * global gain. This module calls the inner iteration loop |
| 999 | * |
| 1000 | * mt 5/99 completely rewritten to allow for bit reservoir control, |
| 1001 | * mid/side channels with L/R or mid/side masking thresholds, |
| 1002 | * and chooses best quantization instead of last quantization when |
| 1003 | * no distortion free quantization can be found. |
| 1004 | * |
| 1005 | * added VBR support mt 5/99 |
| 1006 | * |
| 1007 | * some code shuffle rh 9/00 |
| 1008 | ************************************************************************/ |
| 1009 | |
| 1010 | static int |
| 1011 | outer_loopcxx . . $ outer_loop(c0039c6f518de0c8).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, gr_infocxx . . $ gr_info# * const cod_info, const FLOATcxx . . $ FLOAT# * const l3_xmin, /* allowed distortion */ |
| 1012 | FLOATcxx . . $ FLOAT# xrpow[576], /* coloured magnitudes of spectral */ |
| 1013 | const int ch, const int targ_bits) |
| 1014 | { /* maximum allowed bits */ |
| 1015 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1016 | gr_infocxx . . $ gr_info# cod_info_w; |
| 1017 | FLOATcxx . . $ FLOAT# save_xrpow[576]; |
| 1018 | FLOATcxx . . $ FLOAT# distort[SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!]; |
| 1019 | calc_noise_resultcxx . . $ calc_noise_result# best_noise_info; |
| 1020 | int huff_bits; |
| 1021 | int better; |
| 1022 | int age; |
| 1023 | calc_noise_datacxx . . $ calc_noise_data# prev_noise; |
| 1024 | int best_part2_3_length = 9999999; |
| 1025 | int bEndOfSearch = 0; |
| 1026 | int bRefine = 0; |
| 1027 | int best_ggain_pass1 = 0; |
| 1028 | |
| 1029 | (void) bin_search_StepSizecxx . . $ bin_search_StepSize(3db1ccb649315c03).(gfc, cod_info, targ_bits, ch, xrpow); |
| 1030 | |
| 1031 | if (!cfg->noise_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#noise_shaping.) |
| 1032 | /* fast mode, no noise shaping, we are ready */ |
| 1033 | return 100; /* default noise_info.over_count */ |
| 1034 | |
| 1035 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&prev_noise, 0, sizeof(calc_noise_datacxx . . $ calc_noise_data#)); |
| 1036 | |
| 1037 | |
| 1038 | /* compute the distortion in this quantization */ |
| 1039 | /* coefficients and thresholds both l/r (or both mid/side) */ |
| 1040 | (void) calc_noisecxx . . $ calc_noise(b07b625c5fdf63be).(cod_info, l3_xmin, distort, &best_noise_info, &prev_noise); |
| 1041 | best_noise_info.bitscxx . . $ calc_noise_result_t#bits. = cod_info->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length.; |
| 1042 | |
| 1043 | cod_info_w = *cod_info; |
| 1044 | age = 0; |
| 1045 | /* if (cfg->vbr == vbr_rh || cfg->vbr == vbr_mtrh) */ |
| 1046 | memcpycxx . . $ memcpy(cc817cb175f282d).(save_xrpow, xrpow, sizeof(FLOATcxx . . $ FLOAT#) * 576); |
| 1047 | |
| 1048 | while (!bEndOfSearch) { |
| 1049 | /* BEGIN MAIN LOOP */ |
| 1050 | do { |
| 1051 | calc_noise_resultcxx . . $ calc_noise_result# noise_info; |
| 1052 | int search_limit; |
| 1053 | int maxggain = 255; |
| 1054 | |
| 1055 | /* When quantization with no distorted bands is found, |
| 1056 | * allow up to X new unsuccesful tries in serial. This |
| 1057 | * gives us more possibilities for different quant_compare modes. |
| 1058 | * Much more than 3 makes not a big difference, it is only slower. |
| 1059 | */ |
| 1060 | |
| 1061 | if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..substep_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#substep_shaping. & 2) { |
| 1062 | search_limit = 20; |
| 1063 | } |
| 1064 | else { |
| 1065 | search_limit = 3; |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | /* Check if the last scalefactor band is distorted. |
| 1071 | * in VBR mode we can't get rid of the distortion, so quit now |
| 1072 | * and VBR mode will try again with more bits. |
| 1073 | * (makes a 10% speed increase, the files I tested were |
| 1074 | * binary identical, 2000/05/20 Robert Hegemann) |
| 1075 | * distort[] > 1 means noise > allowed noise |
| 1076 | */ |
| 1077 | if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..sfb21_extracxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#sfb21_extra.) { |
| 1078 | if (distort[cod_info_w.sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax.] > 1.0) |
| 1079 | break; |
| 1080 | if (cod_info_w.block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`! |
| 1081 | && (distort[cod_info_w.sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax. + 1] > 1.0 |
| 1082 | || distort[cod_info_w.sfbmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfbmax. + 2] > 1.0)) |
| 1083 | break; |
| 1084 | } |
| 1085 | |
| 1086 | /* try a new scalefactor conbination on cod_info_w */ |
| 1087 | if (balance_noisecxx . . $ balance_noise(72e30158389f37d3).(gfc, &cod_info_w, distort, xrpow, bRefine) == 0) |
| 1088 | break; |
| 1089 | if (cod_info_w.scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale.) |
| 1090 | maxggain = 254; |
| 1091 | |
| 1092 | /* inner_loop starts with the initial quantization step computed above |
| 1093 | * and slowly increases until the bits < huff_bits. |
| 1094 | * Thus it is important not to start with too large of an inital |
| 1095 | * quantization step. Too small is ok, but inner_loop will take longer |
| 1096 | */ |
| 1097 | huff_bits = targ_bits - cod_info_w.part2_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_length.; |
| 1098 | if (huff_bits <= 0) |
| 1099 | break; |
| 1100 | |
| 1101 | /* increase quantizer stepsize until needed bits are below maximum |
| 1102 | */ |
| 1103 | while ((cod_info_w.part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length. |
| 1104 | = count_bitscxx . . $ count_bits(a840df18a627c36c).(gfc, xrpow, &cod_info_w, &prev_noise)) > huff_bits |
| 1105 | && cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. <= maxggain) |
| 1106 | cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain.++; |
| 1107 | |
| 1108 | if (cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. > maxggain) |
| 1109 | break; |
| 1110 | |
| 1111 | if (best_noise_info.over_countcxx . . $ calc_noise_result_t#over_count. == 0) { |
| 1112 | |
| 1113 | while ((cod_info_w.part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length. |
| 1114 | = count_bitscxx . . $ count_bits(a840df18a627c36c).(gfc, xrpow, &cod_info_w, &prev_noise)) > best_part2_3_length |
| 1115 | && cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. <= maxggain) |
| 1116 | cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain.++; |
| 1117 | |
| 1118 | if (cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. > maxggain) |
| 1119 | break; |
| 1120 | } |
| 1121 | |
| 1122 | /* compute the distortion in this quantization */ |
| 1123 | (void) calc_noisecxx . . $ calc_noise(b07b625c5fdf63be).(&cod_info_w, l3_xmin, distort, &noise_info, &prev_noise); |
| 1124 | noise_info.bitscxx . . $ calc_noise_result_t#bits. = cod_info_w.part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length.; |
| 1125 | |
| 1126 | /* check if this quantization is better |
| 1127 | * than our saved quantization */ |
| 1128 | if (cod_info->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. != SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) /* NORM, START or STOP type */ |
| 1129 | better = cfg->quant_compcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#quant_comp.; |
| 1130 | else |
| 1131 | better = cfg->quant_comp_shortcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#quant_comp_short.; |
| 1132 | |
| 1133 | |
| 1134 | better = quant_comparecxx . . $ quant_compare(b7b6e97eaa8dcf84).(better, &best_noise_info, &noise_info, &cod_info_w, distort); |
| 1135 | |
| 1136 | |
| 1137 | /* save data so we can restore this quantization later */ |
| 1138 | if (better) { |
| 1139 | best_part2_3_length = cod_info->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length.; |
| 1140 | best_noise_info = noise_info; |
| 1141 | *cod_info = cod_info_w; |
| 1142 | age = 0; |
| 1143 | /* save data so we can restore this quantization later */ |
| 1144 | /*if (cfg->vbr == vbr_rh || cfg->vbr == vbr_mtrh) */ { |
| 1145 | /* store for later reuse */ |
| 1146 | memcpycxx . . $ memcpy(cc817cb175f282d).(save_xrpow, xrpow, sizeof(FLOATcxx . . $ FLOAT#) * 576); |
| 1147 | } |
| 1148 | } |
| 1149 | else { |
| 1150 | /* early stop? */ |
| 1151 | if (cfg->full_outer_loopcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#full_outer_loop. == 0) { |
| 1152 | if (++age > search_limit && best_noise_info.over_countcxx . . $ calc_noise_result_t#over_count. == 0) |
| 1153 | break; |
| 1154 | if ((cfg->noise_shaping_ampcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#noise_shaping_amp. == 3) && bRefine && age > 30) |
| 1155 | break; |
| 1156 | if ((cfg->noise_shaping_ampcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#noise_shaping_amp. == 3) && bRefine && |
| 1157 | (cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. - best_ggain_pass1) > 15) |
| 1158 | break; |
| 1159 | } |
| 1160 | } |
| 1161 | } |
| 1162 | while ((cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain. + cod_info_w.scalefac_scalecxx . . $ $anonymous_type_fdda207d22d8fb07_3#scalefac_scale.) < 255); |
| 1163 | |
| 1164 | if (cfg->noise_shaping_ampcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#noise_shaping_amp. == 3) { |
| 1165 | if (!bRefine) { |
| 1166 | /* refine search */ |
| 1167 | cod_info_w = *cod_info; |
| 1168 | memcpycxx . . $ memcpy(cc817cb175f282d).(xrpow, save_xrpow, sizeof(FLOATcxx . . $ FLOAT#) * 576); |
| 1169 | age = 0; |
| 1170 | best_ggain_pass1 = cod_info_w.global_gaincxx . . $ $anonymous_type_fdda207d22d8fb07_3#global_gain.; |
| 1171 | |
| 1172 | bRefine = 1; |
| 1173 | } |
| 1174 | else { |
| 1175 | /* search already refined, stop */ |
| 1176 | bEndOfSearch = 1; |
| 1177 | } |
| 1178 | |
| 1179 | } |
| 1180 | else { |
| 1181 | bEndOfSearch = 1; |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((cod_info->global_gain + cod_info->scalefac_scale) <= 255); |
| 1186 | /* finish up |
| 1187 | */ |
| 1188 | if (cfg->vbrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr. == vbr_rhcxx . . $ vbr_rh. || cfg->vbrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr. == vbr_mtrhcxx . . $ vbr_mtrh. || cfg->vbrcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr. == vbr_mtcxx . . $ vbr_mt.) |
| 1189 | /* restore for reuse on next try */ |
| 1190 | memcpycxx . . $ memcpy(cc817cb175f282d).(xrpow, save_xrpow, sizeof(FLOATcxx . . $ FLOAT#) * 576); |
| 1191 | /* do the 'substep shaping' |
| 1192 | */ |
| 1193 | else if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..substep_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#substep_shaping. & 1) |
| 1194 | trancate_smallspectrumscxx . . $ trancate_smallspectrums(93637adad86d83b8).(gfc, cod_info, l3_xmin, xrpow); |
| 1195 | |
| 1196 | return best_noise_info.over_countcxx . . $ calc_noise_result_t#over_count.; |
| 1197 | } |
| 1198 | |
| 1199 | |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | /************************************************************************ |
| 1204 | * |
| 1205 | * iteration_finish_one() |
| 1206 | * |
| 1207 | * Robert Hegemann 2000-09-06 |
| 1208 | * |
| 1209 | * update reservoir status after FINAL quantization/bitrate |
| 1210 | * |
| 1211 | ************************************************************************/ |
| 1212 | |
| 1213 | static void |
| 1214 | iteration_finish_onecxx . . $ iteration_finish_one(b6022c2330fef37d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int gr, int ch) |
| 1215 | { |
| 1216 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1217 | III_side_info_tcxx . . $ III_side_info_t# *const l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.; |
| 1218 | gr_infocxx . . $ gr_info# *const cod_info = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1219 | |
| 1220 | /* try some better scalefac storage |
| 1221 | */ |
| 1222 | best_scalefac_storecxx . . $ best_scalefac_store(40201c8f8269c0dd).(gfc, gr, ch, l3_side); |
| 1223 | |
| 1224 | /* best huffman_divide may save some bits too |
| 1225 | */ |
| 1226 | if (cfg->use_best_huffmancxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#use_best_huffman. == 1) |
| 1227 | best_huffman_dividecxx . . $ best_huffman_divide(1f82e55fbceb2106).(gfc, cod_info); |
| 1228 | |
| 1229 | /* update reservoir status after FINAL quantization/bitrate |
| 1230 | */ |
| 1231 | ResvAdjustcxx . . $ ResvAdjust(af9ea9d0f6fa39cc).(gfc, cod_info); |
| 1232 | } |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | /********************************************************************* |
| 1237 | * |
| 1238 | * VBR_encode_granule() |
| 1239 | * |
| 1240 | * 2000-09-04 Robert Hegemann |
| 1241 | * |
| 1242 | *********************************************************************/ |
| 1243 | |
| 1244 | static void |
| 1245 | VBR_encode_granulecxx . . $ VBR_encode_granule(8e495360ad104995).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, gr_infocxx . . $ gr_info# * const cod_info, const FLOATcxx . . $ FLOAT# * const l3_xmin, /* allowed distortion of the scalefactor */ |
| 1246 | FLOATcxx . . $ FLOAT# xrpow[576], /* coloured magnitudes of spectral values */ |
| 1247 | const int ch, int min_bits, int max_bits) |
| 1248 | { |
| 1249 | gr_infocxx . . $ gr_info# bst_cod_info; |
| 1250 | FLOATcxx . . $ FLOAT# bst_xrpow[576]; |
| 1251 | int const Max_bits = max_bits; |
| 1252 | int real_bits = max_bits + 1; |
| 1253 | int this_bits = (max_bits + min_bits) / 2; |
| 1254 | int dbits, over, found = 0; |
| 1255 | int const sfb21_extra = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..sfb21_extracxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#sfb21_extra.; |
| 1256 | |
| 1257 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(Max_bits <= MAX_BITS_PER_CHANNELcxx . . $ `external/lame/util.h:85:9`!); |
| 1258 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(bst_cod_info.l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc., 0, sizeof(bst_cod_info.l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc.)); |
| 1259 | |
| 1260 | /* search within round about 40 bits of optimal |
| 1261 | */ |
| 1262 | do { |
| 1263 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(this_bits >= min_bits); |
| 1264 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(this_bits <= max_bits); |
| 1265 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(min_bits <= max_bits); |
| 1266 | |
| 1267 | if (this_bits > Max_bits - 42) |
| 1268 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..sfb21_extracxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#sfb21_extra. = 0; |
| 1269 | else |
| 1270 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..sfb21_extracxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#sfb21_extra. = sfb21_extra; |
| 1271 | |
| 1272 | over = outer_loopcxx . . $ outer_loop(c0039c6f518de0c8).(gfc, cod_info, l3_xmin, xrpow, ch, this_bits); |
| 1273 | |
| 1274 | /* is quantization as good as we are looking for ? |
| 1275 | * in this case: is no scalefactor band distorted? |
| 1276 | */ |
| 1277 | if (over <= 0) { |
| 1278 | found = 1; |
| 1279 | /* now we know it can be done with "real_bits" |
| 1280 | * and maybe we can skip some iterations |
| 1281 | */ |
| 1282 | real_bits = cod_info->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length.; |
| 1283 | |
| 1284 | /* store best quantization so far |
| 1285 | */ |
| 1286 | bst_cod_info = *cod_info; |
| 1287 | memcpycxx . . $ memcpy(cc817cb175f282d).(bst_xrpow, xrpow, sizeof(FLOATcxx . . $ FLOAT#) * 576); |
| 1288 | |
| 1289 | /* try with fewer bits |
| 1290 | */ |
| 1291 | max_bits = real_bits - 32; |
| 1292 | dbits = max_bits - min_bits; |
| 1293 | this_bits = (max_bits + min_bits) / 2; |
| 1294 | } |
| 1295 | else { |
| 1296 | /* try with more bits |
| 1297 | */ |
| 1298 | min_bits = this_bits + 32; |
| 1299 | dbits = max_bits - min_bits; |
| 1300 | this_bits = (max_bits + min_bits) / 2; |
| 1301 | |
| 1302 | if (found) { |
| 1303 | found = 2; |
| 1304 | /* start again with best quantization so far |
| 1305 | */ |
| 1306 | *cod_info = bst_cod_info; |
| 1307 | memcpycxx . . $ memcpy(cc817cb175f282d).(xrpow, bst_xrpow, sizeof(FLOATcxx . . $ FLOAT#) * 576); |
| 1308 | } |
| 1309 | } |
| 1310 | } while (dbits > 12); |
| 1311 | |
| 1312 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..sfb21_extracxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#sfb21_extra. = sfb21_extra; |
| 1313 | |
| 1314 | /* found=0 => nothing found, use last one |
| 1315 | * found=1 => we just found the best and left the loop |
| 1316 | * found=2 => we restored a good one and have now l3_enc to restore too |
| 1317 | */ |
| 1318 | if (found == 2) { |
| 1319 | memcpycxx . . $ memcpy(cc817cb175f282d).(cod_info->l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc., bst_cod_info.l3_enccxx . . $ $anonymous_type_fdda207d22d8fb07_3#l3_enc., sizeof(int) * 576); |
| 1320 | } |
| 1321 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cod_info->part2_3_length <= Max_bits); |
| 1322 | |
| 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | /************************************************************************ |
| 1328 | * |
| 1329 | * get_framebits() |
| 1330 | * |
| 1331 | * Robert Hegemann 2000-09-05 |
| 1332 | * |
| 1333 | * calculates |
| 1334 | * * how many bits are available for analog silent granules |
| 1335 | * * how many bits to use for the lowest allowed bitrate |
| 1336 | * * how many bits each bitrate would provide |
| 1337 | * |
| 1338 | ************************************************************************/ |
| 1339 | |
| 1340 | static void |
| 1341 | get_framebitscxx . . $ get_framebits(2efc052da29e3a17).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, int frameBits[15]) |
| 1342 | { |
| 1343 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1344 | EncResult_tcxx . . $ EncResult_t# *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.; |
| 1345 | int bitsPerFrame, i; |
| 1346 | |
| 1347 | /* always use at least this many bits per granule per channel |
| 1348 | * unless we detect analog silence, see below |
| 1349 | */ |
| 1350 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = cfg->vbr_min_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_min_bitrate_index.; |
| 1351 | bitsPerFrame = getframebitscxx . . $ getframebits(b815612886108da).(gfc); |
| 1352 | |
| 1353 | /* bits for analog silence |
| 1354 | */ |
| 1355 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = 1; |
| 1356 | bitsPerFrame = getframebitscxx . . $ getframebits(b815612886108da).(gfc); |
| 1357 | |
| 1358 | for (i = 1; i <= cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; i++) { |
| 1359 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = i; |
| 1360 | frameBits[i] = ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &bitsPerFrame); |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | /********************************************************************* |
| 1367 | * |
| 1368 | * VBR_prepare() |
| 1369 | * |
| 1370 | * 2000-09-04 Robert Hegemann |
| 1371 | * |
| 1372 | * * converts LR to MS coding when necessary |
| 1373 | * * calculates allowed/adjusted quantization noise amounts |
| 1374 | * * detects analog silent frames |
| 1375 | * |
| 1376 | * some remarks: |
| 1377 | * - lower masking depending on Quality setting |
| 1378 | * - quality control together with adjusted ATH MDCT scaling |
| 1379 | * on lower quality setting allocate more noise from |
| 1380 | * ATH masking, and on higher quality setting allocate |
| 1381 | * less noise from ATH masking. |
| 1382 | * - experiments show that going more than 2dB over GPSYCHO's |
| 1383 | * limits ends up in very annoying artefacts |
| 1384 | * |
| 1385 | *********************************************************************/ |
| 1386 | |
| 1387 | /* RH: this one needs to be overhauled sometime */ |
| 1388 | |
| 1389 | static int |
| 1390 | VBR_old_preparecxx . . $ VBR_old_prepare(f98987d0834f1280).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, |
| 1391 | const FLOATcxx . . $ FLOAT# pe[2][2], FLOATcxx . . $ FLOAT# const ms_ener_ratio[2], |
| 1392 | const III_psy_ratiocxx . . $ III_psy_ratio# ratio[2][2], |
| 1393 | FLOATcxx . . $ FLOAT# l3_xmin[2][2][SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!], |
| 1394 | int frameBits[16], int min_bits[2][2], int max_bits[2][2], int bands[2][2]) |
| 1395 | { |
| 1396 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1397 | EncResult_tcxx . . $ EncResult_t# *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.; |
| 1398 | |
| 1399 | FLOATcxx . . $ FLOAT# masking_lower_db, adjust = 0.0; |
| 1400 | int gr, ch; |
| 1401 | int analog_silence = 1; |
| 1402 | int avg, mxb, bits = 0; |
| 1403 | |
| 1404 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; |
| 1405 | avg = ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &avg) / cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; |
| 1406 | |
| 1407 | get_framebitscxx . . $ get_framebits(2efc052da29e3a17).(gfc, frameBits); |
| 1408 | |
| 1409 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1410 | mxb = on_pecxx . . $ on_pe(2fe9c54108dac159).(gfc, pe, max_bits[gr], avg, gr, 0); |
| 1411 | if (gfc->ov_enccxx . . $ lame_internal_flags#ov_enc..mode_extcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#mode_ext. == MPG_MD_MS_LRcxx . . $ MPG_MD_MS_LR.) { |
| 1412 | ms_convertcxx . . $ ms_convert(1076bfecde684d99).(&gfc->l3_sidecxx . . $ lame_internal_flags#l3_side., gr); |
| 1413 | reduce_sidecxx . . $ reduce_side(442a8dec85e6493).(max_bits[gr], ms_ener_ratio[gr], avg, mxb); |
| 1414 | } |
| 1415 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ++ch) { |
| 1416 | gr_infocxx . . $ gr_info# *const cod_info = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side..ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1417 | |
| 1418 | if (cod_info->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. != SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { /* NORM, START or STOP type */ |
| 1419 | adjust = 1.28 / (1 + expcxx . . $ exp(447c67c6676f75c3).(3.5 - pe[gr][ch] / 300.)) - 0.05; |
| 1420 | masking_lower_db = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..mask_adjustcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#mask_adjust. - adjust; |
| 1421 | } |
| 1422 | else { |
| 1423 | adjust = 2.56 / (1 + expcxx . . $ exp(447c67c6676f75c3).(3.5 - pe[gr][ch] / 300.)) - 0.14; |
| 1424 | masking_lower_db = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..mask_adjust_shortcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#mask_adjust_short. - adjust; |
| 1425 | } |
| 1426 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#masking_lower. = powcxx . . $ pow(d8e7e0733fa41c87).(10.0, masking_lower_db * 0.1); |
| 1427 | |
| 1428 | init_outer_loopcxx . . $ init_outer_loop(1f82e55fbceb2106).(gfc, cod_info); |
| 1429 | bands[gr][ch] = calc_xmincxx . . $ calc_xmin(9751037a4ab03f20).(gfc, &ratio[gr][ch], cod_info, l3_xmin[gr][ch]); |
| 1430 | if (bands[gr][ch]) |
| 1431 | analog_silence = 0; |
| 1432 | |
| 1433 | min_bits[gr][ch] = 126; |
| 1434 | |
| 1435 | bits += max_bits[gr][ch]; |
| 1436 | } |
| 1437 | } |
| 1438 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1439 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1440 | if (bits > frameBits[cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.] && bits > 0) { |
| 1441 | max_bits[gr][ch] *= frameBits[cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.]; |
| 1442 | max_bits[gr][ch] /= bits; |
| 1443 | } |
| 1444 | if (min_bits[gr][ch] > max_bits[gr][ch]) |
| 1445 | min_bits[gr][ch] = max_bits[gr][ch]; |
| 1446 | |
| 1447 | } /* for ch */ |
| 1448 | } /* for gr */ |
| 1449 | |
| 1450 | return analog_silence; |
| 1451 | } |
| 1452 | |
| 1453 | static void |
| 1454 | bitpressure_strategycxx . . $ bitpressure_strategy(ebb41eea12657283).(lame_internal_flagscxx . . $ lame_internal_flags# const *gfc, |
| 1455 | FLOATcxx . . $ FLOAT# l3_xmin[2][2][SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!], const int min_bits[2][2], int max_bits[2][2]) |
| 1456 | { |
| 1457 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1458 | int gr, ch, sfb; |
| 1459 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1460 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1461 | gr_infocxx . . $ gr_info# const *const gi = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side..ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1462 | FLOATcxx . . $ FLOAT# *pxmin = l3_xmin[gr][ch]; |
| 1463 | for (sfb = 0; sfb < gi->psy_lmaxcxx . . $ $anonymous_type_fdda207d22d8fb07_3#psy_lmax.; sfb++) |
| 1464 | *pxmin++ *= 1. + .029 * sfb * sfb / SBMAX_lcxx . . $ `external/lame/encoder.h:103:9`! / SBMAX_lcxx . . $ `external/lame/encoder.h:103:9`!; |
| 1465 | |
| 1466 | if (gi->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { |
| 1467 | for (sfb = gi->sfb_smincxx . . $ $anonymous_type_fdda207d22d8fb07_3#sfb_smin.; sfb < SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; sfb++) { |
| 1468 | *pxmin++ *= 1. + .029 * sfb * sfb / SBMAX_scxx . . $ `external/lame/encoder.h:104:9`! / SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; |
| 1469 | *pxmin++ *= 1. + .029 * sfb * sfb / SBMAX_scxx . . $ `external/lame/encoder.h:104:9`! / SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; |
| 1470 | *pxmin++ *= 1. + .029 * sfb * sfb / SBMAX_scxx . . $ `external/lame/encoder.h:104:9`! / SBMAX_scxx . . $ `external/lame/encoder.h:104:9`!; |
| 1471 | } |
| 1472 | } |
| 1473 | max_bits[gr][ch] = Maxcxx . . $ `external/lame/util.h:92:17`!(min_bits[gr][ch], 0.9 * max_bits[gr][ch]); |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | /************************************************************************ |
| 1479 | * |
| 1480 | * VBR_iteration_loop() |
| 1481 | * |
| 1482 | * tries to find out how many bits are needed for each granule and channel |
| 1483 | * to get an acceptable quantization. An appropriate bitrate will then be |
| 1484 | * choosed for quantization. rh 8/99 |
| 1485 | * |
| 1486 | * Robert Hegemann 2000-09-06 rewrite |
| 1487 | * |
| 1488 | ************************************************************************/ |
| 1489 | |
| 1490 | void |
| 1491 | VBR_old_iteration_loopcxx . . $ VBR_old_iteration_loop(bd687d04ba92e0d4).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, const FLOATcxx . . $ FLOAT# pe[2][2], |
| 1492 | const FLOATcxx . . $ FLOAT# ms_ener_ratio[2], const III_psy_ratiocxx . . $ III_psy_ratio# ratio[2][2]) |
| 1493 | { |
| 1494 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1495 | EncResult_tcxx . . $ EncResult_t# *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.; |
| 1496 | FLOATcxx . . $ FLOAT# l3_xmin[2][2][SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!]; |
| 1497 | |
| 1498 | FLOATcxx . . $ FLOAT# xrpow[576]; |
| 1499 | int bands[2][2]; |
| 1500 | int frameBits[15]; |
| 1501 | int used_bits; |
| 1502 | int bits; |
| 1503 | int min_bits[2][2], max_bits[2][2]; |
| 1504 | int mean_bits; |
| 1505 | int ch, gr, analog_silence; |
| 1506 | III_side_info_tcxx . . $ III_side_info_t# *const l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.; |
| 1507 | |
| 1508 | analog_silence = VBR_old_preparecxx . . $ VBR_old_prepare(f98987d0834f1280).(gfc, pe, ms_ener_ratio, ratio, |
| 1509 | l3_xmin, frameBits, min_bits, max_bits, bands); |
| 1510 | |
| 1511 | /*---------------------------------*/ |
| 1512 | for (;;) { |
| 1513 | |
| 1514 | /* quantize granules with lowest possible number of bits |
| 1515 | */ |
| 1516 | |
| 1517 | used_bits = 0; |
| 1518 | |
| 1519 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1520 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1521 | int ret; |
| 1522 | gr_infocxx . . $ gr_info# *const cod_info = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1523 | |
| 1524 | /* init_outer_loop sets up cod_info, scalefac and xrpow |
| 1525 | */ |
| 1526 | ret = init_xrpowcxx . . $ init_xrpow(37cc32f6f6d0f0d7).(gfc, cod_info, xrpow); |
| 1527 | if (ret == 0 || max_bits[gr][ch] == 0) { |
| 1528 | /* xr contains no energy |
| 1529 | * l3_enc, our encoding data, will be quantized to zero |
| 1530 | */ |
| 1531 | continue; /* with next channel */ |
| 1532 | } |
| 1533 | |
| 1534 | VBR_encode_granulecxx . . $ VBR_encode_granule(8e495360ad104995).(gfc, cod_info, l3_xmin[gr][ch], xrpow, |
| 1535 | ch, min_bits[gr][ch], max_bits[gr][ch]); |
| 1536 | |
| 1537 | /* do the 'substep shaping' |
| 1538 | */ |
| 1539 | if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..substep_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#substep_shaping. & 1) { |
| 1540 | trancate_smallspectrumscxx . . $ trancate_smallspectrums(93637adad86d83b8).(gfc, &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch], l3_xmin[gr][ch], xrpow); |
| 1541 | } |
| 1542 | |
| 1543 | ret = cod_info->part2_3_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_3_length. + cod_info->part2_lengthcxx . . $ $anonymous_type_fdda207d22d8fb07_3#part2_length.; |
| 1544 | used_bits += ret; |
| 1545 | } /* for ch */ |
| 1546 | } /* for gr */ |
| 1547 | |
| 1548 | /* find lowest bitrate able to hold used bits |
| 1549 | */ |
| 1550 | if (analog_silence && !cfg->enforce_min_bitratecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#enforce_min_bitrate.) |
| 1551 | /* we detected analog silence and the user did not specify |
| 1552 | * any hard framesize limit, so start with smallest possible frame |
| 1553 | */ |
| 1554 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = 1; |
| 1555 | else |
| 1556 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = cfg->vbr_min_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_min_bitrate_index.; |
| 1557 | |
| 1558 | for (; eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. < cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index.++) { |
| 1559 | if (used_bits <= frameBits[eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index.]) |
| 1560 | break; |
| 1561 | } |
| 1562 | bits = ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &mean_bits); |
| 1563 | |
| 1564 | if (used_bits <= bits) |
| 1565 | break; |
| 1566 | |
| 1567 | bitpressure_strategycxx . . $ bitpressure_strategy(ebb41eea12657283).(gfc, l3_xmin, (const int (*)[2])min_bits, max_bits); |
| 1568 | |
| 1569 | } /* breaks adjusted */ |
| 1570 | /*--------------------------------------*/ |
| 1571 | |
| 1572 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1573 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1574 | iteration_finish_onecxx . . $ iteration_finish_one(b6022c2330fef37d).(gfc, gr, ch); |
| 1575 | } /* for ch */ |
| 1576 | } /* for gr */ |
| 1577 | ResvFrameEndcxx . . $ ResvFrameEnd(8f5851925078004a).(gfc, mean_bits); |
| 1578 | } |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | static int |
| 1583 | VBR_new_preparecxx . . $ VBR_new_prepare(ce8aaa04b5a8f645).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, |
| 1584 | const FLOATcxx . . $ FLOAT# pe[2][2], const III_psy_ratiocxx . . $ III_psy_ratio# ratio[2][2], |
| 1585 | FLOATcxx . . $ FLOAT# l3_xmin[2][2][SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!], int frameBits[16], int max_bits[2][2], |
| 1586 | int* max_resv) |
| 1587 | { |
| 1588 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1589 | EncResult_tcxx . . $ EncResult_t# *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.; |
| 1590 | |
| 1591 | int gr, ch; |
| 1592 | int analog_silence = 1; |
| 1593 | int avg, bits = 0; |
| 1594 | int maximum_framebits; |
| 1595 | |
| 1596 | if (!cfg->free_formatcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#free_format.) { |
| 1597 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; |
| 1598 | (void) ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &avg); |
| 1599 | *max_resv = gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..ResvMaxcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ResvMax.; |
| 1600 | |
| 1601 | get_framebitscxx . . $ get_framebits(2efc052da29e3a17).(gfc, frameBits); |
| 1602 | maximum_framebits = frameBits[cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.]; |
| 1603 | } |
| 1604 | else { |
| 1605 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = 0; |
| 1606 | maximum_framebits = ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &avg); |
| 1607 | frameBits[0] = maximum_framebits; |
| 1608 | *max_resv = gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..ResvMaxcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#ResvMax.; |
| 1609 | } |
| 1610 | |
| 1611 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1612 | (void) on_pecxx . . $ on_pe(2fe9c54108dac159).(gfc, pe, max_bits[gr], avg, gr, 0); |
| 1613 | if (gfc->ov_enccxx . . $ lame_internal_flags#ov_enc..mode_extcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#mode_ext. == MPG_MD_MS_LRcxx . . $ MPG_MD_MS_LR.) { |
| 1614 | ms_convertcxx . . $ ms_convert(1076bfecde684d99).(&gfc->l3_sidecxx . . $ lame_internal_flags#l3_side., gr); |
| 1615 | } |
| 1616 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ++ch) { |
| 1617 | gr_infocxx . . $ gr_info# *const cod_info = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side..ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1618 | |
| 1619 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#masking_lower. = powcxx . . $ pow(d8e7e0733fa41c87).(10.0, gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..mask_adjustcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#mask_adjust. * 0.1); |
| 1620 | |
| 1621 | init_outer_loopcxx . . $ init_outer_loop(1f82e55fbceb2106).(gfc, cod_info); |
| 1622 | if (0 != calc_xmincxx . . $ calc_xmin(9751037a4ab03f20).(gfc, &ratio[gr][ch], cod_info, l3_xmin[gr][ch])) |
| 1623 | analog_silence = 0; |
| 1624 | |
| 1625 | bits += max_bits[gr][ch]; |
| 1626 | } |
| 1627 | } |
| 1628 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1629 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1630 | if (bits > maximum_framebits && bits > 0) { |
| 1631 | max_bits[gr][ch] *= maximum_framebits; |
| 1632 | max_bits[gr][ch] /= bits; |
| 1633 | } |
| 1634 | |
| 1635 | } /* for ch */ |
| 1636 | } /* for gr */ |
| 1637 | if (analog_silence) { |
| 1638 | *max_resv = 0; |
| 1639 | } |
| 1640 | return analog_silence; |
| 1641 | } |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | void |
| 1646 | VBR_new_iteration_loopcxx . . $ VBR_new_iteration_loop(bd687d04ba92e0d4).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, const FLOATcxx . . $ FLOAT# pe[2][2], |
| 1647 | const FLOATcxx . . $ FLOAT# ms_ener_ratio[2], const III_psy_ratiocxx . . $ III_psy_ratio# ratio[2][2]) |
| 1648 | { |
| 1649 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1650 | EncResult_tcxx . . $ EncResult_t# *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.; |
| 1651 | FLOATcxx . . $ FLOAT# l3_xmin[2][2][SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!]; |
| 1652 | |
| 1653 | FLOATcxx . . $ FLOAT# xrpow[2][2][576]; |
| 1654 | int frameBits[15]; |
| 1655 | int used_bits; |
| 1656 | int max_bits[2][2]; |
| 1657 | int ch, gr, analog_silence, pad; |
| 1658 | III_side_info_tcxx . . $ III_side_info_t# *const l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.; |
| 1659 | |
| 1660 | const FLOATcxx . . $ FLOAT# (*const_l3_xmin)[2][SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!] = (const FLOATcxx . . $ FLOAT# (*)[2][SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!])l3_xmin; |
| 1661 | const FLOATcxx . . $ FLOAT# (*const_xrpow)[2][576] = (const FLOATcxx . . $ FLOAT# (*)[2][576])xrpow; |
| 1662 | const int (*const_max_bits)[2] = (const int (*)[2])max_bits; |
| 1663 | |
| 1664 | (void) ms_ener_ratio; /* not used */ |
| 1665 | |
| 1666 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(xrpow, 0, sizeof(xrpow)); |
| 1667 | |
| 1668 | analog_silence = VBR_new_preparecxx . . $ VBR_new_prepare(ce8aaa04b5a8f645).(gfc, pe, ratio, l3_xmin, frameBits, max_bits, &pad); |
| 1669 | |
| 1670 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1671 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1672 | gr_infocxx . . $ gr_info# *const cod_info = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1673 | |
| 1674 | /* init_outer_loop sets up cod_info, scalefac and xrpow |
| 1675 | */ |
| 1676 | if (0 == init_xrpowcxx . . $ init_xrpow(37cc32f6f6d0f0d7).(gfc, cod_info, xrpow[gr][ch])) { |
| 1677 | max_bits[gr][ch] = 0; /* silent granule needs no bits */ |
| 1678 | } |
| 1679 | } /* for ch */ |
| 1680 | } /* for gr */ |
| 1681 | |
| 1682 | /* quantize granules with lowest possible number of bits |
| 1683 | */ |
| 1684 | |
| 1685 | used_bits = VBR_encode_framecxx . . $ VBR_encode_frame(3a01d120b4130040).(gfc, const_xrpow, const_l3_xmin, const_max_bits); |
| 1686 | |
| 1687 | if (!cfg->free_formatcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#free_format.) { |
| 1688 | int i, j; |
| 1689 | |
| 1690 | /* find lowest bitrate able to hold used bits |
| 1691 | */ |
| 1692 | if (analog_silence && !cfg->enforce_min_bitratecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#enforce_min_bitrate.) { |
| 1693 | /* we detected analog silence and the user did not specify |
| 1694 | * any hard framesize limit, so start with smallest possible frame |
| 1695 | */ |
| 1696 | i = 1; |
| 1697 | } |
| 1698 | else { |
| 1699 | i = cfg->vbr_min_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_min_bitrate_index.; |
| 1700 | } |
| 1701 | |
| 1702 | for (; i < cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; i++) { |
| 1703 | if (used_bits <= frameBits[i]) |
| 1704 | break; |
| 1705 | } |
| 1706 | if (i > cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.) { |
| 1707 | i = cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; |
| 1708 | } |
| 1709 | if (pad > 0) { |
| 1710 | for (j = cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; j > i; --j) { |
| 1711 | int const unused = frameBits[j] - used_bits; |
| 1712 | if (unused <= pad) |
| 1713 | break; |
| 1714 | } |
| 1715 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = j; |
| 1716 | } |
| 1717 | else { |
| 1718 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = i; |
| 1719 | } |
| 1720 | } |
| 1721 | else { |
| 1722 | #if 0 |
| 1723 | static int mmm = 0; |
| 1724 | int fff = getFramesize_kbps(gfc, used_bits); |
| 1725 | int hhh = getFramesize_kbps(gfc, MAX_BITS_PER_GRANULE * cfg->mode_gr); |
| 1726 | if (mmm < fff) |
| 1727 | mmm = fff; |
| 1728 | printf("demand=%3d kbps max=%3d kbps limit=%3d kbps\n", fff, mmm, hhh); |
| 1729 | #endif |
| 1730 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = 0; |
| 1731 | } |
| 1732 | if (used_bits <= frameBits[eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index.]) { |
| 1733 | /* update Reservoire status */ |
| 1734 | int mean_bits, fullframebits; |
| 1735 | fullframebits = ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &mean_bits); |
| 1736 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(used_bits <= fullframebits); |
| 1737 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1738 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1739 | gr_infocxx . . $ gr_info# const *const cod_info = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1740 | ResvAdjustcxx . . $ ResvAdjust(af9ea9d0f6fa39cc).(gfc, cod_info); |
| 1741 | } |
| 1742 | } |
| 1743 | ResvFrameEndcxx . . $ ResvFrameEnd(8f5851925078004a).(gfc, mean_bits); |
| 1744 | } |
| 1745 | else { |
| 1746 | /* SHOULD NOT HAPPEN INTERNAL ERROR |
| 1747 | */ |
| 1748 | ERRORFcxx . . $ `external/lame/util.h:606:9`!(gfc, "INTERNAL ERROR IN VBR NEW CODE, please send bug report\n"); |
| 1749 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | |
| 1756 | |
| 1757 | /******************************************************************** |
| 1758 | * |
| 1759 | * calc_target_bits() |
| 1760 | * |
| 1761 | * calculates target bits for ABR encoding |
| 1762 | * |
| 1763 | * mt 2000/05/31 |
| 1764 | * |
| 1765 | ********************************************************************/ |
| 1766 | |
| 1767 | static void |
| 1768 | calc_target_bitscxx . . $ calc_target_bits(71286f9f9e55d232).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, |
| 1769 | const FLOATcxx . . $ FLOAT# pe[2][2], |
| 1770 | FLOATcxx . . $ FLOAT# const ms_ener_ratio[2], |
| 1771 | int targ_bits[2][2], int *analog_silence_bits, int *max_frame_bits) |
| 1772 | { |
| 1773 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1774 | EncResult_tcxx . . $ EncResult_t# *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.; |
| 1775 | III_side_info_tcxx . . $ III_side_info_t# const *const l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.; |
| 1776 | FLOATcxx . . $ FLOAT# res_factor; |
| 1777 | int gr, ch, totbits, mean_bits; |
| 1778 | int framesize = 576 * cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; |
| 1779 | |
| 1780 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; |
| 1781 | *max_frame_bits = ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &mean_bits); |
| 1782 | |
| 1783 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = 1; |
| 1784 | mean_bits = getframebitscxx . . $ getframebits(b815612886108da).(gfc) - cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len. * 8; |
| 1785 | *analog_silence_bits = mean_bits / (cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr. * cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.); |
| 1786 | |
| 1787 | mean_bits = cfg->vbr_avg_bitrate_kbpscxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_avg_bitrate_kbps. * framesize * 1000; |
| 1788 | if (gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..substep_shapingcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#substep_shaping. & 1) |
| 1789 | mean_bits *= 1.09; |
| 1790 | mean_bits /= cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out.; |
| 1791 | mean_bits -= cfg->sideinfo_lencxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#sideinfo_len. * 8; |
| 1792 | mean_bits /= (cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr. * cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.); |
| 1793 | |
| 1794 | /* |
| 1795 | res_factor is the percentage of the target bitrate that should |
| 1796 | be used on average. the remaining bits are added to the |
| 1797 | bitreservoir and used for difficult to encode frames. |
| 1798 | |
| 1799 | Since we are tracking the average bitrate, we should adjust |
| 1800 | res_factor "on the fly", increasing it if the average bitrate |
| 1801 | is greater than the requested bitrate, and decreasing it |
| 1802 | otherwise. Reasonable ranges are from .9 to 1.0 |
| 1803 | |
| 1804 | Until we get the above suggestion working, we use the following |
| 1805 | tuning: |
| 1806 | compression ratio res_factor |
| 1807 | 5.5 (256kbps) 1.0 no need for bitreservoir |
| 1808 | 11 (128kbps) .93 7% held for reservoir |
| 1809 | |
| 1810 | with linear interpolation for other values. |
| 1811 | |
| 1812 | */ |
| 1813 | res_factor = .93 + .07 * (11.0 - cfg->compression_ratiocxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#compression_ratio.) / (11.0 - 5.5); |
| 1814 | if (res_factor < .90) |
| 1815 | res_factor = .90; |
| 1816 | if (res_factor > 1.00) |
| 1817 | res_factor = 1.00; |
| 1818 | |
| 1819 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1820 | int sum = 0; |
| 1821 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1822 | targ_bits[gr][ch] = res_factor * mean_bits; |
| 1823 | |
| 1824 | if (pe[gr][ch] > 700) { |
| 1825 | int add_bits = (pe[gr][ch] - 700) / 1.4; |
| 1826 | |
| 1827 | gr_infocxx . . $ gr_info# const *const cod_info = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1828 | targ_bits[gr][ch] = res_factor * mean_bits; |
| 1829 | |
| 1830 | /* short blocks use a little extra, no matter what the pe */ |
| 1831 | if (cod_info->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. == SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { |
| 1832 | if (add_bits < mean_bits / 2) |
| 1833 | add_bits = mean_bits / 2; |
| 1834 | } |
| 1835 | /* at most increase bits by 1.5*average */ |
| 1836 | if (add_bits > mean_bits * 3 / 2) |
| 1837 | add_bits = mean_bits * 3 / 2; |
| 1838 | else if (add_bits < 0) |
| 1839 | add_bits = 0; |
| 1840 | |
| 1841 | targ_bits[gr][ch] += add_bits; |
| 1842 | } |
| 1843 | if (targ_bits[gr][ch] > MAX_BITS_PER_CHANNELcxx . . $ `external/lame/util.h:85:9`!) { |
| 1844 | targ_bits[gr][ch] = MAX_BITS_PER_CHANNELcxx . . $ `external/lame/util.h:85:9`!; |
| 1845 | } |
| 1846 | sum += targ_bits[gr][ch]; |
| 1847 | } /* for ch */ |
| 1848 | if (sum > MAX_BITS_PER_GRANULEcxx . . $ `external/lame/util.h:86:9`!) { |
| 1849 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ++ch) { |
| 1850 | targ_bits[gr][ch] *= MAX_BITS_PER_GRANULEcxx . . $ `external/lame/util.h:86:9`!; |
| 1851 | targ_bits[gr][ch] /= sum; |
| 1852 | } |
| 1853 | } |
| 1854 | } /* for gr */ |
| 1855 | |
| 1856 | if (gfc->ov_enccxx . . $ lame_internal_flags#ov_enc..mode_extcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#mode_ext. == MPG_MD_MS_LRcxx . . $ MPG_MD_MS_LR.) |
| 1857 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1858 | reduce_sidecxx . . $ reduce_side(442a8dec85e6493).(targ_bits[gr], ms_ener_ratio[gr], mean_bits * cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out., |
| 1859 | MAX_BITS_PER_GRANULEcxx . . $ `external/lame/util.h:86:9`!); |
| 1860 | } |
| 1861 | |
| 1862 | /* sum target bits |
| 1863 | */ |
| 1864 | totbits = 0; |
| 1865 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1866 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1867 | if (targ_bits[gr][ch] > MAX_BITS_PER_CHANNELcxx . . $ `external/lame/util.h:85:9`!) |
| 1868 | targ_bits[gr][ch] = MAX_BITS_PER_CHANNELcxx . . $ `external/lame/util.h:85:9`!; |
| 1869 | totbits += targ_bits[gr][ch]; |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | /* repartion target bits if needed |
| 1874 | */ |
| 1875 | if (totbits > *max_frame_bits && totbits > 0) { |
| 1876 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1877 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1878 | targ_bits[gr][ch] *= *max_frame_bits; |
| 1879 | targ_bits[gr][ch] /= totbits; |
| 1880 | } |
| 1881 | } |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | |
| 1889 | |
| 1890 | /******************************************************************** |
| 1891 | * |
| 1892 | * ABR_iteration_loop() |
| 1893 | * |
| 1894 | * encode a frame with a disired average bitrate |
| 1895 | * |
| 1896 | * mt 2000/05/31 |
| 1897 | * |
| 1898 | ********************************************************************/ |
| 1899 | |
| 1900 | void |
| 1901 | ABR_iteration_loopcxx . . $ ABR_iteration_loop(bd687d04ba92e0d4).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, const FLOATcxx . . $ FLOAT# pe[2][2], |
| 1902 | const FLOATcxx . . $ FLOAT# ms_ener_ratio[2], const III_psy_ratiocxx . . $ III_psy_ratio# ratio[2][2]) |
| 1903 | { |
| 1904 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1905 | EncResult_tcxx . . $ EncResult_t# *const eov = &gfc->ov_enccxx . . $ lame_internal_flags#ov_enc.; |
| 1906 | FLOATcxx . . $ FLOAT# l3_xmin[SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!]; |
| 1907 | FLOATcxx . . $ FLOAT# xrpow[576]; |
| 1908 | int targ_bits[2][2]; |
| 1909 | int mean_bits, max_frame_bits; |
| 1910 | int ch, gr, ath_over; |
| 1911 | int analog_silence_bits; |
| 1912 | gr_infocxx . . $ gr_info# *cod_info; |
| 1913 | III_side_info_tcxx . . $ III_side_info_t# *const l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.; |
| 1914 | |
| 1915 | mean_bits = 0; |
| 1916 | |
| 1917 | calc_target_bitscxx . . $ calc_target_bits(71286f9f9e55d232).(gfc, pe, ms_ener_ratio, targ_bits, &analog_silence_bits, &max_frame_bits); |
| 1918 | |
| 1919 | /* encode granules |
| 1920 | */ |
| 1921 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 1922 | |
| 1923 | if (gfc->ov_enccxx . . $ lame_internal_flags#ov_enc..mode_extcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#mode_ext. == MPG_MD_MS_LRcxx . . $ MPG_MD_MS_LR.) { |
| 1924 | ms_convertcxx . . $ ms_convert(1076bfecde684d99).(&gfc->l3_sidecxx . . $ lame_internal_flags#l3_side., gr); |
| 1925 | } |
| 1926 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 1927 | FLOATcxx . . $ FLOAT# adjust, masking_lower_db; |
| 1928 | cod_info = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 1929 | |
| 1930 | if (cod_info->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. != SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { /* NORM, START or STOP type */ |
| 1931 | /* adjust = 1.28/(1+exp(3.5-pe[gr][ch]/300.))-0.05; */ |
| 1932 | adjust = 0; |
| 1933 | masking_lower_db = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..mask_adjustcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#mask_adjust. - adjust; |
| 1934 | } |
| 1935 | else { |
| 1936 | /* adjust = 2.56/(1+exp(3.5-pe[gr][ch]/300.))-0.14; */ |
| 1937 | adjust = 0; |
| 1938 | masking_lower_db = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..mask_adjust_shortcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#mask_adjust_short. - adjust; |
| 1939 | } |
| 1940 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#masking_lower. = powcxx . . $ pow(d8e7e0733fa41c87).(10.0, masking_lower_db * 0.1); |
| 1941 | |
| 1942 | |
| 1943 | /* cod_info, scalefac and xrpow get initialized in init_outer_loop |
| 1944 | */ |
| 1945 | init_outer_loopcxx . . $ init_outer_loop(1f82e55fbceb2106).(gfc, cod_info); |
| 1946 | if (init_xrpowcxx . . $ init_xrpow(37cc32f6f6d0f0d7).(gfc, cod_info, xrpow)) { |
| 1947 | /* xr contains energy we will have to encode |
| 1948 | * calculate the masking abilities |
| 1949 | * find some good quantization in outer_loop |
| 1950 | */ |
| 1951 | ath_over = calc_xmincxx . . $ calc_xmin(9751037a4ab03f20).(gfc, &ratio[gr][ch], cod_info, l3_xmin); |
| 1952 | if (0 == ath_over) /* analog silence */ |
| 1953 | targ_bits[gr][ch] = analog_silence_bits; |
| 1954 | |
| 1955 | (void) outer_loopcxx . . $ outer_loop(c0039c6f518de0c8).(gfc, cod_info, l3_xmin, xrpow, ch, targ_bits[gr][ch]); |
| 1956 | } |
| 1957 | iteration_finish_onecxx . . $ iteration_finish_one(b6022c2330fef37d).(gfc, gr, ch); |
| 1958 | } /* ch */ |
| 1959 | } /* gr */ |
| 1960 | |
| 1961 | /* find a bitrate which can refill the resevoir to positive size. |
| 1962 | */ |
| 1963 | for (eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. = cfg->vbr_min_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_min_bitrate_index.; |
| 1964 | eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index. <= cfg->vbr_max_bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#vbr_max_bitrate_index.; eov->bitrate_indexcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#bitrate_index.++) { |
| 1965 | if (ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &mean_bits) >= 0) |
| 1966 | break; |
| 1967 | } |
| 1968 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(eov->bitrate_index <= cfg->vbr_max_bitrate_index); |
| 1969 | |
| 1970 | ResvFrameEndcxx . . $ ResvFrameEnd(8f5851925078004a).(gfc, mean_bits); |
| 1971 | } |
| 1972 | |
| 1973 | |
| 1974 | |
| 1975 | |
| 1976 | |
| 1977 | |
| 1978 | /************************************************************************ |
| 1979 | * |
| 1980 | * CBR_iteration_loop() |
| 1981 | * |
| 1982 | * author/date?? |
| 1983 | * |
| 1984 | * encodes one frame of MP3 data with constant bitrate |
| 1985 | * |
| 1986 | ************************************************************************/ |
| 1987 | |
| 1988 | void |
| 1989 | CBR_iteration_loopcxx . . $ CBR_iteration_loop(bd687d04ba92e0d4).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, const FLOATcxx . . $ FLOAT# pe[2][2], |
| 1990 | const FLOATcxx . . $ FLOAT# ms_ener_ratio[2], const III_psy_ratiocxx . . $ III_psy_ratio# ratio[2][2]) |
| 1991 | { |
| 1992 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 1993 | FLOATcxx . . $ FLOAT# l3_xmin[SFBMAXcxx . . $ `external/lame/l3side.h:26:9`!]; |
| 1994 | FLOATcxx . . $ FLOAT# xrpow[576]; |
| 1995 | int targ_bits[2]; |
| 1996 | int mean_bits, max_bits; |
| 1997 | int gr, ch; |
| 1998 | III_side_info_tcxx . . $ III_side_info_t# *const l3_side = &gfc->l3_sidecxx . . $ lame_internal_flags#l3_side.; |
| 1999 | gr_infocxx . . $ gr_info# *cod_info; |
| 2000 | |
| 2001 | (void) ResvFrameBegincxx . . $ ResvFrameBegin(858e4ff0b2981603).(gfc, &mean_bits); |
| 2002 | |
| 2003 | /* quantize! */ |
| 2004 | for (gr = 0; gr < cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; gr++) { |
| 2005 | |
| 2006 | /* calculate needed bits |
| 2007 | */ |
| 2008 | max_bits = on_pecxx . . $ on_pe(2fe9c54108dac159).(gfc, pe, targ_bits, mean_bits, gr, gr); |
| 2009 | |
| 2010 | if (gfc->ov_enccxx . . $ lame_internal_flags#ov_enc..mode_extcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_9#mode_ext. == MPG_MD_MS_LRcxx . . $ MPG_MD_MS_LR.) { |
| 2011 | ms_convertcxx . . $ ms_convert(1076bfecde684d99).(&gfc->l3_sidecxx . . $ lame_internal_flags#l3_side., gr); |
| 2012 | reduce_sidecxx . . $ reduce_side(442a8dec85e6493).(targ_bits, ms_ener_ratio[gr], mean_bits, max_bits); |
| 2013 | } |
| 2014 | |
| 2015 | for (ch = 0; ch < cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; ch++) { |
| 2016 | FLOATcxx . . $ FLOAT# adjust, masking_lower_db; |
| 2017 | cod_info = &l3_side->ttcxx . . $ $anonymous_type_fdda207d22d8fb07_4#tt.[gr][ch]; |
| 2018 | |
| 2019 | if (cod_info->block_typecxx . . $ $anonymous_type_fdda207d22d8fb07_3#block_type. != SHORT_TYPEcxx . . $ `external/lame/encoder.h:120:9`!) { /* NORM, START or STOP type */ |
| 2020 | /* adjust = 1.28/(1+exp(3.5-pe[gr][ch]/300.))-0.05; */ |
| 2021 | adjust = 0; |
| 2022 | masking_lower_db = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..mask_adjustcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#mask_adjust. - adjust; |
| 2023 | } |
| 2024 | else { |
| 2025 | /* adjust = 2.56/(1+exp(3.5-pe[gr][ch]/300.))-0.14; */ |
| 2026 | adjust = 0; |
| 2027 | masking_lower_db = gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..mask_adjust_shortcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#mask_adjust_short. - adjust; |
| 2028 | } |
| 2029 | gfc->sv_qntcxx . . $ lame_internal_flags#sv_qnt..masking_lowercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_10#masking_lower. = powcxx . . $ pow(d8e7e0733fa41c87).(10.0, masking_lower_db * 0.1); |
| 2030 | |
| 2031 | /* init_outer_loop sets up cod_info, scalefac and xrpow |
| 2032 | */ |
| 2033 | init_outer_loopcxx . . $ init_outer_loop(1f82e55fbceb2106).(gfc, cod_info); |
| 2034 | if (init_xrpowcxx . . $ init_xrpow(37cc32f6f6d0f0d7).(gfc, cod_info, xrpow)) { |
| 2035 | /* xr contains energy we will have to encode |
| 2036 | * calculate the masking abilities |
| 2037 | * find some good quantization in outer_loop |
| 2038 | */ |
| 2039 | (void) calc_xmincxx . . $ calc_xmin(9751037a4ab03f20).(gfc, &ratio[gr][ch], cod_info, l3_xmin); |
| 2040 | (void) outer_loopcxx . . $ outer_loop(c0039c6f518de0c8).(gfc, cod_info, l3_xmin, xrpow, ch, targ_bits[ch]); |
| 2041 | } |
| 2042 | |
| 2043 | iteration_finish_onecxx . . $ iteration_finish_one(b6022c2330fef37d).(gfc, gr, ch); |
| 2044 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cod_info->part2_3_length <= MAX_BITS_PER_CHANNELcxx . . $ `external/lame/util.h:85:9`!); |
| 2045 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cod_info->part2_3_length <= targ_bits[ch]); |
| 2046 | } /* for ch */ |
| 2047 | } /* for gr */ |
| 2048 | |
| 2049 | ResvFrameEndcxx . . $ ResvFrameEnd(8f5851925078004a).(gfc, mean_bits); |
| 2050 | } |