/usr/lib/perl5/SDLx/Sound.pm is in libsdl-perl 2.540-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | package SDLx::Sound;
use strict;
use warnings;
use Carp;
use SDL;
#use SDL::Audio;
#use SDL::AudioSpec;
use SDL::Mixer;
use SDL::Mixer::Music;
#use SDL::Mixer::Channels;
#use SDL::Mixer::Samples;
#use SDL::Mixer::MixChunk;
# SDL::Mixer must be inited only one time
my $audioInited = undef;
sub new {
my $class = shift;
my $self = {@_};
bless ($self, $class);
_initAudio() unless $audioInited;
$self->{supported} = _initMixer();
return $self;
}
sub _initAudio {
SDL::Mixer::open_audio( 44100, AUDIO_S16SYS, 2, 4096 );
my ($status, $freq, $format, $channels) = @{ SDL::Mixer::query_spec() };
$audioInited = 1 if $status == 1;
return ($status, $freq, $format, $channels); #TODO: Save this information in $self;
}
sub _initMixer {
my $init_flags = SDL::Mixer::init( MIX_INIT_MP3 | MIX_INIT_MOD | MIX_INIT_FLAC | MIX_INIT_OGG );
my %init = ();
# Short circuit if we have and older version of SDL_Mixer
return \%init unless $init_flags;
$init{ mp3 } = 1 if $init_flags & MIX_INIT_MP3;
$init{ mod } = 1 if $init_flags & MIX_INIT_MOD;
$init{ flac } = 1 if $init_flags & MIX_INIT_FLAC;
$init{ ogg } = 1 if $init_flags & MIX_INIT_OGG;
return \%init
}
sub load {
my $self = shift;
$self->{files} = {@_};
}
sub unload {
my $self = shift;
$self->{files} = {};
}
sub play {
my $self = shift;
$self->{files} = {@_} if $#_ > 0 && @_;
my $play = 1;
if (-e $_[0]) {
my $music = SDL::Mixer::Music::load_MUS($_[0])
or Carp::croak 'Sound file not found: ' . SDL::get_error();
SDL::Mixer::Music::volume_music(85);
if (SDL::Mixer::Music::play_music($music, -1)<0) {
print("Can't play!\n". SDL::get_error()."\n");
$play = 0;
}
} else {
carp("No newline ".$self->{files}."\n".$_[0]."\n");
$play = 0;
}
return $play;
}
sub loud {
}
sub pause {
my $self = shift;
SDL::Mixer::Music::pause_music();
}
sub resume {
my $self = shift;
SDL::Mixer::Music::resume_music();
}
sub stop {
my $self = shift;
SDL::Mixer::Music::halt_music();
#SDL::Mixer::quit();
}
sub fade {
}
1; # End of SDLx::Sound
|