1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef _I_SOUND_H_
4 #define _I_SOUND_H_
5 
6 #include <string>
7 
8 class float3;
9 class CSoundSource;
10 class SoundItem;
11 
12 
13 /**
14  * @brief sound system interface
15  * This is used in other parts of the engine, whenever sound should be played.
16  */
17 class ISound {
18 	static ISound* singleton;
19 
20 public:
21 	ISound();
~ISound()22 	virtual ~ISound() {};
23 
24 	static void Initialize();
25 	static void Shutdown();
26 	static bool IsInitialized();
GetInstance()27 	static inline ISound* GetInstance() {
28 		return singleton;
29 	}
30 
31 	virtual bool HasSoundItem(const std::string& name) const = 0;
32 	virtual size_t GetSoundId(const std::string& name) = 0;
33 	virtual SoundItem* GetSoundItem(size_t id) const = 0;
34 
35 	/**
36 	 * Returns a free sound source if available,
37 	 * the one with the lowest priority otherwise.
38 	 */
39 	virtual CSoundSource* GetNextBestSource(bool lock = true) = 0;
40 
41 	virtual void UpdateListener(const float3& camPos, const float3& camDir, const float3& camUp, float lastFrameTime) = 0;
42 	virtual void NewFrame() = 0;
43 
44 	virtual void ConfigNotify(const std::string& key, const std::string& value) = 0;
45 	virtual void PitchAdjust(const float newPitch) = 0;
46 
47 	/// @return true if now muted, false otherwise
48 	virtual bool Mute() = 0;
49 	virtual bool IsMuted() const = 0;
50 
51 	///change current output device
52 	static bool ChangeOutput();
53 
54 	virtual void Iconified(bool state) = 0;
55 
56 	virtual void PrintDebugInfo() = 0;
57 	bool LoadSoundDefs(const std::string& fileName);
58 
59 	virtual const float3& GetListenerPos() const = 0;
60 
61 public:
62 	unsigned numEmptyPlayRequests;
63 	unsigned numAbortedPlays;
64 private:
65 	virtual bool LoadSoundDefsImpl(const std::string& fileName) = 0;
66 	static bool IsNullAudio();
67 };
68 
69 #define sound ISound::GetInstance()
70 
71 #endif // _I_SOUND_H_
72