Skip to content

Commit

Permalink
Can now determine amplitude
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 21, 2014
1 parent dd0fb67 commit ea51a0d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/Locabean/src/com/locaudio/signal/WaveProcessing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ea51a0d

Please sign in to comment.