EXPERIMENTAL native host system sound device output for OpenMPT on Wine on Linux

Started by manx, February 26, 2017, 14:50:21

Previous topic - Next topic

manx

What?

As kind of a for-fun project, I implemented native sound output for OpenMPT when running on Wine on Linux. The first version to have it is 1.27.00.34 r7701 as of 2017-02-26. It has only been tested on the following system setups so far:
OpenMPTDistributionArchitectureWine VersionPackagesRemarks
1.27-oldDebian 8amd64wine 1.6.2wine wine32-tools
1.27-oldDebian 8amd64wine-development 1.7.29wine-development wine64-development-tools
1.27-oldUbuntu 14.04 LTSamd64wine 1.6.2wine wine-1.6-dev
1.27Debian 9amd64wine-development 2.0-3+b2wine64-development wine64-development-tools
1.27Ubuntu 16.04 LTSi686wine-development 1.9.6wine-development libwine-development-dev
1.27Ubuntu 16.04 LTSamd64wine-development 1.9.6wine-development libwine-development-dev
1.28Debian 9amd64wine-development 2.0-3+b2wine64-development wine64-development-tools
1.28Debian 10amd64wine 4.0wine wine64 libwine-dev wine64-tools
1.28Ubuntu 16.04 LTSi686wine-development 1.9.6wine-development libwine-development-dev
1.28Ubuntu 16.04 LTSamd64wine-development 1.9.6wine-development libwine-development-dev
1.28Ubuntu 18.04 LTSamd64wine 3.0wine-stable wine64-tools libwine-dev
1.28Ubuntu 20.04 LTSamd64wine 5.0wine wine64-tools libwine-dev
  • Harmless compiler warning when using RtAudio.
1.28Linux Mint 19.3amd64wine 3.0wine-stable wine64-tools libwine-dev
  • Do not use the wine-stable or wine-installer 4.0 (or later) packages provided by Linux Mint,
    because although they provide winegcc, they fail to provide windows.h.
    Force the Wine 3.0 packages provided by upstream Ubuntu 18.04 LTS instead.
1.28GhostBSD 11.1 ALPHA1
(FreeBSD 11.1-RC3)
amd64wine-development 2.13wine-devel
1.29Debian 10amd64wine 4.0wine wine64 libwine-dev wine64-tools
1.29Ubuntu 18.04 LTSamd64wine 3.0wine-stable wine64-tools libwine-dev
1.29Ubuntu 20.04 LTSamd64wine 5.0wine wine64-tools libwine-dev
1.29Linux Mint 19.3amd64wine 3.0wine-stable wine64-tools libwine-dev
  • Do not use the wine-stable or wine-installer 4.0 (or later) packages provided by Linux Mint,
    because although they provide winegcc, they fail to provide windows.h.
    Force the Wine 3.0 packages provided by upstream Ubuntu 18.04 LTS instead.
1.29Linux Mint 20.1amd64wine 5.0wine wine64-tools libwine-dev
  • Do not use the wine-installer package provided by Linux Mint,
    because although it provides winegcc, it fails to provide windows.h.
1.30Ubuntu 20.04 LTSamd64wine 5.0wine wine64-tools libwine-dev
1.30Linux Mint 20.1amd64wine 5.0wine wine64-tools libwine-dev
  • Do not use the wine-installer package provided by Linux Mint,
    because although it provides winegcc, it fails to provide windows.h.
1.30Linux Mint 20.2amd64wine 5.0wine wine64-tools libwine-dev
  • Do not use the wine-installer package provided by Linux Mint,
    because although it provides winegcc, it fails to provide windows.h.
1.31Debian 11amd64wine 5.0wine wine64 libwine-dev wine64-tools
1.32Debian 11amd64wine 5.0wine wine64 libwine-dev wine64-tools
This means, that OpenMPT can now, as an EXPERIMENTAL feature, completely bypass the emulation of Windows sound drivers as implemented in Wine, and instead talk to the native Linux APIs directly.
In its current form, only support for PulseAudio and PortAudio is implemented.
Support for PulseAudio currently still uses the "Simple API" which is suboptimal for the features that OpenMPT wants to use. This will be improved to use the full API in a later OpenMPT version.
Support for PortAudio is probably final in its current form and is no high priority. PortAudio itself can, in particular, talk to ALSA devices directly. PortAudio can also talk to JACK, but this has not been tested at all in OpenMPT and very probably does not work correctly yet.
In addition to using native Linux sound APIs, OpenMPT can now also boost the thread priority, which was not possible at all when using the standard Windows APIs as emulated by Wine. OpenMPT can use both, Linux Realtime Scheduling priorities directly as well as setting system-defined priorities through RealtimeKit. The way OpenMPT chooses between these 2 ways is the way recommended by the Linux Audio Developers community.


How?

Using Wine integration in OpenMPT has various requirements on the host system:
  • OpenMPT bitness must be the same as host system bitness, i.e. use OpenMPT 32bit on i686 and OpenMPT 64bit on x86-64.
  • On Debian or Ubuntu (and derivates), the following packages must be installed: coreutils dialog make pkg-config cpp gcc g++ binutils ccache xterm.
  • Additionally, the Wine developments headers and tools must also be installed. These are called completely different but similarly looking names on various distributions. See the list of tested systems for hints on what package names to look out for.
  • The following packages need optionally be installed: libpulse-dev (for PulseAudio), libjack-jackd2-dev and portaudio19-dev (for PortAudio), libdbus-1-dev (for RealtimeKit)
  • Other distributions should also work, but you have to figure out the required packages yourself.

