This commit is contained in:
bnnm 2024-01-18 22:17:11 +01:00
parent 3f9b0b65b6
commit d24e194f13
8 changed files with 20146 additions and 20149 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,23 +2,21 @@
#include "../coding/coding.h"
/* 2PFS - from Konami Games [Mahoromatic: Moetto - KiraKira Maid-San (PS2), GANTZ The Game (PS2)] */
VGMSTREAM* init_vgmstream_ps2_2pfs(STREAMFILE *sf) {
VGMSTREAM * vgmstream = NULL;
/* 2PFS - from Konami Games [Mahoromatic: Moetto-KiraKira Maid-San (PS2), GANTZ The Game (PS2)] */
VGMSTREAM* init_vgmstream_ps2_2pfs(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset;
int loop_flag, channels, version, interleave;
int loop_start_block, loop_end_block; /* block number */
int loop_start_block, loop_end_block;
int loop_start_adjust, loop_end_adjust; /* loops start/end a few samples into the start/end block */
/* checks */
/* .sap: standard
* .2pfs: header id? (Mahoromatic) */
if (!check_extensions(sf, "sap,2pfs"))
goto fail;
if (read_u32be(0x00,sf) != 0x32504653) /* "2PFS" */
goto fail;
if (!is_id32be(0x00,sf, "2PFS"))
return NULL;
/* .sap: standard */
if (!check_extensions(sf, "sap"))
return NULL;
version = read_u16le(0x04,sf);
if (version != 0x01 && version != 0x02) /* v1: Mahoromatic, v2: Gantz */
@ -77,7 +75,6 @@ VGMSTREAM* init_vgmstream_ps2_2pfs(STREAMFILE *sf) {
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;

View File

@ -4,7 +4,7 @@
/* WB - from Psychonauts (PS2) */
VGMSTREAM* init_vgmstream_pwb(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
int channels, loop_flag;
int channels, loop_flag;
uint32_t stream_offset, stream_size, loop_start, loop_end;
@ -54,7 +54,7 @@ VGMSTREAM* init_vgmstream_pwb(STREAMFILE* sf) {
}
/* build the VGMSTREAM */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
@ -65,7 +65,7 @@ VGMSTREAM* init_vgmstream_pwb(STREAMFILE* sf) {
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, channels);
vgmstream->loop_end_sample = ps_bytes_to_samples(loop_end, channels);
vgmstream->coding_type = coding_PSX;
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_none;
vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = stream_size;

View File

@ -3,19 +3,19 @@
/* STM - from Angel Studios/Rockstar San Diego games [Red Dead Revolver (PS2), Spy Hunter 2 (PS2/Xbox)] */
VGMSTREAM* init_vgmstream_stma(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset;
VGMSTREAM* vgmstream = NULL;
off_t start_offset;
int loop_flag = 0, channel_count;
int big_endian, bps, interleave, data_size, loop_start = 0, loop_end = 0;
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
/* checks */
/* checks */
if (!is_id32be(0x00,sf, "STMA") && /* LE */
!is_id32be(0x00,sf, "AMTS")) /* BE */
goto fail;
/* .stm: real extension
/* .stm: real extension
* .lstm: for plugins */
if (!check_extensions(sf,"stm,lstm"))
goto fail;

View File

@ -1,11 +1,11 @@
#ifndef _UBI_BAO_STREAMFILE_H_
#define _UBI_BAO_STREAMFILE_H_
//todo fix dupe code, but would be nice to keep it all in separate compilation units
#include "ubi_sb_streamfile.h"
static STREAMFILE* setup_ubi_bao_streamfile(STREAMFILE *streamFile, off_t stream_offset, size_t stream_size, int layer_number, int layer_count, int big_endian) {
return setup_ubi_sb_streamfile(streamFile, stream_offset, stream_size, layer_number, layer_count, big_endian, 0);
}
#endif /* _UBI_BAO_STREAMFILE_H_ */
#ifndef _UBI_BAO_STREAMFILE_H_
#define _UBI_BAO_STREAMFILE_H_
//todo fix dupe code, but would be nice to keep it all in separate compilation units
#include "ubi_sb_streamfile.h"
static STREAMFILE* setup_ubi_bao_streamfile(STREAMFILE *streamFile, off_t stream_offset, size_t stream_size, int layer_number, int layer_count, int big_endian) {
return setup_ubi_sb_streamfile(streamFile, stream_offset, stream_size, layer_number, layer_count, big_endian, 0);
}
#endif /* _UBI_BAO_STREAMFILE_H_ */

View File

@ -9,11 +9,11 @@ VGMSTREAM* init_vgmstream_waf(STREAMFILE* sf) {
/* checks */
if (!check_extensions(sf, "waf"))
goto fail;
if (!is_id32be(0x00,sf, "WAF\0"))
goto fail;
return NULL;
if (!check_extensions(sf, "waf"))
return NULL;
if (read_u32le(0x34,sf) + 0x38 != get_streamfile_size(sf))
goto fail;

View File

@ -1,150 +1,150 @@
#ifndef _READER_SF_H
#define _READER_SF_H
#include "../streamfile.h"
#include "reader_get.h"
/* Sometimes you just need an int, and we're doing the buffering.
* Note, however, that if these fail to read they'll return -1,
* so that should not be a valid value or there should be some backup. */
static inline int16_t read_16bitLE(off_t offset, STREAMFILE* sf) {
uint8_t buf[2];
if (read_streamfile(buf,offset,2,sf)!=2) return -1;
return get_s16le(buf);
}
static inline int16_t read_16bitBE(off_t offset, STREAMFILE* sf) {
uint8_t buf[2];
if (read_streamfile(buf,offset,2,sf)!=2) return -1;
return get_s16be(buf);
}
static inline int32_t read_32bitLE(off_t offset, STREAMFILE* sf) {
uint8_t buf[4];
if (read_streamfile(buf,offset,4,sf)!=4) return -1;
return get_s32le(buf);
}
static inline int32_t read_32bitBE(off_t offset, STREAMFILE* sf) {
uint8_t buf[4];
if (read_streamfile(buf,offset,4,sf)!=4) return -1;
return get_s32be(buf);
}
static inline int64_t read_s64le(off_t offset, STREAMFILE* sf) {
uint8_t buf[8];
if (read_streamfile(buf,offset,8,sf)!=8) return -1;
return get_s64le(buf);
}
static inline uint64_t read_u64le(off_t offset, STREAMFILE* sf) { return (uint64_t)read_s64le(offset, sf); }
static inline int64_t read_s64be(off_t offset, STREAMFILE* sf) {
uint8_t buf[8];
if (read_streamfile(buf,offset,8,sf)!=8) return -1;
return get_s64be(buf);
}
static inline uint64_t read_u64be(off_t offset, STREAMFILE* sf) { return (uint64_t)read_s64be(offset, sf); }
static inline int8_t read_8bit(off_t offset, STREAMFILE* sf) {
uint8_t buf[1];
if (read_streamfile(buf,offset,1,sf)!=1) return -1;
return buf[0];
}
/* alias of the above */
static inline int8_t read_s8 (off_t offset, STREAMFILE* sf) { return read_8bit(offset, sf); }
static inline uint8_t read_u8 (off_t offset, STREAMFILE* sf) { return (uint8_t) read_8bit(offset, sf); }
static inline int16_t read_s16le(off_t offset, STREAMFILE* sf) { return read_16bitLE(offset, sf); }
static inline uint16_t read_u16le(off_t offset, STREAMFILE* sf) { return (uint16_t)read_16bitLE(offset, sf); }
static inline int16_t read_s16be(off_t offset, STREAMFILE* sf) { return read_16bitBE(offset, sf); }
static inline uint16_t read_u16be(off_t offset, STREAMFILE* sf) { return (uint16_t)read_16bitBE(offset, sf); }
static inline int32_t read_s32le(off_t offset, STREAMFILE* sf) { return read_32bitLE(offset, sf); }
static inline uint32_t read_u32le(off_t offset, STREAMFILE* sf) { return (uint32_t)read_32bitLE(offset, sf); }
static inline int32_t read_s32be(off_t offset, STREAMFILE* sf) { return read_32bitBE(offset, sf); }
static inline uint32_t read_u32be(off_t offset, STREAMFILE* sf) { return (uint32_t)read_32bitBE(offset, sf); }
static inline float read_f32be(off_t offset, STREAMFILE* sf) {
uint8_t buf[4];
if (read_streamfile(buf, offset, sizeof(buf), sf) != sizeof(buf))
return -1;
return get_f32be(buf);
}
static inline float read_f32le(off_t offset, STREAMFILE* sf) {
uint8_t buf[4];
if (read_streamfile(buf, offset, sizeof(buf), sf) != sizeof(buf))
return -1;
return get_f32le(buf);
}
#if 0
// on GCC, this reader will be correctly optimized out (as long as it's static/inline), would be same as declaring:
// uintXX_t (*read_uXX)(off_t,uint8_t*) = be ? get_uXXbe : get_uXXle;
// only for the functions actually used in code, and inlined if possible (like big_endian param being a constant).
// on MSVC seems all read_X in sf_reader are compiled and included in the translation unit, plus ignores constants
// so may result on bloatness?
// (from godbolt tests, test more real cases)
/* collection of callbacks for quick access */
typedef struct sf_reader {
int32_t (*read_s32)(off_t,STREAMFILE*); //maybe r.s32
float (*read_f32)(off_t,STREAMFILE*);
/* ... */
} sf_reader;
static inline void sf_reader_init(sf_reader* r, int big_endian) {
memset(r, 0, sizeof(sf_reader));
if (big_endian) {
r->read_s32 = read_s32be;
r->read_f32 = read_f32be;
}
else {
r->read_s32 = read_s32le;
r->read_f32 = read_f32le;
}
}
/* sf_reader r;
* ...
* sf_reader_init(&r, big_endian);
* val = r.read_s32; //maybe r.s32?
*/
#endif
#if 0 //todo improve + test + simplify code (maybe not inline?)
static inline int read_s4h(off_t offset, STREAMFILE* sf) {
uint8_t byte = read_u8(offset, streamfile);
return get_nibble_signed(byte, 1);
}
static inline int read_u4h(off_t offset, STREAMFILE* sf) {
uint8_t byte = read_u8(offset, streamfile);
return (byte >> 4) & 0x0f;
}
static inline int read_s4l(off_t offset, STREAMFILE* sf) {
...
}
static inline int read_u4l(off_t offset, STREAMFILE* sf) {
...
}
static inline int max_s32(int32_t a, int32_t b) { return a > b ? a : b; }
static inline int min_s32(int32_t a, int32_t b) { return a < b ? a : b; }
//align32, align16, clamp16, etc
#endif
/* fastest to compare would be read_u32x == (uint32), but should be pre-optimized (see get_id32x) */
static inline /*const*/ int is_id32be(off_t offset, STREAMFILE* sf, const char* s) {
return read_u32be(offset, sf) == get_id32be(s);
}
static inline /*const*/ int is_id32le(off_t offset, STREAMFILE* sf, const char* s) {
return read_u32le(offset, sf) == get_id32be(s);
}
static inline /*const*/ int is_id64be(off_t offset, STREAMFILE* sf, const char* s) {
return read_u64be(offset, sf) == get_id64be(s);
}
#endif
#ifndef _READER_SF_H
#define _READER_SF_H
#include "../streamfile.h"
#include "reader_get.h"
/* Sometimes you just need an int, and we're doing the buffering.
* Note, however, that if these fail to read they'll return -1,
* so that should not be a valid value or there should be some backup. */
static inline int16_t read_16bitLE(off_t offset, STREAMFILE* sf) {
uint8_t buf[2];
if (read_streamfile(buf,offset,2,sf)!=2) return -1;
return get_s16le(buf);
}
static inline int16_t read_16bitBE(off_t offset, STREAMFILE* sf) {
uint8_t buf[2];
if (read_streamfile(buf,offset,2,sf)!=2) return -1;
return get_s16be(buf);
}
static inline int32_t read_32bitLE(off_t offset, STREAMFILE* sf) {
uint8_t buf[4];
if (read_streamfile(buf,offset,4,sf)!=4) return -1;
return get_s32le(buf);
}
static inline int32_t read_32bitBE(off_t offset, STREAMFILE* sf) {
uint8_t buf[4];
if (read_streamfile(buf,offset,4,sf)!=4) return -1;
return get_s32be(buf);
}
static inline int64_t read_s64le(off_t offset, STREAMFILE* sf) {
uint8_t buf[8];
if (read_streamfile(buf,offset,8,sf)!=8) return -1;
return get_s64le(buf);
}
static inline uint64_t read_u64le(off_t offset, STREAMFILE* sf) { return (uint64_t)read_s64le(offset, sf); }
static inline int64_t read_s64be(off_t offset, STREAMFILE* sf) {
uint8_t buf[8];
if (read_streamfile(buf,offset,8,sf)!=8) return -1;
return get_s64be(buf);
}
static inline uint64_t read_u64be(off_t offset, STREAMFILE* sf) { return (uint64_t)read_s64be(offset, sf); }
static inline int8_t read_8bit(off_t offset, STREAMFILE* sf) {
uint8_t buf[1];
if (read_streamfile(buf,offset,1,sf)!=1) return -1;
return buf[0];
}
/* alias of the above */
static inline int8_t read_s8 (off_t offset, STREAMFILE* sf) { return read_8bit(offset, sf); }
static inline uint8_t read_u8 (off_t offset, STREAMFILE* sf) { return (uint8_t) read_8bit(offset, sf); }
static inline int16_t read_s16le(off_t offset, STREAMFILE* sf) { return read_16bitLE(offset, sf); }
static inline uint16_t read_u16le(off_t offset, STREAMFILE* sf) { return (uint16_t)read_16bitLE(offset, sf); }
static inline int16_t read_s16be(off_t offset, STREAMFILE* sf) { return read_16bitBE(offset, sf); }
static inline uint16_t read_u16be(off_t offset, STREAMFILE* sf) { return (uint16_t)read_16bitBE(offset, sf); }
static inline int32_t read_s32le(off_t offset, STREAMFILE* sf) { return read_32bitLE(offset, sf); }
static inline uint32_t read_u32le(off_t offset, STREAMFILE* sf) { return (uint32_t)read_32bitLE(offset, sf); }
static inline int32_t read_s32be(off_t offset, STREAMFILE* sf) { return read_32bitBE(offset, sf); }
static inline uint32_t read_u32be(off_t offset, STREAMFILE* sf) { return (uint32_t)read_32bitBE(offset, sf); }
static inline float read_f32be(off_t offset, STREAMFILE* sf) {
uint8_t buf[4];
if (read_streamfile(buf, offset, sizeof(buf), sf) != sizeof(buf))
return -1;
return get_f32be(buf);
}
static inline float read_f32le(off_t offset, STREAMFILE* sf) {
uint8_t buf[4];
if (read_streamfile(buf, offset, sizeof(buf), sf) != sizeof(buf))
return -1;
return get_f32le(buf);
}
#if 0
// on GCC, this reader will be correctly optimized out (as long as it's static/inline), would be same as declaring:
// uintXX_t (*read_uXX)(off_t,uint8_t*) = be ? get_uXXbe : get_uXXle;
// only for the functions actually used in code, and inlined if possible (like big_endian param being a constant).
// on MSVC seems all read_X in sf_reader are compiled and included in the translation unit, plus ignores constants
// so may result on bloatness?
// (from godbolt tests, test more real cases)
/* collection of callbacks for quick access */
typedef struct sf_reader {
int32_t (*read_s32)(off_t,STREAMFILE*); //maybe r.s32
float (*read_f32)(off_t,STREAMFILE*);
/* ... */
} sf_reader;
static inline void sf_reader_init(sf_reader* r, int big_endian) {
memset(r, 0, sizeof(sf_reader));
if (big_endian) {
r->read_s32 = read_s32be;
r->read_f32 = read_f32be;
}
else {
r->read_s32 = read_s32le;
r->read_f32 = read_f32le;
}
}
/* sf_reader r;
* ...
* sf_reader_init(&r, big_endian);
* val = r.read_s32; //maybe r.s32?
*/
#endif
#if 0 //todo improve + test + simplify code (maybe not inline?)
static inline int read_s4h(off_t offset, STREAMFILE* sf) {
uint8_t byte = read_u8(offset, streamfile);
return get_nibble_signed(byte, 1);
}
static inline int read_u4h(off_t offset, STREAMFILE* sf) {
uint8_t byte = read_u8(offset, streamfile);
return (byte >> 4) & 0x0f;
}
static inline int read_s4l(off_t offset, STREAMFILE* sf) {
...
}
static inline int read_u4l(off_t offset, STREAMFILE* sf) {
...
}
static inline int max_s32(int32_t a, int32_t b) { return a > b ? a : b; }
static inline int min_s32(int32_t a, int32_t b) { return a < b ? a : b; }
//align32, align16, clamp16, etc
#endif
/* fastest to compare would be read_u32x == (uint32), but should be pre-optimized (see get_id32x) */
static inline /*const*/ int is_id32be(off_t offset, STREAMFILE* sf, const char* s) {
return read_u32be(offset, sf) == get_id32be(s);
}
static inline /*const*/ int is_id32le(off_t offset, STREAMFILE* sf, const char* s) {
return read_u32le(offset, sf) == get_id32be(s);
}
static inline /*const*/ int is_id64be(off_t offset, STREAMFILE* sf, const char* s) {
return read_u64be(offset, sf) == get_id64be(s);
}
#endif

View File

@ -1,21 +1,21 @@
#ifndef _READER_TEXT_H
#define _READER_TEXT_H
#include "../streamfile.h"
/* Read into dst a line delimited by CRLF (Windows) / LF (Unux) / CR (Mac) / EOF, null-terminated
* and without line feeds. Returns bytes read (including CR/LF), *not* the same as string length.
* p_line_ok is set to 1 if the complete line was read; pass NULL to ignore. */
size_t read_line(char* buf, int buf_size, off_t offset, STREAMFILE* sf, int* p_line_ok);
/* skip BOM if needed */
size_t read_bom(STREAMFILE* sf);
/* reads a c-string (ANSI only), up to bufsize or NULL, returning size. buf is optional (works as get_string_size). */
size_t read_string(char* buf, size_t buf_size, off_t offset, STREAMFILE* sf);
/* reads a UTF16 string... but actually only as ANSI (discards the upper byte) */
size_t read_string_utf16(char* buf, size_t buf_size, off_t offset, STREAMFILE* sf, int big_endian);
size_t read_string_utf16le(char* buf, size_t buf_size, off_t offset, STREAMFILE* sf);
size_t read_string_utf16be(char* buf, size_t buf_size, off_t offset, STREAMFILE* sf);
#endif
#ifndef _READER_TEXT_H
#define _READER_TEXT_H
#include "../streamfile.h"
/* Read into dst a line delimited by CRLF (Windows) / LF (Unux) / CR (Mac) / EOF, null-terminated
* and without line feeds. Returns bytes read (including CR/LF), *not* the same as string length.
* p_line_ok is set to 1 if the complete line was read; pass NULL to ignore. */
size_t read_line(char* buf, int buf_size, off_t offset, STREAMFILE* sf, int* p_line_ok);
/* skip BOM if needed */
size_t read_bom(STREAMFILE* sf);
/* reads a c-string (ANSI only), up to bufsize or NULL, returning size. buf is optional (works as get_string_size). */
size_t read_string(char* buf, size_t buf_size, off_t offset, STREAMFILE* sf);
/* reads a UTF16 string... but actually only as ANSI (discards the upper byte) */
size_t read_string_utf16(char* buf, size_t buf_size, off_t offset, STREAMFILE* sf, int big_endian);
size_t read_string_utf16le(char* buf, size_t buf_size, off_t offset, STREAMFILE* sf);
size_t read_string_utf16be(char* buf, size_t buf_size, off_t offset, STREAMFILE* sf);
#endif