dbd7f71708c4b6affcf8bfac3386315710632ea5
[platform/upstream/libvorbis.git] / lib / lookups.pl
1 #!/usr/bin/perl
2 print <<'EOD';
3 /********************************************************************
4  *                                                                  *
5  * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
6  * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
7  * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
8  * PLEASE READ THESE TERMS DISTRIBUTING.                            *
9  *                                                                  *
10  * THE OggSQUISH 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
16   function: lookup data; generated by lookups.pl; edit there
17   last mod: $Id: lookups.pl,v 1.2 2000/10/12 03:12:53 xiphmont Exp $
18
19  ********************************************************************/
20
21 #ifndef _V_LOOKUP_DATA_H_
22
23 #ifdef FLOAT_LOOKUP
24 EOD
25
26 $cos_sz=128;
27 $invsq_sz=32;
28 $invsq2exp_min=-32;
29 $invsq2exp_max=32;
30
31 $fromdB_sz=35;
32 $fromdB_shift=5;
33 $fromdB2_shift=3;
34
35 $invsq_i_shift=10;
36 $cos_i_shift=9;
37 $delta_shift=6;
38
39 print "#define COS_LOOKUP_SZ $cos_sz\n";
40 print "static float COS_LOOKUP[COS_LOOKUP_SZ+1]={\n";
41
42 for($i=0;$i<=$cos_sz;){
43     print "\t";
44     for($j=0;$j<4 && $i<=$cos_sz;$j++){
45         printf "%+.13f,", cos(3.14159265358979323846*($i++)/$cos_sz) ;
46     }
47     print "\n";
48 }
49 print "};\n\n";
50
51 print "#define INVSQ_LOOKUP_SZ $invsq_sz\n";
52 print "static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={\n";
53
54 for($i=0;$i<=$invsq_sz;){
55     print "\t";
56     for($j=0;$j<4 && $i<=$invsq_sz;$j++){
57         my$indexmap=$i++/$invsq_sz*.5+.5;
58         printf "%.12f,", 1./sqrt($indexmap);
59     }
60     print "\n";
61 }
62 print "};\n\n";
63
64 print "#define INVSQ2EXP_LOOKUP_MIN $invsq2exp_min\n";
65 print "#define INVSQ2EXP_LOOKUP_MAX $invsq2exp_max\n";
66 print "static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\\\n".
67       "                              INVSQ2EXP_LOOKUP_MIN+1]={\n";
68
69 for($i=$invsq2exp_min;$i<=$invsq2exp_max;){
70     print "\t";
71     for($j=0;$j<4 && $i<=$invsq2exp_max;$j++){
72         printf "%15.10g,", 2**($i++*-.5);
73     }
74     print "\n";
75 }
76 print "};\n\n#endif\n\n";
77
78
79 # 0 to -140 dB
80 $fromdB2_sz=1<<$fromdB_shift;
81 $fromdB_gran=1<<($fromdB_shift-$fromdB2_shift);
82 print "#define FROMdB_LOOKUP_SZ $fromdB_sz\n";
83 print "#define FROMdB2_LOOKUP_SZ $fromdB2_sz\n";
84 print "#define FROMdB_SHIFT $fromdB_shift\n";
85 print "#define FROMdB2_SHIFT $fromdB2_shift\n";
86 print "#define FROMdB2_MASK ".((1<<$fromdB_shift)-1)."\n";
87
88 print "static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={\n";
89
90 for($i=0;$i<$fromdB_sz;){
91     print "\t";
92     for($j=0;$j<4 && $i<$fromdB_sz;$j++){
93         printf "%15.10g,", 10**(.05*(-$fromdB_gran*$i++));
94     }
95     print "\n";
96 }
97 print "};\n\n";
98
99 print "static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={\n";
100
101 for($i=0;$i<$fromdB2_sz;){
102     print "\t";
103     for($j=0;$j<4 && $i<$fromdB_sz;$j++){
104         printf "%15.10g,", 10**(.05*(-$fromdB_gran/$fromdB2_sz*(.5+$i++)));
105     }
106     print "\n";
107 }
108 print "};\n\n#ifdef INT_LOOKUP\n\n";
109
110
111 $iisz=0x10000>>$invsq_i_shift;
112 print "#define INVSQ_LOOKUP_I_SHIFT $invsq_i_shift\n";
113 print "#define INVSQ_LOOKUP_I_MASK ".(0x0ffff>>(16-$invsq_i_shift))."\n";
114 print "static long INVSQ_LOOKUP_I[$iisz+1]={\n";
115 for($i=0;$i<=$iisz;){
116     print "\t";
117     for($j=0;$j<4 && $i<=$iisz;$j++){
118         my$indexmap=$i++/$iisz*.5+.5;
119         printf "%8d,", int(1./sqrt($indexmap)*65536.+.5);
120     }
121     print "\n";
122 }
123 print "};\n\n";
124
125 $cisz=0x10000>>$cos_i_shift;
126 print "#define COS_LOOKUP_I_SHIFT $cos_i_shift\n";
127 print "#define COS_LOOKUP_I_MASK ".(0x0ffff>>(16-$cos_i_shift))."\n";
128 print "#define COS_LOOKUP_I_SZ $cisz\n";
129 print "static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={\n";
130
131 for($i=0;$i<=$cisz;){
132     print "\t";
133     for($j=0;$j<4 && $i<=$cisz;$j++){
134         printf "%8d,", int(cos(3.14159265358979323846*($i++)/$cos_sz)*16384.+.5) ;
135     }
136     print "\n";
137 }
138 print "};\n\n";
139
140
141 print "#endif\n\n#endif\n";
142
143