Spatial Audio & Dynamic Head Tracking
Low-latency 3D binaural sound rendering and 6-DOF dynamic head tracking with Pixel Buds via
useSpatialAudio.
Overview
Section titled “Overview”Spatial Audio transforms stereo and multichannel audio into an immersive three-dimensional soundscape that remains anchored in physical space as the listener turns their head.
Starting with Android 13 and expanded in Android 17 (API 37), the Android audio framework exposes the android.media.Spatializer API. On Google Pixel 11 Pro, spatial rendering is hardware-accelerated directly inside the Tensor G6 low-power Audio DSP, minimizing CPU utilization and battery drain during extended listening sessions.
PixelKit exposes this capability via the useSpatialAudio hook.
import React from 'react';import { View, Text, Switch, Button } from 'react-native';import { useSpatialAudio } from '@pixelkit-labs/sdk';
export function SpatialAudioController() { const { isSupported, isAvailable, isEnabled, hasHeadTracker, headTrackingMode, immersiveAudioLevel, setSpatialAudioEnabled, setHeadTrackingEnabled, getHeadPose, } = useSpatialAudio();
return ( <View> <Text>Spatial Audio Supported: {isSupported ? 'Yes' : 'No'}</Text> <Text>Output Available: {isAvailable ? 'Yes' : 'No'}</Text> <Text>Head Tracker Connected: {hasHeadTracker ? 'Pixel Buds Detected' : 'None'}</Text> <Text>Tracking Mode: {headTrackingMode}</Text> <Text>Spatial Level: {immersiveAudioLevel}</Text>
<Switch value={isEnabled} onValueChange={(val) => setSpatialAudioEnabled(val)} />
{hasHeadTracker && ( <Button title="Log Current Head Pose" onPress={async () => { const pose = await getHeadPose(); console.log('Head Pose:', pose); }} /> )} </View> );}Spatial Audio Pipeline
Section titled “Spatial Audio Pipeline”1. Head-Related Transfer Function (HRTF)
Section titled “1. Head-Related Transfer Function (HRTF)”The Tensor G6 Audio DSP convolves spatialized audio streams with customized Head-Related Transfer Functions. Sound sources positioned behind or above the listener are shaped with pinna reflections and interaural time differences (ITD) and interaural level differences (ILD).
2. Dynamic Head Tracking with Pixel Buds
Section titled “2. Dynamic Head Tracking with Pixel Buds”When Pixel Buds Pro or Pixel Buds Pro 2 are connected via Bluetooth LE Audio or AAC, the earbud IMU streams rotational quaternions (pitch, yaw, roll) to the phone at 100 Hz. The Spatializer shifts the virtual speaker array in the opposite direction, creating the illusion of stationary virtual speakers in the room.
Head Tracking Modes
Section titled “Head Tracking Modes”| Mode | Description |
|---|---|
disabled |
Standard stereo or fixed binaural downmix without head tracking. |
relative_world |
Sounds remain anchored in physical space relative to the room. |
relative_device |
Sounds remain anchored relative to the orientation of the phone screen. |
Best Practices
Section titled “Best Practices”- Check Output Availability:
isAvailableevaluates whether the currently connected audio sink supports spatialization. Built-in phone speakers may support fixed spatial audio, whereas head tracking requires supported headphones. - Audio Track Attributes: Ensure sound playback instances specify
USAGE_MEDIAorUSAGE_GAMEand content typeCONTENT_TYPE_MUSICorCONTENT_TYPE_MOVIEfor the Android system to route through the Spatializer.