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

Building libao using Android standalone toolchain #7

Open
lm8 opened this issue Jan 31, 2018 · 10 comments
Open

Building libao using Android standalone toolchain #7

lm8 opened this issue Jan 31, 2018 · 10 comments

Comments

@lm8
Copy link

lm8 commented Jan 31, 2018

Was experimenting to see if libao would build for Android using the standalone toolchain. I hit an issue with it not being able to find the soundcard.h include.

In configure.ac where the following appear:
AC_CHECK_HEADERS(sys/soundcard.h, have_oss=yes)
AC_CHECK_HEADERS(machine/soundcard.h, have_oss=yes)
I ended up adding this after it:
AC_CHECK_HEADERS(linux/soundcard.h, have_oss=yes)

I then patched ao_oss.c to use the HAVE_LINUX_SOUNDCARD_H define that the above check created:
diff -Naurp src/libao-1.2.0/src/plugins/oss/ao_oss.c tmp/libao-1.2.0/src/plugins/oss/ao_oss.c
--- src/libao-1.2.0/src/plugins/oss/ao_oss.c 2014-01-27 12:02:05 -0500
+++ tmp/libao-1.2.0/src/plugins/oss/ao_oss.c
@@ -34,11 +34,15 @@
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
+#ifdef HAVE_LINUX_SOUNDCARD_H
+#include <linux/soundcard.h>
+#else
#if defined(OpenBSD) || defined(NetBSD)
#include <soundcard.h>
#else
#include <sys/soundcard.h>
#endif
+#endif
#include <sys/ioctl.h>

#include "ao/ao.h"

After those changes, I was able to get libao to build with some sound support. Thought I'd mention the patches I needed in case anyone else was interested or might need them in the future.

Thank you.

@nwrkbiz
Copy link

nwrkbiz commented Dec 29, 2018

Can you please post the full log, i guess this error occours due to a missing dependency for the platform you want to compile this library for. If you want to do cross compilation you need the dependencies (i.e. "alsa for android") on your host system.

I do not know if shared a library like that exists for android. If you do not need live output disable the plugin that is causing problems by passing "--disable-" to the configure script.

@circinusX1
Copy link

circinusX1 commented Oct 29, 2020

Hi am trying to configure it for android I cannot pass the error. (fails sanity check)

checking how to run the C preprocessor... /sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang++
configure: error: in `/sdaone/GIT_HUB/tcp_player/cli/android/libao-1.2.0':
configure: error: C preprocessor "/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/
x86_64-linux-android2#-clang++" fails sanity check
See `config.log' for more details
# linux-android2#-clang++  the # was 21 22 23...28 same error

The script

# omitted for clarity
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
#export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export CPP=$TOOLCHAIN/bin/$TARGET$API-clang++
#export CPP="$CC ${ANDROID_CFLAGS} -E"
# omitted for clarity
./configure --target=${TARGET} --host=${TARGET} --prefix=${SYSROOT}

where

CC=/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang
CPP=/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang++
CXX=
which clang: /sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
which clang++: /sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
TARGET=x86_64-linux-android
SYSROOT=/sdaone/BOARDS/android/android-ndk-r19c/sysroot/
TOOLCHAIN=/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64
PATH=/sdaone/BOARDS/android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin:/home/marius/usr/bin:/home/marius/bin:/home/marius/.local/bin:/opt/SEGGER/JLink/:/usr/local/gcc-arm-none-eabi-4_9-2015q3/bin:/home/marius/bin/node-v12.14.0-linux-x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin/flutter:/usr/bin/dart:/home/marius/APPS/cling_2020-04-02_ubuntu18/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/dart/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/dart/bin
API=21

Thank you

@circinusX1
Copy link

I Passed that error taking out from config the sanity check, but now on Android 9 I get

ao_default_driver_id() returning -1.

@nwrkbiz
Copy link

nwrkbiz commented Oct 30, 2020

What driver plugins do you build? (most probably alsa?) You will need the driver plugin on your android device (which might not be trivial).

You can try to statically link the alsa plugin as described here: #10

@circinusX1
Copy link

circinusX1 commented Oct 30, 2020

Hi, Thank you. I figure that out. Now returns the index for oss driver whichever is 4 or 5 after default static are in the driver table, and goes fine in the oss functions table, but open on /dev/snd/pcm* 0,# fails with access denied errno. I also tried the tinyalsa and is same issue from NDK. Looks like some Java Audio manager has to be called before, but I am in NDK pure C++. I am looking into that.

@nwrkbiz
Copy link

nwrkbiz commented Oct 31, 2020

Do you have a rooted phone? Did you try with su privileges? How did you link the plugins?

@circinusX1
Copy link

circinusX1 commented Oct 31, 2020

Hi, No is not rooted. Rooted will work for sure. I am using now OpenES , though I did not want that, because I wanted to keep same code for linux/android and works fine for what I needed. Is not critical is just a fun project I mess with in my spare time.
Thank you.

@nwrkbiz
Copy link

nwrkbiz commented Nov 6, 2020

Hi, No is not rooted. Rooted will work for sure. I am using now OpenES , though I did not want that, because I wanted to keep same code for linux/android and works fine for what I needed. Is not critical is just a fun project I mess with in my spare time.
Thank you.

I kind of got it to work on my android device using the example I attached to the other issue (#10). I built a completely statically linked binary using musl libc and alsa (wavplay.linux_aarch64_musl). The wav playback works only shortly after android itself performed a sound playback (i.e. beep after using the volume rocker). I guess some values need to be adjusted via amixer.

@nwrkbiz
Copy link

nwrkbiz commented Nov 7, 2020

@circinusX1

I did some further digging. Seems like I miss the right alsa UCM configuration files for the sound hardware of my smartphone (may be the same issue for you). If I use an external USB soundcard via OTG everything works out of the box.

@circinusX1
Copy link

circinusX1 commented Nov 7, 2020

@circinusX1

I did some further digging. Seems like I miss the right alsa UCM configuration files for the sound hardware of my smartphone (may be the same issue for you). If I use an external USB soundcard via OTG everything works out of the box.

Sounds interesting. I will try with the 2.0-sound card-usb. I'll have to solder a OTG, though I cannot find one in the cable box. Thank you. Ill play more definitely.

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

3 participants