]> Dogcows Code - chaz/yoink/blobdiff - src/moof/sound.cc
configuration cleanup and bugfixes
[chaz/yoink] / src / moof / sound.cc
index 7482de7eb9eb22f862041cd6e92a70b2bed14198..a1da62b8be10c9d1c2567f2931e90a1eb9841071 100644 (file)
@@ -16,7 +16,6 @@
 #include <string>
 
 #include <boost/algorithm/string.hpp>
-
 #include <AL/al.h>
 #include <AL/alc.h>
 #include <vorbis/codec.h>
 namespace moof {
 
 
+class impl
+{
+public:
+       
+       impl()
+       {
+               resource::register_type<sound_stream>("ogg");
+       }
+
+       ~impl()
+       {
+               resource::unregister_type("ogg");
+       }
+};
+static impl impl;
+
+
 class sound::impl
 {
 public:
 
-       static ALenum getAudioFormat(const vorbis_info* audioInfo)
+       static ALenum get_audio_format(const vorbis_info* audioInfo)
        {
                if (audioInfo->channels == 1) return AL_FORMAT_MONO16;
                else                                              return AL_FORMAT_STEREO16;
@@ -67,27 +83,22 @@ public:
                }
 
 
-               void init(const std::string& name)
+               void init(const std::string& path)
                {
+                       log_info("initializing audio buffer...");
                        if (mOggStream.datasource)
                        {
                                ov_clear(&mOggStream);
                                mOggStream.datasource = 0;
                        }
 
-                       std::string path(name);
-                       if (!sound::find_path(path))
-                       {
-                               throw std::runtime_error("cannot find resource: " + name);
-                       }
-
                        if (ov_fopen((char*)path.c_str(), &mOggStream) < 0)
                        {
-                               throw std::runtime_error("problem reading audio: " + name);
+                               throw std::runtime_error("problem reading audio: " + path);
                        }
 
                        vorbis_info* vorbisInfo = ov_info(&mOggStream, -1);
-                       mFormat = getAudioFormat(vorbisInfo);
+                       mFormat = get_audio_format(vorbisInfo);
                        mFreq = vorbisInfo->rate;
                }
 
@@ -182,10 +193,11 @@ public:
                init();
        }
 
-       impl(const std::string& name)
+       impl(const std::string& path)
        {
+               log_info("sound::impl constructor");
                init();
-               enqueue(name);
+               enqueue(path);
        }
 
        void init()
@@ -357,7 +369,7 @@ public:
        }
 
 
-       void sample(const std::string& name)
+       void sample(const std::string& path)
        {
                stop();
                alSourcei(source_, AL_BUFFER, AL_NONE);
@@ -365,7 +377,7 @@ public:
                queue_.clear();
                is_loaded_ = false;
 
-               enqueue(name);
+               enqueue(path);
 
                while (!buffers_.empty())
                {
@@ -374,9 +386,9 @@ public:
                }
        }
 
-       void enqueue(const std::string& name)
+       void enqueue(const std::string& path)
        {
-               buffer_ptr buffer = buffer::instance(name);
+               buffer_ptr buffer = buffer::instance(path);
                queue_.push_back(buffer);
        }
 
@@ -469,19 +481,22 @@ ALCdevice*        sound::impl::al_device_ = 0;
 ALCcontext*    sound::impl::al_context_ = 0;
 
 
-sound::sound() :
-       // pass through
-       impl_(new sound::impl) {}
+//sound::sound() :
+       //// pass through
+       //impl_(new sound::impl) {}
 
-sound::sound(const std::string& name) :
+sound::sound(const std::string& path) :
        // pass through
-       impl_(new sound::impl(name)) {}
+       impl_(new sound::impl(path))
+{
+       log_info("sound constructor");
+}
 
 
-void sound::sample(const std::string& name)
+void sound::sample(const std::string& path)
 {
        // pass through
-       impl_->sample(name);
+       impl_->sample(path);
 }
 
 
@@ -559,7 +574,7 @@ void sound::listener_velocity(const vector3& velocity)
 }
 
 void sound::listener_orientation(const vector3& forward,
-                                                                  const vector3& up)
+                                                                const vector3& up)
 {
        float vec[6];
        vec[0] = float(forward[0]);
@@ -572,19 +587,13 @@ void sound::listener_orientation(const vector3& forward,
 }
 
 
-bool sound::find_path(std::string& name)
-{
-       return resource::find_path(name, "sounds/", "ogg");
-}
-
-
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
-void sound_stream::enqueue(const std::string& name)
+void sound_stream::enqueue(const std::string& path)
 {
        // pass through
-       impl_->enqueue(name);
+       impl_->enqueue(path);
 }
 
 
This page took 0.022436 seconds and 4 git commands to generate.