Skip to content

Commit

Permalink
OPL3Duo for Raspberry Pi
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
DhrBaksteen committed Dec 4, 2020
1 parent ba73516 commit fdde7ed
Show file tree
Hide file tree
Showing 24 changed files with 1,762 additions and 190 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This repository contains the OPL2 / OPL3 audio library for the OPL2 Audio Board
* 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 2.0.2, 14th November 2020
Current library version is 2.0.4, 4th December 2020

### 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.
Expand Down
47 changes: 40 additions & 7 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ echo "\033[1;34m \\/ \\/ \\/ \\/ \033[0m"
echo "For the \033[1;36mOPL2 Audio Board\033[0m and \033[1;36mOPL3 Duo!\033[0m synthesizers"
echo ""
echo "Installation script for Raspberry Pi and compatibles"
echo "Library version 2.0.3, 23rd of November 2020"
echo "Library version 2.0.4, 4th of December 2020"
echo "Copyright (c) 2016-2020 Maarten Janssen, Cheerful"
echo ""

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

g++ -std=c++11 -c -fPIC -o "$MYDIR"/OPL3.o "$MYDIR"/src/OPL3.cpp -lwiringPi
g++ -shared -o "$MYDIR"/libOPL3.so "$MYDIR"/OPL3.o
mv "$MYDIR"/libOPL3.so /usr/lib/
cp "$MYDIR"/src/OPL3.h /usr/include/
rm "$MYDIR"/OPL3.o

g++ -std=c++11 -c -fPIC -o "$MYDIR"/OPL3Duo.o "$MYDIR"/src/OPL3Duo.cpp -lwiringPi
g++ -shared -o "$MYDIR"/libOPL3Duo.so "$MYDIR"/OPL3Duo.o
mv "$MYDIR"/libOPL3Duo.so /usr/lib/
cp "$MYDIR"/src/OPL3.h /usr/include/
cp "$MYDIR"/src/OPL3Duo.h /usr/include/
rm "$MYDIR"/OPL3Duo.o

Expand All @@ -96,18 +101,46 @@ g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/drums/drums "$MYDIR"/examples_pi/dr
g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/simpletone/simpletone "$MYDIR"/examples_pi/simpletone/simpletone.cpp -lOPL2 -lwiringPi
g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/opl2play/opl2play "$MYDIR"/examples_pi/opl2play/opl2play.cpp -lOPL2 -lwiringPi -lz
g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/frequency_sweep/sweep "$MYDIR"/examples_pi/frequency_sweep/sweep.cpp -lOPL2 -lwiringPi -lz

g++ -std=c++11 -Wall -o "$MYDIR"/examples_pi/OPL3Duo/HardwareTest/HardwareTest "$MYDIR"/examples_pi/OPL3Duo/HardwareTest/HardwareTest.cpp -lOPL3Duo -lOPL3 -lOPL2 -lwiringPi -lz
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

echo "\033[0;32mDone\033[0m"
echo "Installation complete."

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

echo -n "Are you ready to try your OPL2 Audio Board? "
read REPLY
REPLY=$(echo "$REPLY" | awk '{gsub(/ /, "", $0); print toupper(substr($0==""?"N":$0, 1, 1))}')
if [ $REPLY = "Y" ]
if [ $REPLY = "2" ]
then
"$MYDIR"/connecting

echo -n "Are you ready to try your OPL2 Audio Board? "
read REPLY
REPLY=$(echo "$REPLY" | awk '{gsub(/ /, "", $0); print toupper(substr($0==""?"N":$0, 1, 1))}')
if [ $REPLY = "Y" ]
then
echo "If all went successful you should hear music playing now!"
"$MYDIR"/examples_pi/demotune/demotune &
fi
echo ""
elif [ $REPLY = "3" ]
then
"$MYDIR"/connecting_opl3duo

echo -n "Are you ready to try your OPL3 Duo?"
read REPLY
REPLY=$(echo "$REPLY" | awk '{gsub(/ /, "", $0); print toupper(substr($0==""?"N":$0, 1, 1))}')
if [ $REPLY = "Y" ]
then
echo "If all went successful you should hear music playing now!"
"$MYDIR"/examples_pi/OPL3Duo/DemoTune/DemoTune &
fi
echo ""
else
echo "Hmm... I don't know that one."
echo ""
fi
echo ""
22 changes: 8 additions & 14 deletions connecting
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@
if ! type "gpio" > /dev/null
then
echo "WiringPi was not found!"
echo "Please run the build script to install your OPL2 Audio Board first."
echo "Please run the build script to install the OPL2 library first."
echo ""
exit
fi

PIN_LATCH=$(gpio readall | awk -F\| '{if ($3==1) print $7} {if ($13==1) print $9}')
PIN_A0=$(gpio readall | awk -F\| '{if ($3==4) print $7} {if ($13==4) print $9}')
PIN_RESET=$(gpio readall | awk -F\| '{if ($3==5) print $7} {if ($13==5) print $9}')
PIN_DATA=$(gpio readall | awk -F\| '{gsub(/ /, "", $4) ; if ($4=="MOSI") print $7} {gsub(/ /, "", $12) ; if ($12=="MOSI") print $9}')
PIN_SHIFT=$(gpio readall | awk -F\| '{gsub(/ /, "", $4) ; if ($4=="SCLK") print $7} {gsub(/ /, "", $12) ; if ($12=="SCLK") print $9}')

