Skip to content

Commit

Permalink
Merge pull request #62 from DhrBaksteen/OPL3Duo
Browse files Browse the repository at this point in the history
Library version 2.0.0 adding support for OPL3 Duo
  • Loading branch information
DhrBaksteen authored Oct 31, 2020
2 parents 3284cf3 + c4654a8 commit dfc52b7
Show file tree
Hide file tree
Showing 71 changed files with 4,630 additions and 1,106 deletions.
50 changes: 14 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# OPL2 Audio Board
This repository contains the OPL2 Audio Board library for Arduino, Teensy, Raspberry Pi and compatible boards as well as a number of examples on how the board can be used. You can use the OPL2 Audio Board to:
* Experiment with the YM3812 chip
# Arduino OPL2 Library
This repository contains the OPL2 / OPL3 audio library for the OPL2 Audio Board or OPL3 Duo! board. It is compatible with Arduino, Teensy, Raspberry Pi and other Arduino-like boards. A number of examples are included on how the library can be used. You can use the OPL2 Audio Board or OPL3 Duo! to:
* Experiment with the YM3812 or YMF262 chip
* Build your own synthesizer
* Play your own OPL2 tunes
* Instrument definitions from Adlib, The Fat Man and Windows 3.1 included in the library
* Instrument definitions from Adlib and The Fat Man are included in the library for both 2-op OPL3 and 4-op OPL3.
* Play exported OPL2 music (DRO, IMF, VGM) or Reality Adlib Tracker music files
* Use the board as a MIDI synthesizer (Teensy++ 2.0 and later example included)
* Emulation with DosBox; you can use the board to output MIDI music (Teensy++ 2.0 and later)
* Use the board directly as a synthesizer by using the [OPL3BankEditor](https://github.com/Wohlstand/OPL3BankEditor) software by Wohlstand

Current library version is 1.5.3

To obtain your own OPL2 Audio Board visit the [Tindie store](https://www.tindie.com/products/DhrBaksteen/opl2-audio-board/).
Current library version is 2.0.0

### OPL2 Audio Board
The OPL2 Audio Board is fun and easy board to get started with an OPL2 synthesizer. It is built around the YM3812 OPL2 chip that gives you 9 channels with 2-operators each to produce the classic OPL2 sound that you may remember from early 90s computer games.
For more info visit the [Hackaday project page](https://hackaday.io/project/18995-opl2-audio-board-for-arduino-raspberry-pi).

To obtain your own OPL2 Audio Board visit my [Tindie store](https://www.tindie.com/products/DhrBaksteen/opl2-audio-board/).
![](https://raw.githubusercontent.com/DhrBaksteen/ArduinoOPL2/master/extra/OPL2_board.jpg)


## 1. Assembling the kit
For a step by step guide on how to assemble the kit please read the [Assembly guide](https://github.com/DhrBaksteen/ArduinoOPL2/blob/master/assembling.md).
### OPL3 Duo! Board
The OPL3 Duo! is a more capable version of the OPL2 Audio Board. It has 2 YMF262 OPL3 chips that allow for up to 36 channels of 2-operator sounds or up to 12 4-operator + 12 2-operator sounds. It also has stereo sound and is fully OPL2 compatible. Each OPL3 chip can be controlled individually or the library can control the board as if it were one big OPL3 chip with 36 channels.

The OPL3 Duo! board is available on my [Tindie store](https://www.tindie.com/products/cheerful/opl3-duo/).
![](https://raw.githubusercontent.com/DhrBaksteen/ArduinoOPL2/master/extra/OPL3Duo_board.jpg)


## 2. Installing the library
## 1. Installing the library
#### Arduino / Teensy
The easiest way to install the library it do download it through the Arduino Library Manager. Open the Library Manager from your Arduino IDE's Sketch > Include Library > Library Manager menu. A new window will open that allows you to search for a library. Search for 'Arduino OPL2' and it should show this libarary. Select the library, click the install button and you're good to go.

Expand All @@ -32,29 +36,3 @@ For more information see the [instructions](https://www.arduino.cc/en/Guide/Libr

#### Raspberry Pi / Orange Pi and compatibles
To install the library onto your Pi clone this repo and run `./build`. The OPL2 library requires [WiringPi](http://wiringpi.com/) to be installed on your Pi. Normally this library is already installed, but if this is not the case then the build script can install it for you.


## 3. Connecting the OPL2 Audio Board
You can connect the OPL2 Audio Board directly to a speaker, however for the best results I recommend you connect some active (amplified) speakers. Headphones or line level recording will also work great. See the table below how to connect the OPL2 Audio Board to an Arduino. [Visit the wiki](https://github.com/DhrBaksteen/ArduinoOPL2/wiki/Connecting) to learn how to connect the OPL2 AUdio Board to your favorite development platform.

#### Arduino
| OPL2 Board | Arduino Pin |
|------------|-------------|
| A0 | 9 |
| Data | 11 |
| Latch | 10 |
| Shift | 13 |
| Reset | 8 |


## 4. Using the OPL2 Audio Board
#### Arduino
After installing the library and restarting the Arduino IDE you will find a number of examples under the File > Examples > ArduinoOPL2 menu. These examples can be found in the `examples` folder of the library.

#### Teensy
Most Arduino examples will also work directly on a Teensy. The examples that require an SD card (PlayDRO, PlayIMG and PlayRAD) are Teensy specific when you use the Teensy's on board SD card slot. Teensy++ 2.0 and later can be configured as MIDI device. An example for this can be found among the Teensy specific examples in the `examples/teensy` folder.

#### Raspberry Pi / Orange Pi
After building the library you will find a number of examples in the `examples_pi` folder. The examples have been compiled during installation of the library, so you should be ready to dive right in! Try running `sudo ./demotune` for example from the `examples_pi/demotune` folder.

When compiling your own code using the OPL2 library don't forget to specify the library using the `-lOPL2` argument e.g. `gcc -std=c++11 -Wall -o my_program my_program.cpp -lOPL2 -lwiringPi`
74 changes: 0 additions & 74 deletions examples/Drums/Drums.ino

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void setup() {
music[i] = channel;
}

opl2.init();
opl2.begin();

// Setup channels 0, 1 and 2.
Instrument piano = opl2.loadInstrument(INSTRUMENT_PIANO1);
Expand Down
74 changes: 74 additions & 0 deletions examples/OPL2AudioBoard/Drums/Drums.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* This is a simple demo sketch for the OPL2 library. It plays a drum loop using instrument settings form the Adlib
* standard instrument library. Note that channel 6 is used by the base drum, 7 is used by snare and hi-hat and 8 is
* used by tom tom and cymbal.
*
* OPL2 board is connected as follows:
* Pin 8 - Reset
* Pin 9 - A0
* Pin 10 - Latch
* Pin 11 - Data
* Pin 13 - Shift
*
* Refer to the wiki at https://github.com/DhrBaksteen/ArduinoOPL2/wiki/Connecting to learn how to connect your platform
* of choice!
*
* Code by Maarten Janssen (maarten@cheerful.nl) 2017-04-13
* Most recent version of the library can be found at my GitHub: https://github.com/DhrBaksteen/ArduinoOPL2
*/


#include <SPI.h>
#include <OPL2.h>
#include <instruments.h>


OPL2 opl2;
int i = 0;


void setup() {
opl2.begin();

// Set percussion mode and load instruments.
Instrument bass = opl2.loadInstrument(INSTRUMENT_BDRUM2);
Instrument snare = opl2.loadInstrument(INSTRUMENT_RKSNARE1);
Instrument tom = opl2.loadInstrument(INSTRUMENT_TOM2);
Instrument cymbal = opl2.loadInstrument(INSTRUMENT_CYMBAL1);
Instrument hihat = opl2.loadInstrument(INSTRUMENT_HIHAT2);

opl2.setPercussion(true);
opl2.setDrumInstrument(bass);
opl2.setDrumInstrument(snare);
opl2.setDrumInstrument(tom);
opl2.setDrumInstrument(cymbal);
opl2.setDrumInstrument(hihat);

// Set octave and frequency for bass drum.
opl2.setBlock(6, 4);
opl2.setFNumber(6, opl2.getNoteFNumber(NOTE_C));

// Set octave and frequency for snare drum and hi-hat.
opl2.setBlock(7, 3);
opl2.setFNumber(7, opl2.getNoteFNumber(NOTE_C));
// Set low volume on hi-hat
opl2.setVolume(7, OPERATOR1, 16);

// Set octave and frequency for tom tom and cymbal.
opl2.setBlock(8, 3);
opl2.setFNumber(8, opl2.getNoteFNumber(NOTE_A));
}


void loop() {
bool bass = i % 4 == 0; // Bass drum every 1st tick
bool snare = i % 4 == 2; // Snare drum every 3rd tick
bool tom = i % 8 > 3; // Tom tom
bool cymbal = i % 32 == 0; // Cymbal every 32nd tick
bool hiHat = true; // Hi-hat every tick

opl2.setDrums(bass, snare, tom, cymbal, hiHat);

i ++;
delay(200);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@ float t = 0.0;


void setup() {
opl2.init();
opl2.begin();

// Setup channel 0 carrier.
opl2.setMaintainSustain(0, CARRIER, true);
opl2.setMultiplier(0, CARRIER, 0x04);
opl2.setAttack (0, CARRIER, 0x0A);
opl2.setSustain (0, CARRIER, 0x04);
// Setup channel 0 carrier.
opl2.setMaintainSustain(0, CARRIER, true);
opl2.setMultiplier(0, CARRIER, 0x01);
opl2.setAttack (0, CARRIER, 0x0A);
opl2.setSustain (0, CARRIER, 0x04);
opl2.setVolume (0, CARRIER, 0x00);

// Start tone.
opl2.setKeyOn(0, true);
// Start tone.
opl2.setKeyOn(0, true);
}


void loop() {
float freq = sin(t) * 250 + 500;
opl2.setFrequency(0, freq);
float freq = sin(t) * 250 + 500;
opl2.setFrequency(0, freq);

t += .01;
delay(10);
t += .01;
delay(10);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int keyChannel[9] = {-1, -1, -1, -1, -1, -1, -1, -1, -1};


void setup() {
opl2.init();
opl2.begin();

// Load an instrument and assign it to all OPL2 channels.
Instrument piano = opl2.loadInstrument(INSTRUMENT_CRYSTAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ byte drums[8] = {DRUM_BASS, NO_DRUM, DRUM_SNARE, NO_DRUM, DRUM_TOM, DRUM_HI_HAT,


void setup() {
opl2.init();
opl2.begin();

// Load drum instruments and set percusive mode.
Instrument bass = opl2.loadInstrument(INSTRUMENT_BDRUM1);
Instrument bass = opl2.loadInstrument(INSTRUMENT_BDRUM2);
Instrument snare = opl2.loadInstrument(INSTRUMENT_RKSNARE1);
Instrument tom = opl2.loadInstrument(INSTRUMENT_TOM2);
Instrument cymbal = opl2.loadInstrument(INSTRUMENT_CYMBAL1);
Expand Down
2 changes: 1 addition & 1 deletion examples/PlayDRO/PlayDRO.ino → examples/OPL2AudioBoard/PlayDRO/PlayDRO.ino
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ byte registerMap[256];


void setup() {
opl2.init();
opl2.begin();
SD.begin(7);

loadDroSong("phemopop.dro");
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/PlayIMF/PlayIMF.ino → examples/OPL2AudioBoard/PlayIMF/PlayIMF.ino
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ float imfSpeed;
long songLength = 0;

void setup() {
opl2.init();
opl2.begin();
SD.begin(7);

imfSpeed = 560.0;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void nextOrder(byte startLine = 0) {
* Initialize the OPL2 board and load the first line of the first order.
*/
void initPlayer() {
opl2.init();
opl2.begin();
opl2.setWaveFormSelect(true);
opl2.setPercussion(false);
speed = initialSpeed;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void error(enum playbackStatus errorcode) {

void setup() {
Serial.begin(9600);
opl2.init();
opl2.begin();
if (!SD.begin(7)) {
error(PLAYBACK_ERROR_SD_INIT_FAILURE);
return;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
OPL2 opl2;

void setup() {
opl2.init();
opl2.begin();

Instrument piano = opl2.loadInstrument(INSTRUMENT_PIANO1); // Load a piano instrument.
opl2.setInstrument(0, piano); // Assign the instrument to OPL2 channel 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OPL2 opl2;

void setup() {
Serial.begin(115200);
opl2.init();
opl2.begin();
}

void loop() {
Expand Down
41 changes: 21 additions & 20 deletions examples/SimpleTone/SimpleTone.ino → .../OPL2AudioBoard/SimpleTone/SimpleTone.ino
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@ OPL2 opl2;


void setup() {
opl2.init();

// Setup channels 0, 1 and 2 to produce a bell sound.
for (byte i = 0; i < 3; i ++) {
opl2.setTremolo (i, CARRIER, true);
opl2.setVibrato (i, CARRIER, true);
opl2.setMultiplier(i, CARRIER, 0x04);
opl2.setAttack (i, CARRIER, 0x0A);
opl2.setDecay (i, CARRIER, 0x04);
opl2.setSustain (i, CARRIER, 0x0F);
opl2.setRelease (i, CARRIER, 0x0F);
}

// Play notes C-3 through B-4 on alternating channels.
for (byte i = 0; i < 24; i ++) {
byte octave = 3 + (i / 12);
byte note = i % 12;
opl2.playNote(i % 3, octave, note);
delay(300);
}
opl2.begin();

// Setup channels 0, 1 and 2 to produce a bell sound.
for (byte i = 0; i < 3; i ++) {
opl2.setTremolo (i, CARRIER, true);
opl2.setVibrato (i, CARRIER, true);
opl2.setMultiplier(i, CARRIER, 0x04);
opl2.setAttack (i, CARRIER, 0x0A);
opl2.setDecay (i, CARRIER, 0x04);
opl2.setSustain (i, CARRIER, 0x0F);
opl2.setRelease (i, CARRIER, 0x0F);
opl2.setVolume (i, CARRIER, 0x00);
}

// Play notes C-3 through B-4 on alternating channels.
for (byte i = 0; i < 24; i ++) {
byte octave = 3 + (i / 12);
byte note = i % 12;
opl2.playNote(i % 3, octave, note);
delay(300);
}
}


Expand Down
Loading

0 comments on commit dfc52b7

Please sign in to comment.