Author Topic: EXPERIMENTAL native host system sound device output for OpenMPT on Wine on Linux  (Read 2989 times)

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 160
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:
DistributionArchitectureWine VersionPackages
Debian 8x86-64wine 1.6.2wine wine32-tools
Debian 8x86-64wine-development 1.7.29wine-development wine64-development-tools
Debian 9x86-64wine-development 2.0-3+b2wine64-development wine64-development-tools
Ubuntu 14.04x86-64wine 1.6.2wine wine-1.6-dev
Ubuntu 16.04i686wine-development 1.9.6wine-development libwine-development-dev
GhostBSD 11.1 ALPHA1
(FreeBSD 11.1-RC3)
x86-64wine-development 2.13wine-devel
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.
« Last Edit: September 16, 2017, 17:27:28 by manx »

Offline monsterovich

  • Active artist
  • *
  • Posts: 38
  • Operating System: Linux (wine) :P
We also need prebuilt binaries.  ;)
« Last Edit: February 28, 2017, 13:08:10 by monsterovich »

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 6,303
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 7 x64
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.

Offline monsterovich

  • Active artist
  • *
  • Posts: 38
  • Operating System: Linux (wine) :P
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.
« Last Edit: February 28, 2017, 09:12:46 by monsterovich »

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 160
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.

Offline monsterovich

  • Active artist
  • *
  • Posts: 38
  • Operating System: Linux (wine) :P
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
« Last Edit: February 28, 2017, 12:49:39 by monsterovich »

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 6,303
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 7 x64
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.

Offline monsterovich

  • Active artist
  • *
  • Posts: 38
  • Operating System: Linux (wine) :P
« Last Edit: February 28, 2017, 18:33:34 by monsterovich »

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 160
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?

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 160
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).

Offline monsterovich

  • Active artist
  • *
  • Posts: 38
  • Operating System: Linux (wine) :P
Is your ALSA default device using dmix?

Yes.

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 160
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.

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 160
As of r8368, this now also works on Debian 9.

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 160
Supported also on BSD now, since r8780.

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

Offline monsterovich

  • Active artist
  • *
  • Posts: 38
  • Operating System: Linux (wine) :P
https://pastebin.com/dpprgJTy

Can you please allow to build 32bit wrapper on 64bit system (-m32 or something)?