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

Compare commits

...

4 Commits

2 changed files with 21 additions and 25 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

@@ -18,75 +18,70 @@
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(FILE* 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;
fread(&sampLen, sizeof(uint32_t), 1, file); 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;
fread(&dummy, sizeof(uint64_t), 1, file); fread(&dummy, sizeof(uint64_t), 1, fin);
// Read adpcm data. // Read adpcm data.
fread(a_out.data(), sizeof(uint8_t), sampLen, file); fread(buf.data(), sizeof(uint8_t), sampLen, fin);
}
void DumpBytes(std::string a_path, const std::vector<uint8_t>& a_bytes) FILE* fout = fopen(name.c_str(), "wb");
{ if (!fout)
std::ofstream fileOut(a_path, std::ios::binary); return;
fileOut.write((const char*)a_bytes.data(), a_bytes.size());
fileOut.close(); fwrite(buf.data(), sizeof(uint8_t), buf.size(), fout);
fclose(fout);
} }
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.
FILE* file = fopen(argv[1], "rb"); FILE* file = fopen(argv[1], "rb");
if (!file) 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 smpaCount = 0, smpbCount = 0; int smpaCount = 0, smpbCount = 0;
while (!feof(file) && !ferror(file)) while (!feof(file) && !ferror(file))
{ {
if (fgetc(file) != 0x67 && if (fgetc(file) != 0x67 || fgetc(file) != 0x66)
fgetc(file) != 0x66)
continue; continue;
uint8_t byte = fgetc(file); uint8_t byte = fgetc(file);
if (byte == 0x82) if (byte == 0x82)
{ {
std::cout << "ADPCM-A data found at 0x" << std::hex << ftell(file) << std::endl; printf("ADPCM-A data found at 0x%08lX\n", ftell(file));
DecodeSample(file, smpBytes);
std::stringstream path; std::stringstream path;
path << std::hex << "smpa_" << (smpaCount++) << ".pcm"; path << std::hex << "smpa_" << (smpaCount++) << ".pcm";
DumpBytes(path.str(), smpBytes); DecodeSample(file, path.str(), smpBytes);
} }
else if (byte == 0x83) else if (byte == 0x83)
{ {
std::cout << "ADPCM-B data found at 0x" << std::hex << ftell(file) << std::endl; printf("ADPCM-B data found at 0x%08lX\n", ftell(file));
DecodeSample(file, smpBytes);
std::stringstream path; std::stringstream path;
path << std::hex << "smpb_" << (smpbCount++) << ".pcm"; path << std::hex << "smpb_" << (smpbCount++) << ".pcm";
DumpBytes(path.str(), smpBytes); DecodeSample(file, path.str(), smpBytes);
} }
} }