echo ""
echo "Connect the OPL2 Audio Board to your Raspberry Pi like this:"
echo ""
echo "+------------+------+"
echo "| OPL2 Board | GPIO |\tGPIO header orientation:"
echo "+------------+------+"
echo "| Reset |\033[1m $PIN_RESET \033[0m|\t \033[1;32m|\033[0m"
echo "| Shift |\033[1m $PIN_SHIFT \033[0m|\t ...\033[1m 5 3 1 \033[1;32m|\033[0m"
echo "| Latch |\033[1m $PIN_LATCH \033[0m|\t -----------+ \033[1;32m|\033[0m"
echo "| Data |\033[1m $PIN_DATA \033[0m|\t \033[1;33m o o o o o \033[0m| \033[1;32m|\033[0m"
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"
echo "| GND |\033[1m 6 \033[0m|\t -------------+ \033[1;32m|\033[0m"
echo "| +5v |\033[1m 2 \033[0m|\t ...\033[1m 6 4 2 \033[1;32m|\033[0m <-- Raspberry Pi"
echo "| Reset |\033[1m 13 \033[0m|\t \033[1;32m|\033[0m"
echo "| Shift |\033[1m 23 \033[0m|\t ...\033[1m 5 3 1 \033[1;32m|\033[0m"
echo "| Latch |\033[1m 15 \033[0m|\t -----------+ \033[1;32m|\033[0m"
echo "| Data |\033[1m 19 \033[0m|\t \033[1;33m o o o o o \033[0m| \033[1;32m|\033[0m"
echo "| A0 |\033[1m 16 \033[0m|\t \033[1;33m o o o o o o \033[0m| \033[1;32m|\033[0m"
echo "| GND |\033[1m 6 \033[0m|\t -------------+ \033[1;32m|\033[0m"
echo "| +5v |\033[1m 2 \033[0m|\t ...\033[1m 6 4 2 \033[1;32m|\033[0m <-- Raspberry Pi"
echo "+------------+------+\t \033[1;32m------------------'\033[0m board edge"
echo ""
27 changes: 27 additions & 0 deletions connecting_opl3duo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

if ! type "gpio" > /dev/null
then
echo "WiringPi was not found!"
echo "Please run the build script to install the OPL2 library first."
echo ""
exit
fi

echo ""
echo "Connect the OPL3 Duo! to your Raspberry Pi like this:"
echo ""
echo "+-----------+------+"
echo "| OPL3 Duo! | GPIO |"
echo "+-----------+------+"
echo "| +3.3v |\033[1m 1 \033[0m|\t GPIO header connection:"
echo "| GND |\033[1m 6 \033[0m|"
echo "| A2 |\033[1m 22 \033[0m|\t \033[1;32m|\033[0m"
echo "| A1 |\033[1m 18 \033[0m|\t ...\033[1m 5 3 1 \033[1;32m|\033[0m"
echo "| A0 |\033[1m 16 \033[0m|\t -----------+ \033[1;32m|\033[0m"
echo "| MOSI |\033[1m 19 \033[0m|\t \033[1;33m o o o o o \033[0m| \033[1;32m|\033[0m"
echo "| SCK |\033[1m 23 \033[0m|\t \033[1;33m o o o o o o \033[0m| \033[1;32m|\033[0m"
echo "| /WR |\033[1m 15 \033[0m|\t -------------+ \033[1;32m|\033[0m"
echo "| /IC |\033[1m 13 \033[0m|\t ...\033[1m 6 4 2 \033[1;32m|\033[0m <-- Raspberry Pi"
echo "+-----------+------+\t \033[1;32m------------------'\033[0m board edge"
echo ""
2 changes: 1 addition & 1 deletion examples/OPL3Duo/HardwareTest/HardwareTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Instrument testInstrument2;


void setup() {
delay(1000);
delay(1000);
Serial.begin(9600);
opl3Duo.begin();
testInstrument = opl3Duo.loadInstrument(INSTRUMENT_SYN1);
Expand Down
29 changes: 29 additions & 0 deletions examples_pi/OPL3Duo/DemoTune/DemoTune.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* This is a demonstration sketch for the OPL3 Duo! It demonstrates how the TuneParser can be used with the OPL3 Duo! to
* play music that is defined by simple strings of notes and other commands. The TuneParser can play up to 6 voices at
* the same time.
*
* Code by Maarten Janssen, 2020-12-04
* WWW.CHEERFUL.NL
* Most recent version of the library can be found at my GitHub: https://github.com/DhrBaksteen/ArduinoOPL2
*/

#include "TuneParser.h"
#include <OPL3Duo.h>
#include "midi_instruments_4op.h"

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";
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";
const char voice3[] = "i2o3l8r4gr4.gr4.er4.err4fr4.gr4.gr4.grr4gr4.er4.er4.frr4gr4>ccr4ccr4<aarraar4ggr4ffr4.ro4gab>dr4.r<gr4.gr4.err4er4.fr4.g";

OPL3Duo opl3;
TuneParser tuneParser(&opl3);
Tune tune;


int main(int argc, char **argv) {
tuneParser.begin();
tuneParser.play(voice1, voice2, voice3);

return 0;
}
Loading

0 comments on commit fdde7ed

Please sign in to comment.