I'm using cordova-plugin-audioinput plugin for a JavaScript app that I'm developing. I'm trying to get the different decibel values at different frequencies in realtime using this code:
function startCapture() {
audioinput.start({
audioSourceType: 9,
sampleRate: 44100,
streamToWebAudio: true
});
audioCtx = audioinput.getAudioContext();
analyser = audioCtx.createAnalyser();
analyser.fftSize = 8192;
analyser.maxDecibels = 0;
audioinput.connect(analyser)
bufferLength = analyser.frequencyBinCount;
dataArray = new Uint8Array(bufferLength);
}
The data gets saved into the dataArray
using analyser.getByteFrequencyData(dataArray);
Even though I specify maxDecibels
to 0
, the dataArray
gets filled with positive values which doesn't really make any sense to me. I need the end result to be in decibels and even though the values that get pushed into dataArray
react accordingly to the volume in realtime, they're not in decibels.