Coder Social home page Coder Social logo

dhrbaksteen / arduinoopl2 Goto Github PK

View Code? Open in Web Editor NEW
195.0 25.0 39.0 7.78 MB

Arduino library for use with the OPL2 board (YM3812) and OPL3Duo (YMF262)

License: MIT License

C++ 42.66% C 55.21% Shell 2.13%
opl2-audio-board opl2-library arduino-library synthesizer opl2 adlib kit opl3 opl3duo tindie

arduinoopl2's People

Contributors

bsutherland avatar dhrbaksteen avatar isnotinvain avatar jonkerj avatar judgebeeb avatar pcky avatar prosper00 avatar stople avatar vincentbernat avatar virtuacode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduinoopl2's Issues

SPI device error

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?

Sound issues when using serial USB OPL2 Board on Arduino Uno

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!

Serial issues communicating with DOSBox-X on Linux

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.

OPL3 class seems to lack OPL3-specific addressing

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:

  • OPL3.cpp does not have its own setChipRegister, so defaults to the OPL2 implementation, which masks the register with 0xff. Registers 0x100 and up can never be addressed in this way
  • OPL3.cpp does have a setChannelRegister and setOperatorRegister, but BANK/A1 only get driven when (channel >> 8) & 0x01, which is of course never the case

I 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 :-)

Replacement for 10µF capacitors for breadboard?

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?

OPL2 pass-through for DosBox

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.

A lot of noise in headphones.

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
IMG_20210624_195823
?

Speed issues with complex songs

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

BBC Microbit SPI support

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.

OPL2AudioBoard/MidiSynth example

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.

STLs for board cases?

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

TeensyMidi example for OPL2 Audio Board fails to compile

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;
   ^

No License Specified

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!

Pi connection numbers: GPIO or pins?

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.

More efficient vgm playback

Using DOSBOX-X+sbvgm to play vgm will occupy CPU (over 50% occupancy rate), is there any other way to play vgm through ArduinoOPL2?

Library causing problems with other pins/existing Arduino sketch

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.

terrible noise

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

OPL2.play playback issues

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.

More information on instruments

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

Line out sounds good, speaker out has lots of noise

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!

Explain how PlayDRO works

The PlayDRO example sketch is neat, but it isn't very well documented. Could you explain how everything works?

min / max macros in opl2.h cause issues when using opl2.h with other libraries

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.

Teensy 2.0++ Midi Support

Is it possible to add support for the teensy 2.0++?
The Teensy is able to act like an USB Midi device.

Clicking and popping

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.

click noise.zip

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.

OPL3 Duo with OPL3 demotune hangs with Raspberry Pi

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.

Arduino and 5V/GND

Hey!

Looking at the assembly instruction, I wonder why 5V/GND are not mentioned on Arduino. Shouldn't they be wired?

Type error in opl.py of serialIface example

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

Bug when setting registers for melodic instruments

ArduinoOPL2/src/OPL2.cpp

Lines 260 to 266 in 61e03ff

if (i == 5) {
//Channel parameters C0..C8
reg = 0xC0 + max(0x00, min(channel, 0x08));
} else {
//Operator parameters 20..35, 40..55, 60..75, 80..95, E0..F5
reg = instrumentBaseRegs[i % 6] + getRegisterOffset(channel, i > 5);
}

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?

Piano board support.

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.

Just a question

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?

Teensy MIDI Example buzzing and cracking noise

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

Default configuration is inconsistent with documentation

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!

Gerber files ?

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

Bug: setInstrument uses invalid registers

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,

...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.