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): duck other sounds while a unit replies

Olcay Seygan52714c1dabc3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72ad39fac..3507f955e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1202,6 +1202,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.
- 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 e5ff6fb60..6b18fe9cd 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
@@ -292,7 +292,9 @@ class MilesAudioManager : public AudioManager
H3DSAMPLE getFirst3DSample( AudioEventRTS *event );
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
+
void stopAllSpeech( void );
protected:
@@ -312,6 +314,7 @@ class MilesAudioManager : public AudioManager
HDIGDRIVER m_digitalHandle;
H3DPOBJECT m_listener;
HPROVIDER m_delayFilter;
+ Bool m_voiceDucking; ///< a unit's reply is playing and every other sound is held under it
// This is a list of all handles that are forcibly played. They always play as UI sounds.
std::list<HAUDIO> m_audioForcePlayed;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
index 3523b2bd5..3530c483a 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
@@ -110,6 +110,7 @@ MilesAudioManager::MilesAudioManager() :
m_num3DSamples(0),
m_numStreams(0),
m_delayFilter(NULL),
+ m_voiceDucking(FALSE),
m_binkHandle(NULL),
m_pref3DProvider(AsciiString::TheEmptyString),
m_prefSpeaker(AsciiString::TheEmptyString)
@@ -1433,10 +1434,10 @@ 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, pan);
+ AIL_set_sample_volume_pan(audio->m_sample, m_soundVolume * desiredVolume * getVoiceDuckFactor(audio->m_audioEventRTS), pan);
- } else if (audio->m_type == PAT_3DSample) {
- AIL_set_3D_sample_volume(audio->m_3DSample, m_sound3DVolume * desiredVolume);
+ } else if (audio->m_type == PAT_3DSample) {
+ AIL_set_3D_sample_volume(audio->m_3DSample, m_sound3DVolume * desiredVolume * getVoiceDuckFactor(audio->m_audioEventRTS));
} else if (audio->m_type == PAT_Stream) {
AIL_stream_volume_pan(audio->m_stream, NULL, &pan);
@@ -1474,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;
+ Real volume = event->getVolume() * event->getVolumeShift() * m_soundVolume * getVoiceDuckFactor(event);
AIL_set_sample_volume_pan(sample, volume, 0.5f);
// pitch shift
@@ -1502,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;
+ Real volume = event->getVolume() * event->getVolumeShift() * m_sound3DVolume * getVoiceDuckFactor(event);
AIL_set_3D_sample_volume(sample, volume);
// pitch shift
@@ -2159,6 +2160,39 @@ Bool MilesAudioManager::isObjectPlayingVoice( UnsignedInt objID ) const
return false;
}
+//-------------------------------------------------------------------------------------------------
+Bool MilesAudioManager::isAnyVoicePlaying( void ) const
+{
+ std::list<PlayingAudio *>::const_iterator it;
+ for ( it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it ) {
+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getAudioEventInfo()->m_type & ST_VOICE) {
+ return true;
+ }
+ }
+
+ for ( it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it ) {
+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getAudioEventInfo()->m_type & ST_VOICE) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** 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
+{
+ static const Real VOICE_DUCK_FACTOR = 0.55f;
+
+ if (!m_voiceDucking || (event->getAudioEventInfo()->m_type & ST_VOICE)) {
+ return 1.0f;
+ }
+
+ return VOICE_DUCK_FACTOR;
+}
+
//-------------------------------------------------------------------------------------------------
AudioEventRTS* MilesAudioManager::findLowestPrioritySound( AudioEventRTS *event )
{
@@ -2436,6 +2470,13 @@ void MilesAudioManager::processPlayingList( void )
std::list<PlayingAudio *>::iterator it;
PlayingAudio *playing;
+ // a reply starting or ending re-levels everything already playing
+ const Bool voicePlaying = isAnyVoicePlaying();
+ if (voicePlaying != m_voiceDucking) {
+ m_voiceDucking = voicePlaying;
+ m_volumeHasChanged = true;
+ }
+
for (it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it) {
playing = (*it);
if (!playing)