Moonbase59/loudgain

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

chingming21 opened this issue · 1 comments

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

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!