This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stable version. Map displays location, Measure view records the raw d…
…B value, no weighting yet
- Loading branch information
Showing
6 changed files
with
196 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
app/src/main/java/edu/osu/sphs/soundmap/activities/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
app/src/main/java/edu/osu/sphs/soundmap/util/MeasureTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package edu.osu.sphs.soundmap.util; | ||
|
||
import android.media.MediaRecorder; | ||
import android.os.AsyncTask; | ||
|
||
import java.io.IOException; | ||
|
||
import static java.lang.Math.log10; | ||
|
||
/** | ||
* Created by Gus on 12/3/2017. A tool to get the dB value in the background asynchronously | ||
*/ | ||
|
||
public class MeasureTask extends AsyncTask<String, Double, Double> { | ||
|
||
private double average; | ||
private MediaRecorder recorder; | ||
private OnUpdateCallback callback; | ||
|
||
public MeasureTask setCallback(OnUpdateCallback callback) { | ||
this.callback = callback; | ||
return this; | ||
} | ||
|
||
public void removeCallback() { | ||
this.callback = null; | ||
} | ||
|
||
@Override | ||
protected Double doInBackground(String... files) { | ||
if (files.length > 0) { | ||
recorder = new MediaRecorder(); | ||
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); | ||
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB); | ||
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB); | ||
recorder.setOutputFile(files[0]); | ||
|
||
try { | ||
recorder.prepare(); | ||
recorder.start(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
long endTime = System.currentTimeMillis() + 30000; | ||
int count = 1; | ||
|
||
while (System.currentTimeMillis() < endTime) { | ||
double amplitude = recorder.getMaxAmplitude(); | ||
publishProgress(amplitude); | ||
|
||
try { | ||
Thread.sleep(333); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
recorder.stop(); | ||
recorder.reset(); | ||
recorder.release(); | ||
recorder = null; | ||
|
||
} else { | ||
new Error("Recording file path output parameters must be greater than one").printStackTrace(); | ||
} | ||
|
||
return average; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(Double d) { | ||
if (recorder != null) { | ||
recorder.stop(); | ||
recorder.reset(); | ||
recorder.reset(); | ||
recorder = null; | ||
} | ||
} | ||
|
||
@Override | ||
protected void onProgressUpdate(Double... values) { | ||
if (callback != null) { | ||
callback.onUpdate(20 * log10(values[0] / 1.0)); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onCancelled() { | ||
if (recorder != null) { | ||
recorder.stop(); | ||
recorder.reset(); | ||
recorder.reset(); | ||
recorder = null; | ||
} | ||
} | ||
|
||
public interface OnUpdateCallback { | ||
void onUpdate(double averageDB); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package edu.osu.sphs.soundmap.util; | ||
|
||
/** | ||
* Created by Gus on 12/2/2017. | ||
*/ | ||
|
||
public class Values { | ||
|
||
/** | ||
* Permission request codes | ||
*/ | ||
public static final int LOCATION_REQUEST_CODE = 11; | ||
public static final int AUDIO_REQUEST_CODE = 12; | ||
|
||
} |