mirror of
https://github.com/ScrelliCopter/VGM-Tools
synced 2025-02-21 04:09:25 +11:00
Compare commits
13 Commits
v0.2.0
...
6510096f90
| Author | SHA1 | Date | |
|---|---|---|---|
| 6510096f90 | |||
| 07ee0b546c | |||
| 454fcd3226 | |||
| c94016e793 | |||
| 172174c837 | |||
| 3fafdfd3f4 | |||
| 6ccf9f6e38 | |||
| b12258970e | |||
| 886966d7dc | |||
| 63aacb9a01 | |||
| 7c66bbab52 | |||
| fbf887b534 | |||
| 0a26bc8998 |
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
TARGET := neoadpcmextract
|
TARGET := neoadpcmextract
|
||||||
SOURCE := neoadpcmextract.cpp
|
SOURCE := neoadpcmextract.c
|
||||||
CXXFLAGS := -O2 -pipe -Wall -Wextra
|
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:
|
||||||
|
|||||||
97
neotools/neoadpcmextract.c
Normal file
97
neotools/neoadpcmextract.c
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/* neoadpcmextract.cpp
|
||||||
|
Copyright (C) 2017, 2019 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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct { uint8_t* data; size_t size; } Buffer;
|
||||||
|
|
||||||
|
void 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;
|
||||||
|
sampLen -= sizeof(uint64_t);
|
||||||
|
|
||||||
|
// Resize buffer if needed.
|
||||||
|
if (!buf->data || buf->size < sampLen)
|
||||||
|
{
|
||||||
|
free(buf->data);
|
||||||
|
buf->data = malloc(sampLen);
|
||||||
|
buf->size = sampLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore 8 bytes.
|
||||||
|
uint64_t dummy;
|
||||||
|
fread(&dummy, sizeof(uint64_t), 1, fin);
|
||||||
|
|
||||||
|
// Read adpcm data.
|
||||||
|
fread(buf->data, sizeof(uint8_t), sampLen, fin);
|
||||||
|
|
||||||
|
FILE* fout = fopen(name, "wb");
|
||||||
|
if (!fout)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fwrite(buf->data, sizeof(uint8_t), sampLen, fout);
|
||||||
|
fclose(fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
while (!feof(file) && !ferror(file))
|
||||||
|
{
|
||||||
|
if (fgetc(file) != 0x67 || fgetc(file) != 0x66)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint8_t byte = fgetc(file);
|
||||||
|
if (byte == 0x82)
|
||||||
|
{
|
||||||
|
printf("ADPCM-A data found at 0x%08lX\n", ftell(file));
|
||||||
|
snprintf(namebuf, sizeof(namebuf), "smpa_%x.pcm", smpaCount++);
|
||||||
|
DecodeSample(file, namebuf, &smpBytes);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(smpBytes.data);
|
||||||
|
fclose(file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user