void WinePathToUnix(String* Dest, String* Sorc, String* WineDir) { int i; String TempStr; String_Ctor(& TempStr); if(Sorc -> Data[1] != ':') { String_From(Dest, Sorc); String_Dtor(& TempStr); return; } for(i = 0; i < String_GetLength(Sorc); i ++) if(Sorc -> Data[i] == '\\') Sorc -> Data[i] = '/'; if(Sorc -> Data[0] == 'Z') { MidFrom(Dest, Sorc, 2); }else { char DriveNo[2]; DriveNo[0] = tolower(Sorc -> Data[0]); DriveNo[1] = '\0'; String_From(Dest, WineDir); String_JoinChars(Dest, "/drive_"); String_JoinChars(Dest, (char*)DriveNo); MidFrom(& TempStr, Sorc, 2); String_Join(Dest, & TempStr); } String_Dtor(& TempStr); }
string_t *String_JoinDirect(string_t *str1, const char *str2) { string_t ret = String_Join(str1->c_str, str2); free(str1->c_str); str1->c_str = ret.c_str; return str1; }
int main(int ArgN, char** Arg) { int RegenFlag = 0; char* CWaveFile = NULL; char* CLabelFile = NULL; char* CRecFile = NULL; char* CRegenFile = "RegeneratedTrack.txt"; int c; while((c = getopt(ArgN, Arg, "r")) != -1) { switch(c) { case 'r': RegenFlag = 1; break; case '?': printf("Usage: rsegment [-r] " "[-h] wavfile labelfile recfile\n"); return 1; default: abort(); } } int i; for(i = optind; i < ArgN; i ++) { switch(i - optind) { case 0: CWaveFile = Arg[i]; break; case 1: CLabelFile = Arg[i]; break; case 2: CRecFile = Arg[i]; break; default: fprintf(stderr, "Warning: redundant argument '%s'.\n", Arg[i]); } } if(! CWaveFile) { fprintf(stderr, "Missing argument 'wavfile'.\n"); return 1; } if(! CLabelFile) { fprintf(stderr, "Missing argument 'labelfile'.\n"); return 1; } if(! CRecFile) { fprintf(stderr, "Missing argument 'recfile'.\n"); return 1; } Wave SorcWave; File LabelFile; File RecFile; File RegenFile; String WavePath, LabelPath, RecPath, RegenPath; RNew(String, & WavePath, & LabelPath, & RecPath, & RegenPath); RNew(File, & LabelFile, & RecFile, & RegenFile); RCall(Wave, Ctor)(& SorcWave); String_SetChars(& WavePath, CWaveFile); String_SetChars(& LabelPath, CLabelFile); String_SetChars(& RecPath, CRecFile); String_SetChars(& RegenPath, CRegenFile); if(! RCall(Wave, FromFile)(& SorcWave, & WavePath)) { fprintf(stderr, "Cannot load wave file.\n"); return 1; } if(! File_Open(& LabelFile, & LabelPath, READONLY)) { fprintf(stderr, "Cannot load label file.\n"); return 1; } if(! File_Open(& RecFile, & RecPath, READONLY)) { fprintf(stderr, "Cannot load word table.\n"); return 1; } if(RegenFlag) { if(! File_Open(& RegenFile, & RegenPath, CREATE)) { fprintf(stderr, "Cannot create '%s'.\n", CRegenFile); return 1; } } Array_Ctor(String, RecList); Array_Ctor(int, SegList); ParseRecFile(& RecFile); ParseLabelFile(& LabelFile, SorcWave.SampleRate); Wave SegWave; RCall(Wave, Ctor)(& SegWave); SegWave.SampleRate = SorcWave.SampleRate; String SegName, LineBuf, TempBuf; RNew(String, & SegName, & LineBuf, & TempBuf); for(i = 0; i <= SegList_Index; i ++) { int Start = SegList[i]; int End; if(i == SegList_Index) End = SorcWave.Size; else End = SegList[i + 1]; if(i > RecList_Index) { fprintf(stderr, "Insufficient records in word table.\n"); fprintf(stderr, "Segmentation aborted at %fs.\n", (float)Start / SorcWave.SampleRate); return 1; } String* Name = & RecList[i]; String_Copy(& SegName, Name); String_JoinChars(& SegName, ".wav"); if(! RegenFlag) { int Size = End - Start; Real* Data = RCall(RAlloc, Real)(Size); RCall(Wave, Read)(& SorcWave, Data, Start, Size); RCall(Wave, Resize)(& SegWave, Size); RCall(Wave, Write)(& SegWave, Data, 0, Size); if(! RCall(Wave, ToFile)(& SegWave, & SegName)) fprintf(stderr, "Exporting '%s' failed. Skipped.\n", String_GetChars(& SegName)); RFree(Data); } if(RegenFlag) { CStrFloat(& LineBuf, (float)SegList[i] / SorcWave.SampleRate); String_Copy(& TempBuf, & LineBuf); String_JoinChars(& LineBuf, "\t"); String_Join(& LineBuf, & TempBuf); String_JoinChars(& LineBuf, "\t"); String_Join(& LineBuf, Name); File_WriteLine(& RegenFile, & LineBuf); } } if(i <= RecList_Index) fprintf(stderr, "Warning: redundant records in word table starting from" " '%s'.\n", String_GetChars(& RecList[i])); if(RegenFlag) File_Flush(& RegenFile); File_Close(& RecFile); File_Close(& LabelFile); File_Close(& RegenFile); Array_ObjDtor(String, RecList); Array_Dtor(String, RecList); Array_Dtor(int, SegList); RDelete(& WavePath, & LabelPath, & RecPath, & RegenPath, & SegName, & LineBuf, & TempBuf); RDelete(& SorcWave, & LabelFile, & RecFile, & SegWave, & RegenFile); return 0; }