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

feat!: Unify ReplayGain handling and calculation #3438

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

vitoyucepi
Copy link
Collaborator

@vitoyucepi vitoyucepi commented Oct 2, 2023

Summary

This PR unifies ReplayGain handling by:

  • A new metadata.replaygain method extracts a unified replay gain value in dB from metadata, handling r128_track_gain and replaygain_track_gain internally to provide a single gain value.

  • Adding a compute parameter to file.replaygain and enable_replaygain_metadata to control gain calculation when metadata is missing replaygain tags. enable_replaygain_metadata calls file.replaygain internally with the compute value.

  • Removing the unnecessary ebu_r128 parameter from replaygain since EBU R128 data will be extracted from metadata when available.

Breaking changes

  • replaygain no longer has the ebu_r128 named parameter. r128_track_gain is now always processed from metadata in the metadata.replaygain function.
  • metadata.replaygain extracts gain from replaygain_track_gain always in dB.

Additional

Closes #3435.
Requires #3478.

@vitoyucepi
Copy link
Collaborator Author

I need some help with the tests for replaygain, file.replaygain.compute, and file.replaygain.

@vitoyucepi vitoyucepi force-pushed the replaygain_unification branch 3 times, most recently from 3d916d1 to 3d9c058 Compare October 2, 2023 19:28
@toots toots requested a review from smimram October 2, 2023 19:31
Copy link
Member

@smimram smimram left a comment

Choose a reason for hiding this comment

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

Looks fine thanks!

src/libs/replaygain.liq Outdated Show resolved Hide resolved
@vitoyucepi vitoyucepi force-pushed the replaygain_unification branch 5 times, most recently from f481679 to 62488c3 Compare October 3, 2023 01:40
@vitoyucepi vitoyucepi changed the title feat: Unify ReplayGain handling and calculation feat!: Unify ReplayGain handling and calculation Oct 3, 2023
@toots
Copy link
Member

toots commented Oct 5, 2023

Hi! Do you need anything more with this PR? If @smimram has approved it I trurst y'all 🙂

@vitoyucepi
Copy link
Collaborator Author

Do you need anything more with this PR?

I need some help with the tests for replaygain, file.replaygain.compute, and file.replaygain.

How do I plan to test file.replaygain

  1. mp3 with replaygain_track_gain.
  2. mp3 with r128_track_gain.
  3. mp3 with both replaygain_track_gain and r128_track_gain.
  4. opus with replaygain_track_gain.
  5. opus with r128_track_gain.
  6. opus with both replaygain_track_gain and r128_track_gain.
  7. mp3 with replaygain_track_gain and compute=true.
  8. mp3 with replaygain_track_gain and compute=false.
  9. mp3 without replaygain_track_gain and compute=true.
  10. mp3 without replaygain_track_gain and compute=false.

@toots
Copy link
Member

toots commented Oct 7, 2023

Okay. Do you mean you would like some support writing the test?

@vitoyucepi
Copy link
Collaborator Author

Do you mean you would like some support writing the test?

Yes, I do!

  1. Where should I place tests?
  2. How to generate test assets.
    I can create them before testing the corresponding function.
    ffmpeg -f lavfi -i 'anullsrc=r=44100:cl=mono' -t 0.01 -c:a libmp3lame -metadata REPLAYGAIN_TRACK_GAIN='10 dB' -y '1.mp3'.
  3. If creating files at test time is not a good idea, how do I create minimal files?
  4. How do I store them in the project, as files or as base64?

@toots
Copy link
Member

toots commented Oct 14, 2023

Do you mean you would like some support writing the test?

Yes, I do!

Sorry for the delay.

  1. Where should I place tests?

I think the pattern we seemed to have been following mostly is:

  • tests/media for everything encoder/decoder/media content test
  • tests/stream for everything operator etc.

