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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
/*
* This code is based on Broken Sword 2.5 engine
*
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
*
* Licensed under GNU GPL v2
*
*/
/*
* BS_SoundEngine
* -------------
* This is the sound engine interface that contains all the methods a sound
* engine must implement.
* Implementations of the sound engine have to be derived from this class.
* It should be noted that a sound engine must maintain a list of all the
* samples it uses, and that these samples should be released when the
* destructor is called.
*
* Autor: Malte Thiesen
*/
#ifndef SWORD25_SOUNDENGINE_H
#define SWORD25_SOUNDENGINE_H
// -----------------------------------------------------------------------------
// Includes
// -----------------------------------------------------------------------------
#include "sword25/kernel/common.h"
#include "sword25/kernel/resservice.h"
#include "sword25/kernel/persistable.h"
namespace Sword25 {
// -----------------------------------------------------------------------------
// Class definitions
// -----------------------------------------------------------------------------
class SoundEngine : public ResourceService, public Persistable {
public:
// -----------------------------------------------------------------------------
// Enums and Types
// -----------------------------------------------------------------------------
enum SOUND_TYPES {
MUSIC = 0,
SPEECH = 1,
SFX = 2
};
/**
* The callback function of PlayDynamicSoundEx
* @param UserData User-specified pointer
* @param Data Pointer to the data buffer
* @param DataLength Length of the data to be written in bytes
*/
typedef void (*DynamicSoundReadCallback)(void *UserData, void *Data, unsigned int DataLength);
// -----------------------------------------------------------------------------
// Constructor / destructor
// -----------------------------------------------------------------------------
SoundEngine(Kernel *pKernel);
virtual ~SoundEngine() {};
// --------------------------------------------------------------
// THIS METHOD MUST BE IMPLEMENTED BY THE SOUND ENGINE
// --------------------------------------------------------------
/**
* Initialises the sound engine
* @param SampleRate Specifies the sample rate to use.
* @param Channels The maximum number of channels. The default is 32.
* @return Returns true on success, otherwise false.
* @remark Calls to other methods may take place only if this
* method was called successfully.
*/
virtual bool Init(unsigned int SampleRate, unsigned int Channels = 32) = 0;
/**
* Performs a "tick" of the sound engine
*
* This method should be called once per frame. It can be used by implementations
* of the sound engine that are not running in their own thread, or to perform
* additional administrative tasks that are needed.
*/
virtual void Update() = 0;
/**
* Sets the default volume for the different sound types
* @param Volume The default volume level (0 = off, 1 = full volume)
* @param Type The SoundType whose volume is to be changed
*/
virtual void SetVolume(float Volume, SOUND_TYPES Type) = 0;
/**
* Specifies the default volume of different sound types
* @param Type The SoundType
* @return Returns the standard sound volume for the given type
* (0 = off, 1 = full volume).
*/
virtual float GetVolume(SOUND_TYPES Type) = 0;
/**
* Pauses all the sounds that are playing.
*/
virtual void PauseAll() = 0;
/**
* Resumes all currently stopped sounds
*/
virtual void ResumeAll() = 0;
/**
* Pauses all sounds of a given layer.
* @param Layer The Sound Layer
*/
virtual void PauseLayer(unsigned int Layer) = 0;
/**
* Resumes all the sounds in a layer that was previously stopped with PauseLayer()
* @param Layer The Sound Layer
*/
virtual void ResumeLayer(unsigned int Layer) = 0;
/**
* Plays a sound
* @param FileName The filename of the sound to be played
* @param Type The type of sound
* @param Volume The volume of the sound (0 = off, 1 = full volume)
* @param Pan Panning (-1 = full left, 1 = right)
* @param Loop Indicates whether the sound should be looped
* @param LoopStart Indicates the starting loop point. If a value less than 0 is passed, the start
* of the sound is used.
* @param LoopEnd Indicates the ending loop point. If a avlue is passed less than 0, the end of
* the sound is used.
* @param Layer The sound layer
* @return Returns true if the playback of the sound was started successfully.
* @remark If more control is needed over the playing, eg. changing the sound parameters
* for Volume and Panning, then PlaySoundEx should be used.
*/
virtual bool PlaySound(const Common::String &FileName, SOUND_TYPES Type, float Volume = 1.0f, float Pan = 0.0f, bool Loop = false, int LoopStart = -1, int LoopEnd = -1, unsigned int Layer = 0) = 0;
/**
* Plays a sound
* @param Type The type of sound
* @param Volume The volume of the sound (0 = off, 1 = full volume)
* @param Pan Panning (-1 = full left, 1 = right)
* @param Loop Indicates whether the sound should be looped
* @param LoopStart Indicates the starting loop point. If a value less than 0 is passed, the start
* of the sound is used.
* @param LoopEnd Indicates the ending loop point. If a avlue is passed less than 0, the end of
* the sound is used.
* @param Layer The sound layer
* @return Returns a handle to the sound. With this handle, the sound can be manipulated during playback.
* @remark If more control is needed over the playing, eg. changing the sound parameters
* for Volume and Panning, then PlaySoundEx should be used.
*/
virtual unsigned int PlaySoundEx(const Common::String &FileName, SOUND_TYPES Type, float Volume = 1.0f, float Pan = 0.0f, bool Loop = false, int LoopStart = -1, int LoopEnd = -1, unsigned int Layer = 0) = 0;
/**
* Plays a sound generated at runtime
* @param ReadCallback A pointer to a callback function that is called when sound data is needed.
* See the documentation for DynamicSoundReadCallback for more information.
* @param UserData A pointer to the data. These are passed to the callback function each time.
* If no such data is needed, this parameter can be set to NULL.
* @param Type The type of sound
* @param SampleRate The sample rate for the sound
* @param BitsPerSample The size of the sample in bits. This statement is independant of the number of
* channels. Allowed values are 8, 16, 24, and 32.
* @param Channels The number of channels. Allowed values are 1 and 2.
* @param Volume The volume of the sound (0 = off, 1 = full volume)
* @param Pan Panning (-1 = full left, 1 = right)
* @param Layer The sound layer
* @return Returns a handle to the sound. With this handle, the sound can be manipulated during playback.
* @remark Dynamic sounds cannot be persisted.
*/
virtual unsigned int PlayDynamicSoundEx(DynamicSoundReadCallback ReadCallback, void *UserData, SOUND_TYPES Type, unsigned int SampleRate, unsigned int BitsPerSample, unsigned int Channels, float Volume = 1.0f, float Pan = 0.0f, unsigned int Layer = 0) = 0;
/**
* Sets the volume of a playing sound
* @param Handle The sound handle
* @param Volume The volume of the sound (0 = off, 1 = full volume)
*/
virtual void SetSoundVolume(unsigned int Handle, float Volume) = 0;
/**
* Sets the panning of a playing sound
* @param Handle The sound handle
* @param Pan Panning (-1 = full left, 1 = right)
*/
virtual void SetSoundPanning(unsigned int Handle, float Pan) = 0;
/**
* Pauses a playing sound
* @param Handle The sound handle
*/
virtual void PauseSound(unsigned int Handle) = 0;
/**
* Resumes a paused sound
* @param Handle The sound handle
*/
virtual void ResumeSound(unsigned int Handle) = 0;
/**
* Stops a playing sound
* @param Handle The sound handle
* @remark Calling this method invalidates the passed handle; it can no longer be used.
*/
virtual void StopSound(unsigned int Handle) = 0;
/**
* Returns whether a sound is paused
* @param Handle The sound handle
* @return Returns true if the sound is paused, false otherwise.
*/
virtual bool IsSoundPaused(unsigned int Handle) = 0;
/**
* Returns whether a sound is still playing.
* @param Handle The sound handle
* @return Returns true if the sound is playing, false otherwise.
*/
virtual bool IsSoundPlaying(unsigned int Handle) = 0;
/**
* Returns the volume of a playing sound (0 = off, 1 = full volume)
*/
virtual float GetSoundVolume(unsigned int Handle) = 0;
/**
* Returns the panning of a playing sound (-1 = full left, 1 = right)
*/
virtual float GetSoundPanning(unsigned int Handle) = 0;
/**
* Returns the position within a playing sound in seconds
*/
virtual float GetSoundTime(unsigned int Handle) = 0;
private:
bool _RegisterScriptBindings();
};
} // End of namespace Sword25
#endif
|