mirror of
https://github.com/ScrelliCopter/VGM-Tools
synced 2025-02-21 04:09:25 +11:00
Compare commits
7 Commits
b12258970e
...
6510096f90
| Author | SHA1 | Date | |
|---|---|---|---|
| 6510096f90 | |||
| 07ee0b546c | |||
| 454fcd3226 | |||
| c94016e793 | |||
| 172174c837 | |||
| 3fafdfd3f4 | |||
| 6ccf9f6e38 |
@@ -1,11 +1,11 @@
|
|||||||
TARGET := neoadpcmextract
|
TARGET := neoadpcmextract
|
||||||
SOURCE := neoadpcmextract.cpp
|
SOURCE := neoadpcmextract.c
|
||||||
CXXFLAGS := -O2 -pipe -Wall -Wextra -pedantic
|
CFLAGS := -std=c99 -O2 -pipe -Wall -Wextra -pedantic
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
$(TARGET): $(SOURCE)
|
$(TARGET): $(SOURCE)
|
||||||
$(CXX) $(CXXFLAGS) $< -o $@
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -18,35 +18,42 @@
|
|||||||
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 <string>
|
#include <stdio.h>
|
||||||
#include <sstream>
|
#include <stdlib.h>
|
||||||
#include <vector>
|
#include <stdint.h>
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
void DecodeSample(FILE* fin, const std::string& name, std::vector <uint8_t>& buf)
|
|
||||||
|
typedef struct { uint8_t* data; size_t size; } Buffer;
|
||||||
|
|
||||||
|
void DecodeSample(FILE* fin, const char* name, Buffer* buf)
|
||||||
{
|
{
|
||||||
// Set up output vector.
|
// Get sample data length.
|
||||||
uint32_t sampLen = 0;
|
uint32_t sampLen = 0;
|
||||||
fread(&sampLen, sizeof(uint32_t), 1, fin);
|
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);
|
||||||
buf.clear();
|
|
||||||
buf.resize(sampLen);
|
// Resize buffer if needed.
|
||||||
|
if (!buf->data || buf->size < sampLen)
|
||||||
|
{
|
||||||
|
free(buf->data);
|
||||||
|
buf->data = malloc(sampLen);
|
||||||
|
buf->size = sampLen;
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore 8 bytes.
|
// Ignore 8 bytes.
|
||||||
uint64_t dummy;
|
uint64_t dummy;
|
||||||
fread(&dummy, sizeof(uint64_t), 1, fin);
|
fread(&dummy, sizeof(uint64_t), 1, fin);
|
||||||
|
|
||||||
// Read adpcm data.
|
// Read adpcm data.
|
||||||
fread(buf.data(), sizeof(uint8_t), sampLen, fin);
|
fread(buf->data, sizeof(uint8_t), sampLen, fin);
|
||||||
|
|
||||||
FILE* fout = fopen(name.c_str(), "wb");
|
FILE* fout = fopen(name, "wb");
|
||||||
if (!fout)
|
if (!fout)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fwrite(buf.data(), sizeof(uint8_t), buf.size(), fout);
|
fwrite(buf->data, sizeof(uint8_t), sampLen, fout);
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +68,8 @@ int main(int argc, char** argv)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// Search for pcm headers.
|
// Search for pcm headers.
|
||||||
std::vector<uint8_t> smpBytes;
|
Buffer smpBytes = {NULL, 0};
|
||||||
|
char namebuf[32];
|
||||||
int smpaCount = 0, smpbCount = 0;
|
int smpaCount = 0, smpbCount = 0;
|
||||||
while (!feof(file) && !ferror(file))
|
while (!feof(file) && !ferror(file))
|
||||||
{
|
{
|
||||||
@@ -72,19 +80,18 @@ int main(int argc, char** argv)
|
|||||||
if (byte == 0x82)
|
if (byte == 0x82)
|
||||||
{
|
{
|
||||||
printf("ADPCM-A data found at 0x%08lX\n", ftell(file));
|
printf("ADPCM-A data found at 0x%08lX\n", ftell(file));
|
||||||
std::stringstream path;
|
snprintf(namebuf, sizeof(namebuf), "smpa_%x.pcm", smpaCount++);
|
||||||
path << std::hex << "smpa_" << (smpaCount++) << ".pcm";
|
DecodeSample(file, namebuf, &smpBytes);
|
||||||
DecodeSample(file, path.str(), smpBytes);
|
|
||||||
}
|
}
|
||||||
else if (byte == 0x83)
|
else if (byte == 0x83)
|
||||||
{
|
{
|
||||||
printf("ADPCM-B data found at 0x%08lX\n", ftell(file));
|
printf("ADPCM-B data found at 0x%08lX\n", ftell(file));
|
||||||
std::stringstream path;
|
snprintf(namebuf, sizeof(namebuf), "smpb_%x.pcm", smpbCount++);
|
||||||
path << std::hex << "smpb_" << (smpbCount++) << ".pcm";
|
DecodeSample(file, namebuf, &smpBytes);
|
||||||
DecodeSample(file, path.str(), smpBytes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(smpBytes.data);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user