Opus: Read output gain (#1320)

This commit is contained in:
Felipe
2026-03-31 13:14:44 -03:00
committed by GitHub
parent 78298769de
commit 9411bb161f
3 changed files with 17 additions and 2 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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()