Merge lp:~widelands-dev/widelands/cleanup_mixer_init into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 7332
Proposed branch: lp:~widelands-dev/widelands/cleanup_mixer_init
Merge into: lp:widelands
Diff against target: 111 lines (+48/-21)
2 files modified
src/sound/sound_handler.cc (+45/-21)
src/sound/sound_handler.h (+3/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/cleanup_mixer_init
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+245266@code.launchpad.net

Description of the change

Cleanup SoundHandler init code a bit and report an error if Ogg is not available.

To post a comment you must log in.
Revision history for this message
Tino (tino79) wrote :

It does compile on win32.
But i can't test the disabling of sound if libogg is missing, because it seems on my system libogg is statically linked into libvorbis and libvorbisfile.
If i remove both libvorbis dlls widelands does not start at all.

Revision history for this message
SirVer (sirver) wrote :

I take this as an approve and go ahead and merge this.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sound/sound_handler.cc'
2--- src/sound/sound_handler.cc 2014-12-03 07:15:40 +0000
3+++ src/sound/sound_handler.cc 2014-12-20 18:20:27 +0000
4@@ -44,8 +44,17 @@
5 #include "wui/mapview.h"
6 #include "wui/mapviewpixelfunctions.h"
7
8-#define DEFAULT_MUSIC_VOLUME 64
9-#define DEFAULT_FX_VOLUME 128
10+namespace {
11+
12+constexpr int kDefaultMusicVolume = 64;
13+constexpr int kDefaultFxVolume = 128;
14+
15+void report_initalization_error(const char* msg) {
16+ log("WARNING: Failed to initialize sound system: %s\n", msg);
17+ return;
18+}
19+
20+} // namespace
21
22 /** The global \ref SoundHandler object
23 * The sound handler is a static object because otherwise it'd be quite
24@@ -99,23 +108,27 @@
25 const uint16_t bufsize = 1024;
26 #endif
27
28- if (nosound_)
29- {
30- set_disable_music(true);
31- set_disable_fx(true);
32- lock_audio_disabling_ = true;
33- return;
34- }
35-
36- if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1 ||
37- Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, bufsize) == -1 ||
38- Mix_Init(MIX_INIT_OGG) == -1) {
39- SDL_QuitSubSystem(SDL_INIT_AUDIO);
40- log("WARNING: Failed to initialize sound system: %s\n", Mix_GetError());
41-
42- set_disable_music(true);
43- set_disable_fx(true);
44- lock_audio_disabling_ = true;
45+ if (nosound_) {
46+ set_disable_music(true);
47+ set_disable_fx(true);
48+ lock_audio_disabling_ = true;
49+ return;
50+ }
51+
52+ if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) {
53+ report_initalization_error(SDL_GetError());
54+ return;
55+ }
56+
57+ if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, bufsize) != 0) {
58+ initialization_error(Mix_GetError());
59+ return;
60+ }
61+
62+ constexpr int kMixInitFlags = MIX_INIT_OGG;
63+ int initted = Mix_Init(kMixInitFlags);
64+ if ((initted & kMixInitFlags) != kMixInitFlags) {
65+ initialization_error("No Ogg support in SDL_Mixer.");
66 return;
67 }
68
69@@ -128,6 +141,17 @@
70 fx_lock_ = SDL_CreateMutex();
71 }
72
73+void SoundHandler::initialization_error(const std::string& msg) {
74+ log("WARNING: Failed to initialize sound system: %s\n", msg.c_str());
75+
76+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
77+
78+ set_disable_music(true);
79+ set_disable_fx(true);
80+ lock_audio_disabling_ = true;
81+ return;
82+}
83+
84 void SoundHandler::shutdown()
85 {
86 Mix_ChannelFinished(nullptr);
87@@ -184,8 +208,8 @@
88 } else {
89 set_disable_music(s.get_bool("disable_music", false));
90 set_disable_fx (s.get_bool("disable_fx", false));
91- music_volume_ = s.get_int ("music_volume", DEFAULT_MUSIC_VOLUME);
92- fx_volume_ = s.get_int ("fx_volume", DEFAULT_FX_VOLUME);
93+ music_volume_ = s.get_int ("music_volume", kDefaultMusicVolume);
94+ fx_volume_ = s.get_int ("fx_volume", kDefaultFxVolume);
95 }
96
97 random_order_ = s.get_bool("sound_random_order", true);
98
99=== modified file 'src/sound/sound_handler.h'
100--- src/sound/sound_handler.h 2014-12-03 07:15:40 +0000
101+++ src/sound/sound_handler.h 2014-12-20 18:20:27 +0000
102@@ -243,6 +243,9 @@
103 bool lock_audio_disabling_;
104
105 protected:
106+ // Prints an error and disables the sound system.
107+ void initialization_error(const std::string& msg);
108+
109 void load_one_fx(const char * filename, const std::string & fx_name);
110 int32_t stereo_position(Widelands::Coords position);
111 bool play_or_not

Subscribers

People subscribed via source and target branches

to status/vote changes: