2012-10-13 18:29:53 +00:00
|
|
|
#include "AudioManager.h"
|
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
#include "Log.h"
|
2012-10-13 18:29:53 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_mixer.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include "Sound.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace AudioManager
|
|
|
|
{
|
|
|
|
std::vector<Sound*> sSoundVector;
|
|
|
|
|
|
|
|
bool sInitialized = false;
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
int result = Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16SYS, 2, 1024);
|
|
|
|
|
|
|
|
if(result == -1)
|
|
|
|
{
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogError) << "Error initializing AudioManager!\n " << Mix_GetError();
|
2012-10-13 18:29:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sInitialized = true;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < sSoundVector.size(); i++)
|
|
|
|
{
|
|
|
|
sSoundVector.at(i)->init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerSound(Sound* sound)
|
|
|
|
{
|
|
|
|
sSoundVector.push_back(sound);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unregisterSound(Sound* sound)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < sSoundVector.size(); i++)
|
|
|
|
{
|
|
|
|
if(sSoundVector.at(i) == sound)
|
|
|
|
{
|
|
|
|
sSoundVector.erase(sSoundVector.begin() + i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogError) << "AudioManager Error - tried to unregister a sound that wasn't registered!";
|
2012-10-13 18:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void deinit()
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < sSoundVector.size(); i++)
|
|
|
|
{
|
|
|
|
sSoundVector.at(i)->deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
Mix_CloseAudio();
|
|
|
|
|
|
|
|
sInitialized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInitialized()
|
|
|
|
{
|
|
|
|
return sInitialized;
|
|
|
|
}
|
|
|
|
}
|