joe.fool has asked for the wisdom of the Perl Monks concerning the following question:

I want to use a module for playing short uncompressed and unencoded WAV-Files (PCM).

I found already Win32::Sound, which is doing a quite well job if you live under one of the similar named platforms.

Looking around at CPAN offered me some other modules for making noises on a different OS. But somehow I could not quickly decide which would be the best if you target *nix.

I look for a module that allows easy handling of the sound-files and is rather portable or at least does its job under linux.(And is possibly native perl?)

Could anyone of you wise monks give an advice?

joe.fool

Replies are listed 'Best First'.
Re: Need advice on Sound-Modules
by zentara (Cardinal) on May 05, 2004 at 20:20 UTC
    SDL_Perl is a good multi-purpose multimedia module, with alot of support. It plays wavs, and more. Here is the loopwav test program from the distro. ( I really like the test wav..."I met a woman one night, wearing black and blue tears...her clothes were tight") dood doo do do do da do da :-)
    #!/usr/bin/env perl use SDL; die "Could not initialize SDL: ", SDL::GetError() if ( 0 > SDL::Init(SDL_INIT_AUDIO())); $ARGV[0] ||= 'data/sample.wav'; die "usage: $0 [wavefile]\n" if ( in $ARGV[0], qw/ -h --help -? /); my ($wav_spec,$wav_buffer,$wav_len,$wav_pos) = (0,0,0,0); my $done = 0; $fillerup = sub { my ($data,$len) = @_; $wav_ptr = $wav_buffer + $wav_pos; $wav_remainder = $wav_len - $wav_pos; while ( $wav_remainder <= $len ) { SDL::MixAudio($data,$wav_ptr,$wav_remainder,SDL_MIX_MA +XVOLUME); $data += $wav_remainder; $len -= $wav_remainder; $wav_ptr = $wav_buffer; $wav_remainder = $wav_len; $wav_pos = 0; } SDL::MixAudio($data,$wav_ptr,$len,SDL_MIX_MAXVOLUME); $wav_pos += $len; }; $poked = sub { $done = 1; }; $SIG{HUP} = $poked; $SIG{INT} = $poked; $SIG{QUIT} = $poked; $SIG{TERM} = $poked; $spec = SDL::NewAudioSpec(44100,AUDIO_S16,2,4096); $wave = SDL::LoadWAV($ARGV[0],$spec); ($wav_spec,$wav_buffer,$wav_len) = @$wave; die "Could not load wav file $ARGV[0], ", SDL::GetError(), "\n" unless + ( $wav_len ); die "Could not open audio ", SDL::GetError() if (0 > SDL::OpenAudio($wav_spec,$fillerup)); SDL::PauseAudio(0); print "Using audio driver: ", SDL::AudioDriverName(), "\n"; while (! $done && ( SDL::GetAudioStatus() == SDL_AUDIO_PLAYING())) { SDL::Delay(1000); }

    I'm not really a human, but I play one on earth. flash japh
      Thanks. I will give it a try and report back. =8]

      joe.fool