[Gambas-user] playing sounds: a stopgap measure

Rob sourceforge-raindog2 at ...94...
Wed Aug 13 16:38:41 CEST 2003


I haven't encapsulated this into a gambas library yet, but the following perl 
code, when run on a machine with perl-SDL installed (hint: if you have frozen 
bubble installed, and it's working, you have perl-SDL) allows you to load up 
to 8 samples and play them all near-simultaneously over a Gambas shell 
command.  Latency isn't TOO bad, certainly much better than sparking "play" 
for each sample.

Usage:

load 1 /path/to/my/file.wav
play 1
load 2 /path/to/another/file.wav
play 2
play 1
etc....

(perl code follows)

#!/usr/bin/perl
use SDL;
use SDL::Sound;
use SDL::Mixer;
my $mix = new SDL::Mixer;
my @sound;

while (my $cmd = <>) {
    if ($cmd =~ /^load\s+(\d)\s+(.+)/i) {
	my $slot = $1;
	my $file = $2;
	$sound[$slot] = new SDL::Sound($file) or die $@;
	print STDERR "loaded $file into $slot\n";
    } elsif ($cmd =~ /^play\s+(\d)/) {
	my $slot = $1;
	$mix->play_channel($slot, $sound[$slot], 0);
    }
}





More information about the User mailing list