Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Rubber Band JNI – Controlling Real-Time Audio Time-Stretching from Java

This repository contains an example of real-time pitch-shifting and audio time-stretching in Java. It uses two components. The first component is a high quality software C++ library for audio time-stretching and pitch-shifting C++ called Rubber Band. The second component is a Java audio library called TarsosDSP. To bridge the gap between the two JNI is used. Rubber Band provides a JNI interface and starting from the currently unreleased version 1.8.2, makefiles are provided that make compiling and subsequently using the JNI version of Rubber Band relatively straightforward.

Running the example

For recent 64 bits Linux machines and Mac OS X this library provides compiled JNI libraries. To run the example you need to build it, with “Apache Ant” and set the correct java.library.path when running the executable jar. This could be done as follows:

git clone
cd RubberbandJNI/build
cd ..
java -Djava.library.path=lib/ -jar build/RubberBandJNI.jar


If this does not work, you perhaps need to compile a JNI library yourself. Below documentation is available to get it working on a Linux machine and Mac OS X.

Compiling the Rubber Band JNI library on Debian Linux

To get the example working several elements need to be in place. 1) To compile Rubber Band a C++ tool-chain needs to be available on your system. This includes a compiler and related tools like make. 2) The dependencies for Rubber Band should be installed, otherwise compilation is impossible. 3) A JDK should be installed to compile java files and to provide the JNI header files. Here we assume that a JDK and C++ tool-chain is already available. The rest is explained for Debian 8.1 but should be transferable to any Unix like system.

To install the dependencies on Debian, install following packages:

sudo apt-get install vamp-plugin-sdk libsndfile1-dev libfftw3-dev libvamp-sdk2 libvamp-hostsdk3 libsamplerate0-dev

Once the dependencies are installed correctly the following should work:

# Download and unzip and the latest source code
# Change the working directory
cd breakfastquay-rubberband-46805fcedf7e
# If the dependencies are installed correctly the following will work
# Compile the source code
# Create the JNI library, set JAVA_HOME to your JDK directory
make jni JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
# Copy the newly created JAR-file and native library to the lib directory
cp lib/rubberband.jar ../lib/
cp lib/ ../lib/
# change the working directory
cd ../build
# Build the RubberBandJNI jar file with Apache Ant
cd ..

If everything went well there are a few new files on your system. lib/rubberband.jar contains the Java part of the JNI-bridge. lib/ contains Rubber Band C++ JNI bridge compiled for your system. build/RubberBandJNI.jar contains the example application of this repository. If those files are created correctly, you are ready to run RubberBandJNI. The application needs to be started with a correct java.library.path:

java -Djava.library.path=lib/ -jar build/RubberBandJNI.jar

Watch out: the order of the options does matter: the -D option should appear before -jar. Finally, to clean up remove the previously downloaded source code.

rm -r breakfastquay-rubberband-46805fcedf7e
#rm lib/rubberband.jar
#rm lib/

Compiling the Rubber Band JNI library on Mac OS X

To install the dependencies on Mac OS X the homebrew package manager is very helpful:

brew install
brew install fftw
brew install libsamplerate
brew install libsndfile
brew install wget

To get the makefile working on Mac OS X some changes need to be done. The first change is to correctly name the library with a .dylib instead of an .so:

DYNAMIC_EXTENSION       := .dylib
DYNAMIC_LDFLAGS         := -shared
VAMP_LDFLAGS            := -shared
LADSPA_LDFLAGS          := -shared

Finally compile the library by calling make. It can complain about missing Then call:

make jni JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

If you get complaints about a missing jni_md.h link the header files, as described here.

Compiling the Rubber Band JNI library on Debian for Android

Install the Android Native Development kit, the NDK, and make sure that ndk-build
is available on your path.

# Download and unzip and the latest source code
# Change the working directory
cd breakfastquay-rubberband-46805fcedf7e
mkdir jni
mkdir libs

# Configure the application to use stl
echo "APP_STL := gnustl_static" > jni/
# Copy the build file to the expected location. 
cp jni

Then change jni/ so that the correct directories are used. For me, the beginning of the file looks like this:

LOCAL_MODULE := rubberband
LOCAL_MODULE_FILENAME := librubberband-jni
LOCAL_PATH := /home/joren/breakfastquay-rubberband-46805fcedf7e
LOCAL_C_INCLUDES := $(LOCAL_PATH)/rubberband $(LOCAL_PATH)/rubberband/src
RUBBERBAND_PATH := /home/joren/breakfastquay-rubberband-46805fcedf7e

Now you are ready to call ndk-build in the top directory and it should build a library in libs/armeabi/

[armeabi-v7a] Compile++ arm  : rubberband <= SilentAudioCurve.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= CompoundAudioCurve.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= HighFrequencyAudioCurve.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= SpectralDifferenceAudioCurve.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= ConstantAudioCurve.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= PercussiveAudioCurve.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= StretcherImpl.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= StretcherProcess.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= StretchCalculator.cpp
[armeabi-v7a] Compile++ arm  : rubberband <= RubberBandStretcher.cpp
[armeabi-v7a] Compile arm    : rubberband <= resample.c
[armeabi-v7a] Compile arm    : rubberband <= kiss_fft.c
[armeabi-v7a] Compile arm    : rubberband <= kiss_fftr.c
[armeabi-v7a] SharedLibrary  :
[armeabi-v7a] Install        : => libs/armeabi/

In Android Studio this library can be put in the following folder. It can then be called from Java automatically.

|--|--|--|--|--| Files
|--|--|--|--|--| Files

Compiling the Rubber Band JNI library on Windows for Window x86 and x64

Download the free Visual Studio Community 2015 and install it. Make sure that the C/C++ components are installed. Subsequently download the latest RubberBand source code and place the file that is found in build/ of this repository in the top directory of the downloaded Rubberband source tree. Doubleclick it to start Visual Studio Community.

To make it build successfully make sure that you also have a recent Java JDK on installed your machine. When building the project the following directories need to be set as additional include directories:

C:\Program Files (x86)\Java\jdk1.8.0_60\include;
C:\Program Files (x86)\Java\jdk1.8.0_60\include\win32

If all goes wel a build should create a dll named rubberband-library.dll to work correctly with this project it should be renamed rubberband-jni.dll.


Example application that shows how to control the real-time audio time-stretching library Rubber Band from Java







No releases published


No packages published