Do you like SoundTouch? Then please support SoundTouch development and maintaining by a donation!
Unrestricted Royalty-free license also available for commercial purposes, please contact us for more information!
Are you looking for professional audio application developer(s) to help in your project?
SoundTouch in Android
Compiling SoundTouch for Android
SoundTouch source code package contains "Android-lib" example project that compiles SoundTouch source codes into Android native library, and gives an example of JNI interface for invoking the native SoundTouch routines from an Android application written in Java.
Hint: As installing and configuring all the components for an Android SDK/NDK environment requires fair effort, it's good idea to create a dedicated Virtual Machine environment for the Android development environment installation. Having the Android developer environment setup in dedicated Virtual Machine allows keeping all these settings isolated from your other PC operations, and eases taking backup snapshots of your full development environment.
To compile the SoundTouch library source codes into an Android native library, open Cygwin/bash shell, go to directory "soundtouch/source/Android-lib/jni" and invoke the NDK compiler with following command:
This will build binaries for all the supported Android platforms (arm-v5, arm-v7, X86, MIPS etc) of SoundTouch library, plus the JNI wrapper interface as discussed below. The target binaries will be built into the "libs" subdirectory. As long as all these .so binary library versions are included in the APK Application delivery package, the targer Android device can choose the correct library version to use.
Notice that to allow Cygwin/bash to locate the NDK compile scripts, you need to define the location of the NDK installation defined in environment variable "NDK". That's easiest done by adding the NDK path definition at end of your ~/.bash_profile file, for instance as follows:
Enabling OpenMP parallel computing mode
SoundTouch supports OpenMP for parallel computing in multi-core environments, and these improvements can be enabled also in the Android build. See the SoundTouch main README.html file for generic notes about the OpenMP implementation.
To enable OpenMP mode in Android compilation, edit file Android.mk and enable the "-fopenmp" flag in LOCAL_CFLAGS and LOCAL_LDFLAGS variables. This is done by removing hash # from before the following lines in the Android.mk file, before compiling the library:
LOCAL_CFLAGS += -fopenmp LOCAL_LDFLAGS += -fopenmp
OpenMP COMPATIBILITY NOTE: Android NDK has a threading issue (at least until NDK v10) that causes the native library crash with fatal signal 11 if calling OpenMP-improved routines from a background thread. SoundTouch has a workaround for this issue in soundtouch-jni.cpp, and this workaround requires calling function SoundTouch.getVersionString() from the Android application's main thread at least once before calling other SoundTouch processing routines. See the SoundTouch Android example application and comments in the soundtouch-jni.cpp source code file for more details.
SoundTouch performance in Android
See external blog articles for more discussion about the SoundTouch OpenMP implementation and the SoundTouch performance benchmark tests in Android environment.
Calling SoundTouch native routines from Android application
The NDK tools build the SoundTouch c++ routines into a native binary library, while Android applications are written in Java language. To call the SoundTouch and other c/c++ routines from an Android java application code, you'll need to use Java Native Interface (JNI).
The SoundTouch source code package provides source code example how to use JNI to call native c++ routines from a Java class, and provides source codes also for a simple example Android application:
Feel free to examine and extend the provided cpp/java source code example file pair to implement and integrate the desired SoundTouch library capabilities into your own Android application.
Android floating-point performance considerations
The make process will build dedicated binaries for each supported Android CPU hardware platform type.
SoundTouch uses floating-point algorithms for ideal sound quality on all other platform than in the lowest-end ARMv5. That is because lowest-end Android devices are not guaranteed to have floating-point hardware in their CPUs, so that the ARMv5 compilation uses by default software-emulation for floating-point calculations to allow running the binary executables also in low-end devices without floating-point hardware.
As floating point software-emulation is however several tens of times slower than real hardware-level floating-point calculations, that would make running floating-point-intensive applications such as SoundTouch infeasible in these low-end devices. As workaround, the SoundTouch Android compilation builds the ARMv5 version using integer algorithm versions. The integer algorithm version compromises the sound quality but provides good performance also with low-end devices without hardware floating-point support in the CPU level.
When Android devices with more capable device is used, the device will automatically choose a proper library version for ideal sound quality.
Copyright © Olli Parviainen