Haunted Light 2014-02-20 SoundManager
|
This week I have been working on the sound manager for our game, I started of trying to translate the sound manager we had been using in SDL. I almost immediately changed my mind about the translation because of a quick google search. SFML Handles sounds and music a bit differently than SDL. Instead of loading in entire files and then playing them, SFML handles sounds and music almost as it handles sprites. This however makes the program take an extra step to create sound and music but it is a lot more efficient than loading it entirely like we did in SDL. Sounds are often small files that doesn’t require a lot of processing so they can be fully loaded into the game and works almost identical to how sprites works in SFML, music however works a bit differently but I’ll get to that later. First the audio manager requires sound buffers to be located (these are your files). If you compare it to how SFML handles sprites, this is where the textures are gathered. We later on add the sound buffers to a map to have them in memory even when the loop and method is done working. Afterwards we place them in pair so that every sound buffer gets a string so that we can connect them to sounds. We are using SFML’s own “sound” to play our sounds but as I said they work almost identical as the sprites in SFML. So instead of “GetTexture” we are going to call for “SetSoundBuffer” and then refer to our iterator that goes through our map of SoundBuffers to be able to return the sound.
See how identical the getsound and getsprite really are! However when it comes to the implementation of music it is a bit different. Music files are often large and to process these takes much time and is not the ideal way to get them in a game. SFML handles these in a different way, how does one load something that is big without loading them entirely? You stream it! The music files are streamed into the game to make the processing of the entire game more streamlined. Otherwise there would have been an insanely increased loading time when you start a level. So when we are loading music we just simply finds the file, opens it and then returns the streamed music clip to the required place where it can be played and heard while not taking up a lot of processing power.
|
