]> Dogcows Code - chaz/yoink/blobdiff - src/moof/sound.cc
fixed some resource management bugs
[chaz/yoink] / src / moof / sound.cc
index a6fbf0310679faacc76175aa9d67b71079b1e9e5..0714698673f02f8d7a757e0923ba39ca509f2191 100644 (file)
@@ -35,7 +35,7 @@
 #define BUF_SIZE       (4096)
 #endif
 
-#define NUM_BUFFERS (16)
+#define NUM_BUFFERS (8)
 
 
 namespace moof {
@@ -87,7 +87,6 @@ public:
                        alcMakeContextCurrent(0);
                        alcDestroyContext(al_context);
                        alcCloseDevice(al_device);
-                       log_info("unloaded sound device ALSA");
                }
        }
 
@@ -112,7 +111,7 @@ public:
        
        sound_resource_loader()
        {
-               resource::register_type<sound_resource>("ogg");
+               resource::register_type<sound_resource>("ogg", "sounds");
        }
 
        ~sound_resource_loader()
@@ -146,7 +145,6 @@ public:
                alBufferData(buffer_, format, data, size, freq);
 
                retain_counts_[buffer_] = 1;
-               log_warning("ctor buffer:", buffer_);
        }
 
        buffer(const buffer& buf)
@@ -174,7 +172,6 @@ public:
                {
                        alSourceQueueBuffers(source, 1, &buffer_);
                        retain();
-                       log_warning("queued buffer:", buffer_);
                }
        }
 
@@ -182,13 +179,11 @@ public:
        {
                ALuint buf = (ALuint)-1;
                alSourceUnqueueBuffers(source, 1, &buf);
-               log_warning("unqueued buffer:", buf);
                return buffer(buf);
        }
 
        void set(ALuint source) const
        {
-               log_warning("set buffer:", buffer_);
                if (*this) alSourcei(source, AL_BUFFER, buffer_);
        }
 
@@ -217,7 +212,6 @@ private:
                {
                        alDeleteBuffers(1, &buffer_);
                        retain_counts_.erase(it);
-                       log_warning("kill buffer:", buffer_);
                }
        }
 
@@ -240,7 +234,6 @@ public:
 
        sound_resource(const std::string& path)
        {
-               log_info("audio path is", path);
                if (ov_fopen((char*)path.c_str(), &file_) < 0)
                {
                        throw std::runtime_error("problem reading audio: " + path);
@@ -284,14 +277,10 @@ public:
                        }
                        else if (result == 0 && size > 0)
                        {
-                               log_info("loaded", size, "bytes from vorbis");
                                vorbis_info* info = ov_info(&file_, section);
                                buffer_ = buffer(data, size,
                                                                 get_audio_format(info), info->rate);
                                buf = buffer_;
-                               log_info("this section is", section);
-                               log_info("audio format is", get_audio_format(info));
-                               log_info("audio freq is", info->rate);
                                return true;
                        }
                        else
@@ -320,14 +309,9 @@ public:
 
                if (result > 0)
                {
-                       log_info("loaded", result, "bytes from vorbis");
                        vorbis_info* info = ov_info(&file_, section);
                        buf = buffer(data, result, get_audio_format(info), info->rate);
                        sample = ov_pcm_tell(&file_);
-                       log_info("this section is", section);
-                       log_info("next sample is", sample);
-                       log_info("audio format is", get_audio_format(info));
-                       log_info("audio freq is", info->rate);
                        return true;
                }
 
@@ -360,11 +344,10 @@ public:
                init();
        }
 
-       impl(const std::string& path)
+       impl(const std::string& name)
        {
-               log_info("sound::impl constructor");
                init();
-               enqueue(path);
+               enqueue(name);
        }
 
        void init()
@@ -375,14 +358,12 @@ public:
                sample_ = 0;
 
                alGenSources(1, &source_);
-               log_error("alGenSources:", alGetError());
 
                ALfloat zero[] = {0.0f, 0.0f, 0.0f};
                alSourcef(source_,  AL_PITCH, 1.0f);
                alSourcef(source_,  AL_GAIN, 1.0f);
                alSourcefv(source_, AL_POSITION, zero);
                alSourcefv(source_, AL_VELOCITY, zero);
-               log_error("init:", alGetError());
        }
 
        ~impl()
@@ -401,7 +382,6 @@ public:
 
                if (handle->read(buf))
                {
-                       log_info("playing source...");
                        buf.set(source_);
                        alSourcei(source_, AL_LOOPING, is_looping_);
                        alSourcePlay(source_);
@@ -415,7 +395,6 @@ public:
                if (!is_playing_)
                {
                        alSourcei(source_, AL_LOOPING, false);
-                       log_error("set not looping:", alGetError());
 
                        sound_handle handle = queue_.front();
 
@@ -434,7 +413,6 @@ public:
 
                                ALint queued = 0;
                                alGetSourcei(source_, AL_BUFFERS_QUEUED, &queued);
-                               log_info("buffers queued:", queued);
                        }
                }
 
@@ -444,9 +422,7 @@ public:
                                        0.01, timer::repeat);
                }
 
-               log_info("streaming source...");
                alSourcePlay(source_);
-               log_error("playing:", alGetError());
                is_playing_ = true;
        }
 
@@ -487,13 +463,10 @@ public:
                                        // begin the next buffer in the queue
                                        handle->read(buf, sample_);
                                        buf.queue(source_);
-                                       log_info("loading new buffer");
                                }
                                else if (is_looping_)
                                {
                                        // reload the same buffer
-                                       log_info("looping same buffer");
-
                                        queue_.push_back(handle);
                                        handle->read(buf, sample_);
                                        buf.queue(source_);
@@ -544,19 +517,19 @@ public:
        }
 
 
-       void sample(const std::string& path)
+       void sample(const std::string& name)
        {
                stop();
                alSourcei(source_, AL_BUFFER, AL_NONE);
 
                queue_.clear();
 
-               enqueue(path);
+               enqueue(name);
        }
 
-       void enqueue(const std::string& path)
+       void enqueue(const std::string& name)
        {
-               sound_handle handle = resource::load(path);
+               sound_handle handle = resource::load(name, "ogg");
                queue_.push_back(handle);
        }
 
@@ -613,10 +586,7 @@ sound::sound() :
 
 sound::sound(const std::string& path) :
        // pass through
-       impl_(new sound::impl(path))
-{
-       log_info("sound constructor");
-}
+       impl_(new sound::impl(path)) {}
 
 
 void sound::sample(const std::string& path)
This page took 0.026056 seconds and 4 git commands to generate.