Fix EA .WVE with PCM8 [Madden NHL 97 (PC)]

This commit is contained in:
bnnm 2021-08-22 12:25:06 +02:00
parent e54d9ed20b
commit 65f6197ae4
2 changed files with 76 additions and 59 deletions

View File

@ -6,17 +6,20 @@
void block_update_ea_wve_ad10(off_t block_offset, VGMSTREAM* vgmstream) {
STREAMFILE* sf = vgmstream->ch[0].streamfile;
int i;
size_t block_size, channel_size = 0, interleave = 0;
uint32_t block_id;
size_t channel_size = 0, interleave = 0;
uint32_t block_id, block_size;
block_id = read_32bitBE(block_offset+0x00, sf);
block_size = read_32bitBE(block_offset+0x04, sf);
int flag_be = (vgmstream->codec_config & 0x01);
uint32_t (*read_u32)(off_t,STREAMFILE*) = flag_be ? read_u32be : read_u32le;
block_id = read_u32be(block_offset+0x00, sf);
block_size = read_u32 (block_offset+0x04, sf);
/* accept "Ad10/Ad11" audio block/footer */
if (block_id == 0x41643130 || block_id == 0x41643131) {
channel_size = block_size - 0x08; /* one block per channel */
interleave = block_size;
block_size = block_size*vgmstream->channels;
block_size = block_size * vgmstream->channels;
}
/* rest could be "MDEC" video blocks with 0 size/samples */

View File

@ -1,54 +1,68 @@
#include "meta.h"
#include "../coding/coding.h"
#include "../layout/layout.h"
/* EA WVE (Ad10) - from Electronic Arts PS movies [Wing Commander 3/4 (PS)] */
VGMSTREAM * init_vgmstream_ea_wve_ad10(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int loop_flag, channel_count;
/* checks */
if (!check_extensions(streamFile, "wve"))
goto fail;
start_offset = 0x00;
if (read_32bitBE(start_offset, streamFile) != 0x41643130 && /* "Ad10" */
read_32bitBE(start_offset, streamFile) != 0x41643131) /* "Ad11" (last block, but could be first) */
goto fail;
loop_flag = 0;
/* no header = no channels, but seems if the first PS-ADPCM header is 00 then it's mono, somehow
* (ex. Wing Commander 3 intro / Wing Commander 4 = stereo, rest of Wing Commander 3 = mono) */
channel_count = read_8bit(start_offset+0x08,streamFile) != 0 ? 2 : 1;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = 22050;
vgmstream->meta_type = meta_EA_WVE_AD10;
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_blocked_ea_wve_ad10;
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
/* calc num_samples manually */
{
vgmstream->next_block_offset = start_offset;
do {
block_update(vgmstream->next_block_offset,vgmstream);
vgmstream->num_samples += ps_bytes_to_samples(vgmstream->current_block_size, 1);
}
while (vgmstream->next_block_offset < get_streamfile_size(streamFile));
block_update(start_offset, vgmstream);
}
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}
#include "meta.h"
#include "../coding/coding.h"
#include "../layout/layout.h"
/* EA WVE (Ad10) - from early Electronic Arts movies [Wing Commander 3/4 (PS1), Madden NHL 97 (PC)-w95] */
VGMSTREAM* init_vgmstream_ea_wve_ad10(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset;
int loop_flag, channels;
int big_endian, is_ps1;
/* checks */
/* .wve: common
* .mov: Madden NHL 97 (also uses .wve) */
if (!check_extensions(sf, "wve,mov"))
goto fail;
start_offset = 0x00;
if (!is_id32be(0x00, sf, "AABB") && /* video block */
!is_id32be(0x00, sf, "Ad10") && /* audio block */
!is_id32be(0x00, sf, "Ad11")) /* last audio block, but could be first */
goto fail;
big_endian = guess_endianness32bit(0x04, sf);
if (is_id32be(0x00, sf, "AABB"))
start_offset += big_endian ? read_u32be(0x04, sf) : read_u32le(0x04, sf);
loop_flag = 0;
if (ps_check_format(sf, start_offset + 0x08, 0x40)) {
/* no header = no channels, but seems if the first PS-ADPCM header is 00 then it's mono, somehow
* (ex. Wing Commander 3 intro / Wing Commander 4 = stereo, rest of Wing Commander 3 = mono) */
channels = read_u8(start_offset + 0x08,sf) != 0 ? 2 : 1;
is_ps1 = 1;
VGM_LOG("ps1");
}
else {
channels = 1;
is_ps1 = 0;
}
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = 22050;
vgmstream->meta_type = meta_EA_WVE_AD10;
vgmstream->layout_type = layout_blocked_ea_wve_ad10;
vgmstream->codec_config = big_endian;
if (is_ps1)
vgmstream->coding_type = coding_PSX;
else
vgmstream->coding_type = coding_PCM8_U_int;
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
blocked_count_samples(vgmstream, sf, start_offset);
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}