So I've read various posts and blogs on how to get the amplitude from the microphone on Android. Multiple posts suggested using this implementation:
minSize = AudioRecord.getMinBufferSize(
44100,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT
);
audioRecord = AudioRecord(
MediaRecorder.AudioSource.MIC,
44100,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
minSize
);
val buffer = ShortArray(minSize)
audioRecord.read(buffer, 0, minSize)
var max = 0
for (s in buffer) {
if (abs(s.toInt()) > max) {
max = abs(s.toInt())
}
}
return max.toDouble()//This being the amplitude
First question: What is the measurement of the value I am getting returned? An example of the value could typically be 381 with "regular noise" e.g. milliVolts(mV)?
On iOS you are able to get averagePower and peakPower from the AudioRecorder which returns the average or max amplitude in dbFS.
Second question: Is it possible to do the same implementation that we have on Android on iOS?
Third question: Is it possible to do the same implementation that we have on iOS on Android?
To provide some context; As part of a research project we are looking for different sound patterns that might link a user to a specific context and in order to do so on a larger scale we need to be able to compare the amplitude from Android and iOS.
Fourth question: Regardless of the implementations mentioned above, is there a better way to compare soundwaves from microphones of both iOS and Android devices?
The easiest way to get the max amplitude on Android is a lot less code. Just call MediaRecorder.getMaxAmplitude(). It returns the max amplitude since the previous call. I'm not sure where you got the suggestion to use the call you did, that seems like the hard way.
The units aren't specified. It should correspond to the amount of pressure picked up by the mic, but as every model will have different mics, amps, DACs, etc it isn't going to be the same on all devices. All you can be promised is it will be between 0 and (2^x)-1 where x is the number of bits per sample you picked. I'm not sure why you'd think it would be in millivolts, this isn't an electrical measurement. Sound is typically measured in dB or pascals.
For comparing iOS to Android and trying to do matching- what are you trying to do? The code you have is just finding the max value. That's kind of uninteresting, unless all you're doing is an applause meter. If you're actually looking to compare soundwaves wouldn't you be better off taking the fourier transform and doing so in the frequency domain? The time domain is really messy for that.