Markdown Converter
Agent skill for markdown-converter
The Audio module provides a comprehensive FMOD-based 3D audio system enabling immersive sound experiences with spatial audio, dynamic sound loading, real-time audio parameter control, and multi-listener support for complex audio scenarios.
Sign in to like and favorite skills
Root Directory > Code > Engine > Audio
The Audio module provides a comprehensive FMOD-based 3D audio system enabling immersive sound experiences with spatial audio, dynamic sound loading, real-time audio parameter control, and multi-listener support for complex audio scenarios.
AudioSystem.hpp - Main audio system interface and managementsAudioSystemConfig config; AudioSystem* audioSystem = new AudioSystem(config); audioSystem->Startup(); // Basic audio usage SoundID soundId = audioSystem->CreateOrGetSound("Data/Audio/music.wav", eAudioSystemSoundDimension::Sound2D); SoundPlaybackID playbackId = audioSystem->StartSound(soundId, false, 1.0f, 0.0f, 1.0f, false); // 3D positioned sound SoundID sound3D = audioSystem->CreateOrGetSound("Data/Audio/effect.wav", eAudioSystemSoundDimension::Sound3D); Vec3 soundPosition(10.0f, 0.0f, 5.0f); SoundPlaybackID playback3D = audioSystem->StartSoundAt(sound3D, soundPosition, false, 10.0f);
class AudioSystem { // System lifecycle void Startup(); void Shutdown(); void BeginFrame(); void EndFrame(); // Sound loading and management SoundID CreateOrGetSound(String const& soundFilePath, eAudioSystemSoundDimension dimension); // 2D sound playback SoundPlaybackID StartSound(SoundID soundID, bool isLooped = false, float volume = 1.f, float balance = 0.f, float speed = 1.f, bool isPaused = false); // 3D spatial sound playback SoundPlaybackID StartSoundAt(SoundID soundID, Vec3 const& soundPosition, bool isLooped = false, float volume = 10.0f, float balance = 0.0f, float speed = 1.0f, bool isPaused = false); // Playback control void StopSound(SoundPlaybackID soundPlaybackID); void SetSoundPlaybackVolume(SoundPlaybackID soundPlaybackID, float volume); void SetSoundPlaybackBalance(SoundPlaybackID soundPlaybackID, float balance); void SetSoundPlaybackSpeed(SoundPlaybackID soundPlaybackID, float speed); void SetSoundPosition(SoundPlaybackID soundPlaybackID, const Vec3& soundPosition); bool IsPlaying(SoundPlaybackID soundPlaybackID); };
// Multi-listener support for complex audio scenarios void SetNumListeners(int numListeners) const; void UpdateListener(int listenerIndex, Vec3 const& listenerPosition, Vec3 const& listenerForward, Vec3 const& listenerUp) const;
enum class eAudioSystemSoundDimension : int8_t { Sound2D, // Traditional stereo/mono sounds Sound3D // Spatially positioned sounds with distance attenuation };
fmod.lib, fmodstudio.lib)ThirdParty/fmod/fmod.hppVec3)struct sAudioSystemConfig { // Currently minimal configuration // Future expansion: sample rates, buffer sizes, channel counts };
typedef size_t SoundID; typedef size_t SoundPlaybackID; size_t constexpr MISSING_SOUND_ID = static_cast<size_t>(-1); // Internal sound registry std::map<String, SoundID> m_registeredSoundIDs; std::vector<FMOD::Sound*> m_registeredSounds;
class AudioSystem { protected: FMOD::System* m_fmodSystem; // FMOD system instance std::map<String, SoundID> m_registeredSoundIDs; // Sound path to ID mapping std::vector<FMOD::Sound*> m_registeredSounds; // Loaded sound assets };
// Conversion between engine Vec3 and FMOD_VECTOR FMOD_VECTOR CastVec3ToFmodVec(Vec3 const& vectorToCast) const; FMOD_VECTOR CreateZeroVector() const;
// FMOD result validation with comprehensive error reporting void ValidateResult(FMOD_RESULT result);
A: FMOD supports a wide range of formats including WAV, MP3, OGG, FLAC, AIFF, and many others. Compressed formats are automatically decoded.
A: 3D sounds use FMOD's built-in spatial processing with distance attenuation, doppler effects, and listener orientation for realistic positional audio.
A: Yes, each
StartSound() call returns a unique SoundPlaybackID for independent control of multiple playback instances.
A: Use
StartSound() with isLooped = true. FMOD handles seamless looping for properly prepared audio files.
A: FMOD operations are internally thread-safe, but it's recommended to call audio functions from the main thread for consistency.
A: Future enhancements will include master volume controls and audio category management through FMOD Studio integration.
AudioSystem.cpp - Main audio system implementation with FMOD integrationAudioSystem.hpp - Public API declarations and type definitionsThe Audio module integrates with:
.wav and .mp3 loading from Run/Data/Audio/