Sunday, October 15, 2023
HomeMobileDelivering an immersive sound expertise with Spatial Audio

Delivering an immersive sound expertise with Spatial Audio



Posted by Nevin Mital – Developer Relations Engineer, Android Media

In Android 13 (API degree 33), we launched a brand new standardized platform structure for spatial audio, a premium and extra partaking sound expertise. With spatial audio, your content material sounds extra sensible to customers by making it sound as if they’re in the midst of the motion. The person devices from a band might be separated and “positioned” across the consumer, or the sound from a whale would possibly develop because it approaches from behind and taper off because it swims away. Learn on to be taught extra about Android’s help for spatial audio and the best way to implement the function in your app.

Spatial audio on Android

There are two fundamental distinctions of spatial audio:

  • With static spatial audio, the sounds are anchored to the consumer and transfer with them. A fowl chirping to their left will all the time be on their left, regardless of how they flip or transfer their head.
  • With spatial audio with head monitoring, the sounds are positioned within the atmosphere across the consumer. By turning their head to the left, the consumer will now hear the fowl chirping in entrance of them.
ALT TEXT

On Android, solely multi-channel audio configured with the suitable AudioAttributes and AudioFormat is spatialized by default, although OEMs can customise this habits. On gadgets the place the OEM has built-in a spatializer impact, static spatial audio will work when any headset is linked to the machine, although head-tracked spatial audio requires a headset with suitable head monitoring sensors. OEMs like Pixel, OnePlus, and Xiaomi have already made these experiences obtainable to their customers.

Implementing & testing spatial audio

The simplest solution to combine with this function is to make use of ExoPlayer! Should you use ExoPlayer from Jetpack Media3 launch 1.0.0 or newer, ExoPlayer will configure the decoder to forestall multi-channel audio from being downmixed to stereo and the default observe choice habits will take note of whether or not or not spatialization is feasible. This implies your content material simply wants to incorporate a multi-channel audio observe that ExoPlayer can choose. ExoPlayer will monitor the machine’s state and choose a multi-channel observe when spatialization is feasible, or change to a stereo observe if not.

Android 12L (API degree 32) added the brand new Spatializer class to assist you to question the spatialization capabilities of the machine. There are 4 situations that should all be true for the machine to output spatialized audio:


val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
val spatializer = audioManager.spatializer

if (

spatializer.immersiveAudioLevel != Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE

&& spatializer.isEnabled

&& spatializer.isAvailable

&& spatializer.canBeSpatialized(audioAttributes, audioFormat)
) {

} else {

}

ExoPlayer performs these checks when deciding which audio observe to pick. To additional verify if head monitoring is on the market, you possibly can name the isHeadTrackerAvailable() technique. The Spatializer class additionally contains the next listeners to have the ability to react to modifications within the machine’s state:

OnSpatializerStateChangedListener

For modifications in whether or not the spatializer is enabled or obtainable.

OnHeadTrackerAvailableListener

For modifications in whether or not head monitoring is on the market.

With these indicators, you possibly can manually regulate your playback for spatial audio. Word that if you’re not utilizing ExoPlayer, it is best to make sure that to configure the decoder to output multi-channel audio when attainable by setting the max channel depend to a big quantity with MediaFormat.setInteger(MediaFormat.KEY_MAX_OUTPUT_CHANNEL_COUNT, ##). See how ExoPlayer does this on GitHub. There are two methods to forestall spatialization relying in your use-case. In case your audio is already spatialized, name setIsContentSpatialized(true) when configuring the AudioAttributes on your audio stream to forestall the audio from being double-processed. In all different circumstances, you possibly can as a substitute name setSpatializationBehavior(AudioAttributes.SPATIALIZATION_BEHAVIOR_NEVER) to disable spatialization altogether.

As talked about beforehand, utilizing spatial audio requires a supported machine (that’s, getImmersiveAudioLevel() does not return SPATIALIZER_IMMERSIVE_LEVEL_NONE) and a linked headset. To check spatial audio, begin by ensuring the function is enabled in settings:

  • For wired headsets, go to System settings > Sound & vibration > Spatial audio.
  • For wi-fi headsets, go to System settings > Linked gadgets > Gear icon on your wi-fi machine > Spatial audio.

Word that for spatial audio with head monitoring, the headset should have head monitoring sensors which are suitable with the machine, comparable to Pixel Buds Professional with a Pixel telephone, and head monitoring should even be enabled in settings.

Subsequent steps

Listening to is believing, so we extremely advocate attempting out spatial audio for your self! You’ll be able to see an instance implementation in our pattern app, Common Android Music Participant. And for extra particulars on all the pieces mentioned right here, take a look at our spatial audio developer information.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments