1 /* GemRB - Infinity Engine Emulator
2  * Copyright (C) 2003-2004 The GemRB Project
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  *
19  */
20 
21 #ifndef AUDIO_H_INCLUDED
22 #define AUDIO_H_INCLUDED
23 
24 #include <vector>
25 
26 #include "globals.h"
27 
28 #include "Plugin.h"
29 #include "Holder.h"
30 
31 namespace GemRB {
32 
33 #define GEM_SND_RELATIVE 1
34 #define GEM_SND_LOOPING 2
35 #define GEM_SND_SPEECH   IE_STR_SPEECH // 4
36 #define GEM_SND_QUEUE	8
37 
38 #define GEM_SND_VOL_MUSIC    1
39 #define GEM_SND_VOL_AMBIENTS 2
40 
41 #define SFX_CHAN_NARRATOR	0
42 #define SFX_CHAN_AREA_AMB	1
43 #define SFX_CHAN_ACTIONS	2
44 #define SFX_CHAN_SWINGS		3
45 #define SFX_CHAN_CASTING	4
46 #define SFX_CHAN_GUI		5
47 #define SFX_CHAN_DIALOG		6
48 #define SFX_CHAN_CHAR0		7
49 #define SFX_CHAN_CHAR1		8
50 #define SFX_CHAN_CHAR2		9
51 #define SFX_CHAN_CHAR3		10
52 #define SFX_CHAN_CHAR4		11
53 #define SFX_CHAN_CHAR5		12
54 #define SFX_CHAN_CHAR6		13
55 #define SFX_CHAN_CHAR7		14
56 #define SFX_CHAN_CHAR8		15
57 #define SFX_CHAN_CHAR9		16
58 #define SFX_CHAN_MONSTER	17
59 #define SFX_CHAN_HITS		18
60 #define SFX_CHAN_MISSILE	19
61 #define SFX_CHAN_AMB_LOOP	20
62 #define SFX_CHAN_AMB_OTHER 	21
63 #define SFX_CHAN_WALK_CHAR 	22
64 #define SFX_CHAN_WALK_MONSTER 23
65 #define SFX_CHAN_ARMOR		24
66 
67 class AmbientMgr;
68 class SoundMgr;
69 class MapReverb;
70 
71 class GEM_EXPORT SoundHandle : public Held<SoundHandle> {
72 public:
73 	virtual bool Playing() = 0;
74 	virtual void SetPos(int XPos, int YPos) = 0;
75 	virtual void Stop() = 0;
76 	virtual void StopLooping() = 0;
77 	~SoundHandle() override;
78 };
79 
80 class GEM_EXPORT Channel {
81 public:
Channel(const char * label)82 	Channel(const char *label) : volume(100), reverb(0.0f)
83 		{ strlcpy(name, label, sizeof(name)); }
~Channel()84 	~Channel() {}
85 
getName()86 	const char *getName() const { return name; }
getVolume()87 	int getVolume() const { return volume; }
setVolume(int vol)88 	void setVolume(int vol) { volume = vol; }
getReverb()89 	float getReverb() const { return reverb; }
setReverb(float r)90 	void setReverb(float r) { reverb = r; }
91 
92 private:
93 	char name[10];
94 	int volume; // 1-100
95 	float reverb;
96 };
97 
98 class GEM_EXPORT Audio : public Plugin {
99 public:
100 	static const TypeID ID;
101 public:
102 	Audio(void);
103 	~Audio() override;
104 	virtual bool Init(void) = 0;
105 	virtual Holder<SoundHandle> Play(const char* ResRef, unsigned int channel,
106 				int XPos, int YPos, unsigned int flags = 0, unsigned int *length = 0) = 0;
107 	virtual Holder<SoundHandle> Play(const char* ResRef, unsigned int channel, unsigned int *length = 0)
108 			{ return Play(ResRef, channel, 0, 0, GEM_SND_RELATIVE, length); }
GetAmbientMgr()109 	virtual AmbientMgr* GetAmbientMgr() { return ambim; }
110 	virtual void UpdateVolume(unsigned int flags = GEM_SND_VOL_MUSIC | GEM_SND_VOL_AMBIENTS) = 0;
111 	virtual bool CanPlay() = 0;
112 	virtual void ResetMusics() = 0;
113 	virtual bool Play() = 0;
114 	virtual bool Stop() = 0;
115 	virtual bool Pause() = 0;
116 	virtual bool Resume() = 0;
117 	virtual int CreateStream(Holder<SoundMgr>) = 0;
118 	virtual void UpdateListenerPos(int XPos, int YPos ) = 0;
119 	virtual void GetListenerPos(int &XPos, int &YPos ) = 0;
120 	virtual bool ReleaseStream(int stream, bool HardStop=false ) = 0;
121 	virtual int SetupNewStream( ieWord x, ieWord y, ieWord z,
122 				ieWord gain, bool point, int ambientRange) = 0;
123 	virtual int QueueAmbient(int stream, const char* sound) = 0;
124 	virtual void SetAmbientStreamVolume(int stream, int volume) = 0;
125 	virtual void SetAmbientStreamPitch(int stream, int pitch) = 0;
126 	virtual void QueueBuffer(int stream, unsigned short bits,
127 				int channels, short* memory, int size, int samplerate) = 0;
UpdateMapAmbient(MapReverb &)128 	virtual void UpdateMapAmbient(MapReverb&) {};
129 
130 	unsigned int CreateChannel(const char *name);
131 	void SetChannelVolume(const char *name, int volume);
132 	void SetChannelReverb(const char *name, float reverb);
133 	unsigned int GetChannel(const char *name) const;
134 	int GetVolume(unsigned int channel) const;
135 	float GetReverb(unsigned int channel) const;
136 protected:
137 	AmbientMgr* ambim;
138 	std::vector<Channel> channels;
139 };
140 
141 }
142 
143 #endif // AUDIO_H_INCLUDED
144