ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/Deliantra-Client/DC/Audio.pm
Revision: 1.3
Committed: Wed May 1 20:38:50 2013 UTC (11 years, 2 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +8 -19 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 DC::Audio - audio support for deliantra client
4
5 =head1 SYNOPSIS
6
7 use DC::Audio;
8
9 =head1 DESCRIPTION
10
11 =over 4
12
13 =cut
14
15 package DC::Audio;
16
17 use common::sense;
18 use DC ();
19
20 our $SDL_MIXER;
21
22 sub init() {
23 unless ($::SDL_MIXER) {
24 if (length $::CFG->{audio_driver}) {
25 local $ENV{SDL_AUDIODRIVER} = $::CFG->{audio_driver};
26 DC::SDL_InitSubSystem DC::SDL_INIT_AUDIO
27 and die "SDL::Init failed!\n";
28 } else {
29 DC::SDL_InitSubSystem DC::SDL_INIT_AUDIO
30 and die "SDL::Init failed!\n";
31 }
32
33 $ENV{MIX_EFFECTSMAXSPEED} = 1;
34 $::SDL_MIXER = !DC::Mix_OpenAudio
35 $::CFG->{audio_hw_frequency},
36 DC::MIX_DEFAULT_FORMAT,
37 $::CFG->{audio_hw_channels},
38 $::CFG->{audio_hw_chunksize};
39
40 DC::Mix_AllocateChannels $::CFG->{audio_mix_channels}
41 if $::SDL_MIXER;
42 }
43 }
44
45 sub _probe {
46 my $pid = fork;
47
48 return 1 unless defined $pid;
49
50 unless ($pid) {
51 eval {
52 DC::SDL_Init DC::SDL_INIT_NOPARACHUTE;
53 init;
54 };
55 DC::_exit $@ ? 1 : 0;
56 }
57
58 waitpid $pid, 0
59 and !$?
60 }
61
62 sub probe {
63 return unless $^O eq "linux";
64
65 # on linux, both alsa and pulse (especially the latter)
66 # are prone to segfaults, while the other interfaces are
67 # simply unreliable.
68
69 # let's check whether the default config and a few others segfault,
70 # then decide
71
72 return if _probe; # user selected config
73 $::CFG->{audio_driver} = "" ; return if _probe; # default sdl config
74 $::CFG->{audio_driver} = "pulse"; return if _probe;
75 $::CFG->{audio_driver} = "alsa" ; return if _probe;
76 $::CFG->{audio_driver} = "esd" ; return if _probe;
77 $::CFG->{audio_driver} = "dsp" ; return if _probe;
78 $::CFG->{audio_driver} = "none" ;
79 }
80
81 1;
82
83 =back
84
85 =head1 AUTHOR
86
87 Marc Lehmann <schmorp@schmorp.de>
88 http://home.schmorp.de/
89
90 =cut
91