Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Proteaaudio for audio playback #290

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Use Proteaaudio for audio playback #290

wants to merge 15 commits into from

Conversation

nomeata
Copy link
Member

@nomeata nomeata commented Jul 14, 2023

What works

  • Playing OGG files
  • Aborting playing when a new sound is played

What needs to be done

Fixes #286

@csabahruska
Copy link

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
Copy link
Member Author

nomeata commented Jul 16, 2023

Good point! I'll investigate.

@nomeata
Copy link
Member Author

nomeata commented Jul 16, 2023

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
Copy link
Member Author

nomeata commented Jul 20, 2023

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
Copy link

csabahruska commented Jul 20, 2023

It should be that but it seems that OSS is simply broken on recent linux systems. others have the same issue: mltframework/mlt#716 (comment)
Does any program that uses the OSS API compile on you machine?

@nomeata
Copy link
Member Author

nomeata commented Jul 21, 2023

Yeah, also see thestk/rtaudio#90. Probably OSS not is not a way to go. That leaves ALSA 👀

@nomeata
Copy link
Member Author

nomeata commented Jul 21, 2023

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
Copy link

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

@nomeata
Copy link
Member Author

nomeata commented Jul 21, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore proteaaudio
2 participants