|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
/* neoadpcmextract.cpp
|
|
|
|
|
Copyright (C) 2017 Nicholas Curtis
|
|
|
|
|
Copyright (C) 2017, 2019 Nicholas Curtis
|
|
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
@@ -18,92 +18,73 @@
|
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
|
|
void DecodeSample ( std::ifstream& a_file, std::vector<uint8_t>& a_out )
|
|
|
|
|
void DecodeSample(FILE* fin, const std::string& name, std::vector <uint8_t>& buf)
|
|
|
|
|
{
|
|
|
|
|
// Set up output vector.
|
|
|
|
|
uint32_t sampLen = 0;
|
|
|
|
|
a_file.read ( (char*)&sampLen, sizeof(uint32_t) );
|
|
|
|
|
if ( sampLen < sizeof(uint64_t) )
|
|
|
|
|
{
|
|
|
|
|
fread(&sampLen, sizeof(uint32_t), 1, fin);
|
|
|
|
|
if (sampLen < sizeof(uint64_t))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sampLen -= sizeof(uint64_t);
|
|
|
|
|
a_out.clear ();
|
|
|
|
|
a_out.resize ( sampLen );
|
|
|
|
|
buf.clear();
|
|
|
|
|
buf.resize(sampLen);
|
|
|
|
|
|
|
|
|
|
// Ignore 8 bytes.
|
|
|
|
|
uint64_t dummy;
|
|
|
|
|
a_file.read ( (char*)&dummy, sizeof(uint64_t) );
|
|
|
|
|
fread(&dummy, sizeof(uint64_t), 1, fin);
|
|
|
|
|
|
|
|
|
|
// Read adpcm data.
|
|
|
|
|
a_file.read ( (char*)a_out.data (), sampLen );
|
|
|
|
|
fread(buf.data(), sizeof(uint8_t), sampLen, fin);
|
|
|
|
|
|
|
|
|
|
FILE* fout = fopen(name.c_str(), "wb");
|
|
|
|
|
if (!fout)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
fwrite(buf.data(), sizeof(uint8_t), buf.size(), fout);
|
|
|
|
|
fclose(fout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DumpBytes ( std::string a_path, const std::vector<uint8_t>& a_bytes )
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
|
|
|
|
std::ofstream fileOut ( a_path, std::ios::binary );
|
|
|
|
|
fileOut.write ( (const char*)a_bytes.data (), a_bytes.size () );
|
|
|
|
|
fileOut.close ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main ( int argc, char** argv )
|
|
|
|
|
{
|
|
|
|
|
if ( argc != 2 )
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (argc != 2)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
// Open file.
|
|
|
|
|
std::ifstream file ( argv[1], std::ios::binary );
|
|
|
|
|
if ( !file.is_open () )
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
FILE* file = fopen(argv[1], "rb");
|
|
|
|
|
if (!file)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
// Search for pcm headers.
|
|
|
|
|
std::vector<uint8_t> smpBytes;
|
|
|
|
|
int smpA = 0, smpB = 0;
|
|
|
|
|
while ( !file.eof () && !file.fail () )
|
|
|
|
|
int smpaCount = 0, smpbCount = 0;
|
|
|
|
|
while (!feof(file) && !ferror(file))
|
|
|
|
|
{
|
|
|
|
|
uint8_t byte;
|
|
|
|
|
if (fgetc(file) != 0x67 || fgetc(file) != 0x66)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
file >> byte;
|
|
|
|
|
if ( byte == 0x67 )
|
|
|
|
|
uint8_t byte = fgetc(file);
|
|
|
|
|
if (byte == 0x82)
|
|
|
|
|
{
|
|
|
|
|
file >> byte;
|
|
|
|
|
if ( byte == 0x66 )
|
|
|
|
|
{
|
|
|
|
|
file >> byte;
|
|
|
|
|
if ( byte == 0x82 )
|
|
|
|
|
{
|
|
|
|
|
std::cout << "ADPCM-A data found at 0x" << std::hex << file.tellg () << std::endl;
|
|
|
|
|
DecodeSample ( file, smpBytes );
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << std::hex << "smpa_" << (smpA++) << ".pcm";
|
|
|
|
|
DumpBytes ( path.str (), smpBytes );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if ( byte == 0x83 )
|
|
|
|
|
{
|
|
|
|
|
std::cout << "ADPCM-B data found at 0x" << std::hex << file.tellg () << std::endl;
|
|
|
|
|
DecodeSample ( file, smpBytes );
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << std::hex << "smpb_" << (smpB++) << ".pcm";
|
|
|
|
|
DumpBytes ( path.str (), smpBytes );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("ADPCM-A data found at 0x%08lX\n", ftell(file));
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << std::hex << "smpa_" << (smpaCount++) << ".pcm";
|
|
|
|
|
DecodeSample(file, path.str(), smpBytes);
|
|
|
|
|
}
|
|
|
|
|
else if (byte == 0x83)
|
|
|
|
|
{
|
|
|
|
|
printf("ADPCM-B data found at 0x%08lX\n", ftell(file));
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << std::hex << "smpb_" << (smpbCount++) << ".pcm";
|
|
|
|
|
DecodeSample(file, path.str(), smpBytes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.close ();
|
|
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|