Fix mono .thp [WarioWare, Inc. Mega Party Game$! (GC)]

This commit is contained in:
bnnm 2021-06-20 10:29:49 +02:00
parent bc91258ebf
commit 68b9164d72
2 changed files with 27 additions and 27 deletions

View File

@ -2,15 +2,15 @@
#include "../vgmstream.h"
/* set up for the block at the given offset */
void block_update_thp(off_t block_offset, VGMSTREAM *vgmstream) {
void block_update_thp(off_t block_offset, VGMSTREAM* vgmstream) {
int i, j;
STREAMFILE *streamFile = vgmstream->ch[0].streamfile;
STREAMFILE* sf = vgmstream->ch[0].streamfile;
off_t audio_offset;
size_t next_block_size, video_size;
next_block_size = read_32bitBE(block_offset + 0x00, streamFile);
next_block_size = read_u32be(block_offset + 0x00, sf);
/* 0x04: frame size previous */
video_size = read_32bitBE(block_offset + 0x08,streamFile);
video_size = read_u32be(block_offset + 0x08,sf);
/* 0x0c: audio size */
audio_offset = block_offset + 0x10 + video_size;
@ -21,21 +21,21 @@ void block_update_thp(off_t block_offset, VGMSTREAM *vgmstream) {
/* block samples can be smaller than block size, normally in the last block,
* but num_samples already takes that into account, so there is no real difference */
vgmstream->current_block_size = read_32bitBE(audio_offset + 0x00, streamFile);
vgmstream->current_block_samples = read_32bitBE(audio_offset + 0x04, streamFile);
vgmstream->current_block_size = read_u32be(audio_offset + 0x00, sf);
vgmstream->current_block_samples = read_u32be(audio_offset + 0x04, sf);
audio_offset += 0x08;
for (i = 0; i < vgmstream->channels; i++) {
off_t coef_offset = audio_offset + i*0x20;
off_t hist_offset = audio_offset + vgmstream->channels*0x20 + i*0x04;
off_t data_offset = audio_offset + vgmstream->channels*0x24 + i*vgmstream->current_block_size;
off_t data_offset = audio_offset + 2*0x24 + i*vgmstream->current_block_size; /* reserved for 2 even in mono [WarioWare Inc. (GC)] */
for (j = 0; j < 16; j++) {
vgmstream->ch[i].adpcm_coef[j] = read_16bitBE(coef_offset + (j*0x02),streamFile);
vgmstream->ch[i].adpcm_coef[j] = read_s16be(coef_offset + (j*0x02),sf);
}
vgmstream->ch[i].adpcm_history1_16 = read_16bitBE(hist_offset + 0x00,streamFile);
vgmstream->ch[i].adpcm_history2_16 = read_16bitBE(hist_offset + 0x02,streamFile);
vgmstream->ch[i].adpcm_history1_16 = read_s16be(hist_offset + 0x00,sf);
vgmstream->ch[i].adpcm_history2_16 = read_s16be(hist_offset + 0x02,sf);
vgmstream->ch[i].offset = data_offset;
}
}

View File

@ -2,12 +2,12 @@
#include "../layout/layout.h"
/* THP - Nintendo movie format found in GC/Wii games */
VGMSTREAM* init_vgmstream_thp(STREAMFILE *streamFile) {
VGMSTREAM *vgmstream = NULL;
VGMSTREAM* init_vgmstream_thp(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset, component_type_offset, component_data_offset;
uint32_t version, max_audio_size;
int num_components;
int loop_flag, channel_count;
int loop_flag, channels;
int i;
@ -15,14 +15,14 @@ VGMSTREAM* init_vgmstream_thp(STREAMFILE *streamFile) {
/* .thp: actual extension
* .dsp: fake extension?
* (extensionless): Fragile (Wii) */
if (!check_extensions(streamFile, "thp,dsp,"))
if (!check_extensions(sf, "thp,dsp,"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x54485000) /* "THP\0" */
if (!is_id32be(0x00,sf, "THP\0"))
goto fail;
version = read_32bitBE(0x04,streamFile); /* 16b+16b major/minor */
version = read_u32be(0x04,sf); /* 16b+16b major/minor */
/* 0x08: max buffer size */
max_audio_size = read_32bitBE(0x0C,streamFile);
max_audio_size = read_u32be(0x0C,sf);
/* 0x10: fps in float */
/* 0x14: block count */
/* 0x18: first block size */
@ -33,19 +33,19 @@ VGMSTREAM* init_vgmstream_thp(STREAMFILE *streamFile) {
if (max_audio_size == 0) /* no sound */
goto fail;
component_type_offset = read_32bitBE(0x20,streamFile);
component_type_offset = read_u32be(0x20,sf);
/* 0x24: block offsets table offset (optional, for seeking) */
start_offset = read_32bitBE(0x28,streamFile);
start_offset = read_u32be(0x28,sf);
/* 0x2c: last block offset */
/* first component "type" x16 then component headers */
num_components = read_32bitBE(component_type_offset,streamFile);
num_components = read_u32be(component_type_offset,sf);
component_type_offset += 0x04;
component_data_offset = component_type_offset + 0x10;
/* parse "component" (data that goes into blocks) */
for (i = 0; i < num_components; i++) {
int type = read_8bit(component_type_offset + i,streamFile);
int type = read_u8(component_type_offset + i,sf);
if (type == 0x00) { /* video */
if (version == 0x00010000)
@ -73,24 +73,24 @@ VGMSTREAM* init_vgmstream_thp(STREAMFILE *streamFile) {
* adjusted, but we can't detect Wii (non adjusted) .thp tho */
loop_flag = 0;
channel_count = read_32bitBE(component_data_offset + 0x00,streamFile);
channels = read_u32be(component_data_offset + 0x00,sf);
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
vgmstream = allocate_vgmstream(channels,loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = read_32bitBE(component_data_offset + 0x04,streamFile);
vgmstream->num_samples = read_32bitBE(component_data_offset + 0x08,streamFile);
vgmstream->sample_rate = read_u32be(component_data_offset + 0x04,sf);
vgmstream->num_samples = read_u32be(component_data_offset + 0x08,sf);
vgmstream->meta_type = meta_THP;
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_blocked_thp;
/* coefs are in every block */
vgmstream->full_block_size = read_32bitBE(0x18,streamFile); /* next block size */
vgmstream->full_block_size = read_u32be(0x18,sf); /* next block size */
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
goto fail;
return vgmstream;