Implemented bitrate reporting for vgmstream

CQTexperiment
Chris Moeller 2015-02-08 19:20:24 -08:00
parent 7120ba2dd9
commit 1f0f4a75a0
4 changed files with 44 additions and 1 deletions

View File

@ -3307,3 +3307,39 @@ void try_dual_file_stereo(VGMSTREAM * opened_stream, STREAMFILE *streamFile) {
fail:
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;
}

View File

@ -901,4 +901,8 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length);
* stereo stream. */
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

View File

@ -18,6 +18,7 @@
int sampleRate;
int channels;
int bitrate;
long totalFrames;
long framesLength;
long framesFade;

View File

@ -131,6 +131,8 @@ err1:
framesRead = 0;
bitrate = get_vgmstream_average_bitrate(stream);
[self willChangeValueForKey:@"properties"];
[self didChangeValueForKey:@"properties"];
@ -140,7 +142,7 @@ err1:
- (NSDictionary *)properties
{
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:0], @"bitrate",
[NSNumber numberWithInt:bitrate / 1000], @"bitrate",
[NSNumber numberWithInt:sampleRate], @"sampleRate",
[NSNumber numberWithDouble:totalFrames], @"totalFrames",
[NSNumber numberWithInt:16], @"bitsPerSample",