mpogue2 / SquareDesk

Fully-featured music player and sequence designer, designed for square dance callers
10 stars 4 forks source link

feature request: music player adjust volume to ReplayGain tags #922

Closed Gero5 closed 10 months ago

Gero5 commented 1 year ago

refers to the discussion on #805

problem Even if music files are normalized some pieces sound louder than others. Old productions are recorded differently compared to modern songs where every piece passed several compressors and limiters so the overall loudness impression is much higher. So we have to adjust the volume to that. Special Gero's challenge: I do not use a mixer between the computer and the Bose S1 active loudspeaker on club nights. The possibilities to adjust the music are a bit limited.

solution As far as I understand Replay Gain: Reply Gain is a way to calculate the perceived loudness of a piece of music. Apps like this https://projects.sappharad.com/mp3gain/ can calculate a correction factor for an individual music file and write that factor in the MP3 tags without further modifications of the music data. The Tag should look like "-1.7 dB" wich means play this at -1.7 dB.

implementation Square Desk's music player reads the MP3 tags. If a Replay Gain value is given it is added (talking in dB) to the output volume gain.

questions

mpogue2 commented 10 months ago

This (https://github.com/complexlogic/rsgain) is a very nice ReplayGain app. It will do an entire directory of files, and will NOT modify the MP3 subframe gains (like mp3gain does). Instead, it just adds in the REPLAYGAIN_TRACK_GAIN and REPLAYGAIN_TRACK_PEAK tags (ID3v2). I verified that it adds these tags using the "Kid3.app" application, that allows for editing tags.

Installed rsgain with: brew install complexlogic/tap/rsgain Ran it with: rsgain easy -p no_album /Users/mpogue/Library/CloudStorage/Box-Box/__squareDanceMusic_Box/patter/TEST

But, I'm not quite sure what to do with the results. The calculated ReplayGain Gain is what it takes to get to -18LUFS. This is a pretty low level, so all of the replay gains calculated are large negative numbers. Here's the output of regain for just the 3 files I tried:

mpogue@Mikes-MacBook-Pro TEST % rsgain easy -p no_album /Users/mpogue/Library/CloudStorage/Box-Box/__squareDanceMusic_Box/patter/TEST
[✔] Applying preset 'no_album'...
[✔] Building directory tree...
[✔] Found 1 directory...
[✔] Scanning directory for files...
[✔] Scanning '/Users/mpogue/Library/CloudStorage/Box-Box/__squareDanceMusic_Box/patter/TEST/TEST - tone_1000_0.5.mp3'
[✔] Container: MP2/3 (MPEG audio layer 2/3) [mp3]
[✔] Stream #0: MP3 (MPEG audio layer 3), 48,000 Hz, 1 ch
 100% [==========================================================================================================================]
[✔] Scanning '/Users/mpogue/Library/CloudStorage/Box-Box/__squareDanceMusic_Box/patter/TEST/ACME 156 - Buzzy Wonderland.mp3'
[✔] Container: MP2/3 (MPEG audio layer 2/3) [mp3]
[✔] Stream #0: MP3 (MPEG audio layer 3), 44,100 Hz, 2 ch
 100% [==========================================================================================================================]
[✔] Scanning '/Users/mpogue/Library/CloudStorage/Box-Box/__squareDanceMusic_Box/patter/TEST/TEST - tone_1000_0.99.mp3'
[✔] Container: MP2/3 (MPEG audio layer 2/3) [mp3]
[✔] Stream #0: MP3 (MPEG audio layer 3), 48,000 Hz, 1 ch
 100% [==========================================================================================================================]

Track: /Users/mpogue/Library/CloudStorage/Box-Box/__squareDanceMusic_Box/patter/TEST/TEST - tone_1000_0.5.mp3
  Loudness:    -9.02 LUFS
  Peak:     0.500153 (-6.02 dB)
  Gain:        -8.98 dB

Track: /Users/mpogue/Library/CloudStorage/Box-Box/__squareDanceMusic_Box/patter/TEST/ACME 156 - Buzzy Wonderland.mp3
  Loudness:   -11.71 LUFS
  Peak:     0.927917 (-0.65 dB)
  Gain:        -6.29 dB

Track: /Users/mpogue/Library/CloudStorage/Box-Box/__squareDanceMusic_Box/patter/TEST/TEST - tone_1000_0.99.mp3
  Loudness:    -3.09 LUFS
  Peak:     0.990234 (-0.09 dB)
  Gain:       -14.91 dB

Scanning Complete
Time Elapsed:      00:00:00
Files Scanned:     3
Clip Adjustments:  0 (0.0% of files)
Average Gain:      -10.06 dB
Average Peak:      0.806101 (-1.87 dB)
Negative Gains:    3 (100.0% of files)
Positive Gains:    0 (0.0% of files)

The test files were:

If we're going to be applying a 6dB (or more) attenuation, the volumes are going to end up being quite low. So, then do we add in "makeup gain"? How much?

danlyke commented 10 months ago

Can we use a max of all of the files in the music folder as 100%? Message ID: @.***>

mpogue2 commented 10 months ago

@danlyke I don't think so. The real underlying issue here is that the songs that are very low in volume can't be brought up to match the loud-volume ones right now.

Possible solutions: a) allow the volume control to go higher than 100% for individual songs (with some kind of UX affordance to prevent too much clipping, or to warn the user that clipping will occur) b) pay attention to ReplayGain tags, and use an external program like rsgain to calculate the ID3v2 ReplayGain tags (this is changing the metadata in each MP3 file, so some risk) c) use an external program like mp3gain to alter the data in the MP3 files (mp3gain alters the individual segment volumes, and this is in theory reversible, so this option is riskier than option b, but not as risky as rewriting all the data in all the MP3 files)

