mirror of
https://github.com/ScrelliCopter/VGM-Tools
synced 2025-02-21 04:09:25 +11:00
Refactor most of the opening and scanning between sources
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "neoadpcmextract.h"
|
||||
|
||||
|
||||
@@ -12,6 +13,7 @@ int main(int argc, char** argv)
|
||||
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");
|
||||
@@ -20,7 +22,42 @@ int main(int argc, char** argv)
|
||||
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
int err = vgmExtractSamples(file);
|
||||
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 err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user