ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
soundengine.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on Broken Sword 2.5 engine
24  *
25  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
26  *
27  * Licensed under GNU GPL v2
28  *
29  */
30 
31 /*
32  * BS_SoundEngine
33  * -------------
34  * This is the sound engine interface that contains all the methods a sound
35  * engine must implement.
36  * Implementations of the sound engine have to be derived from this class.
37  * It should be noted that a sound engine must maintain a list of all the
38  * samples it uses, and that these samples should be released when the
39  * destructor is called.
40  *
41  * Autor: Malte Thiesen
42  */
43 
44 #ifndef SWORD25_SOUNDENGINE_H
45 #define SWORD25_SOUNDENGINE_H
46 
47 #include "sword25/kernel/common.h"
48 #include "sword25/kernel/resservice.h"
49 #include "sword25/kernel/persistable.h"
50 
51 #include "audio/mixer.h"
52 
53 namespace Sword25 {
54 
55 #define SOUND_HANDLES 32
56 
57 enum sndHandleType {
58  kFreeHandle,
59  kAllocatedHandle
60 };
61 
62 struct SndHandle {
63  Audio::SoundHandle handle;
64  sndHandleType type;
65  uint32 id;
66 
67  Common::String fileName;
68  int32 sndType;
69  float volume;
70  float pan;
71  bool loop;
72  int32 loopStart;
73  int32 loopEnd;
74  uint32 layer;
75 
76  SndHandle();
77 };
78 
79 
80 class SoundEngine : public ResourceService, public Persistable {
81 public:
82  enum SOUND_TYPES {
83  MUSIC = 0,
84  SPEECH = 1,
85  SFX = 2
86  };
87 
94  typedef void (*DynamicSoundReadCallback)(void *UserData, void *Data, uint DataLength);
95 
96  SoundEngine(Kernel *pKernel);
97  ~SoundEngine() override {}
98 
107  bool init(uint sampleRate, uint channels = 32);
108 
116  void update();
117 
123  void setVolume(float volume, SOUND_TYPES type);
124 
131  float getVolume(SOUND_TYPES type);
132 
136  void pauseAll();
137 
141  void resumeAll();
142 
147  void pauseLayer(uint layer);
148 
153  void resumeLayer(uint layer);
154 
171  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, uint layer = 0);
172 
188  uint 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, uint layer = 0, uint handleId = 0x1337);
189 
195  void setSoundVolume(uint handle, float volume);
196 
202  void setSoundPanning(uint handle, float pan);
203 
208  void pauseSound(uint handle);
209 
214  void resumeSound(uint handle);
215 
221  void stopSound(uint handle);
222 
228  bool isSoundPaused(uint handle);
229 
235  bool isSoundPlaying(uint handle);
236 
240  float getSoundVolume(uint handle);
241 
245  float getSoundPanning(uint handle);
246 
247  Resource *loadResource(const Common::String &fileName) override;
248  bool canLoadResource(const Common::String &fileName) override;
249 
250  bool persist(OutputPersistenceBlock &writer) override;
251  bool unpersist(InputPersistenceBlock &reader) override;
252 
253 private:
254  bool registerScriptBindings();
255  SndHandle *getHandle(uint *id);
256  SndHandle *findHandle(uint id);
257 
258 private:
259  Audio::Mixer *_mixer;
260  SndHandle _handles[SOUND_HANDLES];
261 
262  uint32 _maxHandleId;
263 
264  bool _noMusic;
265 };
266 
267 } // End of namespace Sword25
268 
269 #endif
Definition: str.h:59
Definition: soundengine.h:80
Definition: resource.h:43
Definition: persistable.h:39
Definition: mixer.h:49
Definition: console.h:27
Definition: mixer.h:59
Definition: kernel.h:72
Definition: resservice.h:43
Definition: soundengine.h:62
Definition: inputpersistenceblock.h:40
Definition: outputpersistenceblock.h:39