OPL3Duo Extensions - DhrBaksteen/ArduinoOPL2 GitHub Wiki
This page describes the OPL3Duo functions of the OPL2 library. These functions are intended to be used with the OPL3 Duo! board. using them on an OPL2 Audio board will not work or give unexpected results.
The OPL3Duo functions are an extension to the OPL2 library for the OPL3 Duo! board. All OPL2 library functions are still supported, but since the OPL3 Duo has two OPL3 chips you have control over 36 channels instead of 9. You can access these channels as if they were all on one chip and the library will take care of writing to the chip that holds the actual channel. Channels 0 .. 17 are on chip 0 and channels 18 .. 35 on chip 1.
OPL3Duo::OPL3Duo();
OPL3Duo::OPL3Duo(byte a2, byte a1, byte a0, byte latch, byte reset);
Before the OPL2 library can be used with the OPL3 Duo! we first must create an instance of it. There are two constructors available for this; a default constructor which will create a new library instance with default pin numbers and a constructor that allows you to define custom pins to suit your setup. After createing the OPL3Duo
instance the begin()
function must be called to initialize the board.
-
byte
a2
- The Arduino pin connected to the A2 pin of the OPL3 Duo! board. -
byte
a1
- The Arduino pin connected to the A1 pin of the OPL3 Duo! board. -
byte
a0
- The Arduino pin connected to the A0 pin of the OPL3 Duo! board. -
byte
latch
- The Arduino pin connected to the /WR pin of the OPL3 Duo! board. -
byte
reset
- The Arduino pin connected to the /IC pin of the OPL3 Duo! board.
When no arguments are given the default pins will be used. For Arduino these are:
OPL3 Duo! | Arduino pin |
---|---|
A2 | 6 |
A1 | 7 |
A0 | 8 |
/WR | 10 |
/IC | 9 |
The pins for MOSI and SCK cannot be reassigned.
byte OPL3Duo::getNum4OPChannels();
Get the number of channels that can be configured to work in 4-operator mode. This gives you the MAX_CHANNEL_4OP
as getNum4OPChannels() - 1
. For the OPL3 Duo! board the number of 4-operator channels will be 12.
byte
The number of channels that can be used in 4-operator mode. This will be 12 for the OPL3 Duo!
byte OPL3Duo::get4OPControlChannel(byte channel4OP, byte index2OP = 0);
Get the channel number of one of the 2-operator channels that make up a 4-operator channel. By default this function returns the first 2-operator channel that is also in control of the frequency, key-on, panning, etc. of the 4-operator channel.
4-Operator channels work by grouping two 2-operator channels. The fist of the two grouped channels controls the 4-operator channel in the same way as if it were a 2-operator channel. In other words to start playing a note on a 4-operator channel, for example, you would set the key-on of the first (index 0) of the two grouped channels.
-
byte
channel4OP
- The 4-operator channel [0
,MAX_CHANNEL_4OP
] for which we want to know the index of one of the tho grouped 2-operator channels. -
byte
index2OP
- Optional index [0
,1
] of the 2-operator channel in the group. By default control channel (0) will be requested.
byte
The index of the 2-operator channel.
bool OPL3Duo::isOPL3Enabled();
bool OPL3Duo::isOPL3Enabled(byte synthUnit);
Returns wheter OPL3 mode is enabled on both synth chips or one of the two. Before any of the OPL3 functions can be used OPL3 mode must be enabled. After a reset the OPL3 chips of the OPL3 Duo! will be in OPL2 mode and this function will return false
.
bool
True if OPL3 mode is enabled for the chip. When the isOPL3Enabled()
function (without arguments) is called it will return whether both OPL chips have OPL3 mode enabled.
void OPL3Duo::setOPL3Enabled(bool enable);
void OPL3Duo::setOPL3Enabled(byte synthUnit, bool enable);
Enable OPL3 function on both or one of two OPL3 chips. OPL3 mode must be enabled before any of the OPL3 extensions such as 4-operator mode can be used. After a reset both OPL3 chips of the OPL3 Duo! will have their OPL3 mode disabled and function as OPL2s.
-
bool
enable
- Enables or disables OPL3 functions on the chip(s). -
byte
synthUnit
- Syhtn chip [0
,1
] for which to enable or diable OPL3 functions. If omitted then OPL3 mode will be altered for both synth chips.
bool OPL3Duo::is4OPChannelEnabled(byte channel4OP);
Return whether the given 4-operator channel is enabled (i.e. the two 2-operator channels making up the 4-operator channel have been grouped into a 4-operator channel).
-
byte
channel4OP
- The 4-operator channel index [0
,MAX_CHANNEL_4OP
] for which we want to know if 4-operator synthesis is enabled.
bool
true if the given 4-operator channel is enabled.
void OPL3Duo::set4OPChannelEnabled(byte channel4OP, bool enable);
Enables or disables 4-operator synthesis for the given 4-operator channel. This effectively groups or ungroups the tow 2-operator channels that make up the 4-operator channel.
-
byte
channel4OP
- The 4-operator channel index [0
,MAX_CHANNEL_4OP
] that we want to enable or disable -
bool
enable
- Enables 4-operator synthesis on the channel iftrue
void OPL3Duo::setAll4OPChannelsEnabled(bool enable);
Enables or disables 4-operator synthesis for all 4-operator channels.
bool OPL3Duo::isPannedLeft (byte channel);
Returns whether the given channel has the left panning bit enabled. In other words, if the left speaker will output sound.
-
byte
channel
- The channel [0
,MAX_CHANNEL
] to get left panning
bool
True if the panning bit for the left speaker is enabled
bool OPL3Duo::isPannedRight(byte channel);
Returns whether the given channel has the right panning bit enabled. In other words, if the right speaker will output sound.
-
byte
channel
- The channel [0
,MAX_CHANNEL
] to get right panning
bool
True if the panning bit for the right speaker is enabled
void OPL3Duo::setPanning(byte channel, bool left, bool right);
Set the panning of the given channel.
-
byte
channel
- The channel [0
,MAX_CHANNELS
] for which to set the panning -
bool
left
- Enables the left speaker whentrue
-
bool
right
- Enables the right speaker whentrue
byte OPL3Duo::get4OPSynthMode(byte channel4OP);
The the 4-operator synthesizer configuration of the given 4-operator channel by examining the synth-mode of the two grouped 2-operator channels.
byte
channel4OP
- The 4-operator channel [0
, MAX_CHANNEL_4OP
] for which we want to know the synthesizer configuration
byte
The synthesizer configuration
Value | Synth mode | Definition |
---|---|---|
0 | FM - FM | SYNTH_MODE_FM_FM |
1 | FM - AM | SYNTH_MODE_FM_AM |
2 | AM - FM | SYNTH_MODE_AM_FM |
3 | AM - AM | SYNTH_MODE_AM_AM |
void set4OPSynthMode(byte channel4OP, byte synthMode);
Set the 4-operator synthesizer configuration of the given 4-operator channel.
byte
channel4OP
- The 4-operator channel [0
, MAX_CHANNEL_4OP
] for which we want to shange the synthesizer configuration
byte
synthMode
- The synthesizer configuration to set:
Value | Synth mode | Definition |
---|---|---|
0 | FM - FM | SYNTH_MODE_FM_FM |
1 | FM - AM | SYNTH_MODE_FM_AM |
2 | AM - FM | SYNTH_MODE_AM_FM |
3 | AM - AM | SYNTH_MODE_AM_AM |