mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-19 00:04:04 +01:00
Clean some streamfile code
This commit is contained in:
parent
a0a6e0d172
commit
2969db25de
@ -1160,25 +1160,12 @@ int w_bits(vgm_bitstream * ob, int num_bits, uint32_t value) {
|
|||||||
/* ******************************************** */
|
/* ******************************************** */
|
||||||
|
|
||||||
STREAMFILE* setup_subfile_streamfile(STREAMFILE *sf, off_t subfile_offset, size_t subfile_size, const char* extension) {
|
STREAMFILE* setup_subfile_streamfile(STREAMFILE *sf, off_t subfile_offset, size_t subfile_size, const char* extension) {
|
||||||
STREAMFILE *temp_sf = NULL, *new_sf = NULL;
|
STREAMFILE *new_sf = NULL;
|
||||||
|
|
||||||
new_sf = open_wrap_streamfile(sf);
|
new_sf = open_wrap_streamfile(sf);
|
||||||
if (!new_sf) goto fail;
|
new_sf = open_clamp_streamfile_f(new_sf, subfile_offset, subfile_size);
|
||||||
temp_sf = new_sf;
|
|
||||||
|
|
||||||
new_sf = open_clamp_streamfile(temp_sf, subfile_offset, subfile_size);
|
|
||||||
if (!new_sf) goto fail;
|
|
||||||
temp_sf = new_sf;
|
|
||||||
|
|
||||||
if (extension) {
|
if (extension) {
|
||||||
new_sf = open_fakename_streamfile(temp_sf, NULL, extension);
|
new_sf = open_fakename_streamfile_f(new_sf, NULL, extension);
|
||||||
if (!new_sf) goto fail;
|
|
||||||
temp_sf = new_sf;
|
|
||||||
}
|
}
|
||||||
|
return new_sf;
|
||||||
return temp_sf;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
close_streamfile(temp_sf);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
@ -70,24 +70,15 @@ fail:
|
|||||||
|
|
||||||
/* ************************************** */
|
/* ************************************** */
|
||||||
|
|
||||||
|
//todo maybe use reopen sf? since internal buffer is going to be read
|
||||||
#define ACB_TABLE_BUFFER_SIZE 0x4000
|
#define ACB_TABLE_BUFFER_SIZE 0x4000
|
||||||
|
|
||||||
STREAMFILE* setup_acb_streamfile(STREAMFILE *streamFile, size_t buffer_size) {
|
STREAMFILE* setup_acb_streamfile(STREAMFILE *sf, size_t buffer_size) {
|
||||||
STREAMFILE *temp_streamFile = NULL, *new_streamFile = NULL;
|
STREAMFILE *new_sf = NULL;
|
||||||
|
|
||||||
new_streamFile = open_wrap_streamfile(streamFile);
|
new_sf = open_wrap_streamfile(sf);
|
||||||
if (!new_streamFile) goto fail;
|
new_sf = open_buffer_streamfile_f(new_sf, buffer_size);
|
||||||
temp_streamFile = new_streamFile;
|
return new_sf;
|
||||||
|
|
||||||
new_streamFile = open_buffer_streamfile(temp_streamFile, buffer_size);
|
|
||||||
if (!new_streamFile) goto fail;
|
|
||||||
temp_streamFile = new_streamFile;
|
|
||||||
|
|
||||||
return temp_streamFile;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
close_streamfile(temp_streamFile);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ static VGMSTREAM *build_layered_vgmstream(STREAMFILE *streamFile, off_t segment_
|
|||||||
VGMSTREAM *vgmstream = NULL;
|
VGMSTREAM *vgmstream = NULL;
|
||||||
layered_layout_data* data = NULL;
|
layered_layout_data* data = NULL;
|
||||||
int i;
|
int i;
|
||||||
STREAMFILE* temp_streamFile = NULL;
|
STREAMFILE* temp_sf = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* build layers */
|
/* build layers */
|
||||||
@ -119,17 +119,17 @@ static VGMSTREAM *build_layered_vgmstream(STREAMFILE *streamFile, off_t segment_
|
|||||||
|
|
||||||
for (i = 0; i < layer_count; i++) {
|
for (i = 0; i < layer_count; i++) {
|
||||||
/* build the layer STREAMFILE */
|
/* build the layer STREAMFILE */
|
||||||
temp_streamFile = setup_aix_streamfile(streamFile, segment_offset, segment_size, i, "adx");
|
temp_sf = setup_aix_streamfile(streamFile, segment_offset, segment_size, i, "adx");
|
||||||
if (!temp_streamFile) goto fail;
|
if (!temp_sf) goto fail;
|
||||||
|
|
||||||
/* build the sub-VGMSTREAM */
|
/* build the sub-VGMSTREAM */
|
||||||
data->layers[i] = init_vgmstream_adx(temp_streamFile);
|
data->layers[i] = init_vgmstream_adx(temp_sf);
|
||||||
if (!data->layers[i]) goto fail;
|
if (!data->layers[i]) goto fail;
|
||||||
|
|
||||||
data->layers[i]->stream_size = get_streamfile_size(temp_streamFile);
|
data->layers[i]->stream_size = get_streamfile_size(temp_sf);
|
||||||
|
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
temp_streamFile = NULL;
|
temp_sf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!setup_layout_layered(data))
|
if (!setup_layout_layered(data))
|
||||||
@ -145,7 +145,7 @@ static VGMSTREAM *build_layered_vgmstream(STREAMFILE *streamFile, off_t segment_
|
|||||||
fail:
|
fail:
|
||||||
if (!vgmstream) free_layout_layered(data);
|
if (!vgmstream) free_layout_layered(data);
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,40 +112,22 @@ static size_t aix_io_size(STREAMFILE *streamfile, aix_io_data* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Handles deinterleaving of AIX blocked layer streams */
|
/* Handles deinterleaving of AIX blocked layer streams */
|
||||||
static STREAMFILE* setup_aix_streamfile(STREAMFILE *streamFile, off_t stream_offset, size_t stream_size, int layer_number, const char* extension) {
|
static STREAMFILE* setup_aix_streamfile(STREAMFILE *sf, off_t stream_offset, size_t stream_size, int layer_number, const char* extension) {
|
||||||
STREAMFILE *temp_streamFile = NULL, *new_streamFile = NULL;
|
STREAMFILE *new_sf = NULL;
|
||||||
aix_io_data io_data = {0};
|
aix_io_data io_data = {0};
|
||||||
size_t io_data_size = sizeof(aix_io_data);
|
|
||||||
|
|
||||||
io_data.stream_offset = stream_offset;
|
io_data.stream_offset = stream_offset;
|
||||||
io_data.stream_size = stream_size;
|
io_data.stream_size = stream_size;
|
||||||
io_data.layer_number = layer_number;
|
io_data.layer_number = layer_number;
|
||||||
io_data.logical_offset = -1; /* force reset */
|
io_data.logical_offset = -1; /* force reset */
|
||||||
|
|
||||||
/* setup subfile */
|
new_sf = open_wrap_streamfile(sf);
|
||||||
new_streamFile = open_wrap_streamfile(streamFile);
|
new_sf = open_io_streamfile_f(new_sf, &io_data, sizeof(aix_io_data), aix_io_read, aix_io_size);
|
||||||
if (!new_streamFile) goto fail;
|
new_sf = open_buffer_streamfile_f(new_sf, 0);
|
||||||
temp_streamFile = new_streamFile;
|
|
||||||
|
|
||||||
new_streamFile = open_io_streamfile(new_streamFile, &io_data,io_data_size, aix_io_read,aix_io_size);
|
|
||||||
if (!new_streamFile) goto fail;
|
|
||||||
temp_streamFile = new_streamFile;
|
|
||||||
|
|
||||||
new_streamFile = open_buffer_streamfile(new_streamFile,0);
|
|
||||||
if (!new_streamFile) goto fail;
|
|
||||||
temp_streamFile = new_streamFile;
|
|
||||||
|
|
||||||
if (extension) {
|
if (extension) {
|
||||||
new_streamFile = open_fakename_streamfile(temp_streamFile, NULL,extension);
|
new_sf = open_fakename_streamfile_f(new_sf, NULL, extension);
|
||||||
if (!new_streamFile) goto fail;
|
|
||||||
temp_streamFile = new_streamFile;
|
|
||||||
}
|
}
|
||||||
|
return new_sf;
|
||||||
return temp_streamFile;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
close_streamfile(temp_streamFile);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _AIX_STREAMFILE_H_ */
|
#endif /* _AIX_STREAMFILE_H_ */
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
#include "../coding/coding.h"
|
#include "../coding/coding.h"
|
||||||
|
|
||||||
|
|
||||||
static STREAMFILE* make_nub_streamfile(STREAMFILE* streamFile, off_t header_offset, size_t header_size, off_t stream_offset, size_t stream_size, const char* fake_ext);
|
static STREAMFILE* setup_nub_streamfile(STREAMFILE *sf, off_t header_offset, size_t header_size, off_t stream_offset, size_t stream_size, const char *fake_ext);
|
||||||
|
|
||||||
/* .nub - Namco's nu Sound v2 audio container */
|
/* .nub - Namco's nu Sound v2 audio container */
|
||||||
VGMSTREAM * init_vgmstream_nub(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_nub(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM *vgmstream = NULL;
|
VGMSTREAM *vgmstream = NULL;
|
||||||
STREAMFILE *temp_streamFile = NULL;
|
STREAMFILE *temp_sf = NULL;
|
||||||
off_t name_offset = 0;
|
off_t name_offset = 0;
|
||||||
size_t name_size = 0;
|
size_t name_size = 0;
|
||||||
int total_subsongs, target_subsong = streamFile->stream_index;
|
int total_subsongs, target_subsong = streamFile->stream_index;
|
||||||
@ -133,8 +133,8 @@ VGMSTREAM * init_vgmstream_nub(STREAMFILE *streamFile) {
|
|||||||
|
|
||||||
//;VGM_LOG("NUB: subfile header=%lx + %x, offset=%lx + %x\n", header_offset, header_size, stream_offset, stream_size);
|
//;VGM_LOG("NUB: subfile header=%lx + %x, offset=%lx + %x\n", header_offset, header_size, stream_offset, stream_size);
|
||||||
|
|
||||||
temp_streamFile = make_nub_streamfile(streamFile, header_offset, header_size, stream_offset, stream_size, fake_ext);
|
temp_sf = setup_nub_streamfile(streamFile, header_offset, header_size, stream_offset, stream_size, fake_ext);
|
||||||
if (!temp_streamFile) goto fail;
|
if (!temp_sf) goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get names */
|
/* get names */
|
||||||
@ -166,66 +166,36 @@ VGMSTREAM * init_vgmstream_nub(STREAMFILE *streamFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* init the VGMSTREAM */
|
/* init the VGMSTREAM */
|
||||||
vgmstream = init_vgmstream_function(temp_streamFile);
|
vgmstream = init_vgmstream_function(temp_sf);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
vgmstream->stream_size = get_streamfile_size(temp_streamFile);
|
vgmstream->stream_size = get_streamfile_size(temp_sf);
|
||||||
vgmstream->num_streams = total_subsongs;
|
vgmstream->num_streams = total_subsongs;
|
||||||
if (name[0] != '\0')
|
if (name[0] != '\0')
|
||||||
strcpy(vgmstream->stream_name, name);
|
strcpy(vgmstream->stream_name, name);
|
||||||
|
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *********************************************************** */
|
/* *********************************************************** */
|
||||||
|
|
||||||
static STREAMFILE* make_nub_streamfile(STREAMFILE* streamFile, off_t header_offset, size_t header_size, off_t stream_offset, size_t stream_size, const char* fake_ext) {
|
static STREAMFILE* setup_nub_streamfile(STREAMFILE *sf, off_t header_offset, size_t header_size, off_t stream_offset, size_t stream_size, const char *fake_ext) {
|
||||||
STREAMFILE *temp_streamFile = NULL, *new_streamFile = NULL;
|
STREAMFILE *new_sf = NULL;
|
||||||
STREAMFILE *segment_streamFiles[2] = {0};
|
STREAMFILE *multi_sf[2] = {0};
|
||||||
int i;
|
|
||||||
|
|
||||||
|
multi_sf[0] = open_wrap_streamfile(sf);
|
||||||
new_streamFile = open_wrap_streamfile(streamFile);
|
multi_sf[0] = open_clamp_streamfile_f(multi_sf[0], header_offset, header_size);
|
||||||
if (!new_streamFile) goto fail;
|
multi_sf[1] = open_wrap_streamfile(sf);
|
||||||
segment_streamFiles[0] = new_streamFile;
|
multi_sf[1] = open_clamp_streamfile_f(multi_sf[1], stream_offset, stream_size);
|
||||||
|
new_sf = open_multifile_streamfile_f(multi_sf, 2);
|
||||||
new_streamFile = open_wrap_streamfile(streamFile);
|
new_sf = open_fakename_streamfile_f(new_sf, NULL, fake_ext);
|
||||||
if (!new_streamFile) goto fail;
|
return new_sf;
|
||||||
segment_streamFiles[1] = new_streamFile;
|
|
||||||
|
|
||||||
new_streamFile = open_clamp_streamfile(segment_streamFiles[0], header_offset,header_size);
|
|
||||||
if (!new_streamFile) goto fail;
|
|
||||||
segment_streamFiles[0] = new_streamFile;
|
|
||||||
|
|
||||||
new_streamFile = open_clamp_streamfile(segment_streamFiles[1], stream_offset,stream_size);
|
|
||||||
if (!new_streamFile) goto fail;
|
|
||||||
segment_streamFiles[1] = new_streamFile;
|
|
||||||
|
|
||||||
new_streamFile = open_multifile_streamfile(segment_streamFiles, 2);
|
|
||||||
if (!new_streamFile) goto fail;
|
|
||||||
temp_streamFile = new_streamFile;
|
|
||||||
|
|
||||||
new_streamFile = open_fakename_streamfile(temp_streamFile, NULL, fake_ext);
|
|
||||||
if (!new_streamFile) goto fail;
|
|
||||||
temp_streamFile = new_streamFile;
|
|
||||||
|
|
||||||
return temp_streamFile;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
if (!temp_streamFile) {
|
|
||||||
for (i = 0; i < 2; i++) {
|
|
||||||
close_streamfile(segment_streamFiles[i]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
close_streamfile(temp_streamFile); /* closes all segments */
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *********************************************************** */
|
/* *********************************************************** */
|
||||||
@ -318,7 +288,7 @@ fail:
|
|||||||
/* .nub at3 - from Namco NUB archives [Ridge Racer 7 (PS3), Katamari Forever (PS3)] */
|
/* .nub at3 - from Namco NUB archives [Ridge Racer 7 (PS3), Katamari Forever (PS3)] */
|
||||||
VGMSTREAM * init_vgmstream_nub_at3(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_nub_at3(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
STREAMFILE *temp_streamFile = NULL;
|
STREAMFILE *temp_sf = NULL;
|
||||||
off_t subfile_offset = 0;
|
off_t subfile_offset = 0;
|
||||||
size_t subfile_size = 0;
|
size_t subfile_size = 0;
|
||||||
|
|
||||||
@ -333,16 +303,16 @@ VGMSTREAM * init_vgmstream_nub_at3(STREAMFILE *streamFile) {
|
|||||||
subfile_offset = 0x100;
|
subfile_offset = 0x100;
|
||||||
subfile_size = read_32bitLE(subfile_offset + 0x04, streamFile) + 0x08; /* RIFF size */
|
subfile_size = read_32bitLE(subfile_offset + 0x04, streamFile) + 0x08; /* RIFF size */
|
||||||
|
|
||||||
temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset,subfile_size, NULL);
|
temp_sf = setup_subfile_streamfile(streamFile, subfile_offset,subfile_size, NULL);
|
||||||
if (!temp_streamFile) goto fail;
|
if (!temp_sf) goto fail;
|
||||||
|
|
||||||
vgmstream = init_vgmstream_riff(temp_streamFile);
|
vgmstream = init_vgmstream_riff(temp_sf);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
fail:
|
fail:
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -512,7 +482,7 @@ fail:
|
|||||||
/* .nub is14 - from Namco NUB archives [Tales of Vesperia (PS3)] */
|
/* .nub is14 - from Namco NUB archives [Tales of Vesperia (PS3)] */
|
||||||
VGMSTREAM * init_vgmstream_nub_is14(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_nub_is14(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM *vgmstream = NULL;
|
VGMSTREAM *vgmstream = NULL;
|
||||||
STREAMFILE *temp_streamFile = NULL;
|
STREAMFILE *temp_sf = NULL;
|
||||||
off_t header_offset, stream_offset;
|
off_t header_offset, stream_offset;
|
||||||
size_t header_size, stream_size, sdat_size;
|
size_t header_size, stream_size, sdat_size;
|
||||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
||||||
@ -542,16 +512,16 @@ VGMSTREAM * init_vgmstream_nub_is14(STREAMFILE *streamFile) {
|
|||||||
stream_size = sdat_size;
|
stream_size = sdat_size;
|
||||||
|
|
||||||
|
|
||||||
temp_streamFile = make_nub_streamfile(streamFile, header_offset, header_size, stream_offset, stream_size, "bnsf");
|
temp_sf = setup_nub_streamfile(streamFile, header_offset, header_size, stream_offset, stream_size, "bnsf");
|
||||||
if (!temp_streamFile) goto fail;
|
if (!temp_sf) goto fail;
|
||||||
|
|
||||||
vgmstream = init_vgmstream_bnsf(temp_streamFile);
|
vgmstream = init_vgmstream_bnsf(temp_sf);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
fail:
|
fail:
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user