#!/usr/bin/perl $pid=0; $count=0; $BSD_STYLE=1; $choice=-1; $correct=0; print "\nPress 'a' to play file A, 'b' to play file B and 'x' to play a\n". "random choice between A and B. Use 'A' to vote for x==A, 'B' to vote\n". "for x==B. 'q' to quit.\n\n"; if ($BSD_STYLE) { system "stty cbreak /dev/tty 2>&1"; } else { system "stty", '-icanon', 'eol', "\001"; } while(1){ $key = getc(STDIN); if($key eq "a"){ print " Playing file A...\n"; spawnit($ARGV[0]); }elsif($key eq "b"){ print " Playing file B...\n"; spawnit($ARGV[1]); }elsif($key eq "q"){ killit(); if ($BSD_STYLE) { system "stty -cbreak /dev/tty 2>&1"; } else { system "stty", 'icanon', 'eol', '^@'; # ASCII null } print " QUIT\n\n"; exit(0); }elsif($key eq "x"){ if(defined($choice)){ print " ********Choosing/Playing an X...\n"; $val=rand; if($val<.5){ $x="a"; }else{ $x="b"; } undef $choice; }else{ print " Playing the X again...\n"; } if($x eq "a"){ spawnit($ARGV[0]); }else{ spawnit($ARGV[1]); } }elsif($key eq "A"){ if(!defined($x)){ print " No x has been played yet.\n"; }else{ if($x eq "a"){ $correct++; } undef $x; $count++; $choice="A"; killit(); print " Vote for $choice logged... currently $correct/$count\n"; } }elsif($key eq "B"){ if(!defined($x)){ print " No x has been played yet.\n"; }else{ if($x eq "b"){ $correct++; } undef $x; $count++; $choice="B"; killit(); print " Vote for $choice logged... currently $correct/$count\n"; } }else{ print "Unkown key '$key'.\n"; } if($count==16){ print "All done! ABX results: $correct/$count\n\n"; exit(0); } } sub killit{ if($pid){ kill 9, $pid; waitpid $pid,0; } } sub spawnit{ my($file)=@_; killit(); $pid=fork(); if($pid==0){ exec "sox $file -t ossdsp /dev/dsp"; } }