Compare commits
No commits in common. "5007623accdbcb116613cb93e74fb9023bc228f3" and "61cad3493149119d8a829b51d1ad136c685dcc1f" have entirely different histories.
5007623acc
...
61cad34931
@ -2,16 +2,24 @@ 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 {
|
||||
/**
|
||||
@ -20,9 +28,11 @@ public class MicrophoneDetector extends Detector {
|
||||
* @param context
|
||||
*/
|
||||
|
||||
private static final int RECHTEANFORDERUNG_MIKROFON = 1;
|
||||
|
||||
private AufnahmeTask aufnahmeTask;
|
||||
public boolean armed = false;
|
||||
public int schwellwertAlarm = 100;
|
||||
public int Schwellwert_Alarm = 100;
|
||||
private Context context;
|
||||
|
||||
public MicrophoneDetector(Context context) {
|
||||
@ -48,17 +58,12 @@ 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);
|
||||
@ -107,6 +112,8 @@ public class MicrophoneDetector extends Detector {
|
||||
|
||||
Log.d("0","Konfiguration: "+ s);
|
||||
|
||||
int pufferGroesseInAnzahlAbtastwerten = pufferGroesseInBytes / anzahlBytesProAbtastwert;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -122,7 +129,7 @@ public class MicrophoneDetector extends Detector {
|
||||
|
||||
//Kalibrierung
|
||||
try {
|
||||
Thread.sleep(startDelay); // Time to lay down the phone
|
||||
Thread.sleep(3000); // Time to lay down the phone
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -132,7 +139,7 @@ public class MicrophoneDetector extends Detector {
|
||||
Verarbeitungsergebnis kalibrierErgebnis = verarbeiten(puffer, n);
|
||||
kalibierWert += kalibrierErgebnis.maxAmp;
|
||||
try {
|
||||
Thread.sleep(threadSleeptime);
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -186,7 +193,7 @@ public class MicrophoneDetector extends Detector {
|
||||
publishProgress(ergebnis);
|
||||
|
||||
try {
|
||||
Thread.sleep(threadSleeptime);
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -214,7 +221,7 @@ public class MicrophoneDetector extends Detector {
|
||||
|
||||
ringPuffer.hinzufuegen(max);
|
||||
maxAmp = ringPuffer.maximum();
|
||||
if (maxAmp <= schwellwertAlarm + kalibierWert) {
|
||||
if (maxAmp <= Schwellwert_Alarm+kalibierWert) {
|
||||
armed = true;
|
||||
}
|
||||
}
|
||||
@ -227,10 +234,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("alarmAudio","VR: " + progress[0].verarbeitungsrate + ", Amp: " + maxAmpPrint
|
||||
+ " dB, Kal: " + kalibierWertPrint + " dB");
|
||||
Log.d("0","VR, Max, Kal:" + progress[0].verarbeitungsrate + ", " + maxAmpPrint
|
||||
+ " dB, " + kalibierWertPrint + " dB");
|
||||
|
||||
if (progress[0].maxAmp >= schwellwertAlarm + kalibierWert && armed == true) {
|
||||
if (progress[0].maxAmp >= Schwellwert_Alarm+kalibierWert && armed == true) {
|
||||
armed = false;
|
||||
detectionReport = new DetectionReport(true, "Audio", maxAmpPrint);
|
||||
reportViolation("Audio", maxAmpPrint);
|
||||
@ -352,6 +359,16 @@ 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,8 +15,6 @@ public class PopUpClass {
|
||||
PermissionRequest permission;
|
||||
TextView PopUpText;
|
||||
|
||||
Button buttonEdit;
|
||||
|
||||
|
||||
public PopUpClass(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
@ -49,7 +47,7 @@ public class PopUpClass {
|
||||
|
||||
PopUpText = popupView.findViewById(R.id.titleText);
|
||||
|
||||
buttonEdit = popupView.findViewById(R.id.RechteAnfordern);
|
||||
Button buttonEdit = popupView.findViewById(R.id.RechteAnfordern);
|
||||
buttonEdit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -72,25 +70,19 @@ 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