1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #if !defined(SCUMM_IMUSE_DIGI_H) && defined(ENABLE_SCUMM_7_8)
24 #define SCUMM_IMUSE_DIGI_H
25 
26 #include "common/scummsys.h"
27 #include "common/mutex.h"
28 #include "common/serializer.h"
29 #include "common/textconsole.h"
30 #include "common/util.h"
31 
32 #include "scumm/imuse_digi/dimuse.h"
33 #include "scumm/imuse_digi/dimuse_bndmgr.h"
34 #include "scumm/imuse_digi/dimuse_sndmgr.h"
35 #include "scumm/music.h"
36 #include "scumm/sound.h"
37 
38 namespace Audio {
39 class AudioStream;
40 class Mixer;
41 }
42 
43 namespace Scumm {
44 
45 enum {
46 	MAX_DIGITAL_TRACKS = 8,
47 	MAX_DIGITAL_FADETRACKS = 8
48 };
49 
50 struct imuseDigTable;
51 struct imuseComiTable;
52 class ScummEngine_v7;
53 struct Track;
54 
55 class IMuseDigital : public MusicEngine {
56 private:
57 
58 	int _callbackFps;		// value how many times callback needs to be called per second
59 
60 	struct TriggerParams {
61 		char marker[10];
62 		int fadeOutDelay;
63 		char filename[13];
64 		int soundId;
65 		int hookId;
66 		int volume;
67 	};
68 
69 	TriggerParams _triggerParams;
70 	bool _triggerUsed;
71 
72 	Track *_track[MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS];
73 
74 	Common::Mutex _mutex;
75 	ScummEngine_v7 *_vm;
76 	Audio::Mixer *_mixer;
77 	ImuseDigiSndMgr *_sound;
78 
79 	char *_audioNames;		// filenames of sound SFX used in FT
80 	int32 _numAudioNames;	// number of above filenames
81 
82 	bool _pause;			// flag mean that iMuse callback should be idle
83 
84 	int32 _attributes[188];	// internal attributes for each music file to store and check later
85 	int32 _nextSeqToPlay;	// id of sequence type of music needed played
86 	int32 _curMusicState;	// current or previous id of music
87 	int32 _curMusicSeq;		// current or previous id of sequence music
88 	int32 _curMusicCue;		// current cue for current music. used in FT
89 	int _stopingSequence;
90 	bool _radioChatterSFX;
91 
92 	static void timer_handler(void *refConf);
93 	void callback();
94 	void switchToNextRegion(Track *track);
95 	int allocSlot(int priority);
96 	void startSound(int soundId, const char *soundName, int soundType, int volGroupId, Audio::AudioStream *input, int hookId, int volume, int priority, Track *otherTrack);
97 	void selectVolumeGroup(int soundId, int volGroupId);
98 
99 	int32 getPosInMs(int soundId);
100 	void getLipSync(int soundId, int syncId, int32 msPos, int32 &width, int32 &height);
101 
102 	int getSoundIdByName(const char *soundName);
103 	void fadeOutMusic(int fadeDelay);
104 	void fadeOutMusicAndStartNew(int fadeDelay, const char *filename, int soundId);
105 	void setTrigger(TriggerParams *trigger);
106 	void setHookIdForMusic(int hookId);
107 	Track *cloneToFadeOutTrack(Track *track, int fadeDelay);
108 
109 	void setFtMusicState(int stateId);
110 	void setFtMusicSequence(int seqId);
111 	void setFtMusicCuePoint(int cueId);
112 	void playFtMusic(const char *songName, int opcode, int volume);
113 
114 	void setComiMusicState(int stateId);
115 	void setComiMusicSequence(int seqId);
116 	void playComiMusic(const char *songName, const imuseComiTable *table, int attribPos, bool sequence);
117 
118 	void setDigMusicState(int stateId);
119 	void setDigMusicSequence(int seqId);
120 	void playDigMusic(const char *songName, const imuseDigTable *table, int attribPos, bool sequence);
121 
122 	void flushTrack(Track *track);
123 
124 public:
125 	IMuseDigital(ScummEngine_v7 *scumm, Audio::Mixer *mixer, int fps);
126 	virtual ~IMuseDigital();
127 
128 	void setAudioNames(int32 num, char *names);
129 
130 	void startVoice(int soundId, Audio::AudioStream *input);
131 	void startVoice(int soundId, const char *soundName);
132 	void startMusic(int soundId, int volume);
133 	void startMusic(const char *soundName, int soundId, int hookId, int volume);
134 	void startMusicWithOtherPos(const char *soundName, int soundId, int hookId, int volume, Track *otherTrack);
135 	void startSfx(int soundId, int priority);
startSound(int sound)136 	void startSound(int sound)
137 		{ error("IMuseDigital::startSound(int) should be never called"); }
138 
139 	void saveLoadEarly(Common::Serializer &ser);
140 	void resetState();
setRadioChatterSFX(bool state)141 	void setRadioChatterSFX(bool state) {
142 		_radioChatterSFX = state;
143 	}
144 
145 	void setPriority(int soundId, int priority);
146 	void setVolume(int soundId, int volume);
147 	void setPan(int soundId, int pan);
148 	void setFade(int soundId, int destVolume, int delay60HzTicks);
149 	int getCurMusicSoundId();
150 	void setHookId(int soundId, int hookId);
setMusicVolume(int vol)151 	void setMusicVolume(int vol) {}
152 	void stopSound(int sound);
153 	void stopAllSounds();
154 	void pause(bool pause);
155 	void parseScriptCmds(int cmd, int soundId, int sub_cmd, int d, int e, int f, int g, int h);
156 	void refreshScripts();
157 	void flushTracks();
158 	int getSoundStatus(int sound) const;
159 	int32 getCurMusicPosInMs();
160 	int32 getCurVoiceLipSyncWidth();
161 	int32 getCurVoiceLipSyncHeight();
162 	int32 getCurMusicLipSyncWidth(int syncId);
163 	int32 getCurMusicLipSyncHeight(int syncId);
164 	int32 getSoundElapsedTimeInMs(int soundId);
165 };
166 
167 } // End of namespace Scumm
168 
169 #endif
170