JuliaAudio / PortAudio.jl

PortAudio wrapper for the Julia programming language, compatible with the JuliaAudio family of packages
Other
115 stars 19 forks source link

Failing to start under Pipewire #121

Open jariji opened 2 years ago

jariji commented 2 years ago

I tried to follow the readme.

NixOS, with Pipewire emulating Pulseaudio. Julia 1.7.1

julia> using PortAudio, SampledSignals
 │ Packages [PortAudio, SampledSignals] not found, but packages named
 │ [PortAudio, SampledSignals] are available from a registry. 
 │ Install packages?
 │   (jl_OSROBd) pkg> add PortAudio SampledSignals 
 └ (y/n) [y]: 
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/tmp/jl_OSROBd/Project.toml`
  [80ea8bcb] + PortAudio v1.3.0
  [bd7594eb] + SampledSignals v2.1.3
    Updating `/tmp/jl_OSROBd/Manifest.toml`
  [621f4979] + AbstractFFTs v1.2.1
  [4fba245c] + ArrayInterface v6.0.23
  [30b0a656] + ArrayInterfaceCore v0.1.20
  [d360d2e6] + ChainRulesCore v1.15.5
  [9e997f8a] + ChangesOfVariables v0.1.4
  [34da2185] + Compat v3.46.0
  [187b0558] + ConstructionBase v1.4.1
  [717857b8] + DSP v0.7.7
  [ffbed154] + DocStringExtensions v0.9.1
  [da5c29d0] + EllipsisNotation v1.6.0
  [7a1cc6ca] + FFTW v1.5.0
  [53c48c17] + FixedPointNumbers v0.8.4
  [615f187c] + IfElse v0.1.1
  [8197267c] + IntervalSets v0.5.4
  [3587e190] + InverseFunctions v0.1.7
  [92d709cd] + IrrationalConstants v0.1.1
  [c8e1da08] + IterTools v1.4.0
  [692b3bcd] + JLLWrappers v1.4.1
  [2ab3a3ac] + LogExpFunctions v0.3.18
  [f27b6e38] + Polynomials v3.2.0
  [80ea8bcb] + PortAudio v1.3.0
  [21216c6a] + Preferences v1.3.0
  [3cdcf5f2] + RecipesBase v1.2.1
  [189a3867] + Reexport v1.2.2
  [bd7594eb] + SampledSignals v2.1.3
  [276daf66] + SpecialFunctions v2.1.7
  [aedffcd0] + Static v0.7.6
  [fd094767] + Suppressor v0.2.1
  [a2a6695c] + TreeViews v0.3.0
  [1986cc42] + Unitful v1.12.0
  [cd00e070] + BerkeleyDB_jll v18.1.40+0
  [471b5b61] + BlueZ_jll v5.54.0+1
  [6e34b625] + Bzip2_jll v1.0.8+0
  [83423d85] + Cairo_jll v1.16.1+1
  [491db154] + Check_jll v0.15.2+0
  [ee1fde0b] + Dbus_jll v1.12.16+3
  [ab5a07f8] + Elfutils_jll v0.182.0+1
  [2e619515] + Expat_jll v2.4.8+0
  [b22a6f82] + FFMPEG_jll v4.4.2+0
  [f5851436] + FFTW_jll v3.3.10+0
  [1d38b3a6] + FLAC_jll v1.3.4+1
  [a3f928ae] + Fontconfig_jll v2.13.93+0
  [d7e528f0] + FreeType2_jll v2.10.4+0
  [559328eb] + FriBidi_jll v1.0.10+0
  [1b77fbbe] + GSL_jll v2.7.2+0
  [aaaaf01e] + GStreamer_jll v1.18.3+0
  [54ca2031] + Gdbm_jll v1.19.0+0
  [78b55507] + Gettext_jll v0.21.0+0
  [7746bdde] + Glib_jll v2.68.3+2
  [3b182d85] + Graphite2_jll v1.3.14+0
  [2e76f6c2] + HarfBuzz_jll v2.8.1+1
  [a51ab1cf] + ICU_jll v68.2.0+0
  [1d5cc7b8] + IntelOpenMP_jll v2018.0.3+2
  [c1c5ebd0] + LAME_jll v3.100.1+0
  [dd4b983a] + LZO_jll v2.10.1+0
  [e9f186c6] + Libffi_jll v3.2.2+1
  [d4300ac3] + Libgcrypt_jll v1.8.7+0
  [7add5ba3] + Libgpg_error_jll v1.42.0+0
  [bce108ef] + Libical_jll v3.0.9+0
  [94ce4f54] + Libiconv_jll v1.16.1+1
  [4b2f31a3] + Libmount_jll v2.35.0+0
  [a76c16ae] + Libtool_jll v2.4.6+0
  [38a345b3] + Libuuid_jll v2.36.0+0
  [856f044c] + MKL_jll v2022.1.0+0
  [68e3532b] + Ncurses_jll v6.2.0+0
  [e7412a2a] + Ogg_jll v1.3.5+1
  [458c3c95] + OpenSSL_jll v1.1.17+0
  [efe28fd5] + OpenSpecFun_jll v0.5.5+0
  [91d4177d] + Opus_jll v1.3.2+0
  [2f80f16e] + PCRE_jll v8.44.0+0
  [30392449] + Pixman_jll v0.40.1+0
  [02771fc1] + PulseAudio_jll v15.0.0+0
  [05236dd9] + Readline_jll v8.1.1+1
  [da37f231] + SBC_jll v1.4.0+0
  [fbe68eb6] + SoXResampler_jll v0.1.3+0
  [f2f9631b] + SpeexDSP_jll v1.2.0+0
  [02c8fc9c] + XML2_jll v2.9.14+0
  [aed1982a] + XSLT_jll v1.1.34+0
  [ffd25f8a] + XZ_jll v5.2.5+2
  [4f6342f7] + Xorg_libX11_jll v1.6.9+4
  [0c0b7dd1] + Xorg_libXau_jll v1.0.9+4
  [a3789734] + Xorg_libXdmcp_jll v1.1.3+4
  [1082639a] + Xorg_libXext_jll v1.3.4+4
  [ea2f1a96] + Xorg_libXrender_jll v0.9.10+4
  [14d82f49] + Xorg_libpthread_stubs_jll v0.1.0+3
  [c7cfdc94] + Xorg_libxcb_jll v1.13.0+3
  [c5fb5394] + Xorg_xtrans_jll v1.4.0+3
  [45378030] + alsa_jll v1.2.5+0
  [5ac2f6bb] + alsa_plugins_jll v1.2.2+0
  [c53206cc] + argp_standalone_jll v1.3.1+0
  [35ca27e7] + eudev_jll v3.2.9+0
  [d65627f6] + fts_jll v1.2.7+1
  [1a1c6b14] + gperf_jll v3.1.0+0
  [a4ae2306] + libaom_jll v3.4.0+0
  [0ac62f75] + libass_jll v0.15.1+0
  [ed080073] + libasyncns_jll v0.8.0+0
  [eef66a8b] + libcap_jll v2.27.0+0
  [f638f0a6] + libfdk_aac_jll v2.0.2+0
  [b53b4c65] + libpng_jll v1.6.38+0
  [2d7b7beb] + libportaudio_jll v19.7.0+0
  [9427e74d] + libsamplerate_jll v0.1.9+0
  [5bf562c0] + libsndfile_jll v1.1.0+0
  [f27f6e37] + libvorbis_jll v1.3.7+1
  [c88a4935] + obstack_jll v1.2.2+0
  [1270edf5] + x264_jll v2021.5.5+0
  [dfaa095f] + x265_jll v3.5.0+0
  [0dad84c5] + ArgTools
  [56f22d72] + Artifacts
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [8bb1440f] + DelimitedFiles
  [8ba89e20] + Distributed
  [f43a241f] + Downloads
  [b77e0a4c] + InteractiveUtils
  [4af54fe1] + LazyArtifacts
  [b27032c2] + LibCURL
  [76f85450] + LibGit2
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [a63ad114] + Mmap
  [ca575930] + NetworkOptions
  [44cfe95a] + Pkg
  [de0858da] + Printf
  [3fa0cd96] + REPL
  [9a3f8284] + Random
  [ea8e919c] + SHA
  [9e88b42a] + Serialization
  [1a1011a3] + SharedArrays
  [6462fe0b] + Sockets
  [2f01184e] + SparseArrays
  [10745b16] + Statistics
  [4607b0f0] + SuiteSparse
  [fa267f1f] + TOML
  [a4e569a6] + Tar
  [8dfed614] + Test
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode
  [e66e0078] + CompilerSupportLibraries_jll
  [781609d7] + GMP_jll
  [deac9b47] + LibCURL_jll
  [29816b5a] + LibSSH2_jll
  [745a5e78] + LibUnwind_jll
  [c8ffd9c3] + MbedTLS_jll
  [14a3606d] + MozillaCACerts_jll
  [4536629a] + OpenBLAS_jll
  [05823500] + OpenLibm_jll
  [83775a58] + Zlib_jll
  [8e850b90] + libblastrampoline_jll
  [8e850ede] + nghttp2_jll
  [3f19e933] + p7zip_jll
ERROR: InitError: ArgumentError: Could not find alsa.conf in ("/usr/share/alsa", "/usr/local/share/alsa", "/etc/alsa")
Stacktrace:
 [1] seek_alsa_conf(folders::Tuple{String, String, String})
   @ PortAudio ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:128
 [2] __init__()
   @ PortAudio ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:135
 [3] _include_from_serialized(path::String, depmods::Vector{Any})
   @ Base ./loading.jl:768
 [4] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String)
   @ Base ./loading.jl:854
 [5] _require(pkg::Base.PkgId)
   @ Base ./loading.jl:1097
 [6] require(uuidkey::Base.PkgId)
   @ Base ./loading.jl:1013
 [7] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:997
during initialization of module PortAudio

julia> stream = PortAudioStream(2, 2; warn_xruns = false);
ERROR: UndefVarError: PortAudioStream not defined
Stacktrace:
 [1] top-level scope
   @ REPL[4]:1

julia> PortAudio.initialize()
ERROR: UndefVarError: PortAudio not defined
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

julia> using PortAudio

julia> PortAudio.initialize()
┌ Debug: ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
│ ALSA lib control.c:1481:(snd_ctl_open_noupdate) Invalid CTL hw:0
│ ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
│ ALSA lib control.c:1481:(snd_ctl_open_noupdate) Invalid CTL hw:1
│ ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
│ ALSA lib control.c:1481:(snd_ctl_open_noupdate) Invalid CTL hw:2
│ ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
│ ALSA lib control.c:1481:(snd_ctl_open_noupdate) Invalid CTL hw:3
└ @ PortAudio ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:113

julia> PortAudio.initialize()

julia> stream = PortAudioStream(2, 2; warn_xruns = false);
ERROR: ArgumentError: invalid value for Enum PaErrorCode: -1
Stacktrace:
 [1] enum_argument_error(typename::Symbol, x::Int32)
   @ Base.Enums ./Enums.jl:85
 [2] PaErrorCode
   @ ./Enums.jl:198 [inlined]
 [3] handle_status(error_number::Int32; warn_xruns::Bool)
   @ PortAudio ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:94
 [4] handle_status
   @ ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:93 [inlined]
 [5] get_default_input_index
   @ ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:199 [inlined]
 [6] PortAudioStream(input_channels::Int64, output_channels::Int64; keywords::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:warn_xruns,), Tuple{Bool}}})
   @ PortAudio ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:871
 [7] top-level scope
   @ REPL[8]:1

julia> PortAudio.devices()
PortAudio.PortAudioDevice[]
bramtayl commented 2 years ago

Right now PulseAudio isn't set up to work with pipewire. Related: #92. Some of the other errors might be separate issues. Do you still have alsa? Can you find an alsa.conf file? The invalid PaErrorCode message is a bit of a bug: we should be throwing a better error there.

jariji commented 2 years ago

I have the pipewire-alsa compatiblity shim enabled and there are some related-looking files:

% ll /etc/alsa/conf.d
lrwxrwxrwx 48 root 18 Sep 12:09 49-pipewire-modules.conf -> /etc/static/alsa/conf.d/49-pipewire-modules.conf
lrwxrwxrwx 40 root 18 Sep 12:09 50-pipewire.conf -> /etc/static/alsa/conf.d/50-pipewire.conf
lrwxrwxrwx 48 root 18 Sep 12:09 99-pipewire-default.conf -> /etc/static/alsa/conf.d/99-pipewire-default.conf
bramtayl commented 2 years ago

Well one thing to try would be to add /etc/static/alsa/ to the list here:

https://github.com/JuliaAudio/PortAudio.jl/blob/06c6fd04959975644e308b23138313bfcfde4765/src/PortAudio.jl#L137

bramtayl commented 2 years ago

Another thing to try might be to build a newer version of PulseAudio in BinaryBuilder:

https://github.com/JuliaPackaging/Yggdrasil/blob/master/P/PulseAudio/build_tarballs.jl

But I suspect the best way to solve it would be to build Pipewire with binary builder and then make alsa-plugins aware of it:

https://github.com/JuliaPackaging/Yggdrasil/blob/master/A/alsa_plugins/build_tarballs.jl

jariji commented 1 year ago

I tried setting the ALSA_CONFIG_DIR environment variable which got me past the build step but creating a stream failed. The error is coming from

https://files.portaudio.com/docs/v19-doxydocs/portaudio_8h.html#adc955dfab007624000695c48d4f876dc

which says

The user should first determine the available device ids by using the supplied application "pa_devs".

and then set the environment variable PA_RECOMMENDED_OUTPUT_DEVICE

so I look at pa_devs.c and it's calling Pa_GetDeviceCount. But

julia> PortAudio.LibPortAudio.Pa_GetDeviceCount()
0

even after

julia> PortAudio.LibPortAudio.Pa_Initialize()
0

julia> PortAudio.LibPortAudio.Pa_GetDeviceCount()
0

so something's wrong.

I didn't set ALSA_PLUGIN_DIR but I don't know if that's relevant.

In Python it works fine.

https://github.com/spatialaudio/python-sounddevice/blob/master/sounddevice.py#L453

>>> import sounddevice as sd
>>> sd._lib.Pa_GetDeviceCount()
13

julia> ENV["ALSA_CONFIG_DIR"] = "/etc/static/alsa"
pkg> add PortAudio, SampledSignals
julia> using PortAudio, SampledSignals;
julia> stream = PortAudioStream(2, 2; warn_xruns = false);
ERROR: ArgumentError: invalid value for Enum PaErrorCode: -1
Stacktrace:
 [1-5] ⋮ internal
     @ Base.Enums, PortAudio, Unknown
   [6] PortAudioStream(input_channels::Int64, output_channels::Int64; keywords::Base.Pairs{Symbol, Bool, …})
     @ PortAudio ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:871
Use `err` to retrieve the full stack trace.

julia> err
1-element ExceptionStack:
ArgumentError: invalid value for Enum PaErrorCode: -1
Stacktrace:
 [1] enum_argument_error(typename::Symbol, x::Int32)
   @ Base.Enums ./Enums.jl:93
 [2] PaErrorCode
   @ ./Enums.jl:211 [inlined]
 [3] handle_status(error_number::Int32; warn_xruns::Bool)
   @ PortAudio ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:94
 [4] handle_status
   @ ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:92 [inlined]
 [5] get_default_input_index
   @ ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:199 [inlined]
 [6] PortAudioStream(input_channels::Int64, output_channels::Int64; keywords::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:warn_xruns,), Tuple{Bool}}})
   @ PortAudio ~/.julia/packages/PortAudio/HNBv4/src/PortAudio.jl:871
 [7] top-level scope
   @ REPL[6]:1

(jl_3wZYpH) pkg> st 
Status `/tmp/jl_3wZYpH/Project.toml`
  [80ea8bcb] PortAudio v1.3.0
  [bd7594eb] SampledSignals v2.1.3

julia> versioninfo()
Julia Version 1.9.3
Commit bed2cd540a1 (2023-08-24 14:43 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 24 × AMD Ryzen 9 3900XT 12-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver2)
  Threads: 12 on 24 virtual cores
Environment:
  JULIA_NUM_THREADS = 12
  JULIA_PKG_PRESERVE_TIERED_INSTALLED = true
  JULIA_IMAGE_THREADS = 1
jariji commented 1 year ago

PortAudio.LibPortAudio.Pa_Initialize(); PortAudio.LibPortAudio.Pa_GetDeviceCount() isn't detecting any devices. This may be because it needs to be configured with pipewire support.