return buffer;
}
-SoundSource*
-SoundManager::create_sound_source(const std::string& filename)
+OpenALSoundSource*
+SoundManager::intern_create_sound_source(const std::string& filename)
{
if(!sound_enabled)
- return create_dummy_sound_source();
+ throw new std::exception("sound disabled");
- std::auto_ptr<OpenALSoundSource> source;
- try {
- source.reset(new OpenALSoundSource());
- } catch(std::exception& e) {
- log_warning << "Couldn't create audio source: " << e.what() << std::endl;
- return create_dummy_sound_source();
- }
+ std::auto_ptr<OpenALSoundSource> source (new OpenALSoundSource());
ALuint buffer;
if(i != buffers.end()) {
buffer = i->second;
} else {
- try {
- // Load sound file
- std::auto_ptr<SoundFile> file (load_sound_file(filename));
-
- if(file->size < 100000) {
- buffer = load_file_into_buffer(file.get());
- buffers.insert(std::make_pair(filename, buffer));
- } else {
- StreamSoundSource* source = new StreamSoundSource();
- source->set_sound_file(file.release());
- return source;
- }
- } catch(std::exception& e) {
- log_warning << "Couldn't load soundfile '" << filename << "': " << e.what() << std::endl;
- return create_dummy_sound_source();
+ // Load sound file
+ std::auto_ptr<SoundFile> file (load_sound_file(filename));
+
+ if(file->size < 100000) {
+ buffer = load_file_into_buffer(file.get());
+ buffers.insert(std::make_pair(filename, buffer));
+ } else {
+ StreamSoundSource* source = new StreamSoundSource();
+ source->set_sound_file(file.release());
+ return source;
}
}
return source.release();
}
+SoundSource*
+SoundManager::create_sound_source(const std::string& filename)
+{
+ if(!sound_enabled)
+ return create_dummy_sound_source();
+
+ try {
+ return intern_create_sound_source(filename);
+ } catch(std::exception &e) {
+ log_warning << "Couldn't create audio source: " << e.what() << std::endl;
+ return create_dummy_sound_source();
+ }
+}
+
void
SoundManager::preload(const std::string& filename)
{
try {
std::auto_ptr<OpenALSoundSource> source
- (static_cast<OpenALSoundSource*> (create_sound_source(filename)));
+ (intern_create_sound_source(filename));
if(pos == Vector(-1, -1)) {
source->set_rollof_factor(0);
* Creates a new sound source object which plays the specified soundfile.
* You are responsible for deleting the sound source later (this will stop the
* sound).
- * This function might throw exceptions. It returns 0 if no audio device is
- * available.
+ * This function never throws exceptions, but might return a DummySoundSource
*/
SoundSource* create_sound_source(const std::string& filename);
/**
friend class OpenALSoundSource;
friend class StreamSoundSource;
+ /** creates a new sound source, might throw exceptions, never returns NULL */
+ OpenALSoundSource* intern_create_sound_source(const std::string& filename);
static ALuint load_file_into_buffer(SoundFile* file);
static ALenum get_sample_format(SoundFile* file);