2020-05-24 16:22:40 +02:00
|
|
|
#include "meta.h"
|
2020-05-24 16:59:11 +02:00
|
|
|
#include "../coding/coding.h"
|
2020-05-24 16:22:40 +02:00
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
/* sadf - from Procyon Studio audio driver games [Xenoblade Chronicles 2 (Switch)] (sfx) */
|
|
|
|
VGMSTREAM* init_vgmstream_sadf(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
int channel_count, loop_flag;
|
2020-05-24 16:22:40 +02:00
|
|
|
off_t start_offset;
|
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
|
2020-05-24 16:22:40 +02:00
|
|
|
/* checks */
|
2020-05-24 16:59:11 +02:00
|
|
|
/* .sad: assumed (from older sadX formats)
|
|
|
|
* .nop: assumed (from streamed files)
|
|
|
|
* (extensionless): name in .xsp bigfiles */
|
|
|
|
if (!check_extensions(sf, "sad,nop,"))
|
2020-05-24 16:22:40 +02:00
|
|
|
goto fail;
|
2020-05-24 16:28:07 +02:00
|
|
|
|
|
|
|
if (read_32bitBE(0x00, sf) != 0x73616466) /* "sadf" */
|
2020-05-24 16:22:40 +02:00
|
|
|
goto fail;
|
2020-05-24 16:59:11 +02:00
|
|
|
if (read_32bitBE(0x08, sf) != 0x6470636D) /* "dpcm" ("opus" is used too, see opus.c, "ipcm" supposedly too) */
|
|
|
|
goto fail;
|
2020-05-24 16:22:40 +02:00
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
channel_count = read_8bit(0x18, sf);
|
|
|
|
loop_flag = read_8bit(0x19, sf);
|
|
|
|
start_offset = read_32bitLE(0x1C, sf);
|
2020-05-24 16:22:40 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
vgmstream->num_samples = read_32bitLE(0x28, sf);
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x24, sf);
|
2020-05-24 16:22:40 +02:00
|
|
|
if (loop_flag) {
|
2020-05-24 16:28:07 +02:00
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x2c, sf);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x30, sf);
|
2020-05-24 16:22:40 +02:00
|
|
|
}
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2020-05-24 16:28:07 +02:00
|
|
|
vgmstream->interleave_block_size = channel_count == 1 ? 0x8 : read_32bitLE(0x20, sf) / channel_count;
|
|
|
|
vgmstream->meta_type = meta_SADF;
|
2020-05-24 16:22:40 +02:00
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
dsp_read_coefs_le(vgmstream, sf, 0x80, 0x80);
|
2020-05-24 16:22:40 +02:00
|
|
|
|
2020-05-24 16:28:07 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2020-05-24 16:22:40 +02:00
|
|
|
goto fail;
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|