Fine tuning of Android compilation

This commit is contained in:
oparviai 2012-12-28 19:55:23 +00:00
parent 4d8825ef6d
commit 7a0a940953
5 changed files with 51 additions and 50 deletions

View File

@ -16,39 +16,40 @@
<h1>SoundTouch in Android</h1> <h1>SoundTouch in Android</h1>
<hr> <hr>
<h2>Compiling SoundTouch for Android</h2> <h2>Compiling SoundTouch for Android</h2>
<p>SoundTouch source code package contains example project that compiles SoundTouch <p>SoundTouch source code package contains &quot;Android-lib&quot; example project that compiles SoundTouch
into Android native library, and gives an example JNI interface that can invoke source codes into Android native library, and gives an example of JNI interface
the native SoundTouch routines from an Android application.</p> for invoking
the native SoundTouch routines from an Android application written in Java.</p>
<p style="font-weight: 700">Software prerequisites:</p> <p style="font-weight: 700">Software prerequisites:</p>
<ul> <ul>
<li>Android SDK environment for developing your own Android application. For more <li>Android SDK environment for developing your own Android application. Visit the <a href="http://developer.android.com/index.html">Android developers' site</a>
information about the Android SDK and developing the applications please visit for more information about the Android SDK and developing Android applications.</li>
the <a href="http://developer.android.com/index.html">Android developers' site</a>.</li> <li>Android NDK compiler kit for compiling native library binaries. The Android NDK
<li>Android NDK compiler kit to create native library compilations. Follow this link is <a href="http://developer.android.com/tools/sdk/ndk/index.html">
to <a href="http://developer.android.com/tools/sdk/ndk/index.html"> available for download</a> at the Android developer tools site.</li>
download the Android NDK</a> from the Android developer tools site.</li> <li>In case you're working in Windows environment, install
<li>In case you're working in Windows environment, you'll need <a href="http://cygwin.com/install.html"> <a href="http://cygwin.com/install.html">
Cygwin</a> to invoke the Android NDK/SDK compile scripts.</li> Cygwin</a> to run the Android NDK/SDK compiler scripts</li>
<li>Latest SoundTouch source code package available at <a href="http://soundtouch.surina.net/sourcecode.html"> <li>Latest SoundTouch source code package available at <a href="http://soundtouch.surina.net/sourcecode.html">
soundtouch.surina.net</a>.</li> soundtouch.surina.net</a>.</li>
</ul> </ul>
<p><b>Hint: </b>As setting up all the components and settings for an Android SDK/NDK <p><b>Hint: </b>As installing and configuring all the components for an Android SDK/NDK
environment requires fair effort, I recommend creating a dedicated clean Virtual environment requires fair effort, it&#39;s good idea to create a dedicated Virtual
Machine environment and installing all the Android developer tools into there. Machine environment for the Android development environment installation.
Having the Android developer environment setup in dedicated Virtual Machine Having the Android developer environment setup in dedicated Virtual Machine
allows keeping all these settings isolated from your other PC operations, and allows keeping all these settings isolated from your other PC operations, and
eases creating full backup snapshots of your development environment.</p> eases taking backup snapshots of your full development environment.</p>
<p><b>Compiling</b></p> <p><b>Compiling</b></p>
<p> <p>
To compile the SoundTouch library source codes into an Android native library, To compile the SoundTouch library source codes into an Android native library,
open Cygwin/bash shell and go to directory <b>&quot;soundtouch/source/Android-lib/jni&quot;</b> and invoke the NDK open Cygwin/bash shell, go to directory <b>&quot;soundtouch/source/Android-lib/jni&quot;</b> and invoke the NDK
compiler as follows:</p> compiler with following command:</p>
<pre> $NDK/ndk-build</pre> <pre> $NDK/ndk-build</pre>
<p>This will build the ARMv5 and ARMv7 versions of SoundTouch library (including <p>This will build the ARMv5 and ARMv7 versions of SoundTouch library (including
also the example JNI also the example JNI
interface, see below) into &quot;libs&quot; folder.</p> interface, see below) into the &quot;libs&quot; subdirectory.</p>
<p>Notice that in order for Cygwin/bash to locate the NDK compile scripts, you'll <p>Notice that to allow Cygwin/bash to locate the NDK compile scripts, you
need to have the location of the NDK installation defined in environment need to define the location of the NDK installation defined in environment
variable &quot;NDK&quot;. That's easiest done by adding the NDK path definition at end of variable &quot;NDK&quot;. That's easiest done by adding the NDK path definition at end of
your <b>~/.bash_profile</b> file, for instance as follows:</p> your <b>~/.bash_profile</b> file, for instance as follows:</p>
<pre> NDK=/cygdrive/d/Android/android-ndk-r6</pre> <pre> NDK=/cygdrive/d/Android/android-ndk-r6</pre>
@ -56,63 +57,62 @@
<h2> <h2>
Android floating-point performance considerations</h2> Android floating-point performance considerations</h2>
<p> <p>
Android NDK builds default compilation for ARMv5 CPU generation that works in Default build target for
Android NDK is ARMv5 CPU generation, as that works in
all ARM-based Android devices.<p> all ARM-based Android devices.<p>
This has a pitfall though: For ideal sound quality SoundTouch should be compiled This has a pitfall though: For ideal sound quality SoundTouch should be compiled
to use floating-point algorithms, however, some low-end Android devices do not to use floating-point algorithms, however, all low-end Android devices do not
have floating-point hardware in their CPU, and hence the default ARMv5 compilation uses software-emulation for floating-point calculations instead of have floating-point hardware in their CPUs, and hence the default ARMv5 compilation uses software-emulation for floating-point calculations instead of
hardware floating-point instructions to support also these low-end devices.<p> hardware floating-point to allow running the binary executables also in low-end devices.<p>
The floating point software-emulation is however several tens of times slower The floating point software-emulation is however several tens of times slower
than real hardware-level floating-point calculations, making than real hardware-level floating-point calculations, making
floating-point-intensive applications such as SoundTouch infeasible for low-end floating-point-intensive applications such as SoundTouch infeasible with low-end
devices.<p> devices.<p>
As workaround, the SoundTouch Android compilation builds two separate versions As workaround, the SoundTouch Android compilation builds two separate versions
of the library:<ul> of the library:<ul>
<li>ARMv5 version that compiles SoundTouch using integer algorithms. The integer <li>ARMv5 version that compiles SoundTouch using integer algorithm version. The integer
algorithm version compromises the sound quality but provides good performance also algorithm version compromises the sound quality but provides good performance also
with low-end with low-end
devices whose CPUs do not have hardware floating-point support</li> devices without hardware floating-point support in the CPU level.</li>
<li>ARMv7 version that compiles SoundTouch using hardware floating-point algorithms. <li>ARMv7 version that compiles SoundTouch using hardware floating-point algorithms.
These algorithms provide ideal sound quality yet do not work in simpler CPU These algorithms provide ideal sound quality yet do not work in simpler CPU
versions.</li> models.</li>
</ul> </ul>
<p> <p>
These two library compilations are defined in file &quot;<b>jni/Application.mk</b>&quot; These two library compilations are already defined in file &quot;<b>jni/Application.mk</b>&quot;
and results in automatically building two separate library targets under the &quot;<b>libs</b>&quot; so that these two separate library targets are automatically built under the &quot;<b>libs</b>&quot;
directory. As far as you include both these compiled library versions into your directory. As far as you include both these compiled library versions into your
application delivery, the Android environment can automatically select the right application delivery, the Android devices can automatically select the right
library version based on the customer device capabilities.<p> library version based on the available device&#39;s capabilities.<p>
Please yet be aware that depending on capabilities of the Android devices you Please yet be aware that depending on capabilities of the Android devices you
will need to provide the SoundTouch routines with samples in either integer or will need to provide the SoundTouch routines with samples in either integer or
floating-point format, so build your interface routines to take this into floating-point format, so build your interface routines to take this into
account.<hr /> account.<hr />
<h2> <h2>
Calling SoundTouch native routines from Android application</h2> Calling SoundTouch native routines from Android application</h2>
<p>The NDK tools build SoundTouch c++ routines into a native binary library, while <p>The NDK tools build the SoundTouch c++ routines into a native binary library, while
Android applications are written in Java language. To call SoundTouch and other c/c++ 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 routines from an Android java application code, you'll need to use Java Native
Interface (JNI).</p> Interface (JNI).</p>
<p> <p>
The SoundTouch source code package provides an example how to The SoundTouch source code package provides source code example how to
use JNI to call native c++ routines from a Java class through the following use JNI to call native c++ routines from a Java class through the following
source code file pair:<ul> source code file pair:<ul>
<li><b>Android-lib/jni/soundtouch-jni.cpp</b>: This file contains c/c++ routine that <li><b>Android-lib/jni/soundtouch-jni.cpp</b>: This file contains c/c++ routine that
uses SoundTouch library routines to return the library version string to the main calls SoundTouch library routine to return the library version string to the main
Android application. The NDK compiles this file along with the SoundTouch Android application. The NDK compiles this file along with the SoundTouch
routines into the native library.</li> routines into the native binary library.</li>
<li><b>Android-lib/src/net/surina/soundtouch/SoundTouch.java</b>: This file provides <li><b>Android-lib/src/net/surina/soundtouch/SoundTouch.java</b>: This file provides
a Java interface class to invoke the native routine implemented in file <b>soundtouch-jni.cpp</b> a Java interface class to load the native library and to invoke the native routine implemented in
for reading the SoundTouch library version string from the Android Java the file <b>soundtouch-jni.cpp</b></li>
application code.
</li>
</ul> </ul>
<p> <p>
Feel free to examine and extend the provided cpp/java source code example file pair to Feel free to examine and extend the provided cpp/java source code example file pair to
implement and integrate the desired SoundTouch library behavior into your Android application.</p> implement and integrate the desired SoundTouch library capabilities into your Android application.</p>
<hr /> <hr />
<p style="text-align: center"><i>Copyright &copy; Olli Parviainen</i></p> <p style="text-align: center"><i>Copyright &copy; Olli Parviainen</i></p>
<!-- <!--
$Id: README.html 160 2012-11-08 18:53:01Z oparviai $ $Id$
--> -->
</body> </body>
</html> </html>

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# $Id: Android.mk 327 2012-03-25 18:26:07Z olli $ # $Id$
LOCAL_PATH := $(call my-dir) LOCAL_PATH := $(call my-dir)
@ -21,9 +21,10 @@ include $(CLEAR_VARS)
# *** Remember: Change -O0 into -O2 in add-applications.mk *** # *** Remember: Change -O0 into -O2 in add-applications.mk ***
LOCAL_MODULE := soundtouch LOCAL_MODULE := soundtouch
LOCAL_SRC_FILES := soundtouch-jni.cpp ../../SoundTouch/AAFilter.cpp \ LOCAL_SRC_FILES := soundtouch-jni.cpp ../../SoundTouch/AAFilter.cpp ../../SoundTouch/FIFOSampleBuffer.cpp \
../../SoundTouch/FIFOSampleBuffer.cpp ../../SoundTouch/FIRFilter.cpp ../../SoundTouch/cpu_detect_x86.cpp \ ../../SoundTouch/FIRFilter.cpp ../../SoundTouch/cpu_detect_x86.cpp \
../../SoundTouch/RateTransposer.cpp ../../SoundTouch/SoundTouch.cpp ../../SoundTouch/TDStretch.cpp ../../SoundTouch/RateTransposer.cpp ../../SoundTouch/SoundTouch.cpp \
../../SoundTouch/TDStretch.cpp ../../SoundTouch/BPMDetect.cpp ../../SoundTouch/PeakFinder.cpp
# for native audio # for native audio
LOCAL_LDLIBS += -lgcc LOCAL_LDLIBS += -lgcc

View File

@ -1,4 +1,4 @@
# $Id: Application.mk 222 2011-12-13 21:07:38Z olli $ # $Id$
# #
# Build both ARMv5TE and ARMv7-A machine code. # Build both ARMv5TE and ARMv7-A machine code.
# #

View File

@ -8,7 +8,7 @@
/// ///
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// $Id: jni-routines.cpp 222 2011-12-13 21:07:38Z olli $ // $Id$
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -9,7 +9,7 @@
/// ///
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// $Id: jni-routines.cpp 222 2011-12-13 21:07:38Z olli $ // $Id$
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////