25 #include "common/scummsys.h" 26 #include "common/mutex.h" 27 #include "common/queue.h" 28 #include "audio/mididrv.h" 29 #include "audio/mixer.h" 30 #include "common/list.h" 31 #include "tsage/saveload.h" 32 #include "tsage/core.h" 35 class QueuingAudioStream;
46 #define SOUND_ARR_SIZE 16 47 #define ROLAND_DRIVER_NUM 2 48 #define ADLIB_DRIVER_NUM 3 49 #define SBLASTER_DRIVER_NUM 4 50 #define GENERAL_MIDI_DRIVER_NUM 6 51 #define CALLBACKS_PER_SECOND 60 55 int _chunks[SOUND_ARR_SIZE];
56 int _voiceTypes[SOUND_ARR_SIZE];
59 enum SoundDriverStatus {SNDSTATUS_FAILED = 0, SNDSTATUS_DETECTED = 1, SNDSTATUS_SKIPPED = 2};
60 enum VoiceType {VOICETYPE_0 = 0, VOICETYPE_1 = 1};
65 SoundDriverStatus _status;
81 _regNum = regNum; _value = value;
88 int _minVersion, _maxVersion;
97 const Common::String &getShortDriverDescription() {
return _shortDescription; }
98 const Common::String &getLongDriverDescription() {
return _longDescription; }
100 virtual bool open() {
return true; }
101 virtual void close() {}
102 virtual bool reset() {
return true; }
103 virtual const GroupData *getGroupData() {
return NULL; }
104 virtual void installPatch(
const byte *data,
int size) {}
105 virtual void poll() {}
106 virtual void method6() {}
107 virtual int setMasterVolume(
int volume) {
return 0; }
108 virtual void proc16() {}
109 virtual void noteOff(
int channel,
int note) {}
110 virtual void noteOn(
int channel,
int note,
int velocity) {}
111 virtual void proc22(
int al, VoiceType voiceType,
int v3) {}
112 virtual void controlChange(
int channel,
int controller,
int value) {}
113 virtual void setProgram(
int channel,
int program) {}
114 virtual void setVolume1(
int channel,
int v2,
int v3,
int volume) {}
115 virtual void setPitchBlend(
int channel,
int pitchBlend) {}
116 virtual void playSound(
const byte *channelData,
int dataOffset,
int program,
int channel,
int v0,
int v1) {}
117 virtual void updateVoice(
int channel) {}
118 virtual void proc36() {}
119 virtual void proc38(
int channel,
int cmd,
int value) {}
120 virtual void setPitch(
int channel,
int pitchBlend) {}
121 virtual void proc42(
int channel,
int cmd,
int value,
int *v1,
int *v2) {}
164 VoiceType _voiceType;
178 int _ourSndResVersion, _ourDrvResVersion;
187 bool _driversDetected;
192 bool _soTimeIndexFlag;
198 void listenerSynchronize(
Serializer &s)
override;
199 virtual void postInit();
202 static void saveNotifier(
bool postFlag);
203 void saveNotifierProc(
bool postFlag);
204 static void loadNotifier(
bool postFlag);
205 void loadNotifierProc(
bool postFlag);
207 void installConfigDrivers();
210 void dumpDriverList();
212 bool isInstalled(
int driverNum)
const;
213 void unInstallDriver(
int driverNum);
214 void checkResVersion(
const byte *soundData);
215 int determineGroup(
const byte *soundData);
216 int extractPriority(
const byte *soundData);
217 int extractLoop(
const byte *soundData);
218 bool isOnPlayList(
Sound *sound);
219 void extractTrackInfo(
trackInfoStruct *trackInfo,
const byte *soundData,
int groupNum);
220 void addToSoundList(
Sound *sound);
221 void removeFromSoundList(
Sound *sound);
222 void addToPlayList(
Sound *sound);
223 void removeFromPlayList(
Sound *sound);
224 void rethinkVoiceTypes();
225 void updateSoundVol(
Sound *sound);
226 void updateSoundPri(
Sound *sound);
227 void updateSoundLoop(
Sound *sound);
228 void setMasterVol(
int volume);
229 int getMasterVol()
const;
230 void setPaused(
bool paused);
231 void loadSound(
int soundNum,
bool showErrors);
232 void unloadSound(
int soundNum);
237 static void sfTerminate();
238 static int sfDetermineGroup(
const byte *soundData);
239 static void sfAddToPlayList(
Sound *sound);
240 static void sfRemoveFromPlayList(
Sound *sound);
241 static bool sfIsOnPlayList(
Sound *sound);
242 static void sfRethinkSoundDrivers();
243 static void sfRethinkVoiceTypes();
244 static void sfUpdateVolume(
Sound *sound);
245 static void sfDereferenceAll();
246 static void sfUpdatePriority(
Sound *sound);
247 static void sfUpdateLoop(
Sound *sound);
248 static void sfSetMasterVol(
int volume);
249 static void sfExtractTrackInfo(
trackInfoStruct *trackInfo,
const byte *soundData,
int groupNum);
250 static void sfExtractGroupMask();
252 static void sfUnInstallDriver(
SoundDriver *driver);
253 static void sfInstallPatchBank(
SoundDriver *driver,
const byte *bankData);
254 static void sfDoAddToPlayList(
Sound *sound);
255 static bool sfDoRemoveFromPlayList(
Sound *sound);
256 static void sfDoUpdateVolume(
Sound *sound);
257 static void sfSoundServer(
void *);
258 static void sfProcessFading();
259 static void sfUpdateVoiceStructs();
260 static void sfUpdateVoiceStructs2();
265 void _prime(
int soundResID,
bool dontQueue);
266 void _primeBuffer(
const byte *soundData);
269 bool _stoppedAsynchronously;
287 bool _stopAfterFadeFlag;
289 uint32 _newTimeIndex;
291 int _chProgram[SOUND_ARR_SIZE];
292 int _chModulation[SOUND_ARR_SIZE];
293 int _chVolume[SOUND_ARR_SIZE];
294 int _chPan[SOUND_ARR_SIZE];
295 int _chDamper[SOUND_ARR_SIZE];
296 int _chPitchBlend[SOUND_ARR_SIZE];
297 int _chVoiceType[SOUND_ARR_SIZE];
298 int _chNumVoices[SOUND_ARR_SIZE];
299 int _chSubPriority[SOUND_ARR_SIZE];
300 int _chFlags[SOUND_ARR_SIZE];
301 bool _chWork[SOUND_ARR_SIZE];
303 byte *_channelData[SOUND_ARR_SIZE];
304 int _trkChannel[SOUND_ARR_SIZE];
305 int _trkState[SOUND_ARR_SIZE];
306 int _trkLoopState[SOUND_ARR_SIZE];
307 int _trkIndex[SOUND_ARR_SIZE];
308 int _trkLoopIndex[SOUND_ARR_SIZE];
309 int _trkRest[SOUND_ARR_SIZE];
310 int _trkLoopRest[SOUND_ARR_SIZE];
314 byte *_remoteReceiver;
320 void orientAfterRestore();
322 void play(
int soundResID);
324 void prime(
int soundResID);
329 int getSoundNum()
const;
330 bool isPrimed()
const;
331 bool isPaused()
const;
332 bool isMuted()
const;
333 void pause(
bool flag);
334 void mute(
bool flag);
335 void fade(
int fadeDest,
int fadeSteps,
int fadeTicks,
bool stopAfterFadeFlag);
336 void setTimeIndex(uint32 timeIndex);
337 uint32 getTimeIndex()
const;
338 int getCueValue()
const;
339 void setCueValue(
int cueValue);
340 void setVol(
int volume);
342 void setPri(
int priority);
343 void setLoop(
int flag);
346 void holdAt(
int amount);
348 void orientAfterDriverChange();
351 void soPrimeSound(
bool dontQueue);
352 void soSetTimeIndex(uint timeIndex);
353 bool soServiceTracks();
354 void soPrimeChannelData();
355 void soRemoteReceive();
356 void soServiceTrackType0(
int trackIndex,
const byte *channelData);
357 void soUpdateDamper(
VoiceTypeStruct *voiceType,
int channelNum, VoiceType mode,
int v0);
358 void soPlaySound(
VoiceTypeStruct *vtStruct,
const byte *channelData,
int channelNum, VoiceType voiceType,
int v0,
int v1);
359 void soPlaySound2(
VoiceTypeStruct *vtStruct,
const byte *channelData,
int channelNum, VoiceType voiceType,
int v0);
360 void soProc38(
VoiceTypeStruct *vtStruct,
int channelNum, VoiceType voiceType,
int cmd,
int value);
361 void soProc40(
VoiceTypeStruct *vtStruct,
int channelNum,
int pitchBlend);
362 void soDoTrackCommand(
int channelNum,
int command,
int value);
363 bool soDoUpdateTracks(
int command,
int value);
364 void soSetTrackPos(
int trackIndex,
int trackPos,
int cueValue);
366 void soServiceTrackType1(
int trackIndex,
const byte *channelData);
379 void dispatch()
override;
381 void play(
int soundNum,
EventHandler *endAction = NULL,
int volume = 127);
383 void prime(
int soundNum,
Action *action = NULL);
385 void go() { _sound.go(); }
386 void hault(
void) { _sound.halt(); }
387 bool isPlaying() {
return _sound.isPlaying(); }
388 int getSoundNum()
const {
return _sound.getSoundNum(); }
389 bool isPaused()
const {
return _sound.isPaused(); }
390 bool isMuted()
const {
return _sound.isMuted(); }
391 void pause(
bool flag) { _sound.pause(flag); }
392 void mute(
bool flag) { _sound.mute(flag); }
393 void fade(
int fadeDest,
int fadeSteps,
int fadeTicks,
bool stopAfterFadeFlag,
EventHandler *endAction);
394 void fadeIn() { fade(127, 5, 10,
false, NULL); }
395 void fadeOut(
Action *action) { fade(0, 5, 10,
true, action); }
396 void setTimeIndex(uint32 timeIndex) { _sound.setTimeIndex(timeIndex); }
397 uint32 getTimeIndex()
const {
return _sound.getTimeIndex(); }
398 void setPri(
int v) { _sound.setPri(v); }
399 void setLoop(
int total) { _sound.setLoop(total); }
400 int getPri()
const {
return _sound.getPri(); }
401 int getLoop() {
return _sound.getLoop(); }
402 void setVol(
int volume) { _sound.setVol(volume); }
403 int getVol()
const {
return _sound.getVol(); }
404 void holdAt(
int v) { _sound.holdAt(v); }
405 void release() { _sound.release(); }
406 void fadeSound(
int soundNum);
415 void changeSound(
int soundNum);
419 void signal()
override;
433 ResFileData _resData;
440 static uint32 getFileOffset(
const uint16 *data,
int count,
int voiceNum);
448 bool isPlaying()
const;
450 void remove()
override;
451 void dispatch()
override;
454 #define ADLIB_CHANNEL_COUNT 9 463 byte _modulation[SOUND_ARR_SIZE];
464 byte _channelVolume[SOUND_ARR_SIZE];
465 byte _pan[SOUND_ARR_SIZE];
466 byte _damper[SOUND_ARR_SIZE];
467 byte _program[SOUND_ARR_SIZE];
468 uint16 _pitchBlend[SOUND_ARR_SIZE];
469 bool _active[SOUND_ARR_SIZE];
471 void send(byte status, byte firstOp, byte secondOp);
472 void sendMt32SysEx(uint32 address,
const byte *data, uint16 size);
477 bool open()
override;
478 void close()
override;
479 const GroupData *getGroupData()
override;
480 void installPatch(
const byte *data,
int size)
override;
481 int setMasterVolume(
int volume)
override;
482 void noteOff(
int channel,
int note)
override;
483 void noteOn(
int channel,
int note,
int velocity)
override;
484 void controlChange(
int channel,
int controller,
int value)
override;
485 void setProgram(
int channel,
int program)
override;
486 void setPitchBlend(
int channel,
int pitchBlend)
override;
494 byte _portContents[256];
495 const byte *_patchData;
500 bool _channelVoiced[ADLIB_CHANNEL_COUNT];
501 int _channelVolume[ADLIB_CHANNEL_COUNT];
502 int _v4405E[ADLIB_CHANNEL_COUNT];
503 int _v44067[ADLIB_CHANNEL_COUNT];
504 int _v44070[ADLIB_CHANNEL_COUNT];
505 int _v44079[ADLIB_CHANNEL_COUNT];
506 int _v44082[ADLIB_CHANNEL_COUNT + 1];
507 int _pitchBlend[ADLIB_CHANNEL_COUNT];
508 int _v4409E[ADLIB_CHANNEL_COUNT];
511 void write(byte reg, byte value);
513 void updateChannelVolume(
int channel);
514 void setVoice(
int channel);
515 void clearVoice(
int channel);
516 void updateChannel(
int channel);
517 void setFrequency(
int channel);
522 bool open()
override;
523 void close()
override;
524 bool reset()
override;
525 const GroupData *getGroupData()
override;
526 void installPatch(
const byte *data,
int size)
override;
527 int setMasterVolume(
int volume)
override;
528 void playSound(
const byte *channelData,
int dataOffset,
int program,
int channel,
int v0,
int v1)
override;
529 void updateVoice(
int channel)
override;
530 void proc38(
int channel,
int cmd,
int value)
override;
531 void setPitch(
int channel,
int pitchBlend)
override;
546 byte getVolume()
const;
552 bool open()
override;
553 void close()
override;
554 bool reset()
override;
555 const GroupData *getGroupData()
override;
556 int setMasterVolume(
int volume)
override;
557 void playSound(
const byte *channelData,
int dataOffset,
int program,
int channel,
int v0,
int v1)
override;
558 void updateVoice(
int channel)
override;
559 void proc38(
int channel,
int cmd,
int value)
override;
560 void proc42(
int channel,
int cmd,
int value,
int *v1,
int *v2)
override;
uint32 DeviceHandle
Definition: mididrv.h:322
MusicType
Definition: mididrv.h:44
Definition: mididrv.h:313
Definition: saveload.h:115
Definition: blueforce_dialogs.h:30
Definition: saveload.h:63
Definition: audiostream.h:370
Definition: saveload.h:90