Ignore silence codec in bitrate and info

This commit is contained in:
bnnm 2021-07-23 16:03:20 +02:00
parent 4a178e4e44
commit 805412e129
3 changed files with 28 additions and 10 deletions

View File

@ -240,6 +240,7 @@ VGMSTREAM* allocate_layered_vgmstream(layered_layout_data* data) {
int i, channels, loop_flag, sample_rate, external_looping;
int32_t num_samples, loop_start, loop_end;
int delta = 1024;
coding_t coding_type = data->layers[0]->coding_type;
/* get data */
channels = data->output_channels;
@ -250,6 +251,7 @@ VGMSTREAM* allocate_layered_vgmstream(layered_layout_data* data) {
loop_end = data->layers[0]->loop_end_sample;
external_looping = 0;
sample_rate = 0;
for (i = 0; i < data->layer_count; i++) {
int32_t layer_samples = vgmstream_get_samples(data->layers[i]);
int layer_loop = data->layers[i]->loop_flag;
@ -280,6 +282,9 @@ VGMSTREAM* allocate_layered_vgmstream(layered_layout_data* data) {
if (sample_rate < layer_rate)
sample_rate = layer_rate;
if (coding_type == coding_SILENCE)
coding_type = data->layers[i]->coding_type;
}
data->external_looping = external_looping;
@ -289,12 +294,12 @@ VGMSTREAM* allocate_layered_vgmstream(layered_layout_data* data) {
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = data->layers[0]->meta_type;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
vgmstream->meta_type = data->layers[0]->meta_type; /* info */
vgmstream->coding_type = data->layers[0]->coding_type; /* info */
vgmstream->coding_type = coding_type;
vgmstream->layout_type = layout_layered;
vgmstream->layout_data = data;

View File

@ -296,6 +296,7 @@ VGMSTREAM* allocate_segmented_vgmstream(segmented_layout_data* data, int loop_fl
int channel_layout;
int i, sample_rate;
int32_t num_samples, loop_start, loop_end;
coding_t coding_type = data->segments[0]->coding_type;
/* save data */
channel_layout = data->segments[0]->channel_layout;
@ -322,10 +323,14 @@ VGMSTREAM* allocate_segmented_vgmstream(segmented_layout_data* data, int loop_fl
if (sample_rate < segment_rate)
sample_rate = segment_rate;
if (coding_type == coding_SILENCE)
coding_type = data->segments[i]->coding_type;
}
/* respect loop_flag even when no loop_end found as it's possible file loops are set outside */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(data->output_channels, loop_flag);
if (!vgmstream) goto fail;
@ -335,7 +340,7 @@ VGMSTREAM* allocate_segmented_vgmstream(segmented_layout_data* data, int loop_fl
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
vgmstream->coding_type = data->segments[0]->coding_type;
vgmstream->coding_type = coding_type;
vgmstream->channel_layout = channel_layout;
vgmstream->layout_type = layout_segmented;

View File

@ -1464,7 +1464,21 @@ static int get_vgmstream_file_bitrate_main(VGMSTREAM* vgmstream, bitrate_info_t*
}
if (is_unique) {
size_t stream_size;
if (br->count >= br->count_max) goto fail;
if (vgmstream->stream_size) {
/* stream_size applies to both channels but should add once and detect repeats (for current subsong) */
stream_size = get_vgmstream_file_bitrate_from_size(vgmstream->stream_size, vgmstream->sample_rate, vgmstream->num_samples);
}
else {
stream_size = get_vgmstream_file_bitrate_from_streamfile(sf_cur, vgmstream->sample_rate, vgmstream->num_samples);
}
/* possible in cases like using silence codec */
if (!stream_size)
break;
br->hash[br->count] = hash_cur;
br->subsong[br->count] = subsong_cur;
@ -1473,13 +1487,7 @@ static int get_vgmstream_file_bitrate_main(VGMSTREAM* vgmstream, bitrate_info_t*
if (p_uniques)
(*p_uniques)++;
if (vgmstream->stream_size) {
/* stream_size applies to both channels but should add once and detect repeats (for current subsong) */
bitrate += get_vgmstream_file_bitrate_from_size(vgmstream->stream_size, vgmstream->sample_rate, vgmstream->num_samples);
}
else {
bitrate += get_vgmstream_file_bitrate_from_streamfile(sf_cur, vgmstream->sample_rate, vgmstream->num_samples);
}
bitrate += stream_size;
break;
}