X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fsound.cc;h=a1da62b8be10c9d1c2567f2931e90a1eb9841071;hp=7482de7eb9eb22f862041cd6e92a70b2bed14198;hb=51069fee9139ab8d14ecc80dffbe5deecb73d9e0;hpb=831f04d4bc19a390415ac0bbac4331c7a65509bc diff --git a/src/moof/sound.cc b/src/moof/sound.cc index 7482de7..a1da62b 100644 --- a/src/moof/sound.cc +++ b/src/moof/sound.cc @@ -16,7 +16,6 @@ #include #include - #include #include #include @@ -33,11 +32,28 @@ namespace moof { +class impl +{ +public: + + impl() + { + resource::register_type("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); }