mirror of
https://github.com/ScrelliCopter/VGM-Tools
synced 2025-02-21 04:09:25 +11:00
merge DecodeSample & DumpBytes
This commit is contained in:
@@ -19,40 +19,36 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#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(const char* path, const std::vector<uint8_t>& a_bytes)
|
FILE* fout = fopen(name.c_str(), "wb");
|
||||||
{
|
if (!fout)
|
||||||
FILE* file = fopen(path, "wb");
|
|
||||||
if (!file)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fwrite(a_bytes.data(), sizeof(uint8_t), a_bytes.size(), file);
|
fwrite(buf.data(), sizeof(uint8_t), buf.size(), fout);
|
||||||
fclose(file);
|
fclose(fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
@@ -77,18 +73,16 @@ int main(int argc, char** argv)
|
|||||||
if (byte == 0x82)
|
if (byte == 0x82)
|
||||||
{
|
{
|
||||||
std::cout << "ADPCM-A data found at 0x" << std::hex << ftell(file) << std::endl;
|
std::cout << "ADPCM-A data found at 0x" << std::hex << ftell(file) << std::endl;
|
||||||
DecodeSample(file, smpBytes);
|
|
||||||
std::stringstream path;
|
std::stringstream path;
|
||||||
path << std::hex << "smpa_" << (smpaCount++) << ".pcm";
|
path << std::hex << "smpa_" << (smpaCount++) << ".pcm";
|
||||||
DumpBytes(path.str().c_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;
|
std::cout << "ADPCM-B data found at 0x" << std::hex << ftell(file) << std::endl;
|
||||||
DecodeSample(file, smpBytes);
|
|
||||||
std::stringstream path;
|
std::stringstream path;
|
||||||
path << std::hex << "smpb_" << (smpbCount++) << ".pcm";
|
path << std::hex << "smpb_" << (smpbCount++) << ".pcm";
|
||||||
DumpBytes(path.str().c_str(), smpBytes);
|
DecodeSample(file, path.str(), smpBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user