init
14
.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
116
.idea/codeStyles/Project.xml
generated
Normal file
@ -0,0 +1,116 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
19
.idea/gradle.xml
generated
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
9
.idea/misc.xml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
12
.idea/runConfigurations.xml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
34
app/build.gradle
Normal file
@ -0,0 +1,34 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.feemers.android.fftdrawer"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
}
|
21
app/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
@ -0,0 +1,27 @@
|
||||
package com.feemers.android.fftdrawer;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("com.feemers.android.fftdrawer", appContext.getPackageName());
|
||||
}
|
||||
}
|
21
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.feemers.android.fftdrawer">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,8 @@
|
||||
package com.feemers.android.fftdrawer;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
|
||||
public interface Animation {
|
||||
void Draw(Canvas canvas);
|
||||
void SetBackgroundColor(int c);
|
||||
}
|
28
app/src/main/java/com/feemers/android/fftdrawer/Bar.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.feemers.android.fftdrawer;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
public class Bar {
|
||||
private float value;
|
||||
private int harmonics;
|
||||
private float frequency;
|
||||
private final int color;
|
||||
|
||||
public Bar(float value, int harmonics) {
|
||||
this.value = value;
|
||||
this.harmonics = harmonics;
|
||||
color = Color.rgb(0,255,0);
|
||||
}
|
||||
|
||||
public float getValue(){
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getHarmonics() {
|
||||
return harmonics;
|
||||
}
|
||||
|
||||
public int getColor(){
|
||||
return color;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.feemers.android.fftdrawer;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BarChart implements Animation {
|
||||
|
||||
private final int length;
|
||||
private ArrayList<Bar> bars = null;
|
||||
|
||||
private Paint paint;
|
||||
private int backgroundColor;
|
||||
|
||||
public BarChart(int length){
|
||||
this.length = length;
|
||||
bars = new ArrayList<>();
|
||||
|
||||
paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
backgroundColor = Color.rgb(0,0,0);
|
||||
}
|
||||
|
||||
public void newValues(double[] values){
|
||||
bars.clear();
|
||||
for(int i = 0; i < length; i++){
|
||||
float tmp = (float) values[i];
|
||||
bars.add(new Bar(tmp, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(Canvas canvas) {
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
canvas.drawColor(backgroundColor);
|
||||
// find max
|
||||
float maxValue = 0;
|
||||
for(Bar b : bars){
|
||||
maxValue = maxValue >= b.getValue() ? maxValue : b.getValue();
|
||||
}
|
||||
for(Bar b : bars){
|
||||
paint.setColor(b.getColor());
|
||||
float width = canvas.getWidth();
|
||||
float heigth = canvas.getHeight();
|
||||
float widthOfBar = width / length;
|
||||
|
||||
float left= b.getHarmonics() * widthOfBar;
|
||||
float top = heigth - heigth * b.getValue() / maxValue;
|
||||
float rigth = (b.getHarmonics()+1) * widthOfBar;
|
||||
float buttom = heigth;
|
||||
|
||||
canvas.drawRect(left, top, rigth ,buttom, paint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetBackgroundColor(int c) {
|
||||
backgroundColor = c;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.feemers.android.fftdrawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
public class BarChartView extends SurfaceView implements Runnable {
|
||||
|
||||
private Animation animation;
|
||||
private SurfaceHolder surfaceHolder;
|
||||
private Thread thread = null;
|
||||
private volatile boolean running = false;
|
||||
private int backgroudColor = 0;
|
||||
private String name = "";
|
||||
private int sleepTime = 0;
|
||||
private volatile boolean update;
|
||||
|
||||
|
||||
public BarChartView(Context context) {
|
||||
super(context);
|
||||
surfaceHolder = getHolder();
|
||||
}
|
||||
public BarChartView(Context context, AttributeSet attributeSet){
|
||||
super(context, attributeSet);
|
||||
surfaceHolder = getHolder();
|
||||
ReadXML(attributeSet);
|
||||
}
|
||||
private void ReadXML(AttributeSet attributeSet){
|
||||
android.content.res.TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.BarChartView);
|
||||
//String s = typedArray.getString(R.styleable.GrafikView_android_text);
|
||||
//name = (s!=null) ? s : "";
|
||||
backgroudColor = typedArray.getColor(R.styleable.BarChartView_backgroundColor, Color.BLACK);
|
||||
typedArray.recycle();
|
||||
log(", hintergrundFarbe=" + backgroudColor);
|
||||
}
|
||||
|
||||
public void setAnimation(Animation animation){
|
||||
this.animation = animation;
|
||||
this.animation.SetBackgroundColor(backgroudColor);
|
||||
}
|
||||
|
||||
private void log(String s) {
|
||||
Log.d(this.getClass().getSimpleName(), s);
|
||||
}
|
||||
|
||||
public void Start(){
|
||||
running = true;
|
||||
thread = new Thread(this);
|
||||
thread.start();
|
||||
log("Thread started");
|
||||
}
|
||||
|
||||
public void Stop(){
|
||||
running = false;
|
||||
while(true){
|
||||
try{
|
||||
thread.join();
|
||||
log("Thread stopped");
|
||||
break;
|
||||
}catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Draw(){
|
||||
update = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (running) {
|
||||
if (update) {
|
||||
if (!surfaceHolder.getSurface().isValid()) {
|
||||
continue;
|
||||
}
|
||||
Canvas canvas = surfaceHolder.lockCanvas();
|
||||
if (animation != null) {
|
||||
animation.Draw(canvas);
|
||||
update = false;
|
||||
}
|
||||
surfaceHolder.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(5);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.feemers.android.fftdrawer;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import com.feemers.android.fftdrawer.SignalProcessing.DetectorTimedomain;
|
||||
import com.feemers.android.fftdrawer.SignalProcessing.Logger;
|
||||
import com.feemers.android.fftdrawer.SignalProcessing.SignalProcessingControl;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements Observer {
|
||||
private TextView textView1;
|
||||
private BarChartView grafikView1;
|
||||
private TextView textView2;
|
||||
private BarChartView grafikView2;
|
||||
private SignalProcessingControl signalProcessingControl;
|
||||
private DetectorTimedomain detectorTimedomain;
|
||||
private SensorManager sensorManager;
|
||||
private BarChart barChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
textView1 = findViewById(R.id.textView1);
|
||||
textView1.setText("Nr.1 ");
|
||||
textView2 = findViewById(R.id.textView2);
|
||||
textView2.setText("Nr. 2");
|
||||
|
||||
|
||||
double[] test = new double[64];
|
||||
for (int i = 0; i < 64; i++){
|
||||
test[i] = 0;
|
||||
}
|
||||
|
||||
barChart = new BarChart(64);
|
||||
barChart.newValues(test);
|
||||
|
||||
grafikView1 = findViewById(R.id.graficView1);
|
||||
grafikView1.setAnimation(barChart);
|
||||
grafikView2 = findViewById(R.id.graficView2);
|
||||
grafikView2.setAnimation(new BarChart(64));
|
||||
|
||||
Logger logger = new Logger(this.getClass().getSimpleName(), "");
|
||||
detectorTimedomain = new DetectorTimedomain(20);
|
||||
detectorTimedomain.setThreshold(12);
|
||||
|
||||
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
signalProcessingControl = new SignalProcessingControl(sensorManager, logger);
|
||||
signalProcessingControl.init();
|
||||
|
||||
signalProcessingControl.getNotifier().addObserver(this);
|
||||
signalProcessingControl.start();
|
||||
|
||||
|
||||
grafikView1.Start();
|
||||
grafikView2.Start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
double[] newData = signalProcessingControl.getNotifier().getData();
|
||||
barChart.newValues(newData);
|
||||
grafikView1.Draw();
|
||||
grafikView2.Draw();
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
/******************************************************************************
|
||||
* Compilation: javac Complex.java
|
||||
* Execution: java Complex
|
||||
*
|
||||
* Data type for complex numbers.
|
||||
*
|
||||
* The data type is "immutable" so once you create and initialize
|
||||
* a Complex object, you cannot change it. The "final" keyword
|
||||
* when declaring re and im enforces this rule, making it a
|
||||
* compile-time error to change the .re or .im instance variables after
|
||||
* they've been initialized.
|
||||
*
|
||||
* % java Complex
|
||||
* a = 5.0 + 6.0i
|
||||
* b = -3.0 + 4.0i
|
||||
* Re(a) = 5.0
|
||||
* Im(a) = 6.0
|
||||
* b + a = 2.0 + 10.0i
|
||||
* a - b = 8.0 + 2.0i
|
||||
* a * b = -39.0 + 2.0i
|
||||
* b * a = -39.0 + 2.0i
|
||||
* a / b = 0.36 - 1.52i
|
||||
* (a / b) * b = 5.0 + 6.0i
|
||||
* conj(a) = 5.0 - 6.0i
|
||||
* |a| = 7.810249675906654
|
||||
* tan(a) = -6.685231390246571E-6 + 1.0000103108981198i
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
public class Complex {
|
||||
private final double re; // the real part
|
||||
private final double im; // the imaginary part
|
||||
|
||||
// create a new object with the given real and imaginary parts
|
||||
public Complex(double real, double imag) {
|
||||
re = real;
|
||||
im = imag;
|
||||
}
|
||||
|
||||
// return a string representation of the invoking Complex object
|
||||
public String toString() {
|
||||
if (im == 0) return re + "";
|
||||
if (re == 0) return im + "i";
|
||||
if (im < 0) return re + " - " + (-im) + "i";
|
||||
return re + " + " + im + "i";
|
||||
}
|
||||
|
||||
// return abs/modulus/magnitude
|
||||
public double abs() {
|
||||
return Math.hypot(re, im);
|
||||
}
|
||||
|
||||
// return angle/phase/argument, normalized to be between -pi and pi
|
||||
public double phase() {
|
||||
return Math.atan2(im, re);
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is (this + b)
|
||||
public Complex plus(Complex b) {
|
||||
Complex a = this; // invoking object
|
||||
double real = a.re + b.re;
|
||||
double imag = a.im + b.im;
|
||||
return new Complex(real, imag);
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is (this - b)
|
||||
public Complex minus(Complex b) {
|
||||
Complex a = this;
|
||||
double real = a.re - b.re;
|
||||
double imag = a.im - b.im;
|
||||
return new Complex(real, imag);
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is (this * b)
|
||||
public Complex times(Complex b) {
|
||||
Complex a = this;
|
||||
double real = a.re * b.re - a.im * b.im;
|
||||
double imag = a.re * b.im + a.im * b.re;
|
||||
return new Complex(real, imag);
|
||||
}
|
||||
|
||||
// return a new object whose value is (this * alpha)
|
||||
public Complex scale(double alpha) {
|
||||
return new Complex(alpha * re, alpha * im);
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is the conjugate of this
|
||||
public Complex conjugate() {
|
||||
return new Complex(re, -im);
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is the reciprocal of this
|
||||
public Complex reciprocal() {
|
||||
double scale = re*re + im*im;
|
||||
return new Complex(re / scale, -im / scale);
|
||||
}
|
||||
|
||||
// return the real or imaginary part
|
||||
public double re() { return re; }
|
||||
public double im() { return im; }
|
||||
|
||||
// return a / b
|
||||
public Complex divides(Complex b) {
|
||||
Complex a = this;
|
||||
return a.times(b.reciprocal());
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is the complex exponential of this
|
||||
public Complex exp() {
|
||||
return new Complex(Math.exp(re) * Math.cos(im), Math.exp(re) * Math.sin(im));
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is the complex sine of this
|
||||
public Complex sin() {
|
||||
return new Complex(Math.sin(re) * Math.cosh(im), Math.cos(re) * Math.sinh(im));
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is the complex cosine of this
|
||||
public Complex cos() {
|
||||
return new Complex(Math.cos(re) * Math.cosh(im), -Math.sin(re) * Math.sinh(im));
|
||||
}
|
||||
|
||||
// return a new Complex object whose value is the complex tangent of this
|
||||
public Complex tan() {
|
||||
return sin().divides(cos());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// a static version of plus
|
||||
public static Complex plus(Complex a, Complex b) {
|
||||
double real = a.re + b.re;
|
||||
double imag = a.im + b.im;
|
||||
Complex sum = new Complex(real, imag);
|
||||
return sum;
|
||||
}
|
||||
|
||||
// See Section 3.3.
|
||||
public boolean equals(Object x) {
|
||||
if (x == null) return false;
|
||||
if (this.getClass() != x.getClass()) return false;
|
||||
Complex that = (Complex) x;
|
||||
return (this.re == that.re) && (this.im == that.im);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class DetectorImpl implements IDetector {
|
||||
protected ArrayList<Double> m_buffer;
|
||||
protected int m_buffer_SIZE; //TODO: Make this this dependent to the sampleRate
|
||||
protected double m_sampleRate;
|
||||
protected ThresholdCalculator m_thresholdCalculator;
|
||||
protected double m_threshold;
|
||||
protected Notifier m_Notifier;
|
||||
|
||||
public DetectorImpl(int windowSize)
|
||||
{
|
||||
m_buffer = new ArrayList<>();
|
||||
m_buffer_SIZE = 128; //TODO later: Change this hardcoded value and calculate it during runtime -> depending on sampleRate
|
||||
m_sampleRate = 0;
|
||||
m_thresholdCalculator = new ThresholdCalculator(windowSize);
|
||||
m_threshold = m_thresholdCalculator.getThreshold();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewSample(double sample) {
|
||||
m_thresholdCalculator.onNewSample(sample);
|
||||
m_threshold = m_thresholdCalculator.getThreshold();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSampleRate(double sampleRate) {
|
||||
m_sampleRate = sampleRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setThreshold(double threshold) {
|
||||
// Call this to set the constant part of the threshold determined by the user
|
||||
m_thresholdCalculator.setConstantThresholdPart(threshold);
|
||||
}
|
||||
|
||||
public void connectNotifier(Notifier notifier){
|
||||
if(notifier == null){
|
||||
throw new AssertionError("Notifier is null");
|
||||
}
|
||||
m_Notifier = notifier;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DetectorTimedomain extends DetectorImpl {
|
||||
private boolean m_calculate_amplitude;
|
||||
private int m_threshold_cnt;
|
||||
private int m_sample_cnt;
|
||||
|
||||
public DetectorTimedomain(int windowSize) {
|
||||
super(windowSize);
|
||||
Log.d("DetectorTimedomain", "DetectorTimedomain() - Constructor called");
|
||||
m_calculate_amplitude = false;
|
||||
m_threshold_cnt = 0;
|
||||
m_sample_cnt = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewSample(double sample) {
|
||||
super.onNewSample(sample);
|
||||
check_for_earthquake(sample);
|
||||
}
|
||||
|
||||
public void check_for_earthquake(double sample)
|
||||
{
|
||||
// This method checks if threshold was exceeded and calculates the amplitude if enough values are available
|
||||
// Possible combinitions of the return values:
|
||||
// 1: false, 0.0 -> Threshold wasn't exceeded
|
||||
// 2: true, 0.0 -> Threshold was exceeded, but no value for amplitude is available yet (because m_buffer isn't filled yet)
|
||||
// 3: true, amplitude -> Threshold was exceeded and a value for amplitude is available
|
||||
//TODO: find better solution for returning the results -> temp solution: No return-values but printing to logcat instead. Use Notifier later.
|
||||
|
||||
Pair<Boolean, Double> return_pair = new Pair<Boolean, Double>(false, 0.0);
|
||||
if ((sample > m_threshold) && !(m_calculate_amplitude)) {
|
||||
Log.d("DetectorTimedomain", "threshold was exceeded. threshold: " + m_threshold); //TODO: send this info with notifier instead
|
||||
m_threshold_cnt++;
|
||||
// Later: add Logger entry
|
||||
m_calculate_amplitude = true;
|
||||
m_buffer = new ArrayList<>(); //resetting to an empty ArrayList
|
||||
}
|
||||
|
||||
if (m_calculate_amplitude) {
|
||||
if (m_sample_cnt >= m_buffer_SIZE) {
|
||||
//Vector sensor_samples is filled -> determine amplitude
|
||||
double amplitude = calculate_maximum(m_buffer);
|
||||
m_sample_cnt = 0;
|
||||
m_calculate_amplitude = false;
|
||||
Log.d("DetectorTimedomain", "Maximum calculated: " + amplitude); //TODO: send this message with notifier instead
|
||||
return_pair = new Pair<Boolean, Double>(true, amplitude);
|
||||
// Later: add Logger entry
|
||||
} else {
|
||||
m_buffer.add(sample);
|
||||
m_sample_cnt++;
|
||||
return_pair = new Pair<Boolean, Double>(true, 0.0);
|
||||
}
|
||||
}
|
||||
m_Notifier.sendEvent();
|
||||
//return return_pair;
|
||||
}
|
||||
|
||||
private double calculate_maximum(ArrayList<Double> samples) {
|
||||
double maximum = 0;
|
||||
for (double sample : samples) {
|
||||
if (maximum < sample)
|
||||
maximum = sample;
|
||||
}
|
||||
return maximum;
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Compilation: javac FFT.java
|
||||
* Execution: java FFT n
|
||||
* Dependencies: Complex.java
|
||||
*
|
||||
* Compute the FFT and inverse FFT of a length n complex sequence
|
||||
* using the radix 2 Cooley-Tukey algorithm.
|
||||
|
||||
* Bare bones implementation that runs in O(n log n) time and O(n)
|
||||
* space. Our goal is to optimize the clarity of the code, rather
|
||||
* than performance.
|
||||
*
|
||||
* This implementation uses the primitive root of unity w = e^(-2 pi i / n).
|
||||
* Some resources use w = e^(2 pi i / n).
|
||||
*
|
||||
* Reference: https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/05DivideAndConquerII.pdf
|
||||
*
|
||||
* Limitations
|
||||
* -----------
|
||||
* - assumes n is a power of 2
|
||||
*
|
||||
* - not the most memory efficient algorithm (because it uses
|
||||
* an object type for representing complex numbers and because
|
||||
* it re-allocates memory for the subarray, instead of doing
|
||||
* in-place or reusing a single temporary array)
|
||||
*
|
||||
* For an in-place radix 2 Cooley-Tukey FFT, see
|
||||
* https://introcs.cs.princeton.edu/java/97data/InplaceFFT.java.html
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
public class FFT {
|
||||
|
||||
// compute the FFT of x[], assuming its length n is a power of 2
|
||||
public static Complex[] fft(Complex[] x) {
|
||||
int n = x.length;
|
||||
|
||||
// base case
|
||||
if (n == 1) return new Complex[] { x[0] };
|
||||
|
||||
// radix 2 Cooley-Tukey FFT
|
||||
if (n % 2 != 0) {
|
||||
throw new IllegalArgumentException("n is not a power of 2");
|
||||
}
|
||||
|
||||
// compute FFT of even terms
|
||||
Complex[] even = new Complex[n/2];
|
||||
for (int k = 0; k < n/2; k++) {
|
||||
even[k] = x[2*k];
|
||||
}
|
||||
Complex[] evenFFT = fft(even);
|
||||
|
||||
// compute FFT of odd terms
|
||||
Complex[] odd = even; // reuse the array (to avoid n log n space)
|
||||
for (int k = 0; k < n/2; k++) {
|
||||
odd[k] = x[2*k + 1];
|
||||
}
|
||||
Complex[] oddFFT = fft(odd);
|
||||
|
||||
// combine
|
||||
Complex[] y = new Complex[n];
|
||||
for (int k = 0; k < n/2; k++) {
|
||||
double kth = -2 * k * Math.PI / n;
|
||||
Complex wk = new Complex(Math.cos(kth), Math.sin(kth));
|
||||
y[k] = evenFFT[k].plus (wk.times(oddFFT[k]));
|
||||
y[k + n/2] = evenFFT[k].minus(wk.times(oddFFT[k]));
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
// compute the inverse FFT of x[], assuming its length n is a power of 2
|
||||
public static Complex[] ifft(Complex[] x) {
|
||||
int n = x.length;
|
||||
Complex[] y = new Complex[n];
|
||||
|
||||
// take conjugate
|
||||
for (int i = 0; i < n; i++) {
|
||||
y[i] = x[i].conjugate();
|
||||
}
|
||||
|
||||
// compute forward FFT
|
||||
y = fft(y);
|
||||
|
||||
// take conjugate again
|
||||
for (int i = 0; i < n; i++) {
|
||||
y[i] = y[i].conjugate();
|
||||
}
|
||||
|
||||
// divide by n
|
||||
for (int i = 0; i < n; i++) {
|
||||
y[i] = y[i].scale(1.0 / n);
|
||||
}
|
||||
|
||||
return y;
|
||||
|
||||
}
|
||||
|
||||
// compute the circular convolution of x and y
|
||||
public static Complex[] cconvolve(Complex[] x, Complex[] y) {
|
||||
|
||||
// should probably pad x and y with 0s so that they have same length
|
||||
// and are powers of 2
|
||||
if (x.length != y.length) {
|
||||
throw new IllegalArgumentException("Dimensions don't agree");
|
||||
}
|
||||
|
||||
int n = x.length;
|
||||
|
||||
// compute FFT of each sequence
|
||||
Complex[] a = fft(x);
|
||||
Complex[] b = fft(y);
|
||||
|
||||
// point-wise multiply
|
||||
Complex[] c = new Complex[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
c[i] = a[i].times(b[i]);
|
||||
}
|
||||
|
||||
// compute inverse FFT
|
||||
return ifft(c);
|
||||
}
|
||||
|
||||
|
||||
// compute the linear convolution of x and y
|
||||
public static Complex[] convolve(Complex[] x, Complex[] y) {
|
||||
Complex ZERO = new Complex(0, 0);
|
||||
|
||||
Complex[] a = new Complex[2*x.length];
|
||||
for (int i = 0; i < x.length; i++) a[i] = x[i];
|
||||
for (int i = x.length; i < 2*x.length; i++) a[i] = ZERO;
|
||||
|
||||
Complex[] b = new Complex[2*y.length];
|
||||
for (int i = 0; i < y.length; i++) b[i] = y[i];
|
||||
for (int i = y.length; i < 2*y.length; i++) b[i] = ZERO;
|
||||
|
||||
return cconvolve(a, b);
|
||||
}
|
||||
|
||||
// compute the DFT of x[] via brute force (n^2 time)
|
||||
public static Complex[] dft(Complex[] x) {
|
||||
int n = x.length;
|
||||
Complex ZERO = new Complex(0, 0);
|
||||
Complex[] y = new Complex[n];
|
||||
for (int k = 0; k < n; k++) {
|
||||
y[k] = ZERO;
|
||||
for (int j = 0; j < n; j++) {
|
||||
int power = (k * j) % n;
|
||||
double kth = -2 * power * Math.PI / n;
|
||||
Complex wkj = new Complex(Math.cos(kth), Math.sin(kth));
|
||||
y[k] = y[k].plus(x[j].times(wkj));
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* Test client and sample execution
|
||||
*
|
||||
* % java FFT 4
|
||||
* x
|
||||
* -------------------
|
||||
* -0.03480425839330703
|
||||
* 0.07910192950176387
|
||||
* 0.7233322451735928
|
||||
* 0.1659819820667019
|
||||
*
|
||||
* y = fft(x)
|
||||
* -------------------
|
||||
* 0.9336118983487516
|
||||
* -0.7581365035668999 + 0.08688005256493803i
|
||||
* 0.44344407521182005
|
||||
* -0.7581365035668999 - 0.08688005256493803i
|
||||
*
|
||||
* z = ifft(y)
|
||||
* -------------------
|
||||
* -0.03480425839330703
|
||||
* 0.07910192950176387 + 2.6599344570851287E-18i
|
||||
* 0.7233322451735928
|
||||
* 0.1659819820667019 - 2.6599344570851287E-18i
|
||||
*
|
||||
* c = cconvolve(x, x)
|
||||
* -------------------
|
||||
* 0.5506798633981853
|
||||
* 0.23461407150576394 - 4.033186818023279E-18i
|
||||
* -0.016542951108772352
|
||||
* 0.10288019294318276 + 4.033186818023279E-18i
|
||||
*
|
||||
* d = convolve(x, x)
|
||||
* -------------------
|
||||
* 0.001211336402308083 - 3.122502256758253E-17i
|
||||
* -0.005506167987577068 - 5.058885073636224E-17i
|
||||
* -0.044092969479563274 + 2.1934338938072244E-18i
|
||||
* 0.10288019294318276 - 3.6147323062478115E-17i
|
||||
* 0.5494685269958772 + 3.122502256758253E-17i
|
||||
* 0.240120239493341 + 4.655566391833896E-17i
|
||||
* 0.02755001837079092 - 2.1934338938072244E-18i
|
||||
* 4.01805098805014E-17i
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
public interface IDetector {
|
||||
public void onNewSample(double sample);
|
||||
public void setSampleRate(double sampleRate);
|
||||
public void setThreshold(double threshold);
|
||||
public void connectNotifier(Notifier notifier);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
public interface ISensor {
|
||||
public double getSampleRate();
|
||||
|
||||
public void connectDetector(IDetector detector);
|
||||
|
||||
public void startSampling();
|
||||
|
||||
public void stopSampling();
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class Logger
|
||||
{
|
||||
private TextView textView;
|
||||
private StringBuffer sb = new StringBuffer();
|
||||
private String tag;
|
||||
private Activity activity;
|
||||
|
||||
public Logger(String tag, String logInitText)
|
||||
{
|
||||
this.activity = null;
|
||||
this.tag = tag;
|
||||
sb.append(logInitText);
|
||||
}
|
||||
|
||||
public Logger(Activity activity, String tag, TextView textView, String logInitText)
|
||||
{
|
||||
this.activity = activity;
|
||||
this.tag = tag;
|
||||
this.textView = textView;
|
||||
sb.append(logInitText);
|
||||
}
|
||||
|
||||
public void log(String s)
|
||||
{
|
||||
Log.d(tag, s);
|
||||
sb.append(s).append("\n");
|
||||
if (textView != null)
|
||||
{
|
||||
if(activity !=null)
|
||||
{
|
||||
activity.runOnUiThread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
textView.setText(sb.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
textView.setText(sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void log(Exception e)
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(sw));
|
||||
log(sw.toString());
|
||||
}
|
||||
|
||||
public void clearLog()
|
||||
{
|
||||
sb.setLength(0);
|
||||
if (textView != null)
|
||||
{
|
||||
textView.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
public String getLoggedText()
|
||||
{
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class MySensor extends SensorImpl implements SensorEventListener {
|
||||
private SensorManager sensorManager;
|
||||
private Sensor m_sensor;
|
||||
private int sensorType = Sensor.TYPE_ACCELEROMETER;
|
||||
private long time_former_value;
|
||||
private long time_current_value;
|
||||
|
||||
private int sample_cnt;
|
||||
|
||||
public MySensor()
|
||||
{
|
||||
m_sensor = null;
|
||||
time_former_value = 0;
|
||||
time_current_value = 0;
|
||||
sample_cnt = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event)
|
||||
{
|
||||
//Log.d("MySensor","onSensorChanged()\n");
|
||||
|
||||
// Calculating the sample rate
|
||||
time_current_value = System.currentTimeMillis();
|
||||
long period = time_current_value - time_former_value;
|
||||
if ((time_former_value != 0) && (period != 0)) {
|
||||
m_sampleRate = (double) (1.0 / period) * 1000.0; // in Hz
|
||||
m_detector.setSampleRate(m_sampleRate);
|
||||
}
|
||||
|
||||
/*if (sample_cnt == 100) //TODO: Delete this part before final use (inc. sample_cnt) -> only meant for debugging
|
||||
{
|
||||
Log.d("MySensor", "m_sampleRate:" + m_sampleRate + "\n");
|
||||
Log.d("MySensor", "time_current_value:" + time_current_value + "\n");
|
||||
Log.d("MySensor", "time_former_value:" + time_former_value + "\n");
|
||||
Log.d("MySensor", "currentTimeMillis:" + System.currentTimeMillis() + "\n");
|
||||
Log.d("MySensor", "period:" + period + "\n");
|
||||
sample_cnt = 0;
|
||||
}*/
|
||||
|
||||
time_former_value = time_current_value;
|
||||
// Calculating the acceleration
|
||||
double acceleration = (Math.sqrt(event.values[0] * event.values[0] + event.values[1] * (event.values[1] + event.values[2] * event.values[2]))) - 9.81;
|
||||
m_detector.onNewSample(acceleration);
|
||||
sample_cnt++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
Log.d("MySensor","onAccuracyChanged()\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSampleRate() {
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSampling() {
|
||||
if (m_sensor != null) {
|
||||
if (sensorManager.registerListener(this, m_sensor, SensorManager.SENSOR_DELAY_GAME)) {
|
||||
Log.d("MySensor", "Bei Sensor angemeldet.\n");
|
||||
} else {
|
||||
Log.d("MySensor", "Kann dem Sensor keinen Beobachter hinzufügen\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSampling() {
|
||||
if (m_sensor != null) {
|
||||
sensorManager.unregisterListener(this, m_sensor);
|
||||
Log.d("MySensor","Von Sensor abgemeldet.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void connectSensorManager(SensorManager sensorManager){
|
||||
this.sensorManager = sensorManager;
|
||||
if (sensorManager.getSensorList(sensorType).size() == 0) {
|
||||
Log.d("MySensor", "Es gibt den Sensor nicht.\n");
|
||||
m_sensor = null;
|
||||
} else {
|
||||
m_sensor = sensorManager.getSensorList(sensorType).get(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Observable;
|
||||
|
||||
public class Notifier extends Observable {
|
||||
private double[] data;
|
||||
|
||||
public Notifier(){
|
||||
|
||||
}
|
||||
public void sendEvent(){
|
||||
Log.d("Hi", "sendEvent: Test");
|
||||
}
|
||||
|
||||
public void onNewFFTData(double[] data){
|
||||
this.data = data;
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
|
||||
public double[] getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
public class SensorFake extends SensorImpl {
|
||||
@Override
|
||||
public double getSampleRate() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSampling() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSampling() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
public abstract class SensorImpl implements ISensor {
|
||||
protected IDetector m_detector;
|
||||
protected double m_sampleRate;
|
||||
|
||||
public SensorImpl()
|
||||
{
|
||||
m_detector = null;
|
||||
m_sampleRate = 0;
|
||||
}
|
||||
|
||||
public void connectDetector(IDetector detector){
|
||||
if(detector == null){
|
||||
throw new AssertionError("detector == null");
|
||||
}
|
||||
m_detector = detector;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
import android.hardware.SensorManager;
|
||||
|
||||
import java.util.Observer;
|
||||
|
||||
|
||||
public class SignalProcessingControl {
|
||||
private IDetector detector;
|
||||
private ISensor sensor;
|
||||
private Notifier notifier;
|
||||
private Logger logger;
|
||||
|
||||
public SignalProcessingControl(SensorManager sensorManager, Logger logger) {
|
||||
this.logger = logger;
|
||||
logger.log("SignalProcessingControl()");
|
||||
|
||||
// create notifier
|
||||
notifier = new Notifier();
|
||||
|
||||
// create detector
|
||||
//detector = new DetectorTimedomain(20);
|
||||
detector = new DetectorFFT(20);
|
||||
detector.setThreshold(6); //TODO: Remove hardcoded threshold and read from GUI instead
|
||||
detector.connectNotifier(notifier);
|
||||
|
||||
// create & link hardware to sensor -> sensorManager
|
||||
MySensor mySensor = new MySensor();
|
||||
mySensor.connectSensorManager(sensorManager);
|
||||
this.sensor = mySensor;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
logger.log("SignalProcessingControl: init()");
|
||||
sensor.connectDetector(detector);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
logger.log("SignalProcessingControl: start()");
|
||||
sensor.startSampling();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
logger.log("SignalProcessingControl: stop()");
|
||||
sensor.stopSampling();
|
||||
}
|
||||
|
||||
public Notifier getNotifier() {
|
||||
return notifier;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.feemers.android.fftdrawer.SignalProcessing;
|
||||
|
||||
class ThresholdCalculator {
|
||||
private double[] m_buffer;
|
||||
private int m_windowSize;
|
||||
private int m_bufferCounter;
|
||||
private int m_bufferInitCounter;
|
||||
private double m_constantThresholdPart;
|
||||
private double m_adaptiveThresholdPart;
|
||||
|
||||
public ThresholdCalculator(int windowSize) {
|
||||
if (windowSize <= 0) {
|
||||
throw new AssertionError("windowSize should be postive");
|
||||
}
|
||||
m_windowSize = windowSize;
|
||||
reset();
|
||||
}
|
||||
|
||||
public double getThreshold() {
|
||||
// This method is meant for the use inside of a detector implementation
|
||||
// Should be called every time a new sensor value is available
|
||||
// Returns the sum of the constant part of the threshold (determined by the user) and the
|
||||
// adaptive part of the threshold (determined by the noise level of the signal)
|
||||
return m_constantThresholdPart + m_adaptiveThresholdPart;
|
||||
}
|
||||
|
||||
public void setConstantThresholdPart(double constantThresholdPart) {
|
||||
// This method should be called when the User changes the constant part of the threshold with the GUI
|
||||
this.m_constantThresholdPart = constantThresholdPart;
|
||||
}
|
||||
|
||||
public void onNewSample(double sample) {
|
||||
// store sample
|
||||
m_buffer[m_bufferCounter] = sample;
|
||||
// increase counter
|
||||
m_bufferCounter++;
|
||||
// check if we are on the end of Array -> go to start
|
||||
if (m_bufferCounter >= m_windowSize) {
|
||||
m_bufferCounter = 0;
|
||||
}
|
||||
|
||||
// when we start the application we will have an arry with emty values
|
||||
// hence we define how many values are already new
|
||||
// after N_sample == windowSize this will have no further effect
|
||||
if (m_bufferInitCounter < m_windowSize) {
|
||||
m_bufferInitCounter++;
|
||||
}
|
||||
|
||||
// now calculate Mean
|
||||
double absMean = 0;
|
||||
for (int i = 0; i < m_bufferInitCounter; i++) {
|
||||
double sampleVal = m_buffer[i];
|
||||
absMean += Math.sqrt(sampleVal * sampleVal);
|
||||
}
|
||||
m_adaptiveThresholdPart = absMean / m_bufferInitCounter;
|
||||
}
|
||||
|
||||
// for reset this class reset
|
||||
public void reset() {
|
||||
m_bufferCounter = 0;
|
||||
m_bufferInitCounter = 0;
|
||||
m_buffer = new double[m_windowSize];
|
||||
for (int i = 0; i < m_windowSize; i++) {
|
||||
m_buffer[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
30
app/src/main/res/drawable-v24/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
170
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
32
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:mynamespace="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity"
|
||||
android:orientation="vertical"
|
||||
tools:activity=".MainActivity">
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<com.feemers.android.fftdrawer.BarChartView
|
||||
android:id="@+id/graficView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
mynamespace:backgroundColor="#4C614C"/>
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<com.feemers.android.fftdrawer.BarChartView
|
||||
android:id="@+id/graficView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
mynamespace:backgroundColor="#75455E"/>
|
||||
</LinearLayout>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 16 KiB |
6
app/src/main/res/values/attributes.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="BarChartView">
|
||||
<attr name="backgroundColor" format="color"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
6
app/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#6200EE</color>
|
||||
<color name="colorPrimaryDark">#3700B3</color>
|
||||
<color name="colorAccent">#03DAC5</color>
|
||||
</resources>
|
3
app/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">FFTDrawer</string>
|
||||
</resources>
|
11
app/src/main/res/values/styles.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -0,0 +1,17 @@
|
||||
package com.feemers.android.fftdrawer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
29
build.gradle
Normal file
@ -0,0 +1,29 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.6.1'
|
||||
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
20
gradle.properties
Normal file
@ -0,0 +1,20 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app's APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Automatically convert third-party libraries to use AndroidX
|
||||
android.enableJetifier=true
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#Mon Jun 08 18:27:45 CEST 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
|
172
gradlew
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
2
settings.gradle
Normal file
@ -0,0 +1,2 @@
|
||||
rootProject.name='FFTDrawer'
|
||||
include ':app'
|