Wiki
Clone wikilatent_variable / Cross-compile alsa-lib and alsa-utils to Android
Cross-Compile alsa-lib and alsa-utils to Android
Walkthrough
1) Download the git repoitory
git clone https://<username>@bitbucket.org/devnullians/latent_variable.git
2) Compile alsa-lib and test/latency
$ cd <YOUR_SYSTEM_PATH>/latent_variable/alsa/alsa-lib-1.1.0/ $ export PATH=<YOUR_SYSTEM_PATH>/latent_variable/alsa/toolchain/bin/:$PATH $ export CC=arm-linux-androideabi-gcc $ export CXX=arm-linux-androideabi-g++ $ export LD_LIBRARY_PATH=<YOUR_SYSTEM_PATH>/latent_variable/alsa/alsa-lib-1.1.0/src/.libs/ $ CC=arm-linux-androideabi-gcc CFLAGS=-fPIC LDFLAGS=-pie ./configure --host=arm-linux --enable-shared=yes --enable-static=no --disable-python $ make $ cd test/ $ make latency
3) Compile alsa-util (and aplay)
$ cd <YOUR_SYSTEM_PATH>/latent_variable/alsa/alsa-utils-1.1.0/ $ CC=arm-linux-androideabi-gcc CFLAGS=-fPIC LDFLAGS=-pie ./configure --host=arm-linux --prefix=/data --with-alsa-inc-prefix=<YOUR_SYSTEM_PATH>/latent_variable/alsa/alsa-lib-1.1.0/include --with-alsa-prefix=<YOUR_SYSTEM_PATH>/latent_variable/alsa/alsa-lib-1.1.0/src/.libs --disable-alsamixer --disable-xmlto --disable-nls --disable-bat $ make
4) Copy the relevant binaries to the phone (via griffin.ini.cmu.edu)
$ cd <YOUR_SYSTEM_PATH>/latent_variable/alsa/alsa-lib-1.1.0/ $ scp test/.libs/latency devnullian@griffin.ini.cmu.edu:workbench/sandbox $ scp src/.libs/libasound.so.2.0.0 devnullian@griffin.ini.cmu.edu:workbench/sandbox $ cd <YOUR_SYSTEM_PATH>/latent_variable/alsa/alsa-utils-1.1.0/ $ scp aplay/aplay devnullian@griffin.ini.cmu.edu:workbench/sandbox/
4.1) (while on griffin.ini.cmu.edu)
$ cd workbench $ adb push sandbox /sdcard/sandbox/ $ adb shell $ su root $ cp /sdcard/sandbox/ /data/ $ cd /data/ $ chmod 765 latency $ chmod 765 aplay $ chmod 765 libasound.so.2.0.0 $ ln -s libasound.so.2.0.0 libasound.so.2 $ mkdir share/alsa $ cp alsa.conf share/alsa
5) Run the applications (on the phone)
$ export LD_LIBRARY_PATH=/data $ ./latency -P "hw:0,0" -C "hw:0,0" -r 44100 -m 128 -M 128 -p -s 1 WARNING: linker: ./latency: unused DT entry: type 0x1d arg 0x505 WARNING: linker: ./latency: unused DT entry: type 0x6ffffffe arg 0xd3c WARNING: linker: ./latency: unused DT entry: type 0x6fffffff arg 0x1 Scheduler set to Round Robin with priority 99... Playback device is hw:0,0 Capture device is hw:0,0 Parameters are 44100Hz, S16_LE, 2 channels, non-blocking mode Poll mode: yes Loop limit is 44100 frames, minimum latency = 128, maximum latency = 128 Playback open error: Invalid argument
IMPORTANT: to get ./latency to work, make sure you don't have the 64 bit version of libasound2-plugins installed. You should only have libasound2-plugins:i386, which you can install using the following command:
$ apt-get purge libasound2-plugins $ apt-get install libasound2-plugins:i386
Just to be safe, add the path to the 32 bit ALSA libraries to the LD_LIBRARY_PATH:
$ export LD_LIBRARY_PATH=<PATH_TO_libasound_module_conf_pulse.so>
$ ./aplay -l WARNING: linker: ./aplay: unused DT entry: type 0x6ffffffe arg 0x1d20 WARNING: linker: ./aplay: unused DT entry: type 0x6fffffff arg 0x1 **** List of PLAYBACK Hardware Devices **** card 0: msm8226tapan930 [msm8226-tapan9302-snd-card], device 0: MultiMedia1 (*) [] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: msm8226tapan930 [msm8226-tapan9302-snd-card], device 1: MultiMedia2 (*) [] Subdevices: 1/1 Subdevice #0: subdevice #0 (...)
$ ./aplay -L WARNING: linker: ./aplay: unused DT entry: type 0x6ffffffe arg 0x1d20 WARNING: linker: ./aplay: unused DT entry: type 0x6fffffff arg 0x1 null Discard all samples (playback) or generate zero samples (capture)
What's next?
alsa-lib/test/latency still doesn't run successfully on the Moto G. A (work-in-progress) solution is presented in this page.
UPDATE 1 : 2015-11-30
As an alternative to manual cross-compilation, you can build an image of CyanogenMod which includes ALSA-like tools.
tinyalsa
Instead of a 'full-fledged' ALSA lib, Cyanogen uses a stripped-down version called tinyalsa. Besides providing a compact PCM API (similar to alsa-lib), it also provides a set of utilities: * tinyplay: eq. to aplay -D * tinycap: eq. to arecord -D * tinypcminfo: eq. to aplay -L
Enable tinyalsa utils in Cyanogen build
In the Cyanogen sources, the code for external libraries like tynialsa can be found in the external/ directory (relative to Cyanogen's main build folder, in our repo that would be cyanogenmod/android/system/). Each one of these folders has an Android.mk file, in which you can find statements like this:
include $(CLEAR_VARS) LOCAL_C_INCLUDES:= external/tinyalsa/include LOCAL_SRC_FILES:= tinyplay.c LOCAL_MODULE := tinyplay LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE)
Note how LOCAL_MODULE_TAGS is set to 'optional'. In order to make tinyaplay appear as a built-in application which can be run directly from the phone's CLI, you need to mark it for compilation and installation in /system/bin/. To do so, edit the file vendor/motorola/msm8226-common/msm8226-common-vendor.mk and add the desired tinyalsa LOCAL_MODULES (should this be done after running breakfast ?):
# Pick up overlay for features that depend on non-open-source files PRODUCT_PACKAGES += \ com.qualcomm.location \ com.qualcomm.services.location \ MotGeoFenceSvc \ TimeService \ qcrilmsgtunnel \ qcnvitems \ qcrilhook \ libHevcSwDecoder \ tinyplay \ tinypcminfo \ tinycap
Building Cyanogen and installing image on the Moto G
After this, just run the setup script again, and wait for the image to compile.
$ cd <YOUR_SYSTEM_PATH>/latent_variable/cyanogenmod/
$ setup -b
The image shall be available as a .zip file in cyanogenmod/android/system/out/target/product/peregrine/. Copy it to the Moto G's SD card:
$ cd <YOUR_SYSTEM_PATH>/latent_variable/cyanogenmod/android/system/out/target/product/peregrine/ $ export PATH=$PATH:~/Android/Sdk/platform-tools $ adb push cm-12.1-20151130-UNOFFICIAL-peregrine.zip /sdcard
TBC
Sources
- http://www.programering.com/a/MTN0UDMwATk.html
- http://stackoverflow.com/questions/15310934/cannot-compile-using-alsa
- http://developer.android.com/ndk/guides/standalone_toolchain.html
- http://www.armadeus.com/wiki/index.php?title=Android#Audio
- http://www.alsa-project.org/main/index.php/Download
- http://www.linuxquestions.org/questions/linux-software-2/default-sound-card-specification-in-alsa-conf-files-903046/
- http://www.sabi.co.uk/Notes/linuxSoundALSA.html#structConf
- http://www.alsa-project.org/main/index.php/Test_latency.c
- http://superuser.com/questions/53957/what-do-alsa-devices-like-hw0-0-mean-how-do-i-figure-out-which-to-use
Updated