33d820f81e93 — Chris Cannam 7 years ago
Import initial code for MiniBpm example project
A => .hgignore +5 -0
@@ 0,0 1,5 @@ 
+syntax: glob
+re:^obj/local/armeabi-v7a/
+re:^obj/local/armeabi/
+*.so
+*.~1~

          
A => .hgsub +1 -0
@@ 0,0 1,1 @@ 
+jni/minibpm = ssh://hg@bitbucket.org/breakfastquay/minibpm

          
A => .hgsubstate +1 -0
@@ 0,0 1,1 @@ 
+cd38a0308ee0abbc74e025a7b30959ba6c2132b6 jni/minibpm

          
A => AndroidManifest.xml +15 -0
@@ 0,0 1,15 @@ 
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="com.breakfastquay.minibpmexample"
+      android:versionCode="1"
+      android:versionName="1.0">
+    <application android:label="@string/app_name" android:debuggable="true">
+        <activity android:name="MiniBpmExampleActivity"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+</manifest> 

          
A => README +24 -0
@@ 0,0 1,24 @@ 
+
+MiniBPM Android Simple Sample
+=============================
+
+This is a very trivial example Android application that uses the
+MiniBPM tempo estimator.
+
+This project serves as an example of how to link to, and call to,
+MiniBPM from Java code in an Android application.
+
+It is *not* an example of how to write an Android application! The
+Android-specific Java code here is absolutely not something that you
+should refer to in your own work. This is simply an illustration of
+the use of the JNI (Android NDK) interface.
+
+To build:
+
+   $ ndk-build
+   $ ant debug
+   $ ant debug install
+
+The example code is public domain; the MiniBPM licence is documented
+separately (see http://www.breakfastquay.com/minibpm/).
+

          
A => ant.properties +17 -0
@@ 0,0 1,17 @@ 
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in Version Control Systems, as it is
+# integral to the build system of your project.
+
+# This file is only used by the Ant script.
+
+# You can use this to override default values such as
+#  'source.dir' for the location of your java source folder and
+#  'out.dir' for the location of your output folder.
+
+# You can also use it define how the release builds are signed by declaring
+# the following properties:
+#  'key.store' for the location of your keystore and
+#  'key.alias' for the name of the key to use.
+# The password will be asked during the build when you use the 'release' target.
+

          
A => build.xml +85 -0
@@ 0,0 1,85 @@ 
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="MiniBpmExample" default="help">
+
+    <!-- The local.properties file is created and updated by the 'android' tool.
+         It contains the path to the SDK. It should *NOT* be checked into
+         Version Control Systems. -->
+    <loadproperties srcFile="local.properties" />
+
+    <!-- The ant.properties file can be created by you. It is only edited by the
+         'android' tool to add properties to it.
+         This is the place to change some Ant specific build properties.
+         Here are some properties you may want to change/update:
+
+         source.dir
+             The name of the source directory. Default is 'src'.
+         out.dir
+             The name of the output directory. Default is 'bin'.
+
+         For other overridable properties, look at the beginning of the rules
+         files in the SDK, at tools/ant/build.xml
+
+         Properties related to the SDK location or the project target should
+         be updated using the 'android' tool with the 'update' action.
+
+         This file is an integral part of the build system for your
+         application and should be checked into Version Control Systems.
+
+         -->
+    <property file="ant.properties" />
+
+    <!-- The project.properties file is created and updated by the 'android'
+         tool, as well as ADT.
+
+         This contains project specific properties such as project target, and library
+         dependencies. Lower level build properties are stored in ant.properties
+         (or in .classpath for Eclipse projects).
+
+         This file is an integral part of the build system for your
+         application and should be checked into Version Control Systems. -->
+    <loadproperties srcFile="project.properties" />
+
+    <!-- quick check on sdk.dir -->
+    <fail
+            message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
+            unless="sdk.dir"
+    />
+
+
+<!-- extension targets. Uncomment the ones where you want to do custom work
+     in between standard targets -->
+<!--
+    <target name="-pre-build">
+    </target>
+    <target name="-pre-compile">
+    </target>
+
+    /* This is typically used for code obfuscation.
+       Compiled code location: ${out.classes.absolute.dir}
+       If this is not done in place, override ${out.dex.input.absolute.dir} */
+    <target name="-post-compile">
+    </target>
+-->
+
+    <!-- Import the actual build file.
+
+         To customize existing targets, there are two options:
+         - Customize only one target:
+             - copy/paste the target into this file, *before* the
+               <import> task.
+             - customize it to your needs.
+         - Customize the whole content of build.xml
+             - copy/paste the content of the rules files (minus the top node)
+               into this file, replacing the <import> task.
+             - customize to your needs.
+
+         ***********************
+         ****** IMPORTANT ******
+         ***********************
+         In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
+         in order to avoid having your file be overridden by tools such as "android update project"
+    -->
+    <!-- version-tag: 1 -->
+    <import file="${sdk.dir}/tools/ant/build.xml" />
+
+</project>

          
A => jni/Android.mk +7 -0
@@ 0,0 1,7 @@ 
+
+LOCAL_PATH := $(call my-dir)
+
+include $(LOCAL_PATH)/minibpm/Android.mk
+
+$(call import-module,android/cpufeatures)
+

          
A => jni/Application.mk +4 -0
@@ 0,0 1,4 @@ 
+APP_STL := stlport_static
+APP_ABI := armeabi-v7a
+
+APP_OPTIM := release

          
A => local.properties +10 -0
@@ 0,0 1,10 @@ 
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must *NOT* be checked in Version Control Systems,
+# as it contains information specific to your local configuration.
+
+# location of the SDK. This is only used by Ant
+# For customization when using a Version Control System, please read the
+# header note.
+sdk.dir=/opt/android-sdk-linux

          
A => proguard.cfg +40 -0
@@ 0,0 1,40 @@ 
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+    native <methods>;
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+   public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+    public static **[] values();
+    public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+  public static final android.os.Parcelable$Creator *;
+}

          
A => project.properties +11 -0
@@ 0,0 1,11 @@ 
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-8

          
A => res/layout/main.xml +16 -0
@@ 0,0 1,16 @@ 
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal">
+    <Button
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/button_play"
+	android:onClick="play"/>
+    <Button
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/button_stop"
+	android:onClick="stop"/>
+</LinearLayout>

          
A => res/values/strings.xml +6 -0
@@ 0,0 1,6 @@ 
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">MiniBpmExampleActivity</string>
+    <string name="button_play">Play</string>
+    <string name="button_stop">Stop</string>
+</resources>

          
A => src/com/breakfastquay/minibpm/MiniBpm.java +116 -0
@@ 0,0 1,116 @@ 
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    MiniBPM
+    A fixed-tempo BPM estimator for music audio
+    Copyright 2012-2014 Particular Programs Ltd.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+
+    Alternatively, if you have a valid commercial licence for MiniBPM
+    obtained by agreement with the copyright holders, you may
+    redistribute and/or modify it under the terms described in that
+    licence.
+
+    If you wish to distribute code using MiniBPM under terms other
+    than those of the GNU General Public License, you must obtain a
+    valid commercial licence before doing so.
+*/
+
+package com.breakfastquay.minibpm;
+
+/**
+ * A fixed-tempo BPM estimator. This Java wrapper currently provides
+ * only the single-shot API from the C++ library.
+ *
+ * A single channel of audio only may be supplied (multi-channel is
+ * not supported). To process multi-channel audio, average the
+ * channels first.
+ */
+public class MiniBpm
+{
+    public MiniBpm(int sampleRate) {
+	handle = 0;
+	initialise(sampleRate);
+    }
+
+    /**
+     * Call this to dispose of the tempo estimator after use. You must
+     * do so after you have finished using this estimator object, as
+     * the Java garbage collector cannot collect the native object.
+     */
+    public native void dispose();
+
+    /**
+     * Set the range of valid tempi. The default is 55-190bpm.
+     */
+    public native void setBPMRange(double min, double max);
+
+    /**
+     * Get the current minimum supported tempo.
+     */
+    public native double getBPMMin();
+
+    /**
+     * Get the current maximum supported tempo.
+     */
+    public native double getBPMMax();
+
+    /**
+     * Set the number of beats per bar, if known. If unknown, leave at
+     * the default (which is 4).
+     */
+    public native void setBeatsPerBar(int bpb);
+
+    /**
+     * Get the current number of beats per bar.
+     */
+    public native int getBeatsPerBar();
+
+    /**
+     * Return the estimated tempo in bpm of the music audio in the
+     * given sequence of samples. nsamples contains the number of
+     * samples, starting at the given offset in the given input
+     * array. If the tempo cannot be estimated because the clip is too
+     * short, return 0.
+     *
+     * The input samples are expected to be in the range [-1,1].
+     *
+     * If you wish to subsequently obtain a tempo estimate of a
+     * different clip, you must call reset() before calling this
+     * function again. (This is so that the data that is available to
+     * be returned from getTempoCandidates can be cleared.)
+     */
+    public native double estimateTempoOfSamples(float[] input,
+						int offset, int nsamples);
+
+    /**
+     * Return all candidate tempi for the last tempo estimation that
+     * was carried out, in order of likelihood (best first). The value
+     * returned from estimateTempoOfSamples will therefore be the
+     * first in the returned sequence. Calling reset() will clear this
+     * information.
+     */
+    public native double[] getTempoCandidates();
+
+    /**
+     * Prepare the object to carry out another tempo estimation on a
+     * new audio clip. You can either call this between uses, or
+     * simply destroy this object and construct a new one.
+     */
+    public native void reset();
+
+    private native void initialise(int sampleRate);
+    private long handle;
+
+    static {
+	System.loadLibrary("minibpm-jni");
+    }
+};
+
+
+    

          
A => src/com/breakfastquay/minibpmexample/MiniBpmExampleActivity.java +27 -0
@@ 0,0 1,27 @@ 
+package com.breakfastquay.minibpmexample;
+
+import android.app.Activity;
+import android.view.View;
+import android.widget.TextView;
+import android.os.Bundle;
+import android.content.res.Resources;
+import android.util.Log;
+import android.util.TimingLogger;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+import com.breakfastquay.minibpm.MiniBpm;
+
+public class MiniBpmExample extends Activity
+{
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState)
+    {
+        super.onCreate(savedInstanceState);
+
+	setContentView(R.layout.main);
+    }
+}