Audio Engine System
A downloadable tool
What it is
This engine system let's you load WAV files into your engine and play them!
Written using XAudio2 for Windows 10.
Project Structure and Dependencies
Your download will have two projects: 3DAudio (ignore the name) and AudioBuilder.
AudioBuilder will go wherever your asset building projects go.
3DAudio goes into your Engine folder.
Don't forget to add your build dependencies!
BuildMyGameAssets:
You'll also need to add this code in your AssetBuildLibrary project.
AssetBuildFunctions.lua
NewAssetTypeInfo( "audiosources", { ConvertSourceRelativePathToBuiltRelativePath = function( i_sourceRelativePath ) local relativeDirectory, file = i_sourceRelativePath:match( "(.-)([^/\\]+)$" ) local fileName, extensionWithPeriod = file:match( "([^%.]+)(.*)" ) return relativeDirectory .. fileName .. extensionWithPeriod end, GetBuilderRelativePath = function() return "AudioBuilder.exe" end } )
Building Assets
(yes, I switched some things around)
AssetsToBuild.lua
audiosources = { { path = "Audio/myfile.wav" }, { path = "Audio/heylookanotherfile.wav" }, { path = "Audio/wooo.wav" } }
Initialize the Audio Engine
- Head to cbApplication.cpp in the Application project.
- Look for the Initialize_engine() function.
- Add this code:
// Audio! { Audio3D::sInitializationParameters initParams; // you don't need to populate them. It's just a placeholder for future updates. if (!(result = Audio3D::Initialize(initParams))) { EAE6320_ASSERTF(false, "Application can't be initialized without Audio"); return result; } }
Load your Audio File
Get yourself an Audio Source:
eae6320::Audio3D::AudioSource *MySource;
Load a file into it:
auto result = eae6320::Audio3D::AudioSource::Load("data/audio/myfile.wav", MySource);
Of course, you can check your return value to see if you were able to successfully load your file.
Supported formats
Only WAV files are supported at the moment.
MP3 files can be added if demand is high but also compressed audio is disgusting.
Jk if you guys really want MP3 just ping me and I'll support it.
Play your source
Feast your ears!!
Play once, without looping (great for SFX):
auto result = MySource->PlayOnce();
Play looped (great for BGM):
auto result = MySource->PlayLooped();
Pause:
auto result = MySource->Pause();
Stop:
auto result = MySource->Reset();
Check if your source is still playing:
bool IsStillBopping = MySource->IsPlaying();
Clean Up
auto result = MySource->CleanUp(); MySource = nullptr;
Aaaand then you're done!
Concepts I Used
1. Platform-independent interfaces with platform-specific code.
I had to make sure that the interface our "gameplay programmers" would use has no mention of XAudio2 or Windows in it. I wrote all my platform-specific code in separate .cpp files. Nothing too complicated here.
2. Building Assets
I fought with Lua files and Binary files for quite a bit. In the end, I decided to scrap most of that in favor of simplicity, but I did use the concept of having an "Asset Builder" that'll build our .wav files over to the output directory. Useful stuff.
Things I learned
1. XAudio2
Woo boy this was so fun. Low-level audio <3
I learned a lot about how the audio pipeline works. Most of this was in reading, because I decided to optimize this system for ease-of-use over power.
2. Building really simple interfaces
My main focus for this project was to learn to think from the perspective of the user of my code. I've never really written code that other people might use without my supervision so there was a lot of thought put into make this interface incredibly intuitive and simple.
Status | Released |
Category | Tool |
Author | TheDarkMiko |
Leave a comment
Log in with itch.io to leave a comment.