You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.3KB

  1. /*
  2. * Header file for hardcoded QDM2 tables
  3. *
  4. * Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_QDM2_TABLEGEN_H
  23. #define AVCODEC_QDM2_TABLEGEN_H
  24. #include <stdint.h>
  25. #include <math.h>
  26. #include "libavutil/attributes.h"
  27. #define SOFTCLIP_THRESHOLD 27600
  28. #define HARDCLIP_THRESHOLD 35716
  29. #if CONFIG_HARDCODED_TABLES
  30. #define softclip_table_init()
  31. #define rnd_table_init()
  32. #define init_noise_samples()
  33. #include "libavcodec/qdm2_tables.h"
  34. #else
  35. static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1];
  36. static float noise_table[4096];
  37. static uint8_t random_dequant_index[256][5];
  38. static uint8_t random_dequant_type24[128][3];
  39. static float noise_samples[128];
  40. static av_cold void softclip_table_init(void) {
  41. int i;
  42. double dfl = SOFTCLIP_THRESHOLD - 32767;
  43. float delta = 1.0 / -dfl;
  44. for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++)
  45. softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF);
  46. }
  47. // random generated table
  48. static av_cold void rnd_table_init(void) {
  49. int i,j;
  50. uint32_t ldw,hdw;
  51. uint64_t tmp64_1;
  52. uint64_t random_seed = 0;
  53. float delta = 1.0 / 16384.0;
  54. for(i = 0; i < 4096 ;i++) {
  55. random_seed = random_seed * 214013 + 2531011;
  56. noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3;
  57. }
  58. for (i = 0; i < 256 ;i++) {
  59. random_seed = 81;
  60. ldw = i;
  61. for (j = 0; j < 5 ;j++) {
  62. random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF);
  63. ldw = (uint32_t)ldw % (uint32_t)random_seed;
  64. tmp64_1 = (random_seed * 0x55555556);
  65. hdw = (uint32_t)(tmp64_1 >> 32);
  66. random_seed = (uint64_t)(hdw + (ldw >> 31));
  67. }
  68. }
  69. for (i = 0; i < 128 ;i++) {
  70. random_seed = 25;
  71. ldw = i;
  72. for (j = 0; j < 3 ;j++) {
  73. random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF);
  74. ldw = (uint32_t)ldw % (uint32_t)random_seed;
  75. tmp64_1 = (random_seed * 0x66666667);
  76. hdw = (uint32_t)(tmp64_1 >> 33);
  77. random_seed = hdw + (ldw >> 31);
  78. }
  79. }
  80. }
  81. static av_cold void init_noise_samples(void) {
  82. int i;
  83. unsigned random_seed = 0;
  84. float delta = 1.0 / 16384.0;
  85. for (i = 0; i < 128;i++) {
  86. random_seed = random_seed * 214013 + 2531011;
  87. noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0);
  88. }
  89. }
  90. #endif /* CONFIG_HARDCODED_TABLES */
  91. #endif /* AVCODEC_QDM2_TABLEGEN_H */