From 56b7e8580d235f6e5be772261db95f5d381dfd7a Mon Sep 17 00:00:00 2001 From: bnnm Date: Fri, 5 Jan 2024 19:25:05 +0100 Subject: [PATCH] cleanup: asd --- src/formats.c | 2 +- src/meta/dc_asd.c | 111 +++++++++++++++++------------------------- src/meta/meta.h | 2 +- src/vgmstream.c | 2 +- src/vgmstream_types.h | 6 +-- 5 files changed, 50 insertions(+), 73 deletions(-) diff --git a/src/formats.c b/src/formats.c index d91cae22..52f0992f 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1102,7 +1102,7 @@ static const meta_info meta_info_list[] = { {meta_MUS_KROME, "Krome .MUS header"}, {meta_WII_SNG, "SNG DSP Header"}, {meta_RSD, "Radical RSD header"}, - {meta_DC_ASD, "ASD Header"}, + {meta_ASD_NAXAT, "Naxat .ASD header"}, {meta_SPSD, "Sega Naomi SPSD header"}, {meta_FFXI_BGW, "Square Enix .BGW header"}, {meta_FFXI_SPW, "Square Enix .SPW header"}, diff --git a/src/meta/dc_asd.c b/src/meta/dc_asd.c index 53114ca1..13c39487 100644 --- a/src/meta/dc_asd.c +++ b/src/meta/dc_asd.c @@ -1,84 +1,61 @@ #include "meta.h" -#include "../util.h" +#include "../coding/coding.h" -/* ASD - found in Miss Moonlight (DC) */ -VGMSTREAM * init_vgmstream_dc_asd(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - int loop_flag; - int channel_count; - int sample_rate; +/* ASD - found Naxat (Spiel/Mesa) games [Miss Moonlight (DC), Yoshia no Oka de Nekoronde... (DC)] */ +VGMSTREAM* init_vgmstream_asd_naxat(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + uint32_t start_offset; + int loop_flag, channels, sample_rate; - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("asd",filename_extension(filename))) goto fail; - /* We have no "Magic" words in this header format, so we have to do some, - other checks, it seems the samplecount is stored twice in the header, - we'll compare it... */ - if (read_32bitLE(0x0,streamFile) != read_32bitLE(0x4,streamFile)) - goto fail; + /* checks */ + uint32_t data_size = read_u32le(0x00, sf); /* padded and slightly less than file size */ + if (data_size == 0 || data_size >= get_streamfile_size(sf) || data_size + 0x20 + 0x10 < get_streamfile_size(sf)) + return NULL; + if (data_size != read_u32le(0x04,sf)) /* repeated size */ + return NULL; + /* extension of the audio bigfiles (there are N offsets to these subfiles) */ + if (!check_extensions(sf, "asd")) + return NULL; - /* ableton related files can be incorrectly sent to this which don't have - the same style of header and unless we null check we get a divide by zero - crash... */ - sample_rate = read_32bitLE(0xC,streamFile); - if (!sample_rate) - goto fail; - - /* compare the frequency with the bitrate, if it doesn't match we'll close - the vgmstream... */ - if (read_32bitLE(0x10,streamFile)/sample_rate != (uint16_t)read_16bitLE(0xA,streamFile)*2) - goto fail; + /* fmt chunk, extra checks since format is simple */ + if (read_u16le(0x08,sf) != 0x01) /* format*/ + return NULL; + channels = read_u16le(0x0a,sf); + sample_rate = read_s32le(0x0c,sf); + if (channels < 1 || channels > 2) + return NULL; + if (sample_rate != 22050) + return NULL; + if (sample_rate * channels * sizeof(int16_t) != read_u32le(0x10,sf)) /* bitrate */ + return NULL; + /* 04: block size, bps */ + if (read_u32le(0x18,sf) != 0x00 ) + return NULL; + if (read_u32le(0x1c,sf) != 0x00 ) + return NULL; + + start_offset = 0x20; loop_flag = 0; - channel_count = read_16bitLE(0x0A,streamFile); - + + /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; - /* fill in the vital statistics */ - start_offset = get_streamfile_size(streamFile) - read_32bitLE(0x0,streamFile); - vgmstream->channels = channel_count; + vgmstream->meta_type = meta_ASD_NAXAT; vgmstream->sample_rate = sample_rate; + vgmstream->num_samples = pcm16_bytes_to_samples(data_size, channels); + vgmstream->coding_type = coding_PCM16LE; - vgmstream->num_samples = read_32bitLE(0x0,streamFile)/2/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = 0; - vgmstream->loop_end_sample = read_32bitLE(0x0,streamFile)/2/channel_count; - } - - vgmstream->meta_type = meta_DC_ASD; - - if (vgmstream->channels == 1) { - vgmstream->layout_type = layout_none; - } else if (vgmstream->channels == 2) { - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x2; - } - - /* 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;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x02; + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) + goto fail; return vgmstream; - - /* clean up anything we may have opened */ fail: - if (vgmstream) close_vgmstream(vgmstream); + close_vgmstream(vgmstream); return NULL; } diff --git a/src/meta/meta.h b/src/meta/meta.h index 3bfc1784..de6b08bb 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -300,7 +300,7 @@ VGMSTREAM* init_vgmstream_mus_krome(STREAMFILE* sf); VGMSTREAM * init_vgmstream_rsd(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_dc_asd(STREAMFILE * streamFile); +VGMSTREAM* init_vgmstream_asd_naxat(STREAMFILE* sf); VGMSTREAM* init_vgmstream_spsd(STREAMFILE* sf); diff --git a/src/vgmstream.c b/src/vgmstream.c index 95a03209..3d479d0e 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -127,7 +127,6 @@ init_vgmstream_t init_vgmstream_functions[] = { init_vgmstream_ngc_pdt_split, init_vgmstream_ngc_pdt, init_vgmstream_mus_krome, - init_vgmstream_dc_asd, init_vgmstream_spsd, init_vgmstream_rsd, init_vgmstream_bgw, @@ -536,6 +535,7 @@ init_vgmstream_t init_vgmstream_functions[] = { init_vgmstream_seb, init_vgmstream_tgc, init_vgmstream_ivaud, + init_vgmstream_asd_naxat, /* need companion files */ init_vgmstream_pos, init_vgmstream_sli_loops, diff --git a/src/vgmstream_types.h b/src/vgmstream_types.h index 648687a2..754c9ac4 100644 --- a/src/vgmstream_types.h +++ b/src/vgmstream_types.h @@ -370,11 +370,11 @@ typedef enum { meta_FAG, /* Jackie Chan - Stuntmaster */ meta_PS2_MIHB, /* Merged MIH+MIB */ meta_NGC_PDT, /* Mario Party 6 */ - meta_DC_ASD, /* Miss Moonligh */ + meta_ASD_NAXAT, meta_SPSD, meta_RSD, - meta_PS2_ASS, /* ASS */ - meta_SEG, /* Eragon */ + meta_PS2_ASS, + meta_SEG, meta_NDS_STRM_FFTA2, /* Final Fantasy Tactics A2 */ meta_KNON, meta_ZWDSP, /* Zack and Wiki */