Skip to content

Commit 0bec2eb

Browse files
authored
Merge pull request #607 from tintinhamans/arctic/go/stack/04-audio-fixes
bugfix(audio): Cherry-pick upstream Miles audio fixes (b2)
2 parents d188520 + c7434bf commit 0bec2eb

29 files changed

Lines changed: 4581 additions & 4492 deletions

File tree

‎Core/GameEngine/Include/Common/AudioEventRTS.h‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,27 @@ class AudioEventRTS
199199
PortionToPlay m_portionToPlayNext; ///< Which portion (attack, sound, decay) should be played next?
200200
};
201201

202-
class DynamicAudioEventRTS : public MemoryPoolObject
202+
class DynamicAudioEventRTS : public MemoryPoolObject, public RefCountClass, public AudioEventRTS
203203
{
204204
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(DynamicAudioEventRTS, "DynamicAudioEventRTS" )
205205
public:
206206

207-
DynamicAudioEventRTS() { }
208-
DynamicAudioEventRTS(const AudioEventRTS& a) : m_event(a) { }
207+
DynamicAudioEventRTS() {}
208+
DynamicAudioEventRTS( const AsciiString& eventName ) : AudioEventRTS(eventName) {}
209+
DynamicAudioEventRTS( const AsciiString& eventName, ObjectID ownerID ) : AudioEventRTS(eventName, ownerID) {}
210+
DynamicAudioEventRTS( const AsciiString& eventName, DrawableID drawableID ) : AudioEventRTS(eventName, drawableID) {}
211+
DynamicAudioEventRTS( const AsciiString& eventName, const Coord3D *positionOfAudio ) : AudioEventRTS(eventName, positionOfAudio) {}
209212

210-
AudioEventRTS m_event;
213+
DynamicAudioEventRTS(const AudioEventRTS& a) : AudioEventRTS(a) {}
214+
DynamicAudioEventRTS& operator=( const AudioEventRTS& right )
215+
{
216+
*static_cast<AudioEventRTS*>(this) = right;
217+
return *this;
218+
}
219+
220+
void Delete_This() override
221+
{
222+
deleteInstance(this);
223+
}
211224
};
212225
EMPTY_DTOR(DynamicAudioEventRTS)

‎Core/GameEngine/Include/Common/AudioRequest.h‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131
#include "Common/GameAudio.h"
3232
#include "Common/GameMemory.h"
33+
#include "Common/AudioHandleSpecialValues.h"
3334

34-
class AudioEventRTS;
35+
class DynamicAudioEventRTS;
3536

3637
enum RequestType CPP_11(: Int)
3738
{
@@ -45,14 +46,18 @@ struct AudioRequest : public MemoryPoolObject
4546
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( AudioRequest, "AudioRequest" )
4647

4748
public:
48-
AudioEventRTS* releasePendingEvent();
49+
50+
AudioRequest()
51+
: m_request(AR_Play)
52+
, m_pendingEvent(nullptr)
53+
, m_handleToInteractOn(AHSV_Error)
54+
, m_requiresCheckForSample(false)
55+
, m_requestStop(false)
56+
{}
4957

5058
RequestType m_request;
51-
union
52-
{
53-
AudioEventRTS *m_pendingEvent;
54-
AudioHandle m_handleToInteractOn;
55-
};
56-
Bool m_usePendingEvent;
59+
RefCountPtr<DynamicAudioEventRTS> m_pendingEvent;
60+
AudioHandle m_handleToInteractOn;
5761
Bool m_requiresCheckForSample;
62+
Bool m_requestStop; // Let the audio play and finish but stop looping if it is looping
5863
};

‎Core/GameEngine/Include/Common/GameAudio.h‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ class AudioManager : public SubsystemInterface
244244
// on zoom.
245245
virtual void set3DVolumeAdjustment( Real volumeAdjustment );
246246

247-
virtual Bool has3DSensitiveStreamsPlaying() const = 0;
248-
249247
virtual void *getHandleForBink() = 0;
250248
virtual void releaseHandleForBink() = 0;
251249

@@ -257,9 +255,9 @@ class AudioManager : public SubsystemInterface
257255
virtual void setListenerPosition( const Coord3D *newListenerPos, const Coord3D *newListenerOrientation );
258256
virtual const Coord3D *getListenerPosition() const;
259257

