AudioFileFormats.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "AudioFileFormats.hxx"
00023 #include <algorithm>
00024 #include <cctype>
00025
00026 namespace CLAM
00027 {
00028 EAudioFileFormat EAudioFileFormat::FormatFromFilename( std::string filename )
00029 {
00030 std::string::iterator dotPos = std::find( filename.begin(), filename.end(), '.' );
00031 if ( dotPos == filename.end() )
00032 return eWAV;
00033 std::string extension( dotPos+1, filename.end() );
00034 for(unsigned i=0; i<extension.size();++i)
00035 extension[i] = std::tolower(extension[i]);
00036
00037 static struct {
00038 const char * extension;
00039 Enum::tValue format;
00040 } extensionMap[] =
00041 {
00042 {"wav", eWAV},
00043 {"ogg", eVorbisMk1},
00044 {"aif", eAIFF},
00045 {"aiff", eAIFF},
00046 {"au", eAU},
00047 {"snd", eAU},
00048 {"raw", eRAW},
00049 {"paf", ePAF},
00050 {"svx", eSVX},
00051 {"nist", eNIST},
00052 {"voc", eVOC},
00053 {"ircam", eIRCAM},
00054 {"w64", eW64},
00055 {"mat4", eMAT4},
00056 {"mat5", eMAT5},
00057 {"mat", eMAT5},
00058 {"mp1", eMpegLayer1},
00059 {"mp2", eMpegLayer2},
00060 {"mp3", eMpegLayer3},
00061 {0,0}
00062 };
00063 for (unsigned i=0; extensionMap[i].extension; i++)
00064 if (extension==extensionMap[i].extension)
00065 return extensionMap[i].format;
00066 return eWAV;
00067 }
00068
00069
00070 }
00071