Skip to content

Commit

Permalink
add first noise "room tone" baseline #12
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed May 22, 2017
1 parent 6d98ef9 commit 3dcdcc2
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public final class MicrophoneMonitor implements MicSamplerTask.MicListener {
/**
* Threshold for the decibels sampled
*/
private double NOISE_THRESHOLD = 60.0;
private double NOISE_THRESHOLD = 40.0;

/**
* Baseline noise floor
*
*/
private double mBaseLine = -1;

/**
* Messenger used to communicate with alert service
Expand Down Expand Up @@ -67,9 +73,9 @@ public MicrophoneMonitor(Context context)
prefs = new PreferenceManager(context);

if (prefs.getMicrophoneSensitivity().equals("High")) {
NOISE_THRESHOLD = 30.0;
NOISE_THRESHOLD = 10.0;
} else if (prefs.getMicrophoneSensitivity().equals("Medium")) {
NOISE_THRESHOLD = 40.0;
NOISE_THRESHOLD = 20.0;
}

context.bindService(new Intent(context,
Expand Down Expand Up @@ -120,8 +126,13 @@ public void onSignalReceived(short[] signal) {
averageDB = 20 * Math.log10(Math.abs(average) / 1);
}

if (mBaseLine == -1)
{
mBaseLine = averageDB;
Log.d("MicrophoneMonitor","Baseline is: " + mBaseLine);
}

if (averageDB > NOISE_THRESHOLD) {
if ((averageDB-mBaseLine) > NOISE_THRESHOLD) {

if (!MicrophoneTaskFactory.isRecording()) {
try {
Expand Down

0 comments on commit 3dcdcc2

Please sign in to comment.