-
Notifications
You must be signed in to change notification settings - Fork 39
API Reference Utility functions and helpers
byte OPL2::getNumChannels();
Get the number of channels for the OPL chip you're using. This gives you the MAX_CHANNEL
as getNumChannels() - 1
.
byte
The number of channels for the OPL implementation being used (9 for OPL2
or 36 for OPL3Duo
)
void OPL2::playNote(byte channel, byte octave, byte note);
Play a note on a particular channel. This function combines the setkeyon()
, setBlock()
and setFNumber()
functions into a single convenient function to play a note. To stop playing use setKeyOn(channel, false)
.
-
byte
channel
- The channel to play the note on [0
,MAX_CHANNEL
] -
byte
octave
- The octave of the note [0
,7
] -
byte
note
- The note number [0
,11
] orNOTE_C
,NOTE_CS
throughtNOTE_B
Following notes are defined in the library:
Note | Definition | Value |
---|---|---|
C | NOTE_C | 0 |
C# | NOTE_CS | 1 |
D | NOTE_D | 2 |
D# | NOTE_DS | 3 |
E | NOTE_E | 4 |
F | NOTE_F | 5 |
F# | NOTE_FS | 6 |
G | NOTE_G | 7 |
G# | NOTE_GS | 8 |
A | NOTE_A | 9 |
A# | NOTE_AS | 10 |
B | NOTE_B | 11 |
void playDrum(byte drum, byte octave, byte note);
Play the given drum sound at the given pitch. The OPL2 must be put in percussive mode before this function can be used with setPercussion(true)
.
-
byte
drum
- The drum sound to play [0
,4
] -
byte
octave
- The octave for the drum sound [0
,7
] -
byte
note
- The note number [0
,11
] orNOTE_C
throughNOTE_B
The following drum sounds are defined:
Drum sound | Definition | Value |
---|---|---|
Bass drum | DRUM_BASS | 0 |
Snare drum | DRUM_SNARE | 1 |
Tom tom | DRUM_TOM | 2 |
Cymbal | DRUM_CYMBAL | 3 |
Hi-hat | DRUM_HI_HAT | 4 |
Following notes are defined in the library:
Note | Definition | Value |
---|---|---|
C | NOTE_C | 0 |
C# | NOTE_CS | 1 |
D | NOTE_D | 2 |
D# | NOTE_DS | 3 |
E | NOTE_E | 4 |
F | NOTE_F | 5 |
F# | NOTE_FS | 6 |
G | NOTE_G | 7 |
G# | NOTE_GS | 8 |
A | NOTE_A | 9 |
A# | NOTE_AS | 10 |
B | NOTE_B | 11 |
float OPL2::getFrequency(byte channel);
Get the frequency of the given channel in Hz based on the current block and F-number.
-
byte
channel
- Index of the channel [0
,MAX_CHANNEL
]
float
The frequency of the given channelv in Hz
void OPL2::setFrequency(byte channel, float frequency);
Set the frequency of a channel to the given frequency in Hz and change the block number if needed. This will not change the keyOn
state of the channel.
-
byte
channel
- Index of the channel [0
,MAX_CHANNEL
] -
float
frequency
- The frequency to set in Hz
byte OPL2::getFrequencyBlock(float frequency);
Get the block number that is appropriate for the given frequency. This block number can then be set using setBlock()
.
-
float
frequency
- The desired frequency in Hz for which we want to know the block number
byte
The block number to use for the given frequency [0
, 7
]
short OPL2::getFrequencyFNumber(byte channel, float frequency);
Get the F-number to play a given frequency on a channel. The F-number that is returned depends on the current frequency block of the channel that was set prior using setBlock()
. The F-number that is returned can be set using setFNumber()
.
-
byte
channel
- Index of the channel [0
,MAX_CHANNEL
] -
float
frequency
- The desired frequency in Hz
short
The F-number of the given frequency [0
, 1023
]
float OPL2::getFrequencyStep(byte channel);
Get the difference in frequency between two F-numbers on the given channel. This depends on the current frequency block of the channel that was set prior using setBlock()
.
-
byte
channel
- Index of the channel for which to set attack rate [0
,MAX_CHANNEL
]
float
The difference in frequency (in Hz) between two F-numbers for the current block
short OPL2::getNoteFNumber(byte note);
Get the appropriate F-number fot the given note. This function assumes that block numbers are interpreted as octaves.
-
byte
note
- The note index [0
,11
] where0
is a C,1
is a C# and11
is a B.
Following notes are defined in the library:
Note | Definition | Value |
---|---|---|
C | NOTE_C | 0 |
C# | NOTE_CS | 1 |
D | NOTE_D | 2 |
D# | NOTE_DS | 3 |
E | NOTE_E | 4 |
F | NOTE_F | 5 |
F# | NOTE_FS | 6 |
G | NOTE_G | 7 |
G# | NOTE_GS | 8 |
A | NOTE_A | 9 |
A# | NOTE_AS | 10 |
B | NOTE_B | 11 |
short
The F-number of the note [0
, 1023
]
- 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