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

WHat backend to use on a Raspberry Pi (Zero 2) #36

Closed
andrewdavidmackenzie opened this issue Mar 22, 2024 · 9 comments
Closed

WHat backend to use on a Raspberry Pi (Zero 2) #36

andrewdavidmackenzie opened this issue Mar 22, 2024 · 9 comments

Comments

@andrewdavidmackenzie
Copy link

Describe the bug
Soloud::default() returns an error when run on raspberry pi zero 2 w.

To Reproduce
Compile code using the example code (I used a .wav file - I hope that is not important) for raspberry pi using:
cross build --target=arm-unknown-linux-musleabi

(this works for other code prior to adding soloud)

When run, the call to:

let sl = Soloud::default().expect("Could not get Soloud");

returns:

Could not get Soloud: Internal(UnknownError)

I wonder if there is a specific audio backend I need to chose for raspberry pi?

Expected behavior
default() returns a valid instance and I can play audio

Desktop (please complete the following information):

  • OS: Raspberry Pi OS
uname -a
Linux pizero2w0 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux
  • Version [e.g. 22]
  • Output of cargo build -vv: cross compiled from mac so not relevant, as build works fine.

Additional context

@andrewdavidmackenzie
Copy link
Author

I tried using the "alsa" feature, with the failure below.

Maybe that drags me into new "sysroot" territory?

Thanks for any help....

cross build --target arm-unknown-linux-musleabi
   Compiling soloud-sys v1.0.5
error: failed to run custom build command for `soloud-sys v1.0.5`

Caused by:
  process didn't exit successfully: `/target/debug/build/soloud-sys-43494ee817809a52/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build/android.rs
  cargo:rerun-if-changed=build/link.rs
  cargo:rerun-if-changed=build/main.rs
  cargo:rerun-if-changed=build/source.rs
  cargo:rerun-if-env-changed=CC
  cargo:rerun-if-env-changed=CXX
  cargo:rerun-if-env-changed=CFLAGS
  cargo:rerun-if-env-changed=CXXFLAGS
  cargo:rerun-if-changed=sys/CMakeLists.txt
  cargo:rerun-if-changed=sys/soloud_new.cpp
  cargo:rerun-if-changed=sys/soloud_derives.h
  cargo:rerun-if-changed=sys/soloud_derives.cpp
  CMAKE_TOOLCHAIN_FILE_arm-unknown-linux-musleabi = None
  CMAKE_TOOLCHAIN_FILE_arm_unknown_linux_musleabi = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_arm-unknown-linux-musleabi = None
  CMAKE_GENERATOR_arm_unknown_linux_musleabi = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_arm-unknown-linux-musleabi = None
  CMAKE_PREFIX_PATH_arm_unknown_linux_musleabi = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_arm-unknown-linux-musleabi = None
  CMAKE_arm_unknown_linux_musleabi = None
  TARGET_CMAKE = None
  CMAKE = None
  running: cd "/target/arm-unknown-linux-musleabi/debug/build/soloud-sys-12a7994f09c9ce7c/out/build" && CMAKE_PREFIX_PATH="" "cmake" "/cargo/registry/src/index.crates.io-6f17d22bba15001f/soloud-sys-1.0.5/sys" "-DWITH_ALSA=ON" "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "-DCMAKE_SYSTEM_NAME=Linux" "-DCMAKE_SYSTEM_PROCESSOR=arm" "-DCMAKE_INSTALL_PREFIX=/target/arm-unknown-linux-musleabi/debug/build/soloud-sys-12a7994f09c9ce7c/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv6 -marm -mfloat-abi=soft" "-DCMAKE_C_COMPILER=/usr/local/bin/arm-linux-musleabi-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv6 -marm -mfloat-abi=soft" "-DCMAKE_CXX_COMPILER=/usr/local/bin/arm-linux-musleabi-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv6 -marm -mfloat-abi=soft" "-DCMAKE_ASM_COMPILER=/usr/local/bin/arm-linux-musleabi-gcc" "-DCMAKE_BUILD_TYPE=Release"
  -- The C compiler identification is GNU 9.2.0
  -- The CXX compiler identification is GNU 9.2.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/local/bin/arm-linux-musleabi-gcc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/local/bin/arm-linux-musleabi-g++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /target/arm-unknown-linux-musleabi/debug/build/soloud-sys-12a7994f09c9ce7c/out/build
  running: cd "/target/arm-unknown-linux-musleabi/debug/build/soloud-sys-12a7994f09c9ce7c/out/build" && MAKEFLAGS="-j --jobserver-fds=7,8 --jobserver-auth=7,8" "cmake" "--build" "." "--target" "install" "--config" "Release"
  [  1%] Building CXX object CMakeFiles/soloud.dir/soloud_new.cpp.o
  [  3%] Building CXX object CMakeFiles/soloud.dir/soloud/src/backend/alsa/soloud_alsa.cpp.o
  [  5%] Building CXX object CMakeFiles/soloud.dir/soloud/src/c_api/soloud_c.cpp.o
  [  6%] Building CXX object CMakeFiles/soloud.dir/soloud_derives.cpp.o
  CMakeFiles/soloud.dir/build.make:103: recipe for target 'CMakeFiles/soloud.dir/soloud/src/backend/alsa/soloud_alsa.cpp.o' failed
  CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/soloud.dir/all' failed
  Makefile:135: recipe for target 'all' failed

  --- stderr
  fatal: not a git repository (or any parent up to mount point /)
  Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
  CMake Warning:
    Manually-specified variables were not used by the project:

      CMAKE_ASM_COMPILER
      CMAKE_ASM_FLAGS


  /cargo/registry/src/index.crates.io-6f17d22bba15001f/soloud-sys-1.0.5/sys/soloud/src/backend/alsa/soloud_alsa.cpp:41:10: fatal error: alsa/asoundlib.h: No such file or directory
     41 | #include <alsa/asoundlib.h>
        |          ^~~~~~~~~~~~~~~~~~
  compilation terminated.
  make[2]: *** [CMakeFiles/soloud.dir/soloud/src/backend/alsa/soloud_alsa.cpp.o] Error 1
  make[2]: *** Waiting for unfinished jobs....
  make[1]: *** [CMakeFiles/soloud.dir/all] Error 2
  make: *** [all] Error 2
  thread 'main' panicked at /cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:

  command did not execute successfully, got: exit status: 2

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@MoAlyousef
Copy link
Owner

