Skip to content

feat: add audio system using OpenAL - #33

Merged
AhmedSobhy01 merged 20 commits into
mainfrom
feat/audio-system
Apr 17, 2026
Merged

feat: add audio system using OpenAL#33
AhmedSobhy01 merged 20 commits into
mainfrom
feat/audio-system

Conversation

@LoayAhmed304

Copy link
Copy Markdown
Collaborator

New changes

  • Initialize the sound system once in application.cpp to be accessed by all states
  • Added SoundSystem that is updated in Play State every frame to update the sound listener and sources positions, and start any sounds that have onStart as true in the component json config.
  • Expose some on-demand functions to be used:
    • PlaySound, which plays a sound on demand given AudioBuffer instance
    • PlaySound2D, which plays a 2D sound. Typically used for menus, musics and some sound effects
    • isPlaying, which checks if a given source is currently playing
    • setMasterVolume, which sets the master volume of the world
    • stopSound, which stops a given source and detaches its buffer
    • stopAll, which stops all sounds and detaches all buffers

Typical use case would be in play state, to add the audio .wav files in assets/sounds and add them in your app.config, given the entity AudioComponent with the corresponding sound if needed, and for the on-demand functions, call startSound or startSound2D and give it the corresponding buffer from AssetLoader

TODOs

  • Remove the current reloading sound, since it'll be related more to the player/weapon logic in the future, but it's generally here as a showcase of integration.
  • Maybe support more audio files
  • Maybe add pauseSound but I don't have a use case for it so far.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AudioSourceComponent and asset-loading support for AudioBuffer sound assets via AssetLoader.
  • Integrates audio lifecycle into Application startup/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.

Comment thread .vscode/c_cpp_properties.json Outdated
Comment thread src/states/menu-state.hpp Outdated
Comment thread src/states/menu-state.hpp
Comment thread src/common/systems/audio-system.cpp
Comment thread src/common/audio/audio-buffer.hpp Outdated
Comment thread src/common/components/audio-source.hpp Outdated
Comment thread src/common/components/audio-source.hpp Outdated
AhmedSobhy01
AhmedSobhy01 previously approved these changes Apr 17, 2026

@OmarGamal10 OmarGamal10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it but didn't read the code

@AhmedSobhy01
AhmedSobhy01 merged commit a0903bd into main Apr 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants