ScummVM API documentation
entry.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 LASTEXPRESS_SOUND_ENTRY_H
23 #define LASTEXPRESS_SOUND_ENTRY_H
24 
25 /*
26  Sound entry: 68 bytes (this is what appears in savegames)
27  uint32 {4} - status
28  uint32 {4} - tag
29  uint32 {4} - time left (_blockCount - _time)
30  uint32 {4} - time in sound ticks (30Hz timer)
31  uint32 {4} - LastExpress_ADPCMStream::_volumeHoldBlocks
32  (useless since the target volume is not saved)
33  uint32 {4} - ?? [no references except for save/load]
34  uint32 {4} - entity
35  uint32 {4} - activate delay in sound ticks (30Hz timer)
36  uint32 {4} - priority
37  char {16} - name of linked-after sound
38  (always empty because only NIS entries
39  have linked-after sounds, and NIS entries are not saved)
40  char {16} - name
41 
42  Sound queue entry: 120 bytes
43  uint32 {4} - status (combination of flags from SoundFlag)
44  uint32 {4} - tag (enum SoundTag for special sounds,
45  unique value for normal ones)
46  uint32 {4} - pointer to the beginning of the buffer for compressed sound data
47  uint32 {4} - pointer to the end of the buffer for compressed sound data
48  uint32 {4} - decoder pointer inside the buffer
49  uint32 {4} - pointer to the sound buffer [always same as the third field]
50  uint32 {4} - reader pointer inside the buffer
51  uint32 {4} - time left (_blockCount - time)
52  uint32 {4} - time in sound ticks (30Hz timer)
53  uint32 {4} - buffer size
54  uint32 {4} - union:
55  if data stream is open: position in the stream
56  if data stream is closed: close reason, purely informational
57  uint32 {4} - archive structure pointer
58  uint32 {4} - _linkAfter, pointer to the entry for linked-after sound
59  (xxx.LNK for sound entry corresponding to xxx.NIS)
60  uint32 {4} - LastExpress_ADPCMStream::_volumeHoldBlocks
61  (used for smooth change of volume)
62  uint32 {4} - ?? [no references except for save/load]
63  uint32 {4} - target value for smooth change of volume
64  uint32 {4} - base volume if NIS is playing
65  (the actual volume is reduced in half for non-NIS sounds;
66  this is used to restore the volume after NIS ends)
67  uint32 {4} - entity
68  uint32 {4} - activate time in sound ticks (30Hz timer)
69  uint32 {4} - priority
70  char {16} - name of linked-after sound, used to save/load _linkAfter
71  char {16} - name
72  uint32 {4} - pointer to next entry in the queue
73  uint32 {4} - subtitle data pointer
74 */
75 
76 #include "lastexpress/data/snd.h"
77 #include "lastexpress/data/subtitle.h"
78 
79 #include "lastexpress/shared.h"
80 
81 #include "common/serializer.h"
82 
83 namespace LastExpress {
84 
85 class LastExpressEngine;
86 class SubtitleEntry;
87 
89 // SoundEntry
92 public:
94  ~SoundEntry() override;
95 
96  void open(Common::String name, SoundFlag flag, int priority);
97  void close();
98  // startTime is measured in sound ticks, 30Hz timer
99  // [used for restoring the entry from savefile]
100  void play(uint32 startTime = 0);
101  void kill() {
102  _entity = kEntityPlayer; // no kActionEndSound notifications
103  close();
104  }
105  void setVolumeSmoothly(SoundFlag newVolume);
106  // setVolumeSmoothly() treats kVolumeNone in a special way;
107  // fade() terminates the stream after the transition
108  void fade() { setVolumeSmoothly(kVolumeNone); }
109  bool update();
110  void adjustVolumeIfNISPlaying();
111  void setVolume(SoundFlag newVolume);
112  // activateDelay is measured in main ticks, 15Hz timer
113  void initDelayedActivate(unsigned activateDelay);
114 
115  // Subtitles
116  void setSubtitles(const Common::String &filename);
117 
118  // Serializable
119  void saveLoadWithSerializer(Common::Serializer &ser) override;
120 
121  // Accessors
122  void setEntity(EntityIndex entity) { _entity = entity; }
123  bool needSaving() const {
124  return (_name != "NISSND?" && (_status & kSoundTypeMask) != kSoundTypeMenu);
125  }
126 
127  uint32 getStatus() { return _status; }
128  int32 getTag() { return _tag; }
129  uint32 getTime() { return _soundStream ? (_soundStream->getTimeMS() * 30 / 1000) + _startTime : 0; }
130  EntityIndex getEntity() { return _entity; }
131  uint32 getPriority() { return _priority; }
132  const Common::String& getName(){ return _name; }
133 
134  // Streams
135  SimpleSound *getSoundStream() { return _soundStream; }
136 
137 private:
138  LastExpressEngine *_engine;
139 
140  // _status field is a combination of bits from SoundFlag; writing
141  // _status = (SoundFlag)(_status | kSoundFlagXxx) instead of _status |= kSoundFlagXxx
142  // is irksome, so let's keep the type as uint32
143  uint32 _status;
144  int32 _tag; // member of SoundTag for special sounds, unique value for normal sounds
145  //byte *_bufferStart, *_bufferEnd, *_decodePointer, *_buffer, *_readPointer;
146  // the original game uses uint32 _blocksLeft, _time instead of _blockCount
147  // we ask the backend for sound time
148  uint32 _blockCount;
149  uint32 _startTime;
150  //uint32 _bufferSize;
151  //union { uint32 _streamPos; enum StreamCloseReason _streamCloseReason; };
152  Common::SeekableReadStream *_stream; // The file stream
153  //SoundEntry* _linkAfter;
154  //uint32 _volumeHoldBlocks; // the related logic is in LastExpress_ADPCMStream
155  //uint32 _unused;
156  //uint32 _smoothChangeTarget; // the related logic is in LastExpress_ADPCMStream
157  uint32 _volumeWithoutNIS;
158  EntityIndex _entity;
159  // The original game uses one variable _activateTime = _initTime + _activateDelay
160  // and measures everything in sound ticks (30Hz timer).
161  // We use milliseconds and two variables to deal with possible overflow
162  // (probably paranoid, but nothing really complicated).
163  uint32 _initTimeMS, _activateDelayMS;
164  uint32 _priority;
165  // char _linkAfterName[16];
166  Common::String _name; //char[16];
167  // original has pointer to the next structure in the list (not used)
168  SubtitleEntry *_subtitle;
169 
170  // Sound buffer & stream
171  StreamedSound *_soundStream; // the filtered sound stream
172 
173  void setupTag(SoundFlag flag);
174  void setupStatus(SoundFlag flag);
175  void loadStream(Common::String name);
176 };
177 
179 // SubtitleEntry
182 public:
184  ~SubtitleEntry();
185 
186  void load(const Common::String &filename, SoundEntry *soundEntry);
187  void loadData();
188  void close();
189  void setupAndDraw();
190  void drawOnScreen();
191 
192  // Accessors
193  uint32 getStatus() { return _status; }
194  SoundEntry *getSoundEntry() { return _sound; }
195 
196 private:
197  LastExpressEngine *_engine;
198 
199  Common::String _filename;
200  uint32 _status;
201  SoundEntry *_sound;
202  SubtitleManager *_data;
203 };
204 
205 } // End of namespace LastExpress
206 
207 #endif // LASTEXPRESS_SOUND_ENTRY_H
Definition: str.h:59
Definition: subtitle.h:54
Definition: lastexpress.h:69
Definition: stream.h:745
Definition: animation.h:45
Definition: serializer.h:79
Definition: snd.h:53
Definition: snd.h:77
Definition: entry.h:181
Definition: serializer.h:308
Definition: entry.h:91