I have an issue using Android's MediaRecorder to record sound from microphone to .m4a files (AAC-LC, MPEG-4 container). Starting from API level 18, the default sampling rate drops from 44.1 or 48 kHz (depending on device) to only 8 Hz. If I specify the sampling rate using MediaRecorder.setAudioSamplingRate, it uses the specified rate but there are a lot of strange noise in the recording.
In LogCat, the following warning are happening from time to time:
(1) Tag: AudioSource Text: AudioRecord reported overrun
(2) Tag: AudioFlinger Text: RecordThread: buffer overflow
Here's the code:
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioChannels(2);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioSamplingRate(48000); // if not specified, defaults to 8kHz, if specified 44.1 or 48 kHz, lots of noise
recorder.setOutputFile("test.m4a");
try {
recorder.prepare();
recorder.start();
} catch (IOException ioe) {
Log.e(TAG, "IOException", ioe);
} catch (IllegalStateException ise) {
Log.e(TAG, "IllegalStateException", ise);
} catch (Exception e) {
Log.e(TAG, "Exception", e);
}
Any help is greatly appreciated.