#!/usr/bin/perl # # Programmer: Craig Stuart Sapp # Creation Date: Sat Jan 7 03:29:41 PST 2006 # Last Modified: Sat Jan 7 03:29:41 PST 2006 # Filename: runonsettest # Syntax: perl 5 # # Description: # use strict; if (@ARGV <= 0) { print "runonsettest 500 200 pianonote.wav output.dat\n"; exit(1); } my $attacktime = $ARGV[0]; # note attack onset start point (all in ms) my $range = $ARGV[1]; # distance from the note onset to play impulse my $soundfile = $ARGV[2]; # soundfile to process for test my $resultsfile = $ARGV[3]; # file to store responses and answers if (!open(RFILE, ">>$resultsfile")) { print "Error: cannot write/append to file $resultsfile\n"; } my $date = `date`; chomp $date; print RFILE "\n"; print RFILE "!!date: $date\n"; print RFILE "!!center: $attacktime\n"; print RFILE "!!range: $range\n"; print RFILE "!!sound: $soundfile\n"; print RFILE "\n"; my $stimulusname = "trial.wav"; my $clickname = "trial.click"; my $response; my $direction; my $counter = 0; my $clicktime; my $fval; my $delta; print "Type 'quit' to end test.\n"; print "Type 'a' if click sounds after note attack.\n"; print "Type 'b' if click sounds before note attack.\n"; while ($response !~ /q/i) { $direction = chooseDirection(); $delta = chooseMagnitude($range); $clicktime = $attacktime + $direction * $delta; createStimulus($direction, $clicktime, $soundfile, $clickname, $stimulusname); print "Trial $counter:\n"; `./sounder.exe $stimulusname`; `rm -f $stimulusname`; `rm -f $clickname`; # while ($response !~ /^\s*$/) { print "Answer: "; $response = ; print "You said: $response\n"; # } $counter++; $fval = $direction * $delta; if ($response =~ /^a$/i) { if ($direction == +1) { print RFILE "$fval\tA\tY\n"; } else { print RFILE "$fval\tA\tN\n"; } } elsif ($response =~ /^b$/i) { if ($direction == +1) { print RFILE "$fval\tB\tN\n"; } else { print RFILE "$fval\tB\tY\n"; } } else { print "Invalid response\n"; } } exit(0); ########################################################################## ############################## ## ## chooseMagnitude -- ## sub chooseMagnitude { my ($range) = @_; my $top = int($range / 5); my $random = int(rand($top+1)); return $random * 5; } ############################## ## ## chooseDirection -- ## sub chooseDirection { if (rand() > 0.5) { return +1; } else { return -1; } } ############################## ## ## createStimulus -- ## sub createStimulus { my ($direction, $clicktime, $soundfile, $clickname, $stimulusname) = @_; open (CFILE, ">$clickname") || die; print CFILE "$clicktime\n"; close CFILE; `./clicktrack.exe -c 0.65 $soundfile $clickname $stimulusname`; }