Navigate back to the homepage

Android Emulators vs Bluetooth Headphones

Matt McKenna
December 17th, 2021 · 2 min read

This article is featured in Android Weekly 497

Why is my audio quality bad?

I’ve been using Android Emulators since I started developing for Android in 2012. Sometimes using an Emulator makes my audio quality really bad. I hate when this happens. Here’s everything I know about keeping your audio from sounding like you connected your headphones to a coffee grinder.

The decline in audio quality happens whenever an app engages the microphone on your headphones. This is because Bluetooth has limited bandwidth. Bluetooth headphones use two different audio codecs for different situations. They can either deliver:

  1. High quality audio output.
  2. Low quality audio input and output.

Using a single, high quality codec would lead to a choppy audio experience. Bluetooth’s bandwidth is not large enough to support it.

Your emulator might be gaining microphone access causing your headphones to use the low quality codec!

Here’s how to stop it.


Solutions

Remove the Audio Permission from Android Studio

MacOS has evolved to have granular permissions. Access these settings from the Security & Privacy section of Preferences.

  1. To open these settings go to the Apple () logo in the upper left and select System Preferences.

    image.png

  2. Click on Security & Privacy.

  3. Scroll down to Microphone on the left.

  4. Uncheck Android Studio.

image.png

Now Android Studio can no longer request access to your microphone at the OS level. If your audio quality is still poor ensure other apps aren’t using your microphone on your Bluetooth headphones.


Disable Audio Capabilities in the Emulator

This solution is a bit more hands on, but if you are still having trouble this WILL work.

  1. Navigate to your Emulator’s config file. Find this file at:
  • /Users/<Your Name>/.android/avd/<Emulator Name>
  • Be sure to navigate here with your name and the name of the emulator you want to change.
  1. In this folder you will find a config.ini file. Open this and it will look something like:
1AvdId = Pixel_4_API_30
2PlayStore.enabled = true
3abi.type = x86
4avd.ini.displayname = Pixel 4 API 30
5avd.ini.encoding = UTF-8
6disk.dataPartition.size = 6442450944
7fastboot.chosenSnapshotFile =
8fastboot.forceChosenSnapshotBoot = no
9fastboot.forceColdBoot = no
10fastboot.forceFastBoot = yes
11hw.accelerometer = yes
12hw.arc = false
13hw.audioInput = yes
14hw.battery = yes
15...
  1. Find the hardware audio input and output configurations:
1hw.audioInput = yes
2hw.audioOutput = yes
  1. Change yes to no to disable it.
1hw.audioInput = no
2hw.audioOutput = no
  1. As a final step you will need to Wipe Data and Cold Boot Now from the Android Virtual Device Manager.

    ⚠️ Note: You will need to do this for each emulator that you have.


Launch From Command Line with --noaudio

This fix requires use of the command line and using the emulator command.

Google has good documentation on how to use this emulator command if you are not familiar with it.

1emulator -avd Nexus_5X_API_23 -noaudio

or

1emulator @Nexus_5X_API_23 -noaudio

This isn’t ideal for me. I usually like to start my Emulators from with Android Studio.


Override the QEMU_AUDIO_DRV Environment Variable

On a Mac or linux machine open up your shell config file (.bashrc, .zshrc, or other). Set the environment variable: QEMU_AUDIO_DRV to none.

1export QEMU_AUDIO_DRV=none

This will disable the audio backend for Emulators completely!

If you know how to set environment variables on Windows please let me know!

Note: There are other audio backends available to try:

  • alsa: Use the Advanced Linux Sound Architecture (ALSA) backend
  • esd: Use the Enlightened Sound Daemon (EsounD) backend
  • sdl: Use the Simple DirectMedia Layer (SDL) audio backend (no audio input supported)
  • oss: Use the Open Sound System (OSS) backend
  • none: Do not support audio

Let me know how this works for you!

For more Android tips and tricks find me on Twitter.

Hey! We've got a newsletter!

Your weekly dose of bite sized Android news and events delivered Monday mornings to kick off your week.

Each issue contains TL;DRs of recent articles, a developer tool highlight, interview practice, and a stoic sentiment applied to tech careers.

All with a No-Spam Guarantee.

Read more about it here!

More articles from StoicallyTyped

Learning Live Templates for Jetpack Compose

What are Live Templates? How can they speed up your development? And how to create your own for Jetpack Compose!

April 20th, 2021 · 6 min read

Adding comments via Utteranc.es

GitHub Issue powered comments are now available on all posts!

March 22nd, 2021 · 1 min read
© 2020–2021 StoicallyTyped
Link to $https://twitter.com/himattmLink to $https://github.com/himattmLink to $https://instagram.com/himattmLink to $https://unsplash.com/@mmckennaLink to $https://medium.com/@himattm