2008-09-23 13:07:41 +02:00
|
|
|
#include "meta.h"
|
2020-11-21 15:55:46 +01:00
|
|
|
#include "../coding/coding.h"
|
|
|
|
|
2008-09-23 13:07:41 +02:00
|
|
|
|
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;
|
2020-11-21 15:55:46 +01:00
|
|
|
int channels, loop_flag;
|
2008-09-23 13:07:41 +02:00
|
|
|
off_t start_offset;
|
2020-11-21 15:55:46 +01:00
|
|
|
uint8_t flags;
|
|
|
|
uint32_t loop_start, data_size;
|
2008-09-23 13:07:41 +02:00
|
|
|
|
|
|
|
|
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-11-21 15:55:46 +01:00
|
|
|
if (read_u32be(0x00,sf) != 0x7361646c) /* "sadl" */
|
2008-09-23 13:07:41 +02:00
|
|
|
goto fail;
|
2020-11-21 15:55:46 +01:00
|
|
|
/* 04: null */
|
|
|
|
/* 08: data size, or null in later files */
|
|
|
|
/* 0c: version? (x0410=Luminous Arc, 0x0411=Layton, 0x0415=rest) */
|
|
|
|
/* 0e: file id (for .sad packed in .spd) */
|
|
|
|
/* 14: name related? */
|
|
|
|
/* 20: short filename (may be null or nor match full filename) */
|
|
|
|
|
|
|
|
/* 30: flags? (0/1/2) */
|
|
|
|
loop_flag = read_u8(0x31,sf);
|
|
|
|
channels = read_u8(0x32,sf);
|
|
|
|
flags = read_u8(0x33,sf);
|
|
|
|
/* 34: flags? */
|
|
|
|
/* 38: flags? */
|
|
|
|
/* 3c: null? */
|
|
|
|
data_size = read_u32le(0x40,sf); //?
|
|
|
|
start_offset = read_u32le(0x48,sf); /* usually 0x100, 0xc0 in LA */
|
|
|
|
/* 4c: start offset again or 0x40 in LA */
|
|
|
|
/* 50: size or samples? */
|
|
|
|
loop_start = read_u32le(0x54,sf); //?
|
|
|
|
/* others: sizes/samples/flags? */
|
|
|
|
|
|
|
|
data_size -= start_offset;
|
|
|
|
loop_start -= start_offset;
|
|
|
|
|
2008-09-23 13:07:41 +02:00
|
|
|
|
2019-11-02 16:10:23 +01:00
|
|
|
/* build the VGMSTREAM */
|
2020-11-21 15:55:46 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2008-09-23 13:07:41 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2020-11-21 15:55:46 +01:00
|
|
|
vgmstream->meta_type = meta_SADL;
|
|
|
|
|
|
|
|
switch (flags & 6) { /* possibly > 1? (0/1/2) */
|
2008-12-28 07:29:43 +01:00
|
|
|
case 4:
|
|
|
|
vgmstream->sample_rate = 32728;
|
|
|
|
break;
|
2020-11-21 15:55:46 +01:00
|
|
|
case 2: /* Layton */
|
|
|
|
case 0: /* Luminous Arc (DS) */
|
2008-12-28 07:29:43 +01:00
|
|
|
vgmstream->sample_rate = 16364;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
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-11-21 15:55:46 +01:00
|
|
|
switch(flags & 0xf0) { /* possibly >> 6? (0/1/2) */
|
|
|
|
case 0x00: /* Luminous Arc (DS) (non-int IMA? all files are mono though) */
|
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-11-21 15:55:46 +01:00
|
|
|
vgmstream->num_samples = ima_bytes_to_samples(data_size, channels);
|
|
|
|
vgmstream->loop_start_sample = ima_bytes_to_samples(loop_start, channels);
|
2019-11-02 16:10:23 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
2020-11-21 15:55:46 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < channels; i++) {
|
|
|
|
vgmstream->ch[i].adpcm_history1_32 = read_s16le(0x80 + i*0x04 + 0x00, sf);
|
|
|
|
vgmstream->ch[i].adpcm_step_index = read_s16le(0x80 + i*0x04 + 0x02, sf);
|
|
|
|
}
|
|
|
|
}
|
2019-11-02 16:10:23 +01:00
|
|
|
break;
|
2008-09-23 13:07:41 +02:00
|
|
|
|
2020-11-21 15:55:46 +01:00
|
|
|
//TODO: Luminous Arc 2 uses a variation of this, but value 0x70
|
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-11-21 15:55:46 +01:00
|
|
|
vgmstream->num_samples = data_size / channels / 16 * 30;
|
|
|
|
vgmstream->loop_start_sample = loop_start / channels / 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;
|
|
|
|
}
|