Open In App

Introduction to Spatial Audio in Android 13

Last Updated : 07 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

You may have come across the term Spatial Audio, if you have been under the rock then spatial audio is a great enhancement for audio, and is already available in Apple devices for a long period now, and is pretty standard. Google is now taking the game ahead by introducing Spatial Audio in Android 13 onwards.

What is Spatial Audio Exactly

It’s a new kind of audio effect, on paper, by placing your customers at the center of the action, spatial audio creates an immersive audio experience that makes your content sound more authentic. In a movie, a car’s sound may appear to begin behind the viewer, advance, and then fade out into the distance. It is simpler to distinguish speakers while using a video chat because voices can be divided and positioned around the user. 

With headphones, the sound is “spatialized” to produce a surround-sound-like multi-speaker experience. Starting with Android 13, you can include spatial audio in your app if your content uses a supported audio format (API level 33).

GeekTip: Make sure the head tracking on the headset you’re using is compatible with your mobile device before testing spatial audio with head tracking on Android 13 or later.

Head Movement

The platform can change the spatialization of the audio based on the user’s head location when using supported headphones. Call isHeadTrackerAvailable to see if a head tracker is available for the current audio output routing.

How to check if Spatial Audio capability is present?

You might want to check if the device the user is having supports Spatial Audio at all or not because otherwise there would be no use in giving that rich sound, as they won’t be able to experience it, for that Android gives us ways to check, the device’s spatialization capabilities and behavior can be questioned using the Spatializer class. 

We need to call the methods in this order:

Java




Spatializer gfgSpatialAudioTutorial = AudioManager.getSpatializer();


This will return three different types of responses, refer to the table below to identify them and then work accordingly:

Code

Description

behaviorgetImmersiveAudioLevel() Can the device play spatial audio/ is the hardware supported?
getImmersiveAudioLevel() Is spatial audio available on the device?
canBeSpatialized() Does the audio file which has to be played, can be used for Spatial Audio?

How to cancel the Spatial Audio Channels?

Call setIsContentSpatialized(true) to signal that your content has already been spatialized to avoid double-processing the audio. This method may not always work for you so you can modify the spatialization behavior by executing setSpatializationBehavior(AudioAttributes.SPATIALIZATION BEHAVIOR NEVER) to completely turn off spatialization.

Understanding the constraints while playing Spatial Audio

ExoPlayer selects a multi-channel audio track when all three requirements for spatial audio are satisfied. In that case, ExoPlayer selects a stereo track. ExoPlayer will initiate a fresh track selection to choose an audio track that corresponds to the new Spatializer properties if the Spatializer properties change. Be aware that this new track choice can result in a brief rebuffering period. To disable this channeling you can add this line:

Java




// Using the ExoPlayer Class
// Geeks for Geeks
gfgPlayer.setTrackSelectionParameters(
    new DefaultTrackSelector.Parameters.Builder(gfgContext)
        .setConstrainAudioChannelCountToDeviceCapabilities(
            true)
        .build());


GeekTip: You can use a player like Exo, which chooses the audio track with the most channels and playback compatibility at first when the material includes multiple audio tracks and audio channel count limitations are removed.

How Does Spatial Audio work by Default?

The following actions are part of Android’s standard spatialization behavior and can be changed by OEMs:

  1. Stereo content is not spatialized; only multi-channel content is. 
  2. Depending on the format of your multi-channel audio files, you might need to set the maximum number of channels that an audio decoder can output to a high number if you don’t utilize ExoPlayer. 
  3. If the user is set to either USAGE_MEDIA or USAGE_GAME, audio is suitable for spatialization.

Conclusion

This is what an introduction to Spatial Audio seems like, hope this article helped you get a basic idea of what Spatial Audio is all about, and also how to enable new experiences for your users so that they feel that they are right at the center of the content consumption. The user’s understanding of the spatialized sound stage that is being reproduced around their head is aided by head tracking. By enabling spatial audio processing at the lowest level in the audio pipeline to achieve the lowest latency, Android 13 optimizes spatial audio and head tracking.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads