Audio::Audiere - use the Audiere sound library in Perl
use Audio::Audiere qw/AUDIO_STREAM AUDIO_BUFFER/; use strict; use warnings; my $audiere = Audio::Audiere->new(); if ($audiere->error()) { die ("Cannot get audio device: ". print $audiere->error()); } # now we have the driver, add some sound streams # stream the sound from the disk my $stream = $audiere->addStream( 'media/sample.ogg', AUDIO_STREAM); # always check for errors: if ($stream->error()) { print "Cannot load sound: ", $stream->error(),"\n"; } # load sound into memory (if possible), this is also the default my $sound = $audiere->addStream( 'media/effect.wav', AUDIO_BUFFER); # always check for errors: if ($sound->error()) { print "Cannot load sound: ", $sound->error(),"\n"; } $stream->setVolume(0.5); # 50% $stream->setRepeat(1); # loooop if ($stream->isSeekable()) { $stream->setPosition(100); # skip some bit } $stream->play(); # start playing $sound->play(); # start playing # free sound device is not neccessary, will be done automatically
Exports nothing on default. Can export AUDIO_BUFFER and AUDIO_STREAM, as well as the following constants for file formats:
AUDIO_BUFFER
AUDIO_STREAM
FF_AUTODETECT FF_WAV FF_OGG FF_FLAC FF_MP3 FF_MOD
Also, the following sample source format constants can be exported:
SF_U8 SF_S16
This package provides you with an interface to the audio library Audiere.
my $audiere = Audio::Audiere->new( $devicename, $parameters );
Creates a new object that holds the Audiere driver to the optional $devicename and the optional C$parameters>.
$devicename
The latter is a comma-separated list like buffer=100,rate=44100.
buffer=100,rate=44100
When $audiere goes out of scope or is set to undef, the device will be automatically released.
$audiere
In case you wonder how you can play multiple sounds at once with only once device: these are handled as separate streams, and once you have the device, you can add (almost infinitely) many of them via addStream (or any of the other add...() methods.
add...()
In theory you can open more than one device, however, in praxis usually only one of them is connected to the sound output, so this does not make much sense.
print $audiere->getVersion();
Returns the version of Audiere you are using as string.
print $audiere->getName();
Returns the name of the audio device, like 'oss' or 'directsound'.
$stream = $audiere->addStream( $file, $stream_flag )
Create a new sound stream object from $file, and return it.
$file
See "METHODS ON STREAMS" on what methods you can use to manipulate the stream object. Most popular will be play(), of course :)
play()
You should always check for errors before using the stream object:
if ($stream->error()) { print "Cannot load sound: ", $stream->error(),"\n"; }
$audiere->addTone( $frequenzy );
Create a stream object that produces a tone at the given $frequenzy.
$frequenzy
See also addStream and Audio::Audiere::Stream.
$audiere->addSquareWave( $frequenzy );
Create a stream object that produces a swaure wave at the given $frequenzy.
$audiere->addWhiteNoise( );
Create a stream object that produces white noise.
$audiere->addPinkNoise( );
Create a stream object that produces pink noise, which is noise with an equal power distribution among octaves (logarithmic), not frequencies.
$audiere->dropStream($stream);
This will stop the sound playing from this stream and release it's memory. You can also do it like this or just have $stream go out of scope:
$stream
$stream = undef;
$second_stream = $audiere->dupeStream($stream); $second_stream = $stream->copy();
Create a copy of a stream. The streams will share the memory for the sound data, but have separate volumes, positions, pan etc.
my $new_vol = $audiere->setMasterVolume(0.1); # = 0.1 (10%)
Sets a new master volume for all (non-3D) streams. The actual volume of a stream will be $master * $local e.g. a stream with a volume of 0.5 and a master volume of also 0.5 would result in an actual volume of 0.25.
$master * $local
my $vol = $audiere->getMasterVolume();
Return the master volume for (non-3D) streams. See setMasterVolume and set3DMasterVolume.
my $new_vol = $audiere->set3DMasterVolume(0.1); # = 0.1 (10%)
Sets a new master volume for all 3D streams. The actual volume of a stream will be $master * $local e.g. a stream with a volume of 0.5 and a master volume of also 0.5 would result in an actual volume of 0.25.
Return the master volume for all 3D streams. See set3DMasterVolume and setMasterVolume.
See also Audio::Audiere::Stream and Audio::Audiere::Stream::3D for a list of methods you can call on 2D and 3D sound streams.
(c) 2004 Tels <http://bloodgate.com/>
http://audiere.sf.net/
To install Audio::Audiere, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Audio::Audiere
CPAN shell
perl -MCPAN -e shell install Audio::Audiere
For more information on module installation, please visit the detailed CPAN module installation guide.