2011-01-13 09:11:58 +01:00
|
|
|
#include "meta.h"
|
2023-06-30 22:59:22 +02:00
|
|
|
#include "../coding/coding.h"
|
2011-01-13 09:11:58 +01:00
|
|
|
|
2023-06-30 22:59:22 +02:00
|
|
|
/* .lsf - from Gizmondo Studios Helsingborg/Atod AB games [Chicane Street Racing (Gizmondo), Fastlane Street Racing (iOS)] */
|
|
|
|
VGMSTREAM* init_vgmstream_lsf_n1nj4n(STREAMFILE *sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
uint32_t start_offset, data_size, loop_start = 0, loop_end = 0;
|
|
|
|
int channels, loop_flag, sample_rate;
|
|
|
|
bool is_v2 = false;
|
2011-01-13 09:11:58 +01:00
|
|
|
|
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
/* checks */
|
2023-06-30 22:59:22 +02:00
|
|
|
if ((read_u64be(0x00, sf) & 0xFFFFFFFFFFFFFF00) == get_id64be("!n1nj4n\0"))
|
|
|
|
is_v2 = false;
|
|
|
|
else if ((read_u64be(0x00, sf) & 0xFFFFFFFFFFFFFF00) == get_id64be("n1nj4n!\0"))
|
|
|
|
is_v2 = true; /* some files in Agaju: The Sacred Path (Gizmondo) */
|
|
|
|
else
|
|
|
|
return NULL;
|
2019-11-02 16:10:23 +01:00
|
|
|
|
2023-06-30 22:59:22 +02:00
|
|
|
/* .lsf: actual extension, exe strings seem to call this format "LSF" as well */
|
|
|
|
if (!check_extensions(sf, "lsf"))
|
|
|
|
return NULL;
|
2011-01-13 09:11:58 +01:00
|
|
|
|
2023-06-30 22:59:22 +02:00
|
|
|
uint8_t flags = read_u8(0x07, sf);
|
|
|
|
uint32_t offset = 0x08;
|
|
|
|
|
|
|
|
if (flags & 0x01) {
|
|
|
|
loop_start = read_u32le(offset + 0x00,sf);
|
|
|
|
loop_end = read_u32le(offset + 0x04,sf);
|
|
|
|
offset += 0x08;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & 0x01) && (flags & 0x02)) {
|
|
|
|
//00: loop hist related?
|
|
|
|
offset += 0x04;
|
|
|
|
}
|
2011-01-13 09:11:58 +01:00
|
|
|
|
2023-06-30 22:59:22 +02:00
|
|
|
if (flags & 0x02) {
|
|
|
|
int count = read_u32le(offset + 0x00,sf); /* not channels */
|
|
|
|
// per entry:
|
|
|
|
// 00: channel related?
|
|
|
|
// 04: null?
|
|
|
|
// 0c: ~0x3130?
|
|
|
|
offset += 0x04 + 0x0c * count;
|
|
|
|
}
|
2011-01-13 09:11:58 +01:00
|
|
|
|
2023-06-30 22:59:22 +02:00
|
|
|
sample_rate = read_u32le(offset + 0x00, sf);
|
|
|
|
data_size = read_u32le(offset + 0x04, sf);
|
|
|
|
offset += 0x08;
|
|
|
|
start_offset = offset;
|
|
|
|
|
|
|
|
if (start_offset + data_size != get_streamfile_size(sf))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
channels = 1;
|
|
|
|
loop_flag = loop_end > 0;
|
2019-11-02 16:10:23 +01:00
|
|
|
|
2011-01-13 09:11:58 +01:00
|
|
|
/* build the VGMSTREAM */
|
2023-06-30 22:59:22 +02:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2011-01-13 09:11:58 +01:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
vgmstream->meta_type = meta_LSF_N1NJ4N;
|
2023-06-30 22:59:22 +02:00
|
|
|
vgmstream->sample_rate = sample_rate;
|
|
|
|
|
|
|
|
if (is_v2) {
|
|
|
|
vgmstream->coding_type = coding_PSX_cfg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->frame_size = 0x10;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* custom codec but basically obfuscted PSX-cfg */
|
|
|
|
vgmstream->coding_type = coding_LSF;
|
|
|
|
vgmstream->layout_type = layout_interleave; //TODO: flat but decoder doesn't handle it
|
|
|
|
vgmstream->interleave_block_size = 0x1c;
|
|
|
|
vgmstream->frame_size = 0x1c; /* fixed but used below */
|
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream->num_samples = ps_cfg_bytes_to_samples(data_size, vgmstream->frame_size, channels);
|
|
|
|
vgmstream->loop_start_sample = ps_cfg_bytes_to_samples(loop_start, vgmstream->frame_size, channels);
|
|
|
|
vgmstream->loop_end_sample = ps_cfg_bytes_to_samples(loop_end, vgmstream->frame_size, channels);
|
2011-01-13 09:11:58 +01:00
|
|
|
|
2023-06-30 22:59:22 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
|
2019-11-02 16:10:23 +01:00
|
|
|
goto fail;
|
2011-01-13 09:11:58 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2019-11-02 16:10:23 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2011-01-13 09:11:58 +01:00
|
|
|
return NULL;
|
|
|
|
}
|