This commit is contained in:
bnnm 2021-10-24 10:28:48 +02:00
parent 3c8dc615ab
commit 656c70e67b
3 changed files with 185 additions and 181 deletions

View File

@ -105,7 +105,10 @@ for /f "delims=" %%x in ('%CMD_DIR% ^| %CMD_FIND%') do (
call :performance_file "!CMD_FILE!" call :performance_file "!CMD_FILE!"
) )
setlocal DisableDelayedExpansion REM this doesn't seem to properly disable it and will error out after N files
REM but using endlocal will remove vars and counters won't work
REM setlocal DisableDelayedExpansion
endlocal
) )
REM # find time elapsed REM # find time elapsed

View File

@ -1,177 +1,179 @@
#include "meta.h" #include "meta.h"
/* .cks - Cricket Audio stream [Part Time UFO (Android), Mega Man 1-6 (Android)] */ /* .cks - Cricket Audio stream [Part Time UFO (Android), Mega Man 1-6 (Android)] */
VGMSTREAM * init_vgmstream_cks(STREAMFILE *streamFile) { VGMSTREAM* init_vgmstream_cks(STREAMFILE* sf) {
VGMSTREAM * vgmstream = NULL; VGMSTREAM* vgmstream = NULL;
off_t start_offset; off_t start_offset;
int loop_flag, channel_count, codec, sample_rate; int loop_flag, channels, codec, sample_rate;
int32_t num_samples, loop_start, loop_end; int32_t num_samples, loop_start, loop_end;
size_t block_size; size_t block_size;
/* checks */ /* checks */
if (!check_extensions(streamFile, "cks")) if (!is_id32be(0x00,sf, "ckmk"))
goto fail; goto fail;
if (read_32bitBE(0x00,streamFile) != 0x636B6D6B) /* "ckmk" */ if (!check_extensions(sf, "cks"))
goto fail; goto fail;
/* 0x04(4): platform bitflags (from LSB: iOS, Android, OS X, Windows, WP8, Linux, tvOS, undefined/ignored) */
if (read_32bitLE(0x08,streamFile) != 0x00) /* expected file type (0x00: stream, 0x01: bank, 0x02+: unknown) */ /* 0x04(4): platform bitflags (from LSB: iOS, Android, OS X, Windows, WP8, Linux, tvOS, undefined/ignored) */
goto fail; if (read_u32le(0x08,sf) != 0x00) /* expected file type (0x00: stream, 0x01: bank, 0x02+: unknown) */
if (read_32bitLE(0x0c,streamFile) != 0x02) /* file version (always 0x02) */ goto fail;
goto fail; if (read_u32le(0x0c,sf) != 0x02) /* file version (always 0x02) */
goto fail;
codec = read_8bit(0x10,streamFile);
channel_count = read_8bit(0x11,streamFile); codec = read_u8(0x10,sf);
sample_rate = (uint16_t)read_16bitLE(0x12,streamFile); channels = read_u8(0x11,sf);
num_samples = read_32bitLE(0x14,streamFile) * read_16bitLE(0x1a,streamFile); /* number_of_blocks * samples_per_frame */ sample_rate = read_u16le(0x12,sf);
block_size = read_16bitLE(0x18,streamFile); num_samples = read_s32le(0x14,sf) * read_u16le(0x1a,sf); /* number_of_blocks * samples_per_frame */
/* 0x1c(2): volume */ block_size = read_u16le(0x18,sf);
/* 0x1e(2): pan */ /* 0x1c(2): volume */
loop_start = read_32bitLE(0x20,streamFile); /* 0x1e(2): pan */
loop_end = read_32bitLE(0x24,streamFile); loop_start = read_s32le(0x20,sf);
loop_flag = read_16bitLE(0x28,streamFile) != 0; /* loop count (-1 = forever) */ loop_end = read_s32le(0x24,sf);
/* 0x2a(2): unused? */ loop_flag = read_s16le(0x28,sf) != 0; /* loop count (-1 = forever) */
/* 0x2a(2): unused? */
start_offset = 0x2c;
start_offset = 0x2c;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag); /* build the VGMSTREAM */
if (!vgmstream) goto fail; vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples; vgmstream->sample_rate = sample_rate;
vgmstream->loop_start_sample = loop_start; vgmstream->num_samples = num_samples;
vgmstream->loop_end_sample = loop_end; vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
vgmstream->meta_type = meta_CKS;
vgmstream->meta_type = meta_CKS;
switch(codec) {
case 0x00: /* pcm16 [from tests] */ switch(codec) {
vgmstream->coding_type = coding_PCM16LE; case 0x00: /* pcm16 [from tests] */
break; vgmstream->coding_type = coding_PCM16LE;
case 0x01: /* pcm8 [from tests] */ break;
vgmstream->coding_type = coding_PCM8; case 0x01: /* pcm8 [from tests] */
break; vgmstream->coding_type = coding_PCM8;
case 0x02: /* adpcm [Part Time UFO (Android), Mega Man 1-6 (Android)] */ break;
vgmstream->coding_type = coding_MSADPCM_ck; case 0x02: /* adpcm [Part Time UFO (Android), Mega Man 1-6 (Android)] */
vgmstream->frame_size = block_size / channel_count; /* always 0x18 */ vgmstream->coding_type = coding_MSADPCM_ck;
break; vgmstream->frame_size = block_size / channels; /* always 0x18 */
default: break;
goto fail; default:
} goto fail;
vgmstream->layout_type = layout_interleave; }
vgmstream->interleave_block_size = block_size / channel_count; vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = block_size / channels;
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail; if (!vgmstream_open_stream(vgmstream, sf, start_offset))
return vgmstream; goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream); fail:
return NULL; close_vgmstream(vgmstream);
} return NULL;
}
/* .ckb - Cricket Audio bank [Fire Emblem Heroes (Android), Mega Man 1-6 (Android)] */
VGMSTREAM * init_vgmstream_ckb(STREAMFILE *streamFile) { /* .ckb - Cricket Audio bank [Fire Emblem Heroes (Android), Mega Man 1-6 (Android)] */
VGMSTREAM * vgmstream = NULL; VGMSTREAM* init_vgmstream_ckb(STREAMFILE* sf) {
off_t start_offset, name_offset = 0; VGMSTREAM* vgmstream = NULL;
int loop_flag, channel_count, codec, sample_rate; off_t start_offset, name_offset = 0;
int32_t num_samples, loop_start, loop_end; int loop_flag = 0, channels = 0, codec = 0, sample_rate = 0;
size_t block_size, stream_size; int32_t num_samples = 0, loop_start = 0, loop_end = 0;
int total_subsongs, target_subsong = streamFile->stream_index; size_t block_size = 0, stream_size = 0;
int total_subsongs, target_subsong = sf->stream_index;
/* checks */
if (!check_extensions(streamFile, "ckb")) /* checks */
goto fail; if (!is_id32be(0x00,sf, "ckmk"))
if (read_32bitBE(0x00,streamFile) != 0x636B6D6B) /* "ckmk" */ goto fail;
goto fail; if (!check_extensions(sf, "ckb"))
/* 0x04(4): platform bitflags (from LSB: iOS, Android, OS X, Windows, WP8, Linux, tvOS, undefined/ignored) */ goto fail;
if (read_32bitLE(0x08,streamFile) != 0x01) /* expected file type (0x00: stream, 0x01: bank, 0x02+: unknown) */
goto fail; /* 0x04(4): platform bitflags (from LSB: iOS, Android, OS X, Windows, WP8, Linux, tvOS, undefined/ignored) */
if (read_32bitLE(0x0c,streamFile) != 0x02) /* file version (always 0x02) */ if (read_u32le(0x08,sf) != 0x01) /* expected file type (0x00: stream, 0x01: bank, 0x02+: unknown) */
goto fail; goto fail;
if (read_u32le(0x0c,sf) != 0x02) /* file version (always 0x02) */
/* 0x10: bank name (size 0x1c+1) */ goto fail;
/* 0x30/34: reserved? */
total_subsongs = read_32bitLE(0x38,streamFile); /* 0x10: bank name (size 0x1c+1) */
if (target_subsong == 0) target_subsong = 1; /* 0x30/34: reserved? */
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail; total_subsongs = read_u32le(0x38,sf);
/* 0x3c: total_subsongs again? (ignored) */ if (target_subsong == 0) target_subsong = 1;
/* 0x40/44: unknown (ignored) */ if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
/* 0x3c: total_subsongs again? (ignored) */
/* get subsong (stream offset isn't given so must calc manually) */ /* 0x40/44: unknown (ignored) */
{
int i; /* get subsong (stream offset isn't given so must calc manually) */
off_t header_offset = 0x48; {
off_t stream_offset = 0x48 + total_subsongs*0x48; int i;
off_t header_offset = 0x48;
for (i = 0; i < total_subsongs; i++) { off_t stream_offset = 0x48 + total_subsongs*0x48;
name_offset = header_offset+0x00; /* stream name (size 0x1c+1) */
codec = read_8bit(header_offset+0x20,streamFile); for (i = 0; i < total_subsongs; i++) {
channel_count = read_8bit(header_offset+0x21,streamFile); name_offset = header_offset+0x00; /* stream name (size 0x1c+1) */
sample_rate = (uint16_t)read_16bitLE(header_offset+0x22,streamFile); codec = read_8bit(header_offset+0x20,sf);
num_samples = read_32bitLE(header_offset+0x24,streamFile) * read_16bitLE(header_offset+0x2a,streamFile); /* number_of_blocks * samples_per_frame */ channels = read_8bit(header_offset+0x21,sf);
block_size = read_16bitLE(header_offset+0x28,streamFile); sample_rate = (uint16_t)read_16bitLE(header_offset+0x22,sf);
/* 0x2c(2): volume */ num_samples = read_32bitLE(header_offset+0x24,sf) * read_16bitLE(header_offset+0x2a,sf); /* number_of_blocks * samples_per_frame */
/* 0x2e(2): pan */ block_size = read_16bitLE(header_offset+0x28,sf);
loop_start = read_32bitLE(header_offset+0x30,streamFile); /* 0x2c(2): volume */
loop_end = read_32bitLE(header_offset+0x34,streamFile); /* 0x2e(2): pan */
loop_flag = read_16bitLE(header_offset+0x38,streamFile) != 0; /* loop count (-1 = forever) */ loop_start = read_32bitLE(header_offset+0x30,sf);
/* 0x3a(2): unused? */ loop_end = read_32bitLE(header_offset+0x34,sf);
stream_size = read_32bitLE(header_offset+0x3c,streamFile); loop_flag = read_16bitLE(header_offset+0x38,sf) != 0; /* loop count (-1 = forever) */
/* 0x40/44(4): unused? */ /* 0x3a(2): unused? */
stream_size = read_32bitLE(header_offset+0x3c,sf);
if (target_subsong == (i+1)) /* 0x40/44(4): unused? */
break;
header_offset += 0x48; if (target_subsong == (i+1))
stream_offset += stream_size; break;
} header_offset += 0x48;
stream_offset += stream_size;
start_offset = stream_offset; }
}
start_offset = stream_offset;
}
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail; /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
vgmstream->sample_rate = sample_rate; if (!vgmstream) goto fail;
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start; vgmstream->sample_rate = sample_rate;
vgmstream->loop_end_sample = loop_end; vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start;
vgmstream->num_streams = total_subsongs; vgmstream->loop_end_sample = loop_end;
vgmstream->stream_size = stream_size;
read_string(vgmstream->stream_name,0x1c+1, name_offset,streamFile); vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = stream_size;
vgmstream->meta_type = meta_CKB; read_string(vgmstream->stream_name,0x1c+1, name_offset,sf);
switch(codec) { vgmstream->meta_type = meta_CKB;
case 0x00: /* pcm16 [Mega Man 1-6 (Android)] */
vgmstream->coding_type = coding_PCM16LE; switch(codec) {
break; case 0x00: /* pcm16 [Mega Man 1-6 (Android)] */
case 0x01: /* pcm8 */ vgmstream->coding_type = coding_PCM16LE;
vgmstream->coding_type = coding_PCM8; break;
break; case 0x01: /* pcm8 */
case 0x02: /* adpcm [Fire Emblem Heroes (Android)] */ vgmstream->coding_type = coding_PCM8;
vgmstream->coding_type = coding_MSADPCM_ck; break;
/* frame_size is always 0x18 */ case 0x02: /* adpcm [Fire Emblem Heroes (Android)] */
break; vgmstream->coding_type = coding_MSADPCM_ck;
default: /* frame_size is always 0x18 */
goto fail; break;
} default:
vgmstream->layout_type = layout_interleave; goto fail;
vgmstream->interleave_block_size = block_size / channel_count; }
vgmstream->layout_type = layout_interleave;
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) vgmstream->interleave_block_size = block_size / channels;
goto fail;
return vgmstream; if (!vgmstream_open_stream(vgmstream,sf,start_offset))
goto fail;
fail: return vgmstream;
close_vgmstream(vgmstream);
return NULL; fail:
} close_vgmstream(vgmstream);
return NULL;
}

