Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work to incorperate use of Replay Gain #997

Closed
wants to merge 21 commits into from

Conversation

kt--
Copy link

@kt-- kt-- commented May 15, 2024

Draft RFC request only.

I'm trying to use the existing Replay Gain (Ref: https://en.wikipedia.org/wiki/ReplayGain ) functions in ffmpeg to normalise the audio volume in performous.

What does this PR do?

Implements loading and logging of any Replay Gain meta information loaded from audio files. Files might not have any Replay Gain information in them. To add it, you can use a tool like loudgain.

Closes Issue(s)

This PR does not close any issues.

Motivation

When one has audio from different sources, more often than not, the base-level volume of the audio is different. These differences are prevalent even in professionally mastered audio recordings simply due to their jurisdiction. The long-term idea is to somewhat normalise the "loudness" of the audio track, such that continual manual volume adjustments don't need to be made while enjoying performous.

I've raised this Draft PR as a discussion point, because I don't understand how the volume setting code works in performous. I have implemented Replay Gain normalisation before, but I need some pointers on how performous handles track volumes so I can implement it in a design-sympathetic manner.

UPDATE 2024-06-05

EDIT AGAIN: I've broken it all trying to fix the whitespace changes. (angry-swearing-emoji)

EDIT AGAIN: Gah! I've got heaps whitespace changes, maybe I'll just close this and re-merge.

After prompting from @twollgam, I nuked the use of libav's filter, and simply applied the replay gain factor in the correct spot[1]. It seems to be working. I will test it over the next week or so, and if I'm happy take it out of Draft.

As the data from the read from the ffmpeg input stream, it is stuffed into the audio buffer. During this phase the adjustment is made by multiplying the gain to each sample.

So far, its making loud songs softer, and soft songs louder.

[1] Possibly correct spot ;)

Copy link

github-actions bot commented May 29, 2024

Download the artifacts for this pull request:

This service is provided by nightly.link. These artifacts will expire in 90 days and will not be available for download after that time.

game/ffmpeg.cc Outdated
@@ -305,7 +305,7 @@ bool FFmpeg::readReplayGain(const AVStream *stream)
// assert(stream)
m_replaygain = 0.0;
if (stream != nullptr) {
int replay_gain_size = 0;
size_t replay_gain_size = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seams to be wrong cause ffmpeg documentation says that it is an int.

Copy link
Author

@kt-- kt-- Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't build with that as an int, maybe it's a version mismatch, but I have this:

/usr/include/x86_64-linux-gnu/libavformat/avformat.h ~ line 1913
uint8_t *av_stream_get_side_data(const AVStream *stream,
                                 enum AVPacketSideDataType type, size_t *size);

What do you want me to handle this ?

Copy link

sonarcloud bot commented Jun 10, 2024

Quality Gate Passed Quality Gate passed

Issues
3 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@kt-- kt-- closed this Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants