From 05e00814145bf9493f6a9a92b8718626cb5d604b Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Wed, 19 Feb 2014 23:35:23 +0900 Subject: [PATCH 1/2] Avoid using sprintf() in tagreader.cpp to fix an MSVC warning. --- examples/tagreader.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/examples/tagreader.cpp b/examples/tagreader.cpp index cc978eba..ac81be62 100644 --- a/examples/tagreader.cpp +++ b/examples/tagreader.cpp @@ -32,13 +32,6 @@ using namespace std; -TagLib::String formatSeconds(int seconds) -{ - char secondsString[3]; - sprintf(secondsString, "%02i", seconds); - return secondsString; -} - int main(int argc, char *argv[]) { for(int i = 1; i < argc; i++) { @@ -89,7 +82,7 @@ int main(int argc, char *argv[]) cout << "bitrate - " << properties->bitrate() << endl; cout << "sample rate - " << properties->sampleRate() << endl; cout << "channels - " << properties->channels() << endl; - cout << "length - " << minutes << ":" << formatSeconds(seconds) << endl; + cout << "length - " << minutes << ":" << setfill('0') << setw(2) << seconds << endl; } } return 0; From 72cd379f30492102f1a3b5ba18614da5f432c399 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 10 Mar 2014 09:27:04 +0900 Subject: [PATCH 2/2] opus: Estimate the bitrate if possible --- taglib/ogg/opus/opusproperties.cpp | 16 ++++++++++------ tests/test_opus.cpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/taglib/ogg/opus/opusproperties.cpp b/taglib/ogg/opus/opusproperties.cpp index 7bdcd39d..f098921b 100644 --- a/taglib/ogg/opus/opusproperties.cpp +++ b/taglib/ogg/opus/opusproperties.cpp @@ -45,6 +45,7 @@ public: file(f), style(s), length(0), + bitrate(0), inputSampleRate(0), channels(0), opusVersion(0) {} @@ -52,6 +53,7 @@ public: File *file; ReadStyle style; int length; + int bitrate; int inputSampleRate; int channels; int opusVersion; @@ -79,7 +81,7 @@ int Opus::Properties::length() const int Opus::Properties::bitrate() const { - return 0; + return d->bitrate; } int Opus::Properties::sampleRate() const @@ -143,14 +145,16 @@ void Opus::Properties::read() 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."); diff --git a/tests/test_opus.cpp b/tests/test_opus.cpp index 769d3985..18556241 100644 --- a/tests/test_opus.cpp +++ b/tests/test_opus.cpp @@ -23,7 +23,7 @@ public: { 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());