diff --git a/taglib/ogg/opus/opusproperties.cpp b/taglib/ogg/opus/opusproperties.cpp index a936ce77..d7561b90 100644 --- a/taglib/ogg/opus/opusproperties.cpp +++ b/taglib/ogg/opus/opusproperties.cpp @@ -45,6 +45,7 @@ public: int inputSampleRate { 0 }; int channels { 0 }; int opusVersion { 0 }; + int outputGain { 0 }; }; //////////////////////////////////////////////////////////////////////////////// @@ -93,6 +94,11 @@ int Opus::Properties::opusVersion() const return d->opusVersion; } +int Opus::Properties::outputGain() const +{ + return d->outputGain; +} + //////////////////////////////////////////////////////////////////////////////// // private members //////////////////////////////////////////////////////////////////////////////// @@ -122,9 +128,10 @@ void Opus::Properties::read(File *file) // *Input Sample Rate* (32 bits, unsigned, little endian) d->inputSampleRate = data.toUInt(pos, false); - // pos += 4; + pos += 4; // *Output Gain* (16 bits, signed, little endian) + d->outputGain = data.toShort(pos, false); // pos += 2; // *Channel Mapping Family* (8 bits, unsigned) diff --git a/taglib/ogg/opus/opusproperties.h b/taglib/ogg/opus/opusproperties.h index 45523efc..aed23881 100644 --- a/taglib/ogg/opus/opusproperties.h +++ b/taglib/ogg/opus/opusproperties.h @@ -80,7 +80,7 @@ namespace TagLib { * Returns the sample rate in Hz. * * \note Always returns 48000, because Opus can decode any stream at a - * sample rate of 8, 12, 16, 24, or 48 kHz, + * sample rate of 8, 12, 16, 24, or 48 kHz. */ int sampleRate() const override; @@ -101,6 +101,13 @@ namespace TagLib { */ int opusVersion() const; + /*! + * Returns the output gain in signed Q7.8 fixed-point format. + * + * To convert the value to dB, divide it by 256.0. + */ + int outputGain() const; + private: void read(File *file); diff --git a/tests/test_opus.cpp b/tests/test_opus.cpp index 9f6bcc91..dc38a3c5 100644 --- a/tests/test_opus.cpp +++ b/tests/test_opus.cpp @@ -58,6 +58,7 @@ public: CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate()); CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->inputSampleRate()); CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->opusVersion()); + CPPUNIT_ASSERT_EQUAL(-17920, f.audioProperties()->outputGain()); } void testReadComments()