2011-01-17 22:22:10 +01:00
|
|
|
#include "meta.h"
|
2017-12-09 19:01:36 +01:00
|
|
|
#include "../layout/layout.h"
|
2017-01-13 23:47:52 +01:00
|
|
|
#include "../coding/coding.h"
|
2011-01-17 22:22:10 +01:00
|
|
|
|
2017-01-07 17:04:21 +01:00
|
|
|
|
2018-08-19 10:07:27 +02:00
|
|
|
/* VAWX - found in feelplus games [No More Heroes: Heroes Paradise (PS3/X360), Moon Diver (PS3/X360)] */
|
2017-01-07 17:04:21 +01:00
|
|
|
VGMSTREAM * init_vgmstream_vawx(STREAMFILE *streamFile) {
|
2011-01-17 22:22:10 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2017-09-29 23:26:42 +02:00
|
|
|
off_t start_offset, data_size;
|
2018-08-19 10:07:27 +02:00
|
|
|
int loop_flag = 0, channel_count, codec;
|
2011-01-17 22:22:10 +01:00
|
|
|
|
|
|
|
|
2018-08-19 10:07:27 +02:00
|
|
|
/* checks */
|
|
|
|
/* .xwv: actual extension [Moon Diver (PS3/X360)]
|
|
|
|
* .vawx: header id */
|
|
|
|
if ( !check_extensions(streamFile, "xwv,vawx") )
|
2017-01-07 17:04:21 +01:00
|
|
|
goto fail;
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x56415758) /* "VAWX" */
|
2011-01-17 22:22:10 +01:00
|
|
|
goto fail;
|
|
|
|
|
2017-01-07 17:04:21 +01:00
|
|
|
loop_flag = read_8bit(0x37,streamFile);
|
2018-08-19 10:07:27 +02:00
|
|
|
channel_count = read_8bit(0x39,streamFile);
|
|
|
|
start_offset = 0x800; /* ? read_32bitLE(0x0c,streamFile); */
|
|
|
|
codec = read_8bit(0x36,streamFile); /* could be at 0x38 too */
|
|
|
|
|
|
|
|
|
2017-01-07 17:04:21 +01:00
|
|
|
/* build the VGMSTREAM */
|
2011-01-17 22:22:10 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2017-01-07 17:04:21 +01:00
|
|
|
/* 0x04: filesize */
|
|
|
|
/* 0x16: file id */
|
|
|
|
vgmstream->num_samples = read_32bitBE(0x3c,streamFile);
|
2011-01-17 22:22:10 +01:00
|
|
|
vgmstream->sample_rate = read_32bitBE(0x40,streamFile);
|
|
|
|
|
2017-01-07 17:04:21 +01:00
|
|
|
vgmstream->meta_type = meta_VAWX;
|
|
|
|
|
2018-08-19 10:07:27 +02:00
|
|
|
switch(codec) {
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
case 2: /* PS-ADPCM */
|
2017-01-07 17:04:21 +01:00
|
|
|
vgmstream->coding_type = coding_PSX;
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
vgmstream->layout_type = channel_count == 6 ? layout_blocked_vawx : layout_interleave;
|
2017-01-07 17:04:21 +01:00
|
|
|
vgmstream->interleave_block_size = 0x10;
|
|
|
|
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(0x44,streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x48,streamFile);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef VGM_USE_FFMPEG
|
2017-01-13 23:47:52 +01:00
|
|
|
case 1: { /* XMA2 */
|
2017-01-07 17:04:21 +01:00
|
|
|
ffmpeg_codec_data *ffmpeg_data = NULL;
|
2017-09-29 23:26:42 +02:00
|
|
|
uint8_t buf[0x100];
|
2017-01-13 23:47:52 +01:00
|
|
|
int32_t bytes, block_size, block_count;
|
2017-01-07 17:04:21 +01:00
|
|
|
|
2017-09-29 23:26:42 +02:00
|
|
|
data_size = get_streamfile_size(streamFile)-start_offset;
|
|
|
|
block_size = 0x10000; /* VAWX default */
|
|
|
|
block_count = (uint16_t)read_16bitBE(0x3A, streamFile); /* also at 0x56 */
|
|
|
|
|
|
|
|
bytes = ffmpeg_make_riff_xma2(buf,0x100, vgmstream->num_samples, data_size, vgmstream->channels, vgmstream->sample_rate, block_count, block_size);
|
|
|
|
ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,data_size);
|
2017-01-07 17:04:21 +01:00
|
|
|
if ( !ffmpeg_data ) goto fail;
|
|
|
|
vgmstream->codec_data = ffmpeg_data;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(0x44,streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x48,streamFile);
|
2011-01-17 22:22:10 +01:00
|
|
|
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
/* may be only applying end_skip to num_samples? */
|
|
|
|
xma_fix_raw_samples(vgmstream, streamFile, start_offset,data_size, 0, 0,0);
|
2017-01-07 17:04:21 +01:00
|
|
|
break;
|
2011-01-17 22:22:10 +01:00
|
|
|
}
|
2017-01-07 17:04:21 +01:00
|
|
|
|
|
|
|
case 7: { /* ATRAC3 */
|
2017-09-29 23:26:42 +02:00
|
|
|
uint8_t buf[0x100];
|
2017-01-13 23:47:52 +01:00
|
|
|
int32_t bytes, block_size, encoder_delay, joint_stereo, max_samples;
|
2017-01-07 17:04:21 +01:00
|
|
|
|
2017-09-29 23:26:42 +02:00
|
|
|
data_size = read_32bitBE(0x54,streamFile);
|
2017-01-13 23:47:52 +01:00
|
|
|
block_size = 0x98 * vgmstream->channels;
|
2017-01-07 17:04:21 +01:00
|
|
|
joint_stereo = 0;
|
2017-09-29 23:26:42 +02:00
|
|
|
max_samples = atrac3_bytes_to_samples(data_size, block_size);
|
2017-04-07 21:18:38 +02:00
|
|
|
encoder_delay = 0x0; //max_samples - vgmstream->num_samples; /* todo not correct */
|
|
|
|
vgmstream->num_samples = max_samples; /* use calc samples since loop points are too, breaks looping in some files otherwise */
|
2017-01-07 17:04:21 +01:00
|
|
|
|
|
|
|
/* make a fake riff so FFmpeg can parse the ATRAC3 */
|
2017-09-29 23:26:42 +02:00
|
|
|
bytes = ffmpeg_make_riff_atrac3(buf,0x100, vgmstream->num_samples, data_size, vgmstream->channels, vgmstream->sample_rate, block_size, joint_stereo, encoder_delay);
|
|
|
|
vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,data_size);
|
2017-04-07 21:18:38 +02:00
|
|
|
if (!vgmstream->codec_data) goto fail;
|
2017-01-07 17:04:21 +01:00
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
2017-04-07 21:18:38 +02:00
|
|
|
vgmstream->loop_start_sample = atrac3_bytes_to_samples(read_32bitBE(0x44,streamFile), block_size);
|
|
|
|
vgmstream->loop_end_sample = atrac3_bytes_to_samples(read_32bitBE(0x48,streamFile), block_size);
|
|
|
|
//vgmstream->loop_start_sample -= encoder_delay;
|
|
|
|
//vgmstream->loop_end_sample -= encoder_delay;
|
2017-01-07 17:04:21 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
|
2011-01-17 22:22:10 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 17:04:21 +01:00
|
|
|
|
2017-01-14 00:59:54 +01:00
|
|
|
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
2017-01-07 17:04:21 +01:00
|
|
|
goto fail;
|
2011-01-17 22:22:10 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-01-07 17:04:21 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2011-01-17 22:22:10 +01:00
|
|
|
return NULL;
|
|
|
|
}
|