]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Sound.cc
initial port to win32
[chaz/yoink] / src / Moof / Sound.cc
index 59acfaa9af269886ec0cc34a8286671751f75505..a0302fba003aaa6052e7e447f85a97d142ecd781 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"
 
@@ -63,6 +63,7 @@ struct Sound::Impl
                Buffer(const std::string& name) :
                        Mippleton<Buffer>(name)
                {
+                       sound = 0;
                        objects[0] = 0;
                        objects[1] = 0;
                }
@@ -84,8 +85,8 @@ struct Sound::Impl
 
                        if (!sound)
                        {
-                               std::cerr << "could not load sound from file" << std::endl;
-                               exit(1);
+                               logWarning("error while loading sound %s: %s", getName().c_str(), Sound_GetError());
+                               throw Exception(Exception::FILE_NOT_FOUND);
                        }
 
                        if (!stream)
@@ -93,27 +94,28 @@ struct Sound::Impl
                        unsigned decoded = Sound_DecodeAll(sound);
                        if (decoded == 0)
                        {
-                               std::cout << "decoded no bytes" << std::endl;
-                               exit(1);
+                               logWarning("decoded no bytes from %s", getName().c_str());
+                               //throw Exception(Exception::FILE_NOT_FOUND);
+                               return;
                        }
 
                        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 +145,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);
@@ -207,6 +209,8 @@ Sound::Sound(const std::string& name) :
 
 void Sound::play()
 {
+       if (!impl_->buffer_->sound) return;
+
        //alSourceRewind(impl_->source_);
        alSourcePlay(impl_->source_);
        impl_->playing = true;
This page took 0.021034 seconds and 4 git commands to generate.