mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-17 23:36:41 +01:00
Clean segmented layout setup
This commit is contained in:
parent
3eeddcc41e
commit
de94edb34b
@ -74,6 +74,7 @@ void render_vgmstream_aix(sample * buffer, int32_t sample_count, VGMSTREAM * vgm
|
||||
|
||||
void render_vgmstream_segmented(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
|
||||
segmented_layout_data* init_layout_segmented(int segment_count);
|
||||
int setup_layout_segmented(segmented_layout_data* data);
|
||||
void free_layout_segmented(segmented_layout_data *data);
|
||||
void reset_layout_segmented(segmented_layout_data *data);
|
||||
|
||||
|
@ -24,6 +24,49 @@ fail:
|
||||
}
|
||||
|
||||
|
||||
int setup_layout_segmented(segmented_layout_data* data) {
|
||||
int i;
|
||||
|
||||
/* setup each VGMSTREAM (roughly equivalent to vgmstream.c's init_vgmstream_internal stuff) */
|
||||
for (i = 0; i < data->segment_count; i++) {
|
||||
if (!data->segments[i])
|
||||
goto fail;
|
||||
|
||||
if (data->segments[i]->num_samples <= 0)
|
||||
goto fail;
|
||||
|
||||
/* shouldn't happen */
|
||||
if (data->segments[i]->loop_flag != 0) {
|
||||
VGM_LOG("segmented layout: segment %i is looped\n", i);
|
||||
data->segments[i]->loop_flag = 0;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (data->segments[i]->channels != data->segments[i-1]->channels)
|
||||
goto fail;
|
||||
|
||||
/* a bit weird, but no matter */
|
||||
if (data->segments[i]->sample_rate != data->segments[i-1]->sample_rate) {
|
||||
VGM_LOG("segmented layout: segment %i has different sample rate\n", i);
|
||||
}
|
||||
|
||||
//if (data->segments[i]->coding_type != data->segments[i-1]->coding_type)
|
||||
// goto fail; /* perfectly acceptable */
|
||||
}
|
||||
|
||||
|
||||
/* save start things so we can restart for seeking/looping */
|
||||
memcpy(data->segments[i]->start_ch,data->segments[i]->ch,sizeof(VGMSTREAMCHANNEL)*data->segments[i]->channels);
|
||||
memcpy(data->segments[i]->start_vgmstream,data->segments[i],sizeof(VGMSTREAM));
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
fail:
|
||||
return 0; /* caller is expected to free */
|
||||
}
|
||||
|
||||
|
||||
void render_vgmstream_segmented(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
|
||||
int samples_written=0;
|
||||
segmented_layout_data *data = vgmstream->layout_data;
|
||||
|
@ -86,24 +86,13 @@ VGMSTREAM * init_vgmstream_aax(STREAMFILE *streamFile) {
|
||||
|
||||
close_streamfile(temp_streamFile);
|
||||
|
||||
if (!data->segments[i])
|
||||
goto fail;
|
||||
if (data->segments[i]->loop_flag != 0)
|
||||
goto fail; /* should never happen (could be simply disabled tho) */
|
||||
if (i > 0) {
|
||||
if (data->segments[i]->channels != data->segments[i-1]->channels)
|
||||
goto fail;
|
||||
if (data->segments[i]->sample_rate != data->segments[i-1]->sample_rate)
|
||||
goto fail;
|
||||
if (data->segments[i]->coding_type != data->segments[i-1]->coding_type)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* save start things so we can restart for seeking/looping */
|
||||
memcpy(data->segments[i]->start_ch,data->segments[i]->ch,sizeof(VGMSTREAMCHANNEL)*data->segments[i]->channels);
|
||||
memcpy(data->segments[i]->start_vgmstream,data->segments[i],sizeof(VGMSTREAM));
|
||||
if (!data->segments[i]) goto fail;
|
||||
}
|
||||
|
||||
/* setup segmented VGMSTREAMs */
|
||||
if (!setup_layout_segmented(data))
|
||||
goto fail;
|
||||
|
||||
/* get looping and samples */
|
||||
sample_count = 0;
|
||||
loop_flag = 0;
|
||||
|
@ -161,15 +161,14 @@ VGMSTREAM * init_vgmstream_wave_segmented(STREAMFILE *streamFile) {
|
||||
VGM_LOG("WAVE: unknown codec\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
//todo better memcpy (call setup_layout_segmented + validate segments, disable looping, etc?)
|
||||
|
||||
/* save start things so we can restart for seeking/looping */
|
||||
memcpy(data->segments[i]->start_ch,data->segments[i]->ch,sizeof(VGMSTREAMCHANNEL)*data->segments[i]->channels);
|
||||
memcpy(data->segments[i]->start_vgmstream,data->segments[i],sizeof(VGMSTREAM));
|
||||
}
|
||||
}
|
||||
|
||||
/* setup segmented VGMSTREAMs */
|
||||
if (!setup_layout_segmented(data))
|
||||
goto fail;
|
||||
|
||||
|
||||
/* parse samples */
|
||||
{
|
||||
int32_t sample_count = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user