mirror of
https://github.com/ScrelliCopter/VGM-Tools
synced 2025-02-21 04:09:25 +11:00
Compare commits
2 Commits
v0.2.0
...
fbf887b534
| Author | SHA1 | Date | |
|---|---|---|---|
| fbf887b534 | |||
| 0a26bc8998 |
@@ -1,6 +1,6 @@
|
|||||||
TARGET := neoadpcmextract
|
TARGET := neoadpcmextract
|
||||||
SOURCE := neoadpcmextract.cpp
|
SOURCE := neoadpcmextract.cpp
|
||||||
CXXFLAGS := -O2 -pipe -Wall -Wextra
|
CXXFLAGS := -O2 -pipe -Wall -Wextra -pedantic
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* neoadpcmextract.cpp
|
/* neoadpcmextract.cpp
|
||||||
Copyright (C) 2017 Nicholas Curtis
|
Copyright (C) 2017, 2019 Nicholas Curtis
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -25,85 +25,71 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
void DecodeSample ( std::ifstream& a_file, std::vector<uint8_t>& a_out )
|
void DecodeSample(FILE* file, std::vector <uint8_t>& a_out)
|
||||||
{
|
{
|
||||||
// Set up output vector.
|
// Set up output vector.
|
||||||
uint32_t sampLen = 0;
|
uint32_t sampLen = 0;
|
||||||
a_file.read ( (char*)&sampLen, sizeof(uint32_t) );
|
fread(&sampLen, sizeof(uint32_t), 1, file);
|
||||||
if ( sampLen < sizeof(uint64_t) )
|
if (sampLen < sizeof(uint64_t))
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
sampLen -= sizeof(uint64_t);
|
sampLen -= sizeof(uint64_t);
|
||||||
a_out.clear ();
|
a_out.clear();
|
||||||
a_out.resize ( sampLen );
|
a_out.resize(sampLen);
|
||||||
|
|
||||||
// Ignore 8 bytes.
|
// Ignore 8 bytes.
|
||||||
uint64_t dummy;
|
uint64_t dummy;
|
||||||
a_file.read ( (char*)&dummy, sizeof(uint64_t) );
|
fread(&dummy, sizeof(uint64_t), 1, file);
|
||||||
|
|
||||||
// Read adpcm data.
|
// Read adpcm data.
|
||||||
a_file.read ( (char*)a_out.data (), sampLen );
|
fread(a_out.data(), sizeof(uint8_t), sampLen, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DumpBytes ( std::string a_path, const std::vector<uint8_t>& a_bytes )
|
void DumpBytes(std::string a_path, const std::vector<uint8_t>& a_bytes)
|
||||||
{
|
{
|
||||||
std::ofstream fileOut ( a_path, std::ios::binary );
|
std::ofstream fileOut(a_path, std::ios::binary);
|
||||||
fileOut.write ( (const char*)a_bytes.data (), a_bytes.size () );
|
fileOut.write((const char*)a_bytes.data(), a_bytes.size());
|
||||||
fileOut.close ();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main ( int argc, char** argv )
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if ( argc != 2 )
|
if (argc != 2)
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
// Open file.
|
// Open file.
|
||||||
std::ifstream file ( argv[1], std::ios::binary );
|
FILE* file = fopen(argv[1], "rb");
|
||||||
if ( !file.is_open () )
|
if (!file)
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
// Search for pcm headers.
|
// Search for pcm headers.
|
||||||
std::vector<uint8_t> smpBytes;
|
std::vector<uint8_t> smpBytes;
|
||||||
int smpA = 0, smpB = 0;
|
int smpaCount = 0, smpbCount = 0;
|
||||||
while ( !file.eof () && !file.fail () )
|
while (!feof(file) && !ferror(file))
|
||||||
{
|
{
|
||||||
uint8_t byte;
|
if (fgetc(file) != 0x67 &&
|
||||||
|
fgetc(file) != 0x66)
|
||||||
|
continue;
|
||||||
|
|
||||||
file >> byte;
|
uint8_t byte = fgetc(file);
|
||||||
if ( byte == 0x67 )
|
if (byte == 0x82)
|
||||||
{
|
{
|
||||||
file >> byte;
|
std::cout << "ADPCM-A data found at 0x" << std::hex << ftell(file) << std::endl;
|
||||||
if ( byte == 0x66 )
|
DecodeSample(file, smpBytes);
|
||||||
{
|
std::stringstream path;
|
||||||
file >> byte;
|
path << std::hex << "smpa_" << (smpaCount++) << ".pcm";
|
||||||
if ( byte == 0x82 )
|
DumpBytes(path.str(), smpBytes);
|
||||||
{
|
}
|
||||||
std::cout << "ADPCM-A data found at 0x" << std::hex << file.tellg () << std::endl;
|
else if (byte == 0x83)
|
||||||
DecodeSample ( file, smpBytes );
|
{
|
||||||
std::stringstream path;
|
std::cout << "ADPCM-B data found at 0x" << std::hex << ftell(file) << std::endl;
|
||||||
path << std::hex << "smpa_" << (smpA++) << ".pcm";
|
DecodeSample(file, smpBytes);
|
||||||
DumpBytes ( path.str (), smpBytes );
|
std::stringstream path;
|
||||||
}
|
path << std::hex << "smpb_" << (smpbCount++) << ".pcm";
|
||||||
else
|
DumpBytes(path.str(), smpBytes);
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close ();
|
fclose(file);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user