vgmstream/src/meta/sadl.c

72 lines
2.1 KiB
C
Raw Normal View History

#include "meta.h"
2020-05-24 16:28:07 +02:00
/* sadl - from DS games with Procyon Studio audio driver [Professor Layton (DS), Soma Bringer (DS)] */
VGMSTREAM* init_vgmstream_sadl(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
int channel_count, loop_flag;
off_t start_offset;
/* checks */
2020-05-24 16:28:07 +02:00
if (!check_extensions(sf, "sad"))
goto fail;
2020-05-24 16:28:07 +02:00
if (read_32bitBE(0x00,sf) != 0x7361646c) /* "sadl" */
goto fail;
2020-05-24 16:28:07 +02:00
if (read_32bitLE(0x40,sf) != get_streamfile_size(sf))
goto fail;
2020-05-24 16:28:07 +02:00
loop_flag = read_8bit(0x31,sf);
channel_count = read_8bit(0x32,sf);
start_offset = 0x100;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
2020-05-24 16:28:07 +02:00
switch (read_8bit(0x33,sf) & 6) {
case 4:
vgmstream->sample_rate = 32728;
break;
case 2:
vgmstream->sample_rate = 16364;
break;
default:
goto fail;
}
vgmstream->meta_type = meta_SADL;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10;
2020-05-24 16:28:07 +02:00
switch(read_8bit(0x33,sf) & 0xf0) {
case 0x70: /* Ni no Kuni (DS), Professor Layton and the Curious Village (DS), Soma Bringer (DS) */
vgmstream->coding_type = coding_IMA_int;
2020-05-24 16:28:07 +02:00
vgmstream->num_samples = (read_32bitLE(0x40,sf)-start_offset)/channel_count*2;
vgmstream->loop_start_sample = (read_32bitLE(0x54,sf)-start_offset)/channel_count*2;
vgmstream->loop_end_sample = vgmstream->num_samples;
break;
case 0xb0: /* Soma Bringer (DS), Rekishi Taisen Gettenka (DS) */
vgmstream->coding_type = coding_NDS_PROCYON;
2020-05-24 16:28:07 +02:00
vgmstream->num_samples = (read_32bitLE(0x40,sf)-start_offset)/channel_count/16*30;
vgmstream->loop_start_sample = (read_32bitLE(0x54,sf)-start_offset)/channel_count/16*30;
vgmstream->loop_end_sample = vgmstream->num_samples;
break;
default:
goto fail;
}
2020-05-24 16:28:07 +02:00
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}