View File

@ -119,7 +119,7 @@ static size_t stdio_read(STDIO_STREAMFILE* sf, uint8_t* dst, offv_t offset, size
#ifdef VGM_DEBUG_OUTPUT #ifdef VGM_DEBUG_OUTPUT
if (offset < sf->buf_offset && length > 0) { if (offset < sf->buf_offset && length > 0) {
VGM_LOG("stdio: rebuffer, requested %x vs %x (sf %x)\n", (uint32_t)offset, (uint32_t)sf->buf_offset, (uint32_t)sf); //VGM_LOG("stdio: rebuffer, requested %x vs %x (sf %x)\n", (uint32_t)offset, (uint32_t)sf->buf_offset, (uint32_t)sf);
//sf->rebuffer++; //sf->rebuffer++;
//if (rebuffer > N) ... //if (rebuffer > N) ...
} }
@ -352,7 +352,7 @@ static size_t buffer_read(BUFFER_STREAMFILE* sf, uint8_t* dst, offv_t offset, si
#ifdef VGM_DEBUG_OUTPUT #ifdef VGM_DEBUG_OUTPUT
if (offset < sf->buf_offset) { if (offset < sf->buf_offset) {
VGM_LOG("buffer: rebuffer, requested %x vs %x (sf %x)\n", (uint32_t)offset, (uint32_t)sf->buf_offset, (uint32_t)sf); //VGM_LOG("buffer: rebuffer, requested %x vs %x (sf %x)\n", (uint32_t)offset, (uint32_t)sf->buf_offset, (uint32_t)sf);
} }
#endif #endif
@ -1274,7 +1274,6 @@ STREAMFILE* read_filemap_file_pos(STREAMFILE* sf, int file_num, int* p_pos) {
/* better way? */ /* better way? */
if (strcmp(line, "#@reset-pos") == 0) { if (strcmp(line, "#@reset-pos") == 0) {
file_pos = 0; file_pos = 0;
VGM_LOG("pos =%i\n", file_pos);
} }
continue; continue;
} }