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