CRLF to LF

This commit is contained in:
bnnm 2020-04-04 22:07:13 +02:00
parent 44b700454a
commit fd3b240015

View File

@ -1,164 +1,164 @@
#include "meta.h" #include "meta.h"
#include "../layout/layout.h" #include "../layout/layout.h"
#include "../coding/coding.h" #include "../coding/coding.h"
typedef enum { NONE, PSX, DSP, XBOX } mul_codec; typedef enum { NONE, PSX, DSP, XBOX } mul_codec;
/* .MUL - from Crystal Dynamics games [Legacy of Kain: Defiance (PS2), Tomb Raider Underworld (multi)] */ /* .MUL - from Crystal Dynamics games [Legacy of Kain: Defiance (PS2), Tomb Raider Underworld (multi)] */
VGMSTREAM * init_vgmstream_mul(STREAMFILE *streamFile) { VGMSTREAM * init_vgmstream_mul(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL; VGMSTREAM * vgmstream = NULL;
off_t start_offset, coefs_offset = 0; off_t start_offset, coefs_offset = 0;
int loop_flag, channel_count, sample_rate, num_samples, loop_start; int loop_flag, channel_count, sample_rate, num_samples, loop_start;
int big_endian; int big_endian;
mul_codec codec = NONE; mul_codec codec = NONE;
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL; int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
/* checks */ /* checks */
/* .mul: found in the exe, used by the bigfile extractor (Gibbed.TombRaider) /* .mul: found in the exe, used by the bigfile extractor (Gibbed.TombRaider)
* (some files have companion .mus/sam files but seem to be sequences/control stuff) * (some files have companion .mus/sam files but seem to be sequences/control stuff)
* .(extensionless): filenames as found in the bigfile * .(extensionless): filenames as found in the bigfile
* .emff: fake extension ('Eidos Music File Format') */ * .emff: fake extension ('Eidos Music File Format') */
if (!check_extensions(streamFile, "mul,,emff")) if (!check_extensions(streamFile, "mul,,emff"))
goto fail; goto fail;
if (read_32bitBE(0x10,streamFile) != 0 || if (read_32bitBE(0x10,streamFile) != 0 ||
read_32bitBE(0x14,streamFile) != 0 || read_32bitBE(0x14,streamFile) != 0 ||
read_32bitBE(0x18,streamFile) != 0 || read_32bitBE(0x18,streamFile) != 0 ||
read_32bitBE(0x1c,streamFile) != 0) read_32bitBE(0x1c,streamFile) != 0)
goto fail; goto fail;
big_endian = guess_endianness32bit(0x00, streamFile); big_endian = guess_endianness32bit(0x00, streamFile);
read_32bit = big_endian ? read_32bitBE : read_32bitLE; read_32bit = big_endian ? read_32bitBE : read_32bitLE;
sample_rate = read_32bit(0x00,streamFile); sample_rate = read_32bit(0x00,streamFile);
loop_start = read_32bit(0x04,streamFile); loop_start = read_32bit(0x04,streamFile);
num_samples = read_32bit(0x08,streamFile); num_samples = read_32bit(0x08,streamFile);
channel_count = read_32bit(0x0C,streamFile); channel_count = read_32bit(0x0C,streamFile);
if (sample_rate < 8000 || sample_rate > 48000 || channel_count > 8) if (sample_rate < 8000 || sample_rate > 48000 || channel_count > 8)
goto fail; goto fail;
/* 0x20: flag when file has non-audio blocks (ignored by the layout) */ /* 0x20: flag when file has non-audio blocks (ignored by the layout) */
/* 0x24: same? */ /* 0x24: same? */
/* 0x28: loop offset within audio data (not file offset) */ /* 0x28: loop offset within audio data (not file offset) */
/* 0x2c: some value related to loop? */ /* 0x2c: some value related to loop? */
/* 0x34: id? */ /* 0x34: id? */
/* 0x38+: channel config until ~0x100? (multiple 0x3F800000 depending on the number of channels) */ /* 0x38+: channel config until ~0x100? (multiple 0x3F800000 depending on the number of channels) */
/* test known versions (later versions start from 0x24 instead of 0x20) */ /* test known versions (later versions start from 0x24 instead of 0x20) */
if (!(read_32bit(0x38,streamFile) == 0x3F800000 || if (!(read_32bit(0x38,streamFile) == 0x3F800000 ||
read_32bit(0x3c,streamFile) == 0x3F800000)) /* Tomb Raider Underworld */ read_32bit(0x3c,streamFile) == 0x3F800000)) /* Tomb Raider Underworld */
goto fail; goto fail;
loop_flag = (loop_start >= 0); /* 0xFFFFFFFF when not looping */ loop_flag = (loop_start >= 0); /* 0xFFFFFFFF when not looping */
start_offset = 0x800; start_offset = 0x800;
/* format is pretty limited so we need to guess codec */ /* format is pretty limited so we need to guess codec */
if (big_endian) { if (big_endian) {
/* test DSP (GC/Wii): check known coef locations */ /* test DSP (GC/Wii): check known coef locations */
if (read_32bitBE(0xC8,streamFile) != 0) { /* Tomb Raider Legend (GC) */ if (read_32bitBE(0xC8,streamFile) != 0) { /* Tomb Raider Legend (GC) */
codec = DSP; codec = DSP;
coefs_offset = 0xC8; coefs_offset = 0xC8;
} }
else if (read_32bitBE(0xCC,streamFile) != 0) { /* Tomb Raider Anniversary (Wii) */ else if (read_32bitBE(0xCC,streamFile) != 0) { /* Tomb Raider Anniversary (Wii) */
codec = DSP; codec = DSP;
coefs_offset = 0xCC; coefs_offset = 0xCC;
} }
else if (read_32bitBE(0x2D0,streamFile) != 0) { /* Tomb Raider Underworld (Wii) */ else if (read_32bitBE(0x2D0,streamFile) != 0) { /* Tomb Raider Underworld (Wii) */
codec = DSP; codec = DSP;
coefs_offset = 0x2D0; coefs_offset = 0x2D0;
} }
// todo test XMA1 (X360): mono streams, each block has 1 sub-blocks of 0x800 packet per channel // todo test XMA1 (X360): mono streams, each block has 1 sub-blocks of 0x800 packet per channel
// todo test ? (PS3) // todo test ? (PS3)
} }
else { else {
int i; int i;
off_t offset = start_offset; off_t offset = start_offset;
size_t file_size = get_streamfile_size(streamFile); size_t file_size = get_streamfile_size(streamFile);
size_t frame_size; size_t frame_size;
/* check first audio frame */ /* check first audio frame */
while (offset < file_size) { while (offset < file_size) {
uint32_t block_type = read_32bit(offset+0x00, streamFile); uint32_t block_type = read_32bit(offset+0x00, streamFile);
uint32_t block_size = read_32bit(offset+0x04, streamFile); uint32_t block_size = read_32bit(offset+0x04, streamFile);
uint32_t data_size = read_32bit(offset+0x10, streamFile); uint32_t data_size = read_32bit(offset+0x10, streamFile);
if (block_type != 0x00) { if (block_type != 0x00) {
offset += 0x10 + block_size; offset += 0x10 + block_size;
continue; /* not audio */ continue; /* not audio */
} }
/* test PS-ADPCM (PS2/PSP): flag is always 2 in .mul */ /* test PS-ADPCM (PS2/PSP): flag is always 2 in .mul */
frame_size = 0x10; frame_size = 0x10;
for (i = 0; i < data_size / frame_size; i++) { for (i = 0; i < data_size / frame_size; i++) {
if (read_8bit(offset + 0x20 + frame_size*i + 0x01, streamFile) != 0x02) if (read_8bit(offset + 0x20 + frame_size*i + 0x01, streamFile) != 0x02)
break; break;
} }
if (i == data_size / frame_size) { if (i == data_size / frame_size) {
codec = PSX; codec = PSX;
break; break;
} }
/* test XBOX-IMA (PC/Xbox): reserved frame header value is always 0 */ /* test XBOX-IMA (PC/Xbox): reserved frame header value is always 0 */
frame_size = 0x24; frame_size = 0x24;
for (i = 0; i < data_size / frame_size; i++) { for (i = 0; i < data_size / frame_size; i++) {
if (read_8bit(offset + 0x20 + frame_size*i + 0x03, streamFile) != 0x00) if (read_8bit(offset + 0x20 + frame_size*i + 0x03, streamFile) != 0x00)
break; break;
} }
if (i == data_size / frame_size) { if (i == data_size / frame_size) {
codec = XBOX; codec = XBOX;
break; break;
} }
break; break;
} }
} }
if (codec == NONE) { if (codec == NONE) {
VGM_LOG("MUL: unknown codec\n"); VGM_LOG("MUL: unknown codec\n");
goto fail; goto fail;
} }
/* build the VGMSTREAM */ /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag); vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail; if (!vgmstream) goto fail;
vgmstream->meta_type = meta_MUL; vgmstream->meta_type = meta_MUL;
vgmstream->sample_rate = sample_rate; vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples; vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start; vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = num_samples; vgmstream->loop_end_sample = num_samples;
vgmstream->codec_endian = big_endian; vgmstream->codec_endian = big_endian;
switch(codec) { switch(codec) {
case PSX: case PSX:
vgmstream->coding_type = coding_PSX; vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_blocked_mul; vgmstream->layout_type = layout_blocked_mul;
break; break;
case DSP: case DSP:
vgmstream->coding_type = coding_NGC_DSP; vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_blocked_mul; vgmstream->layout_type = layout_blocked_mul;
dsp_read_coefs_be(vgmstream,streamFile,coefs_offset+0x00,0x2e); dsp_read_coefs_be(vgmstream,streamFile,coefs_offset+0x00,0x2e);
dsp_read_hist_be (vgmstream,streamFile,coefs_offset+0x24,0x2e); dsp_read_hist_be (vgmstream,streamFile,coefs_offset+0x24,0x2e);
break; break;
case XBOX: case XBOX:
vgmstream->coding_type = coding_XBOX_IMA_int; vgmstream->coding_type = coding_XBOX_IMA_int;
vgmstream->layout_type = layout_blocked_mul; vgmstream->layout_type = layout_blocked_mul;
break; break;
default: default:
goto fail; goto fail;
} }
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail; goto fail;
return vgmstream; return vgmstream;
fail: fail:
close_vgmstream(vgmstream); close_vgmstream(vgmstream);
return NULL; return NULL;
} }