mirror of
https://github.com/ScrelliCopter/VGM-Tools
synced 2025-02-21 04:09:25 +11:00
Compare commits
3 Commits
6510096f90
...
a76bb43ec1
| Author | SHA1 | Date | |
|---|---|---|---|
| a76bb43ec1 | |||
| 2a654f25e8 | |||
| 47df3e2177 |
3
neotools/.gitignore
vendored
3
neotools/.gitignore
vendored
@@ -5,7 +5,10 @@
|
||||
*.pcm
|
||||
*.wav
|
||||
|
||||
*.obj_*/
|
||||
*.o
|
||||
*.d
|
||||
CMakeLists.txt
|
||||
adpcm
|
||||
adpcmb
|
||||
neoadpcmextract
|
||||
|
||||
18
neotools/autoextract.c
Normal file
18
neotools/autoextract.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include "neoadpcmextract.h"
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2)
|
||||
return 1;
|
||||
|
||||
// Open file.
|
||||
FILE* file = fopen(argv[1], "rb");
|
||||
if (!file)
|
||||
return 1;
|
||||
|
||||
int err = vgmExtractSamples(file);
|
||||
fclose(file);
|
||||
return err;
|
||||
}
|
||||
@@ -1,12 +1,27 @@
|
||||
TARGET := neoadpcmextract
|
||||
SOURCE := neoadpcmextract.c
|
||||
SOURCE := autoextract.c neoadpcmextract.c
|
||||
CFLAGS := -std=c99 -O2 -pipe -Wall -Wextra -pedantic
|
||||
LDFLAGS := $(CFLAGS)
|
||||
|
||||
|
||||
OBJDIR := .obj_$(TARGET)
|
||||
OBJECT := $(patsubst %.c, $(OBJDIR)/%.o, $(SOURCE))
|
||||
DEPEND := $(OBJECT:%.o=%.d)
|
||||
|
||||
.PHONY: default all clean
|
||||
default: $(TARGET)
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SOURCE)
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
$(TARGET): $(OBJECT)
|
||||
$(CC) $(LDFLAGS) $^ -o $@
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir -p $@
|
||||
|
||||
$(OBJDIR)/%.o: %.c | $(OBJDIR)
|
||||
$(CC) $(CFLAGS) -MMD -c $< -o $@
|
||||
|
||||
-include: $(DEPEND)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
rm -rf $(OBJDIR)
|
||||
|
||||
@@ -25,21 +25,23 @@
|
||||
|
||||
typedef struct { uint8_t* data; size_t size; } Buffer;
|
||||
|
||||
void DecodeSample(FILE* fin, const char* name, Buffer* buf)
|
||||
int DecodeSample(FILE* fin, const char* name, Buffer* buf)
|
||||
{
|
||||
// Get sample data length.
|
||||
uint32_t sampLen = 0;
|
||||
fread(&sampLen, sizeof(uint32_t), 1, fin);
|
||||
if (sampLen < sizeof(uint64_t))
|
||||
return;
|
||||
return 1;
|
||||
sampLen -= sizeof(uint64_t);
|
||||
|
||||
// Resize buffer if needed.
|
||||
if (!buf->data || buf->size < sampLen)
|
||||
{
|
||||
free(buf->data);
|
||||
buf->data = malloc(sampLen);
|
||||
buf->size = sampLen;
|
||||
buf->data = malloc(sampLen);
|
||||
if (!buf->data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Ignore 8 bytes.
|
||||
@@ -49,30 +51,28 @@ void DecodeSample(FILE* fin, const char* name, Buffer* buf)
|
||||
// Read adpcm data.
|
||||
fread(buf->data, sizeof(uint8_t), sampLen, fin);
|
||||
|
||||
// Write adpcm sample.
|
||||
FILE* fout = fopen(name, "wb");
|
||||
if (!fout)
|
||||
return;
|
||||
|
||||
return 1;
|
||||
fwrite(buf->data, sizeof(uint8_t), sampLen, fout);
|
||||
fclose(fout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int vgmExtractSamples(FILE* file)
|
||||
{
|
||||
if (argc != 2)
|
||||
return 1;
|
||||
|
||||
// Open file.
|
||||
FILE* file = fopen(argv[1], "rb");
|
||||
if (!file)
|
||||
return 1;
|
||||
|
||||
// Search for pcm headers.
|
||||
Buffer smpBytes = {NULL, 0};
|
||||
char namebuf[32];
|
||||
int smpaCount = 0, smpbCount = 0;
|
||||
|
||||
// Scan for pcm headers.
|
||||
while (!feof(file) && !ferror(file))
|
||||
{
|
||||
// Patterns to match (in hex):
|
||||
// 67 66 82 - ADPCM-A
|
||||
// 67 66 83 - ADPCM-B
|
||||
if (fgetc(file) != 0x67 || fgetc(file) != 0x66)
|
||||
continue;
|
||||
|
||||
@@ -81,17 +81,18 @@ int main(int argc, char** argv)
|
||||
{
|
||||
printf("ADPCM-A data found at 0x%08lX\n", ftell(file));
|
||||
snprintf(namebuf, sizeof(namebuf), "smpa_%x.pcm", smpaCount++);
|
||||
DecodeSample(file, namebuf, &smpBytes);
|
||||
if (DecodeSample(file, namebuf, &smpBytes))
|
||||
break;
|
||||
}
|
||||
else if (byte == 0x83)
|
||||
{
|
||||
printf("ADPCM-B data found at 0x%08lX\n", ftell(file));
|
||||
snprintf(namebuf, sizeof(namebuf), "smpb_%x.pcm", smpbCount++);
|
||||
DecodeSample(file, namebuf, &smpBytes);
|
||||
if (DecodeSample(file, namebuf, &smpBytes))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(smpBytes.data);
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
8
neotools/neoadpcmextract.h
Normal file
8
neotools/neoadpcmextract.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __NEOADPCMEXTRACT_H__
|
||||
#define __NEOADPCMEXTRACT_H__
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int vgmExtractSamples(FILE* file);
|
||||
|
||||
#endif//__NEOADPCMEXTRACT_H__
|
||||
Reference in New Issue
Block a user