Simulating small buffer sizes on Android emulator

I’ve recently tracked down an audio bug reported on an Android app, which was working fine, until I updated the Android SDK to 27 (think it was 25 before). There were some other changes, but the audio code has not been touched in quite a while, so it was a surprise when I got reports that certain devices (Samsung S7 running Android 8 and Pixel running Android 9) were behaving differently.

Once I managed to get hold of one of the offending devices, I found that (as suspected) the issue was due to some new low buffer sizes. Beforehand and on other devices I was getting buffer sizes of 4800, and now, at least on the Samsung, I am seeing 240. The code I wrote was based on the assumption that I was getting large buffer sizes :slight_smile:

Since the device in question belongs to my client, and I had to give it back before completing the fix, does anyone know if it’s at all possible to simulate low buffer sizes in the Android emulator? :iphone:

The device’s buffer size has always been device dependent. A buffer size of 240 frames, whilst on the low side, isn’t the lowest (Pixel devices usually have 192 frames and Nexus 9 has 128 frames). You shouldn’t make the assumption that it is fixed or above a certain size.

The “new low buffer size” is almost certainly because your app is (for some reason) now obtaining a low latency stream. These have lower buffer sizes for reduced latency.

If latency isn’t an issue you could just increase the buffer size to a large (say 20) multiple of the native buffer size (which can be obtained using AudioManager  |  Android Developers)

I’m afraid not. Or at least not without generating your own emulator image. You’re probably better off getting a real Android device for testing since the emulator doesn’t accurately simulate CPU bandwidth either. Pixel 1 has a native buffer size of 192, runs Android Q and shouldn’t break the bank as it’s a few years old now.

1 Like

Thanks Don, I was hoping you’d chime in here :slight_smile:

Ok, both good tips. I’ll grab a Pixel on eBay. Cheers!