+#include <memory>
+
+#include "audio/dummy_sound_source.hpp"
+#include "audio/sound_file.hpp"
+#include "audio/stream_sound_source.hpp"
+#include "util/log.hpp"
+
+SoundManager::SoundManager() :
+ device(0),
+ context(0),
+ sound_enabled(false),
+ buffers(),
+ sources(),
+ update_list(),
+ music_source(),
+ music_enabled(false),
+ current_music()
+{
+ try {
+ device = alcOpenDevice(0);
+ if (device == NULL) {
+ throw std::runtime_error("Couldn't open audio device.");
+ }
+
+ int attributes[] = { 0 };
+ context = alcCreateContext(device, attributes);
+ check_alc_error("Couldn't create audio context: ");
+ alcMakeContextCurrent(context);
+ check_alc_error("Couldn't select audio context: ");
+
+ check_al_error("Audio error after init: ");
+ sound_enabled = true;
+ music_enabled = true;
+ } catch(std::exception& e) {
+ if(context != NULL) {
+ alcDestroyContext(context);
+ context = NULL;
+ }
+ if(device != NULL) {
+ alcCloseDevice(device);
+ device = NULL;
+ }
+ log_warning << "Couldn't initialize audio device: " << e.what() << std::endl;
+ print_openal_version();
+ }
+}
+
+SoundManager::~SoundManager()
+{
+ music_source.reset();
+ sources.clear();
+
+ for(SoundBuffers::iterator i = buffers.begin(); i != buffers.end(); ++i) {
+ ALuint buffer = i->second;
+ alDeleteBuffers(1, &buffer);
+ }