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 #ifndef SCUMM_SOUND_H
24 #define SCUMM_SOUND_H
25 
26 #include "common/scummsys.h"
27 #include "common/serializer.h"
28 #include "common/str.h"
29 #include "audio/mididrv.h"
30 #include "backends/audiocd/audiocd.h"
31 
32 namespace Audio {
33 class Mixer;
34 class SoundHandle;
35 }
36 
37 namespace Scumm {
38 
39 class ScummEngine;
40 
41 struct MP3OffsetTable;
42 
43 enum {
44 	kTalkSoundID = 10000
45 };
46 
47 // TODO: Consider splitting Sound into even more subclasses.
48 // E.g. for v1-v4, v5, v6+, ...
49 class Sound : public Common::Serializable {
50 public:
51 	enum SoundMode {
52 		kVOCMode,
53 		kMP3Mode,
54 		kVorbisMode,
55 		kFLACMode
56 	};
57 
58 protected:
59 	ScummEngine *_vm;
60 	Audio::Mixer *_mixer;
61 
62 	int16 _soundQuePos, _soundQue[0x100];
63 	int16 _soundQue2Pos;
64 
65 	struct {
66 		int16 sound;
67 		int32 offset;
68 		int16 channel;
69 		int16 flags;
70 		int16 freq;
71 		int16 pan;
72 		int16 vol;
73 	} _soundQue2[10];
74 
75 	Common::String _sfxFilename;
76 	byte _sfxFileEncByte;
77 	SoundMode _soundMode;
78 	MP3OffsetTable *_offsetTable;	// For compressed audio
79 	int _numSoundEffects;		// For compressed audio
80 
81 	uint32 _talk_sound_a1, _talk_sound_a2, _talk_sound_b1, _talk_sound_b2;
82 	byte _talk_sound_mode, _talk_sound_channel;
83 	bool _mouthSyncMode;
84 	bool _endOfMouthSync;
85 	uint16 _mouthSyncTimes[64];
86 	uint _curSoundPos;
87 
88 	int16 _currentCDSound;
89 	int16 _currentMusic;
90 
91 	Audio::SoundHandle *_loomSteamCDAudioHandle;
92 	bool _isLoomSteam;
93 	AudioCDManager::Status _loomSteamCD;
94 
95 public:
96 	Audio::SoundHandle *_talkChannelHandle;	// Handle of mixer channel actor is talking on
97 
98 	bool _soundsPaused;
99 	byte _sfxMode;
100 	uint _lastSound;
101 
102 	MidiDriverFlags _musicType;
103 
104 public:
105 	Sound(ScummEngine *parent, Audio::Mixer *mixer);
106 	virtual ~Sound();
107 	virtual void addSoundToQueue(int sound, int heOffset = 0, int heChannel = 0, int heFlags = 0, int heFreq = 0, int hePan = 0, int heVol = 0);
108 	virtual void addSoundToQueue2(int sound, int heOffset = 0, int heChannel = 0, int heFlags = 0, int heFreq = 0, int hePan = 0, int heVol = 0);
109 	void processSound();
110 
111 	void playSound(int soundID);
112 	void startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle *handle = NULL);
113 	void stopTalkSound();
114 	bool isMouthSyncOff(uint pos);
115 	virtual int isSoundRunning(int sound) const;
116 	bool isSoundInUse(int sound) const;
117 	virtual void stopSound(int sound);
118 	virtual void stopAllSounds();
119 	void soundKludge(int *list, int num);
120 	void talkSound(uint32 a, uint32 b, int mode, int channel = 0);
121 	virtual void setupSound();
122 	void pauseSounds(bool pause);
123 
124 	void startCDTimer();
125 	void stopCDTimer();
126 
127 	void playCDTrack(int track, int numLoops, int startFrame, int duration);
128 	void playCDTrackInternal(int track, int numLoops, int startFrame, int duration);
129 	void stopCD();
130 	int pollCD() const;
131 	void updateCD();
132 	AudioCDManager::Status getCDStatus();
getCurrentCDSound()133 	int getCurrentCDSound() const { return _currentCDSound; }
134 
135 	void saveLoadWithSerializer(Common::Serializer &ser);
136 
137 protected:
138 	void setupSfxFile();
139 	bool isSfxFinished() const;
140 	void processSfxQueues();
141 
142 	bool isSoundInQueue(int sound) const;
143 
144 	virtual void processSoundQueues();
145 };
146 
147 
148 } // End of namespace Scumm
149 
150 #endif
151