Remove fake extension .sgx (use .sgh+sgd)

This commit is contained in:
bnnm 2023-07-23 13:56:50 +02:00
parent b67406a683
commit 5d7883fed1
2 changed files with 22 additions and 41 deletions

View File

@ -498,7 +498,6 @@ static const char* extension_list[] = {
"sgb",
"sgd",
"sgt",
"sgx",
"slb", //txth/reserved [THE Nekomura no Hitobito (PS2)]
"sli",
"smc",

View File

@ -3,16 +3,15 @@
#include "../util/chunks.h"
/* SGXD - Sony/SCEI's format (SGB+SGH / SGD / SGX) */
/* SGXD - Sony/SCEI's SGX lib (cousin of RXWS) */
VGMSTREAM* init_vgmstream_sgxd(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
STREAMFILE* sf_head = NULL;
STREAMFILE* sf_body = NULL;
off_t start_offset, data_offset, chunk_offset, name_offset = 0;
size_t stream_size;
uint32_t base1_offset, base2_offset, base3_offset;
int is_sgx, is_sgd = 0;
uint32_t /*base1_offset,*/ base2_offset, base3_offset;
int is_sgd = 0;
int loop_flag, channels, codec, sample_rate;
int32_t num_samples, loop_start_sample, loop_end_sample;
int total_subsongs, target_subsong = sf->stream_index;
@ -28,35 +27,31 @@ VGMSTREAM* init_vgmstream_sgxd(STREAMFILE* sf) {
}
if (!is_id32be(0x00,sf_head, "SGXD"))
goto fail;
return NULL;
/* checks */
/* .sgx: header+data (Genji)
* .sgd: header+data (common)
/* .sgd: header+data (common)
* .sgh+sgd: header+data (streams) */
if (!check_extensions(sf,"sgx,sgd,sgb"))
goto fail;
if (!check_extensions(sf,"sgd,sgb"))
return NULL;
/* SGXD base (size 0x10), always LE even on PS3 */
/* 0x04: SGX = full header size
SGD/SGH = bank name offset (part of NAME table, usually same as filename) */
/* 0x08: SGX = first chunk offset? (0x10)
SGD/SGH = full header size */
/* 0x0c: SGX/SGH = full data size with padding /
SGD = full data size ^ (1<<31) with padding */
base1_offset = read_u32le(0x04, sf_head);
/* 0x04: SGD/SGH = bank name offset (part of NAME table, usually same as filename) */
/* 0x08: SGD/SGH = full header size */
/* 0x0c: SGH = full data size with padding
* SGD = full data size ^ (1<<31) with padding */
//base1_offset = read_u32le(0x04, sf_head);
base2_offset = read_u32le(0x08, sf_head);
base3_offset = read_u32le(0x0c, sf_head);
is_sgx = base2_offset == 0x10; /* fixed size */
is_sgd = base3_offset & (1 << 31); /* flag */
/* Ogg SGXD don't have flag (probably due to codec hijack, or should be split), allow since it's not so obvious */
if (!(is_sgx || is_sgd) && get_streamfile_size(sf_head) != base2_offset) /* sgh but wrong header size must be sgd */
if (!(is_sgd) && get_streamfile_size(sf_head) != base2_offset) /* sgh but wrong header size must be sgd */
is_sgd = 1;
/* for plugins that start with .sgh (and don't check extensions) */
if (!(is_sgx || is_sgd) && sf == sf_head) {
if (!(is_sgd) && sf == sf_head) {
sf_body = open_streamfile_by_ext(sf, "sgb");
if (!sf_body) goto fail;
}
@ -65,9 +60,7 @@ VGMSTREAM* init_vgmstream_sgxd(STREAMFILE* sf) {
}
if (is_sgx) {
data_offset = base1_offset;
} else if (is_sgd) {
if (is_sgd) {
data_offset = base2_offset;
} else {
data_offset = 0x00;
@ -76,7 +69,7 @@ VGMSTREAM* init_vgmstream_sgxd(STREAMFILE* sf) {
/* Format per chunk:
* - 0x00: id
* - 0x04: SGX: unknown; SGD/SGH: chunk length
* - 0x04: chunk length
* - 0x08: null
* - 0x0c: entries */
@ -103,14 +96,8 @@ VGMSTREAM* init_vgmstream_sgxd(STREAMFILE* sf) {
* - BUSS: bus config? */
/* WAVE chunk (size 0x10 + files * 0x38 + optional padding) */
if (is_sgx) { /* position after chunk+size */
if (!is_id32be(0x10,sf_head, "WAVE"))
goto fail;
chunk_offset = 0x18;
} else {
if (!find_chunk_le(sf_head, get_id32be("WAVE"),0x10,0, &chunk_offset, NULL))
goto fail;
}
if (!find_chunk_le(sf_head, get_id32be("WAVE"),0x10,0, &chunk_offset, NULL))
goto fail;
/* check multi-streams (usually only SE containers; Puppeteer) */
total_subsongs = read_s32le(chunk_offset+0x04,sf_head);
@ -123,8 +110,7 @@ VGMSTREAM* init_vgmstream_sgxd(STREAMFILE* sf) {
chunk_offset += 0x08 + 0x38 * (target_subsong-1); /* position in target header*/
/* 0x00: ? (00/01/02) */
if (!is_sgx) /* meaning unknown in .sgx; offset 0 = not a stream (a RGND sample) */
name_offset = read_u32le(chunk_offset+0x04,sf_head);
name_offset = read_u32le(chunk_offset+0x04,sf_head);
codec = read_u8(chunk_offset+0x08,sf_head);
channels = read_u8(chunk_offset+0x09,sf_head);
/* 0x0a: null */
@ -141,13 +127,9 @@ VGMSTREAM* init_vgmstream_sgxd(STREAMFILE* sf) {
loop_end_sample = read_s32le(chunk_offset+0x28,sf_head);
stream_size = read_u32le(chunk_offset+0x2c,sf_head); /* stream size (without padding) / interleave (for type3) */
if (is_sgx) {
stream_offset = 0x0;
} else{
stream_offset = read_u32le(chunk_offset+0x30,sf_head);
}
/* 0x34: SGX = unknown
* SGD/SGH = stream size (with padding) / interleave */
stream_offset = read_u32le(chunk_offset+0x30,sf_head);
/* 0x34: SGD/SGH = stream size (with padding) / interleave */
loop_flag = loop_start_sample != -1 && loop_end_sample != -1;
start_offset = data_offset + stream_offset;