This commit is contained in:
bnnm 2021-08-26 18:48:19 +02:00
parent 5652c7ad59
commit 7400112fbe
3 changed files with 104 additions and 119 deletions

View File

@ -1,68 +1,53 @@
/* #include "meta.h"
Wii U boot sound file for each game/app. #include "../coding/coding.h"
*/
/* .btsnd - Wii U boot sound file for each game/app */
#include "meta.h" VGMSTREAM* init_vgmstream_btsnd(STREAMFILE* sf) {
#include "../util.h" VGMSTREAM* vgmstream = NULL;
int channels, loop_flag;
VGMSTREAM * init_vgmstream_btsnd(STREAMFILE *streamFile) { off_t start_offset, data_size;
VGMSTREAM * vgmstream = NULL; int32_t num_samples, loop_start;
char filename[PATH_LIMIT];
int channel_count = 2;
int loop_flag; /* checks */
off_t start_offset = 0x8; if (!check_extensions(sf, "btsnd"))
goto fail;
/* check extension, case insensitive */
streamFile->get_name(streamFile, filename, sizeof(filename)); if (read_u32be(0x00,sf) != 0x02)
if (strcasecmp("btsnd", filename_extension(filename))) goto fail;
goto fail;
loop_start = read_s32be(0x04, sf);
/* Checking for loop start */ start_offset = 0x08;
if (read_32bitBE(0x4, streamFile) > 0)
loop_flag = 1; channels = 2;
else loop_flag = loop_start > 0;
loop_flag = 0;
/* extra check since format is so simple */
if (channel_count < 1) goto fail; data_size = get_streamfile_size(sf);
num_samples = pcm16_bytes_to_samples(data_size - start_offset, channels);
/* build the VGMSTREAM */ if (loop_start >= num_samples)
goto fail;
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */ /* build the VGMSTREAM */
vgmstream->sample_rate = 48000; vgmstream = allocate_vgmstream(channels, loop_flag);
/* channels and loop flag are set by allocate_vgmstream */ if (!vgmstream) goto fail;
// There's probably a better way to get the sample count... vgmstream->meta_type = meta_WIIU_BTSND;
vgmstream->num_samples = vgmstream->loop_end_sample = (get_streamfile_size(streamFile) - 8) / 4; vgmstream->sample_rate = 48000;
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = read_32bitBE(0x4, streamFile); vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = vgmstream->num_samples;
vgmstream->coding_type = coding_PCM16BE;
vgmstream->layout_type = layout_interleave; vgmstream->coding_type = coding_PCM16BE;
vgmstream->interleave_block_size = 0x2; // Constant for this format vgmstream->layout_type = layout_interleave;
vgmstream->meta_type = meta_WIIU_BTSND; vgmstream->interleave_block_size = 0x02;
/* open the file for reading by each channel */ if (!vgmstream_open_stream(vgmstream, sf, start_offset))
{ goto fail;
int i; return vgmstream;
for (i = 0; i<channel_count; i++) { fail:
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename, close_vgmstream(vgmstream);
STREAMFILE_DEFAULT_BUFFER_SIZE); return NULL;
}
if (!vgmstream->ch[i].streamfile) goto fail;
vgmstream->ch[i].channel_start_offset =
vgmstream->ch[i].offset =
start_offset + i*vgmstream->interleave_block_size;
}
}
return vgmstream;
/* clean up anything we may have opened */
fail:
if (vgmstream) close_vgmstream(vgmstream);
return NULL;
}

View File

