#!/usr/bin/perl # # libnogg: a decoder library for Ogg Vorbis streams # Copyright (c) 2014-2024 Andrew Church # # This software may be copied and redistributed under certain conditions; # see the file "COPYING" in the source code distribution for details. # NO WARRANTY is provided with this software. # # # This script generates the lookup tables used when the library is built # with the USE_LOOKUP_TABLES option. The output of the script should be # written to the file "src/decode/tables.c". # use strict; use warnings; use constant PI => 3.141592653589793238; sub bit_reverse($) { my ($n) = @_; $n = (($n & 0xAAAAAAAA) >> 1) | (($n & 0x55555555) << 1); $n = (($n & 0xCCCCCCCC) >> 2) | (($n & 0x33333333) << 2); $n = (($n & 0xF0F0F0F0) >> 4) | (($n & 0x0F0F0F0F) << 4); $n = (($n & 0xFF00FF00) >> 8) | (($n & 0x00FF00FF) << 8); return ($n >> 16) | ($n << 16); } print <> (32-$bits+3)) << 2, $i%8 == 7 ? "\n" : ""; } print "};\n"; } printf "const uint16_t * const table_bitrev[8] = {%s};\n", join(", ", map {"table_bitrev_$_"} (6..13)); # Generate the window weight lookup tables. print "\n"; foreach my $bits (6..13) { my $blocksize = 1 << $bits; print "ALIGN(32) static const float table_weights_${bits}[] = {\n"; for (my $i = 0; $i < $blocksize/2; $i++) { my $x = sin(($i+0.5)*PI/$blocksize); printf " %.8e,%s", sin(0.5*PI*($x*$x)), $i%4 == 3 ? "\n" : ""; } print "};\n"; } printf "const float * const table_weights[8] = {%s};\n", join(", ", map {"table_weights_$_"} (6..13)); print "\n#endif // USE_LOOKUP_TABLES\n";