A demonstration Android application showcasing spatial audio capabilities and head tracking using Android's Spatializer API. This app helps developers understand and test spatial audio features on compatible Android devices.
- Spatial Audio Detection: Automatically detects device capabilities for spatial audio
- Head Tracking: Demonstrates head tracking integration with spatial audio
- 5.1 Surround Sound Test: Plays multi-channel test tones with different frequencies per channel:
- Front Left: 440Hz (A4)
- Front Right: 554Hz (C#5)
- Center: 330Hz (E4)
- LFE: 80Hz (Low Frequency Effects)
- Rear Left: 660Hz (E5)
- Rear Right: 880Hz (A5)
- Real-time Status Display: Shows spatializer status, head tracker availability, and playback information
- Material Design 3: Modern UI with dynamic color support
- Android Version: Android 13 (API level 33) or higher
- Kotlin: 1.9.22 or higher
- Gradle: 8.3.0 or higher
- Android Gradle Plugin: 8.3.0 or higher
For full functionality, your device should support:
- Spatial audio (Spatializer API)
- Head tracking sensors
- Multi-channel audio output (headphones/speakers)
- Devices with built-in head tracking (e.g., newer Pixel devices)
- Headphones with head tracking support
- Bluetooth headphones with spatial audio capabilities
- Install Android Studio (latest stable version recommended)
- Ensure you have JDK 11 or higher installed
- An Android device or emulator running Android 13+
- Clone the repository:
git clone https://github.com/3130585774/SpatialAudio-HeadTracker-Test.git
cd SpatialAudio-HeadTracker-Test-
Open the project in Android Studio:
- Launch Android Studio
- Select "Open an Existing Project"
- Navigate to the cloned directory and select it
-
Sync Gradle:
- Android Studio should automatically sync Gradle files
- If not, click "Sync Project with Gradle Files" in the toolbar
-
Build the project:
- Select "Build" → "Make Project" from the menu
- Wait for the build to complete
-
On a Physical Device (Recommended for testing spatial audio):
- Enable Developer Options and USB debugging on your device
- Connect your device via USB
- Click the "Run" button in Android Studio
- Select your device from the list
-
On an Emulator:
- Create an AVD (Android Virtual Device) with API 33+
- Launch the emulator
- Click the "Run" button and select the emulator
- Note: Emulators have limited spatial audio support
-
Launch the App: Open the Headtracker Test app on your device
-
Check Device Status:
- The app displays your device's spatial audio capabilities
- Green checkmarks (✅) indicate supported features
- Red crosses (❌) or warnings (
⚠️ ) indicate limitations
-
Play Test Audio:
- Tap the "Play Test Audio" button to start playback
- If head tracking is available, move your head to experience spatial effects
- Each speaker in the 5.1 setup plays a distinct frequency for easy identification
-
Monitor Playback:
- The "Playback Status" card shows whether audio is spatialized
- "Head Tracker Data" updates during playback if available
-
Stop Playback:
- Tap the "Stop" button to end playback
app/
├── src/main/
│ ├── java/com/example/headtrackertest/
│ │ ├── MainActivity.kt # Main activity and UI
│ │ └── ui/theme/ # Material3 theme configuration
│ ├── res/
│ │ ├── values/
│ │ │ ├── strings.xml # String resources
│ │ │ ├── colors.xml # Color definitions
│ │ │ └── themes.xml # Theme definitions
│ │ └── mipmap/ # App icons
│ └── AndroidManifest.xml # App configuration
└── build.gradle.kts # App-level build configuration
The main entry point that initializes the Spatializer and sets up the Compose UI.
The main UI component that displays:
- Device spatial audio capabilities
- Head tracker status
- Playback controls
- Real-time feedback
Handles audio generation and playback:
- Configures AudioTrack for spatial audio
- Generates multi-channel test tones
- Manages audio lifecycle and cleanup
The app uses the following audio configuration:
- Sample Rate: 48kHz
- Encoding: PCM 16-bit
- Channel Mask: 5.1 surround (6 channels)
- Usage: Media
- Content Type: Music
- Spatialization Behavior: Auto
Head tracking data is monitored through the Spatializer API. When available and enabled:
- The app indicates active head tracking
- Audio spatially responds to head movements
- Status updates every 100ms during playback
- Cause: Your device's hardware doesn't support spatial audio
- Solution: Try on a device with spatial audio support
- Cause: Current audio route (speaker/headphones) doesn't support spatialization
- Solution: Try different headphones or audio output devices
- Cause: Spatial audio is disabled in system settings
- Solution: Enable spatial audio in Settings → Sound → Spatial audio
- Cause: Device or headphones don't support head tracking
- Solution: Use compatible hardware with head tracking sensors
- Gradle sync failed: Ensure you have a stable internet connection for dependency download
- SDK not found: Install required Android SDK platforms through SDK Manager
- Kotlin version mismatch: Sync Gradle files to download the correct Kotlin version
- Android Spatial Audio Developer Guide
- Spatializer API Documentation
- AudioTrack Documentation
- Material Design 3
This project is licensed under the terms specified in the LICENSE file.
Contributions are welcome! Please feel free to submit issues or pull requests.
- Follow Kotlin coding conventions
- Add KDoc comments for public APIs
- Test on devices with and without spatial audio support
- Maintain Material Design 3 design principles
- Initial release
- Spatial audio detection and testing
- Head tracking integration
- 5.1 surround sound test tone generation
- Material Design 3 UI
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Review Android Spatial Audio documentation
- Open an issue on GitHub with:
- Device model and Android version
- Steps to reproduce the issue
- Screenshots if applicable
This project demonstrates the use of Android's modern audio APIs and serves as a learning resource for developers interested in spatial audio and head tracking technologies.