From de94edb34bc46433f642dededd2130e048fa7c92 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 11 Mar 2018 19:43:26 +0100 Subject: [PATCH] Clean segmented layout setup --- src/layout/layout.h | 1 + src/layout/segmented.c | 43 +++++++++++++++++++++++++++++++++++++++ src/meta/aax.c | 21 +++++-------------- src/meta/wave_segmented.c | 11 +++++----- 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/layout/layout.h b/src/layout/layout.h index 1a7f893a..49c09bb4 100644 --- a/src/layout/layout.h +++ b/src/layout/layout.h @@ -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); diff --git a/src/layout/segmented.c b/src/layout/segmented.c index 6113e822..9b1c4842 100644 --- a/src/layout/segmented.c +++ b/src/layout/segmented.c @@ -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; diff --git a/src/meta/aax.c b/src/meta/aax.c index e628d9c7..15df8ede 100644 --- a/src/meta/aax.c +++ b/src/meta/aax.c @@ -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; diff --git a/src/meta/wave_segmented.c b/src/meta/wave_segmented.c index 8ca438f0..1becd724 100644 --- a/src/meta/wave_segmented.c +++ b/src/meta/wave_segmented.c @@ -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;