Fix .adm [Dragon Quest V (PS2)]

This commit is contained in:
bnnm 2018-02-25 15:04:29 +01:00
parent 3c1d4ee825
commit 494dfb8194
4 changed files with 75 additions and 64 deletions

View File

@ -846,6 +846,7 @@ static const meta_info meta_info_list[] = {
{meta_DSP_XIII, "XIII dsp header"}, {meta_DSP_XIII, "XIII dsp header"},
{meta_NGC_DSP_STH_STR, "STH dsp header"}, {meta_NGC_DSP_STH_STR, "STH dsp header"},
{meta_DSP_CABELAS, "Cabelas games dsp header"}, {meta_DSP_CABELAS, "Cabelas games dsp header"},
{meta_PS2_ADM, "Dragon Quest V .ADM raw header"},
{meta_PS2_LPCM, "LPCM header"}, {meta_PS2_LPCM, "LPCM header"},
{meta_PS2_VMS, "VMS Header"}, {meta_PS2_VMS, "VMS Header"},
{meta_XAU, "XPEC XAU header"}, {meta_XAU, "XPEC XAU header"},

View File

@ -1,18 +1,48 @@
#include "layout.h" #include "layout.h"
#include "../vgmstream.h" #include "../vgmstream.h"
/* set up for the block at the given offset */ /* blocks of 0x1000 with interleave 0x400 but also smaller last interleave */
void ps2_adm_block_update(off_t block_offset, VGMSTREAM * vgmstream) { void ps2_adm_block_update(off_t block_offset, VGMSTREAM * vgmstream) {
int i; STREAMFILE* streamFile = vgmstream->ch[0].streamfile;
int i, new_full_block;
size_t block_size, interleave_size, interleave_data;
vgmstream->current_block_offset = block_offset; /* no header */
vgmstream->current_block_size = 0x1000; /*read_32bitLE( interleave_size = 0x400;
vgmstream->current_block_offset+0x10, interleave_data = 0x400;
vgmstream->ch[0].streamfile); */ block_size = interleave_size * vgmstream->channels;
vgmstream->next_block_offset = vgmstream->current_block_offset + vgmstream->current_block_size;
//vgmstream->current_block_size/=vgmstream->channels;
for (i=0;i<vgmstream->channels;i++) { /* every 0x1000 is a full block, signaled by PS-ADPCM flags */
vgmstream->ch[i].offset = vgmstream->current_block_offset+(0x400*i); new_full_block = (read_8bit(block_offset+0x01, streamFile) == 0x06);
/* try to autodetect usable interleave data size as can be smaller when a discrete block ends (ex. 0x10~0x50, varies with file) */
if (!new_full_block) {
off_t next_block_offset = block_offset + block_size;
while (next_block_offset > block_offset) {
next_block_offset -= 0x10;
/* check if unused line (all blocks should only use flags 0x06/0x03/0x02) */
if (read_32bitLE(next_block_offset, streamFile) == 0x00000000) {
interleave_data -= 0x10;
next_block_offset -= 0x10;
}
else {
break;
}
}
}
vgmstream->current_block_offset = block_offset;
vgmstream->next_block_offset = block_offset + block_size;
vgmstream->current_block_size = interleave_data;
for (i = 0; i < vgmstream->channels; i++) {
vgmstream->ch[i].offset = block_offset + interleave_size*i;
//if (new_full_block) { /* blocks are not discrete */
// vgmstream->ch[i].adpcm_history1_32 = 0;
// vgmstream->ch[i].adpcm_step_index = 0;
//}
} }
} }

View File

@ -1,75 +1,55 @@
#include "meta.h" #include "meta.h"
#include "../layout/layout.h" #include "../layout/layout.h"
#include "../util.h" #include "../coding/coding.h"
/* WAD (from The golden Compass) */ /* .adm - from Dragon Quest V (PS2) */
VGMSTREAM * init_vgmstream_ps2_adm(STREAMFILE *streamFile) { VGMSTREAM * init_vgmstream_ps2_adm(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL; VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT]; int channel_count, loop_flag = 0;
int loop_flag = 0; off_t start_offset;
int channel_count;
int i;
off_t start_offset;
/* check extension, case insensitive */ /* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename)); if (!check_extensions(streamFile,"adm"))
if (strcasecmp("adm",filename_extension(filename))) goto fail; goto fail;
loop_flag = 0; /* raw data, but test some .ADM blocks as they always start with PS-ADPCM flag 0x06 every 0x1000 */
channel_count = 2;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
start_offset = 0x0;
vgmstream->channels = channel_count;
vgmstream->sample_rate = 44100;
vgmstream->coding_type = coding_PSX;
#if 0
vgmstream->num_samples = read_32bitLE(0x0,streamFile)/channel_count/16*28;
if (loop_flag) {
vgmstream->loop_start_sample = 0;
vgmstream->loop_end_sample = read_32bitLE(0x0,streamFile)/channel_count/16*28;
}
#endif
vgmstream->layout_type = layout_ps2_adm_blocked;
vgmstream->interleave_block_size = 0x400;
vgmstream->meta_type = meta_PS2_ADM;
/* open the file for reading by each channel */
{ {
for (i=0;i<channel_count;i++) { int i;
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,vgmstream->interleave_block_size); for (i = 0; i < 10; i++) {
if (read_8bit(0x1000*i + 0x01, streamFile) != 0x06)
if (!vgmstream->ch[i].streamfile) goto fail; goto fail;
vgmstream->ch[i].channel_start_offset=
vgmstream->ch[i].offset=i*vgmstream->interleave_block_size;
} }
} }
start_offset = 0x00;
loop_flag = 0; /* files loop, but apparently no info in the .adm or in the .dat bigfile containing them */
channel_count = 2;
/* Calc num_samples */ /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = 44100;
vgmstream->meta_type = meta_PS2_ADM;
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_ps2_adm_blocked;
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
/* calc num_samples as playable data size varies between files/blocks */
vgmstream->num_samples = 0; //ps_bytes_to_samples(get_streamfile_size(streamFile), channel_count);
ps2_adm_block_update(start_offset,vgmstream); ps2_adm_block_update(start_offset,vgmstream);
vgmstream->num_samples=0; //(get_streamfile_size(streamFile)/0x1000*0xFE0)/32*28;
do { do {
vgmstream->num_samples += ps_bytes_to_samples(vgmstream->current_block_size * channel_count, channel_count);
vgmstream->num_samples += 0xFE0*14/16;
ps2_adm_block_update(vgmstream->next_block_offset,vgmstream); ps2_adm_block_update(vgmstream->next_block_offset,vgmstream);
} while (vgmstream->next_block_offset<get_streamfile_size(streamFile)); } while (vgmstream->next_block_offset < get_streamfile_size(streamFile));
ps2_adm_block_update(start_offset,vgmstream); ps2_adm_block_update(start_offset,vgmstream);
return vgmstream; return vgmstream;
/* clean up anything we may have opened */
fail: fail:
if (vgmstream) close_vgmstream(vgmstream); close_vgmstream(vgmstream);
return NULL; return NULL;
} }

View File

@ -551,7 +551,7 @@ typedef enum {
meta_PS2_WAD, /* The golden Compass */ meta_PS2_WAD, /* The golden Compass */
meta_DSP_XIII, /* XIII, possibly more (Ubisoft header???) */ meta_DSP_XIII, /* XIII, possibly more (Ubisoft header???) */
meta_DSP_CABELAS, /* Cabelas games */ meta_DSP_CABELAS, /* Cabelas games */
meta_PS2_ADM, /* Dragon Quest 5 */ meta_PS2_ADM, /* Dragon Quest V (PS2) */
meta_PS2_LPCM, /* Ah! My Goddess */ meta_PS2_LPCM, /* Ah! My Goddess */
meta_DSP_BDSP, /* Ah! My Goddess */ meta_DSP_BDSP, /* Ah! My Goddess */
meta_PS2_VMS, /* Autobahn Raser - Police Madness */ meta_PS2_VMS, /* Autobahn Raser - Police Madness */