Skip to content

Commit 9411bb1

Browse files
authored
Opus: Read output gain (#1320)
1 parent 7829876 commit 9411bb1

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

taglib/ogg/opus/opusproperties.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Opus::Properties::PropertiesPrivate
4545
int inputSampleRate { 0 };
4646
int channels { 0 };
4747
int opusVersion { 0 };
48+
int outputGain { 0 };
4849
};
4950

5051
////////////////////////////////////////////////////////////////////////////////
@@ -93,6 +94,11 @@ int Opus::Properties::opusVersion() const
9394
return d->opusVersion;
9495
}
9596

97+
int Opus::Properties::outputGain() const
98+
{
99+
return d->outputGain;
100+
}
101+
96102
////////////////////////////////////////////////////////////////////////////////
97103
// private members
98104
////////////////////////////////////////////////////////////////////////////////
@@ -122,9 +128,10 @@ void Opus::Properties::read(File *file)
122128

123129
// *Input Sample Rate* (32 bits, unsigned, little endian)
124130
d->inputSampleRate = data.toUInt(pos, false);
125-
// pos += 4;
131+
pos += 4;
126132

127133
// *Output Gain* (16 bits, signed, little endian)
134+
d->outputGain = data.toShort(pos, false);
128135
// pos += 2;
129136

130137
// *Channel Mapping Family* (8 bits, unsigned)

taglib/ogg/opus/opusproperties.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace TagLib {
8080
* Returns the sample rate in Hz.
8181
*
8282
* \note Always returns 48000, because Opus can decode any stream at a
83-
* sample rate of 8, 12, 16, 24, or 48 kHz,
83+
* sample rate of 8, 12, 16, 24, or 48 kHz.
8484
*/
8585
int sampleRate() const override;
8686

@@ -101,6 +101,13 @@ namespace TagLib {
101101
*/
102102
int opusVersion() const;
103103

104+
/*!
105+
* Returns the output gain in signed Q7.8 fixed-point format.
106+
*
107+
* To convert the value to dB, divide it by 256.0.
108+
*/
109+
int outputGain() const;
110+
104111
private:
105112
void read(File *file);
106113

tests/test_opus.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class TestOpus : public CppUnit::TestFixture
5858
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate());
5959
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->inputSampleRate());
6060
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->opusVersion());
61+
CPPUNIT_ASSERT_EQUAL(-17920, f.audioProperties()->outputGain());
6162
}
6263

6364
void testReadComments()

0 commit comments

Comments
 (0)