Audio Architecture
The audio subsystem consists of multiple layers that work together to deliver game audio:Cubeb Audio Backend
Cubeb is a cross-platform audio library that provides low-latency audio output across different operating systems.Cross-Platform
Works on macOS, Linux, and Windows
Low Latency
Minimal delay between audio generation and playback
Async Processing
Audio processing runs on dedicated threads
Multiple Formats
Supports various sample rates and channel configurations
Why Cubeb?
Cubeb was chosen for its excellent macOS support, low latency characteristics, and proven track record in emulation projects like Firefox and other emulators.
Audio Services
Hydra implements the Nintendo Switch’s audio service interfaces:Audio Renderer (audren)
The audio renderer service handles complex audio operations including:Voice Management
Voice Management
The audio renderer manages multiple audio voices (sound sources) with individual properties:Each voice can have:
src/core/horizon/services/audio/audio_renderer.cpp
- Custom sample rate and format
- Volume and pitch control
- Biquad filters for audio effects
- Multiple wave buffers for streaming
Audio Mixing
Audio Mixing
Multiple audio sources are mixed together:
- Per-voice volume control
- Channel mixing and routing
- Effect processing
- Final master mix output
Effects Processing
Effects Processing
The renderer supports various audio effects:Effects include:
- Reverb
- Delay
- Biquad filtering (EQ, lowpass, highpass)
Memory Pools
Memory Pools
Audio data is managed through memory pools:This allows efficient management of audio sample data.
Audio Output (audout)
The audio output service provides simpler PCM audio output:Most games use the audio renderer service for its advanced features, while simpler applications may use audio output directly.
Audio Formats
Hydra supports multiple PCM audio formats:- PCM16
- PCM32
- Float
16-bit signed integer samples
- Most common format
- Good balance of quality and performance
- Native format for many games
Wave Buffers
Audio data is streamed through wave buffers:Streaming Playback
Streaming Playback
Games queue multiple wave buffers for continuous playback:
- Up to 4 wave buffers per voice
- Automatic progression through buffers
- Seamless looping support
Loop Support
Loop Support
Wave buffers can loop automatically:Perfect for background music and ambient sounds.
Audio Processing Thread
The audio renderer runs on a dedicated thread to ensure consistent timing:src/core/horizon/services/audio/audio_renderer.cpp
Performance Monitoring
The audio system tracks performance metrics:Audio Quality Settings
While Hydra aims for accurate audio emulation, there are some considerations:Sample Rate
Nintendo Switch games typically use 48kHz audio, which is passed through to the host system
Channel Count
Supports mono, stereo, and surround sound configurations
Buffer Size
Larger buffers reduce stuttering but increase latency
Threading
Dedicated audio threads prevent interference from emulation hiccups
Latency Considerations
Total latency is typically 10-20ms, which is imperceptible for most gaming scenarios.
Configuration
The audio backend can be configured in the settings:- Cubeb
- Null
Full audio emulation with the Cubeb backend
- Recommended for normal gameplay
- Low latency
- High quality
Troubleshooting
No Audio Output
No Audio Output
If you don’t hear any audio:
- Check that
audio_backendis set toCubebin config - Verify macOS audio output is working
- Check the game’s audio settings
- Try restarting the emulator
Audio Crackling
Audio Crackling
If audio crackles or stutters:
- System may be under heavy load
- Try closing other applications
- Check CPU usage
- Some games may have audio timing issues
Audio Delay
Audio Delay
If audio is delayed:
- This is usually imperceptible (10-20ms)
- Cannot be reduced below system audio latency
- Check macOS audio settings for buffer size