ScummVM API documentation
asound.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 MADS_NEBULAR_CORE_ASOUND_H
23 #define MADS_NEBULAR_CORE_ASOUND_H
24 
25 #include "mads/core/sound_manager.h"
26 
27 namespace MADS {
28 namespace Nebular {
29 
30 class ASound;
31 
35 class AdlibChannel {
36 public:
37  ASound *_owner;
38 
39  int _activeCount;
40  int _field1;
41  int _field2;
42  int _field3;
43  int _field4;
44  int _sampleIndex;
45  int _volume;
46  int _field7;
47  int _field8;
48  int _field9;
49  int _fieldA;
50  uint8 _fieldB;
51  int _fieldC;
52  int _fieldD;
53  int _fieldE;
54  byte *_ptr1;
55  byte *_pSrc;
56  byte *_ptr3;
57  byte *_ptr4;
58  byte *_ptrEnd;
59  int _field17;
60  int _field19;
61  byte *_soundData;
62  int _field1D;
63  int _volumeOffset;
64  int _field1F;
65 
66  // TODO: Only used by asound.003. Figure out usage
67  byte _field20;
68 
69  // Phantom-specific fields
70  int _field26; // pitch delta (set in case -14, zeroed in case -3)
71  int _field28; // zeroed in case -3
72  int _field2A; // set in case -18
73  int _field2B; // volume-cap flag (suppresses upward volume changes)
74  int _field2C; // frequency counter (used with _field7 in cases -9/-10)
75 public:
76  static bool _channelsEnabled;
77 public:
78  AdlibChannel();
79 
80  void reset();
81  void enable(int flag);
82  void setPtr2(byte *pData);
83  void load(byte *pData);
84  void check(byte *nullPtr);
85 };
86 
88 public:
89  int _field0;
90  int _freqMask;
91  int _freqBase;
92  int _field6;
93 };
94 
95 class AdlibSample {
96 public:
97  int _attackRate;
98  int _decayRate;
99  int _sustainLevel;
100  int _releaseRate;
101  bool _egTyp;
102  bool _ksr;
103  int _totalLevel;
104  int _scalingLevel;
105  int _waveformSelect;
106  int _freqMultiple;
107  int _feedback;
108  bool _ampMod;
109  int _vib;
110  int _alg;
111  int _fieldE;
112  int _freqMask;
113  int _freqBase;
114  int _field14;
115 
116  AdlibSample() {
117  }
119 };
120 
122  uint8 _regNum;
123  uint8 _value;
124 
125  RegisterValue(int regNum, int value) {
126  _regNum = regNum; _value = value;
127  }
128 };
129 
130 #define ADLIB_CHANNEL_COUNT 9
131 #define ADLIB_CHANNEL_MIDWAY 5
132 
136 class ASound : public SoundDriver {
137 protected:
139  byte *_dataStart = nullptr;
140  byte *_dataEnd = nullptr;
141  CachedDataEntry(byte *dataStart, size_t size) : _dataStart(dataStart),
142  _dataEnd(dataStart + size - 1) {
143  }
144  };
145 
146 private:
148 
149 private:
150  uint16 _randomSeed;
151  int _masterVolume;
152 
156  void adlibInit();
157 
161  void update();
162 
166  void pollChannels();
167 
171  void checkChannels();
172 
176  void pollActiveChannel();
177 
181  void updateOctave();
182 
183  void updateChannelState();
184  void updateActiveChannel();
185 
189  void processSample();
190 
191  void updateFNumber();
192 
196  void onTimer();
197 
198 protected:
199  int _chanCommandCount;
200  int _commandParam;
201 
202  virtual void channelCommand(byte *&pSrc, bool &updateFlag) = 0;
203 
208  byte *loadData(int offset, int size);
209 
210  int getDataOffset(byte *ptr) const {
211  return ptr - &_soundData[0];
212  }
213 
217  void loadSample(int sampleIndex);
218 
222  void write(int reg, int val);
223 
227  int write2(int state, int reg, int val);
228 
232  void flush();
233 
237  void channelOn(int reg, int volume);
238 
242  void channelOff(int reg);
243 
247  void resultCheck();
248 
254  void playSound(int offset, int size);
255 
261  void playSoundData(byte *pData, int startingChannel = ADLIB_CHANNEL_MIDWAY);
262 
266  bool isSoundActive(byte *pData);
267 
271  void setFrequency(int channel, int freq);
272 
276  int getRandomNumber();
277 
282  byte *getDataPtr(int nearPtr);
283 
284  virtual int command0();
285  int command1();
286  int command2();
287  int command3();
288  int command4();
289  int command5();
290  int command6();
291  int command7();
292  int command8();
293 
294  int nullCommand() {
295  return 0;
296  }
297 public:
298  AdlibChannel _channels[ADLIB_CHANNEL_COUNT];
299  AdlibChannel *_activeChannelPtr;
300  AdlibChannelData _channelData[11];
302  AdlibSample *_samplePtr;
304  int _frameCounter;
305  bool _isDisabled;
306  int _v1;
307  int _v2;
308  int _activeChannelNumber;
309  int _freqMask1;
310  int _freqMask2;
311  int _freqBase1;
312  int _freqBase2;
313  int _channelNum1, _channelNum2;
314  int _v7;
315  int _v8;
316  int _v9;
317  int _v10;
318  int _pollResult;
319  int _resultFlag;
320  byte _nullData[2];
321  int _ports[256];
322  bool _stateFlag;
323  int _activeChannelReg;
324  int _v11;
325  bool _amDep, _vibDep, _splitPoint;
326 public:
335  ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::Path &filename,
336  int dataOffset, int dataSize);
337 
341  ~ASound() override {
342  }
343 
347  static void validate();
348 
352  CachedDataEntry &getCachedData(byte *pData);
353 
357  int stop() override;
358 
362  int poll() override;
363 
367  void noise() override;
368 
373  return _frameCounter;
374  }
375 
379  void setVolume(int volume) override;
380 };
381 
382 } // namespace Nebular
383 } // namespace MADS
384 
385 #endif
Definition: array.h:52
Definition: path.h:52
Definition: asound.h:121
Definition: stream.h:745
Definition: mixer.h:70
~ASound() override
Definition: asound.h:341
Definition: sound_manager.h:42
Definition: asound.h:95
Definition: asound.h:138
Definition: asound.h:87
Definition: mps_installer.h:31
Definition: asound.h:35
Definition: asound.h:136
int getFrameCounter()
Definition: asound.h:372
Definition: fmopl.h:116