2019-06-26 08:26:44 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
|
|
|
|
/* BWAV - NintendoWare(?) [Super Mario Maker 2 (Switch)] */
|
|
|
|
VGMSTREAM * init_vgmstream_bwav(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2019-10-20 23:48:45 +02:00
|
|
|
int channel_count, loop_flag, codec;
|
|
|
|
size_t interleave = 0;
|
|
|
|
|
2019-06-26 08:26:44 +02:00
|
|
|
|
|
|
|
/* checks */
|
|
|
|
if (!check_extensions(streamFile, "bwav"))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (read_32bitBE(0x00, streamFile) != 0x42574156) /* "BWAV" */
|
|
|
|
goto fail;
|
|
|
|
|
2019-10-20 23:48:45 +02:00
|
|
|
/* 0x04: BOM */
|
|
|
|
/* 0x06: version? */
|
|
|
|
/* 0x08: ??? */
|
|
|
|
/* 0x0c: null? */
|
2019-06-26 19:10:17 +02:00
|
|
|
channel_count = read_16bitLE(0x0E, streamFile);
|
2019-10-20 23:48:45 +02:00
|
|
|
|
|
|
|
/* - per channel (size 0x4c) */
|
|
|
|
codec = read_16bitLE(0x10, streamFile);
|
|
|
|
/* see below */
|
2019-06-26 19:10:17 +02:00
|
|
|
start_offset = read_32bitLE(0x40, streamFile);
|
2019-10-20 23:48:45 +02:00
|
|
|
loop_flag = read_32bitLE(0x4C, streamFile) != -1;
|
|
|
|
if (channel_count > 1)
|
|
|
|
interleave = read_32bitLE(0x8C, streamFile) - start_offset;
|
|
|
|
//TODO should make sure channels match and offsets make a proper interleave (see bfwav)
|
|
|
|
|
2019-06-26 08:26:44 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2019-06-26 19:10:17 +02:00
|
|
|
vgmstream->sample_rate = read_32bitLE(0x14, streamFile);
|
|
|
|
vgmstream->num_samples = read_32bitLE(0x18, streamFile);
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x50, streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x4C, streamFile);
|
2019-06-26 08:26:44 +02:00
|
|
|
vgmstream->meta_type = meta_BWAV;
|
|
|
|
|
2019-10-20 23:48:45 +02:00
|
|
|
switch(codec) {
|
|
|
|
case 0x0000:
|
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = interleave;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0001:
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = interleave;
|
|
|
|
dsp_read_coefs_le(vgmstream, streamFile, 0x20, 0x4C);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2019-06-26 08:26:44 +02:00
|
|
|
|
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|