JD2022-TU1/main/extern/Raki/Source/RakiTests/TestBinPS3/TestBinPS3.cpp

168 lines
4.1 KiB
C++

#include "Precompiled.h"
#include "RakiEngine/Initializer/TestInitializer.h"
#include "RakiEngine/Data/MemoryBlock/MemoryBlock.h"
#include "RakiEngine/Data/Serialization/Serializer.h"
#include "RakiEngine/Data/Stream/SeekableStreamPart.h"
#include "RakiEngine/Data/WaveFile/RiffChunkManager.h"
#include "RakiEngine/Data/WaveFile/WaveFile.h"
#include "RakiEngine/Sounds/Format.h"
#include "RakiTests/Stream/BinFileReader.h"
#include "RakiTests/Stream/ReadFileStream.h"
#include "RakiTests/Stream/WriteFileStream.h"
#ifndef RAKI_PLATFORM_WIN32
#error // this is a bin test app - only for Win32
#endif // RAKI_PLATFORM_WIN32
namespace raki
{
bool MSEncCompress( const char * _inputPath, const char * _outputPath, const int _bitRate, const bool _loop )
{
STARTUPINFOA si = { 0 };
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
si.wShowWindow = SW_HIDE;//SW_SHOWNORMAL;
PROCESS_INFORMATION pi = { 0 };
char cmdLine[1024];
char msEncPath[] = "d:\\ps3\\tests\\MSEnc.exe";
// -fscomp -x -ignorewavloop
sprintf( cmdLine, "%s -in %s -out %s -mp3 %d %s -x -ignorewavloop",
msEncPath,
_inputPath,
_outputPath,
_bitRate,
_loop ? "-loop" : "");
// Start the child process.
if( !CreateProcessA( NULL, // No module name (use command line).
cmdLine, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
return false;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return true;
}
bool TestBinPS3( const char * _path )
{
TestInitializer initializer;
char msEncOutputPath[512];
sprintf( msEncOutputPath, "%s.msf", _path );
char finalBinPath[512];
sprintf( finalBinPath, "%s.riff", _path );
if ( !MSEncCompress( _path, msEncOutputPath, 192, false ) )
return false;
RiffChunkManager::singleton().setIsWritingToBigEndians( false );
RiffChunkManager::singleton().setShouldReadDataBlockForWaveData( false );
ReadFileStream inputStream;
if ( !inputStream.open( _path ) )
return false;
const char fmtType[] = "fmt ";
WaveFile inputWaveFile;
Serializer readSerializer( &inputStream );
inputWaveFile.serialize( readSerializer );
if ( !inputWaveFile.getChunkData( fmtType ) )
return false;
BinFileReader msEncFile;
if ( !msEncFile.readFrom( msEncOutputPath ) )
return false;
if ( !msEncFile.getData() )
return false;
WaveFile outputWaveFile;
outputWaveFile.createEmptyRiffChunk();
// add fmt chunk
outputWaveFile.addChunk( fmtType, inputWaveFile.getChunkSize( fmtType ), inputWaveFile.getChunkData( fmtType ) );
// add MSEnc data
outputWaveFile.addChunk( "msf ", (u32)msEncFile.getSize(), msEncFile.getData() );
outputWaveFile.recalculateRiffAndListSizes();
WriteFileStream outputFileStream;
if ( !outputFileStream.open( finalBinPath ) )
return false;
outputWaveFile.changeToBigEndian();
RiffChunkManager::singleton().setIsWritingToBigEndians( true );
Serializer writeSerializer( &outputFileStream );
outputWaveFile.serialize( writeSerializer );
if ( writeSerializer.encounteredError() )
return false;
DeleteFileA( msEncOutputPath );
return true;
}
} // namespace raki
int _tmain(int argc, _TCHAR* argv[] )
{
if ( argc < 2 )
return -1;
char path[512];
wcstombs( path, argv[1], 510 );
if ( !raki::TestBinPS3( path ) )
return -1;
return 0;
}