@ -1,50 +1,50 @@
#include "meta.h" #include "meta.h"
#include "../util.h" #include "../coding/coding.h"
#include "../coding/coding.h" #include "../layout/layout.h"
#include "../layout/layout.h"
/* MUSC - from Krome's PS2 games (The Legend of Spyro, Ty the Tasmanian Tiger) */
/* MUSC - from Krome's PS2 games (The Legend of Spyro, Ty the Tasmanian Tiger) */ VGMSTREAM* init_vgmstream_musc(STREAMFILE* sf) {
VGMSTREAM * init_vgmstream_musc(STREAMFILE *streamFile) { VGMSTREAM* vgmstream = NULL;
VGMSTREAM * vgmstream = NULL; int loop_flag, channels;
int loop_flag, channel_count; off_t start_offset;
off_t start_offset; size_t data_size;
size_t data_size;
/* .mus is the real extension, .musc is the header ID */ /* checks */
if (!check_extensions(streamFile,"mus,musc")) /* .mus: actual extension
goto fail; * .musc: header ID */
if (read_32bitBE(0x00,streamFile) != 0x4D555343) /* "MUSC" */ if (!check_extensions(sf,"mus,musc"))
goto fail; goto fail;
if (!is_id32be(0x00,sf, "MUSC"))
start_offset = read_32bitLE(0x10,streamFile); goto fail;
data_size = read_32bitLE(0x14,streamFile);
if (start_offset + data_size != get_streamfile_size(streamFile)) start_offset = read_u32le(0x10,sf);
goto fail; data_size = read_u32le(0x14,sf);
/* always does full loops unless it ends in silence */ if (start_offset + data_size != get_streamfile_size(sf))
loop_flag = read_32bitBE(get_streamfile_size(streamFile) - 0x10,streamFile) != 0x0C000000; goto fail;
channel_count = 2; /* always does full loops unless it ends in silence */
loop_flag = read_u32be(get_streamfile_size(sf) - 0x10,sf) != 0x0C000000;
channels = 2;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail; /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x06,streamFile); if (!vgmstream) goto fail;
vgmstream->num_samples = ps_bytes_to_samples(data_size, channel_count);
vgmstream->loop_start_sample = 0; vgmstream->sample_rate = read_u16le(0x06,sf);
vgmstream->loop_end_sample = vgmstream->num_samples; vgmstream->num_samples = ps_bytes_to_samples(data_size, channels);
vgmstream->loop_start_sample = 0;
vgmstream->meta_type = meta_MUSC; vgmstream->loop_end_sample = vgmstream->num_samples;
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave; vgmstream->meta_type = meta_MUSC;
vgmstream->interleave_block_size = read_32bitLE(0x18,streamFile) / 2; vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) vgmstream->interleave_block_size = read_u32le(0x18,sf) / 2;
goto fail;
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
return vgmstream; goto fail;
return vgmstream;
fail: fail:
close_vgmstream(vgmstream); close_vgmstream(vgmstream);
return NULL; return NULL;
} }

View File

@ -24,7 +24,6 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_bfwav, init_vgmstream_bfwav,
init_vgmstream_bfstm, init_vgmstream_bfstm,
init_vgmstream_mca, init_vgmstream_mca,
init_vgmstream_btsnd,
init_vgmstream_nds_strm, init_vgmstream_nds_strm,
init_vgmstream_agsc, init_vgmstream_agsc,
init_vgmstream_ngc_adpdtk, init_vgmstream_ngc_adpdtk,
@ -533,6 +532,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
/* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */ /* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */
init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */ init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */
init_vgmstream_encrypted, /* encrypted stuff */ init_vgmstream_encrypted, /* encrypted stuff */
init_vgmstream_btsnd, /* semi-headerless */
init_vgmstream_raw_int, /* .int raw PCM */ init_vgmstream_raw_int, /* .int raw PCM */
init_vgmstream_ps_headerless, /* tries to detect a bunch of PS-ADPCM formats */ init_vgmstream_ps_headerless, /* tries to detect a bunch of PS-ADPCM formats */
init_vgmstream_raw_snds, /* .snds raw SNDS IMA (*after* ps_headerless) */ init_vgmstream_raw_snds, /* .snds raw SNDS IMA (*after* ps_headerless) */