-
Notifications
You must be signed in to change notification settings - Fork 7
/
OPL2.h
128 lines (113 loc) · 3.08 KB
/
OPL2.h
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
#ifndef OPL2_LIB_H_
#define OPL2_LIB_H_
#ifdef __linux__
#include <ieee1284.h>
#define LPT_PORT struct parport *
#else
#define LPT_PORT short
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
// Operator definitions.
#define OPERATOR1 false
#define OPERATOR2 true
#define MODULATOR false
#define CARRIER true
// Synthesis type definitions.
#define FREQ_MODULATION false
#define ADDITIVE_SYNTH true
// Drum sounds.
#define DRUM_BASS 0x10
#define DRUM_SNARE 0x08
#define DRUM_TOM 0x04
#define DRUM_CYMBAL 0x02
#define DRUM_HI_HAT 0x01
// Note to frequency mapping.
#define NOTE_C 0
#define NOTE_CS 1
#define NOTE_D 2
#define NOTE_DS 3
#define NOTE_E 4
#define NOTE_F 5
#define NOTE_FS 6
#define NOTE_G 7
#define NOTE_GS 8
#define NOTE_A 9
#define NOTE_AS 10
#define NOTE_B 11
#include <stdint.h>
typedef uint8_t byte;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define PROGMEM
class OPL2 {
public:
OPL2();
void init(LPT_PORT lpt_base);
void reset();
void write(unsigned, byte);
short getNoteFrequency(byte, byte, byte);
byte getRegister(byte);
bool getWaveFormSelect();
bool getTremolo(byte, bool);
bool getVibrato(byte, bool);
bool getMaintainSustain(byte, bool);
bool getEnvelopeScaling(byte, bool);
byte getMultiplier(byte, bool);
byte getScalingLevel(byte, bool);
byte getVolume(byte, bool);
byte getAttack(byte, bool);
byte getDecay(byte, bool);
byte getSustain(byte, bool);
byte getRelease(byte, bool);
short getFrequency(byte);
byte getBlock(byte);
bool getKeyOn(byte);
byte getFeedback(byte);
bool getSynthMode(byte);
bool getDeepTremolo();
bool getDeepVibrato();
bool getPercussion();
byte getDrums();
byte getWaveForm(byte, bool);
void setInstrument(byte, const unsigned char*);
byte setRegister(byte, byte);
byte setWaveFormSelect(bool);
byte setTremolo(byte, bool, bool);
byte setVibrato(byte, bool, bool);
byte setMaintainSustain(byte, bool, bool);
byte setEnvelopeScaling(byte, bool, bool);
byte setMultiplier(byte, bool, byte);
byte setScalingLevel(byte, bool, byte);
byte setVolume(byte, bool, byte);
byte setAttack(byte, bool, byte);
byte setDecay(byte, bool, byte);
byte setSustain(byte, bool, byte);
byte setRelease(byte, bool, byte);
byte setFrequency(byte, short);
byte setBlock(byte, byte);
byte setKeyOn(byte, bool);
byte setFeedback(byte, byte);
byte setSynthMode(byte, bool);
byte setDeepTremolo(bool);
byte setDeepVibrato(bool);
byte setPercussion(bool);
byte setDrums(bool, bool, bool, bool, bool);
byte setWaveForm(byte, bool, byte);
void setOPL3Mode(bool);
byte setOPL3Channels(byte, byte);
private:
const static unsigned fIntervals[8];
const static unsigned notes[12];
const static byte offset[2][9];
const static byte drumOffset[6];
const static byte instrumentBaseRegs[11];
LPT_PORT lpt_base;
byte oplRegisters[256];
byte getRegisterOffset(byte, bool);
};
#endif