Engine: pipe-in the EBU R 128 loudness normalization gain stuff

The idea is that Integrated Loudness is an integral part
of the song, much like knowing it's beginning / ending
in the file, and we must handle it the exact same way,
and pipe it through all the way.

At the same time, `EngineBase` knows Target Level (from settings),
and these two combined tell us the Gain needed to normalize the
Loudness of the particular Song (`EngineBase::Load()` does that).
So the actual backend only needs to handle the Volume.

We don't currently support changing Target Level on the fly.
We don't currently support changing Loudness-normalizing Gain on the fly.

This does not handle the case when the song is loaded from URL
and thus the EBU R 128 measures, that exist, are not nessesairly correct.
This commit is contained in:
Roman Lebedev
2023-06-27 05:05:01 +03:00
committed by Jonas Kvinge
parent 40ef3191fc
commit 13d6cf201f
10 changed files with 63 additions and 19 deletions

View File

@@ -66,6 +66,7 @@ class GstEnginePipeline : public QObject {
void set_stereo_balancer_enabled(const bool enabled);
void set_equalizer_enabled(const bool enabled);
void set_replaygain(const bool enabled, const int mode, const double preamp, const double fallbackgain, const bool compression);
void set_ebur128_loudness_normalization(const bool enabled);
void set_buffer_duration_nanosec(const quint64 duration_nanosec);
void set_buffer_low_watermark(const double value);
void set_buffer_high_watermark(const double value);
@@ -76,7 +77,7 @@ class GstEnginePipeline : public QObject {
void set_fading_enabled(const bool enabled);
// Creates the pipeline, returns false on error
bool InitFromUrl(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 end_nanosec, QString &error);
bool InitFromUrl(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 end_nanosec, const double ebur128_loudness_normalizing_gain_db, QString &error);
// GstBufferConsumers get fed audio data. Thread-safe.
void AddBufferConsumer(GstBufferConsumer *consumer);
@@ -102,6 +103,7 @@ class GstEnginePipeline : public QObject {
// Get information about the music playback
QUrl media_url() const { return media_url_; }
QUrl stream_url() const { return stream_url_; }
double ebur128_loudness_normalizing_gain_db() const { return ebur128_loudness_normalizing_gain_db_; }
QByteArray gst_url() const { return gst_url_; }
QUrl next_media_url() const { return next_media_url_; }
QUrl next_stream_url() const { return next_stream_url_; }
@@ -215,6 +217,9 @@ class GstEnginePipeline : public QObject {
double rg_fallbackgain_;
bool rg_compression_;
// EBU R 128 Loudness Normalization
bool ebur128_loudness_normalization_;
// Buffering
quint64 buffer_duration_nanosec_;
double buffer_low_watermark_;
@@ -282,6 +287,7 @@ class GstEnginePipeline : public QObject {
// Complete the transition to the next song when it starts playing
bool next_uri_set_;
double ebur128_loudness_normalizing_gain_db_;
bool volume_set_;
gdouble volume_internal_;
uint volume_percent_;