2008-09-23 13:07:41 +02:00
|
|
|
#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;
|
2008-09-23 13:07:41 +02:00
|
|
|
off_t start_offset;
|
|
|
|
|
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
/* checks */
|
2020-05-24 16:28:07 +02:00
|
|
|
if (!check_extensions(sf, "sad"))
|
2019-11-02 16:10:23 +01:00
|
|
|
goto fail;
|
2008-09-23 13:07:41 +02:00
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
if (read_32bitBE(0x00,sf) != 0x7361646c) /* "sadl" */
|
2008-09-23 13:07:41 +02:00
|
|
|
goto fail;
|
2020-05-24 16:28:07 +02:00
|
|
|
if (read_32bitLE(0x40,sf) != get_streamfile_size(sf))
|
2008-09-23 13:07:41 +02:00
|
|
|
goto fail;
|
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
loop_flag = read_8bit(0x31,sf);
|
|
|
|
channel_count = read_8bit(0x32,sf);
|
2019-11-02 16:10:23 +01:00
|
|
|
start_offset = 0x100;
|
2008-09-23 13:07:41 +02:00
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
/* build the VGMSTREAM */
|
2008-09-23 13:07:41 +02:00
|
|
|
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) {
|
2008-12-28 07:29:43 +01:00
|
|
|
case 4:
|
|
|
|
vgmstream->sample_rate = 32728;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
vgmstream->sample_rate = 16364;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
vgmstream->meta_type = meta_SADL;
|
2008-12-28 07:29:43 +01:00
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x10;
|
2008-12-28 07:29:43 +01:00
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
switch(read_8bit(0x33,sf) & 0xf0) {
|
2019-11-02 16:10:23 +01:00
|
|
|
case 0x70: /* Ni no Kuni (DS), Professor Layton and the Curious Village (DS), Soma Bringer (DS) */
|
|
|
|
vgmstream->coding_type = coding_IMA_int;
|
2008-09-23 13:07:41 +02:00
|
|
|
|
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;
|
2019-11-02 16:10:23 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
break;
|
2008-09-23 13:07:41 +02:00
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
case 0xb0: /* Soma Bringer (DS), Rekishi Taisen Gettenka (DS) */
|
|
|
|
vgmstream->coding_type = coding_NDS_PROCYON;
|
2008-09-23 13:07:41 +02:00
|
|
|
|
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;
|
2019-11-02 16:10:23 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
break;
|
2008-09-23 13:07:41 +02:00
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
default:
|
|
|
|
goto fail;
|
2008-09-23 13:07:41 +02:00
|
|
|
}
|
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2019-11-02 16:10:23 +01:00
|
|
|
goto fail;
|
2008-09-23 13:07:41 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2019-11-02 16:10:23 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-09-23 13:07:41 +02:00
|
|
|
return NULL;
|
|
|
|
}
|