aether-audio
Spatial audio with HRTF, Opus codec, and acoustic zones
The aether-audio crate provides spatial audio rendering, head-related transfer function (HRTF) processing, Opus codec integration, acoustic zone simulation, voice channel management, and audio capture for the Aether engine.
Overview
Audio in Aether is fully spatialized by default. Every audio source has a 3D position, and the listener's head orientation drives HRTF filtering to produce convincing directional sound. The system supports:
- HRTF-based spatialization for accurate 3D audio positioning in VR.
- Opus codec for low-latency voice encoding and decoding.
- Acoustic zones that model room reverb, occlusion, and material absorption.
- Attenuation models with configurable distance curves.
- Voice channel management for proximity chat, private channels, and zone-based routing.
- Audio capture from microphone input with ring-buffer streaming.
Key Types
AudioRuntime
The central audio processing runtime. Drives the mix pipeline each tick, combining spatial sources, voice streams, and ambient audio.
use aether_audio::{AudioRuntime, AudioRuntimeConfig};
let config = AudioRuntimeConfig {
sample_rate: 48000,
buffer_size: 960,
max_sources: 128,
};
let runtime = AudioRuntime::new(config);
AudioSource
Represents a positioned sound emitter in the world. Sources are attached to entities via the ECS.
use aether_audio::{AudioSource, AudioId, AudioLod, Vec3};
let source = AudioSource {
id: AudioId::new(42),
position: Vec3 { x: 10.0, y: 1.5, z: -3.0 },
lod: AudioLod::Full,
volume: 0.8,
looping: true,
};
HrtfProfile
Defines the HRTF dataset used for spatial filtering. Different profiles model different head shapes for more accurate localization.
use aether_audio::{HrtfProfile, HrtfSample};
let profile = HrtfProfile::default();
AttenuationModel
Controls how sound volume decreases with distance. Supports linear, inverse, and exponential curves with configurable distance bands.
use aether_audio::{AttenuationModel, AttenuationCurve, DistanceBand};
let model = AttenuationModel {
curve: AttenuationCurve::InverseSquare,
bands: vec![
DistanceBand { min: 0.0, max: 5.0, gain: 1.0 },
DistanceBand { min: 5.0, max: 50.0, gain: 0.5 },
],
max_distance: 100.0,
};
VoiceChannelManager
Manages voice chat channels with routing policies. Supports proximity-based channels, private group channels, and world-wide broadcast.
use aether_audio::{VoiceChannelManager, ChannelConfig, ChannelKind};
let mut manager = VoiceChannelManager::new();
manager.create_channel(ChannelConfig {
kind: ChannelKind::Proximity,
max_participants: 20,
radius: 15.0,
});
RoomAcoustics
Models the acoustic properties of an environment, including reverb, early reflections, and occlusion.
use aether_audio::{RoomAcoustics, AcousticsProfile, OcclusionState};
let room = RoomAcoustics {
profile: AcousticsProfile {
reverb_time: 1.2,
room_size: 50.0,
dampening: 0.4,
},
occlusion: OcclusionState::Partial(0.6),
};
CaptureStream
Manages microphone input, buffering audio frames for voice transmission.
use aether_audio::{CaptureStream, CaptureConfig};
let config = CaptureConfig {
sample_rate: 48000,
channels: 1,
buffer_frames: 4,
};
let capture = CaptureStream::new(config);
Usage Examples
Spatial Audio Setup
use aether_audio::{
AudioRuntime, AudioRuntimeConfig, SpatialRenderer,
ListenerState, Vec3,
};
let runtime = AudioRuntime::new(AudioRuntimeConfig::default());
let listener = ListenerState {
position: Vec3 { x: 0.0, y: 1.7, z: 0.0 },
forward: Vec3 { x: 0.0, y: 0.0, z: -1.0 },
up: Vec3 { x: 0.0, y: 1.0, z: 0.0 },
};
Opus Voice Encoding
use aether_audio::{OpusConfig, BitRateKbps};
let opus_config = OpusConfig {
bitrate: BitRateKbps(24),
frame_size_ms: 20,
complexity: 5,
};