2009-02-06 20:16:37 +01:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2020-06-21 01:17:19 +02:00
|
|
|
|
|
|
|
/* SWAV - from Gameloft(?) games [Asphalt Urban GT (DS), Asphalt Urban GT 2 (DS)] */
|
|
|
|
VGMSTREAM* init_vgmstream_swav(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
int channel_count, loop_flag;
|
2009-02-06 20:16:37 +01:00
|
|
|
off_t start_offset;
|
2020-06-21 01:17:19 +02:00
|
|
|
int codec_number, bits_per_sample;
|
|
|
|
coding_t coding_type;
|
2009-02-06 20:16:37 +01:00
|
|
|
|
|
|
|
|
2020-06-21 01:17:19 +02:00
|
|
|
/* checks */
|
|
|
|
/* .swav: standard
|
|
|
|
* .adpcm: Merlin - A Servant of Two Masters (DS) */
|
|
|
|
if (!check_extensions(sf, "swav,adpcm"))
|
2009-02-06 20:16:37 +01:00
|
|
|
goto fail;
|
|
|
|
|
2020-06-21 01:17:19 +02:00
|
|
|
if (read_u32be(0x00,sf) != 0x53574156) /* "SWAV" */
|
|
|
|
goto fail;
|
|
|
|
if (read_u32be(0x10,sf) != 0x44415441) /* "DATA" */
|
2009-02-06 20:16:37 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check type details */
|
2020-06-21 01:17:19 +02:00
|
|
|
codec_number = read_8bit(0x18,sf);
|
|
|
|
loop_flag = read_8bit(0x19,sf);
|
2009-04-06 00:27:35 +02:00
|
|
|
|
|
|
|
channel_count = 1;
|
2020-06-21 01:17:19 +02:00
|
|
|
if (get_streamfile_size(sf) != read_s32le(0x08,sf)) {
|
|
|
|
if (get_streamfile_size(sf) != (read_s32le(0x08,sf) - 0x24) * 2 + 0x24)
|
2009-04-06 00:27:35 +02:00
|
|
|
goto fail;
|
|
|
|
channel_count = 2;
|
|
|
|
}
|
2009-04-05 22:22:55 +02:00
|
|
|
|
2020-06-21 01:17:19 +02:00
|
|
|
switch (codec_number) {
|
2009-02-06 20:16:37 +01:00
|
|
|
case 0:
|
|
|
|
coding_type = coding_PCM8;
|
2009-04-05 22:22:55 +02:00
|
|
|
bits_per_sample = 8;
|
2009-02-06 20:16:37 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
coding_type = coding_PCM16LE;
|
2009-04-05 22:22:55 +02:00
|
|
|
bits_per_sample = 16;
|
2009-02-06 20:16:37 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-04-29 02:53:36 +02:00
|
|
|
coding_type = coding_IMA_int;
|
2009-04-05 22:22:55 +02:00
|
|
|
bits_per_sample = 4;
|
2009-02-06 20:16:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2020-06-21 01:17:19 +02:00
|
|
|
start_offset = 0x24;
|
|
|
|
|
2009-02-06 20:16:37 +01:00
|
|
|
|
2020-06-21 01:17:19 +02:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
2009-02-06 20:16:37 +01:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2020-06-21 01:17:19 +02:00
|
|
|
vgmstream->num_samples = (read_s32le(0x14,sf) - 0x14) * 8 / bits_per_sample;
|
|
|
|
vgmstream->sample_rate = read_u16le(0x1A,sf);
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_u16le(0x1E,sf) * 32 / bits_per_sample;
|
|
|
|
vgmstream->loop_end_sample = read_s32le(0x20,sf) * 32 / bits_per_sample + vgmstream->loop_start_sample;
|
|
|
|
}
|
2009-04-05 22:22:55 +02:00
|
|
|
|
2017-04-29 02:53:36 +02:00
|
|
|
if (coding_type == coding_IMA_int) {
|
2009-04-06 00:27:35 +02:00
|
|
|
/* handle IMA frame header */
|
2009-04-05 22:22:55 +02:00
|
|
|
vgmstream->loop_start_sample -= 32 / bits_per_sample;
|
|
|
|
vgmstream->loop_end_sample -= 32 / bits_per_sample;
|
|
|
|
vgmstream->num_samples -= 32 / bits_per_sample;
|
2009-04-06 00:27:35 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
2020-06-21 01:17:19 +02:00
|
|
|
for (i = 0; i < channel_count; i++) {
|
|
|
|
vgmstream->ch[i].adpcm_history1_32 = read_s16le(start_offset + 0 + 4*i, sf);
|
|
|
|
vgmstream->ch[i].adpcm_step_index = read_s16le(start_offset + 2 + 4*i, sf);
|
2009-04-06 00:27:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
start_offset += 4 * channel_count;
|
2009-04-05 22:22:55 +02:00
|
|
|
}
|
2020-06-21 01:17:19 +02:00
|
|
|
|
|
|
|
vgmstream->coding_type = coding_type;
|
|
|
|
vgmstream->meta_type = meta_SWAV;
|
2009-04-06 00:27:35 +02:00
|
|
|
if (channel_count == 2) {
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 1;
|
|
|
|
} else {
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
}
|
2009-02-06 20:16:37 +01:00
|
|
|
|
2020-06-21 01:17:19 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
|
|
|
goto fail;
|
2009-02-06 20:16:37 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2020-06-21 01:17:19 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2009-02-06 20:16:37 +01:00
|
|
|
return NULL;
|
2009-02-08 09:36:33 +01:00
|
|
|
}
|