Skip to content

Commit b0becc4

Browse files
committed
refactor(milesaudiomanager): Clean up and simplify MilesAudioManager (TheSuperHackers#2718)
1 parent df2224b commit b0becc4

5 files changed

Lines changed: 153 additions & 347 deletions

File tree

Core/GameEngine/Include/Common/GameAudio.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ class AudioManager : public SubsystemInterface
177177
AsciiString prevTrackName(const AsciiString& currentTrack );
178178

179179
// changing music tracks
180-
virtual void nextMusicTrack() = 0;
181-
virtual void prevMusicTrack() = 0;
180+
virtual AsciiString nextMusicTrack() = 0;
181+
virtual AsciiString prevMusicTrack() = 0;
182182
virtual Bool isMusicPlaying() const = 0;
183183
virtual Bool hasMusicTrackCompleted( const AsciiString& trackName, Int numberOfTimes ) const = 0;
184-
virtual AsciiString getMusicTrackName() const = 0;
185184

186185
virtual void setAudioEventEnabled( AsciiString eventToAffect, Bool enable );
187186
virtual void setAudioEventVolumeOverride( AsciiString eventToAffect, Real newVolume );

Core/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ enum PlayingStatus CPP_11(: Int)
4040
{
4141
PS_Playing,
4242
PS_Stopped,
43-
PS_Paused
4443
};
4544

4645
enum PlayingWhich CPP_11(: Int)
@@ -60,22 +59,24 @@ struct PlayingAudio
6059
HSTREAM m_stream;
6160
};
6261

63-
PlayingAudioType m_type;
64-
volatile PlayingStatus m_status; // This member is adjusted by another running thread.
6562
AudioEventRTS *m_audioEventRTS;
66-
void *m_file; // The file that was opened to play this
63+
void *m_file; // The file that was opened to play this
64+
PlayingAudioType m_type;
65+
volatile PlayingStatus m_status; // This member is adjusted by another running thread.
66+
Int m_framesFaded;
6767
Bool m_requestStop;
6868
Bool m_cleanupAudioEventRTS;
69-
Int m_framesFaded;
7069

71-
PlayingAudio() :
72-
m_type(PAT_INVALID),
73-
m_audioEventRTS(nullptr),
74-
m_requestStop(false),
75-
m_cleanupAudioEventRTS(true),
76-
m_sample(nullptr),
77-
m_framesFaded(0)
78-
{ }
70+
PlayingAudio()
71+
: m_sample(nullptr)
72+
, m_audioEventRTS(nullptr)
73+
, m_file(nullptr)
74+
, m_type(PAT_INVALID)
75+
, m_status(PS_Playing)
76+
, m_framesFaded(0)
77+
, m_requestStop(false)
78+
, m_cleanupAudioEventRTS(true)
79+
{}
7980
};
8081

8182
struct ProviderInfo
@@ -114,7 +115,7 @@ class AudioFileCache
114115
// End Protected by mutex
115116

116117
// Note: These functions should be used for informational purposes only. For speed reasons,
117-
// they are not protected by the mutex, so they are not guarenteed to be valid if called from
118+
// they are not protected by the mutex, so they are not guaranteed to be valid if called from
118119
// outside the audio cache. They should be used as a rough estimate only.
119120
UnsignedInt getCurrentlyUsedSize() const { return m_currentlyUsedSize; }
120121
UnsignedInt getMaxSize() const { return m_maxSize; }
@@ -150,12 +151,10 @@ class MilesAudioManager : public AudioManager
150151
MilesAudioManager();
151152
virtual ~MilesAudioManager() override;
152153

153-
154-
virtual void nextMusicTrack() override;
155-
virtual void prevMusicTrack() override;
154+
virtual AsciiString nextMusicTrack() override;
155+
virtual AsciiString prevMusicTrack() override;
156156
virtual Bool isMusicPlaying() const override;
157157
virtual Bool hasMusicTrackCompleted( const AsciiString& trackName, Int numberOfTimes ) const override;
158-
virtual AsciiString getMusicTrackName() const override;
159158

160159
virtual void openDevice() override;
161160
virtual void closeDevice() override;
@@ -172,8 +171,8 @@ class MilesAudioManager : public AudioManager
172171
///< NOTE NOTE NOTE !!DO NOT USE THIS IN FOR GAMELOGIC PURPOSES!! NOTE NOTE NOTE
173172
virtual Bool isCurrentlyPlaying( AudioHandle handle ) override;
174173

175-
virtual void notifyOfAudioCompletion( UnsignedInt audioCompleted, UnsignedInt flags ) override;
176-
virtual PlayingAudio *findPlayingAudioFrom( UnsignedInt audioCompleted, UnsignedInt flags );
174+
virtual void notifyOfAudioCompletion( UnsignedInt handle, UnsignedInt flags ) override;
175+
virtual PlayingAudio *findPlayingAudioFrom( UnsignedInt handle, UnsignedInt flags );
177176

