2021-07-23 18:55:03 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
#include "xwma_konami_streamfile.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* MSFC - Konami (Armature?) variation [Metal Gear Solid 2 HD (X360), Metal Gear Solid 3 HD (X360)] */
|
2023-01-21 22:08:46 +01:00
|
|
|
VGMSTREAM* init_vgmstream_xwma_konami(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2021-07-23 18:55:03 +02:00
|
|
|
off_t start_offset;
|
2023-01-21 22:08:46 +01:00
|
|
|
int loop_flag, channels, codec, sample_rate;
|
2021-07-23 18:55:03 +02:00
|
|
|
size_t data_size;
|
2023-01-21 22:08:46 +01:00
|
|
|
STREAMFILE *temp_sf = NULL;
|
2021-07-23 18:55:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* checks */
|
2023-01-21 22:08:46 +01:00
|
|
|
if (!is_id32be(0x00,sf, "XWMA"))
|
2021-07-23 18:55:03 +02:00
|
|
|
goto fail;
|
2023-01-21 22:08:46 +01:00
|
|
|
if (!check_extensions(sf,"xwma"))
|
2021-07-23 18:55:03 +02:00
|
|
|
goto fail;
|
|
|
|
|
2023-01-21 22:08:46 +01:00
|
|
|
codec = read_32bitBE(0x04,sf);
|
|
|
|
channels = read_32bitBE(0x08,sf);
|
|
|
|
sample_rate = read_32bitBE(0x0c,sf);
|
|
|
|
data_size = read_32bitBE(0x10,sf); /* data size without padding */
|
2021-07-23 18:55:03 +02:00
|
|
|
loop_flag = 0;
|
|
|
|
start_offset = 0x20;
|
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2023-01-21 22:08:46 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2021-07-23 18:55:03 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = sample_rate;
|
|
|
|
vgmstream->meta_type = meta_XWMA_KONAMI;
|
|
|
|
|
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
{
|
|
|
|
/* 0x10: related to size? */
|
2023-01-21 22:08:46 +01:00
|
|
|
int avg_bps = read_32bitBE(0x14, sf);
|
|
|
|
int block_align = read_32bitBE(0x18, sf);
|
2021-07-23 18:55:03 +02:00
|
|
|
|
|
|
|
/* data has padding (unrelated to KCEJ blocks) */
|
2023-01-21 22:08:46 +01:00
|
|
|
temp_sf = setup_xwma_konami_streamfile(sf, start_offset, block_align);
|
|
|
|
if (!temp_sf) goto fail;
|
2021-07-23 18:55:03 +02:00
|
|
|
|
2023-01-21 22:08:46 +01:00
|
|
|
vgmstream->codec_data = init_ffmpeg_xwma(temp_sf, 0x00, data_size, codec, channels, sample_rate, avg_bps, block_align);
|
2021-07-23 18:55:03 +02:00
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
/* manually find total samples */
|
|
|
|
{
|
|
|
|
ms_sample_data msd = {0};
|
|
|
|
|
|
|
|
msd.channels = vgmstream->channels;
|
|
|
|
msd.data_offset = 0x00;
|
|
|
|
msd.data_size = data_size;
|
|
|
|
|
|
|
|
|
|
|
|
if (codec == 0x0161)
|
2023-01-21 22:08:46 +01:00
|
|
|
wma_get_samples(&msd, temp_sf, block_align, vgmstream->sample_rate,0x001F);
|
2021-07-23 18:55:03 +02:00
|
|
|
//else //todo not correct
|
|
|
|
// wmapro_get_samples(&msd, temp_streamFile, block_align, vgmstream->sample_rate,0x00E0);
|
|
|
|
|
|
|
|
vgmstream->num_samples = msd.num_samples;
|
|
|
|
if (vgmstream->num_samples == 0)
|
|
|
|
vgmstream->num_samples = ffmpeg_get_samples(vgmstream->codec_data); /* from avg-br */
|
|
|
|
//num_samples seem to be found in the last "seek" table entry too, as: entry / channels / 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
goto fail;
|
|
|
|
#endif
|
|
|
|
|
2023-01-21 22:08:46 +01:00
|
|
|
close_streamfile(temp_sf);
|
2021-07-23 18:55:03 +02:00
|
|
|
return vgmstream;
|
|
|
|
fail:
|
2023-01-21 22:08:46 +01:00
|
|
|
close_streamfile(temp_sf);
|
2021-07-23 18:55:03 +02:00
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|