But, both options b and c will re-level all the files to -18LUFS, which is a way lower volume than most files are at now.

danlyke commented 10 months ago

Isn't option "a" just like "you have to pick up the gain somewhere, make that downstream in the analog section and turn your amp/speaker gain up higher?"

On Wed, Nov 22, 2023 at 9:52 PM Mike Pogue @.***> wrote:

@danlyke https://github.com/danlyke I don't think so. The real underlying issue here is that the songs that are very low in volume can't be brought up to match the loud-volume ones right now.

Possible solutions: a) allow the volume control to go higher than 100% for individual songs (with some kind of UX affordance to prevent too much clipping, or to warn the user that clipping will occur) b) pay attention to ReplayGain tags, and use an external program like rsgain to calculate the ID3v2 ReplayGain tags (this is changing the metadata in each MP3 file, so some risk) c) use an external program like mp3gain to alter the data in the MP3 files (mp3gain alters the individual segment volumes, and this is in theory reversible, so this option is riskier than option b, but not as risky as rewriting all the data in all the MP3 files)

But, both options b and c will re-level all the files to -18LUFS, which is a way lower volume than most files are at now.

— Reply to this email directly, view it on GitHub https://github.com/mpogue2/SquareDesk/issues/922#issuecomment-1823850676, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAVWVY2D3KU3XTNF2WISH3YF3QCBAVCNFSM6AAAAAA4WGMRTSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRTHA2TANRXGY . You are receiving this because you were mentioned.Message ID: @.***>

Gero5 commented 10 months ago

in v 1.0.6 the whole song is processed at load time to draw the waveform. would it be possible to detect the highest peak value of the volume and get the factor to adjust that to 0 dB? Than the whole song values can be muliplied by that (gain) factor which is a normalization at load time. as feature than can be toggled on or off in the preference values or in the music menu.

I think that would be a big help for my cases.

mpogue2 commented 10 months ago

I was thinking the same thing!

This is essential a "normalize track to 0dB" operation, rather than a ReplayGain operation. We could make it an option in Preferences. I am thinking that maybe the waveform should also scale, so that the peak is at 0dB (it shouldn't take much time). I know you said you'd prefer it NOT to scale, but if it's cheap in terms of time, would you still not want the waveform to scale to indicate the new volume?

Right now, the waveform is a 3-point gaussian-filtered version of the max (peak) in each short segment of time. So, I'm already calculating the max in each segment of music.

mpogue2 commented 10 months ago

See #954.

mpogue2 commented 10 months ago

Given that #954 looks pretty good, I think we should not implement ReplayGain tags at this time. So, closing for now...