mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-24 06:50:20 +01:00
cleanup: experiment
This commit is contained in:
parent
55e6ec3244
commit
1185bf0689
@ -1,13 +1,10 @@
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
#include "../util/meta_utils.h"
|
||||
|
||||
|
||||
/* SVS - SeqVagStream from Square games [Unlimited Saga (PS2) music] */
|
||||
VGMSTREAM* init_vgmstream_svs(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
int channels, loop_flag, pitch;
|
||||
|
||||
|
||||
/* checks */
|
||||
if (!is_id32be(0x00,sf, "SVS\0"))
|
||||
@ -17,39 +14,30 @@ VGMSTREAM* init_vgmstream_svs(STREAMFILE* sf) {
|
||||
if (!check_extensions(sf, "bgm,svs"))
|
||||
return NULL;
|
||||
|
||||
meta_header_t h = {
|
||||
.meta = meta_SVS,
|
||||
};
|
||||
/* 0x04: flags (1=stereo?, 2=loop) */
|
||||
pitch = read_s32le(0x10,sf); /* usually 0x1000 = 48000 */
|
||||
//h.loop_start = read_s32le(0x08,sf) * 28; /* frame count (0x10 * ch) */
|
||||
h.loop_end = read_s32le(0x0c,sf) * 28; /* frame count (not exact num_samples when no loop) */
|
||||
int pitch = read_s32le(0x10,sf); /* usually 0x1000 = 48000 */
|
||||
/* 0x14: volume? */
|
||||
/* 0x18: file id (may be null) */
|
||||
/* 0x1c: null */
|
||||
h.stream_offset = 0x20;
|
||||
h.stream_size = get_streamfile_size(sf) - h.stream_offset;
|
||||
|
||||
loop_flag = (read_s32le(0x08,sf) > 0); /* loop start frame, min is 1 */
|
||||
channels = 2;
|
||||
start_offset = 0x20;
|
||||
h.channels = 2;
|
||||
h.sample_rate = round10((48000 * pitch) / 4096); /* music = ~44100, ambience = 48000 (rounding makes more sense but not sure) */
|
||||
h.num_samples = ps_bytes_to_samples(h.stream_size, h.channels);
|
||||
/* loop start/end on the same frame rarely happens too (ex. file_id 63 SVS), perhaps loop should be +1 */
|
||||
h.loop_flag = (h.loop_start > 0); /* min is 1 */
|
||||
|
||||
h.coding = coding_PSX;
|
||||
h.layout = layout_interleave;
|
||||
h.interleave = 0x10;
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channels, loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->meta_type = meta_SVS;
|
||||
vgmstream->sample_rate = round10((48000 * pitch) / 4096); /* music = ~44100, ambience = 48000 (rounding makes more sense but not sure) */
|
||||
vgmstream->num_samples = ps_bytes_to_samples(get_streamfile_size(sf) - start_offset, channels);
|
||||
if (loop_flag) {
|
||||
vgmstream->loop_start_sample = read_s32le(0x08,sf) * 28; /* frame count (0x10*ch) */
|
||||
vgmstream->loop_end_sample = read_s32le(0x0c,sf) * 28; /* frame count, (not exact num_samples when no loop) */
|
||||
/* start/end on the same frame rarely happens too (ex. file_id 63 SVS), perhaps loop should be +1 */
|
||||
}
|
||||
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = 0x10;
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
h.sf = sf;
|
||||
h.open_stream = true;
|
||||
return alloc_metastream(&h);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user