Re: Correction:Win32::Sound::WaveOut(WAVFILE)
by $Bill Luebkert other posts by this author
Jan 31 2003 7:40AM messages near this date
Re: Correction:Win32::Sound::WaveOut(WAVFILE)
|
Win32::Sound::WaveOut(WAVFILE)
Geert Storme wrote:
> Has anyone been able to open a WAVFILE and play it with the
> Win32::Sound::WaveOut?
>
> Documentation of this:
> http://search.cpan.org/author/ACALPINI/Win32-Sound-0.45/Sound.pm
> (also available here at ASPN)
>
> ====
> Suppose tada.wav is IN my current dir.
>
> $w = new Win32::Sound::WaveOut( "tada.wav") // $w should now be a WaveOut
> object with the tada sound, I guess...
> $w->Reset(); // Just make sure I am at the begin position
> $w->Play(); // Should play, but nothing...
> ====
>
> What I want to create is a number of sounds stored in memory, so I can
> easily replay them without having to read the wav from disk every time.
This works for me, but I made some changes to Win32::Sound:
my $WAV = new Win32::Sound::WaveOut($infile) or die "WaveOut: $!";
$WAV-> Play() or die "Play: $!";
1 until $WAV-> Status();
undef $WAV;
Here are the changes I made to version 0.47:
package Win32::Sound::WaveOut;
sub new {
my($class, $one, $two, $three) = @_;
my $self = {};
bless($self, $class);
# if($one !~ /^\d+$/ # $Bill
# and not defined($two) # $Bill
# and not defined($three)) { # $Bill
# Looks like a file
# $self-> Open($one);
if (($one and $one =~ /\D/) and not $two and not $three) { # $Bill
$self-> Open(0, $one); # $Bill
} else {
# Default format if not given
$self-> {samplerate} = ($one or 44100);
$self-> {bits} = ($two or 16);
$self-> {channels} = ($three or 2);
$self-> OpenDevice();
}
return $self;
}
sub Volume {
my(@in) = @_;
# Allows '0%'..'100%'
# $in[0] =~ s{ ([\d\.]+)%$ }{ int($1*255/100) }ex if defined $in[0]; #$Bill
# $in[1] =~ s{ ([\d\.]+)%$ }{ int($1*255/100) }ex if defined $in[1]; #$Bill
$in[0] =~ s{ ([\d\.]+)%$ }{ int((255/100)*$1) }ex if defined $in[0]; #$Bill
$in[1] =~ s{ ([\d\.]+)%$ }{ int((255/100)*$1) }ex if defined $in[1]; #$Bill
_Volume(@in);
}
--
,-/- __ _ _ $Bill Luebkert ICQ=162126130
(_/ / ) // // DBE Collectibles Mailto:dbe@[...].com
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Geert Storme
$Bill Luebkert
$Bill Luebkert
|