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 BLADERUNNER_AUDIO_MIXER_H
24 #define BLADERUNNER_AUDIO_MIXER_H
25 
26 #include "audio/audiostream.h"
27 #include "audio/mixer.h"
28 
29 #include "common/mutex.h"
30 
31 namespace BladeRunner {
32 
33 class BladeRunnerEngine;
34 
35 class AudioMixer {
36 #if BLADERUNNER_ORIGINAL_BUGS
37 	static const int kChannels         = 9;
38 	static const int kUsableChannels   = 8;
39 	static const int kMusicChannel     = 8;
40 #else
41 	static const int kChannels         = 15;
42 	static const int kUsableChannels   = 14;
43 	static const int kMusicChannel     = 14;
44 #endif // BLADERUNNER_ORIGINAL_BUGS
45 	static const int kUpdatesPerSecond = 40;
46 
47 	struct Channel {
48 		bool                isPresent;
49 		int                 priority;
50 		bool                loop;
51 		Audio::SoundHandle  handle;
52 		Audio::AudioStream *stream;
53 		float               volume;
54 		float               volumeDelta;
55 		float               volumeTarget;
56 		float               pan;
57 		float               panDelta;
58 		float               panTarget;
59 		void              (*endCallback)(int channel, void *data);
60 		void               *callbackData;
61 	};
62 
63 	BladeRunnerEngine *_vm;
64 
65 	Channel       _channels[kChannels];
66 	Common::Mutex _mutex;
67 
68 public:
69 	AudioMixer(BladeRunnerEngine *vm);
70 	~AudioMixer();
71 
72 	int play(Audio::Mixer::SoundType type, Audio::RewindableAudioStream *stream, int priority, bool loop, int volume, int pan, void(*endCallback)(int, void *), void *callbackData);
73 	int playMusic(Audio::RewindableAudioStream *stream, int volume, void(*endCallback)(int, void *), void *callbackData);
74 	void stop(int channel, uint32 delay);
75 
76 	void adjustVolume(int channel, int newVolume, uint32 time);
77 	void adjustPan(int channel, int newPan, uint32 time);
78 
79 	void resume(int channel, uint32 delay);
80 	void pause(int channel, uint32 delay);
81 
82 private:
83 	int playInChannel(int channel, Audio::Mixer::SoundType type, Audio::RewindableAudioStream *stream, int priority, bool loop, int volume, int pan, void(*endCallback)(int, void *), void *callbackData);
84 
85 	bool isActive(int channel) const;
86 	void tick();
87 	static void timerCallback(void *refCon);
88 };
89 
90 } // End of namespace BladeRunner
91 
92 #endif
93