-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleAudio.h
63 lines (48 loc) · 1.65 KB
/
ModuleAudio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef __MODULE_AUDIO_H__
#define __MODULE_AUDIO_H__
#include "Module.h"
#define DEFAULT_MUSIC_FADE_TIME 2.0f
#define MAX_FX 200
struct _Mix_Music;
struct Mix_Chunk;
typedef struct _Mix_Music Mix_Music;
class ModuleAudio : public Module
{
public:
//Constructor
ModuleAudio(bool startEnabled);
//Destructor
~ModuleAudio();
// Called on application start.
// Initializes the SDL audio subsystem and SDL Mixer
bool Init();
// Called on application exit.
// Frees the memory from all stored audio fx and music
// Uninitializes the SDL_Mixer library
bool CleanUp();
// Plays a new music file from a file path
// First loads the music file into the Mix_Music structure
// Then plays the music indefinetely
// Mix_Music* music is used for handling the current playing music
bool PlayMusic(const char* path, float fade_time = DEFAULT_MUSIC_FADE_TIME);
bool MuteMusic();
bool StopMusic();// Loads a sound fx (WAV) file in memory
// Returns an index to the sound fx array
// The index will be used to handle the effect (see PlayFx)
uint LoadFx(const char* path);
// Plays a previously loaded WAV
// Receives an index from the sound fx array
bool PlayFx(uint index, int repeat = 0);
// Removes the memory from the audio stored at index position
bool UnloadFx(uint index);
inline uint GetFxCount() const { return fxCount; };
private:
// The current playing music
Mix_Music* music = nullptr;
// An array of all the loaded sound effects
// Allows us to keep track of all sound fx and handle them through indices
Mix_Chunk* soundFx[MAX_FX] = { nullptr };
// The amount of audio Fx loaded into the array
uint fxCount = 0;
};
#endif // __MODULE_AUDIO_H__