2008-07-12 17:20:39 +02:00
|
|
|
#include "meta.h"
|
2017-06-10 02:25:49 +02:00
|
|
|
#include "../coding/coding.h"
|
|
|
|
#include "../layout/layout.h"
|
|
|
|
|
|
|
|
|
2018-08-17 22:47:33 +02:00
|
|
|
static off_t get_rws_string_size(off_t offset, STREAMFILE *streamFile);
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2019-09-21 13:31:11 +02:00
|
|
|
int big_endian;
|
|
|
|
|
|
|
|
uint32_t codec;
|
2018-08-17 22:47:33 +02:00
|
|
|
int channel_count;
|
|
|
|
int sample_rate;
|
2018-08-19 00:40:01 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
off_t file_name_offset;
|
|
|
|
|
2018-08-17 22:47:33 +02:00
|
|
|
int total_segments;
|
2018-08-19 00:40:01 +02:00
|
|
|
int target_segment;
|
|
|
|
off_t segment_offset;
|
2019-09-21 13:31:11 +02:00
|
|
|
size_t segment_layers_size;
|
2018-08-19 00:40:01 +02:00
|
|
|
off_t segment_name_offset;
|
|
|
|
|
2018-08-17 22:47:33 +02:00
|
|
|
int total_layers;
|
2018-08-19 00:40:01 +02:00
|
|
|
int target_layer;
|
2019-09-21 13:31:11 +02:00
|
|
|
off_t layer_start;
|
|
|
|
//size_t layer_size;
|
2018-08-19 00:40:01 +02:00
|
|
|
off_t layer_name_offset;
|
2018-08-17 22:47:33 +02:00
|
|
|
|
|
|
|
size_t file_size;
|
|
|
|
size_t header_size;
|
|
|
|
size_t data_size;
|
2018-08-19 00:40:01 +02:00
|
|
|
off_t data_offset;
|
2018-08-17 22:47:33 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
size_t usable_size;
|
2018-08-17 22:47:33 +02:00
|
|
|
size_t block_size;
|
2019-09-21 13:31:11 +02:00
|
|
|
size_t block_layers_size;
|
2018-08-17 22:47:33 +02:00
|
|
|
|
|
|
|
off_t coefs_offset;
|
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
char readable_name[STREAM_NAME_SIZE];
|
2018-08-17 22:47:33 +02:00
|
|
|
} rws_header;
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2008-07-12 17:20:39 +02:00
|
|
|
|
2017-06-09 22:31:33 +02:00
|
|
|
/* RWS - RenderWare Stream (from games using RenderWare Audio middleware) */
|
2008-07-12 17:20:39 +02:00
|
|
|
VGMSTREAM * init_vgmstream_rws(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2018-08-17 22:47:33 +02:00
|
|
|
off_t start_offset, offset;
|
2018-08-19 00:40:01 +02:00
|
|
|
size_t stream_size;
|
2018-08-17 22:47:33 +02:00
|
|
|
int loop_flag;
|
|
|
|
int i;
|
2018-08-19 00:40:01 +02:00
|
|
|
int total_subsongs, target_subsong = streamFile->stream_index;
|
2018-08-17 22:47:33 +02:00
|
|
|
rws_header rws = {0};
|
2018-08-19 00:40:01 +02:00
|
|
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
|
|
|
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* checks */
|
2017-06-10 02:25:49 +02:00
|
|
|
if (!check_extensions(streamFile,"rws"))
|
|
|
|
goto fail;
|
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* Audio .RWS is made of file + header + data chunks (non-audio .RWS with other chunks exist).
|
|
|
|
* Chunk format (LE): id, size, RW version, data of size (version is repeated but same for all chunks).
|
|
|
|
* Version is 16b main + 16b build (possibly shifted), no known differences between versions,
|
|
|
|
* and can vary between files of a game. ex: 0c02, 1003, 1400 = 3.5, 1803 = 3.6, 1C02 = 3.7. */
|
2018-08-17 22:47:33 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* parse audio chunks */
|
|
|
|
if (read_32bitLE(0x00,streamFile) != 0x0000080d) /* audio file id */
|
2017-06-10 02:25:49 +02:00
|
|
|
goto fail;
|
2019-09-21 13:31:11 +02:00
|
|
|
rws.file_size = read_32bitLE(0x04, streamFile); /* audio file size */
|
2018-08-17 22:47:33 +02:00
|
|
|
if (rws.file_size + 0x0c != get_streamfile_size(streamFile))
|
|
|
|
goto fail;
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
if (read_32bitLE(0x0c,streamFile) != 0x0000080e) /* header id */
|
2017-06-10 02:25:49 +02:00
|
|
|
goto fail;
|
2019-09-21 13:31:11 +02:00
|
|
|
rws.header_size = read_32bitLE(0x10, streamFile); /* header size */
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2018-08-17 22:47:33 +02:00
|
|
|
rws.data_offset = 0x0c + 0x0c + rws.header_size; /* usually 0x800 but not always */
|
2019-09-21 13:31:11 +02:00
|
|
|
if (read_32bitLE(rws.data_offset + 0x00, streamFile) != 0x0000080f) /* data chunk id */
|
2017-06-10 02:25:49 +02:00
|
|
|
goto fail;
|
2019-09-21 13:31:11 +02:00
|
|
|
rws.data_size = read_32bitLE(rws.data_offset + 0x04, streamFile); /* data chunk size */
|
2018-08-17 22:47:33 +02:00
|
|
|
if (rws.data_size+0x0c + rws.data_offset != get_streamfile_size(streamFile))
|
2017-06-10 02:25:49 +02:00
|
|
|
goto fail;
|
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* inside header chunk (many unknown fields are probably IDs/config/garbage,
|
|
|
|
* as two files of the same size vary a lot) */
|
2018-08-17 22:47:33 +02:00
|
|
|
offset = 0x0c + 0x0c;
|
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
rws.big_endian = guess_endianness32bit(offset + 0x00, streamFile); /* GC/Wii/X360 */
|
|
|
|
read_32bit = rws.big_endian ? read_32bitBE : read_32bitLE;
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* base header */
|
2019-09-21 13:31:11 +02:00
|
|
|
{
|
|
|
|
/* 0x00: actual header size (less than chunk size) */
|
|
|
|
/* 0x04/08/10: sizes of various sections? */
|
|
|
|
/* 0x14/18: config? */
|
|
|
|
/* 0x1c: null? */
|
|
|
|
rws.total_segments = read_32bit(offset + 0x20, streamFile);
|
|
|
|
/* 0x24: config? */
|
|
|
|
rws.total_layers = read_32bit(offset + 0x28, streamFile);
|
|
|
|
/* 0x2c: config? */
|
|
|
|
/* 0x30: 0x800? */
|
|
|
|
/* 0x34: block_layers_size? */
|
|
|
|
/* 0x38: data offset */
|
|
|
|
/* 0x3c: 0? */
|
|
|
|
/* 0x40-50: file uuid */
|
|
|
|
offset += 0x50;
|
2018-08-19 00:40:01 +02:00
|
|
|
}
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* audio file name */
|
2019-09-21 13:31:11 +02:00
|
|
|
{
|
|
|
|
rws.file_name_offset = offset;
|
|
|
|
offset += get_rws_string_size(offset, streamFile);
|
|
|
|
}
|
2017-08-26 02:35:14 +02:00
|
|
|
|
2018-08-17 22:47:33 +02:00
|
|
|
/* RWS data can be divided in two ways:
|
2019-09-21 13:31:11 +02:00
|
|
|
* - "substreams" (layers): interleaved blocks, for fake multichannel L/R+C/S+LS/RS [Burnout 2 (GC/Xbox)]
|
|
|
|
* or song variations [Neighbours From Hell (Xbox/GC)]. Last layer may have padding to keep chunks aligned:
|
|
|
|
* ex.- 0x1700 data of substream_0 2ch, 0x1700 data + 0x200 pad of substream1 2ch, repeat until end
|
2018-08-17 22:47:33 +02:00
|
|
|
* - "segments": cues/divisions within data, like intro+main/loop [[Max Payne 2 (PS2), Nana (PS2)]
|
|
|
|
* or voice1+2+..N, song1+2+..N [Madagascar (PS2), The Legend of Spyro: Dawn of the Dragon (X360)]
|
|
|
|
*
|
2019-09-21 13:31:11 +02:00
|
|
|
* As each layer is given sample rate/channel/codec/etc they are treated as full subsongs, though usually
|
|
|
|
* all layers are the same. Segments are just divisions and can be played one after another, but are useful
|
|
|
|
* to play as subsongs. Since both can exist at the same time (rarely) we make layers*segments=subsongs.
|
|
|
|
* Ex.- subsong1=layer1 blocks in segment1, subsong2=layer2 blocks in segment1, subsong3=layer1 blocks in segment2, ...
|
|
|
|
*
|
|
|
|
* Segment1 Segment2
|
|
|
|
* +-------------------------------------------+-----------------
|
|
|
|
* |Layer1|Layer2|(pad)|...|Layer1|Layer2|(pad)|Layer1|Layer2|...
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
*/
|
2017-08-26 02:35:14 +02:00
|
|
|
|
2018-01-28 00:41:25 +01:00
|
|
|
if (target_subsong == 0) target_subsong = 1;
|
2018-08-19 00:40:01 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
rws.target_layer = ((target_subsong-1) % rws.total_layers) + 1;
|
|
|
|
rws.target_segment = ((target_subsong-1) / rws.total_layers) + 1;
|
|
|
|
total_subsongs = rws.total_layers * rws.total_segments;
|
2018-08-19 00:40:01 +02:00
|
|
|
|
2018-01-28 00:41:25 +01:00
|
|
|
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2018-08-17 22:47:33 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* segment info */
|
2018-08-17 22:47:33 +02:00
|
|
|
for (i = 0; i < rws.total_segments; i++) {
|
2018-08-19 00:40:01 +02:00
|
|
|
if (i+1 == rws.target_segment) {
|
2019-09-21 13:31:11 +02:00
|
|
|
/* 0x00/04/0c: config? */
|
|
|
|
/* others: ? */
|
|
|
|
rws.segment_layers_size = read_32bit(offset + 0x18, streamFile); /* sum of all including padding */
|
|
|
|
rws.segment_offset = read_32bit(offset + 0x1c, streamFile);
|
2018-08-19 00:40:01 +02:00
|
|
|
}
|
2019-09-21 13:31:11 +02:00
|
|
|
offset += 0x20;
|
2017-08-26 02:35:14 +02:00
|
|
|
}
|
2018-08-17 22:47:33 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* usable layer sizes per segment */
|
|
|
|
for (i = 0; i < (rws.total_segments * rws.total_layers); i++) {
|
|
|
|
size_t usable_size = read_32bit(offset, streamFile); /* without padding */
|
|
|
|
/* size order: segment1 layer1 size, ..., segment1 layerN size, segment2 layer1 size, etc */
|
|
|
|
if (i+1 == target_subsong) { /* order matches our subsong order */
|
|
|
|
rws.usable_size = usable_size;
|
2018-08-19 00:40:01 +02:00
|
|
|
}
|
2019-09-21 13:31:11 +02:00
|
|
|
offset += 0x04;
|
2017-06-10 02:25:49 +02:00
|
|
|
}
|
2017-08-26 02:35:14 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* segment uuids */
|
2019-09-21 13:31:11 +02:00
|
|
|
{
|
|
|
|
offset += 0x10 * rws.total_segments;
|
|
|
|
}
|
2017-08-26 02:35:14 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* segment names */
|
2018-08-17 22:47:33 +02:00
|
|
|
for (i = 0; i < rws.total_segments; i++) {
|
2018-08-19 00:40:01 +02:00
|
|
|
if (i+1 == rws.target_segment) {
|
|
|
|
rws.segment_name_offset = offset;
|
|
|
|
}
|
2018-08-17 22:47:33 +02:00
|
|
|
offset += get_rws_string_size(offset, streamFile);
|
2017-06-10 02:25:49 +02:00
|
|
|
}
|
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* layer info */
|
2018-08-17 22:47:33 +02:00
|
|
|
for (i = 0; i < rws.total_layers; i++) { /* get block_sizes */
|
2018-08-19 00:40:01 +02:00
|
|
|
if (i+1 == rws.target_layer) {
|
2019-09-21 13:31:11 +02:00
|
|
|
/* 0x00/04: config? */
|
|
|
|
/* 0x08: null? */
|
|
|
|
/* 0x0c: related to samples per frame? (XBOX-IMA=07, PSX=1C, DSP=0E, PCM=01) */
|
|
|
|
//block_size_pad = read_32bit(offset + 0x10, streamFile); /* with padding, can be different per layer */
|
|
|
|
/* 0x14/18: ? */
|
|
|
|
/* 0x1c: codec related? */
|
|
|
|
rws.block_size = read_32bit(offset + 0x20, streamFile); /* without padding */
|
|
|
|
rws.layer_start = read_32bit(offset + 0x24, streamFile); /* skip data */
|
2017-06-10 02:25:49 +02:00
|
|
|
}
|
2019-09-21 13:31:11 +02:00
|
|
|
rws.block_layers_size += read_32bit(offset + 0x10, streamFile); /* needed to skip during decode */
|
|
|
|
offset += 0x28;
|
2017-06-10 02:25:49 +02:00
|
|
|
}
|
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* layer config */
|
2019-09-21 13:31:11 +02:00
|
|
|
for (i = 0; i < rws.total_layers; i++) {
|
|
|
|
uint32_t layer_codec = 0;
|
2018-08-19 00:40:01 +02:00
|
|
|
if (i+1 == rws.target_layer) {
|
2019-09-21 13:31:11 +02:00
|
|
|
rws.sample_rate = read_32bit(offset + 0x00, streamFile);
|
|
|
|
/* 0x04: config? */
|
|
|
|
//rws.layer_size = read_32bit(offset + 0x08, streamFile); /* same or close to usable size */
|
|
|
|
/* 0x0c: bits per sample */
|
|
|
|
rws.channel_count = read_8bit(offset + 0x0d, streamFile);
|
|
|
|
/* others: ? */
|
|
|
|
rws.codec = (uint32_t)read_32bit(offset + 0x1c, streamFile); /* 128b uuid (32b-16b-16b-8b*8) but first 32b is enough */
|
2017-08-12 11:46:28 +02:00
|
|
|
}
|
2019-09-21 13:31:11 +02:00
|
|
|
layer_codec = (uint32_t)read_32bit(offset + 0x1c, streamFile);
|
2018-08-17 22:47:33 +02:00
|
|
|
offset += 0x2c;
|
2017-06-24 22:54:58 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* DSP has an extra field per layer */
|
|
|
|
if (layer_codec == 0xF86215B0) {
|
|
|
|
/* 0x00: approx num samples? */
|
|
|
|
/* 0x04: approx size/loop related? (can be 0) */
|
2018-08-19 00:40:01 +02:00
|
|
|
if (i+1 == rws.target_layer) {
|
2018-08-17 22:47:33 +02:00
|
|
|
rws.coefs_offset = offset + 0x1c;
|
2017-08-12 11:46:28 +02:00
|
|
|
}
|
2018-08-17 22:47:33 +02:00
|
|
|
offset += 0x60;
|
2017-06-24 22:54:58 +02:00
|
|
|
}
|
2018-08-17 22:47:33 +02:00
|
|
|
offset += 0x04; /* padding/garbage */
|
2017-08-12 11:46:28 +02:00
|
|
|
}
|
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* layer uuids */
|
2019-09-21 13:31:11 +02:00
|
|
|
{
|
|
|
|
offset += 0x10 * rws.total_layers;
|
|
|
|
}
|
2017-06-24 22:54:58 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
/* layer names */
|
2018-08-17 22:47:33 +02:00
|
|
|
for (i = 0; i < rws.total_layers; i++) {
|
2018-08-19 00:40:01 +02:00
|
|
|
if (i+1 == rws.target_layer) {
|
|
|
|
rws.layer_name_offset = offset;
|
2017-08-12 11:46:28 +02:00
|
|
|
}
|
2018-08-17 22:47:33 +02:00
|
|
|
offset += get_rws_string_size(offset, streamFile);
|
2017-06-10 02:25:49 +02:00
|
|
|
}
|
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* rest is padding/garbage until chunk end (may contain strings and uninitialized memory) */
|
2017-08-26 02:35:14 +02:00
|
|
|
// ...
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
start_offset = rws.data_offset + 0x0c + (rws.segment_offset + rws.layer_start);
|
|
|
|
stream_size = rws.usable_size;
|
2017-08-26 02:35:14 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* sometimes segment/layers go over file size in XBOX-IMA for no apparent reason, with usable_size bigger
|
|
|
|
* than segment_layers_size yet data_size being correct (bug in RWS header? maybe stops decoding on file end) */
|
|
|
|
{
|
|
|
|
size_t expected_size = (rws.segment_layers_size / rws.block_layers_size) * (rws.block_size * rws.total_layers) / rws.total_layers;
|
|
|
|
if (stream_size > expected_size) {
|
|
|
|
VGM_LOG("RWS: readjusting wrong stream size %x vs expected %x\n", stream_size, expected_size);
|
|
|
|
stream_size = expected_size;
|
|
|
|
}
|
2018-08-19 00:40:01 +02:00
|
|
|
}
|
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* build readable name */
|
|
|
|
{
|
|
|
|
char base_name[STREAM_NAME_SIZE], file_name[STREAM_NAME_SIZE], segment_name[STREAM_NAME_SIZE], layer_name[STREAM_NAME_SIZE];
|
|
|
|
|
|
|
|
get_streamfile_basename(streamFile, base_name, sizeof(base_name));
|
|
|
|
/* null terminated */
|
|
|
|
read_string(file_name,STREAM_NAME_SIZE, rws.file_name_offset, streamFile);
|
|
|
|
read_string(segment_name,STREAM_NAME_SIZE, rws.segment_name_offset, streamFile);
|
|
|
|
read_string(layer_name,STREAM_NAME_SIZE, rws.layer_name_offset, streamFile);
|
|
|
|
|
|
|
|
/* some internal names aren't very interesting and are stuff like "SubStream" */
|
|
|
|
if (strcmp(base_name, file_name) == 0) {
|
|
|
|
if (rws.total_layers > 1)
|
|
|
|
snprintf(rws.readable_name,STREAM_NAME_SIZE, "%s/%s", segment_name, layer_name);
|
|
|
|
else
|
|
|
|
snprintf(rws.readable_name,STREAM_NAME_SIZE, "%s", segment_name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (rws.total_layers > 1)
|
|
|
|
snprintf(rws.readable_name,STREAM_NAME_SIZE, "%s/%s/%s", file_name, segment_name, layer_name);
|
|
|
|
else
|
|
|
|
snprintf(rws.readable_name,STREAM_NAME_SIZE, "%s/%s", file_name, segment_name);
|
2018-08-19 00:40:01 +02:00
|
|
|
}
|
2017-08-26 02:35:14 +02:00
|
|
|
}
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* seemingly no actual looping supported (devs may fake it with segments) */
|
|
|
|
loop_flag = 0;
|
2018-08-17 22:47:33 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
|
2017-06-10 02:25:49 +02:00
|
|
|
/* build the VGMSTREAM */
|
2018-08-17 22:47:33 +02:00
|
|
|
vgmstream = allocate_vgmstream(rws.channel_count,loop_flag);
|
2008-07-12 17:20:39 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2018-08-26 13:47:48 +02:00
|
|
|
vgmstream->meta_type = meta_RWS;
|
2018-08-17 22:47:33 +02:00
|
|
|
vgmstream->sample_rate = rws.sample_rate;
|
2018-01-28 00:41:25 +01:00
|
|
|
vgmstream->num_streams = total_subsongs;
|
2018-08-19 00:40:01 +02:00
|
|
|
vgmstream->stream_size = stream_size;
|
2019-09-21 13:31:11 +02:00
|
|
|
strcpy(vgmstream->stream_name, rws.readable_name);
|
2008-11-12 21:30:14 +01:00
|
|
|
|
2018-02-25 16:52:57 +01:00
|
|
|
vgmstream->layout_type = layout_blocked_rws;
|
2018-08-17 22:47:33 +02:00
|
|
|
vgmstream->current_block_size = rws.block_size / vgmstream->channels;
|
2019-09-21 13:31:11 +02:00
|
|
|
vgmstream->full_block_size = rws.block_layers_size;
|
2008-11-12 21:30:14 +01:00
|
|
|
|
2018-08-17 22:47:33 +02:00
|
|
|
switch(rws.codec) {
|
2019-09-21 13:31:11 +02:00
|
|
|
case 0xD01BD217: /* {D01BD217,3587,4EED,B9,D9,B8,E8,6E,A9,B9,95} PCM PC/X360 */
|
|
|
|
/* ex. D.i.R.T.: Origin of the Species (PC), The Legend of Spyro (X360) */
|
2017-08-27 22:18:08 +02:00
|
|
|
vgmstream->coding_type = coding_PCM16_int;
|
2019-09-21 13:31:11 +02:00
|
|
|
vgmstream->codec_endian = (rws.big_endian);
|
|
|
|
vgmstream->interleave_block_size = 0x02; /* only to setup channels */
|
2008-11-12 21:30:14 +01:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
vgmstream->num_samples = pcm_bytes_to_samples(stream_size, rws.channel_count, 16);
|
2017-06-10 02:25:49 +02:00
|
|
|
break;
|
2008-07-12 17:20:39 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
case 0xD9EA9798: /* {D9EA9798,BBBC,447B,96,B2,65,47,59,10,2E,16} PS-ADPCM PS2 */
|
2017-06-10 02:25:49 +02:00
|
|
|
/* ex. Silent Hill Origins (PS2), Ghost Rider (PS2), Max Payne 2 (PS2), Nana (PS2) */
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
2018-08-17 22:47:33 +02:00
|
|
|
vgmstream->interleave_block_size = rws.block_size / 2;
|
2008-07-12 17:20:39 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
vgmstream->num_samples = ps_bytes_to_samples(stream_size, rws.channel_count);
|
2017-06-10 02:25:49 +02:00
|
|
|
break;
|
2008-07-12 17:20:39 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
case 0xF86215B0: /* {F86215B0,31D5,4C29,BD,37,CD,BF,9B,D1,0C,53} DSP GC/Wii */
|
2017-06-24 22:54:58 +02:00
|
|
|
/* ex. Burnout 2 (GC), Alice in Wonderland (Wii) */
|
2017-06-10 02:25:49 +02:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
2018-08-17 22:47:33 +02:00
|
|
|
vgmstream->interleave_block_size = rws.block_size / 2;
|
2008-07-12 17:20:39 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* get coefs (all channels share them; also seem fixed for all RWS) */
|
|
|
|
dsp_read_coefs_be(vgmstream, streamFile, rws.coefs_offset, 0);
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
vgmstream->num_samples = dsp_bytes_to_samples(stream_size, rws.channel_count);
|
2017-06-10 02:25:49 +02:00
|
|
|
break;
|
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
case 0xEF386593: /* {EF386593,B611,432D,95,7F,A7,1A,DE,44,22,7A} XBOX-IMA PC */
|
|
|
|
case 0x632FA22B: /* {632FA22B,11DD,458F,AA,27,A5,C3,46,E9,79,0E} XBOX-IMA Xbox */
|
2017-06-10 02:25:49 +02:00
|
|
|
/* ex. Broken Sword 3 (PC), Jacked (PC/Xbox), Burnout 2 (Xbox) */
|
2019-09-21 13:31:11 +02:00
|
|
|
vgmstream->coding_type = coding_XBOX_IMA; /* same data though different uuid */
|
2018-02-17 12:30:14 +01:00
|
|
|
vgmstream->interleave_block_size = 0;
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2018-08-19 00:40:01 +02:00
|
|
|
vgmstream->num_samples = xbox_ima_bytes_to_samples(stream_size, rws.channel_count);
|
2017-06-10 02:25:49 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-08-17 22:47:33 +02:00
|
|
|
VGM_LOG("RWS: unknown codec 0x%08x\n", rws.codec);
|
2017-06-10 02:25:49 +02:00
|
|
|
goto fail;
|
2008-07-12 17:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-06-10 02:25:49 +02:00
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
|
2017-06-10 02:25:49 +02:00
|
|
|
goto fail;
|
2008-07-12 17:20:39 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-06-10 02:25:49 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2008-07-12 17:20:39 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-06-10 02:25:49 +02:00
|
|
|
|
|
|
|
|
2019-09-21 13:31:11 +02:00
|
|
|
/* rws-strings are null-terminated then padded to 0x10 (weirdly enough the padding contains garbage) */
|
2018-08-17 22:47:33 +02:00
|
|
|
static off_t get_rws_string_size(off_t offset, STREAMFILE *streamFile) {
|
2017-06-10 02:25:49 +02:00
|
|
|
int i;
|
2019-09-21 13:31:11 +02:00
|
|
|
for (i = 0; i < 255; i++) { /* arbitrary max */
|
|
|
|
if (read_8bit(offset+i, streamFile) == 0) { /* null terminator */
|
2017-06-10 02:25:49 +02:00
|
|
|
return i + (0x10 - (i % 0x10)); /* size is padded */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|