azurite-engine / Azurite

Azurite Game Engine is a 2D Java game engine built on top of LWJGL.
https://azurite-engine.github.io
MIT License
42 stars 20 forks source link

Audio Driver using OpenAL #48

Closed HilbertCurve closed 2 years ago

HilbertCurve commented 3 years ago

In this PR, I coded up an audio driver using OpenAL. The audio driver is split into four main parts:

  1. Audio Buffer: Using buffer utils, I pull the audio data from the assets folder and store it in an array. This data is then to be used by an audio source.
  2. Audio Source: This class is a Component; it's a point in 3D space (or 2D for our case) where noise can come from. It also has this neat property where, if you set the AL_VELOCITY property using alSourcef(), OpenAL can apply the Doppler Effect to the outputted noise, in case we want to use that. We would attach this to a gameObject first to enable properties like it's position (this is easy to implement, I just haven't gotten around to it yet.)
  3. Audio Listener: This class is also a Component. It is what acts like an "ear" of some sorts. All noise calculations are done with the listener in mind (whether to play the noise on the right or left speaker, relative velocity, etc.) and there can only be one listener; that's why its a singleton.
  4. Audio Master: Finally, this is where all the AudioSource's are. At the end of runtime, some amount of cleanup is required before closing the program (sure, the library does it itself, but I'd prefer to do it manualy.)

I tried to document most classes; that may need a little work, though. I hope this is a good start to the audio driver.

HilbertCurve commented 3 years ago

I synched up the singleton getters, removed AudioTest, and fixed some issues with AudioListener and AudioSource.

HilbertCurve commented 3 years ago

Added a dedicated scene for testing the driver.

HilbertCurve commented 3 years ago

Yeah, I don't think an audio batch makes sense: you're gonna call alPlaySource() for each sound you play no matter what.

HilbertCurve commented 2 years ago

Audio streaming basically means your sound card isn't overloaded with 2.3 megabytes of data whenever you play a song; instead 8 chunks of data are queued and then refreshed once processed

athaun commented 2 years ago

Nice, I will try to take a look soon.

athaun commented 2 years ago

This is a good start for sure, and I am ready to merge. In the future, if you want to add more contributions, better error handling (not crashing when it can't find a file), wider filetype support, and spatial audio would be awesome.