Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix visibility modifiers & add comment to calculateValue
Browse files Browse the repository at this point in the history
  • Loading branch information
incubo4u committed Aug 4, 2023
1 parent 6991d28 commit bf33ec9
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void setSoundDetectionListener(OnSoundDetectedListener listener) {
onSoundDetectedListener = listener;
}

public void setIsSoundDetected(boolean newValue) {
private void setIsSoundDetected(boolean newValue) {
if (onSoundDetectedListener != null) {
onSoundDetectedListener.onSoundDetected(newValue);
}
Expand All @@ -77,7 +77,13 @@ private int getMaxAmplitude(short[] buffer, int bytesRead) {
}
return maxAmplitude;
}

/**
* Calculates the sound level value in decibels (dB) based on the given maxAmplitude.
* If maxAmplitude is non-positive (<= 0), returns a default value of -160 dB.
* Otherwise, computes the value using the formula: 20 * log10(maxAmplitude / 32767),
* where 32767 is the maximum value for a 16-bit PCM audio sample.
* The calculated dB value represents the loudness of the audio signal.
**/
private int calculateValue(int maxAmplitude) {
if (maxAmplitude <= 0) {
return -160;
Expand Down

0 comments on commit bf33ec9

Please sign in to comment.