#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;
}
- 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;
}
init();
}
- impl(const std::string& name)
+ impl(const std::string& path)
{
+ log_info("sound::impl constructor");
init();
- enqueue(name);
+ enqueue(path);
}
void init()
}
- void sample(const std::string& name)
+ void sample(const std::string& path)
{
stop();
alSourcei(source_, AL_BUFFER, AL_NONE);
queue_.clear();
is_loaded_ = false;
- enqueue(name);
+ enqueue(path);
while (!buffers_.empty())
{
}
}
- 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);
}
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);
}
}
void sound::listener_orientation(const vector3& forward,
- const vector3& up)
+ const vector3& up)
{
float vec[6];
vec[0] = float(forward[0]);
}
-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);
}