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  * Additional copyright for this file:
8  * Copyright (C) 1995 Presto Studios, Inc.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19 
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #ifndef BURIED_SOUND_H
26 #define BURIED_SOUND_H
27 
28 #include "audio/mixer.h"
29 #include "common/str.h"
30 
31 namespace Audio {
32 class RewindableAudioStream;
33 class SoundHandle;
34 }
35 
36 namespace Buried {
37 
38 class BuriedEngine;
39 
40 class SoundManager {
41 public:
43  ~SoundManager();
44 
45  // STARTUP/SHUTDOWN FUNCTIONS
46  bool startup();
47  void shutDown();
48 
49  // AMBIENT SOUND CHANNEL FUNCTIONS
50  bool setAmbientSound(const Common::Path &fileName = Common::Path(), bool fade = false, byte finalVolumeLevel = 64);
51  bool adjustAmbientSoundVolume(byte newVolumeLevel, bool fade, byte steps, uint32 fadeLength);
52  bool isAmbientSoundPlaying();
53 
54  bool setSecondaryAmbientSound(const Common::Path &fileName = Common::Path(), bool fade = false, byte finalVolumeLevel = 64);
55  bool adjustSecondaryAmbientSoundVolume(byte newVolumeLevel, bool fade, byte steps, uint32 fadeLength);
56  uint32 getSecondaryAmbientPosition();
57  bool restartSecondaryAmbientSound();
58 
59  // AI SOUND CHANNEL FUNCTIONS
60  bool playSynchronousAIComment(const Common::Path &fileName);
61  bool playAsynchronousAIComment(const Common::Path &fileName);
62  bool isAsynchronousAICommentPlaying();
63  void stopAsynchronousAIComment();
64 
65  // SOUND EFFECTS FUNCTIONS
66  int playSoundEffect(const Common::Path &fileName, int volume = 127, bool loop = false, bool oneShot = true);
67  bool playSynchronousSoundEffect(const Common::Path &fileName, int volume = 127);
68  bool stopSoundEffect(int effectID);
69  bool isSoundEffectPlaying (int effectID);
70  bool adjustSoundEffectSoundVolume(int effectID, byte newVolumeLevel, bool fade, byte steps, uint32 fadeLength);
71 
72  // Interface sound functions
73  bool playInterfaceSound(const Common::Path &fileName);
74  bool stopInterfaceSound();
75  bool isInterfaceSoundPlaying();
76 
77  // START AND STOP SPECIFIED FOOTSTEPS SOUND
78  bool startFootsteps(int footstepsID);
79  bool stopFootsteps();
80 
81  // Pause functions
82  // stop()/restart() do as they say on the tin and aren't true pause functions.
83  // This is what the original does for pausing, and it needs to be done this way.
84  // pause() is used for implementing pauseEngineIntern(). Since stop()/restart()
85  // are not re-entrant, they're not suitable for that purpose.
86  bool stop();
87  void stopSound(int soundId);
88  bool restart();
89  void pause(bool shouldPause);
90 
91  // TIMER CALLBACK FUNCTION
92  void timerCallback();
93 
94 private:
95  enum {
96  kAmbientIndexBase = 0,
97  kAmbientIndexA = 0,
98  kAmbientIndexB = 1,
99 
100  kEffectsIndexBase = 2,
101  kEffectsIndexA = 2,
102  kEffectsIndexB = 3,
103 
104  kInterfaceIndex = 4,
105  kAIVoiceIndex = 5,
106  kFootstepsIndex = 6,
107 
108  kMaxSounds = 7
109  };
110 
111  class Sound {
112  friend class SoundManager;
113 
114  public:
115  Sound();
116  ~Sound();
117 
118  bool load(const Common::Path &fileName);
119  bool start();
120  bool isPlaying() const;
121  bool stop();
122  void pause(bool shouldPause);
123 
124  protected:
125  Audio::RewindableAudioStream *_soundData; // Stream to the data
126  Audio::SoundHandle *_handle; // Handle
127 
128  int32 _volume; // Volume of this sample
129  bool _loop; // Is this sample looping?
130  byte _flags; // Sound flags
131  byte _timedEffectIndex; // Timed effect index
132  int _timedEffectSteps; // Number of steps remaining in timed effect
133  int32 _timedEffectDelta; // Amount to change target value in each step
134  uint32 _timedEffectStart; // The last starting time for the timed effect
135  uint32 _timedEffectRemaining; // The remaining amount of time for the effect
136 
137  bool _wasPlaying;
138  Audio::Mixer::SoundType _soundType;
139  };
140 
141  BuriedEngine *_vm;
142 
143  Sound *_soundData[kMaxSounds];
144 
145  bool _paused;
146 
147  int _fileIDFootsteps;
148  Common::Path _ambientFileNames[2];
149  int _lastAmbient;
150  Common::Path _effectsFileNames[2];
151  Common::Path _interfaceFileName;
152  Common::Path _arthurFileName;
153 };
154 
155 } // End of namespace Buried
156 
157 #endif
Definition: path.h:52
Definition: mixer.h:49
SoundType
Definition: mixer.h:62
Definition: buried.h:67
Definition: agent_evaluation.h:31
Definition: audiostream.h:109
Definition: sound.h:40
Definition: system.h:38