-
Notifications
You must be signed in to change notification settings - Fork 39
API Reference Instrument functions
Instrument OPL2::createInstrument();
Create a new blank instrument structure.
Instrument OPL2::loadInstrument(const unsigned char *instrument, bool fromProgmem = INSTRUMENT_DATA_PROGMEM);
Instrument OPL2::loadInstrument(const unsigned char *instrument); // Raspberry Pi only!
Create an Instrument
structure from an array of 12-bytes of instrument data either in PROGMEM
or SRAM. On Raspberry Pi instrument data con only be loaded from SRAM.
An instrument data array has the following structure:
Index | Data |
---|---|
0 | Rhythm mode drum channel. Drum channels are predefined by the YM3812 and cannot be redefined. Regular instruments have their channel set to `0x00` and can be assigned to any channel by the setInstrument function. Rhythm mode instruments can only be used when rhythm mode is active (see OPL2.setPercussion). |
1 | Operator 1, register 0x20 |
2 | Operator 1, register 0x40 |
3 | Operator 1, register 0x60 |
4 | Operator 1, register 0x80 |
5 | Operator 1, register 0xE0 |
6 | Register 0xC0 |
7 | Operator 2, register 0x20 |
8 | Operator 2, register 0x40 |
9 | Operator 2, register 0x60 |
10 | Operator 2, register 0x80 |
11 | Operator 2, register 0xE0 |
If the loaded instrument has its instrument.type
to 0 or INSTRUMENT_TYPE_MELODIC
then it can be assigned to any channel using the setInstrument()
. If this value is non-zero then is should be set using setDruminstrument()
and it will assigned to the appropriate percussion channel.
Drum | Instrument type definition | Channel |
---|---|---|
Melodic | INSTRUMENT_TYPE_MELODIC | any |
Bass | INSTRUMENT_TYPE_BASS | 6 |
Snare | INSTRUMENT_TYPE_SNARE | 7 |
Tom tom | INSTRUMENT_TYPE_TOM | 8 |
Cymbal | INSTRUMENT_TYPE_CYMBAL | 9 |
Hi-hat | INSTRUMENT_TYPE_HI_HAT | 10 |
-
const unsigned char
*instrument
- Pointer to the start of the instrument data array -
bool
fromProgmem
- When set totrue
(default) the data of the instrument is located inPROGMEM
Instrument
New Instrument
structure created from the 12-byte data structure
void OPL2::setInstrument(byte channel, Instrument instrument, float volume = 1.0);
Set the given instrument to a certain channel. This will load all the operators of the channel with the instrument data.
-
byte
channel
- Index of the channel [0
,MAX_CHANNEL
] -
Instrument
instrument
- The instrument structure -
float
volume
- Optional volume for the instrument [0.0
,1.0
] where 0.0 is silence and 1.0 is full volume. By defaultvolume
will be 1.0.
void OPL2::setDrumInstrument(Instrument instrument, float volume = 1.0);
Set the given drum instrument to the drum channel that is defined in the Instrument
structure.
-
Instrument
instrument
- The instrument structure -
float
volume
- Optional volume to apply to the drum channel. Defaults to full volume
Instrument OPL2::getInstrument(byte channel);
Convert the given channel into an instrument structure.
-
byte
channel
- Index of the channel [0
,MAX_CHANNEL
]
Instrument
New Instrument
structure converted from the given channel
Instrument OPL2::getDrumInstrument(byte drumType);
Convert the channel parameters of the given drum type into an instrument structure.
-
byte
drumType
- Type of drum from which to create the instrument [6
,10
]
Drum | Instrument type definition | Value |
---|---|---|
Bass | INSTRUMENT_TYPE_BASS | 6 |
Snare | INSTRUMENT_TYPE_SNARE | 7 |
Tom tom | INSTRUMENT_TYPE_TOM | 8 |
Cymbal | INSTRUMENT_TYPE_CYMBAL | 9 |
Hi-hat | INSTRUMENT_TYPE_HI_HAT | 10 |
Instrument
New Instrument
structure converted from the the channel used for the given drum type
- 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