Skip to content

Commit fdde7ed

Browse files
committed
OPL3Duo for Raspberry Pi
* Updated library to allow OPL3 Duo! board on Raspberry Pi * Updated build scripts for OPL3 Duo! * Added first examples for OPL3 Duo! * Updated Raspberry Pi examples to latest library version * Added and updated connection scripts
1 parent ba73516 commit fdde7ed

File tree

24 files changed

+1762
-190
lines changed

24 files changed

+1762
-190
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This repository contains the OPL2 / OPL3 audio library for the OPL2 Audio Board
99
* Emulation with DosBox; you can use the board to output MIDI music (Teensy++ 2.0 and later)
1010
* Use the board directly as a synthesizer by using the [OPL3BankEditor](https://github.com/Wohlstand/OPL3BankEditor) software by Wohlstand
1111

12-
Current library version is 2.0.2, 14th November 2020
12+
Current library version is 2.0.4, 4th December 2020
1313

1414
### OPL2 Audio Board
1515
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.

build

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ echo "\033[1;34m \\/ \\/ \\/ \\/ \033[0m"
2020
echo "For the \033[1;36mOPL2 Audio Board\033[0m and \033[1;36mOPL3 Duo!\033[0m synthesizers"
2121
echo ""
2222
echo "Installation script for Raspberry Pi and compatibles"
23-
echo "Library version 2.0.3, 23rd of November 2020"
23+
echo "Library version 2.0.4, 4th of December 2020"
2424
echo "Copyright (c) 2016-2020 Maarten Janssen, Cheerful"
2525
echo ""
2626

@@ -80,10 +80,15 @@ mv "$MYDIR"/libOPL2.so /usr/lib/
8080
cp "$MYDIR"/src/OPL2.h /usr/include/
8181
rm "$MYDIR"/OPL2.o
8282

83+
g++ -std=c++11 -c -fPIC -o "$MYDIR"/OPL3.o "$MYDIR"/src/OPL3.cpp -lwiringPi
84+
g++ -shared -o "$MYDIR"/libOPL3.so "$MYDIR"/OPL3.o
85+
mv "$MYDIR"/libOPL3.so /usr/lib/
86+
cp "$MYDIR"/src/OPL3.h /usr/include/
87+
rm "$MYDIR"/OPL3.o
88+
8389
g++ -std=c++11 -c -fPIC -o "$MYDIR"/OPL3Duo.o "$MYDIR"/src/OPL3Duo.cpp -lwiringPi
8490
g++ -shared -o "$MYDIR"/libOPL3Duo.so "$MYDIR"/OPL3Duo.o
8591
mv "$MYDIR"/libOPL3Duo.so /usr/lib/
86-
cp "$MYDIR"/src/OPL3.h /usr/include/
8792
cp "$MYDIR"/src/OPL3Duo.h /usr/include/
8893
rm "$MYDIR"/OPL3Duo.o
8994

@@ -96,18 +101,46 @@ g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/drums/drums "$MYDIR"/examples_pi/dr
96101
g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/simpletone/simpletone "$MYDIR"/examples_pi/simpletone/simpletone.cpp -lOPL2 -lwiringPi
97102
g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/opl2play/opl2play "$MYDIR"/examples_pi/opl2play/opl2play.cpp -lOPL2 -lwiringPi -lz
98103
g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/frequency_sweep/sweep "$MYDIR"/examples_pi/frequency_sweep/sweep.cpp -lOPL2 -lwiringPi -lz
104+
105+
g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/OPL3Duo/HardwareTest/HardwareTest "$MYDIR"/examples_pi/OPL3Duo/HardwareTest/HardwareTest.cpp -lOPL3Duo -lOPL3 -lOPL2 -lwiringPi -lz
106+
g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/OPL3Duo/DemoTune/DemoTune "$MYDIR"/examples_pi/OPL3Duo/DemoTune/TuneParser.cpp "$MYDIR"/examples_pi/OPL3Duo/DemoTune/DemoTune.cpp -lOPL3Duo -lOPL3 -lOPL2 -lwiringPi -lz
107+
99108
echo "\033[0;32mDone\033[0m"
100109
echo "Installation complete."
101110

102111
echo ""
103-
"$MYDIR"/connecting
112+
echo "What board are you using?"
113+
echo " \033[1;36m2\033[0m - OPL2 Audio Board"
114+
echo " \033[1;36m3\033[0m - OPL3 Duo!"
104115

105-
echo -n "Are you ready to try your OPL2 Audio Board? "
106116
read REPLY
107-
REPLY=$(echo "$REPLY" | awk '{gsub(/ /, "", $0); print toupper(substr($0==""?"N":$0, 1, 1))}')
108-
if [ $REPLY = "Y" ]
117+
if [ $REPLY = "2" ]
109118
then
119+
"$MYDIR"/connecting
120+
121+
echo -n "Are you ready to try your OPL2 Audio Board? "
122+
read REPLY
123+
REPLY=$(echo "$REPLY" | awk '{gsub(/ /, "", $0); print toupper(substr($0==""?"N":$0, 1, 1))}')
124+
if [ $REPLY = "Y" ]
125+
then
110126
echo "If all went successful you should hear music playing now!"
111127
"$MYDIR"/examples_pi/demotune/demotune &
128+
fi
129+
echo ""
130+
elif [ $REPLY = "3" ]
131+
then
132+
"$MYDIR"/connecting_opl3duo
133+
134+
echo -n "Are you ready to try your OPL3 Duo?"
135+
read REPLY
136+
REPLY=$(echo "$REPLY" | awk '{gsub(/ /, "", $0); print toupper(substr($0==""?"N":$0, 1, 1))}')
137+
if [ $REPLY = "Y" ]
138+
then
139+
echo "If all went successful you should hear music playing now!"
140+
"$MYDIR"/examples_pi/OPL3Duo/DemoTune/DemoTune &
141+
fi
142+
echo ""
143+
else
144+
echo "Hmm... I don't know that one."
145+
echo ""
112146
fi
113-
echo ""

connecting

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,23 @@
33
if ! type "gpio" > /dev/null
44
then
55
echo "WiringPi was not found!"
6-
echo "Please run the build script to install your OPL2 Audio Board first."
6+
echo "Please run the build script to install the OPL2 library first."
77
echo ""
88
exit
99
fi
1010

11-
PIN_LATCH=$(gpio readall | awk -F\| '{if ($3==1) print $7} {if ($13==1) print $9}')
12-
PIN_A0=$(gpio readall | awk -F\| '{if ($3==4) print $7} {if ($13==4) print $9}')
13-
PIN_RESET=$(gpio readall | awk -F\| '{if ($3==5) print $7} {if ($13==5) print $9}')
14-
PIN_DATA=$(gpio readall | awk -F\| '{gsub(/ /, "", $4) ; if ($4=="MOSI") print $7} {gsub(/ /, "", $12) ; if ($12=="MOSI") print $9}')
15-
PIN_SHIFT=$(gpio readall | awk -F\| '{gsub(/ /, "", $4) ; if ($4=="SCLK") print $7} {gsub(/ /, "", $12) ; if ($12=="SCLK") print $9}')
16-
1711
echo ""
1812
echo "Connect the OPL2 Audio Board to your Raspberry Pi like this:"
1913
echo ""
2014
echo "+------------+------+"
2115
echo "| OPL2 Board | GPIO |\tGPIO header orientation:"
2216
echo "+------------+------+"
23-
echo "| Reset |\033[1m $PIN_RESET \033[0m|\t \033[1;32m|\033[0m"
24-
echo "| Shift |\033[1m $PIN_SHIFT \033[0m|\t ...\033[1m 5 3 1 \033[1;32m|\033[0m"
25-
echo "| Latch |\033[1m $PIN_LATCH \033[0m|\t -----------+ \033[1;32m|\033[0m"
26-
echo "| Data |\033[1m $PIN_DATA \033[0m|\t \033[1;33m o o o o o \033[0m| \033[1;32m|\033[0m"
27-
echo "| A0 |\033[1m $PIN_A0 \033[0m|\t \033[1;33m o o o o o o \033[0m| \033[1;32m|\033[0m"
28-
echo "| GND |\033[1m 6 \033[0m|\t -------------+ \033[1;32m|\033[0m"
29-
echo "| +5v |\033[1m 2 \033[0m|\t ...\033[1m 6 4 2 \033[1;32m|\033[0m <-- Raspberry Pi"
17+
echo "| Reset |\033[1m 13 \033[0m|\t \033[1;32m|\033[0m"
18+
echo "| Shift |\033[1m 23 \033[0m|\t ...\033[1m 5 3 1 \033[1;32m|\033[0m"
19+
echo "| Latch |\033[1m 15 \033[0m|\t -----------+ \033[1;32m|\033[0m"
20+
echo "| Data |\033[1m 19 \033[0m|\t \033[1;33m o o o o o \033[0m| \033[1;32m|\033[0m"
21+
echo "| A0 |\033[1m 16 \033[0m|\t \033[1;33m o o o o o o \033[0m| \033[1;32m|\033[0m"
22+
echo "| GND |\033[1m 6 \033[0m|\t -------------+ \033[1;32m|\033[0m"
23+
echo "| +5v |\033[1m 2 \033[0m|\t ...\033[1m 6 4 2 \033[1;32m|\033[0m <-- Raspberry Pi"
3024
echo "+------------+------+\t \033[1;32m------------------'\033[0m board edge"
3125
echo ""

connecting_opl3duo

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
if ! type "gpio" > /dev/null
4+
then
5+
echo "WiringPi was not found!"
6+
echo "Please run the build script to install the OPL2 library first."
7+
echo ""
8+
exit
9+
fi
10+
11+
echo ""
12+
echo "Connect the OPL3 Duo! to your Raspberry Pi like this:"
13+
echo ""
14+
echo "+-----------+------+"
15+
echo "| OPL3 Duo! | GPIO |"
16+
echo "+-----------+------+"
17+
echo "| +3.3v |\033[1m 1 \033[0m|\t GPIO header connection:"
18+
echo "| GND |\033[1m 6 \033[0m|"
19+
echo "| A2 |\033[1m 22 \033[0m|\t \033[1;32m|\033[0m"
20+
echo "| A1 |\033[1m 18 \033[0m|\t ...\033[1m 5 3 1 \033[1;32m|\033[0m"
21+
echo "| A0 |\033[1m 16 \033[0m|\t -----------+ \033[1;32m|\033[0m"
22+
echo "| MOSI |\033[1m 19 \033[0m|\t \033[1;33m o o o o o \033[0m| \033[1;32m|\033[0m"
23+
echo "| SCK |\033[1m 23 \033[0m|\t \033[1;33m o o o o o o \033[0m| \033[1;32m|\033[0m"
24+
echo "| /WR |\033[1m 15 \033[0m|\t -------------+ \033[1;32m|\033[0m"
25+
echo "| /IC |\033[1m 13 \033[0m|\t ...\033[1m 6 4 2 \033[1;32m|\033[0m <-- Raspberry Pi"
26+
echo "+-----------+------+\t \033[1;32m------------------'\033[0m board edge"
27+
echo ""

examples/OPL3Duo/HardwareTest/HardwareTest.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Instrument testInstrument2;
1818

1919

2020
void setup() {
21-
delay(1000);
21+
delay(1000);
2222
Serial.begin(9600);
2323
opl3Duo.begin();
2424
testInstrument = opl3Duo.loadInstrument(INSTRUMENT_SYN1);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* This is a demonstration sketch for the OPL3 Duo! It demonstrates how the TuneParser can be used with the OPL3 Duo! to
3+
* play music that is defined by simple strings of notes and other commands. The TuneParser can play up to 6 voices at
4+
* the same time.
5+
*
6+
* Code by Maarten Janssen, 2020-12-04
7+
* WWW.CHEERFUL.NL
8+
* Most recent version of the library can be found at my GitHub: https://github.com/DhrBaksteen/ArduinoOPL2
9+
*/
10+
11+
#include "TuneParser.h"
12+
#include <OPL3Duo.h>
13+
#include "midi_instruments_4op.h"
14+
15+
const char voice1[] = "i96t150o5l8egredgrdcerc<b>er<ba>a<a>agdefefedr4.regredgrdcerc<b>er<ba>a<a>agdedcr4.c<g>cea>cr<ag>cr<gfarfearedgrdcfrc<bagab>cdfegredgrdcerc<b>er<ba>a<a>agdedcr4.cro3c2r2";
16+
const char voice2[] = "i96o4l8crer<br>dr<ar>cr<grbrfr>cr<grbr>crer<gb>dgcrer<br>dr<ar>cr<grbrfr>cr<grbr>ceger4.rfrafergedrfdcrec<br>d<bar>c<agrgd<gr4.o4crer<br>dr<ar>cr<grbrfr>cr<grbr>cege";
17+
const char voice3[] = "i2o3l8r4gr4.gr4.er4.err4fr4.gr4.gr4.grr4gr4.er4.er4.frr4gr4>ccr4ccr4<aarraar4ggr4ffr4.ro4gab>dr4.r<gr4.gr4.err4er4.fr4.g";
18+
19+
OPL3Duo opl3;
20+
TuneParser tuneParser(&opl3);
21+
Tune tune;
22+
23+
24+
int main(int argc, char **argv) {
25+
tuneParser.begin();
26+
tuneParser.play(voice1, voice2, voice3);
27+
28+
return 0;
29+
}

0 commit comments

Comments
 (0)