← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/sound_improvements into lp:widelands

 

SirVer has proposed merging lp:~widelands-dev/widelands/sound_improvements into lp:widelands.

Commit message:
Allocate 32 mixing channels instead of the default 8.

SDL Mixer allocates 2 mixing channels by default. My understanding is that each sound effect and music requires 2 (one for left, one for right), therefore Widelands right now can only play music + 3 sound effects - which we go over very often. This ups the limit to music + 15 sound effects which ought to be enough for everybody.

In fact, it could be that this is excessive on high speeds (i.e. too many sounds firing constantly), but I suggest this change for wider testing.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/sound_improvements/+merge/314035
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/sound_improvements into lp:widelands.
=== modified file 'src/sound/sound_handler.cc'
--- src/sound/sound_handler.cc	2016-10-22 18:19:22 +0000
+++ src/sound/sound_handler.cc	2017-01-03 20:52:54 +0000
@@ -47,6 +47,7 @@
 
 constexpr int kDefaultMusicVolume = 64;
 constexpr int kDefaultFxVolume = 128;
+constexpr int kNumMixingChannels = 32;
 
 void report_initalization_error(const char* msg) {
 	log("WARNING: Failed to initialize sound system: %s\n", msg);
@@ -129,6 +130,10 @@
 		return;
 	}
 
+	if (Mix_AllocateChannels(kNumMixingChannels) != kNumMixingChannels) {
+		initialization_error(Mix_GetError());
+	}
+
 	Mix_HookMusicFinished(SoundHandler::music_finished_callback);
 	Mix_ChannelFinished(SoundHandler::fx_finished_callback);
 	load_system_sounds();
@@ -460,9 +465,9 @@
 	//  retrieve the fx and play it if it's valid
 	if (Mix_Chunk* const m = fxs_[fx_name]->get_fx()) {
 		const int32_t chan = Mix_PlayChannel(-1, m, 0);
-		if (chan == -1)
-			log("SoundHandler: Mix_PlayChannel failed\n");
-		else {
+		if (chan == -1) {
+			log("SoundHandler: Mix_PlayChannel failed: %s\n", Mix_GetError());
+		} else {
 			Mix_SetPanning(chan, 254 - stereo_pos, stereo_pos);
 			Mix_Volume(chan, get_fx_volume());
 


Follow ups