ScummVM API documentation
audio_mixer.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BLADERUNNER_AUDIO_MIXER_H
23 #define BLADERUNNER_AUDIO_MIXER_H
24 
25 #include "audio/audiostream.h"
26 #include "audio/mixer.h"
27 
28 #include "common/mutex.h"
29 
30 #include "bladerunner/bladerunner.h" // For BLADERUNNER_ORIGINAL_BUGS symbol
31 
32 namespace BladeRunner {
33 
34 class BladeRunnerEngine;
35 
36 #if !BLADERUNNER_ORIGINAL_BUGS
37 enum audioMixerAppTimers {
38  kAudioMixerAppTimerMusicNext = 0,
39  kAudioMixerAppTimerMusicFadeOut = 1
40 };
41 #endif
42 
43 class AudioMixer {
44 #if BLADERUNNER_ORIGINAL_BUGS
45  static const int kChannels = 9;
46  static const int kUsableChannels = 8;
47  static const int kMusicChannel = 8;
48 #else
49  static const int kChannels = 15;
50  static const int kUsableChannels = 14;
51  static const int kMusicChannel = 14;
52 
53  static const int kAudioMixerAppTimersNum = 2;
54 #endif // BLADERUNNER_ORIGINAL_BUGS
55  static const int kUpdatesPerSecond = 40;
56 
57  struct Channel {
58  bool isPresent;
59  int priority;
60  bool loop;
61  Audio::SoundHandle handle;
62  Audio::AudioStream *stream;
63  float volume; // should be in [0.0f, 100.0f]. It's percent for the Audio::Mixer::kMaxChannelVolume
64  float volumeDelta;
65  float volumeTarget; // should be in [0.0f, 100.0f], as for volume field.
66  float pan; // should be in [-100.0f, 100.0f]. It's percent for 127 (max absolute balance value)
67  float panDelta;
68  float panTarget; // should be in [-100.0f, 100.0f], as for pan field.
69  void (*endCallback)(int channel, void *data);
70  void *callbackData;
71  uint32 timeStarted;
72  uint32 trackDurationMs;
73  bool sentToMixer;
74  };
75 
76  BladeRunnerEngine *_vm;
77 
78  Channel _channels[kChannels];
79  Common::Mutex _mutex;
80 
81 #if !BLADERUNNER_ORIGINAL_BUGS
82  struct audioMixerAppTimer {
83  bool started;
84  uint32 intervalMillis; // expiration interval in milliseconds
85  uint32 lastFired; // time of last time the timer expired in milliseconds
86  };
87 
88  audioMixerAppTimer _audioMixerAppTimers[kAudioMixerAppTimersNum];
89 #endif // !BLADERUNNER_ORIGINAL_BUGS
90 
91 public:
93  ~AudioMixer();
94 
95  int play(Audio::Mixer::SoundType type, Audio::RewindableAudioStream *stream, int priority, bool loop, int volume, int pan, void(*endCallback)(int, void *), void *callbackData, uint32 trackDurationMs);
96  int playMusic(Audio::RewindableAudioStream *stream, int volume, void(*endCallback)(int, void *), void *callbackData, uint32 trackDurationMs);
97  void stop(int channel, uint32 time);
98 
99  void adjustVolume(int channel, int targetVolume, uint32 time);
100  void adjustPan(int channel, int targetPan, uint32 time);
101 
102 #if !BLADERUNNER_ORIGINAL_BUGS
103  void startAppTimerProc(int audioMixAppTimerId, uint32 intervalMillis);
104  void stopAppTimerProc(int audioMixAppTimerId);
105 #endif // !BLADERUNNER_ORIGINAL_BUGS
106  // TODO Are these completely unused?
107 // void resume(int channel, uint32 delay);
108 // void pause(int channel, uint32 delay);
109 
110 private:
111  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, uint32 trackDurationMs);
112 
113  bool isActive(int channel) const;
114  void tick();
115  static void timerCallback(void *refCon);
116 };
117 
118 } // End of namespace BladeRunner
119 
120 #endif
Definition: actor.h:31
Definition: mixer.h:49
SoundType
Definition: mixer.h:62
Definition: audio_mixer.h:43
Definition: mutex.h:67
Definition: audiostream.h:50
Definition: audiostream.h:109
Definition: bladerunner.h:113