Changed time to lay phone down to startDelay = 20000, threadSleeptime = 10 and Log.d Report in case of detection for readability ´reasons
This commit is contained in:
parent
4222ebef83
commit
94970885cf
@ -2,24 +2,16 @@ package com.example.ueberwachungssystem.Detection;
|
|||||||
|
|
||||||
import static java.lang.Math.*;
|
import static java.lang.Math.*;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.media.AudioFormat;
|
import android.media.AudioFormat;
|
||||||
import android.media.AudioRecord;
|
import android.media.AudioRecord;
|
||||||
import android.media.MediaRecorder;
|
import android.media.MediaRecorder;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.core.app.ActivityCompat;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
|
|
||||||
import com.example.ueberwachungssystem.Detection.Signalverarbeitung.Complex;
|
import com.example.ueberwachungssystem.Detection.Signalverarbeitung.Complex;
|
||||||
import com.example.ueberwachungssystem.Detection.Signalverarbeitung.FFT;
|
import com.example.ueberwachungssystem.Detection.Signalverarbeitung.FFT;
|
||||||
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
|
||||||
import com.example.ueberwachungssystem.Detection.Detector;
|
|
||||||
|
|
||||||
public class MicrophoneDetector extends Detector {
|
public class MicrophoneDetector extends Detector {
|
||||||
/**
|
/**
|
||||||
@ -28,11 +20,9 @@ public class MicrophoneDetector extends Detector {
|
|||||||
* @param context
|
* @param context
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static final int RECHTEANFORDERUNG_MIKROFON = 1;
|
|
||||||
|
|
||||||
private AufnahmeTask aufnahmeTask;
|
private AufnahmeTask aufnahmeTask;
|
||||||
public boolean armed = false;
|
public boolean armed = false;
|
||||||
public int Schwellwert_Alarm = 100;
|
public int schwellwertAlarm = 100;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
public MicrophoneDetector(Context context) {
|
public MicrophoneDetector(Context context) {
|
||||||
@ -58,12 +48,17 @@ public class MicrophoneDetector extends Detector {
|
|||||||
private final int sampleRateInHz = 44100;
|
private final int sampleRateInHz = 44100;
|
||||||
private final int channelConfig = AudioFormat.CHANNEL_IN_MONO;
|
private final int channelConfig = AudioFormat.CHANNEL_IN_MONO;
|
||||||
private final int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
private final int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||||
|
|
||||||
|
private final int startDelay = 20000;
|
||||||
|
private final int threadSleeptime = 10;
|
||||||
private int minPufferGroesseInBytes;
|
private int minPufferGroesseInBytes;
|
||||||
private int pufferGroesseInBytes;
|
private int pufferGroesseInBytes;
|
||||||
private RingPuffer ringPuffer = new RingPuffer(10);
|
private RingPuffer ringPuffer = new RingPuffer(10);
|
||||||
private float kalibierWert;
|
private float kalibierWert;
|
||||||
private com.example.ueberwachungssystem.Detection.DetectionReport detectionReport;
|
private com.example.ueberwachungssystem.Detection.DetectionReport detectionReport;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
AufnahmeTask() {
|
AufnahmeTask() {
|
||||||
minPufferGroesseInBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
|
minPufferGroesseInBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
|
||||||
@ -112,8 +107,6 @@ public class MicrophoneDetector extends Detector {
|
|||||||
|
|
||||||
Log.d("0","Konfiguration: "+ s);
|
Log.d("0","Konfiguration: "+ s);
|
||||||
|
|
||||||
int pufferGroesseInAnzahlAbtastwerten = pufferGroesseInBytes / anzahlBytesProAbtastwert;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -129,7 +122,7 @@ public class MicrophoneDetector extends Detector {
|
|||||||
|
|
||||||
//Kalibrierung
|
//Kalibrierung
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000); // Time to lay down the phone
|
Thread.sleep(startDelay); // Time to lay down the phone
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -139,7 +132,7 @@ public class MicrophoneDetector extends Detector {
|
|||||||
Verarbeitungsergebnis kalibrierErgebnis = verarbeiten(puffer, n);
|
Verarbeitungsergebnis kalibrierErgebnis = verarbeiten(puffer, n);
|
||||||
kalibierWert += kalibrierErgebnis.maxAmp;
|
kalibierWert += kalibrierErgebnis.maxAmp;
|
||||||
try {
|
try {
|
||||||
Thread.sleep(50);
|
Thread.sleep(threadSleeptime);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -193,7 +186,7 @@ public class MicrophoneDetector extends Detector {
|
|||||||
publishProgress(ergebnis);
|
publishProgress(ergebnis);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10);
|
Thread.sleep(threadSleeptime);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -221,7 +214,7 @@ public class MicrophoneDetector extends Detector {
|
|||||||
|
|
||||||
ringPuffer.hinzufuegen(max);
|
ringPuffer.hinzufuegen(max);
|
||||||
maxAmp = ringPuffer.maximum();
|
maxAmp = ringPuffer.maximum();
|
||||||
if (maxAmp <= Schwellwert_Alarm+kalibierWert) {
|
if (maxAmp <= schwellwertAlarm + kalibierWert) {
|
||||||
armed = true;
|
armed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,10 +227,10 @@ public class MicrophoneDetector extends Detector {
|
|||||||
super.onProgressUpdate(progress);
|
super.onProgressUpdate(progress);
|
||||||
float maxAmpPrint = round(20*log10(abs(progress[0].maxAmp/1.0)));
|
float maxAmpPrint = round(20*log10(abs(progress[0].maxAmp/1.0)));
|
||||||
float kalibierWertPrint = round(20*log10(abs(kalibierWert)));
|
float kalibierWertPrint = round(20*log10(abs(kalibierWert)));
|
||||||
Log.d("0","VR, Max, Kal:" + progress[0].verarbeitungsrate + ", " + maxAmpPrint
|
Log.d("alarmAudio","VR: " + progress[0].verarbeitungsrate + ", Amp: " + maxAmpPrint
|
||||||
+ " dB, " + kalibierWertPrint + " dB");
|
+ " dB, Kal: " + kalibierWertPrint + " dB");
|
||||||
|
|
||||||
if (progress[0].maxAmp >= Schwellwert_Alarm+kalibierWert && armed == true) {
|
if (progress[0].maxAmp >= schwellwertAlarm + kalibierWert && armed == true) {
|
||||||
armed = false;
|
armed = false;
|
||||||
detectionReport = new DetectionReport(true, "Audio", maxAmpPrint);
|
detectionReport = new DetectionReport(true, "Audio", maxAmpPrint);
|
||||||
reportViolation("Audio", maxAmpPrint);
|
reportViolation("Audio", maxAmpPrint);
|
||||||
@ -359,16 +352,6 @@ public class MicrophoneDetector extends Detector {
|
|||||||
this.wichtungAlterWert = 1 - this.wichtungNeuerWert;
|
this.wichtungAlterWert = 1 - this.wichtungNeuerWert;
|
||||||
}
|
}
|
||||||
|
|
||||||
float MittelwertPuffer(short[] puffer) {
|
|
||||||
|
|
||||||
for (int i = 0; i < puffer.length; i++) {
|
|
||||||
mittelwert = Math.abs(puffer[i]);
|
|
||||||
}
|
|
||||||
mittelwert = mittelwert/puffer.length;
|
|
||||||
|
|
||||||
return mittelwert;
|
|
||||||
}
|
|
||||||
|
|
||||||
float mittel(float wert) {
|
float mittel(float wert) {
|
||||||
if (istMittelwertGesetzt) {
|
if (istMittelwertGesetzt) {
|
||||||
mittelwert = wert * wichtungNeuerWert + mittelwert * wichtungAlterWert;
|
mittelwert = wert * wichtungNeuerWert + mittelwert * wichtungAlterWert;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user