file(f),
style(s),
length(0),
+ bitrate(0),
inputSampleRate(0),
channels(0),
opusVersion(0) {}
File *file;
ReadStyle style;
int length;
+ int bitrate;
int inputSampleRate;
int channels;
int opusVersion;
int Opus::Properties::bitrate() const
{
- return 0;
+ return d->bitrate;
}
int Opus::Properties::sampleRate() const
pos += 1;
const Ogg::PageHeader *first = d->file->firstPageHeader();
- const Ogg::PageHeader *last = d->file->lastPageHeader();
+ const Ogg::PageHeader *last = d->file->lastPageHeader();
if(first && last) {
- long long start = first->absoluteGranularPosition();
- long long end = last->absoluteGranularPosition();
+ const long long start = first->absoluteGranularPosition();
+ const long long end = last->absoluteGranularPosition();
- if(start >= 0 && end >= 0)
- d->length = (int) ((end - start - preSkip) / 48000);
+ if(start >= 0 && end >= 0) {
+ d->length = (int)((end - start - preSkip) / 48000);
+ d->bitrate = (int)(d->file->length() * 8.0 / (1000.0 * d->length) + 0.5);
+ }
else {
debug("Opus::Properties::read() -- The PCM values for the start or "
"end of this file was incorrect.");
{
Ogg::Opus::File f(TEST_FILE_PATH_C("correctness_gain_silent_output.opus"));
CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->length());
- CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(41, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(48000, ((Ogg::Opus::Properties *)f.audioProperties())->inputSampleRate());