fix(ui): show effective dB of track when playing (#3293)
* show effective db of track when playing * tests
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const calculateReplayGain = (preAmp, gain, peak) => {
|
||||
if (gain === undefined || peak === undefined) {
|
||||
return 1
|
||||
}
|
||||
|
||||
// https://wiki.hydrogenaud.io/index.php?title=ReplayGain_1.0_specification§ion=19
|
||||
// Normalized to max gain
|
||||
return Math.min(10 ** ((gain + preAmp) / 20), 1 / peak)
|
||||
}
|
||||
|
||||
export const calculateGain = (gainInfo, song) => {
|
||||
switch (gainInfo.gainMode) {
|
||||
case 'album': {
|
||||
return calculateReplayGain(
|
||||
gainInfo.preAmp,
|
||||
song.rgAlbumGain,
|
||||
song.rgAlbumPeak,
|
||||
)
|
||||
}
|
||||
case 'track': {
|
||||
return calculateReplayGain(
|
||||
gainInfo.preAmp,
|
||||
song.rgTrackGain,
|
||||
song.rgTrackPeak,
|
||||
)
|
||||
}
|
||||
default: {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user