ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Audio.pm
Revision: 1.2
Committed: Wed Jan 18 15:31:51 2012 UTC (12 years, 5 months ago) by root
Branch: MAIN
Changes since 1.1: +49 -2 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 # user selected config
73 return if _probe;
74
75 # default sdl config
76 delete $ENV{SDL_AUDIODRIVER};
77 $::CFG->{audio_driver} = "";
78 return if _probe;
79
80 $::CFG->{audio_driver} = "pulse";
81 return if _probe;
82
83 $::CFG->{audio_driver} = "alsa";
84 return if _probe;
85
86 $::CFG->{audio_driver} = "dsp";
87 return if _probe;
88
89 $::CFG->{audio_driver} = "none";
90 }
91
92 1;
93
94 =back
95
96 =head1 AUTHOR
97
98 Marc Lehmann <schmorp@schmorp.de>
99 http://home.schmorp.de/
100
101 =cut
102