1
0
mirror of https://github.com/ScrelliCopter/VGM-Tools synced 2025-02-21 04:09:25 +11:00

Compare commits

6 Commits

Author SHA1 Message Date
b12258970e replace cout with printf 2019-09-30 23:17:47 +10:00
886966d7dc merge DecodeSample & DumpBytes 2019-09-30 20:43:07 +10:00
63aacb9a01 FILE io for DumpBytes 2019-09-30 20:33:58 +10:00
7c66bbab52 fix some error prone stuff, also I goofed the short circuit... oops 2019-09-30 17:14:07 +10:00
fbf887b534 c io for input 2019-09-29 11:51:14 +10:00
0a26bc8998 reformat 2019-09-28 10:18:39 +10:00
3 changed files with 42 additions and 60 deletions

View File

@@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
set -e
FILE="$1" FILE="$1"
NAME="$(basename "$FILE")" NAME="$(basename "$FILE")"
@@ -6,7 +7,7 @@ WAVDIR="${NAME%%.*}"
if [ "${NAME##*.}" = "vgz" ]; then if [ "${NAME##*.}" = "vgz" ]; then
cp "$FILE" "temp.vgm.gz" cp "$FILE" "temp.vgm.gz"
gzip -d "temp.vgm.gz" gzip -fd "temp.vgm.gz"
FILE="temp.vgm" FILE="temp.vgm"
fi fi

View File

@@ -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)

View File

@@ -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
@@ -18,92 +18,73 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include <iostream>
#include <fstream>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <cstdint> #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. // 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, fin);
if ( sampLen < sizeof(uint64_t) ) if (sampLen < sizeof(uint64_t))
{
return; return;
}
sampLen -= sizeof(uint64_t); sampLen -= sizeof(uint64_t);
a_out.clear (); buf.clear();
a_out.resize ( sampLen ); buf.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, fin);
// Read adpcm data. // 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 ); if (argc != 2)
fileOut.write ( (const char*)a_bytes.data (), a_bytes.size () ); return 1;
fileOut.close ();
}
int main ( int argc, char** argv )
{
if ( argc != 2 )
{
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; printf("ADPCM-A data found at 0x%08lX\n", ftell(file));
if ( byte == 0x66 ) std::stringstream path;
{ path << std::hex << "smpa_" << (smpaCount++) << ".pcm";
file >> byte; DecodeSample(file, path.str(), smpBytes);
if ( byte == 0x82 ) }
{ else if (byte == 0x83)
std::cout << "ADPCM-A data found at 0x" << std::hex << file.tellg () << std::endl; {
DecodeSample ( file, smpBytes ); printf("ADPCM-B data found at 0x%08lX\n", ftell(file));
std::stringstream path; std::stringstream path;
path << std::hex << "smpa_" << (smpA++) << ".pcm"; path << std::hex << "smpb_" << (smpbCount++) << ".pcm";
DumpBytes ( path.str (), smpBytes ); DecodeSample(file, 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 );
}
}
} }
} }
file.close (); fclose(file);
return 0; return 0;
} }