ScummVM API documentation
opl.music.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 FREESCAPE_DRILLER_OPL_MUSIC_H
23 #define FREESCAPE_DRILLER_OPL_MUSIC_H
24 
25 #include "audio/fmopl.h"
26 #include "freescape/music.h"
27 
28 namespace Freescape {
29 
31 public:
32  DrillerOPLMusicPlayer(int tuneIndex = 1);
33  ~DrillerOPLMusicPlayer() override;
34 
35  void startMusic() override;
36  void stopMusic() override;
37  bool isPlaying() const override;
38 
39 private:
40  enum {
41  kChannelCount = 3,
42  kMaxNote = 94
43  };
44 
45  enum ContinuousEffectEntry {
46  kVoiceDone,
47  kFullEffectPath,
48  kPortamentoOnlyPath
49  };
50 
51  struct VoiceState {
52  const uint8_t *trackDataPtr;
53  uint8_t trackIndex;
54  const uint8_t *patternDataPtr;
55  uint8_t patternIndex;
56  uint8_t instrumentIndex;
57  int8_t delayCounter;
58  uint8_t noteDuration;
59  uint8_t gateMask;
60  uint8_t currentNote;
61  uint8_t currentNoteSlideTarget;
62  uint8_t currentControl;
63  uint8_t whatever0;
64  uint8_t whatever1;
65  uint8_t whatever2;
66  uint8_t whatever3;
67  uint8_t whatever4;
68  uint8_t whatever2_vibDirToggle;
69  uint16_t portaStepRaw;
70  uint8_t something_else[3];
71  uint8_t ctrl0;
72  uint8_t arpTableIndex;
73  uint8_t arpSpeedHiNibble;
74  uint16_t stuff_freq_porta_vib;
75  uint16_t stuff_freq_base;
76  uint8_t stuff_arp_counter;
77  uint8_t things_vib_state;
78  uint16_t things_vib_depth;
79  uint8_t things_vib_delay_reload;
80  uint8_t things_vib_delay_ctr;
81  uint8_t glideDownTimer;
82  uint16_t baseSIDFrequency;
83  uint16_t baseFrequencyFnum;
84  uint8_t baseFrequencyBlock;
85  uint16_t frequencyFnum;
86  uint8_t frequencyBlock;
87  bool keyOn;
88  bool gateReleased;
89 
90  void reset();
91  };
92 
93  OPL::OPL *_opl;
94  bool _musicActive;
95  uint8_t _targetTuneIndex;
96  uint8_t _globalTempo;
97  int8_t _globalTempoCounter;
98  uint32 _tick;
99  VoiceState _voiceState[kChannelCount];
100 
101  void onTimer();
102  void setupTune(int tuneIndex);
103  void resetVoices();
104  void silenceAll();
105  void playVoice(int channel);
106  void applyNote(int channel, VoiceState &voice, const uint8_t *instA0, const uint8_t *instA1);
107  ContinuousEffectEntry postNoteEffectSetup(VoiceState &voice, const uint8_t *instA0, const uint8_t *instA1);
108  void applyContinuousEffects(int channel, VoiceState &voice, const uint8_t *instA0, const uint8_t *instA1, bool startAtPortamento);
109  void applyHardRestart(int channel, VoiceState &voice, const uint8_t *instA1);
110  void setOPLInstrument(int channel, VoiceState &voice);
111  void applyPulseWidth(int channel, const VoiceState &voice);
112  void noteOn(int channel, VoiceState &voice, uint8_t note);
113  void noteOff(int channel);
114  void setFrequency(int channel, VoiceState &voice, uint16 fnum, byte block);
115  void writeFrequency(int channel, const VoiceState &voice, uint16 fnum, byte block);
116  void writeNoteFrequency(int channel, VoiceState &voice, uint8_t note);
117  void writeSIDFrequency(int channel, VoiceState &voice, uint16 sidFrequency);
118  void noteToFnumBlock(int note, uint16 &fnum, byte &block) const;
119 };
120 
121 } // namespace Freescape
122 
123 #endif
Definition: opl.music.h:30
Definition: area.h:36
Definition: music.h:29
Definition: fmopl.h:116