Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(milesaudio): put unit replies in front of every other sound

Olcay Seygan4d02a36aa095
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f8827f404..feebead71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1211,7 +1211,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Audio is real, through the audio library the retail game ships with.
- A death cry plays to the end. So does "construction complete", and the tail of a gun. Telling a sound to stop used to cut it off that frame, where the 2003 game let it finish and only kept it from repeating; our own fix for the audio thread broke that, and it is put back. A looping sound caught in the pause between two plays can be stopped too, instead of carrying on after whatever made it is gone.
-- Your units answer you over the battle. While one of them is replying, every other sound effect drops back by about a half and comes up again when the line is finished, so "Moving out" is heard in the middle of an artillery duel. Music and speech are left where they are.
+- Your units answer you over the battle. A reply plays at whichever of the effects and voice sliders is higher, lifted again on top of that, and while it plays every other sound and the music drop to under a third, then come back when the line is finished. "Moving out" is heard in the middle of an artillery duel. EVA and briefings stay where the voice slider puts them.
- Movies follow the voice volume slider. The volume was handed to the video before it was ready to take it, so every movie played at full level, and moving the slider while one was playing changed nothing.
- A sound at the edge of its range can fade out instead of stopping dead. The volume curve never
actually reaches zero, so a sound you are walking away from was cut off mid-note at the maximum
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
index 6b18fe9cd..28d7e1892 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
@@ -293,7 +293,7 @@ class MilesAudioManager : public AudioManager
void adjustPlayingVolume( PlayingAudio *audio );
Bool isAnyVoicePlaying( void ) const;
- Real getVoiceDuckFactor( const AudioEventRTS *event ) const; ///< under 1 for anything that is not a unit's reply while one plays
+ Real getVoiceMixedVolume( const AudioEventRTS *event, Real sliderVolume ) const; ///< a unit's reply lifted, everything else held under it while one plays
void stopAllSpeech( void );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
index 3530c483a..ed1ca9ea1 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
@@ -1434,15 +1434,15 @@ void MilesAudioManager::adjustPlayingVolume( PlayingAudio *audio )
Real pan;
if (audio->m_type == PAT_Sample) {
AIL_sample_volume_pan(audio->m_sample, NULL, &pan);
- AIL_set_sample_volume_pan(audio->m_sample, m_soundVolume * desiredVolume * getVoiceDuckFactor(audio->m_audioEventRTS), pan);
+ AIL_set_sample_volume_pan(audio->m_sample, getVoiceMixedVolume(audio->m_audioEventRTS, m_soundVolume), pan);
} else if (audio->m_type == PAT_3DSample) {
- AIL_set_3D_sample_volume(audio->m_3DSample, m_sound3DVolume * desiredVolume * getVoiceDuckFactor(audio->m_audioEventRTS));
+ AIL_set_3D_sample_volume(audio->m_3DSample, getVoiceMixedVolume(audio->m_audioEventRTS, m_sound3DVolume));
} else if (audio->m_type == PAT_Stream) {
AIL_stream_volume_pan(audio->m_stream, NULL, &pan);
if (audioIsType(audio->m_audioEventRTS, AT_Music)) {
- AIL_set_stream_volume_pan(audio->m_stream, m_musicVolume * desiredVolume, pan);
+ AIL_set_stream_volume_pan(audio->m_stream, getVoiceMixedVolume(audio->m_audioEventRTS, m_musicVolume), pan);
} else {
AIL_set_stream_volume_pan(audio->m_stream, m_speechVolume * desiredVolume, pan);
@@ -1475,7 +1475,7 @@ void MilesAudioManager::stopAllSpeech( void )
void MilesAudioManager::initFilters( HSAMPLE sample, const AudioEventRTS *event )
{
// set the sample volume
- Real volume = event->getVolume() * event->getVolumeShift() * m_soundVolume * getVoiceDuckFactor(event);
+ Real volume = getVoiceMixedVolume(event, m_soundVolume);
AIL_set_sample_volume_pan(sample, volume, 0.5f);
// pitch shift
@@ -1503,7 +1503,7 @@ void MilesAudioManager::initFilters( HSAMPLE sample, const AudioEventRTS *event
void MilesAudioManager::initFilters3D( H3DSAMPLE sample, const AudioEventRTS *event, const Coord3D *pos )
{
// set the sample volume
- Real volume = event->getVolume() * event->getVolumeShift() * m_sound3DVolume * getVoiceDuckFactor(event);
+ Real volume = getVoiceMixedVolume(event, m_sound3DVolume);
AIL_set_3D_sample_volume(sample, volume);
// pitch shift
@@ -2180,17 +2180,25 @@ Bool MilesAudioManager::isAnyVoicePlaying( void ) const
}
//-------------------------------------------------------------------------------------------------
-/** A unit's reply is one short line, and in a fight it was lost under the guns: every other sound
- * is held about 5dB down for as long as one is playing. Music and speech streams are left alone. */
-Real MilesAudioManager::getVoiceDuckFactor( const AudioEventRTS *event ) const
+/** A unit's reply is one short line, and in a fight it was lost under the guns. It plays at the
+ * louder of the effects and voice sliders, lifted again on top of that up to full scale, and while
+ * one is playing every other sound and the music drop to under a third, so the reply sits in front
+ * of everything. EVA and briefing speech is left where the voice slider puts it. */
+Real MilesAudioManager::getVoiceMixedVolume( const AudioEventRTS *event, Real sliderVolume ) const
{
- static const Real VOICE_DUCK_FACTOR = 0.55f;
+ static const Real VOICE_BOOST = 1.6f;
+ static const Real VOICE_DUCK_FACTOR = 0.3f;
- if (!m_voiceDucking || (event->getAudioEventInfo()->m_type & ST_VOICE)) {
- return 1.0f;
+ const Real eventVolume = event->getVolume() * event->getVolumeShift();
+ if (event->getAudioEventInfo()->m_type & ST_VOICE) {
+ return min( 1.0f, eventVolume * max( sliderVolume, m_speechVolume ) * VOICE_BOOST );
}
- return VOICE_DUCK_FACTOR;
+ if (m_voiceDucking) {
+ return eventVolume * sliderVolume * VOICE_DUCK_FACTOR;
+ }
+
+ return eventVolume * sliderVolume;
}
//-------------------------------------------------------------------------------------------------