new alarmclock toys
#! /usr/bin/perl -w
# $Id: volramp.pl,v 1.1 2004/07/22 23:29:40 mca1001 Exp $
use strict;
use Time::HiRes qw( gettimeofday tv_interval usleep );
$ENV{PATH} = "/bin:/usr/bin";
my ($low, $high, $period) = @ARGV;
die "Syntax: $0 <lowvol> <highvol> <ramp_period_sec>"
unless @ARGV == 3 && $low < $high && $period > 1;
my $start = [ gettimeofday ];
for (my $vol = $low; $vol <= $high; $vol++) {
my $sec_offset = $period / ($high - $low) * ($vol - $low); # desired frac sec since $start
my $until = [ @$start ];
$until->[0] += int( $sec_offset );
$until->[1] += 1E6 * ( $sec_offset - int($sec_offset) );
$until->[0] += int( $until->[1] / 1E6 );
$until->[1] -= int( $until->[1] / 1E6 ) * 1E6;
while (1) {
my $now = [gettimeofday];
my $sleepfor = eval { tv_interval($now, $until) };
$sleepfor = - tv_interval($until, $now) if $@;
last if $sleepfor <= 0;
usleep($sleepfor * 1E6);
}
system("aumix", "-w", $vol);
# print "Time now @{[ gettimeofday ]} : $vol\n";
}
|
Repository owner Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |