2017-11-27 20:22:10 +01:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
|
|
|
|
/* VXN - from Gameloft mobile games */
|
|
|
|
VGMSTREAM * init_vgmstream_vxn(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
int loop_flag = 0, channel_count, codec, sample_rate, block_align, bits, num_samples;
|
|
|
|
off_t start_offset, stream_offset, chunk_offset, first_offset = 0x00;
|
|
|
|
size_t stream_size;
|
2018-01-28 00:41:25 +01:00
|
|
|
int total_subsongs, target_subsong = streamFile->stream_index;
|
2017-11-27 20:22:10 +01:00
|
|
|
|
2019-10-20 16:35:52 +02:00
|
|
|
/* checks */
|
2017-11-27 20:22:10 +01:00
|
|
|
if (!check_extensions(streamFile,"vxn"))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x566F784E) /* "VoxN" */
|
|
|
|
goto fail;
|
|
|
|
if (read_32bitLE(0x10,streamFile) != get_streamfile_size(streamFile) )
|
|
|
|
goto fail;
|
|
|
|
|
2019-10-20 16:35:52 +02:00
|
|
|
/* header is RIFF-like with many custom chunks */
|
2017-11-27 20:22:10 +01:00
|
|
|
if (!find_chunk_le(streamFile, 0x41666D74,first_offset,0, &chunk_offset,NULL)) /* "Afmt" */
|
|
|
|
goto fail;
|
|
|
|
codec = (uint16_t)read_16bitLE(chunk_offset+0x00, streamFile);
|
|
|
|
channel_count = (uint16_t)read_16bitLE(chunk_offset+0x02, streamFile);
|
|
|
|
sample_rate = read_32bitLE(chunk_offset+0x04, streamFile);
|
|
|
|
block_align = (uint16_t)read_16bitLE(chunk_offset+0x08, streamFile);
|
2019-10-20 16:35:52 +02:00
|
|
|
bits = read_16bitLE(chunk_offset+0x0a, streamFile);
|
2017-11-27 20:22:10 +01:00
|
|
|
|
|
|
|
/* files are divided into segment subsongs, often a leadout and loop in that order
|
|
|
|
* (the "Plst" and "Rule" chunks may have order info) */
|
|
|
|
if (!find_chunk_le(streamFile, 0x5365676D,first_offset,0, &chunk_offset,NULL)) /* "Segm" */
|
|
|
|
goto fail;
|
2018-01-28 00:41:25 +01:00
|
|
|
total_subsongs = read_32bitLE(chunk_offset+0x00, streamFile);
|
|
|
|
if (target_subsong == 0) target_subsong = 1;
|
|
|
|
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
|
2017-11-27 20:22:10 +01:00
|
|
|
|
2018-01-28 00:41:25 +01:00
|
|
|
stream_offset = read_32bitLE(chunk_offset+0x04 + (target_subsong-1)*0x18 + 0x00, streamFile);
|
|
|
|
stream_size = read_32bitLE(chunk_offset+0x04 + (target_subsong-1)*0x18 + 0x04, streamFile);
|
|
|
|
num_samples = read_32bitLE(chunk_offset+0x04 + (target_subsong-1)*0x18 + 0x08, streamFile);
|
2017-11-27 20:22:10 +01:00
|
|
|
|
|
|
|
if (!find_chunk_le(streamFile, 0x44617461,first_offset,0, &chunk_offset,NULL)) /* "Data" */
|
|
|
|
goto fail;
|
|
|
|
start_offset = chunk_offset + stream_offset;
|
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = sample_rate;
|
|
|
|
vgmstream->num_samples = num_samples;
|
2018-01-28 00:41:25 +01:00
|
|
|
vgmstream->num_streams = total_subsongs;
|
|
|
|
vgmstream->stream_size = stream_size;
|
2017-11-27 20:22:10 +01:00
|
|
|
vgmstream->meta_type = meta_VXN;
|
|
|
|
|
|
|
|
switch (codec) {
|
2017-12-08 00:17:42 +01:00
|
|
|
case 0x0001: /* PCM */
|
|
|
|
if (bits != 16) goto fail;
|
|
|
|
|
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
|
|
|
vgmstream->interleave_block_size = block_align;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
break;
|
2017-11-27 20:22:10 +01:00
|
|
|
|
|
|
|
case 0x0002: /* MSADPCM (ex. Asphalt 7) */
|
|
|
|
if (bits != 4) goto fail;
|
|
|
|
|
|
|
|
vgmstream->coding_type = coding_MSADPCM;
|
2019-10-20 16:35:52 +02:00
|
|
|
vgmstream->frame_size = block_align;
|
2017-11-27 20:22:10 +01:00
|
|
|
vgmstream->layout_type = layout_none;
|
2019-10-20 16:35:52 +02:00
|
|
|
|
|
|
|
if (find_chunk_le(streamFile, 0x4D736165,first_offset,0, &chunk_offset,NULL)) { /* "Msae" */
|
|
|
|
if (!msadpcm_check_coefs(streamFile, chunk_offset + 0x02))
|
|
|
|
goto fail;
|
|
|
|
}
|
2017-11-27 20:22:10 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0011: /* MS-IMA (ex. Asphalt 6) */
|
|
|
|
if (bits != 16) goto fail;
|
|
|
|
|
|
|
|
vgmstream->coding_type = coding_MS_IMA;
|
|
|
|
vgmstream->interleave_block_size = block_align;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef VGM_USE_FFMPEG
|
2019-10-20 16:35:52 +02:00
|
|
|
case 0x0800: /* Musepack (ex. Asphalt Xtreme) */
|
|
|
|
if (bits != -1) goto fail;
|
2017-11-27 20:22:10 +01:00
|
|
|
|
2019-10-20 16:35:52 +02:00
|
|
|
vgmstream->codec_data = init_ffmpeg_offset(streamFile, start_offset,stream_size);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
2017-11-27 20:22:10 +01:00
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
2019-10-20 16:35:52 +02:00
|
|
|
|
|
|
|
/* unlike standard .mpc, .vxn has no seek table so no need to fix */
|
|
|
|
//ffmpeg_set_force_seek(vgmstream->codec_data);
|
2017-11-27 20:22:10 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
VGM_LOG("VXN: unknown codec 0x%02x\n", codec);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
|
|
|
goto fail;
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|