API Reference Utility functions and helpers - DhrBaksteen/ArduinoOPL2 GitHub Wiki
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).
-
bytechannel- The channel to play the note on [0,MAX_CHANNEL] -
byteoctave- The octave of the note [0,7] -
bytenote- The note number [0,11] orNOTE_C,NOTE_CSthroughtNOTE_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).
-
bytedrum- The drum sound to play [0,4] -
byteoctave- The octave for the drum sound [0,7] -
bytenote- The note number [0,11] orNOTE_CthroughNOTE_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.
-
bytechannel- 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.
-
bytechannel- Index of the channel [0,MAX_CHANNEL] -
floatfrequency- 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().
-
floatfrequency- 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().
-
bytechannel- Index of the channel [0,MAX_CHANNEL] -
floatfrequency- 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().
-
bytechannel- 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.
-
bytenote- The note index [0,11] where0is a C,1is a C# and11is 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]