Moonbase59 / loudgain

ReplayGain 2.0 loudness normalizer based on the EBU R128/ITU BS.1770 standard (-18 LUFS, FLAC, Ogg, MP2, MP3, MP4, M4A, AAC, ALAC, Opus, ASF, WMA, WAV, AIFF, WavPack, APE)
Other
190 stars 23 forks source link

Loudgain has no effect on mp3 file when played in Browser or Audioplayer (e.g. VLC) #52

Closed chingming21 closed 2 years ago

chingming21 commented 2 years ago

I can see Replaygain tags are written to the mp3. But there is no effect on the loudness of the mp3 when played in Web Browser. I have tested the original mp3 also with mp3Gain (89db) and there is no problem when listening in Browser (Chrome, Safari, Firefox). I have tried these options: $ loudgain -I3 -S -L -k -s e .mp3 $ loudgain -I3 -S -k -s i .mp3 $ loudgain -S -k -s i *.mp3

oasiz commented 2 years ago

Hi,

I use the following to adjust the web audio volume according to stored loudgain data (all mp3's are stored into a json file)

  const normalize = (val, max, min)  => (val - min) / (max - min);
  const clamp = (num, min, max) => Math.min(Math.max(num, min), max);

    function getVolume(gain) {

        return clamp(
                        normalize(
                            // https://hydrogenaud.io/index.php?topic=57164.0
                            Math.min(Math.round(Math.pow(10, gain * 0.05) * 100), 100),
                            100,0),
                        0,
                        1
                );
    }

Simply pass in the track loudgain value (-3.4, 2.8 etc) as the parameter, it will return the value to use in audio.volume = X.

Below 89dB is set at volume 1 (max) and above 89dB will be a lower volume depending on the loudgain value.

It's very primitive, please feel free to suggest improvements!