Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: The E on August 18, 2010, 08:38:26 pm
-
Here's a little sexp I've been working on. To quote from sexps.html:
adjust-audio-volume
Adjusts the relative volume of one sound type. Takes 1 to 3 arguments....
1: Sound Type to adjust, either Music, Voice or Effects. Will act as a reset for the given category, if no other argument present
2: Percentage of the users' settings to adjust to (optional), 0 will be silence, 100 means the maximum volume as set by the user
3: Fade time (optional), time in milliseconds to adjust the volume
Test builds for both FRED and FSO, as well as a simple sample mission and a code patch, are included in this download (http://blueplanet.fsmods.net/E/AdjustAudioTest.7z).
-
Thank goodness.
Also thank Axem for agitating for this so his opening cutscene wouldn't break.
-
I'll have to test that voice option next time some political add is on. :P
-
FRAKKING YES
I've been needing this
:D
-
So now we can have FPS-style ear-ringing?
-
You can certainly simulate it.
Also, can you guys pleeeeeeeaaaaaaaaaaaseeeeeeeee test this so I can fix it up if necessary and put it into trunk?
-
On my phone so I can't test this. I assume it doesn't actually touch the user's settings and switches back to defaults at the start of the next mission, right?
-
The actual user settings are unaffected, and it will reset on mission end, and on mission start.
As I said in the help text "100" means "Play this as loud as the user set it". It doesn't go beyond that.
-
That fade time, it's applied to both the start and end of a track?
-
Err.
No, this sexp changes the effective volume of the music, voice and effect channels. It acts as a multiplier of sorts for the volume settings in the Options menu. There is no way to apply it to a specific piece of music or effect.
-
Sorry, my bad.
-
Possible problem with this piece of code is that the snd_adjust_audio_volume(int type, float percent, int time) function can currently attempt to write outside the aav_data[3] array via an off-by-one. The debug Assert() check is for an index into that array of less than 4, although as an array starting at zero the three elements have indices 0, 1 and 2.
The one call within the codebase to snd_adjust_audio_volume() from sexp_adjust_audio_volume() uses the audio_volume_option_lookup() function to pick the 'type'. This has a comment "\t1:\tSound Type to adjust, either Master, Music, Voice or Effects\r\n" i.e. 4 elements even though the SEXP doesn't appear to offer the ability to adjust the Master volume, which may be the cause of the confusion.
audio_volume_option_lookup() can also return -1, which is an error code not checked for (on non-Debug), and would have likewise lead to an out of bounds write to the aav_data array.
Proposed fix (Mantis 2314 (http://scp.indiegames.us/mantis/view.php?id=2314)):
Index: code/sound/sound.cpp
===================================================================
--- code/sound/sound.cpp (revision 6523)
+++ code/sound/sound.cpp (working copy)
@@ -1396,7 +1396,7 @@
void snd_adjust_audio_volume(int type, float percent, int time)
{
- Assert( type >= 0 && type < 4 );
+ Assert( type >= 0 && type < 3 );
switch (type) {
case AAV_MUSIC:
@@ -1420,6 +1420,8 @@
else
aav_data[type].delta = percent - aav_effect_volume;
break;
+ default:
+ Int3();
}
aav_data[type].delta_time = time;
-
Fixed in trunk revision 6524.