260-
virtual AudioRequest *allocateAudioRequest( Bool useAudioEvent );
258+
virtual AudioRequest *allocateAudioRequest();
261259
virtual void releaseAudioRequest( AudioRequest *requestToRelease );
262-
virtual void appendAudioRequest( AudioRequest *m_request );
260+
virtual void appendAudioRequest( AudioRequest *request );
263261
virtual void processRequestList();
264262

265263
virtual AudioEventInfo *newAudioEventInfo( AsciiString newEventName );
@@ -269,9 +267,6 @@ class AudioManager : public SubsystemInterface
269267
const AudioSettings *getAudioSettings() const;
270268
const MiscAudio *getMiscAudio() const;
271269

272-
// This function should only be called by AudioManager, MusicManager and SoundManager
273-
virtual void releaseAudioEventRTS( AudioEventRTS *&eventToRelease );
274-
275270
// For INI
276271
AudioSettings *friend_getAudioSettings();
277272
MiscAudio *friend_getMiscAudio();

‎Core/GameEngine/Include/Common/GameMusic.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ class MusicManager
102102
MusicManager();
103103
virtual ~MusicManager();
104104

105-
void playTrack( AudioEventRTS *eventToUse );
105+
void playTrack( DynamicAudioEventRTS *eventToUse );
106106
void stopTrack( AudioHandle eventToRemove );
107107

108-
virtual void addAudioEvent(AudioEventRTS *eventToAdd); // pre-copied
108+
virtual void addAudioEvent( DynamicAudioEventRTS *eventToAdd ); // pre-copied
109109
virtual void removeAudioEvent( AudioHandle eventToRemove );
110110

111111
void setVolume( Real m_volume );

‎Core/GameEngine/Include/Common/GameSounds.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
#include "Common/GameAudio.h"
4646
#include "Common/GameType.h"
4747

48-
// Forward declarations
4948
class AudioEventRTS;
49+
class DynamicAudioEventRTS;
5050

5151
class SoundManager : public SubsystemInterface
5252
{
@@ -67,7 +67,7 @@ class SoundManager : public SubsystemInterface
6767
virtual void setCameraAudibleDistance( Real audibleDistance );
6868
virtual Real getCameraAudibleDistance();
6969

70-
virtual void addAudioEvent(AudioEventRTS *&eventToAdd); // pre-copied
70+
virtual Bool addAudioEvent(DynamicAudioEventRTS *eventToAdd); // pre-copied
7171

7272
// empty string means that this sound wasn't found or some error occurred. CHECK FOR EMPTY STRING.
7373
virtual AsciiString getFilenameForPlayFromAudioEvent( const AudioEventRTS *eventToGetFrom );

‎Core/GameEngine/Include/GameClient/VideoPlayer.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ class VideoPlayerInterface : public SubsystemInterface
245245
virtual const FieldParse *getFieldParse() const = 0; ///< Return the field parse info
246246

247247
virtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid ) = 0; ///< Notify the video player that they can now ask for an audio handle, or they need to give theirs up.
248+
249+
virtual void setVolume( Real volume ) = 0; ///< Push a new speech volume to the video player's audio output
248250
};
249251

250252

@@ -299,6 +301,13 @@ class VideoPlayer : public VideoPlayerInterface
299301

300302
};
301303

304+
class NullVideoPlayer : public VideoPlayer
305+
{
306+
public:
307+
308+
virtual void setVolume( Real ) override { }
309+
};
310+
302311
extern VideoPlayerInterface *TheVideoPlayer;
303312

304313
//----------------------------------------------------------------------------

‎Core/GameEngine/Source/Common/Audio/AudioRequest.cpp‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,4 @@
3030

3131
AudioRequest::~AudioRequest()
3232
{
33-
if (m_usePendingEvent)
34-
{
35-
delete m_pendingEvent;
36-
}
37-
}
38-
39-
AudioEventRTS* AudioRequest::releasePendingEvent()
40-
{
41-
if (m_usePendingEvent)
42-
{
43-
m_usePendingEvent = false;
44-
AudioEventRTS* event = m_pendingEvent;
45-
m_pendingEvent = nullptr;
46-
return event;
47-
}
48-
return nullptr;
4933
}

