danielrfry / opl2sd1

OPL-compatible driver for Yamaha YMF825 (SD-1)
MIT License
36 stars 5 forks source link

Playing VGM with OPL3 dynamic channel allocation is very stuck #6

Open denjhang opened 1 year ago

denjhang commented 1 year ago

This is very strange.

denjhang commented 1 year ago

Invention and Sinfonia.zip

danielrfry commented 1 year ago

Yes, the channel allocator is very simplistic currently; I implemented just enough for tracker tunes and OPL2 soundtracks that use the same set of channels repeatedly - it does not work well for MIDI for example, if many OPL channels are used in sequence. I hope to improve this soon.

danielrfry commented 1 year ago

Audio files demonstrating the issue, for comparison: OPL2SD1_Issue_6.zip

OPL3 version rendered using ymfm via nsplay from Note Salad Tools YMF825 version played back using opl2sd1 firmware and RetroWave_Player on macOS

denjhang commented 1 year ago

The problem seems to be solved, so how do I play my VGM?

danielrfry commented 1 year ago

I haven't made any changes to the channel allocator yet. There are notes being cut off in the YMF825 version I posted above - were you experiencing a different issue?

I did not test the Python VGM player on Windows as I don't often use that OS, so there may be some platform-specific issues as well.

The latest opl2sd1 revision implements the RetroWave OPL3 serial protocol, so you could try the latest firmware version and the RetroWave_Player tool to play VGM files.

denjhang commented 1 year ago

It looks like I have to recompile the firmware. It seems that using the Pico SDK on Windows 10 is a bit complicated, can you just upload the latest UF2 firmware so I can test it quickly?

danielrfry commented 1 year ago

I've added automated builds with GitHub Actions, you can find the UF2 for the current revision here:

https://github.com/danielrfry/opl2sd1/actions/runs/4657279593

denjhang commented 1 year ago

I have updated the firmware, but how to use nsplay? I found that when I use Retro Wave Player directly, the notes are still cut off. And the compatibility of Retro Wave Player to VGM is poor, when encountering non-OPL3 music, Retro Wave Player will not skip automatically and the program will close automatically. When playing Invention.and.Sinfonia.zip, only 5 tracks can be played continuously, and then the program will close automatically. So I suggest you keep the Python player you wrote for stronger compatibility.

danielrfry commented 1 year ago

The audio files were just to demonstrate the correct/incorrect sound, to help with identifying/fixing the issue - I haven't made any changes to the allocator code yet.

The OPL3 version is rendered using nsplay and the ymfm emulator, and demonstrates the correct sound. The YMF825 version is recorded output from the current firmware, which has the channel allocation issues.

My aim is to add RetroWave protocol support to nsplay (which has more features than the sample Python VGM player in this repository) so that it can be used with this device, the RetroWave OPL3 board, and the ymfm emulator. That way there will be no need to maintain two separate player programs, and any VGM player compatible with RetroWave can also be used.

danielrfry commented 1 year ago

I have re-written the channel allocator which I believe will resolve some of the issues described here and in #13.

Please try the latest firmware build from here: https://github.com/danielrfry/opl2sd1/actions/runs/4659405073

denjhang commented 1 year ago

Although the latest firmware has alleviated the problem of note stuttering, it is not perfect, and many sustains and chords will still be "swallowed".Especially the 2x2op patches.

denjhang commented 1 year ago

You can test my music and sound bank with the latest version of OPL3BankEditor Coup De Coeur.zip

denjhang commented 1 year ago

Regarding the channel allocation algorithm, I suggest that you can also refer to the method of OPL3BankEditor, because I run this program directly on the computer and it will play my music perfectly.

denjhang commented 1 year ago

It is obvious that YMF825 lacks more than 2 channels than OPL3. When the channels are obviously insufficient, my suggestion is to give higher priority to the shorter notes, let them cover the longer notes, and let the notes that appear later cover the earliest notes. The notes that appear.

denjhang commented 1 year ago

Because in many piano MIDIs, there are many overlong sustained tones, which are usually caused by the sustain pedal or reverberation. Once it lasts for 2S, this note will have no meaning, so these notes can be covered.

danielrfry commented 1 year ago

I have fixed some bugs that were causing notes to be cut off when they should not have been, if you'd like to try the latest build:

https://github.com/danielrfry/opl2sd1/actions/runs/4683260124

I'm hopeful this version will handle sustained notes much better.

denjhang commented 1 year ago

Today I tried the piano solo midi music without sustain, and found that it is normal when using 2op tones, but when I use 2x2op tones, the sound swallowing phenomenon still occurs. For midi piano solos that use a lot of extended sounds, the current version of the firmware still swallows the sound seriously. Yiruma-SOLO.zip Here's a set of solo midi pianos that make heavy use of the sustain pedal.

danielrfry commented 1 year ago

I think there might be more than one issue here - I've fixed a couple more things but I'm not sure whether they are related to the problem you've described. I have found it quite difficult to debug with such complex MIDI files.

https://github.com/danielrfry/opl2sd1/actions/runs/4708450511/jobs/8350896014

Please could you find a single, simple example of the problem, and provide detailed steps to recreate it (including the exact bank file and instrument to use in OPL3BankEditor). If you could provide short recordings showing an example of the correct/incorrect playback as well, that would help me to understand the issue better. Thanks!

denjhang commented 1 year ago

The latest version of the firmware has improved significantly. Sincerely happy for you.

denjhang commented 1 year ago

https://user-images.githubusercontent.com/61811583/232237607-3710a828-a588-47ff-adfb-d3d51a026478.mp4 https://user-images.githubusercontent.com/61811583/232237615-5de20298-be54-4d92-803c-75f51be8126d.mp4 These two videos show the correct sound, too beautiful piano music (at least I think so). By the way, this is my completely original OPL3 piano sound, only using FM parameters to realize the reverb effect, without relying on any external DSP reverb. Below are the midi files and library files played in the video. I use "Warm Grand Piano", Bank 0, ID 7. Lost In Island.zip

denjhang commented 1 year ago

I've found that it probably takes more than 2 SD-1 modules to play the music perfectly. At present, it does not seem to be a problem with the scheduling algorithm, and it is very likely that there are still insufficient channels when it is optimized to the extreme.

denjhang commented 1 year ago

Most solo midi piano music that doesn't make extensive use of the sustain pedal can now be played normally.

denjhang commented 1 year ago

On the other hand, even when I play Lost In Island.zip with 2op patches, there are still a lot of notes being cut off and swallowed.