MoAlyousef commented Mar 22, 2024

Hi

Unfortunately I don't have a similar system to try things out. And I'm not sure where the issue arises. The only thing that sticks out to me is the arch your targeting (arm-unknown-linux-musleabi) which is an armv6 or armv7 (32 bits) whereas the raspberry pi zero 2 w seems to be an arm64 system:
https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/

So you might try using cross build --target=aarch64-unknown-linux-musl.

The default backend is the miniaudio backend, which Soloud builds automatically, and which I would think is most preferable especially for cross-compilation.

Note that if you would like to try another backend with cross, you would have to tell cross how to install the dependencies in their provided container, for example (arm64-gnu):

[package.metadata.cross.target.aarch64-unknown-linux-gnu]
pre-build = [""" \
    dpkg --add-architecture arm64 && \
    apt-get update && \
    apt-get install --assume-yes --no-install-recommends \
    libasound2-dev:arm64
    """]

Unfortunately although debian provides musl-linux-arm* arches, it doesn't provide many packages for them.
So that might be a dead end.

Another option is to try building with docker and alpine (which uses musl by default), even if you would like to try other backend you would probably find alsa-lib-dev built for arm64.

A third option is if your raspberry pi runs raspbian or a gnu based distro, is to just not build with musl, and just target the gnu toolchain:
cross build --target=aarch64-unknown-linux-gnu

@andrewdavidmackenzie
Copy link
Author

Thanks for the fast response.

I tried aarch64-unknown-linux-musl - no difference. It can run 32bit or 64 bit executables.
I'm happy to stay with aarch64-unknown-linux-musl though. It works without soloud.