‎Core/GameEngine/Source/Common/Audio/GameAudio.cpp‎

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
439439
return AHSV_NotForLocal;
440440
}
441441

442-
AudioEventRTS *audioEvent = MSGNEW("AudioEventRTS") AudioEventRTS(*eventToAdd); // poolify
442+
RefCountPtr<DynamicAudioEventRTS> audioEvent;
443+
audioEvent.Assign_No_Add_Ref(newInstance(DynamicAudioEventRTS)(*eventToAdd));
443444
audioEvent->setPlayingHandle( allocateNewHandle() );
444445
audioEvent->generateFilename(); // which file are we actually going to play?
445446
eventToAdd->setPlayingAudioIndex( audioEvent->getPlayingAudioIndex() );
@@ -456,7 +457,6 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
456457
#if RETAIL_COMPATIBLE_CRC
457458
if (notForLocal)
458459
{
459-
releaseAudioEventRTS(audioEvent);
460460
return AHSV_NotForLocal;
461461
}
462462
#endif
@@ -466,21 +466,22 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
466466
#ifdef INTENSIVE_AUDIO_DEBUG
467467
DEBUG_LOG((" - culled due to muting (%d).", audioEvent->getVolume()));
468468
#endif
469-
releaseAudioEventRTS(audioEvent);
470469
return AHSV_Muted;
471470
}
472471

473472
if (soundType == AT_Music)
474473
{
475-
m_music->addAudioEvent(audioEvent);
474+
m_music->addAudioEvent(audioEvent.Peek());
476475
}
477476
else
478477
{
479-
//Possible to nuke audioEvent inside.
480-
m_sound->addAudioEvent(audioEvent);
478+
if (!m_sound->addAudioEvent(audioEvent.Peek()))
479+
{
480+
audioEvent.Clear();
481+
}
481482
}
482483

483-
if( audioEvent )
484+
if( audioEvent != nullptr )
484485
{
485486
return audioEvent->getPlayingHandle();
486487
}
@@ -578,7 +579,7 @@ void AudioManager::removeAudioEvent(AudioHandle audioEvent)
578579
return;
579580
}
580581

581-
AudioRequest *req = allocateAudioRequest( false );
582+
AudioRequest *req = allocateAudioRequest();
582583
req->m_handleToInteractOn = audioEvent;
583584
req->m_request = AR_Stop;
584585
appendAudioRequest( req );
@@ -709,7 +710,12 @@ void AudioManager::setVolume( Real volume, AudioAffect whichToAffect )
709710
m_scriptMusicVolume = volume;
710711
}
711712

712-
m_musicVolume = m_scriptMusicVolume * m_systemMusicVolume;
713+
const Real newVolume = m_scriptMusicVolume * m_systemMusicVolume;
714+
if (m_musicVolume != newVolume)
715+
{
716+
m_musicVolume = newVolume;
717+
m_volumeHasChanged = true;
718+
}
713719
}
714720

715721
if (whichToAffect & AudioAffect_Sound) {
@@ -719,7 +725,12 @@ void AudioManager::setVolume( Real volume, AudioAffect whichToAffect )
719725
m_scriptSoundVolume = volume;
720726
}
721727

722-
m_soundVolume = m_scriptSoundVolume * m_systemSoundVolume;
728+
const Real newVolume = m_scriptSoundVolume * m_systemSoundVolume;
729+
if (m_soundVolume != newVolume)
730+
{
731+
m_soundVolume = newVolume;
732+
m_volumeHasChanged = true;
733+
}
723734
}
724735

725736
if (whichToAffect & AudioAffect_Sound3D) {
@@ -728,7 +739,13 @@ void AudioManager::setVolume( Real volume, AudioAffect whichToAffect )
728739
} else {
729740
m_scriptSound3DVolume = volume;
730741
}
731-
m_sound3DVolume = m_scriptSound3DVolume * m_systemSound3DVolume;
742+
743+
const Real newVolume = m_scriptSound3DVolume * m_systemSound3DVolume;
744+
if (m_sound3DVolume != newVolume)
745+
{
746+
m_sound3DVolume = newVolume;
747+
m_volumeHasChanged = true;
748+
}
732749
}
733750

