src/audio/sound_file.hpp File Reference

#include <iostream>

Go to the source code of this file.

Classes

class  SoundFile

Functions

SoundFileload_sound_file (const std::string &filename)


Function Documentation

SoundFile* load_sound_file ( const std::string &  filename  ) 

Definition at line 68 of file sound_file.cpp.

References load_music_file().

Referenced by SoundManager::intern_create_sound_source(), SoundManager::play_music(), and SoundManager::preload().

00069 {
00070   if(filename.length() > 6
00071      && filename.compare(filename.length()-6, 6, ".music") == 0) {
00072     return load_music_file(filename);
00073   }
00074 
00075   PHYSFS_file* file = PHYSFS_openRead(filename.c_str());
00076   if(!file) {
00077     std::stringstream msg;
00078     msg << "Couldn't open '" << filename << "': " << PHYSFS_getLastError() << ", using dummy sound file.";
00079     throw SoundError(msg.str());
00080   }
00081 
00082   try {
00083     char magic[4];
00084     if(PHYSFS_read(file, magic, sizeof(magic), 1) != 1)
00085       throw SoundError("Couldn't read magic, file too short");
00086     PHYSFS_seek(file, 0);
00087     if(strncmp(magic, "RIFF", 4) == 0)
00088       return new WavSoundFile(file);
00089     else if(strncmp(magic, "OggS", 4) == 0)
00090       return new OggSoundFile(file, 0, -1);
00091     else
00092       throw SoundError("Unknown file format");
00093   } catch(std::exception& e) {
00094     std::stringstream msg;
00095     msg << "Couldn't read '" << filename << "': " << e.what();
00096     throw SoundError(msg.str());
00097   }
00098 }


Generated on Mon Jun 9 03:38:26 2014 for SuperTux by  doxygen 1.5.1