23 #ifndef BAGEL_BOFLIB_SOUND_H 24 #define BAGEL_BOFLIB_SOUND_H 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" 40 #define VOLUME_INDEX_MIN 0 41 #define VOLUME_INDEX_MAX 12 42 #define VOLUME_INDEX_DEFAULT 10 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) 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 64 #define SOUND_TYPE_WAV 1 65 #define SOUND_TYPE_XM 2 66 #define SOUND_TYPE_QT 3 68 #define FMT_MILLISEC 1 // Time format specifiers. 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);
94 return &_szFileName[0];
97 void setFlags(uint16 wFlags) {
119 void setQSlot(
int nSlot) {
126 void setVolume(
int nVol);
131 static void initialize();
132 static void shutdown();
133 static void setVolume(
int MidiVolume,
int WaveVolume);
135 static bool soundPlaying() {
136 return (_nCount > 0) ? true :
false;
139 static bool waveSoundPlaying();
140 static bool midiSoundPlaying();
141 static bool soundsPlayingNotOver();
143 static void setQVol(
int nSlot,
int nVol);
147 static ErrorCode flushQueue(
int nSlot);
149 static void resetQVolumes();
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();
172 char _szFileName[MAX_FNAME];
177 bool _bPaused =
false;
178 bool _bPlaying =
false;
180 bool _bExtensionsUsed =
false;
181 uint32 _dwPlayStart = 0;
182 uint32 _dwRePlayStart = 0;
183 uint32 _dwRePlayEnd = 0;
185 byte *_pFileBuf =
nullptr;
186 uint32 _iFileSize = 0;
189 bool _bInQueue =
false;
190 bool _bStarted =
false;
195 static char _szDrivePath[MAX_DIRPATH];
198 static int _nWavCount;
199 static int _nMidiCount;
200 static bool _bSoundAvailable;
201 static bool _bMidiAvailable;
202 static bool _bWaveVolume;
203 static bool _bMidiVolume;
207 static int _nSlotVol[NUM_QUEUES];
208 static CQueue *_cQueue[NUM_QUEUES];
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);
215 #define CSound CBofSound