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 GOB_SOUND_SOUND_H
24 #define GOB_SOUND_SOUND_H
25 
26 #include "common/str.h"
27 #include "gob/sound/sounddesc.h"
28 
29 namespace Gob {
30 
31 class GobEngine;
32 class BackgroundAtmosphere;
33 class PCSpeaker;
34 class SoundBlaster;
35 class ADLPlayer;
36 class MUSPlayer;
37 class Infogrames;
38 class Protracker;
39 class CDROM;
40 
41 class Sound {
42 public:
43 	enum BackgroundPlayMode {
44 		kPlayModeLinear,
45 		kPlayModeRandom
46 	};
47 
48 	static const int kSoundsCount = 60;
49 
50 	Sound(GobEngine *vm);
51 	~Sound();
52 
53 	static void convToSigned(byte *buffer, int length);
54 
55 	// Samples
56 	SoundDesc *sampleGetBySlot(int slot);
57 	const SoundDesc *sampleGetBySlot(int slot) const;
58 	int sampleGetNextFreeSlot() const;
59 
60 	bool sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName);
61 	void sampleFree(SoundDesc *sndDesc, bool noteAdLib = false, int index = -1);
62 
63 
64 	// SoundBlaster
65 	void blasterPlay(SoundDesc *sndDesc, int16 repCount,
66 			int16 frequency, int16 fadeLength = 0);
67 	void blasterStop(int16 fadeLength, SoundDesc *sndDesc = 0);
68 
69 	void blasterPlayComposition(const int16 *composition, int16 freqVal,
70 			SoundDesc *sndDescs = 0, int8 sndCount = kSoundsCount);
71 	void blasterStopComposition();
72 	void blasterRepeatComposition(int32 repCount);
73 
74 	char blasterPlayingSound() const;
75 
76 	void blasterSetRepeating(int32 repCount);
77 	void blasterWaitEndPlay(bool interruptible = false, bool stopComp = true);
78 
79 
80 	// PCSpeaker
81 	void speakerOn(int16 frequency, int32 length = -1);
82 	void speakerOff();
83 	void speakerOnUpdate(uint32 millis);
84 
85 
86 	// AdLib
87 	bool adlibLoadADL(const char *fileName);
88 	bool adlibLoadADL(byte *data, uint32 size, int index = -1);
89 	bool adlibLoadMDY(const char *fileName);
90 	bool adlibLoadTBR(const char *fileName);
91 	void adlibUnload();
92 
93 	void adlibPlayTrack(const char *trackname);
94 	void adlibPlayBgMusic();
95 
96 	void adlibPlay();
97 	void adlibStop();
98 
99 	bool adlibIsPlaying() const;
100 
101 	int adlibGetIndex() const;
102 	int32 adlibGetRepeating() const;
103 
104 	void adlibSetRepeating(int32 repCount);
105 	void adlibSyncVolume();
106 
107 
108 	// Infogrames
109 	bool infogramesLoadInstruments(const char *fileName);
110 	bool infogramesLoadSong(const char *fileName);
111 
112 	void infogramesPlay();
113 	void infogramesStop();
114 
115 
116 	// Protracker
117 	bool protrackerPlay(const char *fileName);
118 	void protrackerStop();
119 
120 
121 	// CD-ROM
122 	void cdLoadLIC(const Common::String &fname);
123 	void cdUnloadLIC();
124 
125 	void cdPlayBgMusic();
126 	void cdPlayMultMusic();
127 
128 	void cdPlay(const Common::String &);
129 	void cdStop();
130 
131 	bool cdIsPlaying() const;
132 
133 	int32 cdGetTrackPos(const char *keyTrack = 0) const;
134 	const char *cdGetCurrentTrack() const;
135 
136 	void cdTest(int trySubst, const char *label);
137 
138 
139 	// Background Atmosphere
140 	void bgPlay(const char *file, SoundType type);
141 	void bgPlay(const char *base, const char *ext, SoundType type, int count);
142 	void bgStop();
143 
144 	void bgSetPlayMode(BackgroundPlayMode mode);
145 
146 	void bgShade();
147 	void bgUnshade();
148 
149 private:
150 	GobEngine *_vm;
151 
152 	bool _hasAdLib;
153 	bool _hasAdLibBg;
154 
155 	SoundDesc _sounds[kSoundsCount];
156 
157 	// Speaker
158 	PCSpeaker *_pcspeaker;
159 
160 	// PCM based
161 	SoundBlaster *_blaster;
162 	BackgroundAtmosphere *_bgatmos;
163 
164 	// AdLib
165 	MUSPlayer *_mdyPlayer;
166 	ADLPlayer *_adlPlayer;
167 
168 	// Amiga Paula
169 	Infogrames *_infogrames;
170 	Protracker *_protracker;
171 
172 	// Audio CD
173 	CDROM *_cdrom;
174 
175 	void createMDYPlayer();
176 	void createADLPlayer();
177 };
178 
179 } // End of namespace Gob
180 
181 #endif // GOB_SOUND_SOUND_H
182