Implemented bitrate reporting for vgmstream
parent
7120ba2dd9
commit
1f0f4a75a0
|
@ -3307,3 +3307,39 @@ void try_dual_file_stereo(VGMSTREAM * opened_stream, STREAMFILE *streamFile) {
|
||||||
fail:
|
fail:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_vgmstream_channel_average_bitrate(VGMSTREAMCHANNEL * channel, int sample_rate, int length_samples)
|
||||||
|
{
|
||||||
|
return (int)((int64_t)get_streamfile_size(channel->streamfile) * 8 * sample_rate / length_samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_vgmstream_average_bitrate(VGMSTREAM * vgmstream)
|
||||||
|
{
|
||||||
|
char path_current[PATH_LIMIT];
|
||||||
|
char path_compare[PATH_LIMIT];
|
||||||
|
|
||||||
|
unsigned int i, j;
|
||||||
|
int bitrate = 0;
|
||||||
|
int sample_rate = vgmstream->sample_rate;
|
||||||
|
int length_samples = vgmstream->num_samples;
|
||||||
|
|
||||||
|
if (vgmstream->channels >= 1)
|
||||||
|
bitrate += get_vgmstream_channel_average_bitrate(&vgmstream->ch[0], sample_rate, length_samples);
|
||||||
|
|
||||||
|
for (i = 1; i < vgmstream->channels; ++i)
|
||||||
|
{
|
||||||
|
VGMSTREAMCHANNEL * ch = &vgmstream->ch[i];
|
||||||
|
ch->streamfile->get_name(ch->streamfile, path_current, sizeof(path_current));
|
||||||
|
for (j = 0; j < i; ++j)
|
||||||
|
{
|
||||||
|
VGMSTREAMCHANNEL * chc = &vgmstream->ch[j];
|
||||||
|
chc->streamfile->get_name(chc->streamfile, path_compare, sizeof(path_compare));
|
||||||
|
if (!strcmp(path_current, path_compare))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (j == i)
|
||||||
|
bitrate += get_vgmstream_channel_average_bitrate(ch, sample_rate, length_samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitrate;
|
||||||
|
}
|
||||||
|
|
|
@ -901,4 +901,8 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length);
|
||||||
* stereo stream. */
|
* stereo stream. */
|
||||||
void try_dual_file_stereo(VGMSTREAM * opened_stream, STREAMFILE *streamFile);
|
void try_dual_file_stereo(VGMSTREAM * opened_stream, STREAMFILE *streamFile);
|
||||||
|
|
||||||
|
/* Return the average bitrate in bps of all unique files contained within this
|
||||||
|
* stream. Compares files by absolute paths. */
|
||||||
|
int get_vgmstream_average_bitrate(VGMSTREAM * vgmstream);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
int sampleRate;
|
int sampleRate;
|
||||||
int channels;
|
int channels;
|
||||||
|
int bitrate;
|
||||||
long totalFrames;
|
long totalFrames;
|
||||||
long framesLength;
|
long framesLength;
|
||||||
long framesFade;
|
long framesFade;
|
||||||
|
|
|
@ -131,6 +131,8 @@ err1:
|
||||||
|
|
||||||
framesRead = 0;
|
framesRead = 0;
|
||||||
|
|
||||||
|
bitrate = get_vgmstream_average_bitrate(stream);
|
||||||
|
|
||||||
[self willChangeValueForKey:@"properties"];
|
[self willChangeValueForKey:@"properties"];
|
||||||
[self didChangeValueForKey:@"properties"];
|
[self didChangeValueForKey:@"properties"];
|
||||||
|
|
||||||
|
@ -140,7 +142,7 @@ err1:
|
||||||
- (NSDictionary *)properties
|
- (NSDictionary *)properties
|
||||||
{
|
{
|
||||||
return [NSDictionary dictionaryWithObjectsAndKeys:
|
return [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
[NSNumber numberWithInt:0], @"bitrate",
|
[NSNumber numberWithInt:bitrate / 1000], @"bitrate",
|
||||||
[NSNumber numberWithInt:sampleRate], @"sampleRate",
|
[NSNumber numberWithInt:sampleRate], @"sampleRate",
|
||||||
[NSNumber numberWithDouble:totalFrames], @"totalFrames",
|
[NSNumber numberWithDouble:totalFrames], @"totalFrames",
|
||||||
[NSNumber numberWithInt:16], @"bitsPerSample",
|
[NSNumber numberWithInt:16], @"bitsPerSample",
|
||||||
|
|
Loading…
Reference in New Issue