dhrbaksteen / arduinoopl2 Goto Github PK
View Code? Open in Web Editor NEWArduino library for use with the OPL2 board (YM3812) and OPL3Duo (YMF262)
License: MIT License
Arduino library for use with the OPL2 board (YM3812) and OPL3Duo (YMF262)
License: MIT License
using raspberry pi 3
Im getting an error when I enter this command.
pi@raspberrypi:~/ArduinoOPL2/examples_pi/opl2play $ sudo ./opl2play tunes/duke2.imf Unable to open SPI device: No such file or directory pi@raspberrypi:~/ArduinoOPL2/examples_pi/opl2play $ pwd /home/pi/ArduinoOPL2/examples_pi/opl2play
what am I doing wrong?
Opl3.h is using pin definitions for A0 and /IC from opl2.h. These are the pins used by the OPL2 Audio Board and cause the OPL3 Duo to only produce clicking noises.
I'm going to assemble this audioboard without your pcb on a breadboard, before ordering or creating a pcb. Do you have a wiring diagram/circuit layout like the one on the hackaday project page, just for the current version, because the parts list is very different from the old revision?
The old diagram: https://cdn.hackaday.io/images/6312461481923275704.png
I have a strange issue with my OPL2 Board. When I use the serial passtrough example and the OPL bank editor I have to turn on max volume of the board to hear anything. There is much noise and distortion when I do that, but at least I hear something. It also doesn't seem to change instruments. Al sounds sound the same when I play notes. I also tried tried flashing the atmega16u2 with the HDUINO MIDI firmware and played notes through MIDI-OX with the same result. However, when I use the Arduino IDE examples that play drums and melody, it sounds just fine! Then I can control the volume and it can even quite loud. Using an UNO clone with CH340 USB chip also gave teh same result with the OPL bank editor. I used my laptop to try it. It's and Asus with Wndows 10.
Kind regards!
I'm trying to get to the bottom of an issue that's preventing the OPL2 Audio Board from working correctly in DOSBox-X on Linux.
OPL2board Audio playback on DOSBox-X is hideous out of time, stuttery and distorted on Linux.
I've been investigating this for a couple of days and what I've found so far indicates that it may be the result of issues involving Linux serial port (ttyACM0) handling, and/or the way either the Arduino or DOSBox-X is using it.
Compiling DOSBox-X with #define OPL2_AUDIO_BOARD_DEBUG 1 in opl2board.h allows us to view every signal being sent to the OPL2board, and the timing of the messages appears to match that of the garbled audio. Occasionally, audio will be sent/received at the correct rate, under which conditions the messages also appear at the correct rate for the music being played
I've videoed this at:
https://theos-cloud.eu/index.php/s/JWwoeoqPyegdZDp
Cut-out occurs at around 27 seconds, example of distortion at 54 seconds.
I've ruled out hardware and DOSBox-X configuration issues by borrowing a Windows PC to confirm that everything works on that as it should, and by reproducing the issue on a second OPL2board.
Since beginning to investigate potentially issues with ttyACM0, I've seen a number of posts discussing issues with transmitting some kinds of data across that port, due to terminals' default configuration favouring ASCII and thus by default dumping certain character strings, for example.
However, disabling all of that with commands such as
stty -F /dev/ttyACM0 115200 -brkint -icrnl -imaxbel -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke min 0
or
stty -F /dev/ttyACM0 raw
has made no impact.
In case further detail would help diagnose this, I noted down some of my investigation as I went in the DOSBox-X issue tracker, several salient points of which I've reproduced here.
I'm aware that, as a hardware developer, apparent operating system/third party software issues aren't your problem per se, but if I can, I'd like to help get this working and accurately documented so that the OPL2board and OPL3 Duo can be used with DOSBox-X on Linux, and if you have any insight into the issue I'd be very appreciative.
I previously wrote some code to do MIDI-to-OPL2 and play old tunes through a MIDI console. I recently upgraded to (single) OPL3 using the OPL3Duo, which sounded great as a drop-in replacement. To level up my game, I enabled 4-op mode, but I got a feeling I could not achieve full 6-voice polyphony: notes sounded like they were getting "stolen" by my voice allocator.
I did some debugging, and the voice allocator works fine. Actually, it did before on 6-voice 2-op OPL2, so I dug a little deeper. My next guess was there was something wrong with the BANK/A1 pin, which would effectively halve the amount of voices. And also, it would prevent the chip from going into OPL3 mode. I started comparing the sounds to an emulated OPL3, and it could be the case.
Looking at the code:
setChipRegister
, so defaults to the OPL2 implementation, which masks the register with 0xff. Registers 0x100 and up can never be addressed in this waysetChannelRegister
and setOperatorRegister
, but BANK/A1 only get driven when (channel >> 8) & 0x01
, which is of course never the caseI am trying to get my head around the datasheet/programming guide to come up with a PR to address these issues, but if anyone is more fluent in YM262, I would appreciate some help :-)
Hi @DhrBaksteen,
I'm working on a modified version of the TeensyMIDI example where I want to store part of the instruments in the EEPROM or SRAM, so I can modify and store them permanently on my Arduino Uno. Unfortunately setInstrument
does not support reading from SRAM when the board type is set to OPL2_BOARD_TYPE_ARDUINO
.
Here's my workaround for this problem:
virtuaCode/ArduinoOPL2@6664009
Hi,
before I'm going to gather and assemble everything on a PCB, I want to test the whole construct on a breadboard. Unfortunately, the only components I'm unable to get my hands on are the 10µF capacitors (not the electrolytic ones), C1 to C4 in the schematic/components list, for use on a breadboard.
Can they be substituted with some other capacitors or can I use electrolytic or tantal ones, with paying attention to the polarity?
I couldn't find any entry for the setPercussion
method, and the links for setBlock
and setFNumber
seem to be dead.
As was mentioned in #29 it would be nice if DosBox can pass its OPL2 data to the OPL2 board to have a real YM3812 play the OPL2 audio. My comments from the PR that is requesting this:
I'm already working on that :)
It will require changes to DosBox that I will place in a new repository. The sketches for the OPL2 board I will add here and of course add links from one repo to the other. What I'm aiming for is that it will work with any controller, not just with a Teensy, but that when using a Teenst you can have both OPL2 pass-through and MIDI support.
I have the pass-through working on one of my test systems which is an Orange Pi that runs a modified version of DosBox, but that is directly communicating to the OPL2 board through the GPIO header. For a more general solution I'm looking into outputting the OPL2 data over a serial line, so it's easy to configure and it will work on any platform.
Since there is nothing for me to merge here I will close this PR and create an enhancement ticket for people to comment on.
Hi! I made OPL2 using your schematic and it seems to be working perfect. But when headphones connected there is interference. I hear shhhhhhhh always and 50 hz buzz when my hands near the board. Also i can hear pc processes like scratching sound when move cursor. When using speakers there is no such problem. Is something with the power? Maybe ams 1117 in my Chinese Arduino is not enough for such current and it causes voltage drops followed by interference
?
Hi!
The board is working perfect!, I started to rip a lot of dro and imf to test and I found this issue.
I tested this in imf player (because it was a bit simpler than dro).
Some complex songs are not playing at constan speed, I think it is because they use variable delays and the playinf is not returning the correct delay.
Removing the "round" from this line seems to (nearly) fix the problem, but still some variable speed.
[code]
return wait * (1000 / imfSpeed);
[/code]
I thought arduino might be too "slow" to play complex songs, but that's not the case, because I used an external constant delay in the loop function, and the speed was constant (but of course the songs play incredibly fast).
Here is a song that has issues, it will play slower when all opl channels are being used.
bpast.zip
Hi there
On https://github.com/DhrBaksteen/ArduinoOPL2/wiki/Connecting you specify that you can use Teensy LC, 3.0 and later.
I was wondering however how that is possible since according to https://www.pjrc.com/teensy/techspecs.html the 3.0 and later only output 3.3V, and not the 5V required by the board?
Best regards,
Kasper
Ter info. Ik heb jouw Arduino OPL2 code gecompileerd op een Microbit en het werkt!!!
Alleen.. jouw arduino SPI pinouts zijn niet compatible met Microbit.
It should be a fairly quick fix.
MidiSynth example the problem of repeatedly "pressing" a key when it is released.
Notes are sounded twice with one press. My keyboard is not sensitive to key pressure. What's with that
make? Build on Arduino Nano.
I'm not sure if this is out of bounds for this project, but some very basic case STLs would be a great idea (or at the very least, some dimensions to build a case).
When a MIDI device uses a channel greater than 16 it will cause random instrument settings and volumes due to the sketch not checking channel bounds.
This has been seen when there are multiple USB MIDI devices connected.
The TeensyMidi example for the OPL2 Audio Board fails to compile with the following error:
TeensyMidi: In function 'void onNoteOn(byte, byte, byte)':
TeensyMidi:165: error: 'octave' was not declared in this scope
octave = note / 12;
^
Hi Maarten
im wondering if this is posible like the OPL2LPT project but with serial.
DhrBaksteen,
I would like to use this library as a starting point for a project I am working on. Since you don't have a license file specified, I am unsure if I can use this for my project.
Would you consider adding an open source license designation to this project such as the MIT license?
Thanks for your hard work!
I'm using the OPL2 board with Raspberry Pi 400, but it's not entirely clear whether the numbers provided on the connection instructions are the pin numbers or the GPIO numbers.
I've assumed pin numbers, as the connection info refers to pins 2 and 6 for 5v and ground, but it would be helpful to have clarification while troubleshooting.
Using DOSBOX-X+sbvgm to play vgm will occupy CPU (over 50% occupancy rate), is there any other way to play vgm through ArduinoOPL2?
I have this sketch:
#include <SPI.h>
#include <OPL2.h>
#define NUM_ROWS 4
#define NUM_COLS 8
// Row input pins
const int row1Pin = 7;
const int row2Pin = 6;
const int row3Pin = 5;
const int row4Pin = 4;
// 74HC595 pins
const int dataPin = 3;
const int latchPin = 2;
const int clockPin = 12;
boolean keyPressed[NUM_ROWS][NUM_COLS];
// bitmasks for scanning columns
int bits[] =
{
B00000001,
B00000010,
B00000100,
B00001000,
B00010000,
B00100000,
B01000000,
B10000000
};
OPL2 opl2;
void setup()
{
// opl2.init();
// opl2.setMaintainSustain(0, CARRIER, true);
// opl2.setMultiplier(0, CARRIER, 0x04);
// opl2.setAttack (0, CARRIER, 0x0A);
// opl2.setSustain (0, CARRIER, 0x04);
for(int colCtr = 0; colCtr < NUM_COLS; ++colCtr)
{
for(int rowCtr = 0; rowCtr < NUM_ROWS; ++rowCtr)
{
keyPressed[rowCtr][colCtr] = false;
}
}
// setup pins output/input mode
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(row1Pin, INPUT);
pinMode(row2Pin, INPUT);
pinMode(row3Pin, INPUT);
pinMode(row4Pin, INPUT);
Serial.begin(9600);
}
void loop()
{
for (int colCtr = 0; colCtr < NUM_COLS; ++colCtr)
{
//scan next column
scanColumn(colCtr);
//get row values at this column
int rowValue[NUM_ROWS];
rowValue[0] = digitalRead(row1Pin);
rowValue[1] = digitalRead(row2Pin);
rowValue[2] = digitalRead(row3Pin);
rowValue[3] = digitalRead(row4Pin);
// process keys pressed
for(int rowCtr=0; rowCtr<NUM_ROWS; ++rowCtr)
{
if(rowValue[rowCtr] != 0 && !keyPressed[rowCtr][colCtr])
{
keyPressed[rowCtr][colCtr] = true;
noteOn(rowCtr,colCtr);
// opl2.playNote(0, 2, 0);
}
}
// process keys released
for(int rowCtr=0; rowCtr<NUM_ROWS; ++rowCtr)
{
if(rowValue[rowCtr] == 0 && keyPressed[rowCtr][colCtr])
{
keyPressed[rowCtr][colCtr] = false;
}
}
}
}
void scanColumn(int colNum)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, bits[colNum]);
digitalWrite(latchPin, HIGH);
}
void noteOn(int row, int col)
{
Serial.println(String(row) + ", " + String(col));
}
Which reads a scan matrix hooked up to a keyboard. It works perfectly as expected as long as I don't call opl2.init()
. If I uncomment that line though, it stops working. Just uncommenting that line alone causes the serial to print lots of output at once when even pressing a single key, and uncommenting everything to do with the OPL2 library causes the serial output to stop altogether.
I'm using all of the default pins for the OPL2 library as stated in the wiki, and the pins I'm using for the scan matrix can be seen in my snippet. If there's something I'm doing wrong please let me know, otherwise there may be an issue with the library.
I'm using an Arduino UNO.
hi mate, i receive the board and connected to my Chinese Arduino NANO clone, and Nothing.
Some beers after i found that the problem is the wires not connected in the correct place.
Now the board it's working but you can only hear some sound in the middle of the noise.
My questions are: Chinese arduino sucks? My computer power switch sucks? I try to power up the board whit an external USB power switch, but the noise still remains.
I will post some photos and audio file to show what im talk about.
Thank for the Board, Romeu
Hello, I've recently purchased your OPL2 sound board, tested it with my Raspberry Pi and it works great!
I played some of the tunes that were included, which worked fine, but most of the recordings I made didn't sound right, found the issue: in line 127 of file examples_pi/opl2play/opl2play.cpp, replace:
} else {
with
} else if (registerCode < dro.registerMapLength) {
My recordings were made using DOSBox 0.74-2, and after this change they play fine.
Is it possible to use OPL2 Audio Board on 86Emu like in DosBox as output device?
Dear Maarten,
Suoer cool project. I very much enjoy programming it so far! I have a question though:
I found the "Working with instruments" section in the Wiki which states that there are many instruments already available. Is there a list of instruments? Are the instruments stored in the OPL2 itself?
Best,
Constantin
Hello!
Been having fun with my opl3 Duo. The line out sounds pretty good, even when amplified by powered speakers or my audio interface up to audible levels. But the speaker out has a lot of buzzing / humming noise even when not playing anything, even with the volume knob turned all the way down.
Is that expected? If not, any ideas what to check for?
Thanks!
The PlayDRO example sketch is neat, but it isn't very well documented. Could you explain how everything works?
How to programmatically adjust the frequency? How to get into unison? Synthesizers usually have this tuning. I haven't figured out which library function to use yet.
Filing this so I don't forget -- I'll try and send a PR with a fix soon.
I'm not a C++ expert but I did some googling after hitting some compiler errors when I tried to use std::min
in a file that includes OPL2.h
and found that defining min/max macros is discouraged (for this reason).
This workaround works:
#include <OPL2.h>
#undef min
#undef max
... rest of your code...
I think probably std::min
and std::max
could be used instead, at least for raspberry pi. Or this macro could move to the relevant cpp files instead.
Is it possible to add support for the teensy 2.0++?
The Teensy is able to act like an USB Midi device.
Hi. I just assembled the board and i can play the demo tune. There is however a lot of loud click noises when the device is idle (possibly also when playing music). When i turn the volume down, the noise disappears. The noise is consistent in both left and right so i dont think its my cabling.
Ps. about ~9 seconds in i put my finger on cap C10 which removes most of the humming noise. Whats causing the hum? I tried with both PC and battery power, and i used a ground loop isolator on the audio output, but the humming persists. Anyway, the hum is easier to filter out from a recording than the clicks and pops.
Hi, I'm using an original Raspberry Pi B model, and the OPL3 version of the demotune program hangs about 5 seconds in, playing the same note forever. The other demotune program doesn't have this issue.
The hardware test seems fine, but I don't know what that program is really supposed to sound like.
Hey!
Looking at the assembly instruction, I wonder why 5V/GND are not mentioned on Arduino. Shouldn't they be wired?
This issue was reported on the Tindie page:
Play "sonic.vgm" on COM5
(Ctrl-C to stop)
Traceback (most recent call last):
File "play.py", line 74, in
handle_arguments()
File "play.py", line 65, in handle_arguments
device = opl.ArduinoOpl(portname)
File "C:\Users\Fu▀pilz Stinkstiefel\Desktop\ArduinoOPL2-master\ArduinoOPL2-master\examples\SerialIface\opl.py", line 28, in init
self.status(self.READYCMD)
File "C:\Users\Fu▀pilz Stinkstiefel\Desktop\ArduinoOPL2-master\ArduinoOPL2-master\examples\SerialIface\opl.py", line 63, in _status
tx_txt = 'Tx: %s' % ' '.join('%02x' % b for b in last_tx)
File "C:\Users\Fu▀pilz Stinkstiefel\Desktop\ArduinoOPL2-master\ArduinoOPL2-master\examples\SerialIface\opl.py", line 63, in
tx_txt = 'Tx: %s' % ' '.join('%02x' % b for b in last_tx)
TypeError: %x format: a number is required, not str
Lines 260 to 266 in 61e03ff
The parameters for the registers C0...C8 are stored in the instrument data at instrument[5]
. Since we always do i + 1
when accessing the instrument data, the condition at line 260 have to be i == 4
. Also accessing the instrumentBaseRegs
array has to be done this way:
reg = instrumentBaseRegs[i == 5 ? 4 : i % 6] + getRegisterOffset(channel, i > 5);
After I fixed this issue I played some notes with the instrument in midi_instrument.h
and realized that for every patch the "synthtype" bit is inverted. 😮 Can you confirm this?
Is it possible to increase number of keys? As it uses 74HC165 it can be connected to others many times. I have few OPL2s and now i want to make keyboard :) . But having only one octave is problem. Im from Russia,sorry for my broken english.
How good is UART speed in SerialPassthrough for OPL2? Is everything running without lags? I have ordered parts i need to make my usb AdLib and I'm going to use it with DOS trackers,midi and vgm players. How good it in very dynamical music?
Hello there!
After modifying the Teensy MIDI Example to work with the standard MIDI Libary an my Arduino Nano the code worked but it produces additionally cracking noises when play some notes.
Is there a simple fix I can use or a specific section in the code where I should look at?
Greetings
This line :
https://github.com/DhrBaksteen/ArduinoOPL2/blob/master/src/OPL2.cpp#L37
states:
Make sure you set the correct BOARD_TYPE in OPL2.h. Default is set to Arduino
but this is actually incorrect, as you can see here:
https://github.com/DhrBaksteen/ArduinoOPL2/blob/master/src/OPL2.h#L24
#define BOARD_TYPE RASPBERRY_PI
The immediate consequence is that the build with the Arduino IDE fails when you first follow the testing instructions. It's a easy to spot, but better keep the comment consistent with the actual code.
Thank you for this amazing board!
Hello, thanks for sharing this cool board !
Unfortunately, the shipping fees to my country are prohibitively expensive.
Could you share the Gerber files so I can order the PCB from an online manufacturer.
Regards
Thanks for a cool project! I am making an OPL synthesizer connected to my digital piano.
SetInstrument uses invalid registers when i == 5. You should change it to something like this (I guess it applies to percussion instruments as well):
default: // Melodic instruments...
for (byte i = 0; i < 11; i ++) {
byte reg;
if (i == 5)
reg = 0xC0 + max(0x00, min(channel, 0x08));
else
reg = instrumentBaseRegs[i % 6] + getRegisterOffset(channel, i > 5);
setRegister(
reg,
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.