#!/usr/bin/perl -w # # SOUND SUPPORT ROUTINES # # These routines support playing sound files. # package ortho_sound; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(sound_init sound_control sound_idle sound_play sound_queued); use POSIX; use strict; # sound variables my $SOUND_IDLE = 0; my $SOUND_ACTIVE = 1; my $sound_state = $SOUND_IDLE; my $current_sound = ""; my $desired_sound = ""; sub sound_init() { # print "sound_init, sound_state = $sound_state\n"; $SIG{CHLD} = \&ortho_sound::sound_reaper; $desired_sound = "sounds/ortho_online.wav"; sound_control(); # force playing of initial sound } sub sound_idle() { return $sound_state == $SOUND_IDLE; } sub sound_play($) { $desired_sound = shift; } sub sound_queued() { return $desired_sound; } sub sound_reaper() { my $child; # print "sound_reaper\n"; while (($child = waitpid(-1, &WNOHANG)) > 0) { # just clean them all up }; $SIG{CHLD} = \&ortho_sound::sound_reaper; # print "after waitpid\n"; $sound_state = $SOUND_IDLE; # $desired_sound = "carma/diesel.wav"; sound_control(); # print "after sound_control\n"; } sub sound_control() { # return; if ($sound_state == $SOUND_IDLE and length($desired_sound) > 0) { print "sound_control: playing $desired_sound\n"; $sound_state = $SOUND_ACTIVE; $current_sound = $desired_sound; $desired_sound = ""; my $pid; if ($pid = fork) { # parent: just continue on } else { # child: play the sound exec("/usr/local/bin/wavplay", $current_sound); }; } else { # print "sound_control: no sound to play\n"; }; } return 1;