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  * This file contains the Sound Driver data structures etc.
22  */
23 
24 #ifndef TINSEL_SOUND_H
25 #define TINSEL_SOUND_H
26 
27 #include "common/file.h"
28 #include "common/file.h"
29 
30 #include "audio/mixer.h"
31 
32 #include "tinsel/dw.h"
33 #include "tinsel/tinsel.h"
34 #include "tinsel/drives.h"
35 
36 namespace Tinsel {
37 
38 enum STYPE {FX, VOICE};
39 
40 enum PlayPriority { PRIORITY_SCRIPT, PRIORITY_SPLAY1, PRIORITY_SPLAY2, PRIORITY_TALK };
41 
42 enum SampleFlags {PS_COMPLETE = 0x01, PS_SUSTAIN = 0x02};
43 
44 /*----------------------------------------------------------------------*\
45 |*				Function Prototypes			*|
46 \*----------------------------------------------------------------------*/
47 
48 class SoundManager {
49 protected:
50 	static const int kNumSFX = 3; // Number of SFX channels
51 	enum {
52 		kChannelTalk = 0,
53 		kChannelTinsel1 = 0, // Always using this channel for DW1
54 		kChannelSFX = 1,
55 		kChannelDW1MacMusic = 2
56 	};
57 	static const int kNumChannels = kChannelSFX + kNumSFX;
58 
59 	enum SoundMode {
60 		kVOCMode,
61 		kMP3Mode,
62 		kVorbisMode,
63 		kFLACMode
64 	};
65 
66 	struct Channel {
67 		// Sample handle
68 		Audio::SoundHandle handle;
69 
70 		// Sample id
71 		int sampleNum;
72 		int subSample;
73 
74 		// Playing properties
75 		bool looped;
76 		int x, y;
77 		int priority;
78 
79 		// Time properties
80 		uint32 timeStarted;
81 		uint32 timeDuration;
82 		uint32 lastStart;
83 	};
84 
85 	Channel _channels[kNumChannels];
86 
87 	//TinselEngine *_vm;	// TODO: Enable this once global _vm var is gone
88 
89 	/** Sample index buffer and number of entries */
90 	uint32 *_sampleIndex;
91 
92 	/** Number of entries in the sample index */
93 	int _sampleIndexLen;
94 
95 	/** Specifies if the sample-data is compressed and if yes, how */
96 	SoundMode _soundMode;
97 
98 	/** file stream for sample file */
99 	TinselFile _sampleStream;
100 
101 	bool offscreenChecks(int x, int &y);
102 	int8 getPan(int x);
103 
104 public:
105 
106 	SoundManager(TinselEngine *vm);
107 	~SoundManager();
108 
109 	bool playSample(int id, Audio::Mixer::SoundType type, Audio::SoundHandle *handle = 0);
110 	bool playSample(int id, int sub, bool bLooped, int x, int y, int priority,
111 			Audio::Mixer::SoundType type, Audio::SoundHandle *handle = 0);
112 	void playDW1MacMusic(Common::File &s, uint32 length);
113 
114 	void stopAllSamples();                // Stops any currently playing sample
115 	void stopSpecSample(int id, int sub = 0); // Stops a specific sample
116 
117 	void setSFXVolumes(uint8 volume);
118 
119 	bool sampleExists(int id);
120 	bool sampleIsPlaying();
121 
122 	void openSampleFiles();
123 	void closeSampleStream();
124 
125 private:
126 	void showSoundError(const char *errorMsg, const char *soundFile);
127 };
128 
129 } // End of namespace Tinsel
130 
131 #endif	// TINSEL_SOUND_H
132