178177
virtual UnsignedInt getProviderCount() const override;
179178
virtual AsciiString getProviderName( UnsignedInt providerNum ) const override;
@@ -208,7 +207,6 @@ class MilesAudioManager : public AudioManager
208207
virtual void processRequestList() override;
209208
virtual void processPlayingList();
210209
virtual void processFadingList();
211-
virtual void processStoppedList();
212210

213211
Bool shouldProcessRequestThisFrame( AudioRequest *req ) const;
214212
void adjustRequest( AudioRequest *req );
@@ -243,7 +241,6 @@ class MilesAudioManager : public AudioManager
243241
void *playSample( AudioEventRTS *event, HSAMPLE sample );
244242
void *playSample3D( AudioEventRTS *event, H3DSAMPLE sample3D );
245243

246-
protected:
247244
void buildProviderList();
248245
void createListener();
249246
void initDelayFilter();
@@ -262,6 +259,9 @@ class MilesAudioManager : public AudioManager
262259
void releaseMilesHandles( PlayingAudio *release );
263260
void releasePlayingAudio( PlayingAudio *release );
264261

262+
PlayingAudio *findActiveMusic( const AsciiString *trackName = nullptr );
263+
const PlayingAudio *findActiveMusic( const AsciiString* trackName = nullptr ) const;
264+
265265
void stopAllAudioImmediately();
266266
void freeAllMilesHandles();
267267

@@ -272,7 +272,6 @@ class MilesAudioManager : public AudioManager
272272

273273
void stopAllSpeech();
274274

275-
protected:
276275
void initFilters( HSAMPLE sample, AudioEventRTS *eventInfo );
277276
void initFilters3D( H3DSAMPLE sample, AudioEventRTS *eventInfo, const Coord3D *pos );
278277

@@ -298,23 +297,16 @@ class MilesAudioManager : public AudioManager
298297
std::list<HSAMPLE> m_availableSamples;
299298
std::list<H3DSAMPLE> m_available3DSamples;
300299

301-
// Currently Playing stuff. Useful if we have to preempt it.
300+
// Currently Playing audio. Useful if we have to preempt it.
302301
// This should rarely if ever happen, as we mirror this in Sounds, and attempt to
303302
// keep preemption from taking place here.
304303
std::list<PlayingAudio *> m_playingSounds;
305304
std::list<PlayingAudio *> m_playing3DSounds;
306305
std::list<PlayingAudio *> m_playingStreams;
307306

308-
// Currently fading stuff. At this point, we just want to let it finish fading, when it is
309-
// done it should be added to the completed list, then "freed" and the counts should be updated
310-
// on the next update
307+
// Currently fading music. We just let it finish fading, then release it.
311308
std::list<PlayingAudio *> m_fadingAudio;
312309

313-
// Stuff that is done playing (either because it has finished or because it was killed)
314-
// This stuff should be cleaned up during the next update cycle. This includes updating counts
315-
// in the sound engine
316-
std::list<PlayingAudio *> m_stoppedAudio;
317-
318310
AudioFileCache *m_audioCache;
319311
PlayingAudio *m_binkHandle;
320312
UnsignedInt m_num2DSamples;
@@ -343,17 +335,16 @@ class MilesAudioManagerDummy : public MilesAudioManager
343335
virtual void resumeAudio(AudioAffect which) override {}
344336
virtual void pauseAmbient(Bool shouldPause) override {}
345337
virtual void killAudioEventImmediately(AudioHandle audioEvent) override {}
346-
virtual void nextMusicTrack() override {}
347-
virtual void prevMusicTrack() override {}
338+
virtual AsciiString nextMusicTrack() override { return AsciiString::TheEmptyString; }
339+
virtual AsciiString prevMusicTrack() override { return AsciiString::TheEmptyString; }
348340
virtual Bool isMusicPlaying() const override { return false; }
349341
virtual Bool hasMusicTrackCompleted(const AsciiString& trackName, Int numberOfTimes) const override { return false; }
350-
virtual AsciiString getMusicTrackName() const override { return ""; }
351342
//virtual void openDevice() override {}
352343
//virtual void closeDevice() override {}
353344
//virtual void* getDevice() override { return nullptr; }
354345
virtual void notifyOfAudioCompletion(UnsignedInt audioCompleted, UnsignedInt flags) override {}
355346
virtual UnsignedInt getProviderCount() const override { return 0; };
356-
virtual AsciiString getProviderName(UnsignedInt providerNum) const override { return ""; }
347+
virtual AsciiString getProviderName(UnsignedInt providerNum) const override { return AsciiString::TheEmptyString; }
357348
virtual UnsignedInt getProviderIndex(AsciiString providerName) const override { return 0; }
358349
virtual void selectProvider(UnsignedInt providerNdx) override {}
359350
virtual void unselectProvider() override {}

0 commit comments

Comments
 (0)