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 SWORD1_MUSIC_H
24 #define SWORD1_MUSIC_H
25 
26 #include "common/scummsys.h"
27 #include "common/mutex.h"
28 #include "common/file.h"
29 #include "audio/audiostream.h"
30 #include "audio/mixer.h"
31 #include "audio/rate.h"
32 
33 namespace Sword1 {
34 
35 #define TOTAL_TUNES 270
36 
37 class MusicHandle : public Audio::AudioStream {
38 private:
39 	Common::File _file;
40 	int32 _fading;
41 	int32 _fadeSamples;
42 	Audio::AudioStream *_audioSource;
43 public:
MusicHandle()44 	MusicHandle() : _fading(0), _audioSource(NULL) {}
45 	virtual int readBuffer(int16 *buffer, const int numSamples);
46 	bool play(const Common::String &filename, bool loop);
47 	bool playPSX(uint16 id, bool loop);
48 	void stop();
49 	void fadeUp();
50 	void fadeDown();
51 	bool streaming() const;
fading()52 	int32 fading() { return _fading; }
53 	bool endOfData() const;
endOfStream()54 	bool endOfStream() const { return false; }
55 	bool isStereo() const;
56 	int getRate() const;
57 };
58 
59 class Music : public Audio::AudioStream {
60 public:
61 	Music(Audio::Mixer *pMixer);
62 	~Music();
63 	void startMusic(int32 tuneId, int32 loopFlag);
64 	void fadeDown();
65 	void setVolume(uint8 volL, uint8 volR);
66 	void giveVolume(uint8 *volL, uint8 *volR);
67 
68 	// AudioStream API
readBuffer(int16 * buffer,const int numSamples)69 	int readBuffer(int16 *buffer, const int numSamples) {
70 		mixer(buffer, numSamples / 2);
71 		return numSamples;
72 	}
isStereo()73 	bool isStereo() const { return true; }
endOfData()74 	bool endOfData() const { return false; }
getRate()75 	int getRate() const { return _sampleRate; }
76 
77 private:
78 	Audio::st_volume_t _volumeL, _volumeR;
79 	MusicHandle _handles[2];
80 	Audio::RateConverter *_converter[2];
81 	Audio::Mixer *_mixer;
82 	Audio::SoundHandle _soundHandle;
83 	uint32 _sampleRate;
84 	Common::Mutex _mutex;
85 
86 	static void passMixerFunc(void *param, int16 *buf, uint len);
87 	void mixer(int16 *buf, uint32 len);
88 
89 	static const char _tuneList[TOTAL_TUNES][8]; // in staticres.cpp
90 };
91 
92 } // End of namespace Sword1
93 
94 #endif // BSMUSIC_H
95