Thus, I would say tests/stream.

  1. How to generate test assets.
    I can create them before testing the corresponding function.
    ffmpeg -f lavfi -i 'anullsrc=r=44100:cl=mono' -t 0.01 -c:a libmp3lame -metadata REPLAYGAIN_TRACK_GAIN='10 dB' -y '1.mp3'.

Yes, that's how we already do it. See for instance in tests/stream/dune:

(rule
 (alias citest)
 (target file1.mp3)
 (action
  (run
   ffmpeg
   -hide_banner
   -loglevel
   error
   -f
   lavfi
   -i
   "sine=frequency=220:duration=5"
   -ac
   2
   %{target})))

You can then put this file has a dependency of your test:

(rule
 (alias citest)
 (package liquidsoap)
 (deps
  195.liq
  ./file1.mp3
  ../../src/bin/liquidsoap.exe
  (package liquidsoap)
  (:test_liq ../test.liq)
  (:run_test ../run_test.exe))
 (action (run %{run_test} 195.liq liquidsoap %{test_liq} 195.liq)))
  1. If creating files at test time is not a good idea, how do I create minimal files?

at test time works!

  1. How do I store them in the project, as files or as base64?

at test time works!

To run a test, we use the tests/test.liq library and a test runner run_test.exe.

Once a new test is placed in tests/stream, you you dune:

% dune build @gendune --auto-promote

This will re-generate the dune files to include your test in the test suite.

If your test does not have generated test files, you can run it manually from within test/streams:

../../liquidsoap ../test.liq ./my-test.liq

If it does, the best is to run all the tests:

% dune build @citest

Once all the tests are ran, if your test still has issues you can manually go to _build/default/tests/streams and run it same as above, this time with all the files generated:

../../../../liquidsoap ../test.liq ./my-test.liq

If you edit the file inside _build/default/tests/streams, don't forget to copy it back to tests/streams!

Hope this helps!

@toots
Copy link
Member

toots commented Oct 18, 2023

@vitoyucepi I had to change the test runner configuration. If you push another commit, they should run this time.

@vitoyucepi
Copy link
Collaborator Author

@toots, I'd like to create another PR with additional test methods.

def test.not_equals(first, second)
def test.almost_equals(~places=7, first, second)
def test.not_almost_equals(~places=7, first, second)

I'm planning to replace

null.defined(g) and abs(null.get(g) - 7.37) < 0.05

with

test.not_equals(g, null())
test.almost_equals(g, 7.37)

@toots
Copy link
Member

toots commented Oct 18, 2023

Sounds great! Unless you want to also convert a bunch of tests to use the new API, you could also introduce it here directly.

@vitoyucepi
Copy link
Collaborator Author

I've created a separate PR with the required test functions.
#3478

@vitoyucepi vitoyucepi force-pushed the replaygain_unification branch 6 times, most recently from f1447a3 to 7865145 Compare October 22, 2023 22:49
@vitoyucepi
Copy link
Collaborator Author

I think this PR is ready.
@toots, could you please check tests/stream/dune and tests/streams/gen_dune.ml?

Add new metadata.replaygain function to extract unified replay gain
value in dB from metadata.
  - Handles r128_track_gain and replaygain_track_gain internally.
  - Returns single gain value.

Add compute parameter to file.replaygain and enable_replaygain_metadata.
  - Controls whether to compute gain when metadata missing tags.
  - enable_replaygain_metadata calls file.replaygain with compute.

BREAKING CHANGE: Remove unnecessary ebu_r128 parameter from replaygain.
BREAKING CHANGE: Extract replaygain_track_gain always in dB.
@toots
Copy link
Member

toots commented Nov 1, 2023

This looks really good sorry for the delay reviewing this. Setting it for auto-merge now!

@toots toots enabled auto-merge November 1, 2023 14:41
@toots toots added this pull request to the merge queue Nov 1, 2023
Merged via the queue into savonet:main with commit 42660ce Nov 1, 2023
25 checks passed
@vitoyucepi vitoyucepi deleted the replaygain_unification branch July 16, 2024 10:27
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.

replaygain issue when dB missing from the tag
3 participants