| 270 | cycrow | 1 | /*
 | 
        
           |  |  | 2 |  Voice file Creation V1.00 Created by Cycrow (Matthew Gravestock)
 | 
        
           |  |  | 3 | */
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 | // Main Spk File Library Include
 | 
        
           |  |  | 6 | #ifdef _WIN32
 | 
        
           |  |  | 7 | #include <spk.h>
 | 
        
           |  |  | 8 | #include <StringList.h>
 | 
        
           |  |  | 9 | #else
 | 
        
           |  |  | 10 | #include "../spk/spk.h"
 | 
        
           |  |  | 11 | #endif
 | 
        
           |  |  | 12 | #include <time.h>
 | 
        
           |  |  | 13 |   | 
        
           |  |  | 14 | #ifdef _WIN32
 | 
        
           |  |  | 15 | #include <windows.h>
 | 
        
           |  |  | 16 | #include <direct.h>
 | 
        
           |  |  | 17 | #include <shlobj.h>
 | 
        
           |  |  | 18 | #endif
 | 
        
           |  |  | 19 |   | 
        
           |  |  | 20 | #include "sndfile.hh"
 | 
        
           |  |  | 21 |   | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 | void PrintSyntax (const Utils::WString &cmd)
 | 
        
           |  |  | 24 | {
 | 
        
           |  |  | 25 | 	/*
 | 
        
           |  |  | 26 | 	printf ( "Syntax: %s %s </command> [arguments]\n", cmd.c_str(), FLAGS );
 | 
        
           |  |  | 27 | 	printf ( "\nCommands:\n" );
 | 
        
           |  |  | 28 | 	printf ( "   /list\n\t- Lists installed packages\n" );
 | 
        
           |  |  | 29 | 	printf ( "   /install <file>\n\t- Installs a package file\n" );
 | 
        
           |  |  | 30 | 	printf ( "   /uninstall <package#>\n\t- Uninstalls a package, use id number from list\n" );
 | 
        
           |  |  | 31 | 	printf ( "   /enable <package#>\n\t- Enables an installed package\n" );
 | 
        
           |  |  | 32 | 	printf ( "   /disable <package#>\n\t- Disables an installed package\n" );
 | 
        
           |  |  | 33 | 	printf ( "   /removeuninstall\n\t- Removes uninstall scripts\n" );
 | 
        
           |  |  | 34 | 	printf ( "   /removeshared\n\t- Removes unused sharded files\n" );
 | 
        
           |  |  | 35 | 	printf ( "\nSwitchs:\n" );
 | 
        
           |  |  | 36 | 	printf ( "   -d (--directory) [directory]\n\tChange destination directory, otherwise uses current\n\n" );
 | 
        
           |  |  | 37 | 	printf ( "   -v (--verbose)\n\tTurns on verbose mode\n\n" );
 | 
        
           |  |  | 38 | 	printf ( "   -o (--override)\n\tOverride install warnings\n\tIE. allows you to install older scripts\n\n" );
 | 
        
           |  |  | 39 | 	printf ( "   -t (--textrename)\n\tForces text file renaming for installed packages\n\n" );
 | 
        
           |  |  | 40 | 	printf ( "   -l (--language) <language>\n\tSets the language id for text file renaming\n\totheriwse reads game lang.dat\n\n" );
 | 
        
           |  |  | 41 | 	printf ( "   -c (--enablechild)\n\tAuto Enabled all children when parent is enabled\n\n" );
 | 
        
           |  |  | 42 | 	printf ( "   -m (--forcemod\n\tForces a mod enabled even if theres one already enabled\n\n" );
 | 
        
           |  |  | 43 | 	*/
 | 
        
           |  |  | 44 | }
 | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 | void Pause()
 | 
        
           |  |  | 47 | {
 | 
        
           |  |  | 48 | #ifdef _DEBUG
 | 
        
           |  |  | 49 | 	char pause;
 | 
        
           |  |  | 50 | 	scanf ( "%s", &pause );
 | 
        
           |  |  | 51 | #endif
 | 
        
           |  |  | 52 | }
 | 
        
           |  |  | 53 |   | 
        
           |  |  | 54 | #define BUFFER_LEN 4096
 | 
        
           |  |  | 55 | /*
 | 
        
           |  |  | 56 | 	Main entry point to program
 | 
        
           |  |  | 57 | */
 | 
        
           |  |  | 58 | int main ( int argc, char **argv )
 | 
        
           |  |  | 59 | {
 | 
        
           |  |  | 60 |  	// display program header to command prompt
 | 
        
           |  |  | 61 | 	printf ( "\nX3 Voice Create V1.00 (SPK Library Version %.2f) 15/12/2023 Created by Cycrow\n\n", GetLibraryVersion() );
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 | 	// parse the cmd name
 | 
        
           |  |  | 64 | 	Utils::WString cmd (argv[0]);
 | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 | 	Utils::String mainFileStr = "d:/x/X3 Terran Conflict - Guilds/addon2/mov/00344.wav";
 | 
        
           |  |  | 67 | 	Utils::WString dir = L"d:/x/X3 Terran Conflict - Guilds/addon2/mov/working";
 | 
        
           |  |  | 68 | 	Utils::String output = "d:/x/X3 Terran Conflict - Guilds/addon2/mov/working/00344.wav";
 | 
        
           |  |  | 69 | 	Utils::WString outputXML = L"d:/x/X3 Terran Conflict - Guilds/addon2/mov/working/00044.xml";
 | 
        
           |  |  | 70 |   | 
        
           |  |  | 71 | 	SF_INFO info;
 | 
        
           |  |  | 72 | 	SNDFILE* mainFile = sf_open(mainFileStr.c_str(), SFM_READ, &info);
 | 
        
           |  |  | 73 | 	if (mainFile) 
 | 
        
           |  |  | 74 | 	{
 | 
        
           |  |  | 75 | 		double duration = static_cast<double>(info.frames) / static_cast<double>(info.samplerate);
 | 
        
           |  |  | 76 | 		size_t currentPos = static_cast<size_t>((duration * 1000.0) + 0.5);
 | 
        
           |  |  | 77 |   | 
        
           |  |  | 78 | 		CFileIO(mainFileStr).copy(output);
 | 
        
           |  |  | 79 |   | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 | 		SF_INFO outInfo;
 | 
        
           |  |  | 82 | 		SNDFILE* outputFile = sf_open(output.c_str(), SFM_RDWR, &outInfo);
 | 
        
           |  |  | 83 | 		if (outputFile) 
 | 
        
           |  |  | 84 | 		{
 | 
        
           |  |  | 85 | 			double buffer[BUFFER_LEN];
 | 
        
           |  |  | 86 |   | 
        
           |  |  | 87 | 			int check = sf_format_check(&outInfo);
 | 
        
           |  |  | 88 | 			sf_count_t seek = sf_seek(outputFile, 0, SEEK_END);
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 | 			Utils::WStringList xmlOut;
 | 
        
           |  |  | 91 | 			xmlOut.pushBack(L"<?xml version=\"1.0\" ?>");
 | 
        
           |  |  | 92 | 			xmlOut.pushBack(L"<language id=\"44\">");
 | 
        
           |  |  | 93 |   | 
        
           |  |  | 94 | 			CDirIO D(dir);
 | 
        
           |  |  | 95 | 			Utils::WStringList list;
 | 
        
           |  |  | 96 | 			if (D.dirList(list))
 | 
        
           |  |  | 97 | 			{
 | 
        
           |  |  | 98 | 				for (auto itr = list.begin(); itr != list.end(); itr++)
 | 
        
           |  |  | 99 | 				{
 | 
        
           |  |  | 100 | 					if (D.isDir((*itr)->str)) 
 | 
        
           |  |  | 101 | 					{
 | 
        
           |  |  | 102 | 						CDirIO curDir(D.dir((*itr)->str));
 | 
        
           |  |  | 103 | 						long pageID = (*itr)->str.toInt();
 | 
        
           |  |  | 104 |   | 
        
           |  |  | 105 | 						xmlOut.pushBack(Utils::WString(L"<page id=\"") + pageID + L"\" stream=\"3\">");
 | 
        
           |  |  | 106 |   | 
        
           |  |  | 107 | 						Utils::WStringList idList;
 | 
        
           |  |  | 108 | 						if (curDir.dirList(idList)) 
 | 
        
           |  |  | 109 | 						{
 | 
        
           |  |  | 110 | 							for (auto itr2 = idList.begin(); itr2 != idList.end(); itr2++)
 | 
        
           |  |  | 111 | 							{
 | 
        
           |  |  | 112 | 								if (curDir.isFile((*itr2)->str))
 | 
        
           |  |  | 113 | 								{
 | 
        
           |  |  | 114 | 									CFileIO F(curDir.file((*itr2)->str));
 | 
        
           |  |  | 115 | 									long id = F.baseName().toInt();
 | 
        
           |  |  | 116 | 									size_t len = 0;
 | 
        
           |  |  | 117 |   | 
        
           |  |  | 118 | 									SF_INFO inInfo;
 | 
        
           |  |  | 119 | 									SNDFILE* inputFile = sf_open(F.fullFilename().toString().c_str(), SFM_READ, &inInfo);
 | 
        
           |  |  | 120 | 									if (inputFile)
 | 
        
           |  |  | 121 | 									{
 | 
        
           |  |  | 122 | 										double duration = static_cast<double>(inInfo.frames) / static_cast<double>(inInfo.samplerate);
 | 
        
           |  |  | 123 | 										size_t len = static_cast<size_t>((duration * 1000.0) + 0.5);
 | 
        
           |  |  | 124 |   | 
        
           |  |  | 125 |   | 
        
           |  |  | 126 | 										sf_count_t readcount;
 | 
        
           |  |  | 127 | 										while ((readcount = sf_read_double(inputFile, buffer, BUFFER_LEN)) > 0)
 | 
        
           |  |  | 128 | 											sf_write_double(outputFile, buffer, readcount);
 | 
        
           |  |  | 129 | 										//int* data = new int[inInfo.frames * inInfo.channels];
 | 
        
           |  |  | 130 | 										//sf_count_t readCount = sf_readf_int(inputFile, data, inInfo.frames);
 | 
        
           |  |  | 131 | 										//sf_count_t writeCount = sf_writef_int(outputFile, data, inInfo.frames);
 | 
        
           |  |  | 132 |   | 
        
           |  |  | 133 | 										xmlOut.pushBack(Utils::WString(L"\t<t id=\"") + id + L"\" s=\"" + (long)currentPos + L"\" l=\"" + (long)len + "\"/>");
 | 
        
           |  |  | 134 | 										currentPos += len;
 | 
        
           |  |  | 135 | 										sf_close(inputFile);
 | 
        
           |  |  | 136 | 									}
 | 
        
           |  |  | 137 | 								}
 | 
        
           |  |  | 138 | 							}
 | 
        
           |  |  | 139 | 						}
 | 
        
           |  |  | 140 |   | 
        
           |  |  | 141 | 						xmlOut.pushBack(L"</page>");
 | 
        
           |  |  | 142 | 					}
 | 
        
           |  |  | 143 | 				}
 | 
        
           |  |  | 144 | 			}
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 | 			xmlOut.pushBack("</language>");
 | 
        
           |  |  | 147 |   | 
        
           |  |  | 148 | 			sf_close(outputFile);
 | 
        
           |  |  | 149 |   | 
        
           |  |  | 150 | 			CFileIO xml(outputXML);
 | 
        
           |  |  | 151 | 			xml.writeFile(&xmlOut);
 | 
        
           |  |  | 152 | 		}
 | 
        
           |  |  | 153 |   | 
        
           |  |  | 154 | 		sf_close(mainFile);
 | 
        
           |  |  | 155 | 	}
 | 
        
           |  |  | 156 | 	//Pause();
 | 
        
           |  |  | 157 |   | 
        
           |  |  | 158 | 	return 0;
 | 
        
           |  |  | 159 | }
 |