I am working with AudioRecord class in android. In my application I want to measure the sound captured by the microphone of a head-set without pre-filtering or equalizations. I know that to reach this result I have to set properly the audio source of the AudioRecord session but trying my code on different devices I came up with different outcomes. For example with a Galaxy Note 3 I managed to record the raw mic data with the MediaRecorder.AudioSource.VOICE_RECOGNITION while using MediaRecorder.AudioSource.MIC I ended up with filtered waves. On the other hand with a Galaxy s4 I had to work reversely. Where is my mistake? Is there a unique way to have access to the raw data of the Microphone? This is the code line I use to initialize the audiorecord instance:
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 44100, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, recordBufferSize);
P.S.: in all my tries I had turned off all the sound pre-equalizations available on the setting page. I tried also with MediaRecorder.AudioSource.DEFAULT but it does not change anything.
To get the closest possible to unprocessed audio, I think the OpenSL ES API specification in the Android NDK is the best option. Google provide an example project of real-time recording and playback (with a delay to avoid feedback).
This is how the underlying implementation of AudioRecorder was built and it allows for much better optimization of your audio processing. Although it uses C++, it may be worthwhile knowing especially if you are planning on implementing any other audio processing apps in the future.
As mentioned previously there is an option to set the MediaRecorder.AudioSource
to UNPROCESSED
. However as mentioned in the documentation, this is not supported on all devices.
To capture the real input the hardware actually receives, via an Android app, is a very unlikely achievable task (at least cross-platform). And even if you get it to work on one device, I would be amazed if it worked on several devices. At this level you would want to look at Android OS development, but then you start to limit yourself to the hardware you want to use.
As mentioned in your question's comments :
Your "mistake" is that each OEM can implement this differently. Even within the same company there might be different teams working on different models that don't do things exactly the same. IIRC, when I worked at Sony we didn't have any microphone setting that didn't use some preprocessing effect(s).
Which I'm sure is true in most OEMs.