ScummVM API documentation
sound_nebular.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_SOUND_NEBULAR_H
23 #define MADS_SOUND_NEBULAR_H
24 
25 #include "common/scummsys.h"
26 #include "common/file.h"
27 #include "common/mutex.h"
28 #include "common/queue.h"
29 
30 namespace Audio {
31 class Mixer;
32 }
33 
34 namespace Common {
35 class SeekableReadStream;
36 }
37 
38 namespace OPL {
39 class OPL;
40 }
41 
42 namespace MADS {
43 
44 namespace Nebular {
45 
46 class ASound;
47 
51 class AdlibChannel {
52 public:
53  ASound *_owner;
54 
55  int _activeCount;
56  int _field1;
57  int _field2;
58  int _field3;
59  int _field4;
60  int _sampleIndex;
61  int _volume;
62  int _field7;
63  int _field8;
64  int _field9;
65  int _fieldA;
66  uint8 _fieldB;
67  int _fieldC;
68  int _fieldD;
69  int _fieldE;
70  byte *_ptr1;
71  byte *_pSrc;
72  byte *_ptr3;
73  byte *_ptr4;
74  byte *_ptrEnd;
75  int _field17;
76  int _field19;
77  byte *_soundData;
78  int _field1D;
79  int _volumeOffset;
80  int _field1F;
81 
82  // TODO: Only used by asound.003. Figure out usage
83  byte _field20;
84 public:
85  static bool _channelsEnabled;
86 public:
87  AdlibChannel();
88 
89  void reset();
90  void enable(int flag);
91  void setPtr2(byte *pData);
92  void load(byte *pData);
93  void check(byte *nullPtr);
94 };
95 
97 public:
98  int _field0;
99  int _freqMask;
100  int _freqBase;
101  int _field6;
102 };
103 
104 class AdlibSample {
105 public:
106  int _attackRate;
107  int _decayRate;
108  int _sustainLevel;
109  int _releaseRate;
110  bool _egTyp;
111  bool _ksr;
112  int _totalLevel;
113  int _scalingLevel;
114  int _waveformSelect;
115  int _freqMultiple;
116  int _feedback;
117  bool _ampMod;
118  int _vib;
119  int _alg;
120  int _fieldE;
121  int _freqMask;
122  int _freqBase;
123  int _field14;
124 
125  AdlibSample() {}
127 };
128 
130  uint8 _regNum;
131  uint8 _value;
132 
133  RegisterValue(int regNum, int value) {
134  _regNum = regNum; _value = value;
135  }
136 };
137 
138 #define ADLIB_CHANNEL_COUNT 9
139 #define ADLIB_CHANNEL_MIDWAY 5
140 #define CALLBACKS_PER_SECOND 60
141 
143  int _offset;
144  byte *_data;
145  byte *_dataEnd;
146 };
147 
151 class ASound {
152 private:
154  uint16 _randomSeed;
155  int _masterVolume;
156 
160  void adlibInit();
161 
165  void update();
166 
170  void pollChannels();
171 
175  void checkChannels();
176 
180  void pollActiveChannel();
181 
185  void updateOctave();
186 
187  void updateChannelState();
188  void updateActiveChannel();
189 
193  void loadSample(int sampleIndex);
194 
198  void processSample();
199 
200  void updateFNumber();
201 
205  void onTimer();
206 protected:
207  int _commandParam;
208 
212  void write(int reg, int val);
213 
217  int write2(int state, int reg, int val);
218 
222  void flush();
223 
227  void channelOn(int reg, int volume);
228 
232  void channelOff(int reg);
233 
237  void resultCheck();
238 
243  byte *loadData(int offset, int size);
244 
250  void playSound(int offset, int size);
251 
257  void playSoundData(byte *pData, int startingChannel = ADLIB_CHANNEL_MIDWAY);
258 
262  bool isSoundActive(byte *pData);
263 
267  void setFrequency(int channel, int freq);
268 
272  int getRandomNumber();
273 
274  virtual int command0();
275  int command1();
276  int command2();
277  int command3();
278  int command4();
279  int command5();
280  int command6();
281  int command7();
282  int command8();
283 
284  int nullCommand() { return 0; }
285 public:
286  Audio::Mixer *_mixer;
287  OPL::OPL *_opl;
288  AdlibChannel _channels[ADLIB_CHANNEL_COUNT];
289  AdlibChannel *_activeChannelPtr;
290  AdlibChannelData _channelData[11];
292  AdlibSample *_samplePtr;
293  Common::File _soundFile;
295  Common::Mutex _driverMutex;
296  int _dataOffset;
297  int _frameCounter;
298  bool _isDisabled;
299  int _v1;
300  int _v2;
301  int _activeChannelNumber;
302  int _freqMask1;
303  int _freqMask2;
304  int _freqBase1;
305  int _freqBase2;
306  int _channelNum1, _channelNum2;
307  int _v7;
308  int _v8;
309  int _v9;
310  int _v10;
311  int _pollResult;
312  int _resultFlag;
313  byte _nullData[2];
314  int _ports[256];
315  bool _stateFlag;
316  int _activeChannelReg;
317  int _v11;
318  bool _amDep, _vibDep, _splitPoint;
319 public:
327  ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::Path &filename, int dataOffset);
328 
332  virtual ~ASound();
333 
337  static void validate();
338 
345  virtual int command(int commandId, int param) = 0;
346 
350  int stop();
351 
355  int poll();
356 
360  void noise();
361 
365  int getFrameCounter() { return _frameCounter; }
366 
370  CachedDataEntry &getCachedData(byte *pData);
371 
375  void setVolume(int volume);
376 };
377 
378 class ASound1 : public ASound {
379 private:
380  typedef int (ASound1::*CommandPtr)();
381  static const CommandPtr _commandList[42];
382  bool _cmd23Toggle;
383 
384  int command9();
385  int command10();
386  int command11();
387  int command12();
388  int command13();
389  int command14();
390  int command15();
391  int command16();
392  int command17();
393  int command18();
394  int command19();
395  int command20();
396  int command21();
397  int command22();
398  int command23();
399  int command24();
400  int command25();
401  int command26();
402  int command27();
403  int command28();
404  int command29();
405  int command30();
406  int command31();
407  int command32();
408  int command33();
409  int command34();
410  int command35();
411  int command36();
412  int command37();
413  int command38();
414  int command39();
415  int command40();
416  int command41();
417 
418  void command111213();
419  int command2627293032();
420 public:
421  ASound1(Audio::Mixer *mixer, OPL::OPL *opl);
422 
423  int command(int commandId, int param) override;
424 };
425 
426 class ASound2 : public ASound {
427 private:
428  byte _command12Param;
429 private:
430  typedef int (ASound2::*CommandPtr)();
431  static const CommandPtr _commandList[44];
432 
433  int command0() override;
434  int command9();
435  int command10();
436  int command11();
437  int command12();
438  int command13();
439  int command14();
440  int command15();
441  int command16();
442  int command17();
443  int command18();
444  int command19();
445  int command20();
446  int command21();
447  int command22();
448  int command23();
449  int command24();
450  int command25();
451  int command26();
452  int command27();
453  int command28();
454  int command29();
455  int command30();
456  int command31();
457  int command32();
458  int command33();
459  int command34();
460  int command35();
461  int command36();
462  int command37();
463  int command38();
464  int command39();
465  int command40();
466  int command41();
467  int command42();
468  int command43();
469 
470  void command9Randomize();
471  void command9Apply(byte *data, int val, int incr);
472 public:
473  ASound2(Audio::Mixer *mixer, OPL::OPL *opl);
474 
475  int command(int commandId, int param) override;
476 };
477 
478 class ASound3 : public ASound {
479 private:
480  bool _command39Flag;
481 
482  typedef int (ASound3::*CommandPtr)();
483  static const CommandPtr _commandList[61];
484 
485  int command9();
486  int command10();
487  int command11();
488  int command13();
489  int command14();
490  int command15();
491  int command16();
492  int command17();
493  int command18();
494  int command19();
495  int command20();
496  int command21();
497  int command22();
498  int command23();
499  int command24();
500  int command25();
501  int command26();
502  int command27();
503  int command28();
504  int command29();
505  int command30();
506  int command31();
507  int command32();
508  int command33();
509  int command34();
510  int command35();
511  int command36();
512  int command37();
513  int command38();
514  int command39();
515  int command40();
516  int command41();
517  int command42();
518  int command43();
519  int command44();
520  int command45();
521  int command46();
522  int command47();
523  int command49();
524  int command50();
525  int command51();
526  int command57();
527  int command59();
528  int command60();
529 
530  void command9Randomize();
531  void command9Apply(byte *data, int val, int incr);
532 public:
533  ASound3(Audio::Mixer *mixer, OPL::OPL *opl);
534 
535  int command(int commandId, int param) override;
536 };
537 
538 class ASound4 : public ASound {
539 private:
540  typedef int (ASound4::*CommandPtr)();
541  static const CommandPtr _commandList[61];
542 
543  int command10();
544  int command12();
545  int command19();
546  int command20();
547  int command21();
548  int command24();
549  int command27();
550  int command30();
551  int command32();
552  int command33();
553  int command34();
554  int command35();
555  int command36();
556  int command37();
557  int command38();
558  int command43();
559  int command52();
560  int command53();
561  int command54();
562  int command55();
563  int command56();
564  int command57();
565  int command58();
566  int command59();
567  int command60();
568 
569  void method1();
570 public:
571  ASound4(Audio::Mixer *mixer, OPL::OPL *opl);
572 
573  int command(int commandId, int param) override;
574 };
575 
576 class ASound5 : public ASound {
577 private:
578  typedef int (ASound5::*CommandPtr)();
579  static const CommandPtr _commandList[42];
580 
581  int command9();
582  int command10();
583  int command11();
584  int command12();
585  int command13();
586  int command14();
587  int command15();
588  int command16();
589  int command17();
590  int command18();
591  int command19();
592  int command20();
593  int command21();
594  int command22();
595  int command23();
596  int command24();
597  int command25();
598  int command26();
599  int command27();
600  int command28();
601  int command29();
602  int command30();
603  int command31();
604  int command32();
605  int command33();
606  int command34();
607  int command35();
608  int command36();
609  int command37();
610  int command38();
611  int command39();
612  int command40();
613  int command41();
614  int command42();
615  int command43();
616 public:
617  ASound5(Audio::Mixer *mixer, OPL::OPL *opl);
618 
619  int command(int commandId, int param) override;
620 };
621 
622 class ASound6 : public ASound {
623 private:
624  typedef int (ASound6::*CommandPtr)();
625  static const CommandPtr _commandList[30];
626 
627  int command9();
628  int command10();
629  int command11();
630  int command12();
631  int command13();
632  int command14();
633  int command15();
634  int command16();
635  int command17();
636  int command18();
637  int command19();
638  int command20();
639  int command21();
640  int command22();
641  int command23();
642  int command24();
643  int command25();
644  int command29();
645 public:
646  ASound6(Audio::Mixer *mixer, OPL::OPL *opl);
647 
648  int command(int commandId, int param) override;
649 };
650 
651 class ASound7 : public ASound {
652 private:
653  typedef int (ASound7::*CommandPtr)();
654  static const CommandPtr _commandList[38];
655 
656  int command9();
657  int command15();
658  int command16();
659  int command18();
660  int command19();
661  int command20();
662  int command21();
663  int command22();
664  int command23();
665  int command24();
666  int command25();
667  int command26();
668  int command27();
669  int command28();
670  int command30();
671  int command32();
672  int command33();
673  int command34();
674  int command35();
675  int command36();
676  int command37();
677 public:
678  ASound7(Audio::Mixer *mixer, OPL::OPL *opl);
679 
680  int command(int commandId, int param) override;
681 };
682 
683 class ASound8 : public ASound {
684 private:
685  typedef int (ASound8::*CommandPtr)();
686  static const CommandPtr _commandList[38];
687 
688  int command9();
689  int command10();
690  int command11();
691  int command12();
692  int command13();
693  int command14();
694  int command15();
695  int command16();
696  int command17();
697  int command18();
698  int command19();
699  int command20();
700  int command21();
701  int command22();
702  int command23();
703  int command24();
704  int command25();
705  int command26();
706  int command27();
707  int command28();
708  int command29();
709  int command30();
710  int command31();
711  int command32();
712  int command33();
713  int command34();
714  int command35();
715  int command36();
716  int command37();
717 
718  void method1(byte *pData);
719  void adjustRange(byte *pData, byte v, int incr);
720 public:
721  ASound8(Audio::Mixer *mixer, OPL::OPL *opl);
722 
723  int command(int commandId, int param) override;
724 };
725 
726 class ASound9 : public ASound {
727 private:
728  int _v1, _v2;
729  byte *_soundPtr;
730 
731  typedef int (ASound9::*CommandPtr)();
732  static const CommandPtr _commandList[52];
733 
734  int command9();
735  int command10();
736  int command11();
737  int command12();
738  int command13();
739  int command14();
740  int command15();
741  int command16();
742  int command17();
743  int command18();
744  int command19();
745  int command20();
746  int command21();
747  int command22();
748  int command23();
749  int command24();
750  int command25();
751  int command26();
752  int command27();
753  int command28();
754  int command29();
755  int command30();
756  int command31();
757  int command32();
758  int command33();
759  int command34();
760  int command35();
761  int command36();
762  int command37();
763  int command38();
764  int command39();
765  int command40();
766  int command41();
767  int command42();
768  int command43();
769  int command44_46();
770  int command45();
771  int command47();
772  int command48();
773  int command49();
774  int command50();
775  int command51();
776  int command57();
777  int command59();
778  int command60();
779 public:
780  ASound9(Audio::Mixer *mixer, OPL::OPL *opl);
781 
782  int command(int commandId, int param) override;
783 };
784 
785 } // End of namespace Nebular
786 
787 } // End of namespace MADS
788 
789 #endif /* MADS_SOUND_NEBULAR_H */
Definition: sound_nebular.h:378
Definition: array.h:52
Definition: sound_nebular.h:478
Definition: list.h:44
Definition: path.h:52
Definition: sound_nebular.h:426
Definition: sound_nebular.h:129
Definition: stream.h:745
Definition: sound_nebular.h:142
Definition: sound_nebular.h:651
Definition: sound_nebular.h:538
Definition: mixer.h:59
Definition: file.h:47
Definition: algorithm.h:29
Definition: mutex.h:67
Definition: sound_nebular.h:683
Definition: sound_nebular.h:576
Definition: sound_nebular.h:104
Definition: fmopl.h:35
Definition: sound_nebular.h:96
Definition: action.h:28
Definition: sound_nebular.h:51
Definition: sound_nebular.h:726
Definition: sound_nebular.h:151
Definition: sound_nebular.h:622
Definition: system.h:38
int getFrameCounter()
Definition: sound_nebular.h:365
Definition: fmopl.h:115