ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/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

# User Rev Content
1 root 1.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 root 1.3 sub init() {
23 root 1.1 unless ($::SDL_MIXER) {
24     if (length $::CFG->{audio_driver}) {
25     local $ENV{SDL_AUDIODRIVER} = $::CFG->{audio_driver};
26 root 1.2 DC::SDL_InitSubSystem DC::SDL_INIT_AUDIO
27 root 1.1 and die "SDL::Init failed!\n";
28     } else {
29 root 1.2 DC::SDL_InitSubSystem DC::SDL_INIT_AUDIO
30 root 1.1 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 root 1.2 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 root 1.3 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 root 1.2 }
80    
81 root 1.1 1;
82    
83     =back
84    
85     =head1 AUTHOR
86    
87     Marc Lehmann <schmorp@schmorp.de>
88     http://home.schmorp.de/
89    
90     =cut
91