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