Search code examples
javaandroidperformanceaudioandroid-audiorecord

Playing sound on Android with SoundPool while Recording microphone with AudioRecord


I'm using AudioRecord to record mic data while at the same time playing sounds with SoundPool. My problem is: When I call startRecording() on the AudioRecord, the SoundPool becomes choppy or stops completely. When I call stopRecording() all the cued sounds come in at once. Is there a better library I should use? I've noticed the Buttons in the app are still responsive and are still able to play their default sounds.

SoundPool stops playing sounds even when the thread that called AudioRecord.startRecording() has finished. It doesn't play sounds again until I call AudioRecord.stopRecording(). I'd like to do both at once. Seeing as the sounds I'm playing are short sounds, I thought SoundPool was the correct class to use. If someone knows how the Android UI Button class plays its sounds I could copy that and it should work.

This is in the emulator with the latest Android Studio 1.0.2

Edit: MediaPlayer is worse, it fails after calling AudioRecord.startRecording() and it has much more latency than SoundPool (when not recording at the same time.) I know SoundPool.play() was being called regularly because of Log statements.


Solution

  • It's just the emulator. It works on a physical Android device.