Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

input.cpp

Go to the documentation of this file.
00001 #include <string.h>
00002 #include "input.hpp"
00003 #include "debug.hpp"
00004 #include "input_mod.hpp"
00005 #include "input_ogg.hpp"
00006 #include "input_wav.hpp"
00007 #include "utility.hpp"
00008 
00009 
00011 
00012 inline bool end_is(const char* begin, const char* end, const char* ext) {
00013   int ext_length = strlen(ext);
00014   if (ext_length > end - begin) {
00015     return false;
00016   } else {
00017     return (strcmp_case(end - ext_length, ext) == 0);
00018   }
00019 }
00020 
00022 
00023 template<typename T>
00024 static T* TryInputStream(IFile* file) {
00025 
00026   // initialize should never close the file
00027 
00028   T* source = new T();
00029   if (source->Initialize(file)) {
00030     return source;
00031   } else {
00032     delete source;
00033     return 0;
00034   }
00035 }
00036 
00038 
00039 ISampleSource* OpenInputStream(IFileSystem* fs, const char* filename)
00040 {
00041   ADR_GUARD("OpenInputStream");
00042 
00043   // try to open the file
00044   IFile* file = fs->Open(filename);
00045   if (!file) {
00046     return 0;
00047   }
00048   
00049   ISampleSource* source;
00050 
00051   #define TRY_SOURCE(source_type)                \
00052     source = TryInputStream<source_type>(file);  \
00053     if (source) {                                \
00054       return source;                             \
00055     } else {                                     \
00056       file->Seek(0, ADR_BEGIN);                  \
00057     }
00058 
00059   // grab the end of the filename so we can do end-of-string compares faster
00060   const char* filename_end = filename + strlen(filename);
00061 
00062   if (end_is(filename, filename_end, ".it") ||
00063       end_is(filename, filename_end, ".xm") ||
00064       end_is(filename, filename_end, ".s3m") ||
00065       end_is(filename, filename_end, ".mod")) {
00066 
00067     TRY_SOURCE(MODInputStream);
00068 
00069   } else if (end_is(filename, filename_end, ".wav")) {
00070 
00071     TRY_SOURCE(WAVInputStream);
00072 
00073   } else if (end_is(filename, filename_end, ".ogg")) {
00074 
00075     TRY_SOURCE(OGGInputStream);
00076 
00077   }
00078 
00079   // autodetect otherwise?
00080   // (in decreasing order of possibility of failure)
00081   TRY_SOURCE(MODInputStream);
00082   TRY_SOURCE(WAVInputStream);
00083   TRY_SOURCE(OGGInputStream);
00084 
00085   delete file;
00086   return 0;
00087 }
00088 

Generated at Mon Jun 10 02:55:12 2002 for audiere by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001