#include "Log.hh"
#include "Mippleton.hh"
#include "Sound.hh"
+#include "Timer.hh"
#define BUFFER_SIZE (64 * 1024)
//#define BUFFER_SIZE (5*2048)
}
- void beginStream(ALuint source, int nBuffers = 4)
+ void beginStream(ALuint source, int nBuffers = 8)
{
if (!oggStream.datasource) openFile();
if (!oggStream.datasource) return;
alSourcei(source_, AL_LOOPING, AL_FALSE);
alSourcePlay(source_);
playing_ = true;
+
+ streamTimer.init(boost::bind(&Impl::streamUpdate, this, _1, _2), 1.0,
+ Timer::REPEAT);
}
inline void update()
std::queue<BufferP> queue_;
std::vector<BufferP> expired_;
+
+ Timer streamTimer;
+
+ void streamUpdate(Timer& timer, Scalar t)
+ {
+ // don't let the music die!
+ update();
+ // TODO - might be nice to also allow using threads for streaming rather
+ // than a timer, probably as a compile-time option
+ }
};
Sound::Sound(const std::string& name) :
impl_->play();
}
-
void Sound::stream()
{
// pass through
impl_->stream();
}
-void Sound::update(Scalar t, Scalar dt)
-{
- // pass through
- impl_->update();
-}
-
void Sound::stop()
{
return impl_->isPlaying();
}
-void Sound::setPosition(Vector3 position)
+void Sound::setPosition(const Vector3& position)
{
float p[3] = {position[0], position[1], position[2]};
alSourcefv(impl_->source_, AL_POSITION, p);
}
-void Sound::setVelocity(Vector3 velocity)
+void Sound::setVelocity(const Vector3& velocity)
{
float v[3] = {velocity[0], velocity[1], velocity[2]};
alSourcefv(impl_->source_, AL_VELOCITY, v);
}
+void Sound::setListenerPosition(const Vector3& position)
+{
+ alListener3f(AL_POSITION, float(position[0]), float(position[1]),
+ float(position[2]));
+}
+
+void Sound::setListenerVelocity(const Vector3& velocity)
+{
+ alListener3f(AL_VELOCITY, float(velocity[0]), float(velocity[1]),
+ float(velocity[2]));
+}
+
+void Sound::setListenerOrientation(const Vector3& forward, const Vector3& up)
+{
+ float vec[6];
+ vec[0] = float(forward[0]);
+ vec[1] = float(forward[1]);
+ vec[2] = float(forward[2]);
+ vec[3] = float(up[0]);
+ vec[4] = float(up[1]);
+ vec[5] = float(up[2]);
+ alListenerfv(AL_ORIENTATION, vec);
+}
+
+
std::string Sound::getPath(const std::string& name)
{
std::string path = Resource::getPath("sounds/" + name + ".ogg");