Compare commits
4 Commits
61cad34931
...
5007623acc
Author | SHA1 | Date | |
---|---|---|---|
5007623acc | |||
3d9e6b7a3e | |||
1eba8e0f7c | |||
94970885cf |
@ -2,24 +2,16 @@ package com.example.ueberwachungssystem.Detection;
|
||||
|
||||
import static java.lang.Math.*;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.MediaRecorder;
|
||||
import android.os.AsyncTask;
|
||||
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.FFT;
|
||||
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||
import com.example.ueberwachungssystem.Detection.Detector;
|
||||
|
||||
public class MicrophoneDetector extends Detector {
|
||||
/**
|
||||
@ -28,11 +20,9 @@ public class MicrophoneDetector extends Detector {
|
||||
* @param context
|
||||
*/
|
||||
|
||||
private static final int RECHTEANFORDERUNG_MIKROFON = 1;
|
||||
|
||||
private AufnahmeTask aufnahmeTask;
|
||||
public boolean armed = false;
|
||||
public int Schwellwert_Alarm = 100;
|
||||
public int schwellwertAlarm = 100;
|
||||
private Context context;
|
||||
|
||||
public MicrophoneDetector(Context context) {
|
||||
@ -58,12 +48,17 @@ public class MicrophoneDetector extends Detector {
|
||||
private final int sampleRateInHz = 44100;
|
||||
private final int channelConfig = AudioFormat.CHANNEL_IN_MONO;
|
||||
private final int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||
|
||||
private final int startDelay = 20000;
|
||||
private final int threadSleeptime = 10;
|
||||
private int minPufferGroesseInBytes;
|
||||
private int pufferGroesseInBytes;
|
||||
private RingPuffer ringPuffer = new RingPuffer(10);
|
||||
private float kalibierWert;
|
||||
private com.example.ueberwachungssystem.Detection.DetectionReport detectionReport;
|
||||
|
||||
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
AufnahmeTask() {
|
||||
minPufferGroesseInBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
|
||||
@ -112,8 +107,6 @@ public class MicrophoneDetector extends Detector {
|
||||
|
||||
Log.d("0","Konfiguration: "+ s);
|
||||
|
||||
int pufferGroesseInAnzahlAbtastwerten = pufferGroesseInBytes / anzahlBytesProAbtastwert;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,7 +122,7 @@ public class MicrophoneDetector extends Detector {
|
||||
|
||||
//Kalibrierung
|
||||
try {
|
||||
Thread.sleep(3000); // Time to lay down the phone
|
||||
Thread.sleep(startDelay); // Time to lay down the phone
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -139,7 +132,7 @@ public class MicrophoneDetector extends Detector {
|
||||
Verarbeitungsergebnis kalibrierErgebnis = verarbeiten(puffer, n);
|
||||
kalibierWert += kalibrierErgebnis.maxAmp;
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
Thread.sleep(threadSleeptime);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -193,7 +186,7 @@ public class MicrophoneDetector extends Detector {
|
||||
publishProgress(ergebnis);
|
||||
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
Thread.sleep(threadSleeptime);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -221,7 +214,7 @@ public class MicrophoneDetector extends Detector {
|
||||
|
||||
ringPuffer.hinzufuegen(max);
|
||||
maxAmp = ringPuffer.maximum();
|
||||
if (maxAmp <= Schwellwert_Alarm+kalibierWert) {
|
||||
if (maxAmp <= schwellwertAlarm + kalibierWert) {
|
||||
armed = true;
|
||||
}
|
||||
}
|
||||
@ -234,10 +227,10 @@ public class MicrophoneDetector extends Detector {
|
||||
super.onProgressUpdate(progress);
|
||||
float maxAmpPrint = round(20*log10(abs(progress[0].maxAmp/1.0)));
|
||||
float kalibierWertPrint = round(20*log10(abs(kalibierWert)));
|
||||
Log.d("0","VR, Max, Kal:" + progress[0].verarbeitungsrate + ", " + maxAmpPrint
|
||||
+ " dB, " + kalibierWertPrint + " dB");
|
||||
Log.d("alarmAudio","VR: " + progress[0].verarbeitungsrate + ", Amp: " + maxAmpPrint
|
||||
+ " dB, Kal: " + kalibierWertPrint + " dB");
|
||||
|
||||
if (progress[0].maxAmp >= Schwellwert_Alarm+kalibierWert && armed == true) {
|
||||
if (progress[0].maxAmp >= schwellwertAlarm + kalibierWert && armed == true) {
|
||||
armed = false;
|
||||
detectionReport = new DetectionReport(true, "Audio", maxAmpPrint);
|
||||
reportViolation("Audio", maxAmpPrint);
|
||||
@ -359,16 +352,6 @@ public class MicrophoneDetector extends Detector {
|
||||
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) {
|
||||
if (istMittelwertGesetzt) {
|
||||
mittelwert = wert * wichtungNeuerWert + mittelwert * wichtungAlterWert;
|
||||
|
@ -15,6 +15,8 @@ public class PopUpClass {
|
||||
PermissionRequest permission;
|
||||
TextView PopUpText;
|
||||
|
||||
Button buttonEdit;
|
||||
|
||||
|
||||
public PopUpClass(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
@ -47,7 +49,7 @@ public class PopUpClass {
|
||||
|
||||
PopUpText = popupView.findViewById(R.id.titleText);
|
||||
|
||||
Button buttonEdit = popupView.findViewById(R.id.RechteAnfordern);
|
||||
buttonEdit = popupView.findViewById(R.id.RechteAnfordern);
|
||||
buttonEdit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -70,19 +72,25 @@ public class PopUpClass {
|
||||
public void RechtePrüfen(){
|
||||
StringBuilder Text = permission.rechtePruefen();
|
||||
PopUpText.setText(Text);
|
||||
buttonEdit.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
public void RechteAnfordern(){
|
||||
permission.rechteAnfordern();
|
||||
StringBuilder Text = permission.rechtePruefen();
|
||||
PopUpText.setText(Text);
|
||||
|
||||
}
|
||||
public void Sensoren(){
|
||||
PopUpText.setText("Es können 3 verschiedene Sensoren verwendet werden \n -1. Beschleunigungssensor\n -2. Mikrofon\n -3. Kamera");
|
||||
buttonEdit.setVisibility(View.GONE);
|
||||
}
|
||||
public void Impressum(){
|
||||
PopUpText.setText("Die Ueberwachungsapp wurde im Rahmen eines Praktikums der TH-Nürnberg programmiert");
|
||||
buttonEdit.setVisibility(View.GONE);
|
||||
}
|
||||
public void DetectionTotal(int num) {
|
||||
PopUpText.setText("Total Detektions:" +num);
|
||||
buttonEdit.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user