diff --git a/android/src/main/java/com/goodatlas/audiorecord/RNAudioRecordModule.java b/android/src/main/java/com/goodatlas/audiorecord/RNAudioRecordModule.java index 11c5ad8..f0e5d6e 100644 --- a/android/src/main/java/com/goodatlas/audiorecord/RNAudioRecordModule.java +++ b/android/src/main/java/com/goodatlas/audiorecord/RNAudioRecordModule.java @@ -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); } diff --git a/index.js b/index.js index d00d285..11e629f 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,8 @@ AudioRecord.start = () => RNAudioRecord.start(); AudioRecord.stop = () => RNAudioRecord.stop(); const eventsMap = { - data: 'data' + data: 'data', + decibel: 'decibel' }; AudioRecord.on = (event, callback) => {