mirror of
https://github.com/ScrelliCopter/VGM-Tools
synced 2025-02-21 04:09:25 +11:00
Compare commits
19 Commits
v0.2.0
...
5cfb861369
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cfb861369 | |||
| 6456404bd3 | |||
| 08b61568e1 | |||
| a76bb43ec1 | |||
| 2a654f25e8 | |||
| 47df3e2177 | |||
| 6510096f90 | |||
| 07ee0b546c | |||
| 454fcd3226 | |||
| c94016e793 | |||
| 172174c837 | |||
| 3fafdfd3f4 | |||
| 6ccf9f6e38 | |||
| b12258970e | |||
| 886966d7dc | |||
| 63aacb9a01 | |||
| 7c66bbab52 | |||
| fbf887b534 | |||
| 0a26bc8998 |
7
neotools/.gitignore
vendored
7
neotools/.gitignore
vendored
@@ -5,7 +5,6 @@
|
||||
*.pcm
|
||||
*.wav
|
||||
|
||||
*.o
|
||||
adpcm
|
||||
adpcmb
|
||||
neoadpcmextract
|
||||
.idea/
|
||||
build/
|
||||
cmake-build-*/
|
||||
|
||||
18
neotools/CMakeLists.txt
Normal file
18
neotools/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
project(neoadpcmtools)
|
||||
cmake_minimum_required(VERSION "3.1" FATAL_ERROR)
|
||||
|
||||
add_executable(adpcm adpcm.c)
|
||||
target_compile_options(adpcm PRIVATE
|
||||
-fomit-frame-pointer -Werror -Wall
|
||||
-W -Wno-sign-compare -Wno-unused
|
||||
-Wpointer-arith -Wbad-function-cast -Wcast-align -Waggregate-return
|
||||
-pedantic
|
||||
-Wshadow
|
||||
-Wstrict-prototypes)
|
||||
target_link_libraries(adpcm m)
|
||||
|
||||
add_executable(adpcmb adpcmb.c)
|
||||
|
||||
add_executable(neoadpcmextract autoextract.c neoadpcmextract.c)
|
||||
set_property(TARGET neoadpcmextract PROPERTY C_STANDARD 99)
|
||||
target_compile_options(neoadpcmextract PRIVATE -Wall -Wextra -pedantic)
|
||||
@@ -1,34 +0,0 @@
|
||||
# Standard makefile to use as a base for DJGPP projects (not anymore lol)
|
||||
# By MARTINEZ Fabrice aka SNK of SUPREMACY
|
||||
|
||||
# Programs to use during make
|
||||
LD := $(CC)
|
||||
|
||||
TARGET := adpcm
|
||||
SOURCE := adpcm.c
|
||||
|
||||
# Flags for compilation
|
||||
CFLAGS := -fomit-frame-pointer -O3 -Werror -Wall \
|
||||
-W -Wno-sign-compare -Wno-unused \
|
||||
-Wpointer-arith -Wbad-function-cast -Wcast-align -Waggregate-return \
|
||||
-pedantic \
|
||||
-Wshadow \
|
||||
-Wstrict-prototypes
|
||||
LDFLAGS := -lm
|
||||
|
||||
# Object files
|
||||
OBJECT := $(SOURCE:%.c=%.o)
|
||||
|
||||
# Make rules
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECT)
|
||||
$(LD) $(CFLAGS) $(LDFLAGS) $^ -o $@
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Rules to manage files
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECT)
|
||||
@@ -1,15 +0,0 @@
|
||||
CC = gcc
|
||||
CFLAGS = -O3
|
||||
|
||||
SRC = .
|
||||
OBJ = .
|
||||
|
||||
OUT_OBJ = $(OBJ)/adpcmb
|
||||
|
||||
all: $(OUT_OBJ)
|
||||
|
||||
$(OBJ)/%.exe: $(SRC)/%.c
|
||||
$(CC) $(CCFLAGS) $(MAINFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm $(OUT_OBJ)
|
||||
63
neotools/autoextract.c
Normal file
63
neotools/autoextract.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.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;
|
||||
|
||||
// Error on VGZ's for now.
|
||||
if (fgetc(file) == 0x1F && fgetc(file) == 0x8B)
|
||||
{
|
||||
printf("I'm a little gzip short and stout\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
Buffer smpbuf = {NULL, 0, 0};
|
||||
char name[32];
|
||||
int smpaCount = 0, smpbCount = 0;
|
||||
|
||||
// Find ADCPM samples.
|
||||
int scanType;
|
||||
while ((scanType = vgmScanSample(file)))
|
||||
{
|
||||
if (scanType != 'A' && scanType != 'B')
|
||||
continue;
|
||||
fprintf(stderr, "ADPCM-%c data found at 0x%08lX\n", scanType, ftell(file));
|
||||
|
||||
if (vgmReadSample(file, &smpbuf) || smpbuf.size == 0)
|
||||
continue;
|
||||
if (scanType == 'A')
|
||||
{
|
||||
// decode
|
||||
snprintf(name, sizeof(name), "smpa_%02x.pcm", smpaCount++);
|
||||
printf("./adpcm \"%s\" \"$WAVDIR/%s.wav\"\n", name, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// decode
|
||||
snprintf(name, sizeof(name), "smpb_%02x.pcm", smpbCount++);
|
||||
printf("./adpcmb -d \"%s\" \"$WAVDIR/%s.wav\"\n", name, name);
|
||||
}
|
||||
|
||||
// Write adpcm sample.
|
||||
FILE* fout = fopen(name, "wb");
|
||||
if (!fout)
|
||||
continue;
|
||||
fwrite(smpbuf.data, sizeof(uint8_t), smpbuf.size, fout);
|
||||
fclose(fout);
|
||||
}
|
||||
|
||||
free(smpbuf.data);
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,19 +1,12 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
FILE="$1"
|
||||
NAME="$(basename "$FILE")"
|
||||
WAVDIR="${NAME%%.*}"
|
||||
|
||||
if [ "${NAME##*.}" = "vgz" ]; then
|
||||
cp "$FILE" "temp.vgm.gz"
|
||||
gzip -d "temp.vgm.gz"
|
||||
FILE="temp.vgm"
|
||||
fi
|
||||
|
||||
./neoadpcmextract "$FILE"
|
||||
mkdir -p "$WAVDIR"
|
||||
for I in smpa_*.pcm; do ./adpcm "$I" "$WAVDIR/${I%%.*}.wav"; done
|
||||
for I in smpb_*.pcm; do ./adpcmb -d "$I" "$WAVDIR/${I%%.*}.wav"; done
|
||||
find . -type f -name "*.pcm" -exec rm -f {} \;
|
||||
|
||||
[ "$FILE" = "temp.vgm" ] && rm -f "temp.vgm"
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
TARGET := neoadpcmextract
|
||||
SOURCE := neoadpcmextract.cpp
|
||||
CXXFLAGS := -O2 -pipe -Wall -Wextra
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SOURCE)
|
||||
$(CXX) $(CXXFLAGS) $< -o $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
75
neotools/neoadpcmextract.c
Normal file
75
neotools/neoadpcmextract.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/* neoadpcmextract.c
|
||||
Copyright (C) 2017, 2019, 2020 Nicholas Curtis
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "neoadpcmextract.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int vgmReadSample(FILE* fin, Buffer* buf)
|
||||
{
|
||||
// Get sample data length.
|
||||
uint32_t sampLen = 0;
|
||||
fread(&sampLen, sizeof(uint32_t), 1, fin);
|
||||
if (sampLen < sizeof(uint64_t))
|
||||
return 1;
|
||||
sampLen -= sizeof(uint64_t);
|
||||
|
||||
// Resize buffer if needed.
|
||||
buf->size = sampLen;
|
||||
if (!buf->data || buf->reserved < sampLen)
|
||||
{
|
||||
free(buf->data);
|
||||
buf->reserved = sampLen;
|
||||
buf->data = malloc(sampLen);
|
||||
if (!buf->data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Ignore 8 bytes.
|
||||
uint64_t dummy;
|
||||
fread(&dummy, sizeof(uint64_t), 1, fin);
|
||||
|
||||
// Read adpcm data.
|
||||
fread(buf->data, sizeof(uint8_t), sampLen, fin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vgmScanSample(FILE* file)
|
||||
{
|
||||
// Scan for pcm headers.
|
||||
while (1)
|
||||
{
|
||||
if (feof(file) || ferror(file))
|
||||
return 0;
|
||||
|
||||
// Patterns to match (in hex):
|
||||
// 67 66 82 - ADPCM-A
|
||||
// 67 66 83 - ADPCM-B
|
||||
if (fgetc(file) != 0x67 || fgetc(file) != 0x66)
|
||||
continue;
|
||||
|
||||
uint8_t byte = fgetc(file);
|
||||
if (byte == 0x82)
|
||||
return 'A';
|
||||
else if (byte == 0x83)
|
||||
return 'B';
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/* neoadpcmextract.cpp
|
||||
Copyright (C) 2017 Nicholas Curtis
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
void DecodeSample ( std::ifstream& a_file, std::vector<uint8_t>& a_out )
|
||||
{
|
||||
// Set up output vector.
|
||||
uint32_t sampLen = 0;
|
||||
a_file.read ( (char*)&sampLen, sizeof(uint32_t) );
|
||||
if ( sampLen < sizeof(uint64_t) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sampLen -= sizeof(uint64_t);
|
||||
a_out.clear ();
|
||||
a_out.resize ( sampLen );
|
||||
|
||||
// Ignore 8 bytes.
|
||||
uint64_t dummy;
|
||||
a_file.read ( (char*)&dummy, sizeof(uint64_t) );
|
||||
|
||||
// Read adpcm data.
|
||||
a_file.read ( (char*)a_out.data (), sampLen );
|
||||
}
|
||||
|
||||
void DumpBytes ( std::string a_path, const std::vector<uint8_t>& a_bytes )
|
||||
{
|
||||
std::ofstream fileOut ( a_path, std::ios::binary );
|
||||
fileOut.write ( (const char*)a_bytes.data (), a_bytes.size () );
|
||||
fileOut.close ();
|
||||
}
|
||||
|
||||
int main ( int argc, char** argv )
|
||||
{
|
||||
if ( argc != 2 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open file.
|
||||
std::ifstream file ( argv[1], std::ios::binary );
|
||||
if ( !file.is_open () )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Search for pcm headers.
|
||||
std::vector<uint8_t> smpBytes;
|
||||
int smpA = 0, smpB = 0;
|
||||
while ( !file.eof () && !file.fail () )
|
||||
{
|
||||
uint8_t byte;
|
||||
|
||||
file >> byte;
|
||||
if ( byte == 0x67 )
|
||||
{
|
||||
file >> byte;
|
||||
if ( byte == 0x66 )
|
||||
{
|
||||
file >> byte;
|
||||
if ( byte == 0x82 )
|
||||
{
|
||||
std::cout << "ADPCM-A data found at 0x" << std::hex << file.tellg () << std::endl;
|
||||
DecodeSample ( file, smpBytes );
|
||||
std::stringstream path;
|
||||
path << std::hex << "smpa_" << (smpA++) << ".pcm";
|
||||
DumpBytes ( 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 ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
12
neotools/neoadpcmextract.h
Normal file
12
neotools/neoadpcmextract.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __NEOADPCMEXTRACT_H__
|
||||
#define __NEOADPCMEXTRACT_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct { uint8_t* data; size_t size, reserved; } Buffer;
|
||||
|
||||
int vgmReadSample(FILE* fin, Buffer* buf);
|
||||
int vgmScanSample(FILE* file);
|
||||
|
||||
#endif//__NEOADPCMEXTRACT_H__
|
||||
Reference in New Issue
Block a user