ScummVM API documentation
sound.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 SOUND_H_
23#define SOUND_H_
24
25#include "audio/audiostream.h"
26#include "audio/mixer.h"
27
28#include "common/str.h"
29
30namespace Myst3 {
31
32class Myst3Engine;
33
34enum SoundType {
35 kAny,
36 kAmbient,
37 kCue,
38 kEffect,
39 kMusic
40};
41
42enum SoundNextCommand {
43 kRandom,
44 kNext,
45 kRandomIfOtherStarting,
46 kNextIfOtherStarting
47};
48
50public:
52 virtual ~SoundChannel();
53
54 void play(uint32 id, uint32 volume, uint16 heading, uint16 attenuation, bool loop, SoundType type);
55 void setVolume3D(uint32 volume, uint16 heading, uint16 attenuation);
56 void fade(uint32 targetVolume, int32 targetHeading, int32 targetAttenuation, uint32 fadeDelay);
57 void fadeOut(uint32 fadeDelay);
58 void update();
59 void stop();
60 void age(uint32 maxAge);
61 uint32 playedFrames();
62 uint32 adjustVolume(uint32 volume);
63
64 uint32 _id;
65 bool _playing;
66 bool _stopWhenSilent;
67 bool _fading;
68 SoundType _type;
69 uint32 _age;
70 uint32 _ambientFadeOutDelay;
71
72 uint _fadeLastTick;
73 int32 _fadeDuration; // In frames (@30 fps)
74 int32 _fadePosition;
75
76 int32 _fadeSourceVolume;
77 int32 _fadeTargetVolume;
78 int32 _fadeSourceHeading;
79 int32 _fadeTargetHeading;
80 int32 _fadeSourceAttenuation;
81 int32 _fadeTargetAttenuation;
82
83 bool _hasFadeArray;
84 uint32 _fadeArrayPosition;
85 uint32 _fadeDurations[4];
86 uint32 _fadeVolumes[4];
87
88private:
89 Myst3Engine *_vm;
90
91 Common::String _name;
92
93 uint32 _volume;
94 int32 _heading;
95 uint32 _headingAngle;
96
97 Audio::AudioStream *_stream;
98 Audio::SoundHandle _handle;
99 Audio::Timestamp _length;
100
101 Audio::RewindableAudioStream *makeAudioStream(const Common::String &name) const;
102 void updateFading();
103 Audio::Mixer::SoundType mixerSoundType();
104};
105
106class Sound {
107public:
108 Sound(Myst3Engine *vm);
109 virtual ~Sound();
110
111 SoundChannel *getChannelForSound(uint32 id, SoundType type, bool *found = nullptr);
112
113 void playEffect(uint32 id, uint32 volume, uint16 heading = 0, uint16 attenuation = 0);
114 void playEffectLooping(uint32 id, uint32 volume, uint16 heading = 0, uint16 attenuation = 0);
115 void playEffectFadeInOut(uint32 id, uint32 volume, uint16 heading, uint16 attenuation,
116 uint32 fadeInDuration, uint32 playDuration, uint32 fadeOutDuration);
117 void stopEffect(uint32 id, uint32 fadeDuration);
118
119 void playCue(uint32 id, uint32 volume, uint16 heading, uint16 attenuation);
120 void stopCue(uint32 fadeDelay);
121
122 void stopMusic(uint32 fadeDelay);
123
124 bool isPlaying(uint32 id);
125 int32 playedFrames(uint32 id);
126
127 void update();
128 void age();
129
130 void fadeOutOldSounds(uint32 fadeDelay);
131
132 void computeVolumeBalance(int32 volume, int32 heading, uint attenuation, int32 *mixerVolume, int32 *balance);
133
134 void setupNextSound(SoundNextCommand command, int16 controlVar, int16 startSoundId, int16 soundCount,
135 int32 soundMinDelay, int32 soundMaxDelay, int32 controlSoundId = 0, int32 controlSoundMaxPosition = 0);
136 void resetSoundVars();
137private:
138 static const uint kNumChannels = 14;
139
140 Myst3Engine *_vm;
141 SoundChannel *_channels[kNumChannels];
142
143 void compute3DVolumes(int32 heading, uint angle, int32 *left, int32 *right);
144};
145
146} // End of namespace Myst3
147
148#endif // SOUND_H_
Definition: audiostream.h:50
SoundType
Definition: mixer.h:73
Definition: audiostream.h:109
Definition: mixer.h:49
Definition: timestamp.h:83
Definition: str.h:59
Definition: myst3.h:87
Definition: sound.h:49
Definition: sound.h:106