feat: add audio system using OpenAL - #33
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an OpenAL-based audio subsystem to the engine, integrates it with ECS-driven gameplay (listener + spatial sources), and wires basic UI/gameplay sound playback through app-level initialization.
Changes:
- Introduces
AudioSystem(OpenAL device/context + pooled sources) with ECS update + on-demand playback APIs. - Adds an
AudioSourceComponentand asset-loading support forAudioBuffersound assets viaAssetLoader. - Integrates audio lifecycle into
Applicationstartup/shutdown and into Menu/Play states; adds example sound config/assets.
Reviewed changes
Copilot reviewed 17 out of 26 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/states/play-state.hpp | Updates audio system each frame; adds a reload SFX trigger; stops audio on exit. |
| src/states/menu-state.hpp | Adds menu music + hover SFX playback integration. |
| src/common/systems/audio-system.hpp | Declares OpenAL-backed audio system and on-demand APIs. |
| src/common/systems/audio-system.cpp | Implements device/context init, listener/source updates, and playback helpers. |
| src/common/components/component-deserializer.hpp | Registers AudioSourceComponent for scene deserialization. |
| src/common/components/audio-source.hpp | New ECS component for spatial/non-spatial sound configuration. |
| src/common/components/audio-source.cpp | Deserializes AudioSourceComponent from JSON. |
| src/common/audio/audio-utils.hpp | Declares WAV loading helper. |
| src/common/audio/audio-utils.cpp | Implements WAV decode (dr_wav) and uploads PCM to OpenAL buffer. |
| src/common/audio/audio-buffer.hpp | Defines an OpenAL buffer wrapper (AudioBuffer). |
| src/common/asset-loader.cpp | Adds AssetLoader<AudioBuffer> specialization + loads "sounds" from config. |
| src/common/application.hpp | Stores AudioSystem in the app and exposes getAudioSystem(). |
| src/common/application.cpp | Initializes/destroys the audio system in the app lifecycle. |
| config/custom-configs/sound.jsonc | Adds a sample config demonstrating sound assets + AudioSource usage. |
| assets/sounds/menu-select.wav | Adds menu hover SFX asset. |
| assets/sounds/gun_shot.wav | Adds gunshot asset. |
| CMakeLists.txt | Adds OpenAL-Soft submodule build + links OpenAL. |
| .vscode/c_cpp_properties.json | Updates VSCode IntelliSense configuration. |
| .gitmodules | Adds vendor/openal-soft submodule entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
AhmedSobhy01
previously approved these changes
Apr 17, 2026
OmarGamal10
approved these changes
Apr 17, 2026
OmarGamal10
left a comment
Collaborator
There was a problem hiding this comment.
I tried it but didn't read the code
AhmedSobhy01
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
New changes
application.cppto be accessed by all statesSoundSystemthat is updated in Play State every frame to update the sound listener and sources positions, and start any sounds that haveonStartas true in the componentjsonconfig.PlaySound, which plays a sound on demand givenAudioBufferinstancePlaySound2D, which plays a 2D sound. Typically used for menus, musics and some sound effectsisPlaying, which checks if a given source is currently playingsetMasterVolume, which sets the master volume of the worldstopSound, which stops a given source and detaches its bufferstopAll, which stops all sounds and detaches all buffersTypical use case would be in play state, to add the audio
.wavfiles inassets/soundsand add them in yourapp.config, given the entityAudioComponentwith the corresponding sound if needed, and for the on-demand functions, callstartSoundorstartSound2Dand give it the corresponding buffer fromAssetLoaderTODOs
pauseSoundbut I don't have a use case for it so far.