From e334ad82cc326125c059b3a462ce09f6771f1f50 Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Sun, 10 Dec 2023 10:41:22 +1100 Subject: [PATCH] neotools: remove autoextract.c and move main logic into the main file --- neotools/CMakeLists.txt | 2 +- neotools/autoextract.c | 58 -------------------------------------- neotools/neoadpcmextract.c | 56 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 59 deletions(-) delete mode 100644 neotools/autoextract.c diff --git a/neotools/CMakeLists.txt b/neotools/CMakeLists.txt index 480c2ec..a87d829 100644 --- a/neotools/CMakeLists.txt +++ b/neotools/CMakeLists.txt @@ -13,7 +13,7 @@ add_executable(adpcmb adpcmb.c) target_compile_options(adpcmb PRIVATE ${WARNINGS}) target_link_libraries(adpcmb Common::headers) -add_executable(neoadpcmextract autoextract.c neoadpcmextract.c) +add_executable(neoadpcmextract neoadpcmextract.c) set_property(TARGET neoadpcmextract PROPERTY C_STANDARD 99) target_compile_definitions(neoadpcmextract PRIVATE $<$:USE_ZLIB=1>) target_compile_options(neoadpcmextract PRIVATE ${WARNINGS}) diff --git a/neotools/autoextract.c b/neotools/autoextract.c deleted file mode 100644 index 95b9753..0000000 --- a/neotools/autoextract.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include "neoadpcmextract.h" - - -int main(int argc, char** argv) -{ - if (argc != 2) return 1; - - nfile* file = nopen(argv[1], "rb"); // Open file - if (!file) return 1; - -#if !USE_ZLIB - if (ngetc(file) == 0x1F && ngetc(file) == 0x8B) - { - printf("I'm a little gzip short and stout\n"); - return 2; - } - nseek(file, 0, SEEK_SET); -#endif - - 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, ntell(file)); - - if (vgmReadSample(file, &smpbuf) || smpbuf.size == 0) - continue; - if (scanType == 'A') - { - snprintf(name, sizeof(name), "smpa_%02x.pcm", smpaCount++); - printf("./adpcm \"%s\" \"$WAVDIR/%s.wav\"\n", name, name); - } - else - { - 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); - nclose(file); - return 0; -} diff --git a/neotools/neoadpcmextract.c b/neotools/neoadpcmextract.c index 00b64fb..4fd15b4 100644 --- a/neotools/neoadpcmextract.c +++ b/neotools/neoadpcmextract.c @@ -3,6 +3,7 @@ #include "neoadpcmextract.h" #include "endian.h" #include +#include static uint32_t read32le(nfile* fin) @@ -56,3 +57,58 @@ int vgmScanSample(nfile* file) } } } + + +int main(int argc, char** argv) +{ + if (argc != 2) return 1; + + nfile* file = nopen(argv[1], "rb"); // Open file + if (!file) return 1; + +#if !USE_ZLIB + if (ngetc(file) == 0x1F && ngetc(file) == 0x8B) + { + printf("I'm a little gzip short and stout\n"); + return 2; + } + nseek(file, 0, SEEK_SET); +#endif + + 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, ntell(file)); + + if (vgmReadSample(file, &smpbuf) || smpbuf.size == 0) + continue; + if (scanType == 'A') + { + snprintf(name, sizeof(name), "smpa_%02x.pcm", smpaCount++); + printf("./adpcm \"%s\" \"$WAVDIR/%s.wav\"\n", name, name); + } + else + { + 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); + nclose(file); + return 0; +}