mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-23 22:41:05 +01:00
cleanup: wpd, ws_aud
This commit is contained in:
parent
637273bcd9
commit
21b3067a7c
@ -1,59 +1,33 @@
|
||||
#include "meta.h"
|
||||
#include "../util.h"
|
||||
|
||||
/* WPD (from Shuffle! (PC)) */
|
||||
VGMSTREAM * init_vgmstream_wpd(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
char filename[PATH_LIMIT];
|
||||
off_t start_offset;
|
||||
int channel_count;
|
||||
int loop_flag;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
||||
if (strcasecmp("wpd",filename_extension(filename))) goto fail;
|
||||
|
||||
/* check header */
|
||||
if (read_32bitBE(0x00,streamFile) != 0x20445057) /* " DPW" */
|
||||
goto fail;
|
||||
|
||||
channel_count = read_32bitLE(0x4,streamFile);
|
||||
loop_flag = 0;
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
/* fill in the vital statistics */
|
||||
start_offset = 0x30;
|
||||
vgmstream->channels = channel_count;
|
||||
vgmstream->sample_rate = read_32bitLE(0x10,streamFile);
|
||||
vgmstream->coding_type = coding_PCM16LE;
|
||||
vgmstream->num_samples = (read_32bitLE(0x14,streamFile))/2/channel_count;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = 2;
|
||||
vgmstream->meta_type = meta_WPD;
|
||||
|
||||
/* open the file for reading */
|
||||
{
|
||||
int i;
|
||||
STREAMFILE * file;
|
||||
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
if (!file) goto fail;
|
||||
for (i=0;i<channel_count;i++) {
|
||||
vgmstream->ch[i].streamfile = file;
|
||||
|
||||
vgmstream->ch[i].channel_start_offset=
|
||||
vgmstream->ch[i].offset=start_offset+
|
||||
vgmstream->interleave_block_size*i;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return vgmstream;
|
||||
|
||||
/* clean up anything we may have opened */
|
||||
fail:
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
#include "meta.h"
|
||||
#include "../util/meta_utils.h"
|
||||
|
||||
/* WPD - from Shuffle! (PC) */
|
||||
VGMSTREAM* init_vgmstream_wpd(STREAMFILE* sf) {
|
||||
|
||||
/* checks */
|
||||
if (!is_id32be(0x00,sf, " DPW"))
|
||||
return NULL;
|
||||
if (!check_extensions(sf, "wpd"))
|
||||
return NULL;
|
||||
|
||||
meta_header_t h = {0};
|
||||
h.meta = meta_WPD;
|
||||
h.channels = read_u32le(0x04,sf); /* always 2? */
|
||||
// 08: always 2?
|
||||
// 0c: bits per sample (16)
|
||||
h.sample_rate = read_s32le(0x10,sf); /* big endian? */
|
||||
h.data_size = read_u32le(0x14,sf);
|
||||
// 18: PCM fmt (codec 0001, channels, srate, bitrate...)
|
||||
|
||||
h.stream_offset = 0x30;
|
||||
h.num_samples = pcm16_bytes_to_samples(h.data_size, h.channels);
|
||||
|
||||
h.coding = coding_PCM16LE;
|
||||
h.layout = layout_interleave;
|
||||
h.interleave = 0x02;
|
||||
|
||||
h.sf = sf;
|
||||
h.open_stream = true;
|
||||
|
||||
return alloc_metastream(&h);
|
||||
}
|
||||
|
@ -2,15 +2,11 @@
|
||||
#include "../layout/layout.h"
|
||||
#include "../util.h"
|
||||
|
||||
/* Westwood Studios .aud (WS-AUD) */
|
||||
|
||||
/* .AUD - from Westwood Studios games [Command & Conquer (PC), ] */
|
||||
VGMSTREAM* init_vgmstream_ws_aud(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
coding_t coding_type = -1;
|
||||
off_t format_offset;
|
||||
int channels;
|
||||
bool new_type = false;
|
||||
int bytes_per_sample = 0;
|
||||
|
||||
|
||||
/* checks **/
|
||||
@ -31,82 +27,69 @@ VGMSTREAM* init_vgmstream_ws_aud(STREAMFILE* sf) {
|
||||
}
|
||||
|
||||
/* blocked format with a mini-header */
|
||||
int sample_rate = read_u16le(0x00,sf);
|
||||
uint8_t channel_flags = read_u8(format_offset + 0x00, sf);
|
||||
uint8_t format_flags = read_u8(format_offset + 0x01, sf);
|
||||
|
||||
if (read_u8(format_offset + 0x00, sf) & 1)
|
||||
channels = 2;
|
||||
else
|
||||
channels = 1;
|
||||
|
||||
int channels = channel_flags & 1 ? 2 : 1;
|
||||
if (channels == 2)
|
||||
goto fail; /* not seen */
|
||||
return NULL; /* not seen */
|
||||
int bytes_per_sample = (channel_flags & 2) ? 2 : 1;
|
||||
|
||||
if (read_u8(format_offset + 0x01,sf) & 2)
|
||||
bytes_per_sample = 2;
|
||||
else
|
||||
bytes_per_sample = 1;
|
||||
|
||||
/* check codec type */
|
||||
switch (read_u8(format_offset + 0x01,sf)) {
|
||||
case 1: /* Westwood custom */
|
||||
coding_type = coding_WS;
|
||||
if (bytes_per_sample != 1) goto fail; /* shouldn't happen? */
|
||||
break;
|
||||
case 99: /* IMA ADPCM */
|
||||
coding_type = coding_IMA_int;
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
uint32_t data_size;
|
||||
if (new_type) {
|
||||
data_size = read_u32le(0x06,sf);
|
||||
}
|
||||
else {
|
||||
/* to read through the file looking at chunk headers */
|
||||
off_t offset = 0x08;
|
||||
off_t file_size = get_streamfile_size(sf);
|
||||
|
||||
data_size = 0;
|
||||
while (offset < file_size) {
|
||||
uint16_t chunk_size = read_u16le(offset + 0x00,sf);
|
||||
data_size += read_u16le(offset + 0x02,sf);
|
||||
/* while we're here might as well check for valid chunks */
|
||||
if (read_u32le(offset + 0x04, sf) != 0x0000DEAF)
|
||||
goto fail;
|
||||
offset += 0x08 + chunk_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channels, 0);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
if (new_type) {
|
||||
vgmstream->num_samples = read_32bitLE(0x06,sf)/bytes_per_sample/channels;
|
||||
}
|
||||
else {
|
||||
/* Doh, no output size in old type files. We have to read through the
|
||||
* file looking at chunk headers! Crap! */
|
||||
int32_t out_size = 0;
|
||||
off_t current_offset = 0x8;
|
||||
off_t file_size = get_streamfile_size(sf);
|
||||
|
||||
while (current_offset < file_size) {
|
||||
int16_t chunk_size;
|
||||
chunk_size = read_16bitLE(current_offset,sf);
|
||||
out_size += read_16bitLE(current_offset+2,sf);
|
||||
/* while we're here might as well check for valid chunks */
|
||||
if (read_32bitLE(current_offset+4,sf) != 0x0000DEAF) goto fail;
|
||||
current_offset+=8+chunk_size;
|
||||
}
|
||||
|
||||
vgmstream->num_samples = out_size/bytes_per_sample/channels;
|
||||
}
|
||||
|
||||
vgmstream->meta_type = meta_WS_AUD;
|
||||
vgmstream->sample_rate = sample_rate;
|
||||
vgmstream->num_samples = data_size / bytes_per_sample / channels;
|
||||
/* they tend to not actually have data for the last odd sample */
|
||||
if (vgmstream->num_samples & 1) vgmstream->num_samples--;
|
||||
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x00,sf);
|
||||
if (vgmstream->num_samples & 1)
|
||||
vgmstream->num_samples--;
|
||||
|
||||
vgmstream->coding_type = coding_type;
|
||||
if (new_type) {
|
||||
vgmstream->meta_type = meta_WS_AUD;
|
||||
switch (format_flags) {
|
||||
case 0x01: /* Westwood ADPCM [The Legend of Kyrandia - Book 3 (PC)] */
|
||||
vgmstream->coding_type = coding_WS;
|
||||
if (bytes_per_sample != 1) /* shouldn't happen? */
|
||||
goto fail;
|
||||
break;
|
||||
|
||||
case 0x63: /* IMA ADPCM [Blade Runner (PC)] */
|
||||
vgmstream->coding_type = coding_IMA_int;
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
vgmstream->layout_type = layout_blocked_ws_aud;
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream, sf, 0x00) )
|
||||
goto fail;
|
||||
|
||||
if (new_type) {
|
||||
block_update(0x0c, vgmstream);
|
||||
} else {
|
||||
block_update(0x08, vgmstream);
|
||||
}
|
||||
block_update(new_type ? 0x0c : 0x08, vgmstream);
|
||||
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user