734751
if (whichToAffect & AudioAffect_Speech) {
@@ -737,10 +754,14 @@ void AudioManager::setVolume( Real volume, AudioAffect whichToAffect )
737754
} else {
738755
m_scriptSpeechVolume = volume;
739756
}
740-
m_speechVolume = m_scriptSpeechVolume * m_systemSpeechVolume;
741-
}
742757

758+
const Real newVolume = m_scriptSpeechVolume * m_systemSpeechVolume;
759+
if (m_speechVolume != newVolume)
760+
{
761+
m_speechVolume = newVolume;
743762
m_volumeHasChanged = true;
763+
}
764+
}
744765
}
745766

746767
//-------------------------------------------------------------------------------------------------
@@ -761,17 +782,13 @@ Real AudioManager::getVolume( AudioAffect whichToGet )
761782
//-------------------------------------------------------------------------------------------------
762783
void AudioManager::set3DVolumeAdjustment( Real volumeAdjustment )
763784
{
764-
m_sound3DVolume = volumeAdjustment * m_scriptSound3DVolume * m_systemSound3DVolume;
765-
766-
// clamp
767-
if (m_sound3DVolume < 0.0f)
768-
m_sound3DVolume = 0.0f;
785+
const Real newVolume = clamp(0.0f, volumeAdjustment * m_scriptSound3DVolume * m_systemSound3DVolume, 1.0f);
769786

770-
if (m_sound3DVolume > 1.0f)
771-
m_sound3DVolume = 1.0f;
772-
773-
if ( ! has3DSensitiveStreamsPlaying() )
774-
m_volumeHasChanged = TRUE;
787+
if (m_sound3DVolume != newVolume)
788+
{
789+
m_sound3DVolume = newVolume;
790+
m_volumeHasChanged = true;
791+
}
775792
}
776793

777794
//-------------------------------------------------------------------------------------------------
@@ -788,10 +805,9 @@ const Coord3D *AudioManager::getListenerPosition() const
788805
}
789806

790807
//-------------------------------------------------------------------------------------------------
791-
AudioRequest *AudioManager::allocateAudioRequest( Bool useAudioEvent )
808+
AudioRequest *AudioManager::allocateAudioRequest()
792809
{
793810
AudioRequest *audioReq = newInstance(AudioRequest);
794-
audioReq->m_usePendingEvent = useAudioEvent;
795811
audioReq->m_requiresCheckForSample = false;
796812
return audioReq;
797813
}
@@ -805,20 +821,19 @@ void AudioManager::releaseAudioRequest( AudioRequest *requestToRelease )
805821
}
806822

807823
//-------------------------------------------------------------------------------------------------
808-
void AudioManager::appendAudioRequest( AudioRequest *m_request )
824+
void AudioManager::appendAudioRequest( AudioRequest *request )
809825
{
810-
m_audioRequests.push_back(m_request);
826+
m_audioRequests.push_back(request);
811827
}
812828

813829
//-------------------------------------------------------------------------------------------------
814830
// Remove all pending audio requests
815831
void AudioManager::removeAllAudioRequests()
816832
{
817833
std::list<AudioRequest*>::iterator it;
818-
for ( it = m_audioRequests.begin(); it != m_audioRequests.end(); it++ ) {
834+
for ( it = m_audioRequests.begin(); it != m_audioRequests.end(); ++it ) {
819835
releaseAudioRequest( *it );
820836
}
821-
822837
m_audioRequests.clear();
823838
}
824839

@@ -1047,17 +1062,10 @@ Bool AudioManager::shouldPlayLocally(const AudioEventRTS *audioEvent)
10471062
//-------------------------------------------------------------------------------------------------
10481063
AudioHandle AudioManager::allocateNewHandle()
10491064
{
1050-
// note, intenionally a post increment rather than a pre increment.
1065+
// note, intentionally a post increment rather than a pre increment.
10511066
return theAudioHandlePool++;
10521067
}
10531068

1054-
//-------------------------------------------------------------------------------------------------
1055-
void AudioManager::releaseAudioEventRTS( AudioEventRTS *&eventToRelease )
1056-
{
1057-
delete eventToRelease;
1058-
eventToRelease = nullptr;
1059-
}
1060-
10611069
//-------------------------------------------------------------------------------------------------
10621070
void AudioManager::muteAudio( MuteAudioReason reason )
10631071
{

0 commit comments

Comments
 (0)