API Reference Utility functions and helpers - DhrBaksteen/ArduinoOPL2 GitHub Wiki

getNumChannels

byte OPL2::getNumChannels();

Get the number of channels for the OPL chip you're using. This gives you the MAX_CHANNEL as getNumChannels() - 1.

Returns

byte The number of channels for the OPL implementation being used (9 for OPL2 or 36 for OPL3Duo)

playNote

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).

Arguments
  • 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] or NOTE_C, NOTE_CS throught NOTE_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

playDrum

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).

Arguments
  • 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] or NOTE_C through NOTE_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

getFrequency

float OPL2::getFrequency(byte channel);

Get the frequency of the given channel in Hz based on the current block and F-number.

Arguments
  • byte channel - Index of the channel [0, MAX_CHANNEL]
Returns

float The frequency of the given channelv in Hz

setFrequency

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.

Arguments
  • byte channel - Index of the channel [0, MAX_CHANNEL]
  • float frequency - The frequency to set in Hz

getFrequencyBlock

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().

Arguments
  • float frequency - The desired frequency in Hz for which we want to know the block number
Returns

byte The block number to use for the given frequency [0, 7]

getFrequencyFNumber

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().

Arguments
  • byte channel - Index of the channel [0, MAX_CHANNEL]
  • float frequency - The desired frequency in Hz
Returns

short The F-number of the given frequency [0, 1023]

getFrequencyStep

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().

Arguments
  • byte channel - Index of the channel for which to set attack rate [0, MAX_CHANNEL]
Returns

float The difference in frequency (in Hz) between two F-numbers for the current block

getNoteFNumber

short OPL2::getNoteFNumber(byte note);

Get the appropriate F-number fot the given note. This function assumes that block numbers are interpreted as octaves.

Arguments
  • byte note - The note index [0, 11] where 0 is a C, 1 is a C# and 11 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
Returns

short The F-number of the note [0, 1023]

⚠️ **GitHub.com Fallback** ⚠️