vgmrips / vgmplay-legacy

VGM file command-line player and Winamp plugin.
http://vgmrips.net
221 stars 52 forks source link

Adapt to OPL3DUO (serial control OPL3 actual hardware) #89

Open denjhang opened 1 year ago

denjhang commented 1 year ago

https://github.com/DhrBaksteen/ArduinoOPL2 Arduino OPL2 allows to use serial port to control YM3812 or YMF262, I hope vgmplay can adapt to this function. I made a USB-OPL3 based on Arduino OPL2, and currently I can use Dosbox-X+sbvgm to play music from OPL1/2/3.

ValleyBell commented 1 year ago

I see lots of Arduino-code in that repo. But VGMPlay doesn't run on an Arduino.,

Is there a way to access the OPL3Duo from the PC side? And if so, please describe (or link) how it is done.
If it should be a serial connection via COM port, then I need information about the baud rate, stop bits, etc.

denjhang commented 1 year ago

https://github.com/DhrBaksteen/ArduinoOPL2/blob/master/examples/OPL3Duo/SerialPassthrough/SerialPassthrough.ino https://github.com/DhrBaksteen/ArduinoOPL2/blob/master/examples/OPL2AudioBoard/SerialPassthrough/SerialPassthrough.ino

Currently I use SerialPassthrough.ino of OPL3DUO, compile these codes with arduino and upload them to arduino nano. After that I use dosbox-x and specify the port number (like com3) and I can use the actual opl3 hardware.

sshot-20221025-123536

denjhang commented 1 year ago

In addition to using dosbox-x to access opl3duo, you can also use opl3bankeditor https://github.com/Wohlstand/OPL3BankEditor

and an immature vgm player made by my friend. https://github.com/zhblue/OPL3USB/tree/main/vgmplay2usb

denjhang commented 1 year ago

sshot-20221025-124005

ValleyBell commented 1 year ago

I may have a look whenever I port the "hardware OPL" code to vgmplay-libvgm.

The important code parts of the two repos are:

denjhang commented 1 year ago

https://github.com/joncampbell123/dosbox-x/tree/master/src/hardware/opl3duoboard https://github.com/joncampbell123/dosbox-x/tree/master/src/hardware/opl2board https://github.com/joncampbell123/dosbox-x/tree/master/src/hardware/serialport

denjhang commented 1 year ago

By the way, the vgmplay2usb made by my friend has been tested and found that the playback speed is very unstable, fast and slow. And it plays very slowly when it encounters VGM with many notes. This doesn't happen when I use dosbox-x+sbvgm.

ValleyBell commented 1 year ago

vgmplay2usb's timing code just uses Sleep(wait/speed); to perform timing. In practise this guarantees you that timing will be inaccurate, because any sort of "wait" command waits at least the specified time. Sleep(4) may return after 4 ms ... or after 300 ms if the OS is busy with other stuff.

VGMPlay uses a separate time counter that is advanced by the VGM wait commands. It does Sleep(1) in a loop until the system time reaches the target time. When waiting takes too long for one delay, it will wait a shorter time for the next command. Thus the overall timing will be stable. (And it has been for hardware OPL passthrough when I used it.)

(Also, vgmplay2usb calling _kbhit() between every VGM command will probably slow down VGM parsing. I'd check for key input only when actively waiting.)