Android Emulator Seems to Record Audio at 96khz : <p>My app is recording audio from phone's microphones and does some real time processing on it. It's working fine on physical devices, but acts "funny" in emulator. It records something, but I'm not quite sure what it is it's recording. </p>

<p><strong>It appears that on emulator the audio samples are being read at about double the rate as on actual devices.</strong> In the app I have a visual progress widget (a horizontally moving recording head), which moves about twice as fast in emulator. </p>

<p>Here is the recording loop:</p>

<pre><code>int FREQUENCY = 44100;
int BLOCKSIZE = 110;

int bufferSize = AudioRecord.getMinBufferSize(FREQUENCY,
        AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT) * 10;

AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.CAMCORDER,
        FREQUENCY, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT,
        bufferSize);

short[] signal = new short[BLOCKSIZE * 2]; // Times two for stereo

audioRecord.startRecording();

while (!isCancelled()) {
    int bufferReadResult = audioRecord.read(signal, 0, BLOCKSIZE * 2);
    if (bufferReadResult != BLOCKSIZE * 2)
        throw new RuntimeException("Recorded less than BLOCKSIZE x 2 samples:"
                + bufferReadResult);

    // process the `signal` array here
}

audioRecord.stop();
audioRecord.release();
</code></pre>

<p>The audio source is set to "CAMCORDER" and it records in stereo. The idea is, if the phone has multiple microphones, the app will process data from both and use whichever has better SNR. But I have the same problems if recording mono from <code>AudioSource.MIC</code>. It reads audio data in a <code>while</code> loop, I am assuming that <code>audioRecord.read()</code> is a blocking call and will not let me read same data twice.</p>

<p>The recorded data looks OK – the record buffer contains 16-bit PCM samples for two channels. The loop just seems to be running at twice the speed as on real devices. Which leads me to think that maybe the emulator is using a higher sampling rate than the specified 44100Hz. If I query the sample rate with <code>audioRecord.getSampleRate()</code> it returns the correct value. </p>

<p>Also there are some interesting audio related messages in logcat while recording:</p>

<pre><code>07-13 12:22:02.282  1187  1531 D AudioFlinger: mixer(0xf44c0000) throttle end: throttle time(154)
(...)
07-13 12:22:02.373  1187  1817 E audio_hw_generic: Error opening input stream format 1, channel_mask 0010, sample_rate 16000
07-13 12:22:02.373  1187  3036 I AudioFlinger: AudioFlinger's thread 0xf3bc0000 ready to run
07-13 12:22:02.403  1187  3036 W AudioFlinger: RecordThread: buffer overflow
(...)
07-13 12:22:24.792  1187  3036 W AudioFlinger: RecordThread: buffer overflow
07-13 12:22:30.677  1187  3036 W AudioFlinger: RecordThread: buffer overflow
07-13 12:22:37.722  1187  3036 W AudioFlinger: RecordThread: buffer overflow
</code></pre>

<p>I'm using up-to-date Android Studio and Android SDK, and I have tried emulator images running API levels 21-24. My dev environment is Ubuntu 16.04</p>

<p>Has anybody experienced something similar? 
Am I doing something wrong in my recording loop? </p>
