ScummVM API documentation
maxtrax.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// Only compiled if Kyra is built-in or we're building for dynamic modules
23#if !defined(AUDIO_MODS_MAXTRAX_H) && (defined(ENABLE_KYRA) || defined(DYNAMIC_MODULES))
24#define AUDIO_MODS_MAXTRAX_H
25
26// #define MAXTRAX_HAS_MODULATION
27// #define MAXTRAX_HAS_MICROTONAL
28
29#include "audio/mods/paula.h"
30
31namespace Audio {
32
33class MaxTrax : public Paula {
34public:
35 MaxTrax(int rate, bool stereo, uint16 vBlankFreq = 50, uint16 maxScores = 128);
36 virtual ~MaxTrax();
37
38 bool load(Common::SeekableReadStream &musicData, bool loadScores = true, bool loadSamples = true);
39 bool playSong(int songIndex, bool loop = false);
40 void advanceSong(int advance = 1);
41 int playNote(byte note, byte patch, uint16 duration, uint16 volume, bool rightSide);
42 void setVolume(const byte volume) { Common::StackLock lock(_mutex); _playerCtx.volume = volume; }
43 void setTempo(const uint16 tempo);
44 void stopMusic();
50 void setSignalCallback(void (*callback) (int));
51
52protected:
53 void interrupt() override;
54
55private:
56 enum { kNumPatches = 64, kNumVoices = 4, kNumChannels = 16, kNumExtraChannels = 1 };
57 enum { kPriorityScore, kPriorityNote, kPrioritySound };
58
59#ifdef MAXTRAX_HAS_MICROTONAL
60 int16 _microtonal[128];
61#endif
62
63 struct Event {
64 uint16 startTime;
65 uint16 stopTime;
66 byte command;
67 byte parameter;
68 };
69
70 const struct Score {
71 const Event *events;
72 uint32 numEvents;
73 } *_scores;
74
75 int _numScores;
76
77 struct {
78 uint32 sineValue;
79 uint16 vBlankFreq;
80 int32 ticks;
81 int32 tickUnit;
82 uint16 frameUnit;
83
84 uint16 maxScoreNum;
85 uint16 tempo;
86 uint16 tempoInitial;
87 uint16 tempoStart;
88 int16 tempoDelta;
89 int32 tempoTime;
90 int32 tempoTicks;
91
92 byte volume;
93
94 bool filterOn;
95 bool handleVolume;
96 bool musicLoop;
97
98 int scoreIndex;
99 const Event *nextEvent;
100 int32 nextEventTime;
101
102 void (*syncCallBack) (int);
103 const Event *repeatPoint[4];
104 byte repeatCount[4];
105 } _playerCtx;
106
107 struct Envelope {
108 uint16 duration;
109 uint16 volume;
110 };
111
112 struct Patch {
113 const Envelope *attackPtr;
114 //Envelope *releasePtr;
115 uint16 attackLen;
116 uint16 releaseLen;
117
118 int16 tune;
119 uint16 volume;
120
121 // this was the SampleData struct in the assembler source
122 const int8 *samplePtr;
123 uint32 sampleTotalLen;
124 uint32 sampleAttackLen;
125 uint16 sampleOctaves;
126 } _patch[kNumPatches];
127
128 struct ChannelContext {
129 const Patch *patch;
130 uint16 regParamNumber;
131
132 uint16 modulation;
133 uint16 modulationTime;
134
135 int16 microtonal;
136
137 uint16 portamentoTime;
138
139 int16 pitchBend;
140 int16 pitchReal;
141 int8 pitchBendRange;
142
143 uint8 volume;
144// uint8 voicesActive;
145
146 enum {
147 kFlagRightChannel = 1 << 0,
148 kFlagPortamento = 1 << 1,
149 kFlagDamper = 1 << 2,
150 kFlagMono = 1 << 3,
151 kFlagMicrotonal = 1 << 4,
152 kFlagModVolume = 1 << 5
153 };
154 byte flags;
155 bool isAltered;
156
157 uint8 lastNote;
158// uint8 program;
159
160 } _channelCtx[kNumChannels + kNumExtraChannels];
161
162 struct VoiceContext {
163 ChannelContext *channel;
164 const Patch *patch;
165 const Envelope *envelope;
166// uint32 uinqueId;
167 int32 preCalcNote;
168 uint32 ticksLeft;
169 int32 portaTicks;
170 int32 incrVolume;
171// int32 periodOffset;
172 uint16 envelopeLeft;
173 uint16 noteVolume;
174 uint16 baseVolume;
175 uint16 lastPeriod;
176 byte baseNote;
177 byte endNote;
178 byte octave;
179// byte number;
180// byte link;
181 enum {
182 kStatusFree,
183 kStatusHalt,
184 kStatusDecay,
185 kStatusRelease,
186 kStatusSustain,
187 kStatusAttack,
188 kStatusStart
189 };
190 uint8 isBlocked;
191 uint8 priority;
192 byte status;
193 byte lastVolume;
194 byte tieBreak;
195 bool hasDamper;
196 bool hasPortamento;
197 byte dmaOff;
198
199 int32 stopEventTime;
200 } _voiceCtx[kNumVoices];
201
202 void controlCh(ChannelContext &channel, byte command, byte data);
203 void freePatches();
204 void freeScores();
205 void resetChannel(ChannelContext &chan, bool rightChannel);
206 void resetPlayer();
207
208 int8 pickvoice(uint pick, int16 pri);
209 uint16 calcNote(const VoiceContext &voice);
210 int8 noteOn(ChannelContext &channel, byte note, uint16 volume, uint16 pri);
211 void killVoice(byte num);
212 void freeResources(bool loadScores, bool loadSamples);
213
214 static void outPutEvent(const Event &ev, int num = -1);
215 static void outPutScore(const Score &sc, int num = -1);
216};
217} // End of namespace Audio
218
219#endif // !defined(AUDIO_MODS_MAXTRAX_H)
Definition: stream.h:745
Definition: mutex.h:51
Definition: system.h:39