ScummVM API documentation
ay.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_AY_MUSIC_H
23 #define FREESCAPE_ECLIPSE_AY_MUSIC_H
24 
25 #include "audio/softsynth/ay8912.h"
26 #include "audio/mixer.h"
27 
28 namespace Freescape {
29 
41 public:
43  ~EclipseAYMusicPlayer() override;
44 
45  void startMusic();
46  void stopMusic();
47  bool isPlaying() const;
48 
49  // AudioStream overrides
50  int readBuffer(int16 *buffer, const int numSamples) override;
51  bool endOfData() const override { return !_musicActive; }
52  bool endOfStream() const override { return false; }
53 
54 private:
55  static const byte kChannelCount = 3;
56  static const byte kMaxNote = 94;
57 
58  enum ADSRPhase {
59  kPhaseOff,
60  kPhaseAttack,
61  kPhaseDecay,
62  kPhaseSustain,
63  kPhaseRelease
64  };
65 
66  struct ChannelState {
67  const byte *orderList;
68  byte orderPos;
69 
70  uint16 patternDataOffset;
71  uint16 patternOffset;
72 
73  byte instrumentOffset;
74  byte currentNote;
75  byte transpose;
76 
77  uint16 currentPeriod;
78 
79  byte durationReload;
80  byte durationCounter;
81 
82  byte effectMode;
83  byte effectParam;
84  byte arpeggioTarget;
85  byte arpeggioParam;
86  byte arpeggioSequencePos;
87  byte arpeggioSequence[9];
88  byte arpeggioSequenceLen;
89 
90  byte noteStepCommand;
91  byte stepDownCounter;
92 
93  byte vibratoPhase;
94  byte vibratoCounter;
95 
96  byte delayValue;
97  byte delayCounter;
98 
99  byte waveform;
100  byte instrumentFlags;
101  bool gateOffDisabled;
102 
103  ADSRPhase adsrPhase;
104  uint16 adsrVolume; // 8.8 fixed point (0x0000 - 0x0F00)
105  uint16 attackRate;
106  uint16 decayRate;
107  byte sustainLevel;
108  uint16 releaseRate;
109 
110  void reset();
111  };
112 
113  Audio::Mixer *_mixer;
114  Audio::SoundHandle _handle;
115  bool _musicActive;
116  byte _speedDivider;
117  byte _speedCounter;
118  byte _mixerRegister;
119  int _tickSampleCount;
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 loadCurrentPeriod(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 
138  void triggerADSR(int channel, byte ad, byte sr);
139  void releaseADSR(int channel);
140  void updateADSR(int channel);
141 
142  byte readPatternByte(int channel);
143  byte clampNote(byte note) const;
144  void writeChannelPeriod(int channel, uint16 period);
145 };
146 
147 } // namespace Freescape
148 
149 #endif
int readBuffer(int16 *buffer, const int numSamples) override
bool endOfStream() const override
Definition: ay.music.h:52
Definition: area.h:36
Definition: ay8912.h:30
Definition: mixer.h:49
Definition: mixer.h:70
Definition: ay.music.h:40
bool endOfData() const override
Definition: ay.music.h:51