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 #define CALLBACKS_PER_SECOND 60
133 
135  int _offset;
136  byte *_data;
137  byte *_dataEnd;
138 };
139 
143 class ASound : public SoundDriver {
144 private:
146  uint16 _randomSeed;
147  int _masterVolume;
148 
152  void adlibInit();
153 
157  void update();
158 
162  void pollChannels();
163 
167  void checkChannels();
168 
172  void pollActiveChannel();
173 
177  void updateOctave();
178 
179  void updateChannelState();
180  void updateActiveChannel();
181 
185  void processSample();
186 
187  void updateFNumber();
188 
192  void onTimer();
193 
194 protected:
195  int _chanCommandCount;
196  int _commandParam;
197 
198  virtual void channelCommand(byte *&pSrc, bool &updateFlag) = 0;
199 
203  void loadSample(int sampleIndex);
204 
208  void write(int reg, int val);
209 
213  int write2(int state, int reg, int val);
214 
218  void flush();
219 
223  void channelOn(int reg, int volume);
224 
228  void channelOff(int reg);
229 
233  void resultCheck();
234 
239  byte *loadData(int offset, int size);
240 
246  void playSound(int offset, int size);
247 
253  void playSoundData(byte *pData, int startingChannel = ADLIB_CHANNEL_MIDWAY);
254 
258  bool isSoundActive(byte *pData);
259 
263  void setFrequency(int channel, int freq);
264 
268  int getRandomNumber();
269 
274  byte *getDataPtr(int nearPtr);
275 
276  virtual int command0();
277  int command1();
278  int command2();
279  int command3();
280  int command4();
281  int command5();
282  int command6();
283  int command7();
284  int command8();
285 
286  int nullCommand() {
287  return 0;
288  }
289 public:
290  AdlibChannel _channels[ADLIB_CHANNEL_COUNT];
291  AdlibChannel *_activeChannelPtr;
292  AdlibChannelData _channelData[11];
294  AdlibSample *_samplePtr;
295  Common::File _soundFile;
297  Common::Mutex _driverMutex;
298  int _dataOffset;
299  int _frameCounter;
300  bool _isDisabled;
301  int _v1;
302  int _v2;
303  int _activeChannelNumber;
304  int _freqMask1;
305  int _freqMask2;
306  int _freqBase1;
307  int _freqBase2;
308  int _channelNum1, _channelNum2;
309  int _v7;
310  int _v8;
311  int _v9;
312  int _v10;
313  int _pollResult;
314  int _resultFlag;
315  byte _nullData[2];
316  int _ports[256];
317  bool _stateFlag;
318  int _activeChannelReg;
319  int _v11;
320  bool _amDep, _vibDep, _splitPoint;
321 public:
329  ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::Path &filename, int dataOffset);
330 
334  ~ASound() override;
335 
339  static void validate();
340 
344  int stop() override;
345 
349  int poll() override;
350 
354  void noise() override;
355 
360  return _frameCounter;
361  }
362 
366  CachedDataEntry &getCachedData(byte *pData);
367 
371  void setVolume(int volume) override;
372 };
373 
374 } // namespace Nebular
375 } // namespace MADS
376 
377 #endif
Definition: array.h:52
Definition: list.h:44
Definition: path.h:52
Definition: asound.h:121
Definition: stream.h:745
Definition: asound.h:134
Definition: mixer.h:70
Definition: file.h:47
Definition: mutex.h:67
Definition: sound_manager.h:40
Definition: asound.h:95
Definition: asound.h:87
Definition: sound_manager.h:38
Definition: asound.h:35
Definition: asound.h:143
int getFrameCounter()
Definition: asound.h:359
Definition: fmopl.h:116