CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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