I am trying to create a simple terminal music application, lets call it a piano. The application reads keys from the key board, and outputs a sample to a file handle (pointing to a /dev/audio; which doesn't exist unless piped through padsp...but that's a another story). The application works...sort of. It reads the keys each time one is pressed, great. But the outputs occur every second key that is read... unless I call the output subroutine twice in each loop. If called only once I get no notes played for the first, but the second key pressed leads to playing of the notes of both the keys pressed). I am sorry if I haven't made this clear. Can someone explain what is happening, please? This is loop concerned in Attempt 2
ReadMode 'cbreak';
while(1){
sleep 1/$refreshRate;
my $key = ReadKey(-1) or next;;
last if ( ord($key)==27); # escape key exits
playNote( ord($key)%96); # have to call play note twice
playNote( ord($key)%96);
}