00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "caudiox.hpp"
00030 #include "uti.h"
00031 #include "xalloc.h"
00032
00033
00034
00035 AFFormat * CAudioFile::getAFFormatObject( const CHAR *fname,
00036 const CHAR *mode )
00037 {
00038 #define RETURNIF(type) if (format.contains(type::formatStr())) return new type(this)
00039 #define TESTFILE(type) if (type::testFile(f)) { fclose(f); return new type(this); }
00040
00041 FILE* f;
00042 const String& format = myOpts.val(CAUDIO_FFORMAT);
00043 if (!format.contains("Auto")) {
00044
00045 RETURNIF(AFWav);
00046 RETURNIF(AFRaw);
00047 RETURNIF(AFAho2);
00048 RETURNIF(AFAho1);
00049 RETURNIF(AFTei);
00050 RETURNIF(AFNist);
00051 RETURNIF(AFHak);
00052
00053
00054 die_beep("CAudioFile: invalid file format string (%s)",
00055 (const char *)format);
00056 }
00057
00058
00059 f = fopen(fname,"rb");
00060 const CHAR *ext= fname + path_extpos(fname);
00061
00062 if ((*mode=='r')||(*mode=='m')||(*mode=='M')||((*mode=='a')&&(f))) {
00063 if (f) {
00064 TESTFILE(AFWav);
00065 TESTFILE(AFTei);
00066 TESTFILE(AFAho2);
00067 TESTFILE(AFAho1);
00068 TESTFILE(AFNist);
00069 TESTFILE(AFHak);
00070
00071 TESTFILE(AFRaw);
00072 fclose(f);
00073 }
00074
00075 if (!stricmp(ext,".wav")) return new AFWav(this);
00076 if (!stricmp(ext,".aho")) return new AFAho1(this);
00077 if (!stricmp(ext,".eus")) return new AFAho1(this);
00078 if (!stricmp(ext,".raw")) return new AFRaw(this);
00079 if (!stricmp(ext,".pcm")) return new AFRaw(this);
00080 if (!stricmp(ext,".nist")) return new AFNist(this);
00081 if (!stricmp(ext,".nis")) return new AFNist(this);
00082 if (!stricmp(ext,".hak")) return new AFHak(this);
00083
00084
00085
00086 RETURNIF(AFRaw);
00087 RETURNIF(AFWav);
00088 RETURNIF(AFAho2);
00089 RETURNIF(AFAho1);
00090 RETURNIF(AFTei);
00091 RETURNIF(AFNist);
00092 RETURNIF(AFHak);
00093
00094
00095
00096
00097
00098
00099 return new AFRaw(this);
00100 }
00101
00102 if (f) fclose(f);
00103
00104
00105 if (!stricmp(ext,".wav")) return new AFWav(this);
00106 if (!stricmp(ext,".aho")) return new AFAho2(this);
00107 if (!stricmp(ext,".eus")) return new AFAho2(this);
00108 if (!stricmp(ext,".raw")) return new AFRaw(this);
00109 if (!stricmp(ext,".pcm")) return new AFRaw(this);
00110 if (!stricmp(ext,".tei")) return new AFTei(this);
00111 if (!stricmp(ext,".nist")) return new AFNist(this);
00112 if (!stricmp(ext,".nis")) return new AFNist(this);
00113 if (!stricmp(ext,".hak")) return new AFHak(this);
00114
00115
00116 RETURNIF(AFRaw);
00117 RETURNIF(AFWav);
00118 RETURNIF(AFAho2);
00119 RETURNIF(AFAho1);
00120 RETURNIF(AFTei);
00121 RETURNIF(AFNist);
00122 RETURNIF(AFHak);
00123
00124
00125
00126
00127
00128 return new AFRaw(this);
00129 }
00130
00131
00132
00133 VOID CAudioFile::txhGetName( const CHAR *fName )
00134 {
00135 #define IFEXT_2EXT(ext1,ext2) if (!stricmp(ext,ext1)) dest2 = path_src2destp(dest,"",ext2)
00136 CHAR *dest = path_src2destp(fName,myOpts.val(CAUDIO_TXHNAME,""),
00137 myOpts.val(CAUDIO_TXHRULE,""));
00138
00139
00140 const CHAR *ext = fName+path_extpos(fName);
00141 if (!stricmp(ext, dest+path_extpos(dest))) {
00142 CHAR *dest2=0;
00143 BOOL inc=FALSE;
00144
00145 IFEXT_2EXT(".pcm",".inf");
00146 else IFEXT_2EXT(".raw",".hdr");
00147 else IFEXT_2EXT(".wav",".wai");
00148 else IFEXT_2EXT(".tei",".teh");
00149 else IFEXT_2EXT(".aho",".ahi");
00150 else IFEXT_2EXT(".eus",".eui");
00151 else IFEXT_2EXT(".inf",".nfo");
00152 else IFEXT_2EXT(".nist",".nish");
00153 else IFEXT_2EXT(".nis",".nih");
00154 else IFEXT_2EXT(".hak",".hai");
00155
00156 else IFEXT_2EXT(".",".dat");
00157 else IFEXT_2EXT("",".dot");
00158 else {
00159 assert(strlen(dest));
00160 (*(dest+strlen(dest)-1))++;
00161 inc=TRUE;
00162 }
00163 if (!inc) { xfree(dest); dest=dest2; }
00164 }
00165
00166 myOpts.add(CAUDIO_TXHNAME,dest),
00167 xfree(dest);
00168 }
00169
00170