refactor(core): overhaul audio engine and device architecture #72
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces a major architectural refactoring to move away from a singleton-based (
AudioEngine.Instance) model to a device-centric, instance-based architecture. This fundamental change enables true multi-device input and output, allowing applications to manage and switch between multiple playback and capture devices simultaneously and independently.This refactor also includes several new features, performance improvements, and critical bug fixes that are built upon the new architecture.
Key Changes & Features
AudioEngine.InstanceandMixer.Masterhave been removed. The new design introducesAudioPlaybackDevice,AudioCaptureDevice, andFullDuplexDeviceabstractions, each managing its own audio graph andMasterMixer.AudioEngineandAudioFormatcontext via their constructors, removing implicit dependencies on global state.Engine.SwitchDevice()API allows for seamless hot-swapping of active audio devices while preserving their state (e.g., attached components or event subscribers).VoiceIsolationEffect: Adds an experimental modifier that acts as a band-pass filter to help isolate human speech frequencies.MultiEnginesSample: A new sample project is included to demonstrate and test the new multi-device capabilities.Fixes & Performance Improvements
NetworkDataProviderto use a chunked streaming and decoding model, resolving excessive memory usage. Memory consumption for a 15-minute audio file is reduced from ~1GB to ~20MB.MathHelperfor Scalar, SSE, and AVX paths to ensure consistent behavior. The SIMD paths are now toggleable via static properties for easier debugging.BREAKING CHANGE: This is a fundamental architectural change that affects the entire public API.
AudioEngine.Instanceis removed. AnAudioEnginemust now be instantiated (e.g.,new MiniAudioEngine()).Mixer.Master. Users must first initialize a device (e.g.,engine.InitializePlaybackDevice(...)) and then add components to the device'sMasterMixer.SoundComponent,ISoundDataProvider,SoundModifier, andAudioAnalyzerderivatives have changed. They now require anAudioEngineand/orAudioFormatinstance to be passed in.AudioEngine.OnAudioProcessedevent is removed. Events for processed audio are now available on a per-device basis (e.g.,AudioCaptureDevice.OnAudioProcessed).SwitchDeviceAPI is replaced with new, more explicit methods on theAudioEngineinstance that return a new device object.