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_ECLIPSE_OPL_MUSIC_H
23 #define FREESCAPE_ECLIPSE_OPL_MUSIC_H
24 
25 #include "audio/fmopl.h"
26 #include "freescape/music.h"
27 
28 namespace Freescape {
29 
40 public:
43 
44  void startMusic() override;
45  void stopMusic() override;
46  bool isPlaying() const override;
47 
48 private:
49  enum {
50  kChannelCount = 3,
51  kMaxNote = 94
52  };
53 
54  struct ChannelState {
55  const byte *orderList;
56  byte orderPos;
57 
58  uint16 patternDataOffset;
59  uint16 patternOffset;
60 
61  byte instrumentOffset;
62  byte currentNote;
63  byte transpose;
64  uint16 frequencyFnum;
65  byte frequencyBlock;
66 
67  byte durationReload;
68  byte durationCounter;
69 
70  byte effectMode;
71  byte effectParam;
72  byte arpeggioTarget;
73  byte arpeggioParam;
74  byte arpeggioSequencePos;
75  byte arpeggioSequence[9];
76  byte arpeggioSequenceLen;
77 
78  byte noteStepCommand;
79  byte stepDownCounter;
80 
81  byte vibratoPhase;
82  byte vibratoCounter;
83 
84  byte delayValue;
85  byte delayCounter;
86 
87  byte waveform;
88  byte instrumentFlags;
89  bool gateOffDisabled;
90  bool keyOn;
91  uint16 pulseWidth;
92  byte pulseWidthMod;
93  byte pulseWidthDirection;
94  byte modBaseLevel;
95  byte carBaseLevel;
96  byte modLevel;
97  byte carLevel;
98  bool rhythmVoice; // routed to the rhythm-mode hi-hat instead of an FM channel
99 
100  void reset();
101  };
102 
103  OPL::OPL *_opl;
104  bool _musicActive;
105  byte _speedDivider;
106  byte _speedCounter;
107  byte _rhythmReg; // shadow of register 0xBD
108  ChannelState _channels[kChannelCount];
109  byte _arpeggioIntervals[8];
110 
111  void onTimer();
112  void setupSong();
113  void silenceAll();
114  void loadNextPattern(int channel);
115  void buildEffectArpeggio(int channel);
116  void loadCurrentFrequency(int channel);
117  void finalizeChannel(int channel);
118  void processChannel(int channel, bool newBeat);
119  void parseCommands(int channel);
120  void applyNote(int channel, byte note);
121  void applyFrameEffects(int channel);
122  bool applyInstrumentVibrato(int channel);
123  void applyEffectArpeggio(int channel);
124  void applyTimedSlide(int channel);
125  void programEnvelope(byte op, byte attack, byte decay, byte sustain, byte release);
126  void updatePulseWidth(int channel, bool advance);
127  void applyOperatorLevels(int channel);
128 
129  void setOPLInstrument(int channel, byte instrumentOffset);
130  void noteOn(int channel);
131  void noteOff(int channel);
132  void setFrequency(int channel, uint16 fnum, byte block);
133  void writeFrequency(int channel, uint16 fnum, byte block);
134  void noteToFnumBlock(byte note, uint16 &fnum, byte &block) const;
135 
136  byte readPatternByte(int channel);
137  byte clampNote(byte note) const;
138 };
139 
140 } // namespace Freescape
141 
142 #endif
Definition: area.h:36
Definition: opl.music.h:39
Definition: music.h:29
Definition: fmopl.h:116