diff --git a/source/Android-lib/README-SoundTouch-Android.html b/source/Android-lib/README-SoundTouch-Android.html new file mode 100644 index 0000000..7beaa7d --- /dev/null +++ b/source/Android-lib/README-SoundTouch-Android.html @@ -0,0 +1,118 @@ + + + + SoundTouch in Android + + + + + + + +
+

SoundTouch in Android

+
+

Compiling SoundTouch for Android

+

SoundTouch source code package contains example project that compiles SoundTouch + into Android native library, and gives an example JNI interface that can invoke + the native SoundTouch routines from an Android application.

+

Software prerequisites:

+ +

Hint: As setting up all the components and settings for an Android SDK/NDK + environment requires fair effort, I recommend creating a dedicated clean Virtual + Machine environment and installing all the Android developer tools into there. + Having the Android developer environment setup in dedicated Virtual Machine + allows keeping all these settings isolated from your other PC operations, and + eases creating full backup snapshots of your development environment.

+

Compiling

+

+ To compile the SoundTouch library source codes into an Android native library, + open Cygwin/bash shell and go to directory "soundtouch/source/Android-lib/jni" and invoke the NDK + compiler as follows:

+
    $NDK/ndk-build
+

This will build the ARMv5 and ARMv7 versions of SoundTouch library (including + also the example JNI + interface, see below) into "libs" folder.

+

Notice that in order for Cygwin/bash to locate the NDK compile scripts, you'll + need to have 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:

+
    NDK=/cygdrive/d/Android/android-ndk-r6
+
+

+ Android floating-point performance considerations

+

+ Android NDK builds default compilation for ARMv5 CPU generation that works in + all ARM-based Android devices.

+ 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 + have floating-point hardware in their CPU, 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.

+ The floating point software-emulation is however several tens of times slower + than real hardware-level floating-point calculations, making + floating-point-intensive applications such as SoundTouch infeasible for low-end + devices.

+ As workaround, the SoundTouch Android compilation builds two separate versions + of the library:

+

+ These two library compilations are defined in file "jni/Application.mk" + and results in automatically building two separate library targets under the "libs" + directory. As far as you include both these compiled library versions into your + application delivery, the Android environment can automatically select the right + library version based on the customer device capabilities.

+ 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 + floating-point format, so build your interface routines to take this into + account.


+

+ Calling SoundTouch native routines from Android application

+

The NDK tools build SoundTouch c++ routines into a native binary library, while + Android applications are written in Java language. To call 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 an example how to + use JNI to call native c++ routines from a Java class through the following + source code file pair:

+

+ 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.

+
+

Copyright © Olli Parviainen

+ + + \ No newline at end of file diff --git a/source/Android-lib/jni/Android.mk b/source/Android-lib/jni/Android.mk new file mode 100644 index 0000000..0c6fd87 --- /dev/null +++ b/source/Android-lib/jni/Android.mk @@ -0,0 +1,39 @@ +# Copyright (C) 2010 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# $Id: Android.mk 327 2012-03-25 18:26:07Z olli $ + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +# *** Remember: Change -O0 into -O2 in add-applications.mk *** + +LOCAL_MODULE := soundtouch +LOCAL_SRC_FILES := soundtouch-jni.cpp ../../SoundTouch/AAFilter.cpp \ + ../../SoundTouch/FIFOSampleBuffer.cpp ../../SoundTouch/FIRFilter.cpp ../../SoundTouch/cpu_detect_x86.cpp \ + ../../SoundTouch/RateTransposer.cpp ../../SoundTouch/SoundTouch.cpp ../../SoundTouch/TDStretch.cpp + +# for native audio +LOCAL_LDLIBS += -lgcc +# --whole-archive -lgcc +# for logging +LOCAL_LDLIBS += -llog +# for native asset manager +#LOCAL_LDLIBS += -landroid +# don't export all symbols +# added "-marm" switch to use arm instruction set instead of thumb for improved calculation performance. +LOCAL_CFLAGS += -Wall -fvisibility=hidden -I ../../../include -D ST_NO_EXCEPTION_HANDLING -fdata-sections -ffunction-sections -marm + +include $(BUILD_SHARED_LIBRARY) diff --git a/source/Android-lib/jni/Application.mk b/source/Android-lib/jni/Application.mk new file mode 100644 index 0000000..5f75683 --- /dev/null +++ b/source/Android-lib/jni/Application.mk @@ -0,0 +1,7 @@ +# $Id: Application.mk 222 2011-12-13 21:07:38Z olli $ +# +# Build both ARMv5TE and ARMv7-A machine code. +# + +APP_ABI := armeabi-v7a armeabi +APP_OPTIM := release diff --git a/source/Android-lib/jni/soundtouch-jni.cpp b/source/Android-lib/jni/soundtouch-jni.cpp new file mode 100644 index 0000000..7cb5509 --- /dev/null +++ b/source/Android-lib/jni/soundtouch-jni.cpp @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////////////// +/// +/// Example Interface class for SoundTouch native compilation +/// +/// Author : Copyright (c) Olli Parviainen +/// Author e-mail : oparviai 'at' iki.fi +/// WWW : http://www.surina.net +/// +//////////////////////////////////////////////////////////////////////////////// +// +// $Id: jni-routines.cpp 222 2011-12-13 21:07:38Z olli $ +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +//#include +//#include +//#include + +#include "../../../include/SoundTouch.h" +//#include "TimeShiftEffect.h" + +#define LOGV(...) __android_log_print((int)ANDROID_LOG_INFO, "SOUNDTOUCH", __VA_ARGS__) +//#define LOGV(...) + + +#define DLL_PUBLIC __attribute__ ((visibility ("default"))) + +using namespace soundtouch; + +extern "C" DLL_PUBLIC jstring Java_net_surina_soundtouch_getVersionString(JNIEnv *env, jobject thiz) +{ + const char *verStr; + + LOGV("JNI call soundtouch.getVersionString"); + + // Call example SoundTouch routine + verStr = SoundTouch::getVersionString(); + + // return version as string + return env->NewStringUTF(verStr); +} diff --git a/source/Android-lib/src/net/surina/soundtouch/SoundTouch.java b/source/Android-lib/src/net/surina/soundtouch/SoundTouch.java new file mode 100644 index 0000000..19c8aec --- /dev/null +++ b/source/Android-lib/src/net/surina/soundtouch/SoundTouch.java @@ -0,0 +1,29 @@ +//////////////////////////////////////////////////////////////////////////////// +/// +/// Example class that invokes native SoundTouch routines through the JNI +/// interface. +/// +/// Author : Copyright (c) Olli Parviainen +/// Author e-mail : oparviai 'at' iki.fi +/// WWW : http://www.surina.net +/// +//////////////////////////////////////////////////////////////////////////////// +// +// $Id: jni-routines.cpp 222 2011-12-13 21:07:38Z olli $ +// +//////////////////////////////////////////////////////////////////////////////// + +package net.surina.soundtouch; + +public final class SoundTouch +{ + // Native interface function that returns SoundTouch version string. + // This invokes the native c++ routine defined in "soundtouch-jni.cpp". + public native final String getVersionString(); + + // Load the native library upon startup + static + { + System.loadLibrary("soundtouch"); + } +}