aboutsummaryrefslogtreecommitdiff
path: root/audio/softsynth/fmtowns_pc98/towns_euphony.h
blob: bff0e99660fe090a0daf3408a75de66f45d622f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef TOWNS_EUP_H
#define TOWNS_EUP_H

#include "audio/softsynth/fmtowns_pc98/towns_audio.h"

class TownsEuphonyDriver : public TownsAudioInterfacePluginDriver {
public:
	TownsEuphonyDriver(Audio::Mixer *mixer);
	virtual ~TownsEuphonyDriver();

	bool init();
	void reset();

	void loadInstrument(int chanType, int id, const uint8 *data);
	void loadWaveTable(const uint8 *data);
	void unloadWaveTable(int id);
	void reserveSoundEffectChannels(int num);

	int setMusicTempo(int tempo);
	int startMusicTrack(const uint8 *data, int trackSize, int startTick);
	void setMusicLoop(bool loop);
	void stopParser();
	bool parserIsPlaying() {return _playing; }
	void continueParsing();

	void playSoundEffect(int chan, int note, int velo, const uint8 *data);
	void stopSoundEffect(int chan);
	bool soundEffectIsPlaying(int chan);

	void chanPanPos(int chan, int mode);
	void chanPitch(int chan, int pitch);
	void chanVolume(int chan, int vol);

	void setOutputVolume(int chanType, int volLeft, int volRight);

	int configChan_enable(int tableEntry, int val);
	int configChan_setMode(int tableEntry, int val);
	int configChan_remap(int tableEntry, int val);
	int configChan_adjustVolume(int tableEntry, int val);
	int configChan_setTranspose(int tableEntry, int val);

	int assignChannel(int chan, int tableEntry);

	void timerCallback(int timerId);

	void setMusicVolume(int volume);
	void setSoundEffectVolume(int volume);

	TownsAudioInterface *intf() {
		return _intf;
	}

private:
	void resetTables();

	void resetTempo();
	void setTempoIntern(int tempo);
	void setTimerA(bool enable, int tempo);
	void setTimerB(bool enable, int tempo);

	void updatePulseCount();
	void updateTimeStampBase();
	void updateParser();
	void updateCheckEot();

	bool parseNext();
	void jumpNextLoop();

	void updateEventBuffer();
	void flushEventBuffer();
	void processBufferNote(int mode, int evt, int note, int velo);

	void resetControl();
	void resetControlIntern(int mode, int chan);
	uint8 appendEvent(uint8 evt, uint8 chan);

	void sendEvent(uint8 mode, uint8 command);

	typedef bool(TownsEuphonyDriver::*EuphonyOpcode)();
	bool evtSetupNote();
	bool evtPolyphonicAftertouch();
	bool evtControlPitch();
	bool evtInstrumentChanAftertouch();
	bool evtLoadInstrument();
	bool evtAdvanceTimestampOffset();
	bool evtTempo();
	bool evtModeOrdrChange();
	bool evtNotImpl() {
		return false;
	}

	uint8 applyTranspose(uint8 in);
	uint8 applyVolumeAdjust(uint8 in);

	void sendNoteOff();
	void sendNoteOn();
	void sendChanVolume();
	void sendPanPosition();
	void sendAllNotesOff();
	void sendSetInstrument();
	void sendPitch();

	int8 *_activeChannels;
	int8 *_sustainChannels;

	struct ActiveChannel {
		int8 chan;
		int8 next;
		uint8 note;
		uint8 sub;
	} *_assignedChannels;

	uint8 *_tEnable;
	uint8 *_tMode;
	uint8 *_tOrdr;
	int8 *_tLevel;
	int8 *_tTranspose;

	struct DlEvent {
		uint8 evt;
		uint8 mode;
		uint8 note;
		uint8 velo;
		uint16 len;
	} *_eventBuffer;
	int _bufferedEventsCount;

	uint8 _para[2];
	uint8 _paraCount;
	uint8 _command;

	uint8 _defaultBaseTickLen;
	uint8 _baseTickLen;
	uint32 _pulseCount;
	int _tempoControlMode;
	int _extraTimingControlRemainder;
	int _extraTimingControl;
	int _timerSetting;
	int8 _tempoDiff;
	int _tempoModifier;
	uint32 _timeStampDest;
	uint32 _timeStampBase;
	int8 _elapsedEvents;
	uint8 _deltaTicks;
	uint32 _tickCounter;
	uint8 _defaultTempo;
	int _trackTempo;

	bool _loop;
	bool _playing;
	bool _endOfTrack;
	bool _suspendParsing;

	const uint8 *_musicStart;
	const uint8 *_musicPos;
	uint32 _musicTrackSize;

	TownsAudioInterface *_intf;
};

#endif