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