ScummVM API documentation
sound.h
1
2/* ScummVM - Graphic Adventure Engine
3 *
4 * ScummVM is the legal property of its developers, whose names
5 * are too numerous to list here. Please refer to the COPYRIGHT
6 * file distributed with this source distribution.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/".
20 *
21 */
22
23#ifndef BAGEL_BOFLIB_SOUND_H
24#define BAGEL_BOFLIB_SOUND_H
25
26#include "audio/mixer.h"
27#include "bagel/boflib/stdinc.h"
28#include "bagel/boflib/llist.h"
29#include "bagel/boflib/object.h"
30#include "bagel/boflib/error.h"
31#include "bagel/boflib/queue.h"
32
33namespace Bagel {
34
35//
36// Wavemix-related constants
37//
38#define VOLUME_INDEX_MIN 0
39#define VOLUME_INDEX_MAX 12
40#define VOLUME_INDEX_DEFAULT 10
41
42// Convert to ScummVM scale
43#define VOLUME_SVM(x) ((x) * Audio::Mixer::kMaxChannelVolume / VOLUME_INDEX_MAX)
44#define SVM_VOLUME(x) (((x) >= 252) ? VOLUME_INDEX_MAX : (x) * VOLUME_INDEX_MAX / 252)
45
46#define SOUND_BUFFERED 0x0001
47#define SOUND_ASYNCH 0x0002
48#define SOUND_NOTIFY 0x0004
49#define SOUND_AUTODELETE 0x0008
50#define SOUND_LOOP 0x0010
51#define SOUND_WAVE 0x0020
52#define SOUND_MIDI 0x0040
53#define SOUND_DONT_LOOP_TO_END 0x0080
54#define SOUND_QUEUE 0x0100 // With wavemix: play after previous sound finishes
55#define SOUND_MIX 0x0200 // Use wavemix to really play asynchronously
56#define SOUND_ASAP 0x0400 // Play as soon as a channel is free (maybe now)
57#define SOUND_WAIT 0x0800 // For wavemix: Set sound up but don't play it yet
58#define SOUND_LOCK 0x1000 // Reserve this channel until user stops it
59#define SOUND_PRELOAD 0x2000 // Only works for Resource MAC snd files
60#define SOUND_OVEROK 0x4000 // OK to play another sound over this file
61#define SND_MEMORY 0x8000 // Raw in-memory sound passed rather than a filename
62
63#define SND_NODEFAULT 0
64#define SND_SYNC 0
65#define SND_ASYNC SOUND_ASYNCH
66
67#define SOUND_TYPE_WAV 1
68#define SOUND_TYPE_XM 2
69#define SOUND_TYPE_QT 3
70#define SOUND_TYPE_SMF 4
71
72#define FMT_MILLISEC 1 // Time format specifiers.
73#define FMT_BPM 2
74
75#define NUM_QUEUES 8
76
77class CBofSound : public CBofError, public CBofObject, public CLList {
78public:
79 friend class MusicPlayer;
80
81 CBofSound();
82 CBofSound(void *pWnd, const char *pszPathName, uint16 wFlags, int nLoops = 1);
83 virtual ~CBofSound();
84 void addToSoundChain();
85
86 void initialize(const char *pszPathName, uint16 wFlags) {
87 initialize(nullptr, pszPathName, wFlags);
88 }
89 void initialize(void *pWnd, const char *pszPathName, uint16 wFlags);
90 void setDrivePath(const char *path) {}
91 bool midiLoopPlaySegment(uint32 LoopBegin, uint32 LoopEnd = 0L, uint32 FirstPassBegin = 0L, uint32 TimeFmt = FMT_MILLISEC);
92 bool play(uint32 StartOfPlay = 0L, uint32 TimeFmtFlag = FMT_MILLISEC);
93 bool pause();
94 bool resume();
95 void stop();
96
97 CBofSound *getNext() {
98 return (CBofSound *)_pNext;
99 }
100 CBofSound *getPrev() {
101 return (CBofSound *)_pPrev;
102 }
103
104 char *getFileName() {
105 return &_szFileName[0];
106 }
107
108 void setFlags(uint16 wFlags) {
109 _wFlags = wFlags;
110 }
111 uint16 getFlags() {
112 return _wFlags;
113 }
114
115 bool playing() {
116 return isPlaying();
117 }
118
119 bool isPlaying() {
120 return _bPlaying;
121 }
122 bool isQueued() {
123 return _bInQueue;
124 }
125
126 bool paused() {
127 return _bPaused;
128 }
129
130 void setQSlot(int nSlot) {
131 _iQSlot = nSlot;
132 }
133 int getQSlot() {
134 return _iQSlot;
135 }
136
137 void setVolume(int nVol);
138 int getVolume() {
139 return _nVol;
140 }
141
142 static void initialize();
143 static void shutdown();
144 static void setVolume(int MidiVolume, int WaveVolume);
145
146 static bool soundPlaying() {
147 return (_nCount > 0) ? true : false;
148 }
149
150 static bool waveSoundPlaying();
151 static bool midiSoundPlaying();
152 static bool soundsPlayingNotOver();
153
154 static void setQVol(int nSlot, int nVol);
155
156 ErrorCode playWAV();
157
158 static ErrorCode flushQueue(int nSlot);
159
160 static void resetQVolumes();
161
162 static bool pauseSounds();
163 static bool resumeSounds();
164 static void stopSounds();
165 static void stopWaveSounds();
166 static void stopMidiSounds();
167 static void clearSounds();
168 static void clearWaveSounds();
169 static void clearMidiSounds();
170 static void waitSounds();
171 static void waitWaveSounds();
172 static void waitMidiSounds();
173 static bool handleMessages();
174 static bool bofSleep(uint32 dwTime);
175 static void audioTask();
176 static bool soundsPlaying();
177 static bool MidiAvailable() {
178 return true;
179 }
180 static bool SoundAvailable() {
181 return true;
182 }
183 static bool SoundVolumeAvailable() {
184 return true;
185 }
186 static bool MidiVolumeAvailable() {
187 return true;
188 }
189
190 static CBofSound *OnMCIStopped(WPARAM wParam, LPARAM lParam) {
191 return nullptr;
192 }
193 static CBofSound *OnMMIOStopped(WPARAM wParam, LPARAM lParam) {
194 return nullptr;
195 }
196
197private:
198 bool loadSound();
199 bool releaseSound();
200
201private:
202 char _szFileName[MAX_FNAME]; // Path spec for sound file
203 int8 _chType = 0; // Type of sound commands used
204
205 uint16 _wLoops = 0; // Number of times to loop the sound (0xFFFF means infinite)
206 uint16 _wFlags = 0; // Flags for playing
207 bool _bPaused = false; // Whether its paused
208 bool _bPlaying = false; // Whether its playing
209
210 bool _bExtensionsUsed = false;
211 uint32 _dwPlayStart = 0;
212 uint32 _dwRePlayStart = 0;
213 uint32 _dwRePlayEnd = 0;
214 Audio::SoundHandle _handle;
215 byte *_pFileBuf = nullptr;
216 uint32 _iFileSize = 0;
217
218 int _iQSlot = 0;
219 bool _bInQueue = false;
220 bool _bStarted = false;
221 int _nVol = 0;
222
223 void *_pWnd = nullptr; // Parent window for messages
224
225 static char _szDrivePath[MAX_DIRPATH]; // Path spec to drive
226 static CBofSound *_pSoundChain; // First item in chain or nullptr
227 static int _nCount; // Count of active sounds
228 static int _nWavCount; // Number of wave sound devices
229 static int _nMidiCount; // Number of midi sound devices
230 static void *_pMainWnd; // Window for message processing
231 static bool _bInit;
232
233 static int _nSlotVol[NUM_QUEUES];
234 static CQueue *_cQueue[NUM_QUEUES];
235};
236
237#define CSound CBofSound
238
239extern bool BofPlaySound(const char *pszSoundFile, uint32 nFlags, int iQSlot = 0);
240extern bool BofPlaySoundEx(const char *pszSoundFile, uint32 nFlags, int iQSlot = 0, bool bWait = false);
241extern bool MessageBeep(int uType);
242
243#define sndPlaySound BofPlaySound
244
245} // namespace Bagel
246
247#endif
Definition: mixer.h:49
Definition: error.h:52
Definition: object.h:28
Definition: sound.h:77
Definition: llist.h:31
Definition: queue.h:31
Definition: music.h:30