Wohlstand / libADLMIDI

A Software MIDI Synthesizer library with OPL3 (YMF262) emulator
GNU Lesser General Public License v3.0
174 stars 17 forks source link

Added an experimental ALSA sequencer client #274

Open NY00123 opened 9 months ago

NY00123 commented 9 months ago

For users of Linux and other relevant environments, this can be seen as a (limited) user-level ALSA equivalent of the WinMM driver.

I'm not as familiar with MIDI or ALSA as others may be, so good chances are that there's at least one mistake. I originally started with a small example currently found here: http://fundamental-code.com/midi/

This program could be adapted to allow greater configurability, the way the WinMM driver and other software did (like selecting a different OPL emulator or changing the number of chips). But I'm not as familiar again. Also, in this manner, I refrained from using GPLed standalone player code of ADLMIDI as a base, in case there's such code.

It currently uses SDL2 for sound output. Code can be written to use ALSA directly (as done for MIDI) and/or other APIs; I'm just more familiar with SDL2, and also know that it'll allow the use of multiple APIs/drivers via SDL_AUDIODRIVER.

For now I've used this program on my own, at least for a few purposes. Others may experiment with this client as well.

Wohlstand commented 9 months ago

Interesting thing! Ye, it's better to add more arguments, there are various options including work modes (different volume models, channel allocation modes), and ability to run with an external WOPL bank files, not just with embedded banks. Also, there is an option that builds the library with all embedded banks disabled, so only external bank files can be used in such builds.

Speaking about the sound output, it's would be good to allow setting different sample rates and sample formats (you may take a look into midiplay how it does), and the buffer size (affects the latency).

NY00123 commented 9 months ago

I see. I'll currently leave this PR as-is, in order to see if another person may test the patch.

I actually did optionally allow changing the sample rate in the beginning, but I eventually omitted this; adlmidiplay and the VLC plugin are the only components under utils that appear to allow the change (based on calls to adl_init), so this didn't seem to be a great deviation.

As for the various options, hopefully there's a source to adapt/copy from without having to change to a GPL license, albeit it's less of a problem for standalone programs; As an alternative to copying, this is where it looks like common configuration and command-line parsing code (to be used by multiple programs) could potentially help; Especially in case more options would get added in the future, and the existence of some of them depended on compile-time macros.

Wohlstand commented 9 months ago

Then, I could extend it by myself after testing. But right now I'm ill, and the rest of time I staying at my bed. I'll take this as soon as I can.

NY00123 commented 9 months ago

Then, I could extend it by myself after testing. But right now I'm ill, and the rest of time I staying at my bed. I'll take this as soon as I can.

First of all, get well soon!

Personally, I can make use of the sequencer client separately. libADLMIDI is structured as a library so other programs can use it, after all. I've still thought of adding the ALSA sequencer client to the repository, as it's more general purpose, like the WinMM driver, albeit expected to have a significantly smaller audience.

NY00123 commented 9 months ago

btw, this can be used with Windows software that's run via Wine, as Wine may subscribe to an ALSA sequencer client. One test case of mine is the game DemonStar (versions preceding the one recently released on Steam).

NY00123 commented 9 months ago

Added a minor modification defining the port as SND_SEQ_PORT_TYPE_MIDI_GENERIC. It was previously defined just as SND_SEQ_PORT_TYPE_APPLICATION, which wasn't sufficient for one program. Other bits might or might not make sense, and SND_SEQ_PORT_TYPE_APPLICATION should maybe be removed.

I've actually uploaded a demonstration of this sequencer with DemonStar last week. As written earlier, this does not hold to the new edition recently released via Steam, since it doesn't use MIDI at all. But other versions (including older shareware ones) should work, as demonstrated here: https://www.youtube.com/watch?v=KeTPOf9S_ks

As previously mentioned, I haven't really added a lot of user-accessible configuration. There might be ways in which the output differs from a single genuine OPL3 chip, like Nuked OPL3's optional extended stereo support accessible from EDuke32-based ports.

Ignoring the changes in output related to Apogee's EMIDI format, this technically allows stereo FM output for DOS executables by using the Apogee Sound System without modifying them, in case it's identified as a General MIDI device for the game. There was originally limited stereo FM support only, disabled in compile-time as of early February 1995, according to the Apogee Sound System's change log.