annotate src/libvorbis-1.3.3/vq/make_residue_books.pl @ 124:e3d5853d5918

Current stable PortAudio source
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 18 Oct 2016 13:11:05 +0100
parents 98c1576536ae
children
rev   line source
cannam@86 1 #!/usr/bin/perl
cannam@86 2
cannam@86 3 # quick, very dirty little script so that we can put all the
cannam@86 4 # information for building a residue book set (except the original
cannam@86 5 # partitioning) in one spec file.
cannam@86 6
cannam@86 7 #eg:
cannam@86 8
cannam@86 9 # >res0_128_128 interleaved
cannam@86 10 # haux 44c0_s/resaux_0.vqd res0_96_128aux 0,4,2 9
cannam@86 11 # :1 res0_128_128_1.vqd, 4, nonseq cull, 0 +- 1
cannam@86 12 # :2 res0_128_128_2.vqd, 4, nonseq, 0 +- 1(.7) 2
cannam@86 13 # :3 res0_128_128_3.vqd, 4, nonseq, 0 +- 1(.7) 3 5
cannam@86 14 # :4 res0_128_128_4.vqd, 2, nonseq, 0 +- 1(.7) 3 5 8 11
cannam@86 15 # :5 res0_128_128_5.vqd, 1, nonseq, 0 +- 1 3 5 8 11 14 17 20 24 28 31 35 39
cannam@86 16
cannam@86 17
cannam@86 18 die "Could not open $ARGV[0]: $!" unless open (F,$ARGV[0]);
cannam@86 19
cannam@86 20 $goflag=0;
cannam@86 21 while($line=<F>){
cannam@86 22
cannam@86 23 print "#### $line";
cannam@86 24 if($line=~m/^GO/){
cannam@86 25 $goflag=1;
cannam@86 26 next;
cannam@86 27 }
cannam@86 28
cannam@86 29 if($goflag==0){
cannam@86 30 if($line=~m/\S+/ && !($line=~m/^\#/) ){
cannam@86 31 my $command=$line;
cannam@86 32 print ">>> $command";
cannam@86 33 die "Couldn't shell command.\n\tcommand:$command\n"
cannam@86 34 if syst($command);
cannam@86 35 }
cannam@86 36 next;
cannam@86 37 }
cannam@86 38
cannam@86 39 # >res0_128_128
cannam@86 40 if($line=~m/^>(\S+)\s+(\S*)/){
cannam@86 41 # set the output name
cannam@86 42 $globalname=$1;
cannam@86 43 $interleave=$2;
cannam@86 44 next;
cannam@86 45 }
cannam@86 46
cannam@86 47 # haux 44c0_s/resaux_0.vqd res0_96_128aux 0,4,2 9
cannam@86 48 if($line=~m/^h(.*)/){
cannam@86 49 # build a huffman book (no mapping)
cannam@86 50 my($name,$datafile,$bookname,$interval,$range)=split(' ',$1);
cannam@86 51
cannam@86 52 # check the desired subdir to see if the data file exists
cannam@86 53 if(-e $datafile){
cannam@86 54 my $command="cp $datafile $bookname.tmp";
cannam@86 55 print ">>> $command\n";
cannam@86 56 die "Couldn't access partition data file.\n\tcommand:$command\n"
cannam@86 57 if syst($command);
cannam@86 58
cannam@86 59 my $command="huffbuild $bookname.tmp $interval";
cannam@86 60 print ">>> $command\n";
cannam@86 61 die "Couldn't build huffbook.\n\tcommand:$command\n"
cannam@86 62 if syst($command);
cannam@86 63
cannam@86 64 my $command="rm $bookname.tmp";
cannam@86 65 print ">>> $command\n";
cannam@86 66 die "Couldn't remove temporary file.\n\tcommand:$command\n"
cannam@86 67 if syst($command);
cannam@86 68 }else{
cannam@86 69 my $command="huffbuild $bookname.tmp 0-$range";
cannam@86 70 print ">>> $command\n";
cannam@86 71 die "Couldn't build huffbook.\n\tcommand:$command\n"
cannam@86 72 if syst($command);
cannam@86 73
cannam@86 74 }
cannam@86 75 next;
cannam@86 76 }
cannam@86 77
cannam@86 78 # :1 res0_128_128_1.vqd, 4, nonseq, 0 +- 1
cannam@86 79 if($line=~m/^:(.*)/){
cannam@86 80 my($namedata,$dim,$seqp,$vals)=split(',',$1);
cannam@86 81 my($name,$datafile)=split(' ',$namedata);
cannam@86 82 # build value list
cannam@86 83 my$plusminus="+";
cannam@86 84 my$list;
cannam@86 85 my$thlist;
cannam@86 86 my$count=0;
cannam@86 87 foreach my$val (split(' ',$vals)){
cannam@86 88 if($val=~/\-?\+?\d+/){
cannam@86 89 my$th;
cannam@86 90
cannam@86 91 # got an explicit threshhint?
cannam@86 92 if($val=~/([0-9\.]+)\(([^\)]+)/){
cannam@86 93 $val=$1;
cannam@86 94 $th=$2;
cannam@86 95 }
cannam@86 96
cannam@86 97 if($plusminus=~/-/){
cannam@86 98 $list.="-$val ";
cannam@86 99 if(defined($th)){
cannam@86 100 $thlist.="," if(defined($thlist));
cannam@86 101 $thlist.="-$th";
cannam@86 102 }
cannam@86 103 $count++;
cannam@86 104 }
cannam@86 105 if($plusminus=~/\+/){
cannam@86 106 $list.="$val ";
cannam@86 107 if(defined($th)){
cannam@86 108 $thlist.="," if(defined($thlist));
cannam@86 109 $thlist.="$th";
cannam@86 110 }
cannam@86 111 $count++;
cannam@86 112 }
cannam@86 113 }else{
cannam@86 114 $plusminus=$val;
cannam@86 115 }
cannam@86 116 }
cannam@86 117 die "Couldn't open temp file $globalname$name.vql: $!" unless
cannam@86 118 open(G,">$globalname$name.vql");
cannam@86 119 print G "$count $dim 0 ";
cannam@86 120 if($seqp=~/non/){
cannam@86 121 print G "0\n$list\n";
cannam@86 122 }else{
cannam@86 123 print G "1\n$list\n";
cannam@86 124 }
cannam@86 125 close(G);
cannam@86 126
cannam@86 127 my $command="latticebuild $globalname$name.vql > $globalname$name.vqh";
cannam@86 128 print ">>> $command\n";
cannam@86 129 die "Couldn't build latticebook.\n\tcommand:$command\n"
cannam@86 130 if syst($command);
cannam@86 131
cannam@86 132 if(-e $datafile){
cannam@86 133
cannam@86 134 if($interleave=~/non/){
cannam@86 135 $restune="res1tune";
cannam@86 136 }else{
cannam@86 137 $restune="res0tune";
cannam@86 138 }
cannam@86 139
cannam@86 140 if($seqp=~/cull/){
cannam@86 141 my $command="$restune $globalname$name.vqh $datafile 1 > temp$$.vqh";
cannam@86 142 print ">>> $command\n";
cannam@86 143 die "Couldn't tune latticebook.\n\tcommand:$command\n"
cannam@86 144 if syst($command);
cannam@86 145 }else{
cannam@86 146 my $command="$restune $globalname$name.vqh $datafile > temp$$.vqh";
cannam@86 147 print ">>> $command\n";
cannam@86 148 die "Couldn't tune latticebook.\n\tcommand:$command\n"
cannam@86 149 if syst($command);
cannam@86 150 }
cannam@86 151
cannam@86 152 my $command="mv temp$$.vqh $globalname$name.vqh";
cannam@86 153 print ">>> $command\n";
cannam@86 154 die "Couldn't rename latticebook.\n\tcommand:$command\n"
cannam@86 155 if syst($command);
cannam@86 156
cannam@86 157 }else{
cannam@86 158 print "No matching training file; leaving this codebook untrained.\n";
cannam@86 159 }
cannam@86 160
cannam@86 161 my $command="rm $globalname$name.vql";
cannam@86 162 print ">>> $command\n";
cannam@86 163 die "Couldn't remove temp files.\n\tcommand:$command\n"
cannam@86 164 if syst($command);
cannam@86 165
cannam@86 166 next;
cannam@86 167 }
cannam@86 168 }
cannam@86 169
cannam@86 170 $command="rm -f temp$$.vqd";
cannam@86 171 print ">>> $command\n";
cannam@86 172 die "Couldn't remove temp files.\n\tcommand:$command\n"
cannam@86 173 if syst($command);
cannam@86 174
cannam@86 175 sub syst{
cannam@86 176 system(@_)/256;
cannam@86 177 }