I also tried the gnu toolchain before, with the same or similar issues (I'd have to go back and reproduce them for details).

I can try building on the pi itself, but I doubt there will be any difference.
I don't see where that error is reported. I'd offer to debug it, but I don't have remote debugging working right now.

@MoAlyousef
Copy link
Owner

MoAlyousef commented Mar 23, 2024

Looking at the way the miniaudio driver is initialized, it searches for several libs in the system lib path, starting with libasound2 (alsa) then it dynamically loads it.
If it finds no libs, it defaults to a null driver which won’t produce any sound.
So you would still need to install libasound2 on your rpi. (You shouldn’t need the -dev package though)

@andrewdavidmackenzie
Copy link
Author

This is what I have:

find /usr/lib -name "lib*sound*"
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_ctl_pulse.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_lavrate.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_lavrate_higher.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_samplerate.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_speexrate_best.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_pcm_vdownmix.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_lavrate_fast.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_lavrate_faster.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_pcm_oss.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_pcm_jack.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_pcm_upmix.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_samplerate_medium.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_ctl_arcam_av.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_samplerate_order.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_samplerate_best.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_speexrate.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_pcm_pulse.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_speexrate_medium.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_ctl_oss.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_lavrate_high.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_conf_pulse.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_pcm_a52.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_pcm_usb_stream.so
/usr/lib/aarch64-linux-gnu/alsa-lib/libasound_module_rate_samplerate_linear.so
/usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstsoundtouch.so
/usr/lib/aarch64-linux-gnu/libasound.so.2
/usr/lib/aarch64-linux-gnu/libasound.so.2.0.0
/usr/lib/jvm/java-17-openjdk-arm64/lib/libjsound.so
/usr/lib/jvm/java-11-openjdk-arm64/lib/libjsound.so

So, I will see where I can get libsound2 ...

@andrewdavidmackenzie
Copy link
Author

andrewdavidmackenzie commented Mar 23, 2024

What exact file is it trying to load?

Would it find and load /usr/lib/aarch64-linux-gnu/libasound.so.2?

That comes as part of the libasound2 package and is installed.

On my Pi the file /etc/ld.so.conf.d/aarch64-linux-gnu.conf has:

# Multiarch support
/usr/local/lib/aarch64-linux-gnu
/lib/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu

The last line being /usr/lib/aarch64-linux-gnu where the files:

/usr/lib/aarch64-linux-gnu/libasound.so.2
/usr/lib/aarch64-linux-gnu/libasound.so.2.0.0

I tried export SYSTEM_LIB_PATH=/usr/lib/aarch64-linux-gnu/ also, but no change in error.

Maybe related to use of MUSL, so I'll try a switch to GNU libc and see if that changes how the dynamic linking works and if this lib is then found.

@andrewdavidmackenzie
Copy link
Author

Problem linking that (so far)...

cross build --target=aarch64-unknown-linux-gnu
info: downloading component 'rust-std' for 'aarch64-unknown-linux-gnu'
info: installing component 'rust-std' for 'aarch64-unknown-linux-gnu'
 32.1 MiB /  32.1 MiB (100 %)  12.0 MiB/s in  2s ETA:  0s
Unable to find image 'ghcr.io/cross-rs/aarch64-unknown-linux-gnu:0.2.5' locally
0.2.5: Pulling from cross-rs/aarch64-unknown-linux-gnu
58690f9b18fc: Pull complete 
b51569e7c507: Pull complete 
da8ef40b9eca: Pull complete 
fb15d46c38dc: Pull complete 
9d5962c83f5f: Pull complete 
9cccf86b8f43: Pull complete 
4c6d73517e75: Pull complete 
4afe128e6862: Pull complete 
2765f54cfdee: Pull complete 
40c841a9d0e8: Pull complete 
70c492706cd4: Pull complete 
b376264cc3c9: Pull complete 
f94a42110e99: Pull complete 
29835156cc05: Pull complete 
d48b139772fe: Pull complete 
55ba4d0a0c25: Pull complete 
5f4fa2c62d4d: Pull complete 
6bc43a1e4611: Pull complete 
Digest: sha256:7f8308a8734d9fcd2ebbe9a3e4bdea74af293f0799d80c3cc341e340cda49a4c
Status: Downloaded newer image for ghcr.io/cross-rs/aarch64-unknown-linux-gnu:0.2.5
   Compiling bitflags v2.5.0
   Compiling libc v0.2.153
   Compiling soloud-sys v1.0.5
error: failed to run custom build command for `soloud-sys v1.0.5`

Caused by:
  process didn't exit successfully: `/target/debug/build/soloud-sys-dae2317822c9970c/build-script-main` (exit status: 1)
  --- stderr
  /target/debug/build/soloud-sys-dae2317822c9970c/build-script-main: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /target/debug/build/soloud-sys-dae2317822c9970c/build-script-main)
warning: build failed, waiting for other jobs to finish...
make: *** [build] Error 101

@MoAlyousef
Copy link
Owner

MoAlyousef commented Mar 23, 2024

In the miniaudio header, it searches for both libasound.so.2 and libasound.so, so it should be able to load /usr/lib/aarch64-linux-gnu/libasound.so.2.

Regarding the "version 'GLIBC_2.25'" error, this is a Rust toolchain error. Can you try a cargo clean first?
cross-rs/cross#724

@andrewdavidmackenzie
Copy link
Author

Brilliant! I got it working with gnu!
(just some ssh / X bullshit to work out...)
Thanks so much for the help!
Now I need to try some speach!

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

No branches or pull requests

2 participants