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"
38#define VOLUME_INDEX_MIN 0
39#define VOLUME_INDEX_MAX 12
40#define VOLUME_INDEX_DEFAULT 10
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)
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
55#define SOUND_MIX 0x0200
56#define SOUND_ASAP 0x0400
57#define SOUND_WAIT 0x0800
58#define SOUND_LOCK 0x1000
59#define SOUND_PRELOAD 0x2000
60#define SOUND_OVEROK 0x4000
61#define SND_MEMORY 0x8000
63#define SND_NODEFAULT 0
65#define SND_ASYNC SOUND_ASYNCH
67#define SOUND_TYPE_WAV 1
68#define SOUND_TYPE_XM 2
69#define SOUND_TYPE_QT 3
70#define SOUND_TYPE_SMF 4
82 CBofSound(
void *pWnd,
const char *pszPathName, uint16 wFlags,
int nLoops = 1);
84 void addToSoundChain();
86 void initialize(
const char *pszPathName, uint16 wFlags) {
87 initialize(
nullptr, pszPathName, wFlags);
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);
104 char *getFileName() {
105 return &_szFileName[0];
108 void setFlags(uint16 wFlags) {
130 void setQSlot(
int nSlot) {
137 void setVolume(
int nVol);
142 static void initialize();
143 static void shutdown();
144 static void setVolume(
int MidiVolume,
int WaveVolume);
146 static bool soundPlaying() {
147 return (_nCount > 0) ? true :
false;
150 static bool waveSoundPlaying();
151 static bool midiSoundPlaying();
152 static bool soundsPlayingNotOver();
154 static void setQVol(
int nSlot,
int nVol);
158 static ErrorCode flushQueue(
int nSlot);
160 static void resetQVolumes();
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() {
180 static bool SoundAvailable() {
183 static bool SoundVolumeAvailable() {
186 static bool MidiVolumeAvailable() {
190 static CBofSound *OnMCIStopped(WPARAM wParam, LPARAM lParam) {
193 static CBofSound *OnMMIOStopped(WPARAM wParam, LPARAM lParam) {
202 char _szFileName[MAX_FNAME];
207 bool _bPaused =
false;
208 bool _bPlaying =
false;
210 bool _bExtensionsUsed =
false;
211 uint32 _dwPlayStart = 0;
212 uint32 _dwRePlayStart = 0;
213 uint32 _dwRePlayEnd = 0;
215 byte *_pFileBuf =
nullptr;
216 uint32 _iFileSize = 0;
219 bool _bInQueue =
false;
220 bool _bStarted =
false;
223 void *_pWnd =
nullptr;
225 static char _szDrivePath[MAX_DIRPATH];
228 static int _nWavCount;
229 static int _nMidiCount;
230 static void *_pMainWnd;
233 static int _nSlotVol[NUM_QUEUES];
234 static CQueue *_cQueue[NUM_QUEUES];
237#define CSound CBofSound
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);
243#define sndPlaySound BofPlaySound