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 NANCY_SOUND_H
23 #define NANCY_SOUND_H
24 
25 #include "engines/nancy/commontypes.h"
26 
27 #include "audio/mixer.h"
28 
29 namespace Common {
30 class SeekableReadStream;
31 }
32 
33 namespace Audio {
34 class SeekableAudioStream;
35 class QueuingAudioStream;
36 }
37 
38 namespace Nancy {
39 
40 class IFF;
41 class NancyConsole;
42 class NancyEngine;
43 
44 class SoundManager {
45 public:
46  // Settings for playing a sound, used in nancy3 and up
47  // Older versions had a different, non-bitflag enum, but testing
48  // indicates those were never actually implemented
49  enum PlayCommandFlags {
50  kPlaySequential = 0x0001, // Play normally
51  kPlaySequentialPosition = 0x0003, // Play at fixed position in 3D space
52  kPlaySequentialFrameAnchor = 0x0007, // Position in 3D space is tied to a background frame, ignoring 3D coordinates
53 
54  kPlayRandomTime = 0x0010, // Play at random time intervals
55  kPlayRandomPosition = 0x0020, // Play at random 3D positions
56 
57  kPlayMoveLinear = 0x0100, // Move sound position in 3D space. The movement is linear unless kPlayMoveCircular is also set
58  kPlayMoveCircular = 0x0300, // Move sound position in a circular direction (see SoundRotationAxis)
59  kPlayRandomMove = 0x0500 // Move along random vector. Does not combine with kPlayMoveCircular
60  };
61 
62  SoundManager();
63  ~SoundManager();
64 
65  void loadCommonSounds(IFF *boot);
66  void initSoundChannels();
67 
68  // Load a sound into a channel without starting it
69  void loadSound(const SoundDescription &description, SoundEffectDescription **effectData = nullptr, bool forceReload = false);
70 
71  void playSound(uint16 channelID);
72  void playSound(const SoundDescription &description);
73  void playSound(const Common::String &chunkName);
74 
75  void pauseSound(uint16 channelID, bool pause);
76  void pauseSound(const SoundDescription &description, bool pause);
77  void pauseSound(const Common::String &chunkName, bool pause);
78  void pauseAllSounds(bool pause);
79 
80  bool isSoundPlaying(uint16 channelID) const;
81  bool isSoundPlaying(const SoundDescription &description) const;
82  bool isSoundPlaying(const Common::String &chunkName) const;
83 
84  void stopSound(uint16 channelID);
85  void stopSound(const SoundDescription &description);
86  void stopSound(const Common::String &chunkName);
87  void stopAllSounds();
88 
89  byte getVolume(uint16 channelID);
90  byte getVolume(const SoundDescription &description);
91  byte getVolume(const Common::String &chunkName);
92 
93  void setVolume(uint16 channelID, uint16 volume);
94  void setVolume(const SoundDescription &description, uint16 volume);
95  void setVolume(const Common::String &chunkName, uint16 volume);
96 
97  uint32 getRate(uint16 channelID);
98  uint32 getRate(const SoundDescription &description);
99  uint32 getRate(const Common::String &chunkName);
100 
101  uint32 getBaseRate(uint16 channelID);
102  uint32 getBaseRate(const SoundDescription &description);
103  uint32 getBaseRate(const Common::String &chunkName);
104 
105  void setRate(uint16 channelID, uint32 rate);
106  void setRate(const SoundDescription &description, uint32 rate);
107  void setRate(const Common::String &chunkName, uint32 rate);
108 
109  Audio::Timestamp getLength(uint16 channelID);
110  Audio::Timestamp getLength(const SoundDescription &description);
111  Audio::Timestamp getLength(const Common::String &chunkName);
112 
113  void soundEffectMaintenance();
114  void recalculateSoundEffects();
115 
116  Math::Vector3d &getOrientation() { return _orientation; }
117  Common::String getChannelInfo(uint16 channelID);
118 
119  // Used when changing scenes
120  void stopAndUnloadSceneSpecificSounds();
121  void pauseSceneSpecificSounds(bool pause);
122 
123  static Audio::SeekableAudioStream *makeHISStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 overrideSamplesPerSec = 0);
124 
125 protected:
126  struct Channel {
127  ~Channel();
128  Common::String name;
129  Audio::Mixer::SoundType type = Audio::Mixer::SoundType::kPlainSoundType;
130  uint16 playCommands = 1;
131  uint16 numLoops = 0;
132  uint volume = 0;
133  uint16 panAnchorFrame = 0;
134  bool isPanning = false;
135  Audio::SeekableAudioStream *stream = nullptr;
136  Audio::AudioStream *streamForMixer = nullptr;
137  Audio::SoundHandle handle;
138  bool isPersistent = false;
139 
140  // Sound effect data, not applicable to nancy2 and below
141  SoundEffectDescription *effectData = nullptr;
142  Math::Vector3d position;
143  Math::Vector3d positionDelta;
144  uint32 nextStepTime = 0;
145  uint16 stepsLeft = 0;
146  uint32 nextRepeatTime = 0;
147  };
148 
149  void soundEffectMaintenance(uint16 channelID, bool force = false);
150 
151  Audio::Mixer *_mixer;
152 
153  Common::Array<Channel> _channels;
155 
156  bool _shouldRecalculate;
157 
158  Math::Vector3d _orientation;
159  Math::Vector3d _position;
160  uint _positionLerp = 0;
161 };
162 
163 } // End of namespace Nancy
164 
165 #endif // NANCY_SOUND_H
Definition: str.h:59
Definition: array.h:52
Definition: timestamp.h:83
Definition: stream.h:745
Definition: commontypes.h:218
Definition: audiostream.h:212
Definition: mixer.h:49
SoundType
Definition: mixer.h:73
Definition: mixer.h:70
Definition: hashmap.h:85
Definition: algorithm.h:29
Definition: audiostream.h:50
Definition: sound.h:44
Definition: commontypes.h:255
Definition: sound.h:126
Definition: iff.h:34
Definition: system.h:38
Definition: actionmanager.h:32