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  enum ADSRPhase {
55  kPhaseOff,
56  kPhaseAttack,
57  kPhaseDecay,
58  kPhaseSustain,
59  kPhaseRelease
60  };
61 
62  struct ChannelState {
63  const byte *orderList;
64  byte orderPos;
65 
66  uint16 patternDataOffset;
67  uint16 patternOffset;
68 
69  byte instrumentOffset;
70  byte currentNote;
71  byte transpose;
72  uint16 frequencyFnum;
73  byte frequencyBlock;
74 
75  byte durationReload;
76  byte durationCounter;
77 
78  byte effectMode;
79  byte effectParam;
80  byte arpeggioTarget;
81  byte arpeggioParam;
82  byte arpeggioSequencePos;
83  byte arpeggioSequence[9];
84  byte arpeggioSequenceLen;
85 
86  byte noteStepCommand;
87  byte stepDownCounter;
88 
89  byte vibratoPhase;
90  byte vibratoCounter;
91 
92  byte delayValue;
93  byte delayCounter;
94 
95  byte waveform;
96  byte instrumentFlags;
97  bool gateOffDisabled;
98  bool keyOn;
99  uint16 pulseWidth;
100  byte pulseWidthMod;
101  byte pulseWidthDirection;
102  byte modBaseLevel;
103  byte carBaseLevel;
104  byte modLevel;
105  byte carLevel;
106  ADSRPhase adsrPhase;
107  uint16 adsrVolume;
108  uint16 attackRate;
109  uint16 decayRate;
110  byte sustainLevel;
111  uint16 releaseRate;
112 
113  void reset();
114  };
115 
116  OPL::OPL *_opl;
117  bool _musicActive;
118  byte _speedDivider;
119  byte _speedCounter;
120  ChannelState _channels[kChannelCount];
121  byte _arpeggioIntervals[8];
122 
123  void onTimer();
124  void setupSong();
125  void silenceAll();
126  void loadNextPattern(int channel);
127  void buildEffectArpeggio(int channel);
128  void loadCurrentFrequency(int channel);
129  void finalizeChannel(int channel);
130  void processChannel(int channel, bool newBeat);
131  void parseCommands(int channel);
132  void applyNote(int channel, byte note);
133  void applyFrameEffects(int channel);
134  bool applyInstrumentVibrato(int channel);
135  void applyEffectArpeggio(int channel);
136  void applyTimedSlide(int channel);
137  void triggerADSR(int channel, byte ad, byte sr);
138  void releaseADSR(int channel);
139  void updateADSR(int channel);
140  void updatePulseWidth(int channel, bool advance);
141  void applyOperatorLevels(int channel);
142 
143  void setOPLInstrument(int channel, byte instrumentOffset);
144  void noteOn(int channel);
145  void noteOff(int channel);
146  void setFrequency(int channel, uint16 fnum, byte block);
147  void writeFrequency(int channel, uint16 fnum, byte block);
148  void noteToFnumBlock(byte note, uint16 &fnum, byte &block) const;
149 
150  byte readPatternByte(int channel);
151  byte clampNote(byte note) const;
152 };
153 
154 } // namespace Freescape
155 
156 #endif
Definition: area.h:36
Definition: opl.music.h:39
Definition: music.h:29
Definition: fmopl.h:116