Add stream_size to calculate bitrate in subsongs, print bitrate info

This commit is contained in:
bnnm 2018-01-28 00:31:12 +01:00
parent a0a5143daa
commit 694cded587
2 changed files with 15 additions and 2 deletions

View File

@ -2200,6 +2200,11 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
}
concatn(length,desc,temp);
snprintf(temp,TEMPSIZE,
"\nbitrate: %d kbps",
get_vgmstream_average_bitrate(vgmstream) / 1000);
concatn(length,desc,temp);
/* only interesting if more than one */
if (vgmstream->num_streams > 1) {
snprintf(temp,TEMPSIZE,
@ -2448,9 +2453,11 @@ static STREAMFILE * get_vgmstream_average_bitrate_channel_streamfile(VGMSTREAM *
return vgmstream->ch[channel].streamfile;
}
static int get_vgmstream_average_bitrate_from_size(size_t size, int sample_rate, int length_samples) {
return (int)((int64_t)size * 8 * sample_rate / length_samples);
}
static int get_vgmstream_average_bitrate_from_streamfile(STREAMFILE * streamfile, int sample_rate, int length_samples) {
// todo: not correct in subsongs or formats which only use part of the data
return (int)((int64_t)get_streamfile_size(streamfile) * 8 * sample_rate / length_samples);
return get_vgmstream_average_bitrate_from_size(get_streamfile_size(streamfile), sample_rate, length_samples);
}
/* Return the average bitrate in bps of all unique files contained within this stream. */
@ -2468,6 +2475,11 @@ int get_vgmstream_average_bitrate(VGMSTREAM * vgmstream) {
if (!sample_rate || !channels || !length_samples)
return 0;
/* subsongs need to report this to properly calculate */
if (vgmstream->stream_size) {
return get_vgmstream_average_bitrate_from_size(vgmstream->stream_size, sample_rate, length_samples);
}
if (channels >= 1) {
streamFile = get_vgmstream_average_bitrate_channel_streamfile(vgmstream, 0);
if (streamFile) {

View File

@ -737,6 +737,7 @@ typedef struct {
int num_streams; /* for multi-stream formats (0=not set/one stream, 1=one stream) */
int stream_index; /* selected stream (also 1-based) */
char stream_name[STREAM_NAME_SIZE]; /* name of the current stream (info), if the file stores it and it's filled */
size_t stream_size; /* info to properly calculate bitrate */
/* looping */
int loop_flag; /* is this stream looped? */