]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Sound.cc
better logging (maybe) and exception handling
[chaz/yoink] / src / Moof / Sound.cc
index 59acfaa9af269886ec0cc34a8286671751f75505..368e9388bca4aee4f3665ae40b1abf1afa71f6cd 100644 (file)
 
 *******************************************************************************/
 
-#include <iostream>
 #include <string>
 
 #include <SDL/SDL.h>
 #include <SDL/SDL_sound.h>
 #include <AL/al.h>
 
+#include "Log.hh"
 #include "Mippleton.hh"
 #include "Sound.hh"
 
@@ -84,8 +84,8 @@ struct Sound::Impl
 
                        if (!sound)
                        {
-                               std::cerr << "could not load sound from file" << std::endl;
-                               exit(1);
+                               logWarning("audio not found: %s", getName().c_str());
+                               throw Exception(Exception::FILE_NOT_FOUND);
                        }
 
                        if (!stream)
@@ -93,27 +93,27 @@ struct Sound::Impl
                        unsigned decoded = Sound_DecodeAll(sound);
                        if (decoded == 0)
                        {
-                               std::cout << "decoded no bytes" << std::endl;
-                               exit(1);
+                               logWarning("decoded not bytes from %s", getName().c_str());
+                               throw Exception(Exception::FILE_NOT_FOUND);
                        }
 
                        alGenBuffers(2, objects);
                        alBufferData(objects[0], getAudioFormat(sound->actual), sound->buffer,
                                        sound->buffer_size, sound->actual.rate);
-                       std::cerr << "buffer size: " << sound->buffer_size << std::endl;
-                       std::cerr << "channels: " << (int)sound->actual.channels << std::endl;
-                       std::cerr << "format: " << sound->actual.format << std::endl;
-                       std::cerr << "frequency: " << sound->actual.rate << std::endl;
+                       logDebug("buffer size: %d", sound->buffer_size);
+                       logDebug("   channels: %d", sound->actual.channels);
+                       logDebug("     format: %d", sound->actual.format);
+                       logDebug("  frequency: %d", sound->actual.rate);
 
                        Sound_FreeSample(sound);
                        sound = 0;
                        }
                        else
                        {
-                       std::cerr << "buffer size: " << sound->buffer_size << std::endl;
-                       std::cerr << "channels: " << (int)sound->actual.channels << std::endl;
-                       std::cerr << "format: " << sound->actual.format << std::endl;
-                       std::cerr << "frequency: " << sound->actual.rate << std::endl;
+                       logDebug("buffer size: %d", sound->buffer_size);
+                       logDebug("   channels: %d", sound->actual.channels);
+                       logDebug("     format: %d", sound->actual.format);
+                       logDebug("  frequency: %d", sound->actual.rate);
                                alGenBuffers(2, objects);
                        }
                }
@@ -143,7 +143,7 @@ struct Sound::Impl
        };
 
        Impl(const std::string& name, bool stream = false) :
-               buffer_(Buffer::retain(name), Buffer::release)
+               buffer_(Buffer::getInstance(name))
        {
                if (!stream) buffer_->loadFromFile(Sound::getPath(name), stream);
                else         buffer_->loadFromFile(SoundStream::getPath(name), stream);
This page took 0.022149 seconds and 4 git commands to generate.