Add Firebrand Games .wavebatch [NFS: The Run (3DS), F&F: Showdown (3DS)]

This commit is contained in:
bnnm 2018-08-13 23:03:39 +02:00
parent c26ad84497
commit 36c6168c27
8 changed files with 146 additions and 0 deletions

View File

@ -412,6 +412,7 @@ static const char* extension_list[] = {
"was",
//"wav", //common
"wave",
"wavebatch",
"wavm",
"wb",
"wem",
@ -1060,6 +1061,7 @@ static const meta_info meta_info_list[] = {
{meta_CKS, "Cricket Audio CKS header"},
{meta_CKB, "Cricket Audio CKB header"},
{meta_WV6, "Gorilla Systems WV6 header"},
{meta_WAVEBATCH, "Firebrand Games WBAT header"},
#ifdef VGM_USE_FFMPEG
{meta_FFmpeg, "FFmpeg supported file format"},

View File

@ -1378,6 +1378,10 @@
RelativePath=".\meta\wave.c"
>
</File>
<File
RelativePath=".\meta\wavebatch.c"
>
</File>
<File
RelativePath=".\meta\wii_04sw.c"
>

View File

@ -424,6 +424,7 @@
<ClCompile Include="meta\waf.c" />
<ClCompile Include="meta\wave_segmented.c" />
<ClCompile Include="meta\wave.c" />
<ClCompile Include="meta\wavebatch.c" />
<ClCompile Include="meta\wii_04sw.c" />
<ClCompile Include="meta\wii_bns.c" />
<ClCompile Include="meta\wii_mus.c" />

View File

@ -844,6 +844,9 @@
<ClCompile Include="meta\wave.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\wavebatch.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\wii_04sw.c">
<Filter>meta\Source Files</Filter>
</ClCompile>

View File

@ -767,4 +767,6 @@ VGMSTREAM * init_vgmstream_wv6(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_str_wav(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_wavebatch(STREAMFILE *streamFile);
#endif /*_META_H*/

132
src/meta/wavebatch.c Normal file
View File

@ -0,0 +1,132 @@
#include "meta.h"
#include "../coding/coding.h"
/* WBAT - Firebrand Games header [Need for Speed: The Run (3DS), Fast & Furious: Showdown (3DS)] */
VGMSTREAM * init_vgmstream_wavebatch(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset, name_offset, offset, stream_offset;
size_t names_size, stream_size;
int loop_flag, channel_count, sample_rate, num_samples;
int big_endian, version, codec;
int total_subsongs, target_subsong = streamFile->stream_index;
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
/* checks */
if (!check_extensions(streamFile, "wavebatch"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x54414257) /* "TABW" */
goto fail;
/* section0: base header */
big_endian = ((uint16_t)read_16bitBE(0x04,streamFile) == 0xFEFF); /* BOM (always LE on 3DS/Android) */
if (big_endian) {
read_32bit = read_32bitBE;
read_16bit = read_16bitBE;
} else {
read_32bit = read_32bitLE;
read_16bit = read_16bitLE;
}
version = read_16bit(0x06, streamFile); /* assumed */
if (version != 0x06 && version != 0x07) /* v6 = NFS: The Run , v7 = F&F Showndown */
goto fail;
total_subsongs = read_32bit(0x08,streamFile);
if (target_subsong == 0) target_subsong = 1;
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
names_size = read_32bit(0x0c,streamFile);
/* 0x10/14: see below */
/* 0x18: data size (all subsongs) */
offset = 0x1c + names_size; /* skip names table */
/* the following 2 sections (rarely) won't match total_subsongs */
/* section1: unknown */
{
size_t unknown_size = read_32bit(0x10,streamFile);
/* 0x00: usually 0, rarely 0x20? */
offset += unknown_size*0x04;
}
/* section2: samples */
{
size_t samples_size = read_32bit(0x14,streamFile);
/* 0x00: num_samples */
offset += samples_size*0x04;
}
/* section3: headers */
{
off_t header_offset = offset+(target_subsong-1)*0x24;
name_offset = read_32bit(header_offset+0x00, streamFile) + 0x1c; /* within name table */
codec = read_32bit(header_offset+0x04, streamFile);
sample_rate = read_32bit(header_offset+0x08, streamFile);
channel_count = read_32bit(header_offset+0x0c, streamFile);
/* 0x10: index within section1/2? */
/* 0x14: flags? 0x01 or (rarely) 0x02 */
stream_offset = read_32bit(header_offset+0x18, streamFile);
stream_size = read_32bit(header_offset+0x1c, streamFile); /* including DSP config */
num_samples = read_32bit(header_offset+0x20, streamFile) / channel_count; /* nibble/PCMs */
offset += total_subsongs*0x24;
}
loop_flag = 0;
start_offset = offset + stream_offset;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples;
vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = stream_size;
vgmstream->meta_type = meta_WAVEBATCH;
switch(codec) {
case 0x00: /* PCM16 [NASCAR Unleashed (3DS), Solar Flux Pocket (Android)] */
vgmstream->coding_type = big_endian ? coding_PCM16BE : coding_PCM16LE;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x02;
break;
case 0x02: { /* DSP [WRC FIA World Rally Championship (3DS)] */
size_t config_size = (0x20+0x14)*channel_count + (0x0c)*channel_count; /* coefs+hist + padding */
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = (stream_size - config_size) / channel_count; /* full interleave*/;
dsp_read_coefs(vgmstream,streamFile,start_offset+0x00,0x20+0x14,big_endian);
dsp_read_hist (vgmstream,streamFile,start_offset+0x20,0x14+0x20,big_endian);
start_offset += config_size;
break;
}
default:
VGM_LOG("WAVEBATCH: unknown codec\n");
goto fail;
}
read_string(vgmstream->stream_name,STREAM_NAME_SIZE, name_offset,streamFile); /* always null-terminated */
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -420,6 +420,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_ckb,
init_vgmstream_wv6,
init_vgmstream_str_wav,
init_vgmstream_wavebatch,
init_vgmstream_txth, /* should go at the end (lower priority) */
#ifdef VGM_USE_FFMPEG

View File

@ -696,6 +696,7 @@ typedef enum {
meta_CKS, /* Cricket Audio stream [Part Time UFO (Android), Mega Man 1-6 (Android)] */
meta_CKB, /* Cricket Audio bank [Fire Emblem Heroes (Android), Mega Man 1-6 (Android)] */
meta_WV6, /* Gorilla Systems PC games */
meta_WAVEBATCH, /* Firebrand Games */
#ifdef VGM_USE_FFMPEG
meta_FFmpeg,