This commit is contained in:
bnnm 2021-06-20 10:33:28 +02:00
parent f75df3f388
commit 38360275a5
3 changed files with 20 additions and 105 deletions

View File

@ -44,7 +44,6 @@ VGMSTREAM * init_vgmstream_cstr(STREAMFILE* sf) {
loop_flag = (loop_start >= 0);
start_offset = 0x20 + 0x60 * channels + first_skip;
#if 1
/* nonlooped tracks may not set first skip for no reason, but can be tested with initial p/s */
if (!loop_flag && channels == 2 && first_skip == 0) {
while (first_skip < 0x800) {
@ -61,7 +60,7 @@ VGMSTREAM * init_vgmstream_cstr(STREAMFILE* sf) {
}
if (first_skip > 0 && loop_start >= (interleave - first_skip))
loop_start = loop_start - (interleave - first_skip);
#endif
loop_start = loop_start * 2;
/* Mr. Driller oddity, unreliable loop flag */
@ -97,7 +96,7 @@ VGMSTREAM * init_vgmstream_cstr(STREAMFILE* sf) {
vgmstream->interleave_first_block_size = interleave - first_skip;
vgmstream->interleave_first_skip = first_skip;
vgmstream->meta_type = meta_DSP_CSTR;
VGM_LOG("1=%x, =%x\n",vgmstream->interleave_first_block_size, vgmstream->interleave_first_skip);
dsp_read_coefs_be(vgmstream, sf, 0x3c, 0x60);
if (!vgmstream_open_stream(vgmstream, sf, start_offset))

View File

@ -599,75 +599,32 @@ fail:
}
static size_t silence_io_read(STREAMFILE* streamfile, uint8_t *dest, off_t offset, size_t length, void* data) {
int i;
for (i = 0; i < length; i++) {
dest[i] = 0;
}
return length; /* pretend we read zeroes */
}
static size_t silence_io_size(STREAMFILE* streamfile, void* data) {
return 0x7FFFFFF; /* whatevs */
}
static STREAMFILE* setup_silence_streamfile(STREAMFILE* sf) {
STREAMFILE* temp_sf = NULL, *new_sf = NULL;
/* setup custom streamfile */
new_sf = open_wrap_streamfile(sf);
if (!new_sf) goto fail;
temp_sf = new_sf;
new_sf = open_io_streamfile(temp_sf, NULL,0, silence_io_read,silence_io_size);
if (!new_sf) goto fail;
temp_sf = new_sf;
return temp_sf;
fail:
close_streamfile(temp_sf);
return NULL;
}
static VGMSTREAM* init_vgmstream_ubi_bao_silence(ubi_bao_header* bao, STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
STREAMFILE* temp_sf = NULL;
int channel_count, sample_rate;
int channels, sample_rate;
int32_t num_samples;
channel_count = bao->channels;
/* by default silences don't have settings */
channels = bao->channels;
if (channels == 0)
channels = 2;
sample_rate = bao->sample_rate;
/* by default silences don't have settings so let's pretend */
if (channel_count == 0)
channel_count = 2;
if (sample_rate == 0)
sample_rate = 48000;
num_samples = bao->duration * sample_rate;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, 0);
/* init the VGMSTREAM */
vgmstream = init_vgmstream_silence(channels, sample_rate, num_samples);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_UBI_BAO;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = bao->duration * sample_rate;
vgmstream->num_streams = bao->total_subsongs;
vgmstream->stream_size = vgmstream->num_samples * channel_count * 0x02; /* PCM size */
vgmstream->coding_type = coding_PCM16LE;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x02;
temp_sf = setup_silence_streamfile(sf);
if ( !vgmstream_open_stream(vgmstream, temp_sf, 0x00) )
goto fail;
close_streamfile(temp_sf);
return vgmstream;
fail:
close_vgmstream(vgmstream);
close_streamfile(temp_sf);
return vgmstream;
}

View File

@ -1526,74 +1526,33 @@ fail:
return NULL;
}
static size_t silence_io_read(STREAMFILE* sf, uint8_t *dest, off_t offset, size_t length, void* data) {
int i;
for (i = 0; i < length; i++) {
dest[i] = 0;
}
return length; /* pretend we read zeroes */
}
static size_t silence_io_size(STREAMFILE* sf, void* data) {
return 0x7FFFFFF; /* whatevs */
}
static STREAMFILE* setup_silence_streamfile(STREAMFILE* sf) {
STREAMFILE *temp_sf = NULL, *new_sf = NULL;
/* setup custom streamfile */
new_sf = open_wrap_streamfile(sf);
if (!new_sf) goto fail;
temp_sf = new_sf;
new_sf = open_io_streamfile(temp_sf, NULL,0, silence_io_read,silence_io_size);
if (!new_sf) goto fail;
temp_sf = new_sf;
return temp_sf;
fail:
close_streamfile(temp_sf);
return NULL;
}
static VGMSTREAM* init_vgmstream_ubi_sb_silence(ubi_sb_header* sb, STREAMFILE* sf_index, STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
STREAMFILE* temp_sf = NULL;
int channel_count, sample_rate;
int channels, sample_rate;
int32_t num_samples;
channel_count = sb->channels;
/* by default silences don't have settings */
channels = sb->channels;
if (channels == 0)
channels = 2;
sample_rate = sb->sample_rate;
/* by default silences don't have settings so let's pretend */
if (channel_count == 0)
channel_count = 2;
if (sample_rate == 0)
sample_rate = 48000;
num_samples = sb->duration * sample_rate;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, 0);
/* init the VGMSTREAM */
vgmstream = init_vgmstream_silence(channels, sample_rate, num_samples);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_UBI_SB;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = (int32_t)(sb->duration * (float)sample_rate);
vgmstream->num_streams = sb->total_subsongs;
vgmstream->stream_size = vgmstream->num_samples * channel_count * 0x02; /* PCM size */
vgmstream->coding_type = coding_PCM16LE;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x02;
temp_sf = setup_silence_streamfile(sf);
if ( !vgmstream_open_stream(vgmstream, temp_sf, 0x00) )
goto fail;
close_streamfile(temp_sf);
return vgmstream;
fail:
close_vgmstream(vgmstream);
close_streamfile(temp_sf);
return vgmstream;
}