COMPONENT_audio - CSCI150GTeam/GTeamProject GitHub Wiki

By: Joseph Gascon

[Sammy] - Audio class explanation: Ok Joseph, here's what your audio class should do- pretty much your class is going to receive commands from other classes to play sounds. So for example example every time the player shoots his weapon, the weapon class is going to have a line that says something like audio->playSound("gunshot");, and your class will take the input string, in this case "gunshot", and play the matching file. So one function you'll need is playSound(string).
In the class' constructor, you're going to need to call the Mix_OpenAudio function to initialize the mixer. Keep most of the arguments for that function their defaults (or what was shown in the tutorial), but for the third argument (number of channels) go ahead and put in 3 for now, one for music, and two for game SFX.
For now, as long as you can get the playSound() function working, that'll be fine, we can figure out all the specifics later. Load up 2 or 3 sound effects that we can play for testing purposes tomorrow, and during class I'll show you how we're going to load and manage audio files in the final product. For this function the main thing you'll be using is calling SDL's Mix_PlayChannel(). It should be pretty simple.

class audio {
public:
void playSound(string);
audio();
~audio();
private:
Mix_Chunk* sound1; //load these two in the constructor using Mix_LoadWAV
Mix_Chuck* sound2;
}

To do list:

*background music for the game menu
*background music for the levels
*sound effects for objects (e.g. breaking glass, etc.)
*sound effects for actions or events (e.g. door opening and closing, etc.)
*setup code to load, open, and run the audio or sound effects in SDL 1.2

Future Additions:

  • ability to adjust the volume through settings menu
⚠️ **GitHub.com Fallback** ⚠️