| 1 | /* |
| 2 | * lame utility library source file |
| 3 | * |
| 4 | * Copyright (c) 1999 Albert L Faber |
| 5 | * Copyright (c) 2000-2005 Alexander Leidinger |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public |
| 18 | * License along with this library; if not, write to the |
| 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | /* $Id: util.c,v 1.159 2017/09/06 15:07:30 robert Exp $ */ |
| 24 | |
| 25 | //#ifdef HAVE_CONFIG_H |
| 26 | #include "lame__config.h"cxx . . $ `<file>/external/lame/lame__config.h`/ |
| 27 | //#endif |
| 28 | |
| 29 | #include <float.h> |
| 30 | #include "lame.h"cxx . . $ `<file>/external/lame/lame.h`/ |
| 31 | #include "machine.h"cxx . . $ `<file>/external/lame/machine.h`/ |
| 32 | #include "encoder.h"cxx . . $ `<file>/external/lame/encoder.h`/ |
| 33 | #include "util.h"cxx . . $ `<file>/external/lame/util.h`/ |
| 34 | #include "tables.h"cxx . . $ `<file>/external/lame/tables.h`/ |
| 35 | |
| 36 | #define PRECOMPUTEcxx . . $ `external/lame/util.c:36:9`! |
| 37 | #if defined(__FreeBSD__) && !defined(__alpha__) |
| 38 | # include <machine/floatingpoint.h> |
| 39 | #endif |
| 40 | |
| 41 | |
| 42 | /*********************************************************************** |
| 43 | * |
| 44 | * Global Function Definitions |
| 45 | * |
| 46 | ***********************************************************************/ |
| 47 | /*empty and close mallocs in gfc */ |
| 48 | |
| 49 | void |
| 50 | free_id3tagcxx . . $ free_id3tag(4f558d83b2842a93).(lame_internal_flagscxx . . $ lame_internal_flags# * const gfc) |
| 51 | { |
| 52 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..languagecxx . . $ id3tag_spec#language.[0] = 0; |
| 53 | if (gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..titlecxx . . $ id3tag_spec#title. != 0) { |
| 54 | freecxx . . $ free(5d22bdacc48458e8).(gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..titlecxx . . $ id3tag_spec#title.); |
| 55 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..titlecxx . . $ id3tag_spec#title. = 0; |
| 56 | } |
| 57 | if (gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..artistcxx . . $ id3tag_spec#artist. != 0) { |
| 58 | freecxx . . $ free(5d22bdacc48458e8).(gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..artistcxx . . $ id3tag_spec#artist.); |
| 59 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..artistcxx . . $ id3tag_spec#artist. = 0; |
| 60 | } |
| 61 | if (gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..albumcxx . . $ id3tag_spec#album. != 0) { |
| 62 | freecxx . . $ free(5d22bdacc48458e8).(gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..albumcxx . . $ id3tag_spec#album.); |
| 63 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..albumcxx . . $ id3tag_spec#album. = 0; |
| 64 | } |
| 65 | if (gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..commentcxx . . $ id3tag_spec#comment. != 0) { |
| 66 | freecxx . . $ free(5d22bdacc48458e8).(gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..commentcxx . . $ id3tag_spec#comment.); |
| 67 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..commentcxx . . $ id3tag_spec#comment. = 0; |
| 68 | } |
| 69 | |
| 70 | if (gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..albumartcxx . . $ id3tag_spec#albumart. != 0) { |
| 71 | freecxx . . $ free(5d22bdacc48458e8).(gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..albumartcxx . . $ id3tag_spec#albumart.); |
| 72 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..albumartcxx . . $ id3tag_spec#albumart. = 0; |
| 73 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..albumart_sizecxx . . $ id3tag_spec#albumart_size. = 0; |
| 74 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..albumart_mimetypecxx . . $ id3tag_spec#albumart_mimetype. = MIMETYPE_NONEcxx . . $ MIMETYPE_NONE.; |
| 75 | } |
| 76 | if (gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..v2_headcxx . . $ id3tag_spec#v2_head. != 0) { |
| 77 | FrameDataNodecxx . . $ FrameDataNode# *node = gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..v2_headcxx . . $ id3tag_spec#v2_head.; |
| 78 | do { |
| 79 | void *p = node->dsccxx . . $ FrameDataNode#dsc..ptrcxx . . $ FrameDataNode#$anonymous_type_1#ptr..bcxx . . $ FrameDataNode#$anonymous_type_1#$anonymous_type_2#b.; |
| 80 | void *q = node->txtcxx . . $ FrameDataNode#txt..ptrcxx . . $ FrameDataNode#$anonymous_type_1#ptr..bcxx . . $ FrameDataNode#$anonymous_type_1#$anonymous_type_2#b.; |
| 81 | void *r = node; |
| 82 | node = node->nxtcxx . . $ FrameDataNode#nxt.; |
| 83 | freecxx . . $ free(5d22bdacc48458e8).(p); |
| 84 | freecxx . . $ free(5d22bdacc48458e8).(q); |
| 85 | freecxx . . $ free(5d22bdacc48458e8).(r); |
| 86 | } while (node != 0); |
| 87 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..v2_headcxx . . $ id3tag_spec#v2_head. = 0; |
| 88 | gfc->tag_speccxx . . $ lame_internal_flags#tag_spec..v2_tailcxx . . $ id3tag_spec#v2_tail. = 0; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | |
| 93 | static void |
| 94 | free_global_datacxx . . $ free_global_data(4f558d83b2842a93).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc) |
| 95 | { |
| 96 | if (gfc && gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.) { |
| 97 | if (gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3.) { |
| 98 | /* XXX allocated in psymodel_init() */ |
| 99 | freecxx . . $ free(5d22bdacc48458e8).(gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->lcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#l..s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3.); |
| 100 | } |
| 101 | if (gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3.) { |
| 102 | /* XXX allocated in psymodel_init() */ |
| 103 | freecxx . . $ free(5d22bdacc48458e8).(gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.->scxx . . $ $anonymous_type_fa6ce02aa65ebf3c_4#s..s3cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_3#s3.); |
| 104 | } |
| 105 | freecxx . . $ free(5d22bdacc48458e8).(gfc->cd_psycxx . . $ lame_internal_flags#cd_psy.); |
| 106 | gfc->cd_psycxx . . $ lame_internal_flags#cd_psy. = 0; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |
| 111 | void |
| 112 | freegfccxx . . $ freegfc(4f558d83b2842a93).(lame_internal_flagscxx . . $ lame_internal_flags# * const gfc) |
| 113 | { /* bit stream structure */ |
| 114 | int i; |
| 115 | |
| 116 | if (gfc == 0) return; |
| 117 | |
| 118 | for (i = 0; i <= 2 * BPCcxx . . $ `external/lame/util.h:254:9`!; i++) |
| 119 | if (gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..blackfiltcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#blackfilt.[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 120 | freecxx . . $ free(5d22bdacc48458e8).(gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..blackfiltcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#blackfilt.[i]); |
| 121 | gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..blackfiltcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#blackfilt.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 122 | } |
| 123 | if (gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[0]) { |
| 124 | freecxx . . $ free(5d22bdacc48458e8).(gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[0]); |
| 125 | gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[0] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 126 | } |
| 127 | if (gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[1]) { |
| 128 | freecxx . . $ free(5d22bdacc48458e8).(gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[1]); |
| 129 | gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[1] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 130 | } |
| 131 | |
| 132 | if (gfc->bscxx . . $ lame_internal_flags#bs..bufcxx . . $ bit_stream_struc#buf. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 133 | freecxx . . $ free(5d22bdacc48458e8).(gfc->bscxx . . $ lame_internal_flags#bs..bufcxx . . $ bit_stream_struc#buf.); |
| 134 | gfc->bscxx . . $ lame_internal_flags#bs..bufcxx . . $ bit_stream_struc#buf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 135 | } |
| 136 | |
| 137 | if (gfc->VBR_seek_tablecxx . . $ lame_internal_flags#VBR_seek_table..bagcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_1#bag.) { |
| 138 | freecxx . . $ free(5d22bdacc48458e8).(gfc->VBR_seek_tablecxx . . $ lame_internal_flags#VBR_seek_table..bagcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_1#bag.); |
| 139 | gfc->VBR_seek_tablecxx . . $ lame_internal_flags#VBR_seek_table..bagcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_1#bag. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 140 | gfc->VBR_seek_tablecxx . . $ lame_internal_flags#VBR_seek_table..sizecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_1#size. = 0; |
| 141 | } |
| 142 | if (gfc->ATHcxx . . $ lame_internal_flags#ATH.) { |
| 143 | freecxx . . $ free(5d22bdacc48458e8).(gfc->ATHcxx . . $ lame_internal_flags#ATH.); |
| 144 | } |
| 145 | if (gfc->sv_rpgcxx . . $ lame_internal_flags#sv_rpg..rgdatacxx . . $ $anonymous_type_fa6ce02aa65ebf3c_11#rgdata.) { |
| 146 | freecxx . . $ free(5d22bdacc48458e8).(gfc->sv_rpgcxx . . $ lame_internal_flags#sv_rpg..rgdatacxx . . $ $anonymous_type_fa6ce02aa65ebf3c_11#rgdata.); |
| 147 | } |
| 148 | if (gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..in_buffer_0cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#in_buffer_0.) { |
| 149 | freecxx . . $ free(5d22bdacc48458e8).(gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..in_buffer_0cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#in_buffer_0.); |
| 150 | } |
| 151 | if (gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..in_buffer_1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#in_buffer_1.) { |
| 152 | freecxx . . $ free(5d22bdacc48458e8).(gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..in_buffer_1cxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#in_buffer_1.); |
| 153 | } |
| 154 | free_id3tagcxx . . $ free_id3tag(4f558d83b2842a93).(gfc); |
| 155 | |
| 156 | #ifdef DECODE_ON_THE_FLY |
| 157 | if (gfc->hip) { |
| 158 | hip_decode_exit(gfc->hip); |
| 159 | gfc->hip = 0; |
| 160 | } |
| 161 | #endif |
| 162 | |
| 163 | free_global_datacxx . . $ free_global_data(4f558d83b2842a93).(gfc); |
| 164 | |
| 165 | freecxx . . $ free(5d22bdacc48458e8).(gfc); |
| 166 | } |
| 167 | |
| 168 | void |
| 169 | calloc_alignedcxx . . $ calloc_aligned(e8f4ad1733f94427).(aligned_pointer_tcxx . . $ aligned_pointer_t# * ptr, unsigned int size, unsigned int bytes) |
| 170 | { |
| 171 | if (ptr) { |
| 172 | if (!ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer.) { |
| 173 | ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size + bytes); |
| 174 | if (ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer. != 0) { |
| 175 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer., 0, size + bytes); |
| 176 | if (bytes > 0) { |
| 177 | ptr->alignedcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#aligned. = (void *) ((((size_t) ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer. + bytes - 1) / bytes) * bytes); |
| 178 | } |
| 179 | else { |
| 180 | ptr->alignedcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#aligned. = ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer.; |
| 181 | } |
| 182 | } |
| 183 | else { |
| 184 | ptr->alignedcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#aligned. = 0; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void |
| 191 | free_alignedcxx . . $ free_aligned(e81f82272f16aa8f).(aligned_pointer_tcxx . . $ aligned_pointer_t# * ptr) |
| 192 | { |
| 193 | if (ptr) { |
| 194 | if (ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer.) { |
| 195 | freecxx . . $ free(5d22bdacc48458e8).(ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer.); |
| 196 | ptr->pointercxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#pointer. = 0; |
| 197 | ptr->alignedcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_0#aligned. = 0; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /*those ATH formulas are returning |
| 203 | their minimum value for input = -1*/ |
| 204 | |
| 205 | static FLOATcxx . . $ FLOAT# |
| 206 | ATHformula_GBcxx . . $ ATHformula_GB(95d5df56d1097f86).(FLOATcxx . . $ FLOAT# f, FLOATcxx . . $ FLOAT# value, FLOATcxx . . $ FLOAT# f_min, FLOATcxx . . $ FLOAT# f_max) |
| 207 | { |
| 208 | /* from Painter & Spanias |
| 209 | modified by Gabriel Bouvigne to better fit the reality |
| 210 | ath = 3.640 * pow(f,-0.8) |
| 211 | - 6.800 * exp(-0.6*pow(f-3.4,2.0)) |
| 212 | + 6.000 * exp(-0.15*pow(f-8.7,2.0)) |
| 213 | + 0.6* 0.001 * pow(f,4.0); |
| 214 | |
| 215 | |
| 216 | In the past LAME was using the Painter &Spanias formula. |
| 217 | But we had some recurrent problems with HF content. |
| 218 | We measured real ATH values, and found the older formula |
| 219 | to be inacurate in the higher part. So we made this new |
| 220 | formula and this solved most of HF problematic testcases. |
| 221 | The tradeoff is that in VBR mode it increases a lot the |
| 222 | bitrate. */ |
| 223 | |
| 224 | |
| 225 | /*this curve can be udjusted according to the VBR scale: |
| 226 | it adjusts from something close to Painter & Spanias |
| 227 | on V9 up to Bouvigne's formula for V0. This way the VBR |
| 228 | bitrate is more balanced according to the -V value.*/ |
| 229 | |
| 230 | FLOATcxx . . $ FLOAT# ath; |
| 231 | |
| 232 | /* the following Hack allows to ask for the lowest value */ |
| 233 | if (f < -.3) |
| 234 | f = 3410; |
| 235 | |
| 236 | f /= 1000; /* convert to khz */ |
| 237 | f = Maxcxx . . $ `external/lame/util.h:92:17`!(f_min, f); |
| 238 | f = Mincxx . . $ `external/lame/util.h:91:17`!(f_max, f); |
| 239 | |
| 240 | ath = 3.640 * pow(f, -0.8) |
| 241 | - 6.800 * exp(-0.6 * pow(f - 3.4, 2.0)) |
| 242 | + 6.000 * exp(-0.15 * pow(f - 8.7, 2.0)) |
| 243 | + (0.6 + 0.04 * value) * 0.001 * pow(f, 4.0); |
| 244 | return ath; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | |
| 249 | FLOATcxx . . $ FLOAT# |
| 250 | ATHformulacxx . . $ ATHformula(e110220ec0e8c77a).(SessionConfig_tcxx . . $ SessionConfig_t# const *cfg, FLOATcxx . . $ FLOAT# f) |
| 251 | { |
| 252 | FLOATcxx . . $ FLOAT# ath; |
| 253 | switch (cfg->ATHtypecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#ATHtype.) { |
| 254 | case 0: |
| 255 | ath = ATHformula_GBcxx . . $ ATHformula_GB(95d5df56d1097f86).(f, 9, 0.1f, 24.0f); |
| 256 | break; |
| 257 | case 1: |
| 258 | ath = ATHformula_GBcxx . . $ ATHformula_GB(95d5df56d1097f86).(f, -1, 0.1f, 24.0f); /*over sensitive, should probably be removed */ |
| 259 | break; |
| 260 | case 2: |
| 261 | ath = ATHformula_GBcxx . . $ ATHformula_GB(95d5df56d1097f86).(f, 0, 0.1f, 24.0f); |
| 262 | break; |
| 263 | case 3: |
| 264 | ath = ATHformula_GBcxx . . $ ATHformula_GB(95d5df56d1097f86).(f, 1, 0.1f, 24.0f) + 6; /*modification of GB formula by Roel */ |
| 265 | break; |
| 266 | case 4: |
| 267 | ath = ATHformula_GBcxx . . $ ATHformula_GB(95d5df56d1097f86).(f, cfg->ATHcurvecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#ATHcurve., 0.1f, 24.0f); |
| 268 | break; |
| 269 | case 5: |
| 270 | ath = ATHformula_GBcxx . . $ ATHformula_GB(95d5df56d1097f86).(f, cfg->ATHcurvecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#ATHcurve., 3.41f, 16.1f); |
| 271 | break; |
| 272 | default: |
| 273 | ath = ATHformula_GBcxx . . $ ATHformula_GB(95d5df56d1097f86).(f, 0, 0.1f, 24.0f); |
| 274 | break; |
| 275 | } |
| 276 | return ath; |
| 277 | } |
| 278 | |
| 279 | /* see for example "Zwicker: Psychoakustik, 1982; ISBN 3-540-11401-7 */ |
| 280 | FLOATcxx . . $ FLOAT# |
| 281 | freq2barkcxx . . $ freq2bark(fbcf3211dfe1bfd1).(FLOATcxx . . $ FLOAT# freq) |
| 282 | { |
| 283 | /* input: freq in hz output: barks */ |
| 284 | if (freq < 0) |
| 285 | freq = 0; |
| 286 | freq = freq * 0.001; |
| 287 | return 13.0 * atan(.76 * freq) + 3.5 * atan(freq * freq / (7.5 * 7.5)); |
| 288 | } |
| 289 | |
| 290 | #if 0 |
| 291 | extern FLOAT freq2cbw(FLOAT freq); |
| 292 | |
| 293 | /* see for example "Zwicker: Psychoakustik, 1982; ISBN 3-540-11401-7 */ |
| 294 | FLOAT |
| 295 | freq2cbw(FLOAT freq) |
| 296 | { |
| 297 | /* input: freq in hz output: critical band width */ |
| 298 | freq = freq * 0.001; |
| 299 | return 25 + 75 * pow(1 + 1.4 * (freq * freq), 0.69); |
| 300 | } |
| 301 | |
| 302 | #endif |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | #define ABScxx . . $ `external/lame/util.c:307:9`!(A) (((A)>0) ? (A) : -(A)) |
| 308 | |
| 309 | int |
| 310 | FindNearestBitratecxx . . $ FindNearestBitrate(2326284602b0bb2d).(int bRate, /* legal rates from 8 to 320 */ |
| 311 | int version, int samplerate) |
| 312 | { /* MPEG-1 or MPEG-2 LSF */ |
| 313 | int bitrate; |
| 314 | int i; |
| 315 | |
| 316 | if (samplerate < 16000) |
| 317 | version = 2; |
| 318 | |
| 319 | bitrate = bitrate_tablecxx . . $ bitrate_table.[version][1]; |
| 320 | |
| 321 | for (i = 2; i <= 14; i++) { |
| 322 | if (bitrate_tablecxx . . $ bitrate_table.[version][i] > 0) { |
| 323 | if (ABScxx . . $ `external/lame/util.c:307:9`!(bitrate_table[version][i] - bRate) < ABScxx . . $ `external/lame/util.c:307:9`!(bitrate - bRate)) |
| 324 | bitrate = bitrate_tablecxx . . $ bitrate_table.[version][i]; |
| 325 | } |
| 326 | } |
| 327 | return bitrate; |
| 328 | } |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | #ifndef Mincxx . . $ `external/lame/util.h:91:17`! |
| 335 | #define Min(A, B) ((A) < (B) ? (A) : (B)) |
| 336 | #endif |
| 337 | #ifndef Maxcxx . . $ `external/lame/util.h:92:17`! |
| 338 | #define Max(A, B) ((A) > (B) ? (A) : (B)) |
| 339 | #endif |
| 340 | |
| 341 | |
| 342 | /* Used to find table index when |
| 343 | * we need bitrate-based values |
| 344 | * determined using tables |
| 345 | * |
| 346 | * bitrate in kbps |
| 347 | * |
| 348 | * Gabriel Bouvigne 2002-11-03 |
| 349 | */ |
| 350 | int |
| 351 | nearestBitrateFullIndexcxx . . $ nearestBitrateFullIndex(377f6a3136964dac).(uint16_tcxx . . $ uint16_t# bitrate) |
| 352 | { |
| 353 | /* borrowed from DM abr presets */ |
| 354 | |
| 355 | const int full_bitrate_table[] = |
| 356 | { 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 }; |
| 357 | |
| 358 | |
| 359 | int lower_range = 0, lower_range_kbps = 0, upper_range = 0, upper_range_kbps = 0; |
| 360 | |
| 361 | |
| 362 | int b; |
| 363 | |
| 364 | |
| 365 | /* We assume specified bitrate will be 320kbps */ |
| 366 | upper_range_kbps = full_bitrate_table[16]; |
| 367 | upper_range = 16; |
| 368 | lower_range_kbps = full_bitrate_table[16]; |
| 369 | lower_range = 16; |
| 370 | |
| 371 | /* Determine which significant bitrates the value specified falls between, |
| 372 | * if loop ends without breaking then we were correct above that the value was 320 |
| 373 | */ |
| 374 | for (b = 0; b < 16; b++) { |
| 375 | if ((Maxcxx . . $ `external/lame/util.h:92:17`!(bitrate, full_bitrate_table[b + 1])) != bitrate) { |
| 376 | upper_range_kbps = full_bitrate_table[b + 1]; |
| 377 | upper_range = b + 1; |
| 378 | lower_range_kbps = full_bitrate_table[b]; |
| 379 | lower_range = (b); |
| 380 | break; /* We found upper range */ |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /* Determine which range the value specified is closer to */ |
| 385 | if ((upper_range_kbps - bitrate) > (bitrate - lower_range_kbps)) { |
| 386 | return lower_range; |
| 387 | } |
| 388 | return upper_range; |
| 389 | } |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | /* map frequency to a valid MP3 sample frequency |
| 396 | * |
| 397 | * Robert Hegemann 2000-07-01 |
| 398 | */ |
| 399 | int |
| 400 | map2MP3Frequencycxx . . $ map2MP3Frequency(7864480464b09eea).(int freq) |
| 401 | { |
| 402 | if (freq <= 8000) |
| 403 | return 8000; |
| 404 | if (freq <= 11025) |
| 405 | return 11025; |
| 406 | if (freq <= 12000) |
| 407 | return 12000; |
| 408 | if (freq <= 16000) |
| 409 | return 16000; |
| 410 | if (freq <= 22050) |
| 411 | return 22050; |
| 412 | if (freq <= 24000) |
| 413 | return 24000; |
| 414 | if (freq <= 32000) |
| 415 | return 32000; |
| 416 | if (freq <= 44100) |
| 417 | return 44100; |
| 418 | |
| 419 | return 48000; |
| 420 | } |
| 421 | |
| 422 | int |
| 423 | BitrateIndexcxx . . $ BitrateIndex(2326284602b0bb2d).(int bRate, /* legal rates from 32 to 448 kbps */ |
| 424 | int version, /* MPEG-1 or MPEG-2/2.5 LSF */ |
| 425 | int samplerate) |
| 426 | { /* convert bitrate in kbps to index */ |
| 427 | int i; |
| 428 | if (samplerate < 16000) |
| 429 | version = 2; |
| 430 | for (i = 0; i <= 14; i++) { |
| 431 | if (bitrate_tablecxx . . $ bitrate_table.[version][i] > 0) { |
| 432 | if (bitrate_tablecxx . . $ bitrate_table.[version][i] == bRate) { |
| 433 | return i; |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | return -1; |
| 438 | } |
| 439 | |
| 440 | /* convert samp freq in Hz to index */ |
| 441 | |
| 442 | int |
| 443 | SmpFrqIndexcxx . . $ SmpFrqIndex(ac48f4a6ffa9e770).(int sample_freq, int *const version) |
| 444 | { |
| 445 | switch (sample_freq) { |
| 446 | case 44100: |
| 447 | *version = 1; |
| 448 | return 0; |
| 449 | case 48000: |
| 450 | *version = 1; |
| 451 | return 1; |
| 452 | case 32000: |
| 453 | *version = 1; |
| 454 | return 2; |
| 455 | case 22050: |
| 456 | *version = 0; |
| 457 | return 0; |
| 458 | case 24000: |
| 459 | *version = 0; |
| 460 | return 1; |
| 461 | case 16000: |
| 462 | *version = 0; |
| 463 | return 2; |
| 464 | case 11025: |
| 465 | *version = 0; |
| 466 | return 0; |
| 467 | case 12000: |
| 468 | *version = 0; |
| 469 | return 1; |
| 470 | case 8000: |
| 471 | *version = 0; |
| 472 | return 2; |
| 473 | default: |
| 474 | *version = 0; |
| 475 | return -1; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | |
| 480 | /***************************************************************************** |
| 481 | * |
| 482 | * End of bit_stream.c package |
| 483 | * |
| 484 | *****************************************************************************/ |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | /* resampling via FIR filter, blackman window */ |
| 496 | inlinecxx . . $ `external/lame/machine.h:107:10`! static FLOATcxx . . $ FLOAT# |
| 497 | blackmancxx . . $ blackman(6cf58f87de11613d).(FLOATcxx . . $ FLOAT# x, FLOATcxx . . $ FLOAT# fcn, int l) |
| 498 | { |
| 499 | /* This algorithm from: |
| 500 | SIGNAL PROCESSING ALGORITHMS IN FORTRAN AND C |
| 501 | S.D. Stearns and R.A. David, Prentice-Hall, 1992 |
| 502 | */ |
| 503 | FLOATcxx . . $ FLOAT# bkwn, x2; |
| 504 | FLOATcxx . . $ FLOAT# const wcn = (PIcxx . . $ `external/lame/util.h:56:17`! * fcn); |
| 505 | |
| 506 | x /= l; |
| 507 | if (x < 0) |
| 508 | x = 0; |
| 509 | if (x > 1) |
| 510 | x = 1; |
| 511 | x2 = x - .5; |
| 512 | |
| 513 | bkwn = 0.42 - 0.5 * cos(2 * x * PIcxx . . $ `external/lame/util.h:56:17`!) + 0.08 * cos(4 * x * PIcxx . . $ `external/lame/util.h:56:17`!); |
| 514 | if (fabs(x2) < 1e-9) |
| 515 | return wcn / PIcxx . . $ `external/lame/util.h:56:17`!; |
| 516 | else |
| 517 | return (bkwn * sin(l * wcn * x2) / (PIcxx . . $ `external/lame/util.h:56:17`! * l * x2)); |
| 518 | |
| 519 | |
| 520 | } |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | /* gcd - greatest common divisor */ |
| 526 | /* Joint work of Euclid and M. Hendry */ |
| 527 | |
| 528 | static int |
| 529 | gcdcxx . . $ gcd(9b79fb6aee4c0440).(int i, int j) |
| 530 | { |
| 531 | /* assert ( i > 0 && j > 0 ); */ |
| 532 | return j ? gcdcxx . . $ gcd(9b79fb6aee4c0440).(j, i % j) : i; |
| 533 | } |
| 534 | |
| 535 | |
| 536 | |
| 537 | static int |
| 538 | fill_buffer_resamplecxx . . $ fill_buffer_resample(3ca691ebf560588d).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, |
| 539 | sample_tcxx . . $ sample_t# * outbuf, |
| 540 | int desired_len, sample_tcxx . . $ sample_t# const *inbuf, int len, int *num_used, int ch) |
| 541 | { |
| 542 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 543 | EncStateVar_tcxx . . $ EncStateVar_t# *esv = &gfc->sv_enccxx . . $ lame_internal_flags#sv_enc.; |
| 544 | double resample_ratio = (double)cfg->samplerate_incxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_in. / (double)cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out.; |
| 545 | int BLACKSIZE; |
| 546 | FLOATcxx . . $ FLOAT# offset, xvalue; |
| 547 | int i, j = 0, k; |
| 548 | int filter_l; |
| 549 | FLOATcxx . . $ FLOAT# fcn, intratio; |
| 550 | FLOATcxx . . $ FLOAT# *inbuf_old; |
| 551 | int bpc; /* number of convolution functions to pre-compute */ |
| 552 | bpc = cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. / gcdcxx . . $ gcd(9b79fb6aee4c0440).(cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out., cfg->samplerate_incxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_in.); |
| 553 | if (bpc > BPCcxx . . $ `external/lame/util.h:254:9`!) |
| 554 | bpc = BPCcxx . . $ `external/lame/util.h:254:9`!; |
| 555 | |
| 556 | intratio = (fabs(resample_ratio - floor(.5 + resample_ratio)) < FLT_EPSILONcxx . . $ `<external>/18143172452841944454/float.h:113:9`!); |
| 557 | fcn = 1.00 / resample_ratio; |
| 558 | if (fcn > 1.00) |
| 559 | fcn = 1.00; |
| 560 | filter_l = 31; /* must be odd */ |
| 561 | filter_l += intratio; /* unless resample_ratio=int, it must be even */ |
| 562 | |
| 563 | |
| 564 | BLACKSIZE = filter_l + 1; /* size of data needed for FIR */ |
| 565 | |
| 566 | if (gfc->fill_buffer_resample_initcxx . . $ lame_internal_flags#fill_buffer_resample_init. == 0) { |
| 567 | esv->inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[0] = lame_calloccxx . . $ `external/lame/machine.h:161:9`!(sample_t, BLACKSIZE); |
| 568 | esv->inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[1] = lame_calloccxx . . $ `external/lame/machine.h:161:9`!(sample_t, BLACKSIZE); |
| 569 | for (i = 0; i <= 2 * bpc; ++i) |
| 570 | esv->blackfiltcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#blackfilt.[i] = lame_calloccxx . . $ `external/lame/machine.h:161:9`!(sample_t, BLACKSIZE); |
| 571 | |
| 572 | esv->itimecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#itime.[0] = 0; |
| 573 | esv->itimecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#itime.[1] = 0; |
| 574 | |
| 575 | /* precompute blackman filter coefficients */ |
| 576 | for (j = 0; j <= 2 * bpc; j++) { |
| 577 | FLOATcxx . . $ FLOAT# sum = 0.; |
| 578 | offset = (j - bpc) / (2. * bpc); |
| 579 | for (i = 0; i <= filter_l; i++) |
| 580 | sum += esv->blackfiltcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#blackfilt.[j][i] = blackmancxx . . $ blackman(6cf58f87de11613d).(i - offset, fcn, filter_l); |
| 581 | for (i = 0; i <= filter_l; i++) |
| 582 | esv->blackfiltcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#blackfilt.[j][i] /= sum; |
| 583 | } |
| 584 | gfc->fill_buffer_resample_initcxx . . $ lame_internal_flags#fill_buffer_resample_init. = 1; |
| 585 | } |
| 586 | |
| 587 | inbuf_old = esv->inbuf_oldcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#inbuf_old.[ch]; |
| 588 | |
| 589 | /* time of j'th element in inbuf = itime + j/ifreq; */ |
| 590 | /* time of k'th element in outbuf = j/ofreq */ |
| 591 | for (k = 0; k < desired_len; k++) { |
| 592 | double time0 = k * resample_ratio; /* time of k'th output sample */ |
| 593 | int joff; |
| 594 | |
| 595 | j = floor(time0 - esv->itimecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#itime.[ch]); |
| 596 | |
| 597 | /* check if we need more input data */ |
| 598 | if ((filter_l + j - filter_l / 2) >= len) |
| 599 | break; |
| 600 | |
| 601 | /* blackman filter. by default, window centered at j+.5(filter_l%2) */ |
| 602 | /* but we want a window centered at time0. */ |
| 603 | offset = (time0 - esv->itimecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#itime.[ch] - (j + .5 * (filter_l % 2))); |
| 604 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(fabs(offset) <= .501); |
| 605 | |
| 606 | /* find the closest precomputed window for this offset: */ |
| 607 | joff = floor((offset * 2 * bpc) + bpc + .5); |
| 608 | |
| 609 | xvalue = 0.; |
| 610 | for (i = 0; i <= filter_l; ++i) { |
| 611 | int const j2 = i + j - filter_l / 2; |
| 612 | sample_tcxx . . $ sample_t# y; |
| 613 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j2 < len); |
| 614 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j2 + BLACKSIZE >= 0); |
| 615 | y = (j2 < 0) ? inbuf_old[BLACKSIZE + j2] : inbuf[j2]; |
| 616 | #ifdef PRECOMPUTEcxx . . $ `external/lame/util.c:36:9`! |
| 617 | xvalue += y * esv->blackfiltcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#blackfilt.[joff][i]; |
| 618 | #else |
| 619 | xvalue += y * blackman(i - offset, fcn, filter_l); /* very slow! */ |
| 620 | #endif |
| 621 | } |
| 622 | outbuf[k] = xvalue; |
| 623 | } |
| 624 | |
| 625 | |
| 626 | /* k = number of samples added to outbuf */ |
| 627 | /* last k sample used data from [j-filter_l/2,j+filter_l-filter_l/2] */ |
| 628 | |
| 629 | /* how many samples of input data were used: */ |
| 630 | *num_used = Mincxx . . $ `external/lame/util.h:91:17`!(len, filter_l + j - filter_l / 2); |
| 631 | |
| 632 | /* adjust our input time counter. Incriment by the number of samples used, |
| 633 | * then normalize so that next output sample is at time 0, next |
| 634 | * input buffer is at time itime[ch] */ |
| 635 | esv->itimecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#itime.[ch] += *num_used - k * resample_ratio; |
| 636 | |
| 637 | /* save the last BLACKSIZE samples into the inbuf_old buffer */ |
| 638 | if (*num_used >= BLACKSIZE) { |
| 639 | for (i = 0; i < BLACKSIZE; i++) |
| 640 | inbuf_old[i] = inbuf[*num_used + i - BLACKSIZE]; |
| 641 | } |
| 642 | else { |
| 643 | /* shift in *num_used samples into inbuf_old */ |
| 644 | int const n_shift = BLACKSIZE - *num_used; /* number of samples to shift */ |
| 645 | |
| 646 | /* shift n_shift samples by *num_used, to make room for the |
| 647 | * num_used new samples */ |
| 648 | for (i = 0; i < n_shift; ++i) |
| 649 | inbuf_old[i] = inbuf_old[i + *num_used]; |
| 650 | |
| 651 | /* shift in the *num_used samples */ |
| 652 | for (j = 0; i < BLACKSIZE; ++i, ++j) |
| 653 | inbuf_old[i] = inbuf[j]; |
| 654 | |
| 655 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(j == *num_used); |
| 656 | } |
| 657 | return k; /* return the number samples created at the new samplerate */ |
| 658 | } |
| 659 | |
| 660 | int |
| 661 | isResamplingNecessarycxx . . $ isResamplingNecessary(3353a2dd70c7b2e6).(SessionConfig_tcxx . . $ SessionConfig_t# const* cfg) |
| 662 | { |
| 663 | int const l = cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. * 0.9995f; |
| 664 | int const h = cfg->samplerate_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_out. * 1.0005f; |
| 665 | return (cfg->samplerate_incxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_in. < l) || (h < cfg->samplerate_incxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#samplerate_in.) ? 1 : 0; |
| 666 | } |
| 667 | |
| 668 | /* copy in new samples from in_buffer into mfbuf, with resampling |
| 669 | if necessary. n_in = number of samples from the input buffer that |
| 670 | were used. n_out = number of samples copied into mfbuf */ |
| 671 | |
| 672 | void |
| 673 | fill_buffercxx . . $ fill_buffer(a28439526dc95a64).(lame_internal_flagscxx . . $ lame_internal_flags# * gfc, |
| 674 | sample_tcxx . . $ sample_t# * const mfbuf[2], sample_tcxx . . $ sample_t# const * const in_buffer[2], int nsamples, int *n_in, int *n_out) |
| 675 | { |
| 676 | SessionConfig_tcxx . . $ SessionConfig_t# const *const cfg = &gfc->cfgcxx . . $ lame_internal_flags#cfg.; |
| 677 | int mf_size = gfc->sv_enccxx . . $ lame_internal_flags#sv_enc..mf_sizecxx . . $ $anonymous_type_fa6ce02aa65ebf3c_7#mf_size.; |
| 678 | int framesize = 576 * cfg->mode_grcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#mode_gr.; |
| 679 | int nout, ch = 0; |
| 680 | int nch = cfg->channels_outcxx . . $ $anonymous_type_fa6ce02aa65ebf3c_13#channels_out.; |
| 681 | |
| 682 | /* copy in new samples into mfbuf, with resampling if necessary */ |
| 683 | if (isResamplingNecessarycxx . . $ isResamplingNecessary(3353a2dd70c7b2e6).(cfg)) { |
| 684 | do { |
| 685 | nout = |
| 686 | fill_buffer_resamplecxx . . $ fill_buffer_resample(3ca691ebf560588d).(gfc, &mfbuf[ch][mf_size], |
| 687 | framesize, in_buffer[ch], nsamples, n_in, ch); |
| 688 | } while (++ch < nch); |
| 689 | *n_out = nout; |
| 690 | } |
| 691 | else { |
| 692 | nout = Mincxx . . $ `external/lame/util.h:91:17`!(framesize, nsamples); |
| 693 | do { |
| 694 | memcpycxx . . $ memcpy(cc817cb175f282d).(&mfbuf[ch][mf_size], &in_buffer[ch][0], nout * sizeof(mfbuf[0][0])); |
| 695 | } while (++ch < nch); |
| 696 | *n_out = nout; |
| 697 | *n_in = nout; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | /*********************************************************************** |
| 708 | * |
| 709 | * Message Output |
| 710 | * |
| 711 | ***********************************************************************/ |
| 712 | |
| 713 | void |
| 714 | lame_report_defcxx . . $ lame_report_def(ac175dd46a4e4d7f).(const char *format, va_listcxx . . $ va_list# args) |
| 715 | { |
| 716 | (void) vfprintfcxx . . $ vfprintf(bded311e54d67f9c).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, format, args); |
| 717 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!); /* an debug function should flush immediately */ |
| 718 | } |
| 719 | |
| 720 | void |
| 721 | lame_report_fnccxx . . $ lame_report_fnc(eff5491a82813ecf).(lame_report_functioncxx . . $ lame_report_function# print_f, const char *format, ...) |
| 722 | { |
| 723 | if (print_f) { |
| 724 | va_listcxx . . $ va_list# args; |
| 725 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, format); |
| 726 | print_f(format, args); |
| 727 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | |
| 732 | void |
| 733 | lame_debugfcxx . . $ lame_debugf(9ec3808e79d7f8bc).(const lame_internal_flagscxx . . $ lame_internal_flags#* gfc, const char *format, ...) |
| 734 | { |
| 735 | if (gfc && gfc->report_dbgcxx . . $ lame_internal_flags#report_dbg.) { |
| 736 | va_listcxx . . $ va_list# args; |
| 737 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, format); |
| 738 | gfc->report_dbgcxx . . $ lame_internal_flags#report_dbg.(format, args); |
| 739 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | |
| 744 | void |
| 745 | lame_msgfcxx . . $ lame_msgf(9ec3808e79d7f8bc).(const lame_internal_flagscxx . . $ lame_internal_flags#* gfc, const char *format, ...) |
| 746 | { |
| 747 | if (gfc && gfc->report_msgcxx . . $ lame_internal_flags#report_msg.) { |
| 748 | va_listcxx . . $ va_list# args; |
| 749 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, format); |
| 750 | gfc->report_msgcxx . . $ lame_internal_flags#report_msg.(format, args); |
| 751 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | |
| 756 | void |
| 757 | lame_errorfcxx . . $ lame_errorf(9ec3808e79d7f8bc).(const lame_internal_flagscxx . . $ lame_internal_flags#* gfc, const char *format, ...) |
| 758 | { |
| 759 | if (gfc && gfc->report_errcxx . . $ lame_internal_flags#report_err.) { |
| 760 | va_listcxx . . $ va_list# args; |
| 761 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, format); |
| 762 | gfc->report_errcxx . . $ lame_internal_flags#report_err.(format, args); |
| 763 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | |
| 768 | |
| 769 | /*********************************************************************** |
| 770 | * |
| 771 | * routines to detect CPU specific features like 3DNow, MMX, SSE |
| 772 | * |
| 773 | * donated by Frank Klemm |
| 774 | * added Robert Hegemann 2000-10-10 |
| 775 | * |
| 776 | ***********************************************************************/ |
| 777 | |
| 778 | #ifdef HAVE_NASM |
| 779 | extern int has_MMX_nasm(void); |
| 780 | extern int has_3DNow_nasm(void); |
| 781 | extern int has_SSE_nasm(void); |
| 782 | extern int has_SSE2_nasm(void); |
| 783 | #endif |
| 784 | |
| 785 | int |
| 786 | has_MMXcxx . . $ has_MMX(b126dc7c1de90089).(void) |
| 787 | { |
| 788 | #ifdef HAVE_NASM |
| 789 | return has_MMX_nasm(); |
| 790 | #else |
| 791 | return 0; /* don't know, assume not */ |
| 792 | #endif |
| 793 | } |
| 794 | |
| 795 | int |
| 796 | has_3DNowcxx . . $ has_3DNow(b126dc7c1de90089).(void) |
| 797 | { |
| 798 | #ifdef HAVE_NASM |
| 799 | return has_3DNow_nasm(); |
| 800 | #else |
| 801 | return 0; /* don't know, assume not */ |
| 802 | #endif |
| 803 | } |
| 804 | |
| 805 | int |
| 806 | has_SSEcxx . . $ has_SSE(b126dc7c1de90089).(void) |
| 807 | { |
| 808 | #ifdef HAVE_NASM |
| 809 | return has_SSE_nasm(); |
| 810 | #else |
| 811 | #if defined( _M_X64 ) || defined( MIN_ARCH_SSE ) |
| 812 | return 1; |
| 813 | #else |
| 814 | return 0; /* don't know, assume not */ |
| 815 | #endif |
| 816 | #endif |
| 817 | } |
| 818 | |
| 819 | int |
| 820 | has_SSE2cxx . . $ has_SSE2(b126dc7c1de90089).(void) |
| 821 | { |
| 822 | #ifdef HAVE_NASM |
| 823 | return has_SSE2_nasm(); |
| 824 | #else |
| 825 | #if defined( _M_X64 ) || defined( MIN_ARCH_SSE ) |
| 826 | return 1; |
| 827 | #else |
| 828 | return 0; /* don't know, assume not */ |
| 829 | #endif |
| 830 | #endif |
| 831 | } |
| 832 | |
| 833 | void |
| 834 | disable_FPEcxx . . $ disable_FPE(49f6e7a06ebc5aa8).(void) |
| 835 | { |
| 836 | /* extremly system dependent stuff, move to a lib to make the code readable */ |
| 837 | /*==========================================================================*/ |
| 838 | |
| 839 | |
| 840 | |
| 841 | /* |
| 842 | * Disable floating point exceptions |
| 843 | */ |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | #if defined(__FreeBSD__) && !defined(__alpha__) |
| 849 | { |
| 850 | /* seet floating point mask to the Linux default */ |
| 851 | fp_except_t mask; |
| 852 | mask = fpgetmask(); |
| 853 | /* if bit is set, we get SIGFPE on that error! */ |
| 854 | fpsetmask(mask & ~(FP_X_INV | FP_X_DZ)); |
| 855 | /* DEBUGF("FreeBSD mask is 0x%x\n",mask); */ |
| 856 | } |
| 857 | #endif |
| 858 | |
| 859 | #if defined(__riscos__) && !defined(ABORTFP) |
| 860 | /* Disable FPE's under RISC OS */ |
| 861 | /* if bit is set, we disable trapping that error! */ |
| 862 | /* _FPE_IVO : invalid operation */ |
| 863 | /* _FPE_DVZ : divide by zero */ |
| 864 | /* _FPE_OFL : overflow */ |
| 865 | /* _FPE_UFL : underflow */ |
| 866 | /* _FPE_INX : inexact */ |
| 867 | DisableFPETraps(_FPE_IVO | _FPE_DVZ | _FPE_OFL); |
| 868 | #endif |
| 869 | |
| 870 | /* |
| 871 | * Debugging stuff |
| 872 | * The default is to ignore FPE's, unless compiled with -DABORTFP |
| 873 | * so add code below to ENABLE FPE's. |
| 874 | */ |
| 875 | |
| 876 | #if defined(ABORTFP) |
| 877 | #if defined(_MSC_VER) |
| 878 | { |
| 879 | #if 0 |
| 880 | /* rh 061207 |
| 881 | the following fix seems to be a workaround for a problem in the |
| 882 | parent process calling LAME. It would be better to fix the broken |
| 883 | application => code disabled. |
| 884 | */ |
| 885 | |
| 886 | /* set affinity to a single CPU. Fix for EAC/lame on SMP systems from |
| 887 | "Todd Richmond" <[email protected]> */ |
| 888 | SYSTEM_INFO si; |
| 889 | GetSystemInfo(&si); |
| 890 | SetProcessAffinityMask(GetCurrentProcess(), si.dwActiveProcessorMask); |
| 891 | #endif |
| 892 | #include <float.h> |
| 893 | unsigned int mask; |
| 894 | mask = _controlfp(0, 0); |
| 895 | mask &= ~(_EM_OVERFLOW | _EM_UNDERFLOW | _EM_ZERODIVIDE | _EM_INVALID); |
| 896 | mask = _controlfp(mask, _MCW_EM); |
| 897 | } |
| 898 | #elif defined(__CYGWIN__) |
| 899 | # define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw)) |
| 900 | # define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw)) |
| 901 | |
| 902 | # define _EM_INEXACT 0x00000020 /* inexact (precision) */ |
| 903 | # define _EM_UNDERFLOW 0x00000010 /* underflow */ |
| 904 | # define _EM_OVERFLOW 0x00000008 /* overflow */ |
| 905 | # define _EM_ZERODIVIDE 0x00000004 /* zero divide */ |
| 906 | # define _EM_INVALID 0x00000001 /* invalid */ |
| 907 | { |
| 908 | unsigned int mask; |
| 909 | _FPU_GETCW(mask); |
| 910 | /* Set the FPU control word to abort on most FPEs */ |
| 911 | mask &= ~(_EM_OVERFLOW | _EM_ZERODIVIDE | _EM_INVALID); |
| 912 | _FPU_SETCW(mask); |
| 913 | } |
| 914 | # elif defined(__linux__) |
| 915 | { |
| 916 | |
| 917 | # include <fpu_control.h> |
| 918 | # ifndef _FPU_GETCW |
| 919 | # define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw)) |
| 920 | # endif |
| 921 | # ifndef _FPU_SETCW |
| 922 | # define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw)) |
| 923 | # endif |
| 924 | |
| 925 | /* |
| 926 | * Set the Linux mask to abort on most FPE's |
| 927 | * if bit is set, we _mask_ SIGFPE on that error! |
| 928 | * mask &= ~( _FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM ); |
| 929 | */ |
| 930 | |
| 931 | unsigned int mask; |
| 932 | _FPU_GETCW(mask); |
| 933 | mask &= ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM); |
| 934 | _FPU_SETCW(mask); |
| 935 | } |
| 936 | #endif |
| 937 | #endif /* ABORTFP */ |
| 938 | } |
| 939 | |
| 940 | |
| 941 | |
| 942 | |
| 943 | |
| 944 | #ifdef USE_FAST_LOGcxx . . $ `external/lame/lame__config.h:292:9`! |
| 945 | /*********************************************************************** |
| 946 | * |
| 947 | * Fast Log Approximation for log2, used to approximate every other log |
| 948 | * (log10 and log) |
| 949 | * maximum absolute error for log10 is around 10-6 |
| 950 | * maximum *relative* error can be high when x is almost 1 because error/log10(x) tends toward x/e |
| 951 | * |
| 952 | * use it if typical RESULT values are > 1e-5 (for example if x>1.00001 or x<0.99999) |
| 953 | * or if the relative precision in the domain around 1 is not important (result in 1 is exact and 0) |
| 954 | * |
| 955 | ***********************************************************************/ |
| 956 | |
| 957 | |
| 958 | #define LOG2_SIZEcxx . . $ `external/lame/util.c:958:9`! (512) |
| 959 | #define LOG2_SIZE_L2cxx . . $ `external/lame/util.c:959:9`! (9) |
| 960 | |
| 961 | static ieee754_float32_tcxx . . $ ieee754_float32_t# log_tablecxx . . $ log_table.[LOG2_SIZEcxx . . $ `external/lame/util.c:958:9`! + 1]; |
| 962 | |
| 963 | |
| 964 | |
| 965 | void |
| 966 | init_log_tablecxx . . $ init_log_table(49f6e7a06ebc5aa8).(void) |
| 967 | { |
| 968 | int j; |
| 969 | static int init = 0; |
| 970 | |
| 971 | /* Range for log2(x) over [1,2[ is [0,1[ */ |
| 972 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!((1 << LOG2_SIZE_L2cxx . . $ `external/lame/util.c:959:9`!) == LOG2_SIZEcxx . . $ `external/lame/util.c:958:9`!); |
| 973 | |
| 974 | if (!init) { |
| 975 | for (j = 0; j < LOG2_SIZEcxx . . $ `external/lame/util.c:958:9`! + 1; j++) |
| 976 | log_tablecxx . . $ log_table.[j] = log(1.0f + j / (ieee754_float32_tcxx . . $ ieee754_float32_t#) LOG2_SIZEcxx . . $ `external/lame/util.c:958:9`!) / log(2.0f); |
| 977 | } |
| 978 | init = 1; |
| 979 | } |
| 980 | |
| 981 | |
| 982 | |
| 983 | ieee754_float32_tcxx . . $ ieee754_float32_t# |
| 984 | fast_log2cxx . . $ fast_log2(fbcf3211dfe1bfd1).(ieee754_float32_tcxx . . $ ieee754_float32_t# x) |
| 985 | { |
| 986 | ieee754_float32_tcxx . . $ ieee754_float32_t# log2val, partial; |
| 987 | unioncxx . . $ fast_log2(fbcf3211dfe1bfd1).$anonymous_type_0# { |
| 988 | ieee754_float32_tcxx . . $ ieee754_float32_t# fcxx . . $ fast_log2(fbcf3211dfe1bfd1).$anonymous_type_0#f.; |
| 989 | int icxx . . $ fast_log2(fbcf3211dfe1bfd1).$anonymous_type_0#i.; |
| 990 | } fi; |
| 991 | int mantisse; |
| 992 | fi.fcxx . . $ fast_log2(fbcf3211dfe1bfd1).$anonymous_type_0#f. = x; |
| 993 | mantisse = fi.icxx . . $ fast_log2(fbcf3211dfe1bfd1).$anonymous_type_0#i. & 0x7fffff; |
| 994 | log2val = ((fi.icxx . . $ fast_log2(fbcf3211dfe1bfd1).$anonymous_type_0#i. >> 23) & 0xFF) - 0x7f; |
| 995 | partial = (mantisse & ((1 << (23 - LOG2_SIZE_L2cxx . . $ `external/lame/util.c:959:9`!)) - 1)); |
| 996 | partial *= 1.0f / ((1 << (23 - LOG2_SIZE_L2cxx . . $ `external/lame/util.c:959:9`!))); |
| 997 | |
| 998 | |
| 999 | mantisse >>= (23 - LOG2_SIZE_L2cxx . . $ `external/lame/util.c:959:9`!); |
| 1000 | |
| 1001 | /* log2val += log_table[mantisse]; without interpolation the results are not good */ |
| 1002 | log2val += log_tablecxx . . $ log_table.[mantisse] * (1.0f - partial) + log_tablecxx . . $ log_table.[mantisse + 1] * partial; |
| 1003 | |
| 1004 | return log2val; |
| 1005 | } |
| 1006 | |
| 1007 | #else /* Don't use FAST_LOG */ |
| 1008 | |
| 1009 | |
| 1010 | void |
| 1011 | init_log_table(void) |
| 1012 | { |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | #endif |
| 1017 | |
| 1018 | /* end of util.c */ |