From ea51a0dd4392b91256ad211d901f71c1e4dcd95b Mon Sep 17 00:00:00 2001 From: Alexander James Wallar Date: Tue, 21 Jan 2014 18:03:21 -0500 Subject: [PATCH] Can now determine amplitude --- .../com/locaudio/signal/WaveProcessing.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Locabean/src/com/locaudio/signal/WaveProcessing.java b/app/Locabean/src/com/locaudio/signal/WaveProcessing.java index c412546..9155745 100644 --- a/app/Locabean/src/com/locaudio/signal/WaveProcessing.java +++ b/app/Locabean/src/com/locaudio/signal/WaveProcessing.java @@ -8,9 +8,32 @@ public static float amplitudeToSoundPressureLevel(float amplitude) { return (float) (20 * Math.log(amplitude) / Math.log(10)); } + public static boolean isPeak(int prevVal, int curVal, int nextVal) { + if (prevVal <= curVal && nextVal <= curVal) { + return true; + } else { + return false; + } + } + public static float determineAverageAmplitude(Wave wave) { - return 0; + short threshold = 100; + int runningSum = 0; + int count = 0; + + short[] amplitudes = wave.getSampleAmplitudes(); + + for (int i = 1; i < amplitudes.length - 1; i++) { + if (isPeak(amplitudes[i - 1], amplitudes[i], amplitudes[i + 1])) { + if (amplitudes[i] > threshold) { + runningSum += amplitudes[i]; + count++; + } + } + } + + return (float) runningSum / (float) count; } public static float determineAverageSoundPressureLevel(Wave wave) {