-
Notifications
You must be signed in to change notification settings - Fork 39
API Reference Constructors and initialization
OPL2::OPL2();
OPL2::OPL2(byte reset, byte address, byte latch);
Before the OPL2 library can be used 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.
-
byte
reset
- The Arduino pin connected to the RESET pin of the OPL2 Audio Board -
byte
address
- The Arduino pin connected to the A0 pin of the OPL2 Audio Board -
byte
latch
- The Arduino pin connected to the LATCH pin of the OPL2 Audio Board
When no arguments are given the default pins will be used. For Arduino these are:
OPL2 pin | Arduino pin |
---|---|
RESET | 8 |
A0 | 9 |
LATCH | 10 |
The pins for DATA and SHIFT cannot be reassigned.
void OPL2::begin();
The begin
function initializes the library and the OPL2 Audio Board by preparing the IO pins of the Arduino and resetting the chip by calling the reset()
function. It also calls createShadowRegisters()
to set aside a portion of SRAM to contain a copy of the OPL2 registers. This function must be called after creating the library instance, before calling any of the library functions.
For backward compatibility the OPL2::init()
function is still available. Internally this function will call begin()
. The init()
function is deprecated and should no longer be used.
void OPL2::reset();
Reset the OPL2 and clear internal registers. This stops all sound and resets the registers to all zeros. This function is called internally when the library is initialized though the begin()
function.
void OPL2::createShadowRegisters();
This function sets aside a portion of SRAM that will contain a copy of the OPL2 registers. The library uses these registers when reading register values or when changing register values through the getter and setter functions. This function is called from begin()
. Normally you wouldn't call this function.
The OPL2 library will only reserve as many bytes as it needs for the shadow registers. Mind that when your program directly calls the write()
function it will not update the shadow registers!
- OPL2 Audio Board assembly guide
- Connecting the OPL2 Audio Board
- Connecting the OPL3 Duo!
- Troubleshooting
- Definitions
- Constructors and initialization
- Utility functions and helpers
- Instrument functions
- Register getters and setters
- OPL3Duo extensions
- Low level access
- Running OPL2 Audio Board example code on your OPL3 Duo!
- In-depth OPL2 and OPL3 programming guide
- Making a sound
- Working with instruments
- Using the OPL3BankEditor
- DosBox configuration (MIDI only)
- DosBox-X configuration
- Nuke.YKT's serial OPL2/OPL3 protocol
- Bonus project: Touch sensor piano