2009-04-19 11:49:08 +02:00
|
|
|
#include "meta.h"
|
2017-07-23 13:16:59 +02:00
|
|
|
#include "../layout/layout.h"
|
|
|
|
#include "../coding/coding.h"
|
2009-04-19 11:49:08 +02:00
|
|
|
|
2017-07-23 13:16:59 +02:00
|
|
|
/* HWAS - found in Vicarious Visions NDS games (Spider-Man 3, Tony Hawk's Downhill Jam, etc) */
|
2009-04-19 11:49:08 +02:00
|
|
|
VGMSTREAM * init_vgmstream_nds_hwas(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2017-07-23 13:16:59 +02:00
|
|
|
int channel_count, loop_flag = 0;
|
2009-04-19 11:49:08 +02:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2017-07-23 13:16:59 +02:00
|
|
|
if (!check_extensions(streamFile,"hwas"))
|
|
|
|
goto fail;
|
2009-04-19 11:49:08 +02:00
|
|
|
|
|
|
|
/* check header */
|
2009-04-22 03:17:49 +02:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x73617768) /* "sawh" */
|
2009-04-19 11:49:08 +02:00
|
|
|
goto fail;
|
|
|
|
|
2017-07-23 13:16:59 +02:00
|
|
|
loop_flag = 1; /* almost all files seem to loop (usually if num_samples != loop_end doesn't loop, but not always) */
|
2009-04-19 11:49:08 +02:00
|
|
|
channel_count = read_32bitLE(0x0C,streamFile);
|
2017-07-23 13:16:59 +02:00
|
|
|
if (channel_count > 1) goto fail; /* unknown block layout when stereo, not seen */
|
|
|
|
|
|
|
|
start_offset = 0x200;
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2009-04-19 11:49:08 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x08,streamFile);
|
2017-07-23 13:16:59 +02:00
|
|
|
vgmstream->num_samples = ima_bytes_to_samples(read_32bitLE(0x14,streamFile), channel_count);
|
|
|
|
vgmstream->loop_start_sample = ima_bytes_to_samples(read_32bitLE(0x10,streamFile), channel_count); //assumed, always 0
|
|
|
|
vgmstream->loop_end_sample = ima_bytes_to_samples(read_32bitLE(0x18,streamFile), channel_count);
|
2009-04-19 11:49:08 +02:00
|
|
|
|
|
|
|
vgmstream->meta_type = meta_NDS_HWAS;
|
|
|
|
|
2017-07-23 13:16:59 +02:00
|
|
|
vgmstream->coding_type = coding_IMA;
|
|
|
|
vgmstream->layout_type = layout_hwas_blocked;
|
|
|
|
vgmstream->full_block_size = read_32bitLE(0x04,streamFile); /* usually 0x2000, 0x4000 or 0x8000 */
|
|
|
|
|
2009-04-19 11:49:08 +02:00
|
|
|
/* open the file for reading by each channel */
|
2017-07-23 13:16:59 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
hwas_block_update(start_offset, vgmstream);
|
2009-04-19 11:49:08 +02:00
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-07-23 13:16:59 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2009-04-19 11:49:08 +02:00
|
|
|
return NULL;
|
|
|
|
}
|