mpegaudio_tablegen.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Header file for hardcoded mpegaudiodec tables
  3. *
  4. * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_MPEGAUDIO_TABLEGEN_H
  23. #define AVCODEC_MPEGAUDIO_TABLEGEN_H
  24. #include <stdint.h>
  25. #include <math.h>
  26. #include "libavutil/attributes.h"
  27. #define TABLE_4_3_SIZE (8191 + 16)*4
  28. #if CONFIG_HARDCODED_TABLES
  29. #define mpegaudio_tableinit()
  30. #include "libavcodec/mpegaudio_tables.h"
  31. #else
  32. static int8_t table_4_3_exp[TABLE_4_3_SIZE];
  33. static uint32_t table_4_3_value[TABLE_4_3_SIZE];
  34. static uint32_t exp_table_fixed[512];
  35. static uint32_t expval_table_fixed[512][16];
  36. static float exp_table_float[512];
  37. static float expval_table_float[512][16];
  38. #define FRAC_BITS 23
  39. #define IMDCT_SCALAR 1.759
  40. static av_cold void mpegaudio_tableinit(void)
  41. {
  42. int i, value, exponent;
  43. static const double exp2_lut[4] = {
  44. 1.00000000000000000000, /* 2 ^ (0 * 0.25) */
  45. 1.18920711500272106672, /* 2 ^ (1 * 0.25) */
  46. M_SQRT2 , /* 2 ^ (2 * 0.25) */
  47. 1.68179283050742908606, /* 2 ^ (3 * 0.25) */
  48. };
  49. static double pow43_lut[16];
  50. double exp2_base = 2.11758236813575084767080625169910490512847900390625e-22; // 2^(-72)
  51. double exp2_val;
  52. double pow43_val = 0;
  53. for (i = 0; i < 16; ++i)
  54. pow43_lut[i] = i * cbrt(i);
  55. for (i = 1; i < TABLE_4_3_SIZE; i++) {
  56. double f, fm;
  57. int e, m;
  58. double value = i / 4;
  59. if ((i & 3) == 0)
  60. pow43_val = value / IMDCT_SCALAR * cbrt(value);
  61. f = pow43_val * exp2_lut[i & 3];
  62. fm = frexp(f, &e);
  63. m = llrint(fm * (1LL << 31));
  64. e += FRAC_BITS - 31 + 5 - 100;
  65. /* normalized to FRAC_BITS */
  66. table_4_3_value[i] = m;
  67. table_4_3_exp[i] = -e;
  68. }
  69. for (exponent = 0; exponent < 512; exponent++) {
  70. if (exponent && (exponent & 3) == 0)
  71. exp2_base *= 2;
  72. exp2_val = exp2_base * exp2_lut[exponent & 3] / IMDCT_SCALAR;
  73. for (value = 0; value < 16; value++) {
  74. double f = pow43_lut[value] * exp2_val;
  75. expval_table_fixed[exponent][value] = (f < 0xFFFFFFFF ? llrint(f) : 0xFFFFFFFF);
  76. expval_table_float[exponent][value] = f;
  77. }
  78. exp_table_fixed[exponent] = expval_table_fixed[exponent][1];
  79. exp_table_float[exponent] = expval_table_float[exponent][1];
  80. }
  81. }
  82. #endif /* CONFIG_HARDCODED_TABLES */
  83. #endif /* AVCODEC_MPEGAUDIO_TABLEGEN_H */