Fix some .cnk SCHl [NBA Live 97 (PS1)]

This commit is contained in:
bnnm 2021-10-10 13:04:43 +02:00
parent b8ab88c404
commit 45020c8acf

View File

@ -1,118 +1,155 @@
#include "meta.h" #include "meta.h"
#include "../layout/layout.h" #include "../layout/layout.h"
#include "../coding/coding.h" #include "../coding/coding.h"
/* Possibly the same as EA_CODEC_x in variable SCHl */ /* Possibly the same as EA_CODEC_x in variable SCHl */
#define EA_CODEC_PCM 0x00 #define EA_CODEC_PCM 0x00
#define EA_CODEC_IMA 0x02 #define EA_CODEC_IMA 0x02
#define EA_CODEC_PSX 0x06
typedef struct {
int8_t version; typedef struct {
int8_t bps; int8_t version;
int8_t channels; int8_t bps;
int8_t codec; int8_t channels;
int16_t sample_rate; int8_t codec;
int32_t num_samples; int sample_rate;
int32_t num_samples;
int big_endian;
int loop_flag; int big_endian;
} ea_fixed_header; int loop_flag;
} ea_fixed_header;
static int parse_fixed_header(STREAMFILE* streamFile, ea_fixed_header* ea, off_t begin_offset);
static int parse_fixed_header(STREAMFILE* sf, ea_fixed_header* ea);
/* EA SCHl with fixed header - from EA games (~1997? ex. NHL 97 PC) */
VGMSTREAM * init_vgmstream_ea_schl_fixed(STREAMFILE *streamFile) { /* EA SCHl with fixed header - from EA games (~1997?) */
VGMSTREAM * vgmstream = NULL; VGMSTREAM* init_vgmstream_ea_schl_fixed(STREAMFILE* sf) {
off_t start_offset; VGMSTREAM* vgmstream = NULL;
size_t header_size; off_t start_offset;
ea_fixed_header ea = {0}; size_t header_size;
ea_fixed_header ea = {0};
/* checks */
/* .asf: original /* checks */
* .lasf: fake for plugins */ if (!is_id32be(0x00,sf, "SCHl"))
if (!check_extensions(streamFile,"asf,lasf")) goto fail;
goto fail;
/* .asf: original [NHK 97 (PC)]
/* check header (see ea_schl.c for more info about blocks) */ * .lasf: fake for plugins
if (read_32bitBE(0x00,streamFile) != 0x5343486C) /* "SCHl" */ * .cnk: ps1 [NBA Live 97 (PS1)] */
goto fail; if (!check_extensions(sf,"asf,lasf,cnk"))
goto fail;
header_size = read_32bitLE(0x04,streamFile);
/* see ea_schl.c for more info about blocks */
if (!parse_fixed_header(streamFile,&ea, 0x08)) //TODO: handle SCCl? [NBA Live 97 (PS1)]
goto fail;
header_size = read_u32le(0x04,sf);
start_offset = header_size;
if (!parse_fixed_header(sf, &ea))
goto fail;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(ea.channels, ea.loop_flag); start_offset = header_size;
if (!vgmstream) goto fail;
vgmstream->sample_rate = ea.sample_rate; /* build the VGMSTREAM */
vgmstream->num_samples = ea.num_samples; vgmstream = allocate_vgmstream(ea.channels, ea.loop_flag);
//vgmstream->loop_start_sample = ea.loop_start; if (!vgmstream) goto fail;
//vgmstream->loop_end_sample = ea.loop_end;
vgmstream->sample_rate = ea.sample_rate;
vgmstream->codec_endian = ea.big_endian; vgmstream->num_samples = ea.num_samples;
//vgmstream->loop_start_sample = ea.loop_start;
vgmstream->meta_type = meta_EA_SCHL_fixed; //vgmstream->loop_end_sample = ea.loop_end;
vgmstream->layout_type = layout_blocked_ea_schl; vgmstream->codec_endian = ea.big_endian;
switch (ea.codec) { vgmstream->meta_type = meta_EA_SCHL_fixed;
case EA_CODEC_PCM: vgmstream->layout_type = layout_blocked_ea_schl;
vgmstream->coding_type = ea.bps==8 ? coding_PCM8 : (ea.big_endian ? coding_PCM16BE : coding_PCM16LE);
break; switch (ea.codec) {
case EA_CODEC_PCM:
case EA_CODEC_IMA: vgmstream->coding_type = ea.bps==8 ? coding_PCM8 : (ea.big_endian ? coding_PCM16BE : coding_PCM16LE);
vgmstream->coding_type = coding_DVI_IMA; /* stereo/mono, high nibble first */ break;
break;
case EA_CODEC_IMA:
default: vgmstream->coding_type = coding_DVI_IMA; /* stereo/mono, high nibble first */
VGM_LOG("EA: unknown codec 0x%02x\n", ea.codec); break;
goto fail;
} case EA_CODEC_PSX:
vgmstream->coding_type = coding_PSX;
break;
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail; default:
return vgmstream; VGM_LOG("EA: unknown codec 0x%02x\n", ea.codec);
goto fail;
fail: }
close_vgmstream(vgmstream);
return NULL;
} if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
static int parse_fixed_header(STREAMFILE* streamFile, ea_fixed_header* ea, off_t begin_offset) {
off_t offset = begin_offset; fail:
close_vgmstream(vgmstream);
if (read_32bitBE(offset+0x00, streamFile) != 0x5041546C && /* "PATl" */ return NULL;
read_32bitBE(offset+0x38, streamFile) != 0x544D706C) /* "TMpl" */ }
goto fail;
offset += 0x3c; /* after TMpl */ static int parse_fixed_header(STREAMFILE* sf, ea_fixed_header* ea) {
ea->version = read_8bit(offset+0x00, streamFile); uint32_t offset = 0x00, size = 0;
ea->bps = read_8bit(offset+0x01, streamFile);
ea->channels = read_8bit(offset+0x02, streamFile); if (is_id32be(offset+0x08, sf, "PATl"))
ea->codec = read_8bit(offset+0x03, streamFile); offset = 0x08;
VGM_ASSERT(read_16bitLE(offset+0x04, streamFile) != 0, "EA SCHl fixed: unknown1 found\n"); else if (is_id32be(offset+0x0c, sf, "PATl"))
/* 0x04(16): unknown */ offset = 0x0c; /* extra field in PS1 */
ea->sample_rate = (uint16_t)read_16bitLE(offset+0x06, streamFile); else
ea->num_samples = read_32bitLE(offset+0x08, streamFile); goto fail;
VGM_ASSERT(read_32bitLE(offset+0x0c, streamFile) != -1, "EA SCHl fixed: unknown2 found\n"); /* loop start? */
VGM_ASSERT(read_32bitLE(offset+0x10, streamFile) != -1, "EA SCHl fixed: unknown3 found\n"); /* loop end? */ size = read_u32le(offset+0x34, sf);
VGM_ASSERT(read_32bitLE(offset+0x14, streamFile) != 0, "EA SCHl fixed: unknown4 found\n"); /* data start? */ if (size == 0x20 && is_id32be(offset+0x38, sf, "TMpl")) { /* PC LE? */
VGM_ASSERT(read_32bitLE(offset+0x18, streamFile) != -1, "EA SCHl fixed: unknown5 found\n"); offset += 0x3c;
VGM_ASSERT(read_32bitLE(offset+0x1c, streamFile) != 0x7F, "EA SCHl fixed: unknown6 found\n");
ea->version = read_u8 (offset+0x00, sf);
//ea->loop_flag = (ea->loop_end_sample); ea->bps = read_u8 (offset+0x01, sf);
ea->channels = read_u8 (offset+0x02, sf);
return 1; ea->codec = read_u8 (offset+0x03, sf);
/* 0x04: 0? */
fail: ea->sample_rate = read_u16le(offset+0x06, sf);
return 0; ea->num_samples = read_s32le(offset+0x08, sf);
} /* 0x0c: -1? loop_start? */
/* 0x10: -1? loop_end? */
/* 0x14: 0? data start? */
/* 0x18: -1? */
/* 0x1c: volume? (always 128) */
}
else if (size == 0x38 && is_id32be(offset+0x38, sf, "TMxl")) { /* PSX LE? */
offset += 0x3c;
ea->version = read_u8 (offset+0x00, sf);
ea->bps = read_u8 (offset+0x01, sf);
ea->channels = read_u8 (offset+0x02, sf);
ea->codec = read_u8 (offset+0x03, sf);
/* 0x04: 0? */
ea->sample_rate = read_u16le(offset+0x06, sf);
/* 0x08: 0x20C? */
ea->num_samples = read_s32le(offset+0x0c, sf);
/* 0x10: -1? loop_start? */
/* 0x14: -1? loop_end? */
/* 0x18: 0x20C? */
/* 0x1c: 0? */
/* 0x20: 0? */
/* 0x24: 0? */
/* 0x28: -1? */
/* 0x2c: -1? */
/* 0x30: -1? */
/* 0x34: volume? (always 128) */
}
else {
goto fail;
}
//ea->loop_flag = (ea->loop_end_sample);
return 1;
fail:
return 0;
}