View Issue Details

IDProjectCategoryView StatusLast Update
0002517FSSCPsoundpublic2011-10-10 16:52
Reportertorc Assigned ToEli2  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.6.13 
Fixed in Version3.6.13 
Summary0002517: loop sounds are always at 100% volume locked, and afterburner fade out sound not work
Descriptionthe loop sounds,as i said,are locked to 100% volume level,plus, when afterburner are engaged,before they running dry,the sound should fade out:
Now the sound start clipping at the end of the loop.
TagsNo tags attached.

Activities

2011-10-08 16:23

 

SoundPatchFix.svn.patch (4,050 bytes)   
Index: code/sound/sound.cpp
===================================================================
--- code/sound/sound.cpp
+++ code/sound/sound.cpp
@@ -56,7 +56,20 @@ float Master_voice_volume = 0.7f;	// range is 0 -> 1, used for all voice playbac
 
 unsigned int SND_ENV_DEFAULT = 0;
 
-SCP_list<int> currentlyLoopingSoundHandles;
+struct LoopingSoundInfo {
+	int dsHandle;
+	float defaultVolume;	//!< The default volume of this sound (from game_snd)
+	float dynamicVolume;	//!< The dynamic volume before scripted volume adjustment is applied (is updated via snd_set_volume)
+
+	LoopingSoundInfo(int dsHandle, float defaultVolume, float dynamicVolume):
+		dsHandle(dsHandle),
+		defaultVolume(defaultVolume),
+		dynamicVolume(dynamicVolume)
+	{
+	}
+};
+
+SCP_list<LoopingSoundInfo> currentlyLoopingSoundInfos;
 
 //For the adjust-audio-volume sexp
 float aav_voice_volume = 1.0f;
@@ -811,7 +824,7 @@ int snd_play_looping( game_snd *gs, float pan, int start_loop, int stop_loop, fl
 		handle = ds_play( snd->sid, gs->id_sig, DS_MUST_PLAY, volume, pan, 1);
 
 		if(handle != -1 && scriptingUpdateVolume) {
-			currentlyLoopingSoundHandles.push_back(handle);
+			currentlyLoopingSoundInfos.push_back(LoopingSoundInfo(handle, gs->default_volume, vol_scale));
 		}
 	}
 
@@ -834,12 +847,11 @@ void snd_stop( int sig )
 	if ( channel == -1 )
 		return;
 	
-	SCP_list<int>::iterator iter = currentlyLoopingSoundHandles.begin();
-	while (iter != currentlyLoopingSoundHandles.end())
+	SCP_list<LoopingSoundInfo>::iterator iter = currentlyLoopingSoundInfos.begin();
+	while (iter != currentlyLoopingSoundInfos.end())
 	{
-		int handle = *iter;
-		if(handle == sig) {
-			iter = currentlyLoopingSoundHandles.erase(iter);
+		if(iter->dsHandle == sig) {
+			iter = currentlyLoopingSoundInfos.erase(iter);
 		} else {
 			++iter;
 		}
@@ -859,18 +871,16 @@ void snd_stop_all()
 	if (!ds_initialized)
 		return;
 
-	currentlyLoopingSoundHandles.clear();
+	currentlyLoopingSoundInfos.clear();
 	ds_stop_channel_all();
 }
 
-// ---------------------------------------------------------------------------------------
-// snd_set_volume()
-//
-// Set the volume of a currently playing sound
-//
-// parameters:		sig		=> handle to sound, what is returned from snd_play()
-//						volume	=> volume of sound (range: 0.0 -> 1.0)
-//
+/**
+ * Set the volume of a currently playing sound
+ *
+ * @param sig		handle to sound, what is returned from snd_play()
+ * @param volume	volume of sound (range: 0.0 -> 1.0)
+ */
 void snd_set_volume( int sig, float volume )
 {
 	int	channel;
@@ -888,8 +898,23 @@ void snd_set_volume( int sig, float volume )
 		return;
 	}
 
-	new_volume = volume * (Master_sound_volume * aav_effect_volume);
-	ds_set_volume( channel, new_volume );
+	bool isLoopingSound = false;
+
+	SCP_list<LoopingSoundInfo>::iterator iter;
+	for (iter = currentlyLoopingSoundInfos.begin(); iter != currentlyLoopingSoundInfos.end(); ++iter) {
+		if(iter->dsHandle == sig) {
+			iter->dynamicVolume = volume;
+
+			isLoopingSound = true;
+			break;
+		}
+	}
+
+	//looping sound volumes are updated in snd_do_frame
+	if(!isLoopingSound) {
+		new_volume = volume * (Master_sound_volume * aav_effect_volume);
+		ds_set_volume( channel, new_volume );
+	}
 }
 
 // ---------------------------------------------------------------------------------------
@@ -1345,10 +1370,11 @@ void snd_do_frame()
 	adjust_volume_on_frame(&aav_voice_volume, &aav_data[AAV_VOICE]);
 	adjust_volume_on_frame(&aav_effect_volume, &aav_data[AAV_EFFECTS]);
 
-	SCP_list<int>::iterator iter;
-	for (iter = currentlyLoopingSoundHandles.begin(); iter != currentlyLoopingSoundHandles.end(); ++iter) {
-		int handle = *iter;
-		snd_set_volume(handle, 1.0f);
+	SCP_list<LoopingSoundInfo>::iterator iter;
+	for (iter = currentlyLoopingSoundInfos.begin(); iter != currentlyLoopingSoundInfos.end(); ++iter) {
+
+		float new_volume = iter->defaultVolume * iter->dynamicVolume * (Master_sound_volume * aav_effect_volume);
+		ds_set_volume(ds_get_channel(iter->dsHandle), new_volume);
 	}
 
 	ds_do_frame();
SoundPatchFix.svn.patch (4,050 bytes)   

Eli2

2011-10-08 16:24

developer   ~0012883

I attached a patch, that should fix this issue.
Tested by torc.

niffiwan

2011-10-09 11:09

developer   ~0012887

I've succesfully tested the patch as well - committed to trunk in 7885

torc

2011-10-09 19:01

reporter   ~0012888

it works good... issue solved

Goober5000

2011-10-10 16:52

administrator   ~0012890

Crediting Eli2 for the fix, per request.

Issue History

Date Modified Username Field Change
2011-10-08 15:51 torc New Issue
2011-10-08 16:23 Eli2 File Added: SoundPatchFix.svn.patch
2011-10-08 16:24 Eli2 Note Added: 0012883
2011-10-09 11:09 niffiwan Note Added: 0012887
2011-10-09 11:13 niffiwan Status new => assigned
2011-10-09 11:13 niffiwan Assigned To => niffiwan
2011-10-09 11:13 niffiwan Status assigned => feedback
2011-10-09 19:01 torc Note Added: 0012888
2011-10-10 09:38 niffiwan Status feedback => resolved
2011-10-10 09:38 niffiwan Fixed in Version => 3.6.13
2011-10-10 09:38 niffiwan Resolution open => fixed
2011-10-10 16:52 Goober5000 Note Added: 0012890
2011-10-10 16:52 Goober5000 Assigned To niffiwan => Eli2