lookups.pl 4.0 KB

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