qdm2_tablegen.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 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_QDM2_TABLEGEN_H
  23. #define AVCODEC_QDM2_TABLEGEN_H
  24. #include <stdint.h>
  25. #include <math.h>
  26. #include "libavutil/attributes.h"
  27. #include "qdm2data.h"
  28. #define SOFTCLIP_THRESHOLD 27600
  29. #define HARDCLIP_THRESHOLD 35716
  30. #if CONFIG_HARDCODED_TABLES
  31. #define softclip_table_init()
  32. #define rnd_table_init()
  33. #define init_noise_samples()
  34. #define qdm2_init_vlc()
  35. #include "libavcodec/qdm2_tables.h"
  36. #else
  37. static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1];
  38. static float noise_table[4096 + 20];
  39. static uint8_t random_dequant_index[256][5];
  40. static uint8_t random_dequant_type24[128][3];
  41. static float noise_samples[128];
  42. static av_cold void softclip_table_init(void) {
  43. int i;
  44. double dfl = SOFTCLIP_THRESHOLD - 32767;
  45. float delta = 1.0 / -dfl;
  46. for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++)
  47. softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF);
  48. }
  49. // random generated table
  50. static av_cold void rnd_table_init(void) {
  51. int i,j;
  52. uint32_t ldw;
  53. uint64_t random_seed = 0;
  54. float delta = 1.0 / 16384.0;
  55. for(i = 0; i < 4096 ;i++) {
  56. random_seed = random_seed * 214013 + 2531011;
  57. noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3;
  58. }
  59. for (i = 0; i < 256 ;i++) {
  60. random_seed = 81;
  61. ldw = i;
  62. for (j = 0; j < 5 ;j++) {
  63. random_dequant_index[i][j] = ldw / random_seed;
  64. ldw %= random_seed;
  65. random_seed /= 3;
  66. }
  67. }
  68. for (i = 0; i < 128 ;i++) {
  69. random_seed = 25;
  70. ldw = i;
  71. for (j = 0; j < 3 ;j++) {
  72. random_dequant_type24[i][j] = ldw / random_seed;
  73. ldw %= random_seed;
  74. random_seed /= 5;
  75. }
  76. }
  77. }
  78. static av_cold void init_noise_samples(void) {
  79. int i;
  80. unsigned random_seed = 0;
  81. float delta = 1.0 / 16384.0;
  82. for (i = 0; i < 128;i++) {
  83. random_seed = random_seed * 214013 + 2531011;
  84. noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0);
  85. }
  86. }
  87. static VLC vlc_tab_level;
  88. static VLC vlc_tab_diff;
  89. static VLC vlc_tab_run;
  90. static VLC fft_level_exp_alt_vlc;
  91. static VLC fft_level_exp_vlc;
  92. static VLC fft_stereo_exp_vlc;
  93. static VLC fft_stereo_phase_vlc;
  94. static VLC vlc_tab_tone_level_idx_hi1;
  95. static VLC vlc_tab_tone_level_idx_mid;
  96. static VLC vlc_tab_tone_level_idx_hi2;
  97. static VLC vlc_tab_type30;
  98. static VLC vlc_tab_type34;
  99. static VLC vlc_tab_fft_tone_offset[5];
  100. static const uint16_t qdm2_vlc_offs[] = {
  101. 0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
  102. };
  103. static VLC_TYPE qdm2_table[3838][2];
  104. static av_cold void qdm2_init_vlc(void)
  105. {
  106. vlc_tab_level.table = &qdm2_table[qdm2_vlc_offs[0]];
  107. vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
  108. init_vlc(&vlc_tab_level, 8, 24,
  109. vlc_tab_level_huffbits, 1, 1,
  110. vlc_tab_level_huffcodes, 2, 2,
  111. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  112. vlc_tab_diff.table = &qdm2_table[qdm2_vlc_offs[1]];
  113. vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
  114. init_vlc(&vlc_tab_diff, 8, 37,
  115. vlc_tab_diff_huffbits, 1, 1,
  116. vlc_tab_diff_huffcodes, 2, 2,
  117. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  118. vlc_tab_run.table = &qdm2_table[qdm2_vlc_offs[2]];
  119. vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
  120. init_vlc(&vlc_tab_run, 5, 6,
  121. vlc_tab_run_huffbits, 1, 1,
  122. vlc_tab_run_huffcodes, 1, 1,
  123. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  124. fft_level_exp_alt_vlc.table = &qdm2_table[qdm2_vlc_offs[3]];
  125. fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] -
  126. qdm2_vlc_offs[3];
  127. init_vlc(&fft_level_exp_alt_vlc, 8, 28,
  128. fft_level_exp_alt_huffbits, 1, 1,
  129. fft_level_exp_alt_huffcodes, 2, 2,
  130. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  131. fft_level_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[4]];
  132. fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
  133. init_vlc(&fft_level_exp_vlc, 8, 20,
  134. fft_level_exp_huffbits, 1, 1,
  135. fft_level_exp_huffcodes, 2, 2,
  136. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  137. fft_stereo_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[5]];
  138. fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] -
  139. qdm2_vlc_offs[5];
  140. init_vlc(&fft_stereo_exp_vlc, 6, 7,
  141. fft_stereo_exp_huffbits, 1, 1,
  142. fft_stereo_exp_huffcodes, 1, 1,
  143. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  144. fft_stereo_phase_vlc.table = &qdm2_table[qdm2_vlc_offs[6]];
  145. fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] -
  146. qdm2_vlc_offs[6];
  147. init_vlc(&fft_stereo_phase_vlc, 6, 9,
  148. fft_stereo_phase_huffbits, 1, 1,
  149. fft_stereo_phase_huffcodes, 1, 1,
  150. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  151. vlc_tab_tone_level_idx_hi1.table =
  152. &qdm2_table[qdm2_vlc_offs[7]];
  153. vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] -
  154. qdm2_vlc_offs[7];
  155. init_vlc(&vlc_tab_tone_level_idx_hi1, 8, 20,
  156. vlc_tab_tone_level_idx_hi1_huffbits, 1, 1,
  157. vlc_tab_tone_level_idx_hi1_huffcodes, 2, 2,
  158. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  159. vlc_tab_tone_level_idx_mid.table =
  160. &qdm2_table[qdm2_vlc_offs[8]];
  161. vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] -
  162. qdm2_vlc_offs[8];
  163. init_vlc(&vlc_tab_tone_level_idx_mid, 8, 24,
  164. vlc_tab_tone_level_idx_mid_huffbits, 1, 1,
  165. vlc_tab_tone_level_idx_mid_huffcodes, 2, 2,
  166. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  167. vlc_tab_tone_level_idx_hi2.table =
  168. &qdm2_table[qdm2_vlc_offs[9]];
  169. vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] -
  170. qdm2_vlc_offs[9];
  171. init_vlc(&vlc_tab_tone_level_idx_hi2, 8, 24,
  172. vlc_tab_tone_level_idx_hi2_huffbits, 1, 1,
  173. vlc_tab_tone_level_idx_hi2_huffcodes, 2, 2,
  174. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  175. vlc_tab_type30.table = &qdm2_table[qdm2_vlc_offs[10]];
  176. vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
  177. init_vlc(&vlc_tab_type30, 6, 9,
  178. vlc_tab_type30_huffbits, 1, 1,
  179. vlc_tab_type30_huffcodes, 1, 1,
  180. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  181. vlc_tab_type34.table = &qdm2_table[qdm2_vlc_offs[11]];
  182. vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
  183. init_vlc(&vlc_tab_type34, 5, 10,
  184. vlc_tab_type34_huffbits, 1, 1,
  185. vlc_tab_type34_huffcodes, 1, 1,
  186. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  187. vlc_tab_fft_tone_offset[0].table =
  188. &qdm2_table[qdm2_vlc_offs[12]];
  189. vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] -
  190. qdm2_vlc_offs[12];
  191. init_vlc(&vlc_tab_fft_tone_offset[0], 8, 23,
  192. vlc_tab_fft_tone_offset_0_huffbits, 1, 1,
  193. vlc_tab_fft_tone_offset_0_huffcodes, 2, 2,
  194. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  195. vlc_tab_fft_tone_offset[1].table =
  196. &qdm2_table[qdm2_vlc_offs[13]];
  197. vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] -
  198. qdm2_vlc_offs[13];
  199. init_vlc(&vlc_tab_fft_tone_offset[1], 8, 28,
  200. vlc_tab_fft_tone_offset_1_huffbits, 1, 1,
  201. vlc_tab_fft_tone_offset_1_huffcodes, 2, 2,
  202. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  203. vlc_tab_fft_tone_offset[2].table =
  204. &qdm2_table[qdm2_vlc_offs[14]];
  205. vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] -
  206. qdm2_vlc_offs[14];
  207. init_vlc(&vlc_tab_fft_tone_offset[2], 8, 32,
  208. vlc_tab_fft_tone_offset_2_huffbits, 1, 1,
  209. vlc_tab_fft_tone_offset_2_huffcodes, 2, 2,
  210. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  211. vlc_tab_fft_tone_offset[3].table =
  212. &qdm2_table[qdm2_vlc_offs[15]];
  213. vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] -
  214. qdm2_vlc_offs[15];
  215. init_vlc(&vlc_tab_fft_tone_offset[3], 8, 35,
  216. vlc_tab_fft_tone_offset_3_huffbits, 1, 1,
  217. vlc_tab_fft_tone_offset_3_huffcodes, 2, 2,
  218. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  219. vlc_tab_fft_tone_offset[4].table =
  220. &qdm2_table[qdm2_vlc_offs[16]];
  221. vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] -
  222. qdm2_vlc_offs[16];
  223. init_vlc(&vlc_tab_fft_tone_offset[4], 8, 38,
  224. vlc_tab_fft_tone_offset_4_huffbits, 1, 1,
  225. vlc_tab_fft_tone_offset_4_huffcodes, 2, 2,
  226. INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
  227. }
  228. #endif /* CONFIG_HARDCODED_TABLES */
  229. #endif /* AVCODEC_QDM2_TABLEGEN_H */