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 #include "bagel/boflib/gui/window.h"
33 
34 namespace Bagel {
35 
36 
37 //
38 // Wavemix-related constants
39 //
40 #define VOLUME_INDEX_MIN 0
41 #define VOLUME_INDEX_MAX 12
42 #define VOLUME_INDEX_DEFAULT 10
43 
44 // Convert to ScummVM scale
45 #define VOLUME_SVM(x) ((x) * Audio::Mixer::kMaxChannelVolume / VOLUME_INDEX_MAX)
46 #define SVM_VOLUME(x) (((x) >= 252) ? VOLUME_INDEX_MAX : (x) * VOLUME_INDEX_MAX / 252)
47 
48 #define SOUND_BUFFERED 0x0001
49 #define SOUND_ASYNCH 0x0002
50 #define SOUND_NOTIFY 0x0004
51 #define SOUND_AUTODELETE 0x0008
52 #define SOUND_LOOP 0x0010
53 #define SOUND_WAVE 0x0020
54 #define SOUND_MIDI 0x0040
55 #define SOUND_DONT_LOOP_TO_END 0x0080
56 #define SOUND_QUEUE 0x0100 // With wavemix: play after previous sound finishes
57 #define SOUND_MIX 0x0200 // Use wavemix to really play asynchronously
58 #define SOUND_ASAP 0x0400 // Play as soon as a channel is free (maybe now)
59 #define SOUND_WAIT 0x0800 // For wavemix: Set sound up but don't play it yet
60 #define SOUND_LOCK 0x1000 // Reserve this channel until user stops it
61 #define SOUND_PRELOAD 0x2000 // Only works for Resource MAC snd files
62 #define SOUND_OVEROK 0x4000 // OK to play another sound over this file
63 
64 #define SOUND_TYPE_WAV 1
65 #define SOUND_TYPE_XM 2
66 #define SOUND_TYPE_QT 3
67 
68 #define FMT_MILLISEC 1 // Time format specifiers.
69 #define FMT_BPM 2
70 
71 #define NUM_QUEUES 8
72 
73 class CBofSound : public CBofError, public CBofObject, public CLList {
74 public:
75  friend class MusicPlayer;
76 
77  CBofSound(CBofWindow *pWnd, const char *pszPathName, uint16 wFlags, int nLoops = 1);
78  virtual ~CBofSound();
79 
80  bool midiLoopPlaySegment(uint32 LoopBegin, uint32 LoopEnd = 0L, uint32 FirstPassBegin = 0L, uint32 TimeFmt = FMT_MILLISEC);
81  bool play(uint32 StartOfPlay = 0L, uint32 TimeFmtFlag = FMT_MILLISEC);
82  bool pause();
83  bool resume();
84  void stop();
85 
86  CBofSound *getNext() {
87  return (CBofSound *)_pNext;
88  }
89  CBofSound *getPrev() {
90  return (CBofSound *)_pPrev;
91  }
92 
93  char *getFileName() {
94  return &_szFileName[0];
95  }
96 
97  void setFlags(uint16 wFlags) {
98  _wFlags = wFlags;
99  }
100  uint16 getFlags() {
101  return _wFlags;
102  }
103 
104  bool playing() {
105  return isPlaying();
106  }
107 
108  bool isPlaying() {
109  return _bPlaying;
110  }
111  bool isQueued() {
112  return _bInQueue;
113  }
114 
115  bool paused() {
116  return _bPaused;
117  }
118 
119  void setQSlot(int nSlot) {
120  _iQSlot = nSlot;
121  }
122  int getQSlot() {
123  return _iQSlot;
124  }
125 
126  void setVolume(int nVol);
127  int getVolume() {
128  return _nVol;
129  }
130 
131  static void initialize();
132  static void shutdown();
133  static void setVolume(int MidiVolume, int WaveVolume);
134 
135  static bool soundPlaying() {
136  return (_nCount > 0) ? true : false;
137  }
138 
139  static bool waveSoundPlaying();
140  static bool midiSoundPlaying();
141  static bool soundsPlayingNotOver();
142 
143  static void setQVol(int nSlot, int nVol);
144 
145  ErrorCode playWAV();
146 
147  static ErrorCode flushQueue(int nSlot);
148 
149  static void resetQVolumes();
150 
151  static bool pauseSounds();
152  static bool resumeSounds();
153  static void stopSounds();
154  static void stopWaveSounds();
155  static void stopMidiSounds();
156  static void clearSounds();
157  static void clearWaveSounds();
158  static void clearMidiSounds();
159  static void waitSounds();
160  static void waitWaveSounds();
161  static void waitMidiSounds();
162  static bool handleMessages();
163  static bool bofSleep(uint32 dwTime);
164  static void audioTask();
165  static bool soundsPlaying();
166 
167 private:
168  bool loadSound();
169  bool releaseSound();
170 
171 private:
172  char _szFileName[MAX_FNAME]; // Path spec for sound file
173  int8 _chType = 0; // Type of sound commands used
174 
175  uint16 _wLoops = 0; // Number of times to loop the sound (0xFFFF means infinite)
176  uint16 _wFlags = 0; // Flags for playing
177  bool _bPaused = false; // Whether its paused
178  bool _bPlaying = false; // Whether its playing
179 
180  bool _bExtensionsUsed = false;
181  uint32 _dwPlayStart = 0;
182  uint32 _dwRePlayStart = 0;
183  uint32 _dwRePlayEnd = 0;
184  Audio::SoundHandle _handle;
185  byte *_pFileBuf = nullptr;
186  uint32 _iFileSize = 0;
187 
188  int _iQSlot = 0;
189  bool _bInQueue = false;
190  bool _bStarted = false;
191  int _nVol = 0;
192 
193  CBofWindow *_pWnd = nullptr; // Parent window for messages
194 
195  static char _szDrivePath[MAX_DIRPATH]; // Path spec to drive
196  static CBofSound *_pSoundChain; // First item in chain or nullptr
197  static int _nCount; // Count of active sounds
198  static int _nWavCount; // Number of wave sound devices
199  static int _nMidiCount; // Number of midi sound devices
200  static bool _bSoundAvailable; // Whether wave sound is available
201  static bool _bMidiAvailable; // Whether midi sound is available
202  static bool _bWaveVolume; // Whether wave volume can be set
203  static bool _bMidiVolume; // Whether midi volume can be set
204  static CBofWindow *_pMainWnd; // Window for message processing
205  static bool _bInit;
206 
207  static int _nSlotVol[NUM_QUEUES];
208  static CQueue *_cQueue[NUM_QUEUES];
209 };
210 
211 bool BofPlaySound(const char *pszSoundFile, uint32 nFlags, int iQSlot = 0);
212 bool BofPlaySoundEx(const char *pszSoundFile, uint32 nFlags, int iQSlot = 0, bool bWait = false);
213 
214 // Support legacy code
215 #define CSound CBofSound
216 
217 } // namespace Bagel
218 
219 #endif
Definition: window.h:50
Definition: object.h:28
Definition: sound.h:73
Definition: mixer.h:49
Definition: error.h:50
Definition: bagel.h:31
Definition: music.h:30
Definition: queue.h:31
Definition: llist.h:31