In order to enable Wine integration, go to the Wine options tab (the tab is only shown if OpenMPT actually detected Wine), check the checkbox and restart OpenMPT. Additional settings are available under Advanced settings in the WineSupport section. For most of these settings, you need to restart OpenMPT for them to take effect.


If OpenMPT Wine integration is enabled, OpenMPT will compile the required library adapters for your system on startup itself. It will spawn a terminal window and show a progress bar while doing so. Please do not be scared or surprised when you see the terminal window popping up. Starting native host applications from within a Windows application running on Wine is officially supported behaviour of Wine. If all works fine, native sound devices will be listed in the Sound Card settings.



Technical Details

2 shared libraries are compiled by OpenMPT. The required source code is distributed with OpenMPT in the file openmpt-wine-support.zip and must match the OpenMPT version exactly.


openmpt_wine_support.dll gets placed below AppData/ in the Wine environment. This is a Wine DLL, which will be loaded by OpenMPT and used as a proxy to call to the system native library libopenmpt_native_support.so.
libopenmpt_native_support.so gets placed below $XDG_DATA_HOME/ on the host system. The shared library is a host-native library that implements the OpenMPT sound device API on top of the PulseAudio or PortAudio libraries provided by the host system.

OpenMPT will recompile these libraries as required and cache the result such that starting the exact same version of OpenMPT again does not require recompiling.

monsterovich

We also need prebuilt binaries.  ;)

Saga Musix

It's not really feasible to provide pre-built binaries for the n different Linux distributions times m different Wine versions out there. If you have problems with the feature (if so, please post them), those would most likely also exist with pre-built binaries.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

monsterovich

Quote from: Saga Musix on February 27, 2017, 22:43:07
It's not really feasible to provide pre-built binaries for the n different Linux distributions times m different Wine versions out there. If you have problems with the feature (if so, please post them), those would most likely also exist with pre-built binaries.

Such wine libraries should be compatible with different wine versions (ex. wineasio works well). The process of building a wine library is very complicated for users.
That's why we should have built-in binaries.

manx

Compatibility with different Wine versions should in fact not be a problem.
However, there are a couple of other problems:

  • The way we use 2 libraries (which is absolutely required to keep the code maintainable and extendible) requires hard-coding the library path of the .so in the .dll. That path is user-specific and even runtime dependent on environment variables.
  • Providing binaries would require different binaries for different system setups. In the past, you often stated that you do not want PulseAudio on your system. If we provided binaries, these would drag in PulseAudio (and PortAudio and DBus) as a dependency for you OR we would have to implement dynamic on-demand loading for these libraries which would increase the maintenance overhead considerably.
Thus, the effort to make binaries would require: #distributions (because of different settings in the distribution default C++ ABI used by the native .so library) * #configurations * #platforms. The distributions amount to about 2 stable Debian versions, Debian testing, 2 stable Ubuntu LTS versions, the latest Ubuntu non-LTS, latest Fedora, latest OpenSuse, probably latest Arch and Gentoo, which amounts to about 10 systems I would have to maintain to actually build those, let alone actually test them. There are about 2^3 configurations and 3 platforms (i568, i686+SSE2, x86-64). This results in 10*8*3 = 240 packages. I wont do that. Ever.
Also consider that we only have about 5% users on Wine (of which (I am guessing here because we do not have these numbers) about 50% are using Linux) of which (even more guessing) at best 10% would even be using the Wine integration feature at all. Providing packages for about 0.25% of the users is not worth the effort.

Also, what aspect of building the libraries is difficult?
We only require packages in the stock distribution repository.
Installing binary packages would require users either to setup an additional package repository in their package manager or install the OpenMPT Wine integration packages by hand.

monsterovich

How can I also build these libraries outside openmpt?

-----------

I got an error:

http://www.zimagez.com/zimage/2017-02-2814-37-56.php

FIXED: http://pastebin.com/7zEujVNn

Saga Musix

This is a known bug in the current Wine development version and will be fixed in the next Wine update (which I suppose will be available in a few days).
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

monsterovich


manx

Quote from: monsterovich on February 28, 2017, 13:18:37
http://www.zimagez.com/zimage/2017-02-2815-11-13.php
The buffer value is probably invalid.

The value displayed as "Buffer" is just the overall buffer/latency divided by the buffer that is requested/used by OpenMPT/PortAudio, i.e. it's literally just currentlatency/latency as shown the line below it.

In any case, that latency is way higher than I would expect it to need to be for stable playback. Is your ALSA default device using dmix?

manx

Quote from: monsterovich on February 28, 2017, 12:29:08
How can I also build these libraries outside openmpt?

Even though that is technically possible of course, it is currently not supported and I do not want to document that right now because the process will almost certainly be changed often.
Also, different versions are guarded and cached using checksums, which you would have to calculate manually when compiling outside of OpenMPT in order to be able to place the libraries in the expected directory (the checksum is part of the pathname).


manx

Quote from: monsterovich on February 28, 2017, 18:35:27
Quote from: manx on February 28, 2017, 14:02:35
Is your ALSA default device using dmix?
Yes.

So, your dmix is configured for about 93ms of latency. The numbers are not all that surprising then.

Note that PulseAudio does not use a fixed period and buffer output strategy but rather a huge buffer which may be filled on as short notice as required, allowing it to dynamically work with appropriate application to outputjack latency as required and desired per application. That is, IMHO, way better suited for occasional DAW usage than dmix is.

manx


manx

Supported also on BSD now, since r8780.

Tested on:
GhostBSD 11.1 ALPHA1 (FreeBSD 11.1-RC3), wine-development 2.13 (wine-devel)

monsterovich