diff --git a/Frameworks/vgmstream/vgmstream/src/layout/halpst_blocked.c b/Frameworks/vgmstream/vgmstream/src/layout/halpst_blocked.c index affb135f7..7c36c1bf8 100644 --- a/Frameworks/vgmstream/vgmstream/src/layout/halpst_blocked.c +++ b/Frameworks/vgmstream/vgmstream/src/layout/halpst_blocked.c @@ -3,7 +3,9 @@ /* set up for the block at the given offset */ void halpst_block_update(off_t block_offset, VGMSTREAM * vgmstream) { - int i; + int i, header_length; + /* header length must be a multiple of 0x20 */ + header_length = (4+8*vgmstream->channels+0x1f)/0x20*0x20; vgmstream->current_block_offset = block_offset; vgmstream->current_block_size = read_32bitBE( vgmstream->current_block_offset, @@ -14,6 +16,6 @@ void halpst_block_update(off_t block_offset, VGMSTREAM * vgmstream) { for (i=0;ichannels;i++) { vgmstream->ch[i].offset = vgmstream->current_block_offset + - 0x20 + vgmstream->current_block_size*i; + header_length + vgmstream->current_block_size*i; } } diff --git a/Frameworks/vgmstream/vgmstream/src/meta/halpst.c b/Frameworks/vgmstream/vgmstream/src/meta/halpst.c index 32edda16b..caec16ade 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/halpst.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/halpst.c @@ -9,6 +9,7 @@ VGMSTREAM * init_vgmstream_halpst(STREAMFILE *streamFile) { int channel_count; int loop_flag = 0; + int header_length = 0x80; int32_t samples_l,samples_r; int32_t start_sample = 0; @@ -28,14 +29,20 @@ VGMSTREAM * init_vgmstream_halpst(STREAMFILE *streamFile) { channel_count = read_32bitBE(0xc,streamFile); max_block = read_32bitBE(0x10,streamFile)/channel_count; - if (channel_count != 1 && channel_count != 2) goto fail; + if (channel_count > 2) { + /* align the header length needed for the extra channels */ + header_length = 0x10+0x38*channel_count; + header_length = (header_length+0x1f)/0x20*0x20; + } /* yay for redundancy, gives us something to test */ samples_l = dsp_nibbles_to_samples(read_32bitBE(0x18,streamFile))+1; - if (channel_count == 2) { - samples_r = dsp_nibbles_to_samples(read_32bitBE(0x50,streamFile))+1; - - if (samples_l != samples_r) goto fail; + { + int i; + for (i=1;ich[0].adpcm_coef[i] = read_16bitBE(0x20+i*2,streamFile); - if (channel_count == 2) - for (i=0;i<16;i++) - vgmstream->ch[1].adpcm_coef[i] = read_16bitBE(0x58+i*2,streamFile); + int i,j; + for (i=0;ich[i].adpcm_coef[j] = read_16bitBE(0x20+0x38*i+j*2,streamFile); } /* open the file for reading by each channel */ @@ -115,7 +120,7 @@ VGMSTREAM * init_vgmstream_halpst(STREAMFILE *streamFile) { } /* start me up */ - halpst_block_update(0x80,vgmstream); + halpst_block_update(header_length,vgmstream); return vgmstream;