entropia / tip-toi-reveng

Trying to understand the file format of Tip Toi
http://tttool.entropia.de/
MIT License
655 stars 122 forks source link

Use Proteaaudio for audio playback #290

Open nomeata opened 1 year ago

nomeata commented 1 year ago

What works

What needs to be done

csabahruska commented 1 year ago

Would ALSA or OSS work better? It's possible to enable these backends: https://github.com/csabahruska/proteaaudio/blob/master/cbits/RtAudio.h#L286-L293

nomeata commented 1 year ago

Good point! I'll investigate.

nomeata commented 1 year ago

Based on https://www.music.mcgill.ca/~gary/rtaudio/compiling.html it seems that in particular the OSS backend needs no extra libraries, so static building should be possible.

For ALSA it seems that [static builds are possible](https://github.com/alsa-project/alsa-lib/blob/master/INSTALL#L4>, so that should work as well; might require more work on the nixpkgs side.

So some Cabal flags to choose a backend might help indeed!

nomeata commented 1 year ago

Would ALSA or OSS work better?

How do I enable that backend, @csabahruska? Just

~/build/haskell/proteaaudio/proteaaudio $ git diff
diff --git a/proteaaudio/proteaaudio.cabal b/proteaaudio/proteaaudio.cabal
index 939c4e0..d0caa1e 100644
--- a/proteaaudio/proteaaudio.cabal
+++ b/proteaaudio/proteaaudio.cabal
@@ -87,9 +87,8 @@ Library
     CXX-Options:        "-D__WINDOWS_DS__"
     Extra-Libraries:    ole32 dsound winmm
   if os(linux)
-    CXX-Options:        "-D__LINUX_PULSE__"
-    Extra-Libraries:    pthread pulse-simple pulse
-    pkgconfig-depends:  libpulse-simple, libpulse
+    CXX-Options:        "-D__LINUX_OSS__"
+    Extra-Libraries:    pthread
   if os(darwin)
     CXX-Options:        "-D__MACOSX_CORE__"
     Extra-Libraries:    pthread

Did not seem to be enough, I get errors from the C compiler.

csabahruska commented 1 year ago

It should be that but it seems that OSS is simply broken on recent linux systems. others have the same issue: https://github.com/mltframework/mlt/issues/716#issuecomment-855446265 Does any program that uses the OSS API compile on you machine?

nomeata commented 1 year ago

Yeah, also see https://github.com/thestk/rtaudio/issues/90. Probably OSS not is not a way to go. That leaves ALSA 👀

nomeata commented 1 year ago

I can compile against alsa with this:

diff --git a/proteaaudio/proteaaudio.cabal b/proteaaudio/proteaaudio.cabal
index cb2cba8..89ab45f 100644
--- a/proteaaudio/proteaaudio.cabal
+++ b/proteaaudio/proteaaudio.cabal
@@ -88,9 +88,9 @@ Library
     CXX-Options:        "-D__WINDOWS_DS__"
     Extra-Libraries:    ole32 dsound winmm
   if os(linux)
-    CXX-Options:        "-D__LINUX_PULSE__"
-    Extra-Libraries:    pthread pulse-simple pulse
-    pkgconfig-depends:  libpulse-simple, libpulse
+    CXX-Options:        "-D__LINUX_ALSA__"
+    Extra-Libraries:    pthread
+    pkgconfig-depends:  alsa
   if os(darwin)
     CXX-Options:        "-D__MACOSX_CORE__"
     Extra-Libraries:    pthread

and it works if I compile normally.

I can even compile statically against a statically linked ALSA library, but the resulting binary doesn’t work:

~/projekte/tiptoi/tip-toi-reveng $ ./result/bin/tttool play text2speech.gme
Initial state (not showing zero registers): $0=0
Playing audio sample 0
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib control.c:1543:(snd_ctl_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_ctl_pulse.so cannot be opened or _snd_ctl_pulse_open was not defined inside
ALSA lib pcm.c:2657:(snd_pcm_open_conf) Either /nix/store/rp36fxs6am3pxbfwnf3hnl947yx6dxyl-alsa-plugins-1.2.7.1/lib/alsa-lib/libasound_module_pcm_pulse.so cannot be opened or _snd_pcm_pulse_open was not defined inside
RtApiAlsa::probeDeviceOpen: pcm device (default) won't open for output.

It seems that ALSA has a plugin architecture, and once compiled statically, it cannot load such plugins any more? In that way, it’s no better for me than using libpulse.

csabahruska commented 1 year ago

So what will you do? Is it possible at all on linux to use static linking with on audio lib.

nomeata commented 1 year ago

I'm inclined to use the old code, shelling out to sox, on Linux, but use your library on Windows and OsX (when and if MP3 is supported)