Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Added decibel event to Android - Shows decibel level when user is rec… #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ public void run() {
// skip first 2 buffers to eliminate "click sound"
if (bytesRead > 0 && ++count > 2) {
base64Data = Base64.encodeToString(buffer, Base64.NO_WRAP);
// Check decibels in 16 bit
if (audioFormat == AudioFormat.ENCODING_PCM_16BIT) {
double p2 = buffer[buffer.length-1];
double decibel;
if (p2==0) {
decibel=Double.NEGATIVE_INFINITY;
eventEmitter.emit("decibel", decibel);
} else {
decibel = 20.0*Math.log10(p2/65535.0);
if (Double.isNaN(decibel)) {
eventEmitter.emit("decibel", Double.NEGATIVE_INFINITY);
} else {
eventEmitter.emit("decibel", decibel);
}
}

}
eventEmitter.emit("data", base64Data);
os.write(buffer, 0, bytesRead);
}
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ AudioRecord.start = () => RNAudioRecord.start();
AudioRecord.stop = () => RNAudioRecord.stop();

const eventsMap = {
data: 'data'
data: 'data',
decibel: 'decibel'
};

AudioRecord.on = (event, callback) => {
Expand Down