DhrBaksteen / ArduinoOPL2

Arduino library for use with the OPL2 board (YM3812) and OPL3Duo (YMF262)
MIT License
198 stars 39 forks source link

SerialIface.ino: add a variant protocol using less bytes #20

Closed vincentbernat closed 4 years ago

vincentbernat commented 6 years ago

Some games, like Another World, are sampling sounds with the OPL2. The serial port becomes a bottleneck, whatever the buffer size is. Therefore, the handshake is modified to let the user opt-in for shorter binary commands (2 bytes) by using "B0F?" instead of "BUF?".

We use a different function to parse commands in fast mode to avoid too many "if". I don't know if a simple CPU like the ATMega328P can do effective branch prediction.

Note this PR also contains the commit for PR #19.

ghost commented 6 years ago

Looks good to me - this new protocol makes sense where throughput is the most important consideration.

Just curious, does the serial port keep up with sample playback after this change? At 115200 bps, 10 bits per byte (including start and stop bits), you could send at most 5760 2-byte commands per second. What sample rate is used by Another World?

By the way, I don't have write access to the repository, but if I did I'd merge your changes.

vincentbernat commented 6 years ago

Another World is 5 KHz. Just right! :) I don't get a single overflow.

I have also tried to use faster speeds, but nothing works. Either 230,400 or 460,800. On Linux side, the driver is OK with these speeds. On Arduino side, it seems to be OK too. But only garbage is received. I suppose someone is lying. :)

Maybe a project could be to switch to USB HID to get 12 Mbps. However, I am quite not fluent enough with Arduino for that.

ghost commented 6 years ago

Perfect :+1: Playing digital audio via a serial port.. there's an application I never imagined before!

I couldn't make it work with baud rates higher than 115,200 either (using Windows / pyserial). Not sure where the problem is though.

12 Mbps via the USB sounds like a great idea, but I'm also a beginner with Arduino.. I only learned it so that I could play with the OPL board. It's very easy to get started, but it has some limitations.

vincentbernat commented 4 years ago

This has been superseded by SerialPassthrough.ino.