lookups.pl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/perl
  2. print <<'EOD';
  3. /********************************************************************
  4. * *
  5. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  6. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  7. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  8. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  9. * *
  10. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
  11. * by the Xiph.Org Foundation https://xiph.org/ *
  12. * *
  13. ********************************************************************
  14. function: lookup data; generated by lookups.pl; edit there
  15. ********************************************************************/
  16. #ifndef _V_LOOKUP_DATA_H_
  17. #ifdef FLOAT_LOOKUP
  18. EOD
  19. $cos_sz=128;
  20. $invsq_sz=32;
  21. $invsq2exp_min=-32;
  22. $invsq2exp_max=32;
  23. $fromdB_sz=35;
  24. $fromdB_shift=5;
  25. $fromdB2_shift=3;
  26. $invsq_i_shift=10;
  27. $cos_i_shift=9;
  28. $delta_shift=6;
  29. print "#define COS_LOOKUP_SZ $cos_sz\n";
  30. print "static float COS_LOOKUP[COS_LOOKUP_SZ+1]={\n";
  31. for($i=0;$i<=$cos_sz;){
  32. print "\t";
  33. for($j=0;$j<4 && $i<=$cos_sz;$j++){
  34. printf "%+.13f,", cos(3.14159265358979323846*($i++)/$cos_sz) ;
  35. }
  36. print "\n";
  37. }
  38. print "};\n\n";
  39. print "#define INVSQ_LOOKUP_SZ $invsq_sz\n";
  40. print "static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={\n";
  41. for($i=0;$i<=$invsq_sz;){
  42. print "\t";
  43. for($j=0;$j<4 && $i<=$invsq_sz;$j++){
  44. my$indexmap=$i++/$invsq_sz*.5+.5;
  45. printf "%.12f,", 1./sqrt($indexmap);
  46. }
  47. print "\n";
  48. }
  49. print "};\n\n";
  50. print "#define INVSQ2EXP_LOOKUP_MIN $invsq2exp_min\n";
  51. print "#define INVSQ2EXP_LOOKUP_MAX $invsq2exp_max\n";
  52. print "static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\\\n".
  53. " INVSQ2EXP_LOOKUP_MIN+1]={\n";
  54. for($i=$invsq2exp_min;$i<=$invsq2exp_max;){
  55. print "\t";
  56. for($j=0;$j<4 && $i<=$invsq2exp_max;$j++){
  57. printf "%15.10g,", 2**($i++*-.5);
  58. }
  59. print "\n";
  60. }
  61. print "};\n\n#endif\n\n";
  62. # 0 to -140 dB
  63. $fromdB2_sz=1<<$fromdB_shift;
  64. $fromdB_gran=1<<($fromdB_shift-$fromdB2_shift);
  65. print "#define FROMdB_LOOKUP_SZ $fromdB_sz\n";
  66. print "#define FROMdB2_LOOKUP_SZ $fromdB2_sz\n";
  67. print "#define FROMdB_SHIFT $fromdB_shift\n";
  68. print "#define FROMdB2_SHIFT $fromdB2_shift\n";
  69. print "#define FROMdB2_MASK ".((1<<$fromdB_shift)-1)."\n";
  70. print "static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={\n";
  71. for($i=0;$i<$fromdB_sz;){
  72. print "\t";
  73. for($j=0;$j<4 && $i<$fromdB_sz;$j++){
  74. printf "%15.10g,", 10**(.05*(-$fromdB_gran*$i++));
  75. }
  76. print "\n";
  77. }
  78. print "};\n\n";
  79. print "static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={\n";
  80. for($i=0;$i<$fromdB2_sz;){
  81. print "\t";
  82. for($j=0;$j<4 && $i<$fromdB_sz;$j++){
  83. printf "%15.10g,", 10**(.05*(-$fromdB_gran/$fromdB2_sz*(.5+$i++)));
  84. }
  85. print "\n";
  86. }
  87. print "};\n\n#ifdef INT_LOOKUP\n\n";
  88. $iisz=0x10000>>$invsq_i_shift;
  89. print "#define INVSQ_LOOKUP_I_SHIFT $invsq_i_shift\n";
  90. print "#define INVSQ_LOOKUP_I_MASK ".(0x0ffff>>(16-$invsq_i_shift))."\n";
  91. print "static long INVSQ_LOOKUP_I[$iisz+1]={\n";
  92. for($i=0;$i<=$iisz;){
  93. print "\t";
  94. for($j=0;$j<4 && $i<=$iisz;$j++){
  95. my$indexmap=$i++/$iisz*.5+.5;
  96. printf "%8d,", int(1./sqrt($indexmap)*65536.+.5);
  97. }
  98. print "\n";
  99. }
  100. print "};\n\n";
  101. $cisz=0x10000>>$cos_i_shift;
  102. print "#define COS_LOOKUP_I_SHIFT $cos_i_shift\n";
  103. print "#define COS_LOOKUP_I_MASK ".(0x0ffff>>(16-$cos_i_shift))."\n";
  104. print "#define COS_LOOKUP_I_SZ $cisz\n";
  105. print "static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={\n";
  106. for($i=0;$i<=$cisz;){
  107. print "\t";
  108. for($j=0;$j<4 && $i<=$cisz;$j++){
  109. printf "%8d,", int(cos(3.14159265358979323846*($i++)/$cos_sz)*16384.+.5) ;
  110. }
  111. print "\n";
  112. }
  113. print "};\n\n";
  114. print "#endif\n\n#endif\n";