if(frameCount > 0) {
const double length = frameCount * 1000.0 / 48000.0;
+ long fileLengthWithoutOverhead = file->length();
+ // Ignore the two mandatory header packets, see "3. Packet Organization"
+ // in https://tools.ietf.org/html/rfc7845.html
+ for (unsigned int i = 0; i < 2; ++i) {
+ fileLengthWithoutOverhead -= file->packet(i).size();
+ }
d->length = static_cast<int>(length + 0.5);
- d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
+ d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {
if(frameCount > 0) {
const double length = frameCount * 1000.0 / d->sampleRate;
+ long fileLengthWithoutOverhead = file->length();
+ // Ignore the two header packets, see "Ogg file format" in
+ // https://www.speex.org/docs/manual/speex-manual/node8.html
+ for (unsigned int i = 0; i < 2; ++i) {
+ fileLengthWithoutOverhead -= file->packet(i).size();
+ }
d->length = static_cast<int>(length + 0.5);
- d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
+ d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {
if(frameCount > 0) {
const double length = frameCount * 1000.0 / d->sampleRate;
-
+ long fileLengthWithoutOverhead = file->length();
+ // Ignore the three initial header packets, see "1.3.1. Decode Setup" in
+ // https://xiph.org/vorbis/doc/Vorbis_I_spec.html
+ for (unsigned int i = 0; i < 3; ++i) {
+ fileLengthWithoutOverhead -= file->packet(i).size();
+ }
d->length = static_cast<int>(length + 0.5);
- d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
+ d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
- CPPUNIT_ASSERT_EQUAL(9, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->vorbisVersion());
CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds());
- CPPUNIT_ASSERT_EQUAL(37, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(36, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->inputSampleRate());