X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSound.cc;h=a0302fba003aaa6052e7e447f85a97d142ecd781;hp=59acfaa9af269886ec0cc34a8286671751f75505;hb=8ad81a8282ce6e9e488a453e6bcd05fbc09715dc;hpb=4701bf580b75a7d77a460c6f14f9fc31fb109bbb diff --git a/src/Moof/Sound.cc b/src/Moof/Sound.cc index 59acfaa..a0302fb 100644 --- a/src/Moof/Sound.cc +++ b/src/Moof/Sound.cc @@ -26,13 +26,13 @@ *******************************************************************************/ -#include #include #include #include #include +#include "Log.hh" #include "Mippleton.hh" #include "Sound.hh" @@ -63,6 +63,7 @@ struct Sound::Impl Buffer(const std::string& name) : Mippleton(name) { + sound = 0; objects[0] = 0; objects[1] = 0; } @@ -84,8 +85,8 @@ struct Sound::Impl if (!sound) { - std::cerr << "could not load sound from file" << std::endl; - exit(1); + logWarning("error while loading sound %s: %s", getName().c_str(), Sound_GetError()); + throw Exception(Exception::FILE_NOT_FOUND); } if (!stream) @@ -93,27 +94,28 @@ struct Sound::Impl unsigned decoded = Sound_DecodeAll(sound); if (decoded == 0) { - std::cout << "decoded no bytes" << std::endl; - exit(1); + logWarning("decoded no bytes from %s", getName().c_str()); + //throw Exception(Exception::FILE_NOT_FOUND); + return; } alGenBuffers(2, objects); alBufferData(objects[0], getAudioFormat(sound->actual), sound->buffer, sound->buffer_size, sound->actual.rate); - std::cerr << "buffer size: " << sound->buffer_size << std::endl; - std::cerr << "channels: " << (int)sound->actual.channels << std::endl; - std::cerr << "format: " << sound->actual.format << std::endl; - std::cerr << "frequency: " << sound->actual.rate << std::endl; + logDebug("buffer size: %d", sound->buffer_size); + logDebug(" channels: %d", sound->actual.channels); + logDebug(" format: %d", sound->actual.format); + logDebug(" frequency: %d", sound->actual.rate); Sound_FreeSample(sound); sound = 0; } else { - std::cerr << "buffer size: " << sound->buffer_size << std::endl; - std::cerr << "channels: " << (int)sound->actual.channels << std::endl; - std::cerr << "format: " << sound->actual.format << std::endl; - std::cerr << "frequency: " << sound->actual.rate << std::endl; + logDebug("buffer size: %d", sound->buffer_size); + logDebug(" channels: %d", sound->actual.channels); + logDebug(" format: %d", sound->actual.format); + logDebug(" frequency: %d", sound->actual.rate); alGenBuffers(2, objects); } } @@ -143,7 +145,7 @@ struct Sound::Impl }; Impl(const std::string& name, bool stream = false) : - buffer_(Buffer::retain(name), Buffer::release) + buffer_(Buffer::getInstance(name)) { if (!stream) buffer_->loadFromFile(Sound::getPath(name), stream); else buffer_->loadFromFile(SoundStream::getPath(name), stream); @@ -207,6 +209,8 @@ Sound::Sound(const std::string& name) : void Sound::play() { + if (!impl_->buffer_->sound) return; + //alSourceRewind(impl_->source_); alSourcePlay(impl_->source_); impl_->playing = true;